@samitouri / QOSamiQemu / commits / 3305853f48

hw/arm/sabrelite: Introduce class SabreliteMachineState

Create full class SabreliteMachineState extending MachineState. Previously, Sabrelite board MachineState was declared indirectly by the DEFINE_MACHINE_ARM macro. FslIMX6State was only instantiated in the sabrelite_init function. For FlexCAN device, machine properties will be used to select QEMU CAN buses. A custom class is therefore required, so the CanBusState "connections" can then be added as fields. Signed-off-by: Matyáš Bobek <matyas.bobek@gmail.com> Signed-off-by: Pavel Pisa <pisa@fel.cvut.cz> Tested-by: Pavel Pisa <pisa@fel.cvut.cz> Reviewed-by: Bernhard Beschow <shentey@gmail.com> Reviewed-by: Pavel Pisa <pisa@fel.cvut.cz> Message-id: 115740db83cf2e5a5e7bb349130c9706934ec1f3.1782140438.git.matyas.bobek@gmail.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Matyáš Bobek committed Jun 22, 2026 at 18:08 UTC 3305853f48c5a96ffec5bcc413bef6cabb51cca0
1 file changed +18 -10
hw/arm/sabrelite.c
+18 -10
@@ -20,6 +20,15 @@
20 #include "qemu/error-report.h"
21 #include "system/qtest.h"
22
23 +struct SabreliteMachineState {
24 + MachineState parent_obj;
25 +
26 + FslIMX6State soc;
27 +};
28 +
29 +#define TYPE_SABRELITE_MACHINE MACHINE_TYPE_NAME("sabrelite")
30 +OBJECT_DECLARE_SIMPLE_TYPE(SabreliteMachineState, SABRELITE_MACHINE)
31 +
32 static struct arm_boot_info sabrelite_binfo = {
33 /* DDR memory start */
34 .loader_start = FSL_IMX6_MMDC_ADDR,
@@ -41,7 +50,7 @@ static void sabrelite_reset_secondary(ARMCPU *cpu,
50
51 static void sabrelite_init(MachineState *machine)
52 {
44 - FslIMX6State *s;
53 + SabreliteMachineState *s = SABRELITE_MACHINE(machine);
54
55 /* Check the amount of memory is compatible with the SOC */
56 if (machine->ram_size > FSL_IMX6_MMDC_SIZE) {
@@ -50,13 +59,12 @@ static void sabrelite_init(MachineState *machine)
59 exit(1);
60 }
61
53 - s = FSL_IMX6(object_new(TYPE_FSL_IMX6));
54 - object_property_add_child(OBJECT(machine), "soc", OBJECT(s));
62 + object_initialize_child(OBJECT(machine), "soc", &s->soc, TYPE_FSL_IMX6);
63
64 /* Ethernet PHY address is 6 */
57 - object_property_set_int(OBJECT(s), "fec-phy-num", 6, &error_fatal);
65 + object_property_set_int(OBJECT(&s->soc), "fec-phy-num", 6, &error_fatal);
66
59 - qdev_realize(DEVICE(s), NULL, &error_fatal);
67 + qdev_realize(DEVICE(&s->soc), NULL, &error_fatal);
68
69 memory_region_add_subregion(get_system_memory(), FSL_IMX6_MMDC_ADDR,
70 machine->ram);
@@ -70,7 +78,7 @@ static void sabrelite_init(MachineState *machine)
78 /* Add the sst25vf016b NOR FLASH memory to first SPI */
79 Object *spi_dev;
80
73 - spi_dev = object_resolve_path_component(OBJECT(s), "spi1");
81 + spi_dev = object_resolve_path_component(OBJECT(&s->soc), "spi1");
82 if (spi_dev) {
83 SSIBus *spi_bus;
84
@@ -89,7 +97,7 @@ static void sabrelite_init(MachineState *machine)
97 qdev_realize_and_unref(flash_dev, BUS(spi_bus), &error_fatal);
98
99 cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
92 - qdev_connect_gpio_out(DEVICE(&s->gpio[2]), 19, cs_line);
100 + qdev_connect_gpio_out(DEVICE(&s->soc.gpio[2]), 19, cs_line);
101 }
102 }
103 }
@@ -100,7 +108,7 @@ static void sabrelite_init(MachineState *machine)
108 sabrelite_binfo.secondary_cpu_reset_hook = sabrelite_reset_secondary;
109
110 if (!qtest_enabled()) {
103 - arm_load_kernel(&s->cpu[0], machine, &sabrelite_binfo);
111 + arm_load_kernel(&s->soc.cpu[0], machine, &sabrelite_binfo);
112 }
113 }
114
@@ -117,10 +125,10 @@ static void sabrelite_machine_class_init(ObjectClass *oc, const void *data)
125 }
126
127 static const TypeInfo sabrelite_machine_init_typeinfo = {
120 - .name = MACHINE_TYPE_NAME("sabrelite"),
128 + .name = TYPE_SABRELITE_MACHINE,
129 .parent = TYPE_MACHINE,
130 .class_init = sabrelite_machine_class_init,
123 - .instance_size = sizeof(MachineState),
131 + .instance_size = sizeof(SabreliteMachineState),
132 .abstract = false,
133 .interfaces = arm_machine_interfaces,
134 };