Patchwork [RFC,v1,16/20] i440fx-pmc: calculate PCI memory hole directly

login
register
mail settings
Submitter Hu Tao
Date May 22, 2013, 5:33 a.m.
Message ID <ef699a30f8d13bf3c7b9b96b7dfd2e8df329460d.1369193012.git.hutao@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/245539/
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    |  6 ------
 hw/pci-host/piix.c   | 49 ++++++++++++++++++++++++-------------------------
 include/hw/i386/pc.h |  4 ----
 3 files changed, 24 insertions(+), 35 deletions(-)

Patch

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 80e29d2..79747fa 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -138,12 +138,6 @@  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,
-                              below_4g_mem_size,
-                              0x100000000ULL - below_4g_mem_size,
-                              0x100000000ULL + above_4g_mem_size,
-                              (sizeof(hwaddr) == 4
-                               ? 0
-                               : ((uint64_t)1 << 62)),
                               pci_memory, ram_memory);
     } else {
         pci_bus = NULL;
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 1798060..c91607f 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -47,6 +47,9 @@ 
 #define XEN_PIIX_NUM_PIRQS      128ULL
 #define PIIX_PIRQC              0x60
 
+#define I440FX_PMC_PCI_HOLE       0xE0000000ULL
+#define I440FX_PMC_PCI_HOLE_END   0x100000000ULL
+
 /*
  * Reset Control Register: PCI-accessible ISA-Compatible Register at address
  * 0xcf9, provided by the PCI/ISA bridge (PIIX3 PCI function 0, 8086:7000).
@@ -106,10 +109,6 @@  struct I440FXPMCState {
     MemoryRegion smram_region;
     uint8_t smm_enabled;
     ram_addr_t ram_size;
-    hwaddr pci_hole_start;
-    hwaddr pci_hole_size;
-    hwaddr pci_hole64_start;
-    hwaddr pci_hole64_size;
 };
 
 #define TYPE_I440FX_DEVICE "i440FX"
@@ -285,21 +284,37 @@  static int i440fx_pmc_initfn(PCIDevice *dev)
 {
     I440FXPMCState *d = I440FX_PMC_DEVICE(dev);
     ram_addr_t ram_size;
+    hwaddr pci_hole_start, pci_hole_size;
+    hwaddr pci_hole64_start, pci_hole64_size;
     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) {
+        pci_hole_start = I440FX_PMC_PCI_HOLE;
+    } else {
+        pci_hole_start = d->ram_size;
+    }
+    pci_hole_size = I440FX_PMC_PCI_HOLE_END - pci_hole_start;
+
+    pci_hole64_start = I440FX_PMC_PCI_HOLE_END + d->ram_size - pci_hole_start;
+    if (sizeof(hwaddr) == 4) {
+        pci_hole64_size = 0;
+    } else {
+        pci_hole64_size = (1ULL << 62);
+    }
+
     memory_region_init_alias(&d->pci_hole, "pci-hole", d->pci_address_space,
-                             d->pci_hole_start, d->pci_hole_size);
-    memory_region_add_subregion(d->system_memory, d->pci_hole_start,
+                             pci_hole_start, pci_hole_size);
+    memory_region_add_subregion(d->system_memory, pci_hole_start,
                                 &d->pci_hole);
     memory_region_init_alias(&d->pci_hole_64bit, "pci-hole64",
                              d->pci_address_space,
-                             d->pci_hole64_start, d->pci_hole64_size);
-    if (d->pci_hole64_size) {
-        memory_region_add_subregion(d->system_memory, d->pci_hole64_start,
+                             pci_hole64_start, pci_hole64_size);
+    if (pci_hole64_size) {
+        memory_region_add_subregion(d->system_memory, pci_hole64_start,
                                     &d->pci_hole_64bit);
     }
     memory_region_init_alias(&d->smram_region, "smram-region",
@@ -336,10 +351,6 @@  static PCIBus *i440fx_common_init(const char *device_name,
                                   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_address_space,
                                   MemoryRegion *ram_memory)
 {
@@ -357,12 +368,6 @@  static PCIBus *i440fx_common_init(const char *device_name,
     piix3 = &i440fx->piix3;
     piix3->pic = pic;
 
-    /* FIXME these should be derived */
-    i440fx->pmc.pci_hole_start = pci_hole_start;
-    i440fx->pmc.pci_hole_size = pci_hole_size;
-    i440fx->pmc.pci_hole64_start = pci_hole64_start;
-    i440fx->pmc.pci_hole64_size = pci_hole64_size;
-
     f = &i440fx->pmc;
     f->ram_size = ram_size;
     f->system_memory = address_space_mem;
@@ -385,10 +390,6 @@  PCIBus *i440fx_init(int *piix3_devfn,
                     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)
 
 {
@@ -397,8 +398,6 @@  PCIBus *i440fx_init(int *piix3_devfn,
     b = i440fx_common_init(TYPE_I440FX_PMC_DEVICE,
                            piix3_devfn, isa_bus, pic,
                            address_space_mem, address_space_io, ram_size,
-                           pci_hole_start, pci_hole_size,
-                           pci_hole64_start, pci_hole64_size,
                            pci_memory, ram_memory);
     return b;
 }
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 99fef1c..0875295 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -127,10 +127,6 @@  PCIBus *i440fx_init(int *piix_devfn,
                     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);