Patchwork [v2,02/12] isa: rework ISA bus internals, and add ISA bus ops structure

login
register
mail settings
Submitter Hervé Poussineau
Date Sept. 20, 2011, 5:24 a.m.
Message ID <1316496250-2727-3-git-send-email-hpoussin@reactos.org>
Download mbox | patch
Permalink /patch/115438/
State New
Headers show

Comments

Hervé Poussineau - Sept. 20, 2011, 5:24 a.m.
This allows future implementations of real pci-isa bridges

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 Makefile.objs   |    2 +-
 hw/isa-bridge.c |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/isa-bus.c    |   69 ++++++++++++++++++++++++++++++-----------------------
 hw/isa.h        |   16 +++++++++++-
 qemu-common.h   |    1 +
 5 files changed, 127 insertions(+), 32 deletions(-)
 create mode 100644 hw/isa-bridge.c

Patch

diff --git a/Makefile.objs b/Makefile.objs
index 1c65087..fa0746e 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -276,7 +276,7 @@  hw-obj-$(CONFIG_AHCI) += ide/ich.o
 hw-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
 hw-obj-$(CONFIG_ESP) += esp.o
 
-hw-obj-y += dma-helpers.o sysbus.o isa-bus.o
+hw-obj-y += dma-helpers.o sysbus.o isa-bus.o isa-bridge.o
 hw-obj-y += qdev-addr.o
 
 # VGA
diff --git a/hw/isa-bridge.c b/hw/isa-bridge.c
new file mode 100644
index 0000000..49fa033
--- /dev/null
+++ b/hw/isa-bridge.c
@@ -0,0 +1,71 @@ 
+/*
+ * Simple ISA bus bridge
+ *
+ * Copyright (c) 2011 Herve Poussineau
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "isa.h"
+#include "sysbus.h"
+#include "exec-memory.h"
+
+typedef struct {
+    SysBusDevice busdev;
+    ISABus bus;
+    qemu_irq *irqs;
+} ISABridgeSysBusState;
+
+static void isabus_bridge_set_irqs(ISABus *bus, qemu_irq *irqs)
+{
+    ISABridgeSysBusState *s = container_of(bus, ISABridgeSysBusState, bus);
+    s->irqs = irqs;
+}
+
+static qemu_irq isabus_bridge_get_irq(ISABus *bus, int isairq)
+{
+    ISABridgeSysBusState *s = container_of(bus, ISABridgeSysBusState, bus);
+    if (!s->irqs || isairq < 0 || isairq > 15) {
+        hw_error("isa irq %d invalid", isairq);
+    }
+    return s->irqs[isairq];
+}
+
+static ISABusOps isabus_bridge_ops = {
+    .set_irqs = isabus_bridge_set_irqs,
+    .get_irq = isabus_bridge_get_irq,
+};
+
+static int isabus_bridge_init(SysBusDevice *dev)
+{
+    ISABridgeSysBusState *isa = FROM_SYSBUS(ISABridgeSysBusState, dev);
+    isa_bus_new(&isa->bus, &isabus_bridge_ops, &dev->qdev);
+    return 0;
+}
+
+static SysBusDeviceInfo isabus_bridge_info = {
+    .init = isabus_bridge_init,
+    .qdev.name  = "isabus-bridge",
+    .qdev.fw_name  = "isa",
+    .qdev.size  = sizeof(ISABridgeSysBusState),
+    .qdev.no_user = 1,
+};
+
+static void isabus_bridge_register_devices(void)
+{
+    sysbus_register_withprop(&isabus_bridge_info);
+}
+
+device_init(isabus_bridge_register_devices)
+
diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 0f8b682..27cffb3 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -22,12 +22,9 @@ 
 #include "isa.h"
 #include "exec-memory.h"
 
-struct ISABus {
-    BusState qbus;
-    qemu_irq *irqs;
-};
 static ISABus *isabus;
 target_phys_addr_t isa_mem_base = 0;
+static qemu_irq *isa_bus_default_irqs;
 
 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent);
 static char *isabus_get_fw_dev_path(DeviceState *dev);
@@ -39,6 +36,24 @@  static struct BusInfo isa_bus_info = {
     .get_fw_dev_path = isabus_get_fw_dev_path,
 };
 
+static void isa_bus_default_set_irqs(ISABus *bus, qemu_irq *irqs)
+{
+    isa_bus_default_irqs = irqs;
+}
+
+static qemu_irq isa_bus_default_get_irq(ISABus *bus, int isairq)
+{
+    if (isairq < 0 || isairq > 15) {
+        hw_error("isa irq %d invalid", isairq);
+    }
+    return isa_bus_default_irqs[isairq];
+}
+
+static ISABusOps isa_bus_default_ops = {
+    .set_irqs = isa_bus_default_set_irqs,
+    .get_irq = isa_bus_default_get_irq,
+};
+
 ISABus *isa_bus_bridge_init(DeviceState *dev)
 {
     if (isabus) {
@@ -48,15 +63,29 @@  ISABus *isa_bus_bridge_init(DeviceState *dev)
     if (NULL == dev) {
         dev = qdev_create(NULL, "isabus-bridge");
         qdev_init_nofail(dev);
+    } else {
+        isabus = FROM_QBUS(ISABus, qbus_create(&isa_bus_info, dev, NULL));
+        isabus->ops = &isa_bus_default_ops;
     }
-
-    isabus = FROM_QBUS(ISABus, qbus_create(&isa_bus_info, dev, NULL));
     return isabus;
 }
 
+void isa_bus_new(ISABus *bus, ISABusOps *ops, DeviceState *host)
+{
+    if (isabus) {
+        hw_error("Can't create a second ISA bus");
+    }
+    qbus_create_inplace(&bus->qbus, &isa_bus_info, host, NULL);
+    bus->ops = ops;
+    isabus = bus;
+}
+
 void isa_bus_irqs(qemu_irq *irqs)
 {
-    isabus->irqs = irqs;
+    if (!isabus || !isabus->ops->set_irqs) {
+        hw_error("Tried to set isa irqs with no isa bus present.");
+    }
+    isabus->ops->set_irqs(isabus, irqs);
 }
 
 /*
@@ -67,10 +96,10 @@  void isa_bus_irqs(qemu_irq *irqs)
  */
 qemu_irq isa_get_irq(int isairq)
 {
-    if (isairq < 0 || isairq > 15) {
-        hw_error("isa irq %d invalid", isairq);
+    if (!isabus || !isabus->ops->get_irq) {
+        hw_error("ISA bus invalid");
     }
-    return isabus->irqs[isairq];
+    return isabus->ops->get_irq(isabus, isairq);
 }
 
 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq)
@@ -170,25 +199,6 @@  static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent)
     }
 }
 
-static int isabus_bridge_init(SysBusDevice *dev)
-{
-    /* nothing */
-    return 0;
-}
-
-static SysBusDeviceInfo isabus_bridge_info = {
-    .init = isabus_bridge_init,
-    .qdev.name  = "isabus-bridge",
-    .qdev.fw_name  = "isa",
-    .qdev.size  = sizeof(SysBusDevice),
-    .qdev.no_user = 1,
-};
-
-static void isabus_register_devices(void)
-{
-    sysbus_register_withprop(&isabus_bridge_info);
-}
-
 static char *isabus_get_fw_dev_path(DeviceState *dev)
 {
     ISADevice *d = (ISADevice*)dev;
@@ -208,4 +218,3 @@  MemoryRegion *isa_address_space(ISADevice *dev)
     return get_system_memory();
 }
 
-device_init(isabus_register_devices)
diff --git a/hw/isa.h b/hw/isa.h
index 210b3fe..129f129 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -7,7 +7,7 @@ 
 #include "memory.h"
 #include "qdev.h"
 
-typedef struct ISABus ISABus;
+typedef struct ISABusOps ISABusOps;
 typedef struct ISADevice ISADevice;
 typedef struct ISADeviceInfo ISADeviceInfo;
 
@@ -25,7 +25,21 @@  struct ISADeviceInfo {
     isa_qdev_initfn init;
 };
 
+/* isa-bus.c */
+
+struct ISABus {
+    BusState qbus;
+    ISABusOps *ops;
+};
+
+struct ISABusOps {
+    void (*set_irqs)(ISABus *bus, qemu_irq *irqs);
+    qemu_irq (*get_irq)(ISABus *bus, int isairq);
+};
+
 ISABus *isa_bus_bridge_init(DeviceState *dev);
+
+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_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
diff --git a/qemu-common.h b/qemu-common.h
index 404c421..dbba401 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -243,6 +243,7 @@  typedef struct VLANClientState VLANClientState;
 typedef struct i2c_bus i2c_bus;
 typedef struct i2c_slave i2c_slave;
 typedef struct SMBusDevice SMBusDevice;
+typedef struct ISABus ISABus;
 typedef struct PCIHostState PCIHostState;
 typedef struct PCIExpressHost PCIExpressHost;
 typedef struct PCIBus PCIBus;