mirror of https://github.com/xqemu/xqemu.git
qdev: remove DeviceType
The only purpose DeviceType serves is creating a linked list of DeviceInfo structs. This removes DeviceType and add a next field to DeviceInfo instead, so the DeviceInfo structs can be changed that way. Elimitates a pointless extra level of indirection. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
10c4c98ab7
commit
042f84d0af
38
hw/qdev.c
38
hw/qdev.c
|
@ -41,28 +41,20 @@ struct DeviceProperty {
|
||||||
DeviceProperty *next;
|
DeviceProperty *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DeviceType {
|
|
||||||
DeviceInfo *info;
|
|
||||||
DeviceType *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* This is a nasty hack to allow passing a NULL bus to qdev_create. */
|
/* This is a nasty hack to allow passing a NULL bus to qdev_create. */
|
||||||
static BusState *main_system_bus;
|
static BusState *main_system_bus;
|
||||||
extern struct BusInfo system_bus_info;
|
extern struct BusInfo system_bus_info;
|
||||||
|
|
||||||
static DeviceType *device_type_list;
|
static DeviceInfo *device_info_list;
|
||||||
|
|
||||||
/* Register a new device type. */
|
/* Register a new device type. */
|
||||||
void qdev_register(DeviceInfo *info)
|
void qdev_register(DeviceInfo *info)
|
||||||
{
|
{
|
||||||
DeviceType *t;
|
|
||||||
|
|
||||||
assert(info->size >= sizeof(DeviceState));
|
assert(info->size >= sizeof(DeviceState));
|
||||||
|
assert(!info->next);
|
||||||
|
|
||||||
t = qemu_mallocz(sizeof(DeviceType));
|
info->next = device_info_list;
|
||||||
t->next = device_type_list;
|
device_info_list = info;
|
||||||
device_type_list = t;
|
|
||||||
t->info = info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a new device. This only initializes the device state structure
|
/* Create a new device. This only initializes the device state structure
|
||||||
|
@ -70,7 +62,7 @@ void qdev_register(DeviceInfo *info)
|
||||||
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)
|
||||||
{
|
{
|
||||||
DeviceType *t;
|
DeviceInfo *info;
|
||||||
DeviceState *dev;
|
DeviceState *dev;
|
||||||
|
|
||||||
if (!bus) {
|
if (!bus) {
|
||||||
|
@ -80,19 +72,19 @@ DeviceState *qdev_create(BusState *bus, const char *name)
|
||||||
bus = main_system_bus;
|
bus = main_system_bus;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (t = device_type_list; t; t = t->next) {
|
for (info = device_info_list; info != NULL; info = info->next) {
|
||||||
if (t->info->bus_info != bus->info)
|
if (info->bus_info != bus->info)
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(t->info->name, name) != 0)
|
if (strcmp(info->name, name) != 0)
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!t) {
|
if (!info) {
|
||||||
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(t->info->size);
|
dev = qemu_mallocz(info->size);
|
||||||
dev->type = t;
|
dev->info = info;
|
||||||
dev->parent_bus = bus;
|
dev->parent_bus = bus;
|
||||||
LIST_INSERT_HEAD(&bus->children, dev, sibling);
|
LIST_INSERT_HEAD(&bus->children, dev, sibling);
|
||||||
return dev;
|
return dev;
|
||||||
|
@ -103,7 +95,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)
|
||||||
calling this function. */
|
calling this function. */
|
||||||
void qdev_init(DeviceState *dev)
|
void qdev_init(DeviceState *dev)
|
||||||
{
|
{
|
||||||
dev->type->info->init(dev, dev->type->info);
|
dev->info->init(dev, dev->info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unlink device from bus and free the structure. */
|
/* Unlink device from bus and free the structure. */
|
||||||
|
@ -165,7 +157,7 @@ CharDriverState *qdev_init_chardev(DeviceState *dev)
|
||||||
static int next_serial;
|
static int next_serial;
|
||||||
static int next_virtconsole;
|
static int next_virtconsole;
|
||||||
/* FIXME: This is a nasty hack that needs to go away. */
|
/* FIXME: This is a nasty hack that needs to go away. */
|
||||||
if (strncmp(dev->type->info->name, "virtio", 6) == 0) {
|
if (strncmp(dev->info->name, "virtio", 6) == 0) {
|
||||||
return virtcon_hds[next_virtconsole++];
|
return virtcon_hds[next_virtconsole++];
|
||||||
} else {
|
} else {
|
||||||
return serial_hds[next_serial++];
|
return serial_hds[next_serial++];
|
||||||
|
@ -338,7 +330,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
|
||||||
{
|
{
|
||||||
DeviceProperty *prop;
|
DeviceProperty *prop;
|
||||||
BusState *child;
|
BusState *child;
|
||||||
qdev_printf("dev: %s\n", dev->type->info->name);
|
qdev_printf("dev: %s\n", dev->info->name);
|
||||||
indent += 2;
|
indent += 2;
|
||||||
if (dev->num_gpio_in) {
|
if (dev->num_gpio_in) {
|
||||||
qdev_printf("gpio-in %d\n", dev->num_gpio_in);
|
qdev_printf("gpio-in %d\n", dev->num_gpio_in);
|
||||||
|
@ -357,7 +349,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
|
||||||
break;
|
break;
|
||||||
case PROP_TYPE_DEV:
|
case PROP_TYPE_DEV:
|
||||||
qdev_printf("prop-dev %s %s\n", prop->name,
|
qdev_printf("prop-dev %s %s\n", prop->name,
|
||||||
((DeviceState *)prop->value.ptr)->type->info->name);
|
((DeviceState *)prop->value.ptr)->info->name);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
qdev_printf("prop-unknown%d %s\n", prop->type, prop->name);
|
qdev_printf("prop-unknown%d %s\n", prop->type, prop->name);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "hw.h"
|
#include "hw.h"
|
||||||
#include "sys-queue.h"
|
#include "sys-queue.h"
|
||||||
|
|
||||||
typedef struct DeviceType DeviceType;
|
typedef struct DeviceInfo DeviceInfo;
|
||||||
|
|
||||||
typedef struct DeviceProperty DeviceProperty;
|
typedef struct DeviceProperty DeviceProperty;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ typedef struct BusInfo BusInfo;
|
||||||
/* This structure should not be accessed directly. We declare it here
|
/* This structure should not be accessed directly. We declare it here
|
||||||
so that it can be embedded in individual device state structures. */
|
so that it can be embedded in individual device state structures. */
|
||||||
struct DeviceState {
|
struct DeviceState {
|
||||||
DeviceType *type;
|
DeviceInfo *info;
|
||||||
BusState *parent_bus;
|
BusState *parent_bus;
|
||||||
DeviceProperty *props;
|
DeviceProperty *props;
|
||||||
int num_gpio_out;
|
int num_gpio_out;
|
||||||
|
@ -72,8 +72,6 @@ typedef struct {
|
||||||
DevicePropType type;
|
DevicePropType type;
|
||||||
} DevicePropList;
|
} DevicePropList;
|
||||||
|
|
||||||
typedef struct DeviceInfo DeviceInfo;
|
|
||||||
|
|
||||||
typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
|
typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
|
||||||
typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
|
typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
|
||||||
int unit);
|
int unit);
|
||||||
|
@ -86,6 +84,7 @@ struct DeviceInfo {
|
||||||
/* Private to qdev / bus. */
|
/* Private to qdev / bus. */
|
||||||
qdev_initfn init;
|
qdev_initfn init;
|
||||||
BusInfo *bus_info;
|
BusInfo *bus_info;
|
||||||
|
struct DeviceInfo *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
void qdev_register(DeviceInfo *info);
|
void qdev_register(DeviceInfo *info);
|
||||||
|
|
Loading…
Reference in New Issue