Patchwork [v3,12/16] isa: give bus to isa_get_irq() and isa_bus_irqs()

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

Comments

Hervé Poussineau - Oct. 2, 2011, 4:10 p.m.
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/i8254.c         |    2 +-
 hw/ide.h           |   12 ++++++++----
 hw/ide/piix.c      |   30 ++++++++++++++++++++++--------
 hw/ide/via.c       |   18 ++++++++++++++----
 hw/isa-bus.c       |    6 +++---
 hw/isa.h           |    4 ++--
 hw/mips_fulong2e.c |    2 +-
 hw/mips_jazz.c     |    2 +-
 hw/mips_malta.c    |    6 +++---
 hw/mips_r4k.c      |    2 +-
 hw/pc_piix.c       |   11 ++++++-----
 hw/ppc_prep.c      |    2 +-
 12 files changed, 63 insertions(+), 34 deletions(-)

Patch

diff --git a/hw/i8254.c b/hw/i8254.c
index 12571ef..cb391de 100644
--- a/hw/i8254.c
+++ b/hw/i8254.c
@@ -525,7 +525,7 @@  static int pit_initfn(ISADevice *dev)
     s = &pit->channels[0];
     /* the timer 0 is connected to an IRQ */
     s->irq_timer = qemu_new_timer_ns(vm_clock, pit_irq_timer, s);
-    s->irq = isa_get_irq(pit->irq);
+    s->irq = isa_get_irq(isa_bus_from_device(dev), pit->irq);
 
     memory_region_init_io(&pit->ioports, &pit_ioport_ops, pit, "pit", 4);
     isa_register_ioport(dev, &pit->ioports, pit->iobase);
diff --git a/hw/ide.h b/hw/ide.h
index 7075170..f1cfeb1 100644
--- a/hw/ide.h
+++ b/hw/ide.h
@@ -13,10 +13,14 @@  ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int isairq,
 /* ide-pci.c */
 void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
                          int secondary_ide_enabled);
-PCIDevice *pci_piix3_xen_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
-PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
-PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
-void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
+PCIDevice *pci_piix3_xen_ide_init(PCIBus *pci_bus, ISABus *isa_bus,
+                                  DriveInfo **hd_table, int devfn);
+PCIDevice *pci_piix3_ide_init(PCIBus *bus, ISABus *isa_bus,
+                              DriveInfo **hd_table, int devfn);
+PCIDevice *pci_piix4_ide_init(PCIBus *bus, ISABus *isa_bus,
+                              DriveInfo **hd_table, int devfn);
+void vt82c686b_ide_init(PCIBus *pci_bus, ISABus *isa_bus, DriveInfo **hd_table,
+                        int devfn);
 
 /* ide-macio.c */
 MemoryRegion *pmac_ide_init (DriveInfo **hd_table, qemu_irq irq,
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 88d3181..70b7835 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -121,7 +121,8 @@  static void piix3_reset(void *opaque)
     pci_conf[0x20] = 0x01; /* BMIBA: 20-23h */
 }
 
-static void pci_piix_init_ports(PCIIDEState *d) {
+static void pci_piix_init_legacy_ports(ISABus *isa_bus, PCIIDEState *d)
+{
     int i;
     struct {
         int iobase;
@@ -135,8 +136,15 @@  static void pci_piix_init_ports(PCIIDEState *d) {
     for (i = 0; i < 2; i++) {
         ide_bus_new(&d->bus[i], &d->dev.qdev, i);
         ide_init_ioport(&d->bus[i], port_info[i].iobase, port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_get_irq(port_info[i].isairq));
+        ide_init2(&d->bus[i], isa_get_irq(isa_bus, port_info[i].isairq));
+    }
+}
 
+static void pci_piix_init_ports(PCIIDEState *d)
+{
+    int i;
+
+    for (i = 0; i < 2; i++) {
         bmdma_init(&d->bus[i], &d->bmdma[i], d);
         d->bmdma[i].bus = &d->bus[i];
         qemu_add_vm_change_state_handler(d->bus[i].dma->ops->restart_cb,
@@ -189,11 +197,13 @@  static int pci_piix3_xen_ide_unplug(DeviceState *dev)
     return 0;
 }
 
-PCIDevice *pci_piix3_xen_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
+PCIDevice *pci_piix3_xen_ide_init(PCIBus *pci_bus, ISABus *isa_bus,
+                                  DriveInfo **hd_table, int devfn)
 {
     PCIDevice *dev;
 
-    dev = pci_create_simple(bus, devfn, "piix3-ide-xen");
+    dev = pci_create_simple(pci_bus, devfn, "piix3-ide-xen");
+    pci_piix_init_legacy_ports(isa_bus, DO_UPCAST(PCIIDEState, dev, dev));
     dev->qdev.info->unplug = pci_piix3_xen_ide_unplug;
     pci_ide_create_devs(dev, hd_table);
     return dev;
@@ -217,22 +227,26 @@  static int pci_piix_ide_exitfn(PCIDevice *dev)
 
 /* hd_table must contain 4 block drivers */
 /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
-PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
+PCIDevice *pci_piix3_ide_init(PCIBus *pci_bus, ISABus *isa_bus,
+                              DriveInfo **hd_table, int devfn)
 {
     PCIDevice *dev;
 
-    dev = pci_create_simple(bus, devfn, "piix3-ide");
+    dev = pci_create_simple(pci_bus, devfn, "piix3-ide");
+    pci_piix_init_legacy_ports(isa_bus, DO_UPCAST(PCIIDEState, dev, dev));
     pci_ide_create_devs(dev, hd_table);
     return dev;
 }
 
 /* hd_table must contain 4 block drivers */
 /* NOTE: for the PIIX4, the IRQs and IOports are hardcoded */
-PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
+PCIDevice *pci_piix4_ide_init(PCIBus *pci_bus, ISABus *isa_bus,
+                              DriveInfo **hd_table, int devfn)
 {
     PCIDevice *dev;
 
-    dev = pci_create_simple(bus, devfn, "piix4-ide");
+    dev = pci_create_simple(pci_bus, devfn, "piix4-ide");
+    pci_piix_init_legacy_ports(isa_bus, DO_UPCAST(PCIIDEState, dev, dev));
     pci_ide_create_devs(dev, hd_table);
     return dev;
 }
diff --git a/hw/ide/via.c b/hw/ide/via.c
index dab8a39..6af4e79 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -145,7 +145,8 @@  static void via_reset(void *opaque)
     pci_set_long(pci_conf + 0xc0, 0x00020001);
 }
 
-static void vt82c686b_init_ports(PCIIDEState *d) {
+static void vt82c686b_init_legacy_ports(ISABus *isa_bus, PCIIDEState *d)
+{
     int i;
     struct {
         int iobase;
@@ -159,8 +160,15 @@  static void vt82c686b_init_ports(PCIIDEState *d) {
     for (i = 0; i < 2; i++) {
         ide_bus_new(&d->bus[i], &d->dev.qdev, i);
         ide_init_ioport(&d->bus[i], port_info[i].iobase, port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_get_irq(port_info[i].isairq));
+        ide_init2(&d->bus[i], isa_get_irq(isa_bus, port_info[i].isairq));
+    }
+}
 
+static void vt82c686b_init_ports(PCIIDEState *d)
+{
+    int i;
+
+    for (i = 0; i < 2; i++) {
         bmdma_init(&d->bus[i], &d->bmdma[i], d);
         d->bmdma[i].bus = &d->bus[i];
         qemu_add_vm_change_state_handler(d->bus[i].dma->ops->restart_cb,
@@ -204,11 +212,13 @@  static int vt82c686b_ide_exitfn(PCIDevice *dev)
     return 0;
 }
 
-void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
+void vt82c686b_ide_init(PCIBus *pci_bus, ISABus *isa_bus,
+                        DriveInfo **hd_table, int devfn)
 {
     PCIDevice *dev;
 
-    dev = pci_create_simple(bus, devfn, "via-ide");
+    dev = pci_create_simple(pci_bus, devfn, "via-ide");
+    vt82c686b_init_legacy_ports(isa_bus, DO_UPCAST(PCIIDEState, dev, dev));
     pci_ide_create_devs(dev, hd_table);
 }
 
diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index cdfed29..4a95834 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -58,7 +58,7 @@  void isa_bus_new(ISABus *bus, ISABusOps *ops, DeviceState *host)
     isabus = bus;
 }
 
-void isa_bus_irqs(qemu_irq *irqs)
+void isa_bus_irqs(ISABus *bus, qemu_irq *irqs)
 {
     if (!isabus || !isabus->ops->set_irqs) {
         hw_error("Tried to set isa irqs with no isa bus present.");
@@ -72,7 +72,7 @@  void isa_bus_irqs(qemu_irq *irqs)
  * This function is only for special cases such as the 'ferr', and
  * temporary use for normal devices until they are converted to qdev.
  */
-qemu_irq isa_get_irq(int isairq)
+qemu_irq isa_get_irq(ISABus *bus, int isairq)
 {
     if (!isabus || !isabus->ops->get_irq) {
         hw_error("ISA bus invalid");
@@ -84,7 +84,7 @@  void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq)
 {
     assert(dev->nirqs < ARRAY_SIZE(dev->isairq));
     dev->isairq[dev->nirqs] = isairq;
-    *p = isa_get_irq(isairq);
+    *p = isa_get_irq(isa_bus_from_device(dev), isairq);
     dev->nirqs++;
 }
 
diff --git a/hw/isa.h b/hw/isa.h
index 484180c..5ac3631 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -45,8 +45,8 @@  struct ISABusOps {
 ISABus *isa_bus_bridge_init(MemoryRegion *address_space_io);
 
 void isa_bus_new(ISABus *bus, ISABusOps *ops, DeviceState *host);
-void isa_bus_irqs(qemu_irq *irqs);
-qemu_irq isa_get_irq(int isairq);
+void isa_bus_irqs(ISABus *bus, qemu_irq *irqs);
+qemu_irq isa_get_irq(ISABus *bus, int isairq);
 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
 void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start);
 void isa_init_ioport(ISADevice *dev, uint16_t ioport);
diff --git a/hw/mips_fulong2e.c b/hw/mips_fulong2e.c
index f509b67..0b98402 100644
--- a/hw/mips_fulong2e.c
+++ b/hw/mips_fulong2e.c
@@ -343,7 +343,7 @@  static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
         exit(1);
     }
 
-    vt82c686b_ide_init(pci_bus, hd, PCI_DEVFN(FULONG2E_VIA_SLOT, 1));
+    vt82c686b_ide_init(pci_bus, isa_bus, hd, PCI_DEVFN(FULONG2E_VIA_SLOT, 1));
     usb_uhci_vt82c686b_init(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 2));
     usb_uhci_vt82c686b_init(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 3));
 
diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 172df66..b887038 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -185,7 +185,7 @@  static void mips_jazz_init(MemoryRegion *address_space,
     /* ISA devices */
     isa_bus = isa_bus_bridge_init(address_space_io);
     i8259 = i8259_init(env->irq[4]);
-    isa_bus_irqs(i8259);
+    isa_bus_irqs(isa_bus, i8259);
     cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
     DMA_init(0, cpu_exit_irq);
     pit = pit_init(isa_bus, 0x40, 0);
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index 8126ca7..542c1ff 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -949,10 +949,10 @@  void mips_malta_init (ram_addr_t ram_size,
     i8259 = i8259_init(env->irq[2]);
     isa_bus = piix4_init(pci_bus, 80, i8259, &piix4_devfn);
 
-    pci_piix4_ide_init(pci_bus, hd, piix4_devfn + 1);
+    pci_piix4_ide_init(pci_bus, isa_bus, hd, piix4_devfn + 1);
     usb_uhci_piix4_init(pci_bus, piix4_devfn + 2);
-    smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100, isa_get_irq(9),
-                          NULL, NULL, 0);
+    smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100,
+                          isa_get_irq(isa_bus, 9), NULL, NULL, 0);
     /* TODO: Populate SPD eeprom data.  */
     smbus_eeprom_init(smbus, 8, NULL, 0);
     pit = pit_init(isa_bus, 0x40, 0);
diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
index cb099ab..abc9a80 100644
--- a/hw/mips_r4k.c
+++ b/hw/mips_r4k.c
@@ -259,7 +259,7 @@  void mips_r4k_init (ram_addr_t ram_size,
     /* The PIC is attached to the MIPS CPU INT0 pin */
     isa_bus = isa_bus_bridge_init(get_system_io());
     i8259 = i8259_init(env->irq[2]);
-    isa_bus_irqs(i8259);
+    isa_bus_irqs(isa_bus, i8259);
 
     rtc_init(isa_bus, 2000, NULL);
 
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index a5f8b7a..d5c5ae5 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -150,7 +150,7 @@  static void pc_init1(MemoryRegion *system_memory,
         isa_bus = isa_bus_bridge_init(system_io);
         no_hpet = 1;
     }
-    isa_bus_irqs(isa_irq);
+    isa_bus_irqs(isa_bus, isa_irq);
 
     if (!xen_enabled()) {
         cpu_irq = pc_allocate_cpu_irq();
@@ -164,7 +164,7 @@  static void pc_init1(MemoryRegion *system_memory,
         ioapic_init(isa_irq_state);
     }
 
-    pc_register_ferr_irq(isa_get_irq(13));
+    pc_register_ferr_irq(isa_get_irq(isa_bus, 13));
 
     pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
 
@@ -188,9 +188,10 @@  static void pc_init1(MemoryRegion *system_memory,
     if (pci_enabled) {
         PCIDevice *dev;
         if (xen_enabled()) {
-            dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
+            dev = pci_piix3_xen_ide_init(pci_bus, isa_bus, hd,
+                                         piix3_devfn + 1);
         } else {
-            dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
+            dev = pci_piix3_ide_init(pci_bus, isa_bus, hd, piix3_devfn + 1);
         }
         idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
         idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
@@ -224,7 +225,7 @@  static void pc_init1(MemoryRegion *system_memory,
         smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
         /* TODO: Populate SPD eeprom data.  */
         smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
-                              isa_get_irq(9), *cmos_s3, *smi_irq,
+                              isa_get_irq(isa_bus, 9), *cmos_s3, *smi_irq,
                               kvm_enabled());
         smbus_eeprom_init(smbus, 8, NULL, 0);
     }
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index 499e63f..5e39982 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -653,7 +653,7 @@  static void ppc_prep_init (ram_addr_t ram_size,
     isa_bus = isa_bus_bridge_init(get_system_io());
     i8259 = i8259_init(first_cpu->irq_inputs[PPC6xx_INPUT_INT]);
     pci_bus = pci_prep_init(i8259, get_system_memory(), get_system_io());
-    isa_bus_irqs(i8259);
+    isa_bus_irqs(isa_bus, i8259);
     //    pci_bus = i440fx_init();
     /* Register 8 MB of ISA IO space (needed for non-contiguous map) */
     PPC_io_memory = cpu_register_io_memory(PPC_prep_io_read,