diff mbox

[2/5] Add get_dev_path callback to ISA bus in qdev.

Message ID 1288090091-25874-3-git-send-email-gleb@redhat.com
State New
Headers show

Commit Message

Gleb Natapov Oct. 26, 2010, 10:48 a.m. UTC
Use device ioports to create unique device path.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
 hw/isa-bus.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 12938f5..b2ddfb5 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -31,11 +31,13 @@  static ISABus *isabus;
 target_phys_addr_t isa_mem_base = 0;
 
 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent);
+static char *isabus_get_dev_path(DeviceState *dev);
 
 static struct BusInfo isa_bus_info = {
     .name      = "ISA",
     .size      = sizeof(ISABus),
     .print_dev = isabus_dev_print,
+    .get_dev_path = isabus_get_dev_path,
 };
 
 ISABus *isa_bus_new(DeviceState *dev)
@@ -187,4 +189,41 @@  static void isabus_register_devices(void)
     sysbus_register_withprop(&isabus_bridge_info);
 }
 
+static int find_range_end(ISADevice *d, int i)
+{
+    uint16_t p = d->ioports[i++];
+
+    while (i < d->nioports) {
+        if (d->ioports[i] - p != 1) {
+            break;
+        }
+        p = d->ioports[i++];
+    }
+    return i - 1;
+}
+
+static char *isabus_get_dev_path(DeviceState *dev)
+{
+    ISADevice *d = (ISADevice*)dev;
+    char path[100];
+    int i = 0, off = 0;
+
+    while (i < d->nioports) {
+        int e = find_range_end(d, i);
+        if (off)
+            path[off++] = ',';
+        if (i == e) {
+            off += snprintf(path + off, sizeof(path) - off, "%04x",
+                            d->ioports[i]);
+            i++;
+        } else {
+            off += snprintf(path + off, sizeof(path) - off, "%04x-%04x",
+                            d->ioports[i], d->ioports[e]);
+            i = e + 1;
+        }
+    }
+
+    return strdup(path);
+}
+
 device_init(isabus_register_devices)