Skip to content

Commit 6094a8a

Browse files
refactor(s8000): deduplicate some prop logic
1 parent 5e1dba1 commit 6094a8a

1 file changed

Lines changed: 47 additions & 123 deletions

File tree

hw/arm/apple-silicon/s8000.c

Lines changed: 47 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@
5353
#include "system/system.h"
5454
#include "target/arm/arm-powerctl.h"
5555

56+
#define PROP_STR_GETTER_SETTER(_name) \
57+
static char *s8000_get_##_name(Object *obj, Error **errp) \
58+
{ \
59+
return g_strdup(S8000_MACHINE(obj)->_name); \
60+
} \
61+
\
62+
static void s8000_set_##_name(Object *obj, const char *value, \
63+
Error **errp) \
64+
{ \
65+
S8000MachineState *s8000_machine; \
66+
\
67+
s8000_machine = S8000_MACHINE(obj); \
68+
g_free(s8000_machine->_name); \
69+
s8000_machine->_name = g_strdup(value); \
70+
}
71+
72+
#define PROP_GETTER_SETTER(_type, _name) \
73+
static void s8000_set_##_name(Object *obj, _type value, Error **errp) \
74+
{ \
75+
S8000_MACHINE(obj)->_name = value; \
76+
} \
77+
\
78+
static _type s8000_get_##_name(Object *obj, Error **errp) \
79+
{ \
80+
return S8000_MACHINE(obj)->_name; \
81+
}
82+
5683
#define S8000_SPI0_IRQ 188
5784

5885
#define S8000_GPIO_HOLD_KEY 97
@@ -76,7 +103,7 @@
76103
#define S8000_NVME_SART_BASE (S8000_DRAM_BASE + 0x7F400000ull)
77104
#define S8000_NVME_SART_SIZE 0xc00000ull
78105

79-
// regions 0x1/0x7/0xa are in between, each with a size of 0x4000 bytes.
106+
// regions 0x1/0x7/0xa are in-between, each with a size of 0x4000 bytes.
80107

81108
// Carveout region 0xC
82109
#define S8000_PANIC_SIZE 0x80000ull
@@ -1506,100 +1533,12 @@ static void s8000_machine_init(MachineState *machine)
15061533
qemu_add_machine_init_done_notifier(&s8000_machine->init_done_notifier);
15071534
}
15081535

1509-
static void s8000_set_kaslr_off(Object *obj, bool value, Error **errp)
1510-
{
1511-
S8000MachineState *s8000_machine;
1512-
1513-
s8000_machine = S8000_MACHINE(obj);
1514-
s8000_machine->kaslr_off = value;
1515-
}
1516-
1517-
static bool s8000_get_kaslr_off(Object *obj, Error **errp)
1518-
{
1519-
S8000MachineState *s8000_machine;
1520-
1521-
s8000_machine = S8000_MACHINE(obj);
1522-
return s8000_machine->kaslr_off;
1523-
}
1524-
15251536
static ram_addr_t s8000_machine_fixup_ram_size(ram_addr_t size)
15261537
{
15271538
g_assert_cmpuint(size, ==, S8000_DRAM_SIZE);
15281539
return size;
15291540
}
15301541

1531-
static void s8000_set_trustcache_filename(Object *obj, const char *value,
1532-
Error **errp)
1533-
{
1534-
S8000MachineState *s8000_machine;
1535-
1536-
s8000_machine = S8000_MACHINE(obj);
1537-
g_free(s8000_machine->trustcache_filename);
1538-
s8000_machine->trustcache_filename = g_strdup(value);
1539-
}
1540-
1541-
static char *s8000_get_trustcache_filename(Object *obj, Error **errp)
1542-
{
1543-
S8000MachineState *s8000_machine;
1544-
1545-
s8000_machine = S8000_MACHINE(obj);
1546-
return g_strdup(s8000_machine->trustcache_filename);
1547-
}
1548-
1549-
static void s8000_set_ticket_filename(Object *obj, const char *value,
1550-
Error **errp)
1551-
{
1552-
S8000MachineState *s8000_machine;
1553-
1554-
s8000_machine = S8000_MACHINE(obj);
1555-
g_free(s8000_machine->ticket_filename);
1556-
s8000_machine->ticket_filename = g_strdup(value);
1557-
}
1558-
1559-
static char *s8000_get_ticket_filename(Object *obj, Error **errp)
1560-
{
1561-
S8000MachineState *s8000_machine;
1562-
1563-
s8000_machine = S8000_MACHINE(obj);
1564-
return g_strdup(s8000_machine->ticket_filename);
1565-
}
1566-
1567-
static void s8000_set_seprom_filename(Object *obj, const char *value,
1568-
Error **errp)
1569-
{
1570-
S8000MachineState *s8000_machine;
1571-
1572-
s8000_machine = S8000_MACHINE(obj);
1573-
g_free(s8000_machine->seprom_filename);
1574-
s8000_machine->seprom_filename = g_strdup(value);
1575-
}
1576-
1577-
static char *s8000_get_seprom_filename(Object *obj, Error **errp)
1578-
{
1579-
S8000MachineState *s8000_machine;
1580-
1581-
s8000_machine = S8000_MACHINE(obj);
1582-
return g_strdup(s8000_machine->seprom_filename);
1583-
}
1584-
1585-
static void s8000_set_sepfw_filename(Object *obj, const char *value,
1586-
Error **errp)
1587-
{
1588-
S8000MachineState *s8000_machine;
1589-
1590-
s8000_machine = S8000_MACHINE(obj);
1591-
g_free(s8000_machine->sep_fw_filename);
1592-
s8000_machine->sep_fw_filename = g_strdup(value);
1593-
}
1594-
1595-
static char *s8000_get_sepfw_filename(Object *obj, Error **errp)
1596-
{
1597-
S8000MachineState *s8000_machine;
1598-
1599-
s8000_machine = S8000_MACHINE(obj);
1600-
return g_strdup(s8000_machine->sep_fw_filename);
1601-
}
1602-
16031542
static void s8000_set_boot_mode(Object *obj, const char *value, Error **errp)
16041543
{
16051544
S8000MachineState *s8000_machine;
@@ -1641,44 +1580,28 @@ static char *s8000_get_boot_mode(Object *obj, Error **errp)
16411580
static void s8000_get_ecid(Object *obj, Visitor *v, const char *name,
16421581
void *opaque, Error **errp)
16431582
{
1644-
S8000MachineState *s8000_machine;
1645-
int64_t value;
1583+
uint64_t value;
16461584

1647-
s8000_machine = S8000_MACHINE(obj);
1648-
value = s8000_machine->ecid;
1649-
visit_type_int(v, name, &value, errp);
1585+
value = S8000_MACHINE(obj)->ecid;
1586+
visit_type_uint64(v, name, &value, errp);
16501587
}
16511588

16521589
static void s8000_set_ecid(Object *obj, Visitor *v, const char *name,
16531590
void *opaque, Error **errp)
16541591
{
1655-
S8000MachineState *s8000_machine;
1656-
int64_t value;
1592+
uint64_t value;
16571593

1658-
s8000_machine = S8000_MACHINE(obj);
1659-
1660-
if (!visit_type_int(v, name, &value, errp)) {
1661-
return;
1594+
if (visit_type_uint64(v, name, &value, errp)) {
1595+
S8000_MACHINE(obj)->ecid = value;
16621596
}
1663-
1664-
s8000_machine->ecid = value;
1665-
}
1666-
1667-
static void s8000_set_force_dfu(Object *obj, bool value, Error **errp)
1668-
{
1669-
S8000MachineState *s8000_machine;
1670-
1671-
s8000_machine = S8000_MACHINE(obj);
1672-
s8000_machine->force_dfu = value;
16731597
}
16741598

1675-
static bool s8000_get_force_dfu(Object *obj, Error **errp)
1676-
{
1677-
S8000MachineState *s8000_machine;
1678-
1679-
s8000_machine = S8000_MACHINE(obj);
1680-
return s8000_machine->force_dfu;
1681-
}
1599+
PROP_STR_GETTER_SETTER(trustcache_filename);
1600+
PROP_STR_GETTER_SETTER(ticket_filename);
1601+
PROP_STR_GETTER_SETTER(sep_rom_filename);
1602+
PROP_STR_GETTER_SETTER(sep_fw_filename);
1603+
PROP_GETTER_SETTER(bool, kaslr_off);
1604+
PROP_GETTER_SETTER(bool, force_dfu);
16821605

16831606
static void s8000_machine_class_init(ObjectClass *klass, const void *data)
16841607
{
@@ -1707,13 +1630,14 @@ static void s8000_machine_class_init(ObjectClass *klass, const void *data)
17071630
s8000_set_ticket_filename);
17081631
object_class_property_set_description(klass, "ticket",
17091632
"APTicket to be loaded");
1710-
object_class_property_add_str(klass, "seprom", s8000_get_seprom_filename,
1711-
s8000_set_seprom_filename);
1712-
object_class_property_set_description(klass, "seprom",
1633+
object_class_property_add_str(klass, "sep-rom", s8000_get_sep_rom_filename,
1634+
s8000_set_sep_rom_filename);
1635+
object_class_property_set_description(klass, "sep-rom",
17131636
"SEPROM to be loaded");
1714-
object_class_property_add_str(klass, "sepfw", s8000_get_sepfw_filename,
1715-
s8000_set_sepfw_filename);
1716-
object_class_property_set_description(klass, "sepfw", "SEPFW to be loaded");
1637+
object_class_property_add_str(klass, "sep-fw", s8000_get_sep_fw_filename,
1638+
s8000_set_sep_fw_filename);
1639+
object_class_property_set_description(klass, "sep-fw",
1640+
"SEPFW to be loaded");
17171641
object_class_property_add_str(klass, "boot-mode", s8000_get_boot_mode,
17181642
s8000_set_boot_mode);
17191643
object_class_property_set_description(klass, "boot-mode",

0 commit comments

Comments
 (0)