On 18 October 2018 at 14:19, Philippe Mathieu-Daudé <phi...@redhat.com> wrote: > On 18/10/2018 15:08, Peter Maydell wrote: >> This field is the parent-type for the QOM object, so I don't >> think it makes sense for it to be a union. Any one QOM object >> should have a single distinct parent type. (There are other >> examples of "some more or less similar device has ISA and >> SysBus or PCI and SysBus variations" which should provide >> some models to copy from.
> So to avoid union, I have to use: > > typedef struct PVPanicCommonState { > MemoryRegion mr; > uint16_t ioport; > } PVPanicCommonState; > > typedef struct PVPanicISAState { > /*< private >*/ > ISADevice isadev; > > /*< public >*/ > PVPanicCommonState common; > } PVPanicISAState; > > #define PVPANIC_ISA(obj) \ > OBJECT_CHECK(PVPanicISAState, (obj), TYPE_PVPANIC) > > typedef struct PVPanicMMIOState { > /*< private >*/ > SysBusDevice busdev; > > /*< public >*/ > PVPanicCommonState common; > } PVPanicMMIOState; > > #define PVPANIC_MMIO(obj) \ > OBJECT_CHECK(PVPanicMMIOState, (obj), TYPE_PVPANIC) > Something like that, I think. Basically you have two distinct types, an ISA PVPanic and a SysBus PVPanic, which have straightforward inheritance (the ISA PVPanic is-a ISADevice, the SysBus PVPanic is-a SysBusdevice). Both have-a PVPanic common state. See eg hw/display/sm501.c, or hw/net/ne2000{,-isa}.c. thanks -- PMM