Patchwork [RFC,v1,17/20] i440fx-pmc: create pci address space

login
register
mail settings
Submitter Hu Tao
Date May 22, 2013, 5:33 a.m.
Message ID <a26eedbc3d7bfc37cd22d4e7115920be2b983cf5.1369193012.git.hutao@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/245540/
State New
Headers show

Comments

Hu Tao - May 22, 2013, 5:33 a.m.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 hw/i386/pc_piix.c    | 33 +++++++++++++++------------------
 hw/pci-host/piix.c   | 16 +++++++++-------
 include/hw/i386/pc.h |  2 +-
 3 files changed, 25 insertions(+), 26 deletions(-)

Patch

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 79747fa..2120dc6 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -109,23 +109,6 @@  static void pc_init1(MemoryRegion *system_memory,
         below_4g_mem_size = ram_size;
     }
 
-    if (pci_enabled) {
-        pci_memory = g_new(MemoryRegion, 1);
-        memory_region_init(pci_memory, "pci", INT64_MAX);
-        rom_memory = pci_memory;
-    } else {
-        pci_memory = NULL;
-        rom_memory = system_memory;
-    }
-
-    /* allocate ram and load rom/bios */
-    if (!xen_enabled()) {
-        fw_cfg = pc_memory_init(system_memory,
-                       kernel_filename, kernel_cmdline, initrd_filename,
-                       below_4g_mem_size, above_4g_mem_size,
-                       rom_memory, &ram_memory);
-    }
-
     gsi_state = g_malloc0(sizeof(*gsi_state));
     if (kvm_irqchip_in_kernel()) {
         kvm_pc_setup_irq_routing(pci_enabled);
@@ -138,7 +121,7 @@  static void pc_init1(MemoryRegion *system_memory,
     if (pci_enabled) {
         pci_bus = i440fx_init(&piix3_devfn, &isa_bus, gsi,
                               system_memory, system_io, ram_size,
-                              pci_memory, ram_memory);
+                              &pci_memory, ram_memory);
     } else {
         pci_bus = NULL;
         isa_bus = isa_bus_new(NULL, system_io);
@@ -146,6 +129,20 @@  static void pc_init1(MemoryRegion *system_memory,
     }
     isa_bus_irqs(isa_bus, gsi);
 
+    if (pci_enabled) {
+        rom_memory = pci_memory;
+    } else {
+        rom_memory = system_memory;
+    }
+
+    /* allocate ram and load rom/bios */
+    if (!xen_enabled()) {
+        fw_cfg = pc_memory_init(system_memory,
+                       kernel_filename, kernel_cmdline, initrd_filename,
+                       below_4g_mem_size, above_4g_mem_size,
+                       rom_memory, &ram_memory);
+    }
+
     if (kvm_irqchip_in_kernel()) {
         i8259 = kvm_i8259_init(isa_bus);
     } else if (xen_enabled()) {
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index c91607f..7246265 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -118,7 +118,7 @@  struct I440FXPMCState {
 typedef struct I440FXState {
     PCIHostState parent_obj;
     MemoryRegion *address_space_io;
-    MemoryRegion *pci_address_space;
+    MemoryRegion pci_address_space;
 
     PIIX3State piix3;
     I440FXPMCState pmc;
@@ -227,7 +227,7 @@  static int i440fx_realize(SysBusDevice *dev)
     PCIHostState *s = PCI_HOST_BRIDGE(dev);
     I440FXState *f = I440FX_DEVICE(dev);
 
-    s->bus = pci_bus_new(DEVICE(f), NULL, f->pci_address_space,
+    s->bus = pci_bus_new(DEVICE(f), NULL, &f->pci_address_space,
                          f->address_space_io, 0, TYPE_PCI_BUS);
 
     memory_region_init_io(&s->conf_mem, &pci_host_conf_le_ops, s,
@@ -252,6 +252,8 @@  static int i440fx_realize(SysBusDevice *dev)
         pci_bus_set_route_irq_fn(s->bus, piix3_route_intx_pin_to_irq);
     }
 
+    f->pmc.pci_address_space = &f->pci_address_space;
+
     qdev_set_parent_bus(DEVICE(&f->pmc), BUS(s->bus));
     qdev_init_nofail(DEVICE(&f->pmc));
 
@@ -278,6 +280,8 @@  static void i440fx_initfn(Object *obj)
     object_initialize(&f->pmc, TYPE_I440FX_PMC_DEVICE);
     object_property_add_child(obj, "pmc", OBJECT(&f->pmc), NULL);
     qdev_prop_set_uint32(DEVICE(&f->pmc), "addr", PCI_DEVFN(0, 0));
+
+    memory_region_init(&f->pci_address_space, "pci", INT64_MAX);
 }
 
 static int i440fx_pmc_initfn(PCIDevice *dev)
@@ -289,7 +293,6 @@  static int i440fx_pmc_initfn(PCIDevice *dev)
     int i;
 
     g_assert(d->system_memory != NULL);
-    g_assert(d->pci_address_space != NULL);
     g_assert(d->ram_memory != NULL);
 
     if(d->ram_size > I440FX_PMC_PCI_HOLE) {
@@ -351,7 +354,7 @@  static PCIBus *i440fx_common_init(const char *device_name,
                                   MemoryRegion *address_space_mem,
                                   MemoryRegion *address_space_io,
                                   ram_addr_t ram_size,
-                                  MemoryRegion *pci_address_space,
+                                  MemoryRegion **pci_address_space,
                                   MemoryRegion *ram_memory)
 {
     PCIHostState *s;
@@ -363,7 +366,6 @@  static PCIBus *i440fx_common_init(const char *device_name,
     s = PCI_HOST_BRIDGE(i440fx);
 
     i440fx->address_space_io = address_space_io;
-    i440fx->pci_address_space = pci_address_space;
 
     piix3 = &i440fx->piix3;
     piix3->pic = pic;
@@ -371,7 +373,6 @@  static PCIBus *i440fx_common_init(const char *device_name,
     f = &i440fx->pmc;
     f->ram_size = ram_size;
     f->system_memory = address_space_mem;
-    f->pci_address_space = pci_address_space;
     f->ram_memory = ram_memory;
 
     object_property_add_child(qdev_get_machine(), "i440fx",
@@ -381,6 +382,7 @@  static PCIBus *i440fx_common_init(const char *device_name,
 
     *isa_bus = piix3->bus;
     *piix3_devfn = piix3->dev.devfn;
+    *pci_address_space = &i440fx->pci_address_space;
 
     return s->bus;
 }
@@ -390,7 +392,7 @@  PCIBus *i440fx_init(int *piix3_devfn,
                     MemoryRegion *address_space_mem,
                     MemoryRegion *address_space_io,
                     ram_addr_t ram_size,
-                    MemoryRegion *pci_memory, MemoryRegion *ram_memory)
+                    MemoryRegion **pci_memory, MemoryRegion *ram_memory)
 
 {
     PCIBus *b;
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 0875295..c733e68 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -127,7 +127,7 @@  PCIBus *i440fx_init(int *piix_devfn,
                     MemoryRegion *address_space_mem,
                     MemoryRegion *address_space_io,
                     ram_addr_t ram_size,
-                    MemoryRegion *pci_memory,
+                    MemoryRegion **pci_memory,
                     MemoryRegion *ram_memory);
 
 /* piix4.c */