Message ID | 20250204002240.97830-4-philmd@linaro.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | hw/arm/raspi: Allow creating any Raspberry Pi machine | expand |
On Tue, 4 Feb 2025 at 00:23, Philippe Mathieu-Daudé <philmd@linaro.org> wrote: > > Merge Raspi4bMachineState within RaspiMachineState by > using an unnamed union. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > hw/arm/raspi.c | 21 +++++++-------------- > 1 file changed, 7 insertions(+), 14 deletions(-) > > diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c > index 3fa382d62ce..ef94d57dab5 100644 > --- a/hw/arm/raspi.c > +++ b/hw/arm/raspi.c > @@ -38,9 +38,6 @@ > #define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common") > OBJECT_DECLARE_SIMPLE_TYPE(RaspiMachineState, RASPI_MACHINE) > > -#define TYPE_RASPI4B_MACHINE MACHINE_TYPE_NAME("raspi4b") > -OBJECT_DECLARE_SIMPLE_TYPE(Raspi4bMachineState, RASPI4B_MACHINE) > - > #define SMPBOOT_ADDR 0x300 /* this should leave enough space for ATAGS */ > #define MVBAR_ADDR 0x400 /* secure vectors */ > #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20) /* board setup code */ > @@ -49,15 +46,12 @@ OBJECT_DECLARE_SIMPLE_TYPE(Raspi4bMachineState, RASPI4B_MACHINE) > #define SPINTABLE_ADDR 0xd8 /* Pi 3 bootloader spintable */ > > struct RaspiMachineState { > - /*< private >*/ > RaspiBaseMachineState parent_obj; > - /*< public >*/ > - BCM283XState soc; > -}; > > -struct Raspi4bMachineState { > - RaspiBaseMachineState parent_obj; > - BCM2838State soc; > + union { > + BCM283XState soc; > + BCM2838State soc4; > + }; Do we have any other examples of using a union like this? I think it's exactly because the components are different for raspi4b that it has its own machine state struct. thanks -- PMM
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index 3fa382d62ce..ef94d57dab5 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -38,9 +38,6 @@ #define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common") OBJECT_DECLARE_SIMPLE_TYPE(RaspiMachineState, RASPI_MACHINE) -#define TYPE_RASPI4B_MACHINE MACHINE_TYPE_NAME("raspi4b") -OBJECT_DECLARE_SIMPLE_TYPE(Raspi4bMachineState, RASPI4B_MACHINE) - #define SMPBOOT_ADDR 0x300 /* this should leave enough space for ATAGS */ #define MVBAR_ADDR 0x400 /* secure vectors */ #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20) /* board setup code */ @@ -49,15 +46,12 @@ OBJECT_DECLARE_SIMPLE_TYPE(Raspi4bMachineState, RASPI4B_MACHINE) #define SPINTABLE_ADDR 0xd8 /* Pi 3 bootloader spintable */ struct RaspiMachineState { - /*< private >*/ RaspiBaseMachineState parent_obj; - /*< public >*/ - BCM283XState soc; -}; -struct Raspi4bMachineState { - RaspiBaseMachineState parent_obj; - BCM2838State soc; + union { + BCM283XState soc; + BCM2838State soc4; + }; }; /* @@ -380,10 +374,10 @@ static void raspi4_modify_dtb(const struct arm_boot_info *info, void *fdt) static void raspi4b_machine_init(MachineState *machine) { - Raspi4bMachineState *s = RASPI4B_MACHINE(machine); + RaspiMachineState *s = RASPI_MACHINE(machine); RaspiBaseMachineState *s_base = RASPI_BASE_MACHINE(machine); RaspiBaseMachineClass *mc = RASPI_BASE_MACHINE_GET_CLASS(machine); - BCM2838State *soc = &s->soc; + BCM2838State *soc = &s->soc4; s_base->binfo.modify_dtb = raspi4_modify_dtb; s_base->binfo.board_id = mc->board_rev; @@ -515,8 +509,7 @@ static const TypeInfo raspi_machine_types[] = { .class_init = raspi3b_machine_class_init, }, { .name = MACHINE_TYPE_NAME("raspi4"), - .parent = TYPE_RASPI_BASE_MACHINE, - .instance_size = sizeof(Raspi4bMachineState), + .parent = TYPE_RASPI_MACHINE, .class_init = raspi4b_machine_class_init, #endif /* TARGET_AARCH64 */ }, {
Merge Raspi4bMachineState within RaspiMachineState by using an unnamed union. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- hw/arm/raspi.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)