Commit 042f84d0af0e6c654d836f57ce916d7dec2b263d

Authored by Gerd Hoffmann
Committed by Paul Brook
1 parent 10c4c98a

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>
Showing 2 changed files with 18 additions and 27 deletions
hw/qdev.c
@@ -41,28 +41,20 @@ struct DeviceProperty { @@ -41,28 +41,20 @@ struct DeviceProperty {
41 DeviceProperty *next; 41 DeviceProperty *next;
42 }; 42 };
43 43
44 -struct DeviceType {  
45 - DeviceInfo *info;  
46 - DeviceType *next;  
47 -};  
48 -  
49 /* This is a nasty hack to allow passing a NULL bus to qdev_create. */ 44 /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
50 static BusState *main_system_bus; 45 static BusState *main_system_bus;
51 extern struct BusInfo system_bus_info; 46 extern struct BusInfo system_bus_info;
52 47
53 -static DeviceType *device_type_list; 48 +static DeviceInfo *device_info_list;
54 49
55 /* Register a new device type. */ 50 /* Register a new device type. */
56 void qdev_register(DeviceInfo *info) 51 void qdev_register(DeviceInfo *info)
57 { 52 {
58 - DeviceType *t;  
59 -  
60 assert(info->size >= sizeof(DeviceState)); 53 assert(info->size >= sizeof(DeviceState));
  54 + assert(!info->next);
61 55
62 - t = qemu_mallocz(sizeof(DeviceType));  
63 - t->next = device_type_list;  
64 - device_type_list = t;  
65 - t->info = info; 56 + info->next = device_info_list;
  57 + device_info_list = info;
66 } 58 }
67 59
68 /* Create a new device. This only initializes the device state structure 60 /* Create a new device. This only initializes the device state structure
@@ -70,7 +62,7 @@ void qdev_register(DeviceInfo *info) @@ -70,7 +62,7 @@ void qdev_register(DeviceInfo *info)
70 initialize the actual device emulation. */ 62 initialize the actual device emulation. */
71 DeviceState *qdev_create(BusState *bus, const char *name) 63 DeviceState *qdev_create(BusState *bus, const char *name)
72 { 64 {
73 - DeviceType *t; 65 + DeviceInfo *info;
74 DeviceState *dev; 66 DeviceState *dev;
75 67
76 if (!bus) { 68 if (!bus) {
@@ -80,19 +72,19 @@ DeviceState *qdev_create(BusState *bus, const char *name) @@ -80,19 +72,19 @@ DeviceState *qdev_create(BusState *bus, const char *name)
80 bus = main_system_bus; 72 bus = main_system_bus;
81 } 73 }
82 74
83 - for (t = device_type_list; t; t = t->next) {  
84 - if (t->info->bus_info != bus->info) 75 + for (info = device_info_list; info != NULL; info = info->next) {
  76 + if (info->bus_info != bus->info)
85 continue; 77 continue;
86 - if (strcmp(t->info->name, name) != 0) 78 + if (strcmp(info->name, name) != 0)
87 continue; 79 continue;
88 break; 80 break;
89 } 81 }
90 - if (!t) { 82 + if (!info) {
91 hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name); 83 hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name);
92 } 84 }
93 85
94 - dev = qemu_mallocz(t->info->size);  
95 - dev->type = t; 86 + dev = qemu_mallocz(info->size);
  87 + dev->info = info;
96 dev->parent_bus = bus; 88 dev->parent_bus = bus;
97 LIST_INSERT_HEAD(&bus->children, dev, sibling); 89 LIST_INSERT_HEAD(&bus->children, dev, sibling);
98 return dev; 90 return dev;
@@ -103,7 +95,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) @@ -103,7 +95,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)
103 calling this function. */ 95 calling this function. */
104 void qdev_init(DeviceState *dev) 96 void qdev_init(DeviceState *dev)
105 { 97 {
106 - dev->type->info->init(dev, dev->type->info); 98 + dev->info->init(dev, dev->info);
107 } 99 }
108 100
109 /* Unlink device from bus and free the structure. */ 101 /* Unlink device from bus and free the structure. */
@@ -165,7 +157,7 @@ CharDriverState *qdev_init_chardev(DeviceState *dev) @@ -165,7 +157,7 @@ CharDriverState *qdev_init_chardev(DeviceState *dev)
165 static int next_serial; 157 static int next_serial;
166 static int next_virtconsole; 158 static int next_virtconsole;
167 /* FIXME: This is a nasty hack that needs to go away. */ 159 /* FIXME: This is a nasty hack that needs to go away. */
168 - if (strncmp(dev->type->info->name, "virtio", 6) == 0) { 160 + if (strncmp(dev->info->name, "virtio", 6) == 0) {
169 return virtcon_hds[next_virtconsole++]; 161 return virtcon_hds[next_virtconsole++];
170 } else { 162 } else {
171 return serial_hds[next_serial++]; 163 return serial_hds[next_serial++];
@@ -338,7 +330,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) @@ -338,7 +330,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
338 { 330 {
339 DeviceProperty *prop; 331 DeviceProperty *prop;
340 BusState *child; 332 BusState *child;
341 - qdev_printf("dev: %s\n", dev->type->info->name); 333 + qdev_printf("dev: %s\n", dev->info->name);
342 indent += 2; 334 indent += 2;
343 if (dev->num_gpio_in) { 335 if (dev->num_gpio_in) {
344 qdev_printf("gpio-in %d\n", dev->num_gpio_in); 336 qdev_printf("gpio-in %d\n", dev->num_gpio_in);
@@ -357,7 +349,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) @@ -357,7 +349,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
357 break; 349 break;
358 case PROP_TYPE_DEV: 350 case PROP_TYPE_DEV:
359 qdev_printf("prop-dev %s %s\n", prop->name, 351 qdev_printf("prop-dev %s %s\n", prop->name,
360 - ((DeviceState *)prop->value.ptr)->type->info->name); 352 + ((DeviceState *)prop->value.ptr)->info->name);
361 break; 353 break;
362 default: 354 default:
363 qdev_printf("prop-unknown%d %s\n", prop->type, prop->name); 355 qdev_printf("prop-unknown%d %s\n", prop->type, prop->name);
hw/qdev.h
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 #include "hw.h" 4 #include "hw.h"
5 #include "sys-queue.h" 5 #include "sys-queue.h"
6 6
7 -typedef struct DeviceType DeviceType; 7 +typedef struct DeviceInfo DeviceInfo;
8 8
9 typedef struct DeviceProperty DeviceProperty; 9 typedef struct DeviceProperty DeviceProperty;
10 10
@@ -15,7 +15,7 @@ typedef struct BusInfo BusInfo; @@ -15,7 +15,7 @@ typedef struct BusInfo BusInfo;
15 /* This structure should not be accessed directly. We declare it here 15 /* This structure should not be accessed directly. We declare it here
16 so that it can be embedded in individual device state structures. */ 16 so that it can be embedded in individual device state structures. */
17 struct DeviceState { 17 struct DeviceState {
18 - DeviceType *type; 18 + DeviceInfo *info;
19 BusState *parent_bus; 19 BusState *parent_bus;
20 DeviceProperty *props; 20 DeviceProperty *props;
21 int num_gpio_out; 21 int num_gpio_out;
@@ -72,8 +72,6 @@ typedef struct { @@ -72,8 +72,6 @@ typedef struct {
72 DevicePropType type; 72 DevicePropType type;
73 } DevicePropList; 73 } DevicePropList;
74 74
75 -typedef struct DeviceInfo DeviceInfo;  
76 -  
77 typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info); 75 typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
78 typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv, 76 typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
79 int unit); 77 int unit);
@@ -86,6 +84,7 @@ struct DeviceInfo { @@ -86,6 +84,7 @@ struct DeviceInfo {
86 /* Private to qdev / bus. */ 84 /* Private to qdev / bus. */
87 qdev_initfn init; 85 qdev_initfn init;
88 BusInfo *bus_info; 86 BusInfo *bus_info;
  87 + struct DeviceInfo *next;
89 }; 88 };
90 89
91 void qdev_register(DeviceInfo *info); 90 void qdev_register(DeviceInfo *info);