Patchwork [v3,05/16] pc: improve bus implementation of PIIX3 bridge

login
register
mail settings
Submitter Hervé Poussineau
Date Oct. 2, 2011, 4:10 p.m.
Message ID <1317571828-9059-6-git-send-email-hpoussin@reactos.org>
Download mbox | patch
Permalink /patch/117334/
State New
Headers show

Comments

Hervé Poussineau - Oct. 2, 2011, 4:10 p.m.
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/pc.h       |    2 +-
 hw/pc_piix.c  |    3 ++-
 hw/piix_pci.c |   45 ++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 43 insertions(+), 7 deletions(-)

Patch

diff --git a/hw/pc.h b/hw/pc.h
index c546037..746973f 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -181,7 +181,7 @@  struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
-                    qemu_irq *pic,
+                    ISABus **isa_bus,
                     MemoryRegion *address_space_mem,
                     MemoryRegion *address_space_io,
                     ram_addr_t ram_size,
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index f971d52..7ccbfca 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -84,6 +84,7 @@  static void pc_init1(MemoryRegion *system_memory,
     int i;
     ram_addr_t below_4g_mem_size, above_4g_mem_size;
     PCIBus *pci_bus;
+    ISABus *isa_bus;
     PCII440FXState *i440fx_state;
     int piix3_devfn = -1;
     qemu_irq *cpu_irq;
@@ -134,7 +135,7 @@  static void pc_init1(MemoryRegion *system_memory,
     isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
 
     if (pci_enabled) {
-        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq,
+        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, &isa_bus,
                               system_memory, system_io, ram_size,
                               below_4g_mem_size,
                               0x100000000ULL - below_4g_mem_size,
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index 287bd19..76464f6 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -30,6 +30,7 @@ 
 #include "sysbus.h"
 #include "range.h"
 #include "xen.h"
+#include "exec-memory.h"
 
 /*
  * I440FX chipset data sheet.
@@ -45,6 +46,7 @@  typedef PCIHostState I440FXState;
 
 typedef struct PIIX3State {
     PCIDevice dev;
+    ISABus bus;
 
     /*
      * bitmap to track pic levels.
@@ -263,7 +265,7 @@  static int i440fx_initfn(PCIDevice *dev)
 static PCIBus *i440fx_common_init(const char *device_name,
                                   PCII440FXState **pi440fx_state,
                                   int *piix3_devfn,
-                                  qemu_irq *pic,
+                                  ISABus **isa_bus,
                                   MemoryRegion *address_space_mem,
                                   MemoryRegion *address_space_io,
                                   ram_addr_t ram_size,
@@ -324,7 +326,7 @@  static PCIBus *i440fx_common_init(const char *device_name,
         pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3,
                 PIIX_NUM_PIRQS);
     }
-    piix3->pic = pic;
+    *isa_bus = &piix3->bus;
 
     (*pi440fx_state)->piix3 = piix3;
 
@@ -341,7 +343,7 @@  static PCIBus *i440fx_common_init(const char *device_name,
 }
 
 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
-                    qemu_irq *pic,
+                    ISABus **isa_bus,
                     MemoryRegion *address_space_mem,
                     MemoryRegion *address_space_io,
                     ram_addr_t ram_size,
@@ -354,7 +356,7 @@  PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
 {
     PCIBus *b;
 
-    b = i440fx_common_init("i440FX", pi440fx_state, piix3_devfn, pic,
+    b = i440fx_common_init("i440FX", pi440fx_state, piix3_devfn, isa_bus,
                            address_space_mem, address_space_io, ram_size,
                            pci_hole_start, pci_hole_size,
                            pci_hole64_size, pci_hole64_size,
@@ -500,11 +502,44 @@  static const VMStateDescription vmstate_piix3 = {
     }
 };
 
+static void piix3_bus_set_irqs(ISABus *bus, qemu_irq *irqs)
+{
+    PIIX3State *d = container_of(bus, PIIX3State, bus);
+    d->pic = irqs;
+}
+
+static qemu_irq piix3_bus_get_irq(ISABus *bus, int isairq)
+{
+    PIIX3State *d = container_of(bus, PIIX3State, bus);
+    if (isairq < 0 || isairq >= PIIX_NUM_PIC_IRQS) {
+        hw_error("isa irq %d invalid", isairq);
+    }
+    return d->pic[isairq];
+}
+
+static MemoryRegion *piix3_bus_get_io_space(ISABus *bus)
+{
+    PIIX3State *d = container_of(bus, PIIX3State, bus);
+    return pci_address_space_io(&d->dev);
+}
+
+static MemoryRegion *piix3_bus_get_memory_space(ISABus *bus)
+{
+    return get_system_memory();
+}
+
+static ISABusOps piix3_bus_ops = {
+    .set_irqs = piix3_bus_set_irqs,
+    .get_irq = piix3_bus_get_irq,
+    .get_io_space = piix3_bus_get_io_space,
+    .get_memory_space = piix3_bus_get_memory_space,
+};
+
 static int piix3_initfn(PCIDevice *dev)
 {
     PIIX3State *d = DO_UPCAST(PIIX3State, dev, dev);
 
-    isa_bus_bridge_init(&d->dev.qdev, pci_address_space_io(dev));
+    isa_bus_new(&d->bus, &piix3_bus_ops, &dev->qdev);
     qemu_register_reset(piix3_reset, d);
     return 0;
 }