qdev: create default bus names.
Create a default bus name if none is passed to qbus_create(). If the parent device has DeviceState->id set it will be used to create the bus name,. i.e. -device lsi,id=foo will give you a scsi bus named "foo.0". If there is no id BusInfo->name (lowercased) will be used instead, i.e. -device lsi will give you a scsi bus named "scsi.0". A scsi adapter with two scsi busses would have "scsi.0" and "scsi.1" or "$id.0" and "$id.1" busses. The numbers of the child busses are per device, i.e. when adding two lsi adapters both will have a "*.0" child bus. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
a6307b086b
commit
d271de9f1b
25
hw/qdev.c
25
hw/qdev.c
|
@ -232,14 +232,37 @@ void scsi_bus_new(DeviceState *host, SCSIAttachFn attach)
|
||||||
BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name)
|
BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name)
|
||||||
{
|
{
|
||||||
BusState *bus;
|
BusState *bus;
|
||||||
|
char *buf;
|
||||||
|
int i,len;
|
||||||
|
|
||||||
bus = qemu_mallocz(info->size);
|
bus = qemu_mallocz(info->size);
|
||||||
bus->info = info;
|
bus->info = info;
|
||||||
bus->parent = parent;
|
bus->parent = parent;
|
||||||
bus->name = qemu_strdup(name);
|
|
||||||
|
if (name) {
|
||||||
|
/* use supplied name */
|
||||||
|
bus->name = qemu_strdup(name);
|
||||||
|
} else if (parent && parent->id) {
|
||||||
|
/* parent device has id -> use it for bus name */
|
||||||
|
len = strlen(parent->id) + 16;
|
||||||
|
buf = qemu_malloc(len);
|
||||||
|
snprintf(buf, len, "%s.%d", parent->id, parent->num_child_bus);
|
||||||
|
bus->name = buf;
|
||||||
|
} else {
|
||||||
|
/* no id -> use lowercase bus type for bus name */
|
||||||
|
len = strlen(info->name) + 16;
|
||||||
|
buf = qemu_malloc(len);
|
||||||
|
len = snprintf(buf, len, "%s.%d", info->name,
|
||||||
|
parent ? parent->num_child_bus : 0);
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
buf[i] = tolower(buf[i]);
|
||||||
|
bus->name = buf;
|
||||||
|
}
|
||||||
|
|
||||||
LIST_INIT(&bus->children);
|
LIST_INIT(&bus->children);
|
||||||
if (parent) {
|
if (parent) {
|
||||||
LIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
|
LIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
|
||||||
|
parent->num_child_bus++;
|
||||||
}
|
}
|
||||||
return bus;
|
return bus;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ struct DeviceState {
|
||||||
int num_gpio_in;
|
int num_gpio_in;
|
||||||
qemu_irq *gpio_in;
|
qemu_irq *gpio_in;
|
||||||
LIST_HEAD(, BusState) child_bus;
|
LIST_HEAD(, BusState) child_bus;
|
||||||
|
int num_child_bus;
|
||||||
NICInfo *nd;
|
NICInfo *nd;
|
||||||
LIST_ENTRY(DeviceState) sibling;
|
LIST_ENTRY(DeviceState) sibling;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue