mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-17 21:26:13 -07:00
qdev: replace bus_type enum with bus_info struct.
BusInfo is filled with name and size (pretty much like I did for DeviceInfo as well). There is also a function pointer to print bus-specific device information to the monitor. sysbus is hooked up there, I've also added a print function for PCI. Device creation is slightly modified as well: The device type search loop now also checks the bus type while scanning the list instead of complaining thereafter in case of a mismatch. This effectively gives each bus a private namespace for device names. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Paul Brook <paul@codesourcery.com>
This commit is contained in:
parent
0aab0d3a4a
commit
10c4c98ab7
6 changed files with 103 additions and 62 deletions
58
hw/qdev.c
58
hw/qdev.c
|
|
@ -48,6 +48,7 @@ struct DeviceType {
|
|||
|
||||
/* This is a nasty hack to allow passing a NULL bus to qdev_create. */
|
||||
static BusState *main_system_bus;
|
||||
extern struct BusInfo system_bus_info;
|
||||
|
||||
static DeviceType *device_type_list;
|
||||
|
||||
|
|
@ -72,31 +73,26 @@ DeviceState *qdev_create(BusState *bus, const char *name)
|
|||
DeviceType *t;
|
||||
DeviceState *dev;
|
||||
|
||||
for (t = device_type_list; t; t = t->next) {
|
||||
if (strcmp(t->info->name, name) == 0) {
|
||||
break;
|
||||
if (!bus) {
|
||||
if (!main_system_bus) {
|
||||
main_system_bus = qbus_create(&system_bus_info, NULL, "main-system-bus");
|
||||
}
|
||||
bus = main_system_bus;
|
||||
}
|
||||
|
||||
for (t = device_type_list; t; t = t->next) {
|
||||
if (t->info->bus_info != bus->info)
|
||||
continue;
|
||||
if (strcmp(t->info->name, name) != 0)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
if (!t) {
|
||||
hw_error("Unknown device '%s'\n", name);
|
||||
hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name);
|
||||
}
|
||||
|
||||
dev = qemu_mallocz(t->info->size);
|
||||
dev->type = t;
|
||||
|
||||
if (!bus) {
|
||||
/* ???: This assumes system busses have no additional state. */
|
||||
if (!main_system_bus) {
|
||||
main_system_bus = qbus_create(BUS_TYPE_SYSTEM, sizeof(BusState),
|
||||
NULL, "main-system-bus");
|
||||
}
|
||||
bus = main_system_bus;
|
||||
}
|
||||
if (t->info->bus_type != bus->type) {
|
||||
/* TODO: Print bus type names. */
|
||||
hw_error("Device '%s' on wrong bus type (%d/%d)", name,
|
||||
t->info->bus_type, bus->type);
|
||||
}
|
||||
dev->parent_bus = bus;
|
||||
LIST_INSERT_HEAD(&bus->children, dev, sibling);
|
||||
return dev;
|
||||
|
|
@ -320,13 +316,12 @@ void scsi_bus_new(DeviceState *host, SCSIAttachFn attach)
|
|||
}
|
||||
}
|
||||
|
||||
BusState *qbus_create(BusType type, size_t size,
|
||||
DeviceState *parent, const char *name)
|
||||
BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name)
|
||||
{
|
||||
BusState *bus;
|
||||
|
||||
bus = qemu_mallocz(size);
|
||||
bus->type = type;
|
||||
bus = qemu_mallocz(info->size);
|
||||
bus->info = info;
|
||||
bus->parent = parent;
|
||||
bus->name = qemu_strdup(name);
|
||||
LIST_INIT(&bus->children);
|
||||
|
|
@ -336,14 +331,6 @@ BusState *qbus_create(BusType type, size_t size,
|
|||
return bus;
|
||||
}
|
||||
|
||||
static const char *bus_type_names[] = {
|
||||
[ BUS_TYPE_SYSTEM ] = "System",
|
||||
[ BUS_TYPE_PCI ] = "PCI",
|
||||
[ BUS_TYPE_SCSI ] = "SCSI",
|
||||
[ BUS_TYPE_I2C ] = "I2C",
|
||||
[ BUS_TYPE_SSI ] = "SSI",
|
||||
};
|
||||
|
||||
#define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)
|
||||
static void qbus_print(Monitor *mon, BusState *bus, int indent);
|
||||
|
||||
|
|
@ -377,13 +364,8 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
|
|||
break;
|
||||
}
|
||||
}
|
||||
switch (dev->parent_bus->type) {
|
||||
case BUS_TYPE_SYSTEM:
|
||||
sysbus_dev_print(mon, dev, indent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (dev->parent_bus->info->print_dev)
|
||||
dev->parent_bus->info->print_dev(mon, dev, indent);
|
||||
LIST_FOREACH(child, &dev->child_bus, sibling) {
|
||||
qbus_print(mon, child, indent);
|
||||
}
|
||||
|
|
@ -395,7 +377,7 @@ static void qbus_print(Monitor *mon, BusState *bus, int indent)
|
|||
|
||||
qdev_printf("bus: %s\n", bus->name);
|
||||
indent += 2;
|
||||
qdev_printf("type %s\n", bus_type_names[bus->type]);
|
||||
qdev_printf("type %s\n", bus->info->name);
|
||||
LIST_FOREACH(dev, &bus->children, sibling) {
|
||||
qdev_print(mon, dev, indent);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue