[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 03/17] qdev: Allow device addressing via 'driver.
From: |
Jan Kiszka |
Subject: |
[Qemu-devel] [PATCH v3 03/17] qdev: Allow device addressing via 'driver.instance' |
Date: |
Sun, 23 May 2010 12:59:16 +0200 |
From: Jan Kiszka <address@hidden>
Extend qbus_find_dev to allow addressing of devices without an unique id
via an optional per-bus instance number. The new formats are
'driver.instance' and 'alias.instance'.
Signed-off-by: Jan Kiszka <address@hidden>
---
docs/qdev-device-use.txt | 14 +++++++++++++-
hw/qdev.c | 23 ++++++++++++++++++-----
2 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/docs/qdev-device-use.txt b/docs/qdev-device-use.txt
index 9ac1fa1..74d4960 100644
--- a/docs/qdev-device-use.txt
+++ b/docs/qdev-device-use.txt
@@ -1,6 +1,6 @@
= How to convert to -device & friends =
-=== Specifying Bus and Address on Bus ===
+=== Specifying Bus, Address on Bus, and Devices ===
In qdev, each device has a parent bus. Some devices provide one or
more buses for children. You can specify a device's parent bus with
@@ -24,6 +24,18 @@ Furthermore, if a device only hosts a single bus, the bus
name can be
omitted in the path. Example: /i440FX-pcihost/PIIX3 abbreviates
/i440FX-pcihost/pci.0/PIIX3/isa.0 as none of the buses has siblings.
+Existing devices can be addressed either via a unique ID if it was
+assigned during creation or via the device tree path:
+
+/full_bus_address/driver_name[.instance_number]
+ or
+abbreviated_bus_address/driver_name[.instance_number]
+
+The instance number is zero-based.
+
+Example: /i440FX-pcihost/pci.0/e1000.1 addresses the second e1000
+adapter on the bus 'pci.0'.
+
Note: the USB device address can't be controlled at this time.
=== Block Devices ===
diff --git a/hw/qdev.c b/hw/qdev.c
index 2e50531..6b4a629 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -527,28 +527,41 @@ static BusState *qbus_find_bus(DeviceState *dev, char
*elem)
return NULL;
}
-static DeviceState *qbus_find_dev(BusState *bus, char *elem)
+static DeviceState *qbus_find_dev(BusState *bus, const char *elem)
{
DeviceState *dev;
+ int instance, n;
+ char buf[128];
/*
* try to match in order:
* (1) instance id, if present
- * (2) driver name
- * (3) driver alias, if present
+ * (2) driver name [.instance]
+ * (3) driver alias [.instance], if present
*/
QLIST_FOREACH(dev, &bus->children, sibling) {
if (dev->id && strcmp(dev->id, elem) == 0) {
return dev;
}
}
+
+ if (sscanf(elem, "%127[^.].%u", buf, &instance) == 2) {
+ elem = buf;
+ } else {
+ instance = 0;
+ }
+
+ n = 0;
QLIST_FOREACH(dev, &bus->children, sibling) {
- if (strcmp(dev->info->name, elem) == 0) {
+ if (strcmp(dev->info->name, elem) == 0 && n++ == instance) {
return dev;
}
}
+
+ n = 0;
QLIST_FOREACH(dev, &bus->children, sibling) {
- if (dev->info->alias && strcmp(dev->info->alias, elem) == 0) {
+ if (dev->info->alias && strcmp(dev->info->alias, elem) == 0 &&
+ n++ == instance) {
return dev;
}
}
--
1.6.0.2
- [Qemu-devel] [PATCH v3 00/17] Basic device state visualization, Jan Kiszka, 2010/05/23
- [Qemu-devel] [PATCH v3 02/17] qdev: Fix scanning across single-bus devices, Jan Kiszka, 2010/05/23
- [Qemu-devel] [PATCH v3 03/17] qdev: Allow device addressing via 'driver.instance',
Jan Kiszka <=
- [Qemu-devel] [PATCH v3 06/17] qdev: Allow device specification by qtree path for device_del, Jan Kiszka, 2010/05/23
- [Qemu-devel] Re: [PATCH v3 06/17] qdev: Allow device specification by qtree path for device_del, Luiz Capitulino, 2010/05/27
- Re: [Qemu-devel] Re: [PATCH v3 06/17] qdev: Allow device specification by qtree path for device_del, Markus Armbruster, 2010/05/28
- Re: [Qemu-devel] Re: [PATCH v3 06/17] qdev: Allow device specification by qtree path for device_del, Jan Kiszka, 2010/05/28
- Re: [Qemu-devel] Re: [PATCH v3 06/17] qdev: Allow device specification by qtree path for device_del, Markus Armbruster, 2010/05/29
- Re: [Qemu-devel] Re: [PATCH v3 06/17] qdev: Allow device specification by qtree path for device_del, Jan Kiszka, 2010/05/29
[Qemu-devel] [PATCH v3 04/17] qdev: Give qtree names precedence over user-assigned IDs, Jan Kiszka, 2010/05/23