提交 0c17542d 编写于 作者: M Markus Armbruster

qdev: Factor qdev_create_from_info() out of qdev_create()

To make it obvious that -device and device_add can't die in
hw_error().
上级 327867b6
...@@ -78,13 +78,32 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name) ...@@ -78,13 +78,32 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
return NULL; return NULL;
} }
static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
{
DeviceState *dev;
assert(bus->info == info->bus_info);
dev = qemu_mallocz(info->size);
dev->info = info;
dev->parent_bus = bus;
qdev_prop_set_defaults(dev, dev->info->props);
qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
qdev_prop_set_globals(dev);
QLIST_INSERT_HEAD(&bus->children, dev, sibling);
if (qdev_hotplug) {
assert(bus->allow_hotplug);
dev->hotplugged = 1;
}
dev->state = DEV_STATE_CREATED;
return dev;
}
/* Create a new device. This only initializes the device state structure /* Create a new device. This only initializes the device state structure
and allows properties to be set. qdev_init should be called to and allows properties to be set. qdev_init should be called to
initialize the actual device emulation. */ initialize the actual device emulation. */
DeviceState *qdev_create(BusState *bus, const char *name) DeviceState *qdev_create(BusState *bus, const char *name)
{ {
DeviceInfo *info; DeviceInfo *info;
DeviceState *dev;
if (!bus) { if (!bus) {
if (!main_system_bus) { if (!main_system_bus) {
...@@ -98,19 +117,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) ...@@ -98,19 +117,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)
hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name); hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name);
} }
dev = qemu_mallocz(info->size); return qdev_create_from_info(bus, info);
dev->info = info;
dev->parent_bus = bus;
qdev_prop_set_defaults(dev, dev->info->props);
qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
qdev_prop_set_globals(dev);
QLIST_INSERT_HEAD(&bus->children, dev, sibling);
if (qdev_hotplug) {
assert(bus->allow_hotplug);
dev->hotplugged = 1;
}
dev->state = DEV_STATE_CREATED;
return dev;
} }
static void qdev_print_devinfo(DeviceInfo *info) static void qdev_print_devinfo(DeviceInfo *info)
...@@ -224,7 +231,7 @@ DeviceState *qdev_device_add(QemuOpts *opts) ...@@ -224,7 +231,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
} }
/* create device, set properties */ /* create device, set properties */
qdev = qdev_create(bus, driver); qdev = qdev_create_from_info(bus, info);
id = qemu_opts_id(opts); id = qemu_opts_id(opts);
if (id) { if (id) {
qdev->id = id; qdev->id = id;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册