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.
Changes in v5:
* fix bisect issues
* take advantage of Andreas's pci_host patchset
* drop convert MemoryRegion to QOM
* drop prepare to create HPET, RTC and i8254 through composition
Changes 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 | 76 +++++ hw/pc.c | 753 ++++++++++++++++++++++++++++++++++++++++++++++--- hw/pc.h | 41 +--- hw/pc_piix.c | 716 ---------------------------------------------- hw/pci_host.c | 9 + hw/piix3.c | 258 +++++++++++++++++ hw/piix3.h | 73 +++++ hw/piix_pci.c | 622 ---------------------------------------- 10 files changed, 1558 insertions(+), 1427 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 1/3 eliminate piix_pci.c and module i440fx and piix3
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
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 | 76 ++++++ hw/pc.c | 39 +--- hw/pc.h | 20 +-- hw/pc_piix.c | 52 +++-- hw/piix3.c | 258 ++++++++++++++++++++ hw/piix3.h | 73 ++++++ hw/piix_pci.c | 622 ------------------------------------------------- 9 files changed, 882 insertions(+), 694 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 +76 -0
76 lines not on this page · raw message
hw/pc.c +1 -38
@@ -882,50 +882,13 @@ void *pc_memory_init(MemoryRegion *system_memory,const char *kernel_cmdline, const char *initrd_filename, ram_addr_t below_4g_mem_size, - ram_addr_t above_4g_mem_size, - MemoryRegion *rom_memory, - MemoryRegion **ram_memory) + ram_addr_t above_4g_mem_size) { int linux_boot, i; -MemoryRegion *ram, *option_rom_mr; -MemoryRegion *ram_below_4g, *ram_above_4g;void *fw_cfg; linux_boot = (kernel_filename !=NULL ); -/* Allocate RAM. We allocate it as a single memory region and use -* aliases to address portions of it, mostly for backwards compatibility -* with older qemus that used qemu_ram_alloc(). -*/ - ram =g_malloc (sizeof (*ram)); -memory_region_init_ram (ram,"pc.ram" , - below_4g_mem_size + above_4g_mem_size); -vmstate_register_ram_global (ram); - *ram_memory = ram; - ram_below_4g =g_malloc (sizeof (*ram_below_4g)); -memory_region_init_alias (ram_below_4g,"ram-below-4g" , ram, -0 , below_4g_mem_size); -memory_region_add_subregion (system_memory,0 , ram_below_4g); -if (above_4g_mem_size >0 ) { - ram_above_4g =g_malloc (sizeof (*ram_above_4g)); -memory_region_init_alias (ram_above_4g,"ram-above-4g" , ram, - below_4g_mem_size, above_4g_mem_size); -memory_region_add_subregion (system_memory,0x100000000ULL , - ram_above_4g); - } - - -/* Initialize PC system firmware */ -pc_system_firmware_init (rom_memory); - - option_rom_mr =g_malloc (sizeof (*option_rom_mr)); -memory_region_init_ram (option_rom_mr,"pc.rom" ,PC_ROM_SIZE ); -vmstate_register_ram_global (option_rom_mr); -memory_region_add_subregion_overlap (rom_memory, -PC_ROM_MIN_VGA , - option_rom_mr, -1 ); - fw_cfg =bochs_bios_init ();rom_set_fw (fw_cfg);
hw/pc.h +1 -19
@@ -84,9 +84,7 @@ void *pc_memory_init(MemoryRegion *system_memory,const char *kernel_cmdline, const char *initrd_filename, ram_addr_t below_4g_mem_size, - ram_addr_t above_4g_mem_size, - MemoryRegion *rom_memory, - MemoryRegion **ram_memory); + ram_addr_t above_4g_mem_size);qemu_irq *pc_allocate_cpu_irq (void );DeviceState *pc_vga_init (ISABus *isa_bus,PCIBus *pci_bus); void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
@@ -121,22 +119,6 @@ void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr);/* hpet.c */ extern int no_hpet; -/* piix_pci.c */ -struct PCII440FXState ; -typedef struct PCII440FXState PCII440FXState ; - -PCIBus *i440fx_init (PCII440FXState **pi440fx_state,int *piix_devfn, -ISABus **isa_bus,qemu_irq *pic, -MemoryRegion *address_space_mem, -MemoryRegion *address_space_io, -ram_addr_t ram_size, -hwaddr pci_hole_start, -hwaddr pci_hole_size, -hwaddr pci_hole64_start, -hwaddr pci_hole64_size, -MemoryRegion *pci_memory, -MemoryRegion *ram_memory); -/* piix4.c */ extern PCIDevice *piix4_dev;int piix4_init (PCIBus *bus,ISABus **isa_bus,int devfn);
hw/pc_piix.c +38 -14
97 lines not on this page · raw message
hw/piix3.c new file +258 -0
258 lines not on this page · raw message
hw/piix3.h new file +73 -0
73 lines not on this page · raw message
hw/piix_pci.c deleted +0 -622
622 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 LiA long time ago, there was a grand plan to merge q35 chipset support. The start of that series was a refactoring of pc.c which split a bunch of the "common" functionality into a separate file that could be shared by the two.
But q35 never got merged and the refactoring, in retrospect, just made things worse. Making things proper objects and using composition is the right way to share common devices.
By pulling these files back together, we can start to fix some of this mess.
--- hw/i386/Makefile.objs | 1 - hw/pc.c | 714 ++++++++++++++++++++++++++++++++++++++++++++++- hw/pc.h | 23 +-- hw/pc_piix.c | 740 ------------------------------------------------- 4 files changed, 706 insertions(+), 772 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 +705 -9
792 lines not on this page · raw message
hw/pc.h +1 -22
@@ -9,6 +9,7 @@#include "net.h" #include "memory.h" #include "ioapic.h" +#include "i440fx.h" /* PC-style peripherals (also used by other machines). */
@@ -52,8 +53,6 @@ typedef struct GSIState {qemu_irq ioapic_irq[IOAPIC_NUM_PINS ]; } GSIState; -void gsi_handler (void *opaque,int n,int level); -/* vmport.c */ static inline void vmport_init (ISABus *bus) {
@@ -75,28 +74,8 @@ void i8042_setup_a20_line(ISADevice *dev, qemu_irq *a20_out);/* pc.c */ extern int fd_bootchk; -void pc_register_ferr_irq (qemu_irq irq);void pc_acpi_smi_interrupt (void *opaque,int irq,int level); -void pc_cpus_init (const char *cpu_model); -void *pc_memory_init (MemoryRegion *system_memory, -const char *kernel_filename, -const char *kernel_cmdline, -const char *initrd_filename, -ram_addr_t below_4g_mem_size, -ram_addr_t above_4g_mem_size); -qemu_irq *pc_allocate_cpu_irq (void ); -DeviceState *pc_vga_init (ISABus *isa_bus,PCIBus *pci_bus); -void pc_basic_device_init (ISABus *isa_bus,qemu_irq *gsi, -ISADevice **rtc_state, -ISADevice **floppy, -bool no_vmport); -void pc_init_ne2k_isa (ISABus *bus,NICInfo *nd); -void pc_cmos_init (ram_addr_t ram_size,ram_addr_t above_4g_mem_size, -const char *boot_device, -ISADevice *floppy,BusState *ide0,BusState *ide1, -ISADevice *s); -void pc_pci_device_init (PCIBus *pci_bus);typedef void (*cpu_set_smm_t )(int smm,void *arg);void cpu_smm_register (cpu_set_smm_t callback,void *arg);
hw/pc_piix.c deleted +0 -740
740 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH v5 3/3 convert pci-host to QOM
In reply to Wanpeng LiTake advantage of Andreas's pci-host patchset, add instance_init function to fully implement convert pci-host to QOM.
--- hw/pci_host.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
hw/pci_host.c +9 -0
@@ -165,11 +165,20 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +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 )
Signature · 1 line
1.7.7.6
Re: [Qemu-devel] [PATCH v5 3/3] convert pci-host to QOM
Am 08.11.2012 06:36, schrieb Wanpeng Li:
Quoted 14 lines
Take advantage of Andreas's pci-host patchset, add
instance_initfunction to fully implement convert pci-host to QOM.Signed-off-by Anthony Liguori <[email protected]>Signed-off-by Wanpeng Li <[email protected]>--- hw/pci_host.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)hw/pci_host.c +0
-0
hw/pci_host.c const MemoryRegionOps pci_host_data_be_ops = { · line 173
Quoted 9 lines
hw/pci_host.c +6
-0@@ -165,11 +165,20 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +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 );
This strikes me as wrong, unless I've overlooked something in the previous patches. Also the commit message seems outdated.
Please cc me on the next version, I received no response to my question about i440fx status and just noticed this now.
Regards,
Andreas
Quoted 11 lines
hw/pci_host.c +3
-0+} +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 )
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
Quoted 15 lines · Wanpeng Li
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_initis trivialized to creating devices and setting properties4) 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->initdisappears completely in favor of just creating a handful of devices.
Quoted 8 lines
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 calledDeviceState::inittoday) will be called right before the guest starts up for the first time.
Hi Anthony,
What's the state of these two patchsets, are they ready to be merged?
Regards,
Wanpeng Li
Quoted 47 lines
Changes in v5:
* fix bisect issues
* take advantage of Andreas'spci_hostpatchset
* drop convert MemoryRegion to QOM
* drop prepare to create HPET, RTC and i8254 through compositionChanges in v4:
*rebase patchset
Changes in v3:
* fix coding style issues
* fix rebase error
* add changes logChanges in v2:
* Rebase patch series of i440fx in Anthony's qom-rebase.12 branch to upstream
* convert MemoryRegion to QOM
* convertpci_hostto QOMAnthony Liguori (3):
eliminatepiix_pci.cand module i440fx and piix3
mergepc_piix.ctopc.c
convert pci-host to QOMhw/i386/Makefile.objs | 3 +- hw/i440fx.c | 434 ++++++++++++++++++++++++++++ hw/i440fx.h | 76 +++++ hw/pc.c | 753 ++++++++++++++++++++++++++++++++++++++++++++++--- hw/pc.h | 41 +--- hw/pc_piix.c | 716 ---------------------------------------------- hw/pci_host.c | 9 + hw/piix3.c | 258 +++++++++++++++++ hw/piix3.h | 73 +++++ hw/piix_pci.c | 622 ---------------------------------------- 10 files changed, 1558 insertions(+), 1427 deletions(-)create mode 100644
hw/i440fx.c
create mode 100644hw/i440fx.h
delete mode 100644hw/pc_piix.c
create mode 100644hw/piix3.c
create mode 100644hw/piix3.h
delete mode 100644hw/piix_pci.cSignature · 1 line
1.7.7.6