refactor PC machine, i440fx and piix3 to take advantage of QOM
v5 cover refactor PC machine, i440fx and piix3 to take advantage of QOM
This series aggressively refactors the PC machine initialization to be more modelled and less ad-hoc. The highlights of this series are:
1) Things like -m and -bios-name are now device model properties
2) The i440fx and piix3 are now modelled in a thorough fashion
3) i440fx_init is trivialized to creating devices and setting properties
4) convert PCI host bridge to QOM
The point (3) is the most important one. As we refactor in this fashion, we should quickly get to the point where machine->init disappears completely in favor of just creating a handful of devices.
The two stage initialization of QOM is important here. instance_init() is when composed devices are created which means that after you've created a device, all of its children are visible in the device model. This lets you set properties of the parent and its children.
realize() (which is still called DeviceState::init today) will be called right before the guest starts up for the first time.
Change in v5:
* drop patch "convert MemoryRegion to QOM" and "prepare to create HPET, RTC and i8254 through composition"
* add Andreas' recent attempt against pci_host
Change in v4:
*rebase patchset
Changes in v3:
* fix coding style issues
* fix rebase error
* add changes log
Changes in v2:
* Rebase patch series of i440fx in Anthony's qom-rebase.12 branch to upstream
* convert MemoryRegion to QOM
* convert pci_host to QOM
Anthony Liguori (3):
eliminate piix_pci.c and module i440fx and piix3 merge pc_piix.c to pc.c
convert pci-host to QOM
hw/i386/Makefile.objs | 3 +- hw/i440fx.c | 434 ++++++++++++++++++++++++++++++ hw/i440fx.h | 77 ++++++ hw/pc.c | 695 +++++++++++++++++++++++++++++++++++++++++++++---- hw/pc.h | 46 +--- hw/pc_piix.c | 661 ---------------------------------------------- hw/pci_host.c | 14 + hw/pci_host.h | 2 + hw/piix3.c | 234 +++++++++++++++++ hw/piix3.h | 69 +++++ hw/piix_pci.c | 599 ------------------------------------------ 11 files changed, 1481 insertions(+), 1353 deletions(-) create mode 100644 hw/i440fx.c create mode 100644 hw/i440fx.h delete mode 100644 hw/pc_piix.c create mode 100644 hw/piix3.c create mode 100644 hw/piix3.h delete mode 100644 hw/piix_pci.c
Signature · 1 line
1.7.7.6
PATCH v5 3/3 convert pci-host to QOM
From: Anthony Liguori <[email protected]>
makes pci_host a proper QOM type.
Changelog:
* against Andreas pci_host branch
* make host bridge TypeInfos const
* use PCI_HOST_BRIDGE() where appropriate
--- hw/i440fx.c | 6 +++--- hw/pc.c | 2 +- hw/pci_host.c | 14 ++++++++++++++ hw/pci_host.h | 2 ++ hw/piix3.c | 4 ++-- 5 files changed, 22 insertions(+), 6 deletions(-)
hw/i440fx.c +3 -3
@@ -191,7 +191,7 @@ static const VMStateDescription vmstate_i440fx_pmc = {static int i440fx_realize (SysBusDevice *dev) {I440FXState *s =I440FX (dev); -PCIHostState *h =PCI_HOST (s); +PCIHostState *h =PCI_HOST_BRIDGE (s);int bios_size, isa_bios_size;char *filename;int ret;
@@ -401,7 +401,7 @@ static void i440fx_pmc_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_i440fx_pmc; } -static TypeInfo i440fx_pmc_info = { +static const TypeInfo i440fx_pmc_info = { .name =TYPE_I440FX_PMC , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (I440FXPMCState),
@@ -418,7 +418,7 @@ static void i440fx_class_init(ObjectClass *klass, void *data) dc->no_user =1 ; } -static TypeInfo i440fx_info = { +static const TypeInfo i440fx_info = { .name =TYPE_I440FX , .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (I440FXState),
hw/pc.c +1 -1
@@ -1217,7 +1217,7 @@ static PCIBus *i440fx_init(I440FXPMCState **pi440fx_state, int *piix3_devfn,PCIHostState *h; s =I440FX (object_new (TYPE_I440FX )); - h =PCI_HOST (s); + h =PCI_HOST_BRIDGE (s);/* FIXME make a properties */ h->address_space = address_space_mem;
hw/pci_host.c +14 -0
@@ -165,11 +165,25 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +void pci_host_set_mmio (PCIHostState *s,MemoryRegion *value) +{ +object_property_set_link (OBJECT (s),OBJECT (value),"mmio" ,NULL ); +} + +static void pci_host_initfn (Object *obj) +{ +PCIHostState *s =PCI_HOST_BRIDGE (obj); + +object_property_add_link (obj,"mmio" ,"memory-region" , + (Object **)&s->address_space,NULL ); +} +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .abstract = true, .instance_size =sizeof (PCIHostState), + .instance_init = pci_host_initfn, };static void pci_host_register_types (void )
hw/pci_host.h +2 -0
@@ -54,6 +54,8 @@ uint32_t pci_host_config_read_common(PCIDevice *pci_dev, uint32_t addr,void pci_data_write (PCIBus *s,uint32_t addr,uint32_t val,int len);uint32_t pci_data_read (PCIBus *s,uint32_t addr,int len); +void pci_host_set_mmio (PCIHostState *s,MemoryRegion *value); +extern const MemoryRegionOps pci_host_conf_le_ops;extern const MemoryRegionOps pci_host_conf_be_ops;extern const MemoryRegionOps pci_host_data_le_ops;
hw/piix3.c +2 -2
@@ -204,7 +204,7 @@ static void piix3_class_init(ObjectClass *klass, void *data) k->class_id =PCI_CLASS_BRIDGE_ISA ; } -static TypeInfo piix3_info = { +static const TypeInfo piix3_info = { .name =TYPE_PIIX3 , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PIIX3State),
@@ -219,7 +219,7 @@ static void piix3_xen_class_init(ObjectClass *klass, void *data) k->config_write = piix3_write_config_xen; }; -static TypeInfo piix3_xen_info = { +static const TypeInfo piix3_xen_info = { .name ="PIIX3-xen" , .parent =TYPE_PIIX3 , .instance_size =sizeof (PIIX3State),
Signature · 1 line
1.7.5.4
PATCH v5 1/3 eliminate piix_pci.c and module i440fx and piix3
In reply to Wanpeng LiFrom: Anthony Liguori <[email protected]>
The big picture about the patch is shown as follows:
1) pc_init creates an I440FX, any bus devices (ISA serial port, PCI vga and nics, etc.), sets properties appropriately, and realizes the
devices.
2) I440FX is-a PCIHost, has-a I440FX-PMC, has-a PIIX3
3) PIIX3 has-a RTC, has-a I8042, has-a DMAController, etc.
i440fx-pcihost => i440fx
i440fx => i440fx-pmc
i440fx_pmc is Programmable Memory Controller which integrated in I440FX chipset, and move ram initialization into i440fx-pmc.
It might seem like a small change, but it better reflects the fact that the PMC is contained within the i440fx which we will now reflect in composition in the next few changesets.
--- hw/i386/Makefile.objs | 2 +- hw/i440fx.c | 434 +++++++++++++++++++++++++++++++++++ hw/i440fx.h | 77 +++++++ hw/piix3.c | 234 +++++++++++++++++++ hw/piix3.h | 69 ++++++ hw/piix_pci.c | 599 ------------------------------------------------- 6 files changed, 815 insertions(+), 600 deletions(-) create mode 100644 hw/i440fx.c create mode 100644 hw/i440fx.h create mode 100644 hw/piix3.c create mode 100644 hw/piix3.h delete mode 100644 hw/piix_pci.c
hw/i386/Makefile.objs +1 -1
@@ -1,6 +1,6 @@ obj-y += mc146818rtc.o pc.o obj-y += apic_common.o apic.o kvmvapic.o -obj-y += sga.o ioapic_common.o ioapic.o piix_pci.o +obj-y += sga.o ioapic_common.o ioapic.o i440fx.o piix3.o obj-y += vmport.o obj-y += pci-hotplug.o smbios.o wdt_ib700.o obj-y += debugcon.o multiboot.o
hw/i440fx.c new file +434 -0
434 lines not on this page · raw message
hw/i440fx.h new file +77 -0
77 lines not on this page · raw message
hw/piix3.c new file +234 -0
234 lines not on this page · raw message
hw/piix3.h new file +69 -0
69 lines not on this page · raw message
hw/piix_pci.c deleted +0 -599
599 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH v5 2/3 merge pc_piix.c to pc.c
In reply to Wanpeng LiFrom: Anthony Liguori <[email protected]>
--- hw/i386/Makefile.objs | 1 - hw/pc.c | 695 +++++++++++++++++++++++++++++++++++++++++++++---- hw/pc.h | 46 +--- hw/pc_piix.c | 661 ---------------------------------------------- 4 files changed, 650 insertions(+), 753 deletions(-) delete mode 100644 hw/pc_piix.c
hw/i386/Makefile.objs +0 -1
@@ -4,7 +4,6 @@ obj-y += sga.o ioapic_common.o ioapic.o i440fx.o piix3.o obj-y += vmport.o obj-y += pci-hotplug.o smbios.o wdt_ib700.o obj-y += debugcon.o multiboot.o -obj-y += pc_piix.o obj-y += pc_sysfw.o obj-$(CONFIG_XEN) += xen_platform.o xen_apic.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
hw/pc.c +646 -49
794 lines not on this page · raw message
hw/pc.h +4 -42
70 lines not on this page · raw message
hw/pc_piix.c deleted +0 -661
661 lines not on this page · raw message
Signature · 1 line
1.7.7.6
Re: [Qemu-devel] [PATCH v5 3/3] convert pci-host to QOM
In reply to Wanpeng LiAm 23.07.2012 14:35, schrieb Wanpeng Li:
Quoted 25 lines
From: Anthony Liguori <[email protected]>
makes
pci_hosta proper QOM type.Changelog:
* against Andreaspci_hostbranch
* make host bridge TypeInfos const
* usePCI_HOST_BRIDGE()where appropriateSigned-off-by Anthony Liguori <[email protected]>Signed-off-by Wanpeng Li <[email protected]>--- hw/i440fx.c | 6 +++--- hw/pc.c | 2 +- hw/pci_host.c | 14 ++++++++++++++ hw/pci_host.h | 2 ++ hw/piix3.c | 4 ++-- 5 files changed, 22 insertions(+), 6 deletions(-)hw/i440fx.c +0
-0
hw/i440fx.c static const VMStateDescription vmstate_i440fx_pmc = { · line 197
Quoted 8 lines
hw/i440fx.c +1
-1@@ -191,7 +191,7 @@ static const VMStateDescription vmstate_i440fx_pmc = {static int i440fx_realize (SysBusDevice *dev) {I440FXState *s =I440FX (dev); -PCIHostState *h =PCI_HOST (s); +PCIHostState *h =PCI_HOST_BRIDGE (s);int bios_size, isa_bios_size;char *filename;int ret;
Either there's a miscommunication or a technical error: My branch surely is using PCI_HOST_BRIDGE(), so these PCI_HOST -> PCI_HOST_BRIDGE changes look bogus. Did you make sure each patch compiles?
Quoted 10 lines
hw/i440fx.c +1
-1@@ -401,7 +401,7 @@ static void i440fx_pmc_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_i440fx_pmc; } -static TypeInfo i440fx_pmc_info = { +static const TypeInfo i440fx_pmc_info = { .name =TYPE_I440FX_PMC , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (I440FXPMCState),
hw/i440fx.c static void i440fx_class_init(ObjectClass *klass, void *data) · line 424
Quoted 8 lines
hw/i440fx.c +1
-1@@ -418,7 +418,7 @@ static void i440fx_class_init(ObjectClass *klass, void *data) dc->no_user =1 ; } -static TypeInfo i440fx_info = { +static const TypeInfo i440fx_info = { .name =TYPE_I440FX , .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (I440FXState),
Patch 1/3 does not have const, patch 2/3 adds new TypeInfos without const.
So my guess is you've not rebased this on my pci-host branch [1] but onto something else? If they're not against master it's advisable to mark patches [PATCH treename xx/nn] btw, for clarity.
For the new/changed TypeInfos please add const from the start.
Regards,
Andreas
[1] http://repo.or.cz/w/qemu/afaerber.git/shortlog/refs/heads/pci-hostgit://repo.or.cz/qemu/afaerber.git pci-host
Quoted 79 lines
hw/pc.c +1
-1@@ -1217,7 +1217,7 @@ static PCIBus *i440fx_init(I440FXPMCState **pi440fx_state, int *piix3_devfn,PCIHostState *h; s =I440FX (object_new (TYPE_I440FX )); - h =PCI_HOST (s); + h =PCI_HOST_BRIDGE (s);/* FIXME make a properties */ h->address_space = address_space_mem;hw/pci_host.c +14
-0@@ -165,11 +165,25 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +void pci_host_set_mmio (PCIHostState *s,MemoryRegion *value) +{ +object_property_set_link (OBJECT (s),OBJECT (value),"mmio" ,NULL ); +} + +static void pci_host_initfn (Object *obj) +{ +PCIHostState *s =PCI_HOST_BRIDGE (obj); + +object_property_add_link (obj,"mmio" ,"memory-region" , + (Object **)&s->address_space,NULL ); +} +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .abstract = true, .instance_size =sizeof (PCIHostState), + .instance_init = pci_host_initfn, };static void pci_host_register_types (void )hw/pci_host.h +2
-0@@ -54,6 +54,8 @@ uint32_t pci_host_config_read_common(PCIDevice *pci_dev, uint32_t addr,void pci_data_write (PCIBus *s,uint32_t addr,uint32_t val,int len);uint32_t pci_data_read (PCIBus *s,uint32_t addr,int len); +void pci_host_set_mmio (PCIHostState *s,MemoryRegion *value); +extern const MemoryRegionOps pci_host_conf_le_ops;extern const MemoryRegionOps pci_host_conf_be_ops;extern const MemoryRegionOps pci_host_data_le_ops;hw/piix3.c +2
-2@@ -204,7 +204,7 @@ static void piix3_class_init(ObjectClass *klass, void *data) k->class_id =PCI_CLASS_BRIDGE_ISA ; } -static TypeInfo piix3_info = { +static const TypeInfo piix3_info = { .name =TYPE_PIIX3 , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PIIX3State),@@ -219,7 +219,7 @@ static void piix3_xen_class_init(ObjectClass *klass, void *data) k->config_write = piix3_write_config_xen; }; -static TypeInfo piix3_xen_info = { +static const TypeInfo piix3_xen_info = { .name ="PIIX3-xen" , .parent =TYPE_PIIX3 , .instance_size =sizeof (PIIX3State),
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH v5 3/3] convert pci-host to QOM
Quoted 30 lines · Andreas Färber
Am 23.07.2012 14:35, schrieb Wanpeng Li:
Quoted 29 lines
From: Anthony Liguori <[email protected]>
makes
pci_hosta proper QOM type.Changelog:
* against Andreaspci_hostbranch
* make host bridge TypeInfos const
* usePCI_HOST_BRIDGE()where appropriateSigned-off-by Anthony Liguori <[email protected]>Signed-off-by Wanpeng Li <[email protected]>--- hw/i440fx.c | 6 +++--- hw/pc.c | 2 +- hw/pci_host.c | 14 ++++++++++++++ hw/pci_host.h | 2 ++ hw/piix3.c | 4 ++-- 5 files changed, 22 insertions(+), 6 deletions(-)hw/i440fx.c +0
-1@@ -191,7 +191,7 @@ static const VMStateDescription vmstate_i440fx_pmc = {static int i440fx_realize (SysBusDevice *dev) {I440FXState *s =I440FX (dev); -PCIHostState *h =PCI_HOST (s);
Quoted 8 lines
hw/i440fx.c static const VMStateDescription vmstate_i440fx_pmc = { · line 197
Quoted 4 lines
hw/i440fx.c +1
-0+PCIHostState *h =PCI_HOST_BRIDGE (s);int bios_size, isa_bios_size;char *filename;int ret;Either there's a miscommunication or a technical error: My branch surely is using
PCI_HOST_BRIDGE(), so thesePCI_HOST->PCI_HOST_BRIDGEchanges look bogus. Did you make sure each patch compiles?
The third patch against your pci-host branch which you hope to, the three patches can overall compile success, but not each patch compile success. Because PATCH 1/3 should take advantage of PCI_HOST_BRIDGE(), and PATCH 2/3 also should take advantage of PATCH 1/3.
Quoted 14 lines
Quoted 14 lines
hw/i440fx.c +1
-1@@ -401,7 +401,7 @@ static void i440fx_pmc_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_i440fx_pmc; } -static TypeInfo i440fx_pmc_info = { +static const TypeInfo i440fx_pmc_info = { .name =TYPE_I440FX_PMC , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (I440FXPMCState),@@ -418,7 +418,7 @@ static void i440fx_class_init(ObjectClass *klass, void *data) dc->no_user =1 ; }
Quoted 7 lines
hw/i440fx.c static void i440fx_class_init(ObjectClass *klass, void *data) · line 424
Quoted 5 lines
hw/i440fx.c +1
-1-static TypeInfo i440fx_info = { +static const TypeInfo i440fx_info = { .name =TYPE_I440FX , .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (I440FXState),Patch 1/3 does not have const, patch 2/3 adds new TypeInfos without const.
Patch 2/3 doesn't add any new TypeInfos, where you see the new TypeInfos you mentioned.
Quoted 3 lines
So my guess is you've not rebased this on my pci-host branch [1] but
No, I rebase the third patch against your pci_host branch. Since your patch
pci: Derive PCI host bridges from TYPE_PCI_HOST_BRIDGE Some typedef'ed their state to PCIHostState. Use a proper struct, and use PCIHostState and PCI_HOST_BRIDGE() where appropriate.
want to use PCI_HOST_BRIDGE() where appropriate, so I add them to Patch 1/3 codes.
Regards,
Wanpeng Li
Quoted 97 lines
onto something else? If they're not against master it's advisable to mark patches [PATCH treename xx/nn] btw, for clarity.
For the new/changed TypeInfos please add const from the start.
Regards,
Andreas[1] http://repo.or.cz/w/qemu/afaerber.git/shortlog/refs/heads/pci-host
git://repo.or.cz/qemu/afaerber.gitpci-hostQuoted 79 lines
hw/pc.c +1
-1@@ -1217,7 +1217,7 @@ static PCIBus *i440fx_init(I440FXPMCState **pi440fx_state, int *piix3_devfn,PCIHostState *h; s =I440FX (object_new (TYPE_I440FX )); - h =PCI_HOST (s); + h =PCI_HOST_BRIDGE (s);/* FIXME make a properties */ h->address_space = address_space_mem;hw/pci_host.c +14
-0@@ -165,11 +165,25 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +void pci_host_set_mmio (PCIHostState *s,MemoryRegion *value) +{ +object_property_set_link (OBJECT (s),OBJECT (value),"mmio" ,NULL ); +} + +static void pci_host_initfn (Object *obj) +{ +PCIHostState *s =PCI_HOST_BRIDGE (obj); + +object_property_add_link (obj,"mmio" ,"memory-region" , + (Object **)&s->address_space,NULL ); +} +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .abstract = true, .instance_size =sizeof (PCIHostState), + .instance_init = pci_host_initfn, };static void pci_host_register_types (void )hw/pci_host.h +2
-0@@ -54,6 +54,8 @@ uint32_t pci_host_config_read_common(PCIDevice *pci_dev, uint32_t addr,void pci_data_write (PCIBus *s,uint32_t addr,uint32_t val,int len);uint32_t pci_data_read (PCIBus *s,uint32_t addr,int len); +void pci_host_set_mmio (PCIHostState *s,MemoryRegion *value); +extern const MemoryRegionOps pci_host_conf_le_ops;extern const MemoryRegionOps pci_host_conf_be_ops;extern const MemoryRegionOps pci_host_data_le_ops;hw/piix3.c +2
-2@@ -204,7 +204,7 @@ static void piix3_class_init(ObjectClass *klass, void *data) k->class_id =PCI_CLASS_BRIDGE_ISA ; } -static TypeInfo piix3_info = { +static const TypeInfo piix3_info = { .name =TYPE_PIIX3 , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PIIX3State),@@ -219,7 +219,7 @@ static void piix3_xen_class_init(ObjectClass *klass, void *data) k->config_write = piix3_write_config_xen; }; -static TypeInfo piix3_xen_info = { +static const TypeInfo piix3_xen_info = { .name ="PIIX3-xen" , .parent =TYPE_PIIX3 , .instance_size =sizeof (PIIX3State),Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg