Patchwork [v3,03/16] isa: correctly implement isa_address_space(), by calling a bus-specific function

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

Comments

Hervé Poussineau - Oct. 2, 2011, 4:10 p.m.
This method can be used later to remove the isa_mem_base variable.

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/isa-bridge.c |    7 +++++++
 hw/isa-bus.c    |   13 ++++++++++++-
 hw/isa.h        |    6 ++++++
 3 files changed, 25 insertions(+), 1 deletions(-)

Patch

diff --git a/hw/isa-bridge.c b/hw/isa-bridge.c
index 6f51701..de7c46b 100644
--- a/hw/isa-bridge.c
+++ b/hw/isa-bridge.c
@@ -19,6 +19,7 @@ 
 
 #include "isa.h"
 #include "sysbus.h"
+#include "exec-memory.h"
 
 typedef struct {
     SysBusDevice busdev;
@@ -54,11 +55,17 @@  static MemoryRegion *isa_bridge_get_io_space(ISABus *bus)
     return s->io_space;
 }
 
+static MemoryRegion *isa_bridge_get_memory_space(ISABus *bus)
+{
+    return get_system_memory();
+}
+
 static ISABusOps isabus_bridge_ops = {
     .set_irqs = isabus_bridge_set_irqs,
     .get_irq = isabus_bridge_get_irq,
     .set_io_space = isa_bridge_set_io_space,
     .get_io_space = isa_bridge_get_io_space,
+    .get_memory_space = isa_bridge_get_memory_space,
 };
 
 static int isabus_bridge_init(SysBusDevice *dev)
diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index f8b5dcb..dd539e5 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -60,11 +60,17 @@  static MemoryRegion *isa_bus_default_get_io_space(ISABus *bus)
     return isa_bus_io_space;
 }
 
+static MemoryRegion *isa_bus_default_get_memory_space(ISABus *bus)
+{
+    return get_system_memory();
+}
+
 static ISABusOps isa_bus_default_ops = {
     .set_irqs = isa_bus_default_set_irqs,
     .get_irq = isa_bus_default_get_irq,
     .set_io_space = isa_bus_default_set_io_space,
     .get_io_space = isa_bus_default_get_io_space,
+    .get_memory_space = isa_bus_default_get_memory_space,
 };
 
 ISABus *isa_bus_bridge_init(DeviceState *dev, MemoryRegion *address_space_io)
@@ -247,6 +253,11 @@  static char *isabus_get_fw_dev_path(DeviceState *dev)
 
 MemoryRegion *isa_address_space(ISADevice *dev)
 {
-    return get_system_memory();
+    ISABus *bus = isa_bus_from_device(dev);
+
+    if (!bus->ops->get_memory_space) {
+        hw_error("Tried to get isa address space on invalid isa bus.");
+    }
+    return bus->ops->get_memory_space(bus);
 }
 
diff --git a/hw/isa.h b/hw/isa.h
index 3437199..8d439b5 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -39,6 +39,7 @@  struct ISABusOps {
     qemu_irq (*get_irq)(ISABus *bus, int isairq);
     void (*set_io_space)(ISABus *bus, MemoryRegion *address_space);
     MemoryRegion *(*get_io_space)(ISABus *bus);
+    MemoryRegion *(*get_memory_space)(ISABus *bus);
 };
 
 ISABus *isa_bus_bridge_init(DeviceState *dev, MemoryRegion *address_space_io);
@@ -56,6 +57,11 @@  ISADevice *isa_create(const char *name);
 ISADevice *isa_try_create(const char *name);
 ISADevice *isa_create_simple(const char *name);
 
+static inline ISABus *isa_bus_from_device(ISADevice *d)
+{
+    return FROM_QBUS(ISABus, qdev_get_parent_bus(&d->qdev));
+}
+
 extern target_phys_addr_t isa_mem_base;
 
 void isa_mmio_setup(MemoryRegion *mr, target_phys_addr_t size);