Commit 074f2fff798cb8f9588080b740dc356217a24720
Committed by
Paul Brook
1 parent
57b452a8
qdev: move name+size into DeviceInfo (v2)
Rationale: move device information from code to data structures. v2: Adapt the drivers missed in the first version. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Showing
27 changed files
with
95 additions
and
61 deletions
hw/ads7846.c
@@ -155,13 +155,15 @@ static void ads7846_init(SSISlave *dev) | @@ -155,13 +155,15 @@ static void ads7846_init(SSISlave *dev) | ||
155 | } | 155 | } |
156 | 156 | ||
157 | static SSISlaveInfo ads7846_info = { | 157 | static SSISlaveInfo ads7846_info = { |
158 | + .qdev.name ="ads7846", | ||
159 | + .qdev.size = sizeof(ADS7846State), | ||
158 | .init = ads7846_init, | 160 | .init = ads7846_init, |
159 | .transfer = ads7846_transfer | 161 | .transfer = ads7846_transfer |
160 | }; | 162 | }; |
161 | 163 | ||
162 | static void ads7846_register_devices(void) | 164 | static void ads7846_register_devices(void) |
163 | { | 165 | { |
164 | - ssi_register_slave("ads7846", sizeof(ADS7846State), &ads7846_info); | 166 | + ssi_register_slave(&ads7846_info); |
165 | } | 167 | } |
166 | 168 | ||
167 | device_init(ads7846_register_devices) | 169 | device_init(ads7846_register_devices) |
hw/i2c.c
@@ -152,12 +152,12 @@ static void i2c_slave_qdev_init(DeviceState *dev, DeviceInfo *base) | @@ -152,12 +152,12 @@ static void i2c_slave_qdev_init(DeviceState *dev, DeviceInfo *base) | ||
152 | info->init(s); | 152 | info->init(s); |
153 | } | 153 | } |
154 | 154 | ||
155 | -void i2c_register_slave(const char *name, int size, I2CSlaveInfo *info) | 155 | +void i2c_register_slave(I2CSlaveInfo *info) |
156 | { | 156 | { |
157 | - assert(size >= sizeof(i2c_slave)); | 157 | + assert(info->qdev.size >= sizeof(i2c_slave)); |
158 | info->qdev.init = i2c_slave_qdev_init; | 158 | info->qdev.init = i2c_slave_qdev_init; |
159 | info->qdev.bus_type = BUS_TYPE_I2C; | 159 | info->qdev.bus_type = BUS_TYPE_I2C; |
160 | - qdev_register(name, size, &info->qdev); | 160 | + qdev_register(&info->qdev); |
161 | } | 161 | } |
162 | 162 | ||
163 | DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, int addr) | 163 | DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, int addr) |
hw/i2c.h
@@ -57,7 +57,7 @@ void i2c_slave_load(QEMUFile *f, i2c_slave *dev); | @@ -57,7 +57,7 @@ void i2c_slave_load(QEMUFile *f, i2c_slave *dev); | ||
57 | #define I2C_SLAVE_FROM_QDEV(dev) DO_UPCAST(i2c_slave, qdev, dev) | 57 | #define I2C_SLAVE_FROM_QDEV(dev) DO_UPCAST(i2c_slave, qdev, dev) |
58 | #define FROM_I2C_SLAVE(type, dev) DO_UPCAST(type, i2c, dev) | 58 | #define FROM_I2C_SLAVE(type, dev) DO_UPCAST(type, i2c, dev) |
59 | 59 | ||
60 | -void i2c_register_slave(const char *name, int size, I2CSlaveInfo *type); | 60 | +void i2c_register_slave(I2CSlaveInfo *type); |
61 | 61 | ||
62 | DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, int addr); | 62 | DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, int addr); |
63 | 63 |
hw/lm832x.c
@@ -526,6 +526,8 @@ void lm832x_key_event(struct i2c_slave *i2c, int key, int state) | @@ -526,6 +526,8 @@ void lm832x_key_event(struct i2c_slave *i2c, int key, int state) | ||
526 | } | 526 | } |
527 | 527 | ||
528 | static I2CSlaveInfo lm8323_info = { | 528 | static I2CSlaveInfo lm8323_info = { |
529 | + .qdev.name = "lm8323", | ||
530 | + .qdev.size = sizeof(LM823KbdState), | ||
529 | .init = lm8323_init, | 531 | .init = lm8323_init, |
530 | .event = lm_i2c_event, | 532 | .event = lm_i2c_event, |
531 | .recv = lm_i2c_rx, | 533 | .recv = lm_i2c_rx, |
@@ -534,7 +536,7 @@ static I2CSlaveInfo lm8323_info = { | @@ -534,7 +536,7 @@ static I2CSlaveInfo lm8323_info = { | ||
534 | 536 | ||
535 | static void lm832x_register_devices(void) | 537 | static void lm832x_register_devices(void) |
536 | { | 538 | { |
537 | - i2c_register_slave("lm8323", sizeof(LM823KbdState), &lm8323_info); | 539 | + i2c_register_slave(&lm8323_info); |
538 | } | 540 | } |
539 | 541 | ||
540 | device_init(lm832x_register_devices) | 542 | device_init(lm832x_register_devices) |
hw/max111x.c
@@ -164,19 +164,23 @@ void max111x_set_input(DeviceState *dev, int line, uint8_t value) | @@ -164,19 +164,23 @@ void max111x_set_input(DeviceState *dev, int line, uint8_t value) | ||
164 | } | 164 | } |
165 | 165 | ||
166 | static SSISlaveInfo max1110_info = { | 166 | static SSISlaveInfo max1110_info = { |
167 | + .qdev.name = "max1110", | ||
168 | + .qdev.size = sizeof(MAX111xState), | ||
167 | .init = max1110_init, | 169 | .init = max1110_init, |
168 | .transfer = max111x_transfer | 170 | .transfer = max111x_transfer |
169 | }; | 171 | }; |
170 | 172 | ||
171 | static SSISlaveInfo max1111_info = { | 173 | static SSISlaveInfo max1111_info = { |
174 | + .qdev.name = "max1111", | ||
175 | + .qdev.size = sizeof(MAX111xState), | ||
172 | .init = max1111_init, | 176 | .init = max1111_init, |
173 | .transfer = max111x_transfer | 177 | .transfer = max111x_transfer |
174 | }; | 178 | }; |
175 | 179 | ||
176 | static void max111x_register_devices(void) | 180 | static void max111x_register_devices(void) |
177 | { | 181 | { |
178 | - ssi_register_slave("max1110", sizeof(MAX111xState), &max1110_info); | ||
179 | - ssi_register_slave("max1111", sizeof(MAX111xState), &max1111_info); | 182 | + ssi_register_slave(&max1110_info); |
183 | + ssi_register_slave(&max1111_info); | ||
180 | } | 184 | } |
181 | 185 | ||
182 | device_init(max111x_register_devices) | 186 | device_init(max111x_register_devices) |
hw/max7310.c
@@ -218,6 +218,8 @@ void max7310_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler) | @@ -218,6 +218,8 @@ void max7310_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler) | ||
218 | } | 218 | } |
219 | 219 | ||
220 | static I2CSlaveInfo max7310_info = { | 220 | static I2CSlaveInfo max7310_info = { |
221 | + .qdev.name = "max7310", | ||
222 | + .qdev.size = sizeof(MAX7310State), | ||
221 | .init = max7310_init, | 223 | .init = max7310_init, |
222 | .event = max7310_event, | 224 | .event = max7310_event, |
223 | .recv = max7310_rx, | 225 | .recv = max7310_rx, |
@@ -226,7 +228,7 @@ static I2CSlaveInfo max7310_info = { | @@ -226,7 +228,7 @@ static I2CSlaveInfo max7310_info = { | ||
226 | 228 | ||
227 | static void max7310_register_devices(void) | 229 | static void max7310_register_devices(void) |
228 | { | 230 | { |
229 | - i2c_register_slave("max7310", sizeof(MAX7310State), &max7310_info); | 231 | + i2c_register_slave(&max7310_info); |
230 | } | 232 | } |
231 | 233 | ||
232 | device_init(max7310_register_devices) | 234 | device_init(max7310_register_devices) |
hw/pci.c
@@ -924,11 +924,13 @@ void pci_qdev_register(const char *name, int size, pci_qdev_initfn init) | @@ -924,11 +924,13 @@ void pci_qdev_register(const char *name, int size, pci_qdev_initfn init) | ||
924 | PCIDeviceInfo *info; | 924 | PCIDeviceInfo *info; |
925 | 925 | ||
926 | info = qemu_mallocz(sizeof(*info)); | 926 | info = qemu_mallocz(sizeof(*info)); |
927 | + info->qdev.name = qemu_strdup(name); | ||
928 | + info->qdev.size = size; | ||
927 | info->init = init; | 929 | info->init = init; |
928 | info->qdev.init = pci_qdev_init; | 930 | info->qdev.init = pci_qdev_init; |
929 | info->qdev.bus_type = BUS_TYPE_PCI; | 931 | info->qdev.bus_type = BUS_TYPE_PCI; |
930 | 932 | ||
931 | - qdev_register(name, size, &info->qdev); | 933 | + qdev_register(&info->qdev); |
932 | } | 934 | } |
933 | 935 | ||
934 | PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name) | 936 | PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name) |
hw/pxa2xx.c
@@ -1485,6 +1485,8 @@ static void pxa2xx_i2c_slave_init(i2c_slave *i2c) | @@ -1485,6 +1485,8 @@ static void pxa2xx_i2c_slave_init(i2c_slave *i2c) | ||
1485 | } | 1485 | } |
1486 | 1486 | ||
1487 | static I2CSlaveInfo pxa2xx_i2c_slave_info = { | 1487 | static I2CSlaveInfo pxa2xx_i2c_slave_info = { |
1488 | + .qdev.name = "pxa2xx-i2c-slave", | ||
1489 | + .qdev.size = sizeof(PXA2xxI2CSlaveState), | ||
1488 | .init = pxa2xx_i2c_slave_init, | 1490 | .init = pxa2xx_i2c_slave_init, |
1489 | .event = pxa2xx_i2c_event, | 1491 | .event = pxa2xx_i2c_event, |
1490 | .recv = pxa2xx_i2c_rx, | 1492 | .recv = pxa2xx_i2c_rx, |
@@ -2258,8 +2260,7 @@ PXA2xxState *pxa255_init(unsigned int sdram_size) | @@ -2258,8 +2260,7 @@ PXA2xxState *pxa255_init(unsigned int sdram_size) | ||
2258 | 2260 | ||
2259 | static void pxa2xx_register_devices(void) | 2261 | static void pxa2xx_register_devices(void) |
2260 | { | 2262 | { |
2261 | - i2c_register_slave("pxa2xx-i2c-slave", sizeof(PXA2xxI2CSlaveState), | ||
2262 | - &pxa2xx_i2c_slave_info); | 2263 | + i2c_register_slave(&pxa2xx_i2c_slave_info); |
2263 | sysbus_register_dev("pxa2xx-ssp", sizeof(PXA2xxSSPState), pxa2xx_ssp_init); | 2264 | sysbus_register_dev("pxa2xx-ssp", sizeof(PXA2xxSSPState), pxa2xx_ssp_init); |
2264 | } | 2265 | } |
2265 | 2266 |
hw/qdev.c
@@ -42,9 +42,7 @@ struct DeviceProperty { | @@ -42,9 +42,7 @@ struct DeviceProperty { | ||
42 | }; | 42 | }; |
43 | 43 | ||
44 | struct DeviceType { | 44 | struct DeviceType { |
45 | - const char *name; | ||
46 | DeviceInfo *info; | 45 | DeviceInfo *info; |
47 | - int size; | ||
48 | DeviceType *next; | 46 | DeviceType *next; |
49 | }; | 47 | }; |
50 | 48 | ||
@@ -54,17 +52,15 @@ static BusState *main_system_bus; | @@ -54,17 +52,15 @@ static BusState *main_system_bus; | ||
54 | static DeviceType *device_type_list; | 52 | static DeviceType *device_type_list; |
55 | 53 | ||
56 | /* Register a new device type. */ | 54 | /* Register a new device type. */ |
57 | -void qdev_register(const char *name, int size, DeviceInfo *info) | 55 | +void qdev_register(DeviceInfo *info) |
58 | { | 56 | { |
59 | DeviceType *t; | 57 | DeviceType *t; |
60 | 58 | ||
61 | - assert(size >= sizeof(DeviceState)); | 59 | + assert(info->size >= sizeof(DeviceState)); |
62 | 60 | ||
63 | t = qemu_mallocz(sizeof(DeviceType)); | 61 | t = qemu_mallocz(sizeof(DeviceType)); |
64 | t->next = device_type_list; | 62 | t->next = device_type_list; |
65 | device_type_list = t; | 63 | device_type_list = t; |
66 | - t->name = qemu_strdup(name); | ||
67 | - t->size = size; | ||
68 | t->info = info; | 64 | t->info = info; |
69 | } | 65 | } |
70 | 66 | ||
@@ -77,7 +73,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) | @@ -77,7 +73,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) | ||
77 | DeviceState *dev; | 73 | DeviceState *dev; |
78 | 74 | ||
79 | for (t = device_type_list; t; t = t->next) { | 75 | for (t = device_type_list; t; t = t->next) { |
80 | - if (strcmp(t->name, name) == 0) { | 76 | + if (strcmp(t->info->name, name) == 0) { |
81 | break; | 77 | break; |
82 | } | 78 | } |
83 | } | 79 | } |
@@ -85,7 +81,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) | @@ -85,7 +81,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) | ||
85 | hw_error("Unknown device '%s'\n", name); | 81 | hw_error("Unknown device '%s'\n", name); |
86 | } | 82 | } |
87 | 83 | ||
88 | - dev = qemu_mallocz(t->size); | 84 | + dev = qemu_mallocz(t->info->size); |
89 | dev->type = t; | 85 | dev->type = t; |
90 | 86 | ||
91 | if (!bus) { | 87 | if (!bus) { |
@@ -173,7 +169,7 @@ CharDriverState *qdev_init_chardev(DeviceState *dev) | @@ -173,7 +169,7 @@ CharDriverState *qdev_init_chardev(DeviceState *dev) | ||
173 | static int next_serial; | 169 | static int next_serial; |
174 | static int next_virtconsole; | 170 | static int next_virtconsole; |
175 | /* FIXME: This is a nasty hack that needs to go away. */ | 171 | /* FIXME: This is a nasty hack that needs to go away. */ |
176 | - if (strncmp(dev->type->name, "virtio", 6) == 0) { | 172 | + if (strncmp(dev->type->info->name, "virtio", 6) == 0) { |
177 | return virtcon_hds[next_virtconsole++]; | 173 | return virtcon_hds[next_virtconsole++]; |
178 | } else { | 174 | } else { |
179 | return serial_hds[next_serial++]; | 175 | return serial_hds[next_serial++]; |
@@ -355,7 +351,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) | @@ -355,7 +351,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) | ||
355 | { | 351 | { |
356 | DeviceProperty *prop; | 352 | DeviceProperty *prop; |
357 | BusState *child; | 353 | BusState *child; |
358 | - qdev_printf("dev: %s\n", dev->type->name); | 354 | + qdev_printf("dev: %s\n", dev->type->info->name); |
359 | indent += 2; | 355 | indent += 2; |
360 | if (dev->num_gpio_in) { | 356 | if (dev->num_gpio_in) { |
361 | qdev_printf("gpio-in %d\n", dev->num_gpio_in); | 357 | qdev_printf("gpio-in %d\n", dev->num_gpio_in); |
@@ -374,7 +370,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) | @@ -374,7 +370,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) | ||
374 | break; | 370 | break; |
375 | case PROP_TYPE_DEV: | 371 | case PROP_TYPE_DEV: |
376 | qdev_printf("prop-dev %s %s\n", prop->name, | 372 | qdev_printf("prop-dev %s %s\n", prop->name, |
377 | - ((DeviceState *)prop->value.ptr)->type->name); | 373 | + ((DeviceState *)prop->value.ptr)->type->info->name); |
378 | break; | 374 | break; |
379 | default: | 375 | default: |
380 | qdev_printf("prop-unknown%d %s\n", prop->type, prop->name); | 376 | qdev_printf("prop-unknown%d %s\n", prop->type, prop->name); |
hw/qdev.h
@@ -78,12 +78,16 @@ typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv, | @@ -78,12 +78,16 @@ typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv, | ||
78 | int unit); | 78 | int unit); |
79 | 79 | ||
80 | struct DeviceInfo { | 80 | struct DeviceInfo { |
81 | + const char *name; | ||
82 | + size_t size; | ||
83 | + DevicePropList *props; | ||
84 | + | ||
85 | + /* Private to qdev / bus. */ | ||
81 | qdev_initfn init; | 86 | qdev_initfn init; |
82 | BusType bus_type; | 87 | BusType bus_type; |
83 | - DevicePropList *props; | ||
84 | }; | 88 | }; |
85 | 89 | ||
86 | -void qdev_register(const char *name, int size, DeviceInfo *info); | 90 | +void qdev_register(DeviceInfo *info); |
87 | 91 | ||
88 | /* Register device properties. */ | 92 | /* Register device properties. */ |
89 | /* GPIO inputs also double as IRQ sinks. */ | 93 | /* GPIO inputs also double as IRQ sinks. */ |
hw/smbus.c
@@ -206,14 +206,14 @@ static void smbus_device_init(i2c_slave *i2c) | @@ -206,14 +206,14 @@ static void smbus_device_init(i2c_slave *i2c) | ||
206 | t->init(dev); | 206 | t->init(dev); |
207 | } | 207 | } |
208 | 208 | ||
209 | -void smbus_register_device(const char *name, int size, SMBusDeviceInfo *info) | 209 | +void smbus_register_device(SMBusDeviceInfo *info) |
210 | { | 210 | { |
211 | - assert(size >= sizeof(SMBusDevice)); | 211 | + assert(info->i2c.qdev.size >= sizeof(SMBusDevice)); |
212 | info->i2c.init = smbus_device_init; | 212 | info->i2c.init = smbus_device_init; |
213 | info->i2c.event = smbus_i2c_event; | 213 | info->i2c.event = smbus_i2c_event; |
214 | info->i2c.recv = smbus_i2c_recv; | 214 | info->i2c.recv = smbus_i2c_recv; |
215 | info->i2c.send = smbus_i2c_send; | 215 | info->i2c.send = smbus_i2c_send; |
216 | - i2c_register_slave(name, size, &info->i2c); | 216 | + i2c_register_slave(&info->i2c); |
217 | } | 217 | } |
218 | 218 | ||
219 | /* Master device commands. */ | 219 | /* Master device commands. */ |
hw/smbus.h
@@ -53,7 +53,7 @@ typedef struct { | @@ -53,7 +53,7 @@ typedef struct { | ||
53 | uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n); | 53 | uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n); |
54 | } SMBusDeviceInfo; | 54 | } SMBusDeviceInfo; |
55 | 55 | ||
56 | -void smbus_register_device(const char *name, int size, SMBusDeviceInfo *info); | 56 | +void smbus_register_device(SMBusDeviceInfo *info); |
57 | 57 | ||
58 | /* Master device commands. */ | 58 | /* Master device commands. */ |
59 | void smbus_quick_command(i2c_bus *bus, int addr, int read); | 59 | void smbus_quick_command(i2c_bus *bus, int addr, int read); |
hw/smbus_eeprom.c
@@ -105,6 +105,8 @@ static void smbus_eeprom_init(SMBusDevice *dev) | @@ -105,6 +105,8 @@ static void smbus_eeprom_init(SMBusDevice *dev) | ||
105 | } | 105 | } |
106 | 106 | ||
107 | static SMBusDeviceInfo smbus_eeprom_info = { | 107 | static SMBusDeviceInfo smbus_eeprom_info = { |
108 | + .i2c.qdev.name = "smbus-eeprom", | ||
109 | + .i2c.qdev.size = sizeof(SMBusEEPROMDevice), | ||
108 | .init = smbus_eeprom_init, | 110 | .init = smbus_eeprom_init, |
109 | .quick_cmd = eeprom_quick_cmd, | 111 | .quick_cmd = eeprom_quick_cmd, |
110 | .send_byte = eeprom_send_byte, | 112 | .send_byte = eeprom_send_byte, |
@@ -115,8 +117,7 @@ static SMBusDeviceInfo smbus_eeprom_info = { | @@ -115,8 +117,7 @@ static SMBusDeviceInfo smbus_eeprom_info = { | ||
115 | 117 | ||
116 | static void smbus_eeprom_register_devices(void) | 118 | static void smbus_eeprom_register_devices(void) |
117 | { | 119 | { |
118 | - smbus_register_device("smbus-eeprom", sizeof(SMBusEEPROMDevice), | ||
119 | - &smbus_eeprom_info); | 120 | + smbus_register_device(&smbus_eeprom_info); |
120 | } | 121 | } |
121 | 122 | ||
122 | device_init(smbus_eeprom_register_devices) | 123 | device_init(smbus_eeprom_register_devices) |
hw/spitz.c
@@ -1076,19 +1076,23 @@ static void spitz_machine_init(void) | @@ -1076,19 +1076,23 @@ static void spitz_machine_init(void) | ||
1076 | machine_init(spitz_machine_init); | 1076 | machine_init(spitz_machine_init); |
1077 | 1077 | ||
1078 | static SSISlaveInfo corgi_ssp_info = { | 1078 | static SSISlaveInfo corgi_ssp_info = { |
1079 | + .qdev.name = "corgi-ssp", | ||
1080 | + .qdev.size = sizeof(CorgiSSPState), | ||
1079 | .init = corgi_ssp_init, | 1081 | .init = corgi_ssp_init, |
1080 | .transfer = corgi_ssp_transfer | 1082 | .transfer = corgi_ssp_transfer |
1081 | }; | 1083 | }; |
1082 | 1084 | ||
1083 | static SSISlaveInfo spitz_lcdtg_info = { | 1085 | static SSISlaveInfo spitz_lcdtg_info = { |
1086 | + .qdev.name = "spitz-lcdtg", | ||
1087 | + .qdev.size = sizeof(SpitzLCDTG), | ||
1084 | .init = spitz_lcdtg_init, | 1088 | .init = spitz_lcdtg_init, |
1085 | .transfer = spitz_lcdtg_transfer | 1089 | .transfer = spitz_lcdtg_transfer |
1086 | }; | 1090 | }; |
1087 | 1091 | ||
1088 | static void spitz_register_devices(void) | 1092 | static void spitz_register_devices(void) |
1089 | { | 1093 | { |
1090 | - ssi_register_slave("corgi-ssp", sizeof(CorgiSSPState), &corgi_ssp_info); | ||
1091 | - ssi_register_slave("spitz-lcdtg", sizeof(SpitzLCDTG), &spitz_lcdtg_info); | 1094 | + ssi_register_slave(&corgi_ssp_info); |
1095 | + ssi_register_slave(&spitz_lcdtg_info); | ||
1092 | } | 1096 | } |
1093 | 1097 | ||
1094 | device_init(spitz_register_devices) | 1098 | device_init(spitz_register_devices) |
hw/ssd0303.c
@@ -316,6 +316,8 @@ static void ssd0303_init(i2c_slave *i2c) | @@ -316,6 +316,8 @@ static void ssd0303_init(i2c_slave *i2c) | ||
316 | } | 316 | } |
317 | 317 | ||
318 | static I2CSlaveInfo ssd0303_info = { | 318 | static I2CSlaveInfo ssd0303_info = { |
319 | + .qdev.name = "ssd0303", | ||
320 | + .qdev.size = sizeof(ssd0303_state), | ||
319 | .init = ssd0303_init, | 321 | .init = ssd0303_init, |
320 | .event = ssd0303_event, | 322 | .event = ssd0303_event, |
321 | .recv = ssd0303_recv, | 323 | .recv = ssd0303_recv, |
@@ -324,7 +326,7 @@ static I2CSlaveInfo ssd0303_info = { | @@ -324,7 +326,7 @@ static I2CSlaveInfo ssd0303_info = { | ||
324 | 326 | ||
325 | static void ssd0303_register_devices(void) | 327 | static void ssd0303_register_devices(void) |
326 | { | 328 | { |
327 | - i2c_register_slave("ssd0303", sizeof(ssd0303_state), &ssd0303_info); | 329 | + i2c_register_slave(&ssd0303_info); |
328 | } | 330 | } |
329 | 331 | ||
330 | device_init(ssd0303_register_devices) | 332 | device_init(ssd0303_register_devices) |
hw/ssd0323.c
@@ -339,13 +339,15 @@ static void ssd0323_init(SSISlave *dev) | @@ -339,13 +339,15 @@ static void ssd0323_init(SSISlave *dev) | ||
339 | } | 339 | } |
340 | 340 | ||
341 | static SSISlaveInfo ssd0323_info = { | 341 | static SSISlaveInfo ssd0323_info = { |
342 | + .qdev.name = "ssd0323", | ||
343 | + .qdev.size = sizeof(ssd0323_state), | ||
342 | .init = ssd0323_init, | 344 | .init = ssd0323_init, |
343 | .transfer = ssd0323_transfer | 345 | .transfer = ssd0323_transfer |
344 | }; | 346 | }; |
345 | 347 | ||
346 | static void ssd03232_register_devices(void) | 348 | static void ssd03232_register_devices(void) |
347 | { | 349 | { |
348 | - ssi_register_slave("ssd0323", sizeof(ssd0323_state), &ssd0323_info); | 350 | + ssi_register_slave(&ssd0323_info); |
349 | } | 351 | } |
350 | 352 | ||
351 | device_init(ssd03232_register_devices) | 353 | device_init(ssd03232_register_devices) |
hw/ssi-sd.c
@@ -241,13 +241,15 @@ static void ssi_sd_init(SSISlave *dev) | @@ -241,13 +241,15 @@ static void ssi_sd_init(SSISlave *dev) | ||
241 | } | 241 | } |
242 | 242 | ||
243 | static SSISlaveInfo ssi_sd_info = { | 243 | static SSISlaveInfo ssi_sd_info = { |
244 | + .qdev.name = "ssi-sd", | ||
245 | + .qdev.size = sizeof(ssi_sd_state), | ||
244 | .init = ssi_sd_init, | 246 | .init = ssi_sd_init, |
245 | .transfer = ssi_sd_transfer | 247 | .transfer = ssi_sd_transfer |
246 | }; | 248 | }; |
247 | 249 | ||
248 | static void ssi_sd_register_devices(void) | 250 | static void ssi_sd_register_devices(void) |
249 | { | 251 | { |
250 | - ssi_register_slave("ssi-sd", sizeof(ssi_sd_state), &ssi_sd_info); | 252 | + ssi_register_slave(&ssi_sd_info); |
251 | } | 253 | } |
252 | 254 | ||
253 | device_init(ssi_sd_register_devices) | 255 | device_init(ssi_sd_register_devices) |
hw/ssi.c
@@ -29,12 +29,12 @@ static void ssi_slave_init(DeviceState *dev, DeviceInfo *base_info) | @@ -29,12 +29,12 @@ static void ssi_slave_init(DeviceState *dev, DeviceInfo *base_info) | ||
29 | info->init(s); | 29 | info->init(s); |
30 | } | 30 | } |
31 | 31 | ||
32 | -void ssi_register_slave(const char *name, int size, SSISlaveInfo *info) | 32 | +void ssi_register_slave(SSISlaveInfo *info) |
33 | { | 33 | { |
34 | - assert(size >= sizeof(SSISlave)); | 34 | + assert(info->qdev.size >= sizeof(SSISlave)); |
35 | info->qdev.init = ssi_slave_init; | 35 | info->qdev.init = ssi_slave_init; |
36 | info->qdev.bus_type = BUS_TYPE_SSI; | 36 | info->qdev.bus_type = BUS_TYPE_SSI; |
37 | - qdev_register(name, size, &info->qdev); | 37 | + qdev_register(&info->qdev); |
38 | } | 38 | } |
39 | 39 | ||
40 | DeviceState *ssi_create_slave(SSIBus *bus, const char *name) | 40 | DeviceState *ssi_create_slave(SSIBus *bus, const char *name) |
hw/ssi.h
@@ -30,7 +30,7 @@ struct SSISlave { | @@ -30,7 +30,7 @@ struct SSISlave { | ||
30 | #define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev) | 30 | #define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev) |
31 | #define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev) | 31 | #define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev) |
32 | 32 | ||
33 | -void ssi_register_slave(const char *name, int size, SSISlaveInfo *info); | 33 | +void ssi_register_slave(SSISlaveInfo *info); |
34 | 34 | ||
35 | DeviceState *ssi_create_slave(SSIBus *bus, const char *name); | 35 | DeviceState *ssi_create_slave(SSIBus *bus, const char *name); |
36 | 36 |
hw/stellaris.c
@@ -1444,6 +1444,8 @@ static void stellaris_machine_init(void) | @@ -1444,6 +1444,8 @@ static void stellaris_machine_init(void) | ||
1444 | machine_init(stellaris_machine_init); | 1444 | machine_init(stellaris_machine_init); |
1445 | 1445 | ||
1446 | static SSISlaveInfo stellaris_ssi_bus_info = { | 1446 | static SSISlaveInfo stellaris_ssi_bus_info = { |
1447 | + .qdev.name = "evb6965-ssi", | ||
1448 | + .qdev.size = sizeof(stellaris_ssi_bus_state), | ||
1447 | .init = stellaris_ssi_bus_init, | 1449 | .init = stellaris_ssi_bus_init, |
1448 | .transfer = stellaris_ssi_bus_transfer | 1450 | .transfer = stellaris_ssi_bus_transfer |
1449 | }; | 1451 | }; |
@@ -1456,8 +1458,7 @@ static void stellaris_register_devices(void) | @@ -1456,8 +1458,7 @@ static void stellaris_register_devices(void) | ||
1456 | stellaris_gptm_init); | 1458 | stellaris_gptm_init); |
1457 | sysbus_register_dev("stellaris-adc", sizeof(stellaris_adc_state), | 1459 | sysbus_register_dev("stellaris-adc", sizeof(stellaris_adc_state), |
1458 | stellaris_adc_init); | 1460 | stellaris_adc_init); |
1459 | - ssi_register_slave("evb6965-ssi", sizeof(stellaris_ssi_bus_state), | ||
1460 | - &stellaris_ssi_bus_info); | 1461 | + ssi_register_slave(&stellaris_ssi_bus_info); |
1461 | } | 1462 | } |
1462 | 1463 | ||
1463 | device_init(stellaris_register_devices) | 1464 | device_init(stellaris_register_devices) |
hw/syborg_timer.c
@@ -228,18 +228,17 @@ static void syborg_timer_init(SysBusDevice *dev) | @@ -228,18 +228,17 @@ static void syborg_timer_init(SysBusDevice *dev) | ||
228 | 228 | ||
229 | static SysBusDeviceInfo syborg_timer_info = { | 229 | static SysBusDeviceInfo syborg_timer_info = { |
230 | .init = syborg_timer_init, | 230 | .init = syborg_timer_init, |
231 | - .qdev = { | ||
232 | - .props = (DevicePropList[]) { | ||
233 | - {.name = "frequency", .type = PROP_TYPE_INT}, | ||
234 | - {.name = NULL} | ||
235 | - } | 231 | + .qdev.name = "syborg,timer", |
232 | + .qdev.size = sizeof(SyborgTimerState), | ||
233 | + .qdev.props = (DevicePropList[]) { | ||
234 | + {.name = "frequency", .type = PROP_TYPE_INT}, | ||
235 | + {.name = NULL} | ||
236 | } | 236 | } |
237 | }; | 237 | }; |
238 | 238 | ||
239 | static void syborg_timer_register_devices(void) | 239 | static void syborg_timer_register_devices(void) |
240 | { | 240 | { |
241 | - sysbus_register_withprop("syborg,timer", sizeof(SyborgTimerState), | ||
242 | - &syborg_timer_info); | 241 | + sysbus_register_withprop(&syborg_timer_info); |
243 | } | 242 | } |
244 | 243 | ||
245 | device_init(syborg_timer_register_devices) | 244 | device_init(syborg_timer_register_devices) |
hw/sysbus.c
@@ -105,14 +105,13 @@ static void sysbus_device_init(DeviceState *dev, DeviceInfo *base) | @@ -105,14 +105,13 @@ static void sysbus_device_init(DeviceState *dev, DeviceInfo *base) | ||
105 | info->init(sysbus_from_qdev(dev)); | 105 | info->init(sysbus_from_qdev(dev)); |
106 | } | 106 | } |
107 | 107 | ||
108 | -void sysbus_register_withprop(const char *name, size_t size, | ||
109 | - SysBusDeviceInfo *info) | 108 | +void sysbus_register_withprop(SysBusDeviceInfo *info) |
110 | { | 109 | { |
111 | info->qdev.init = sysbus_device_init; | 110 | info->qdev.init = sysbus_device_init; |
112 | info->qdev.bus_type = BUS_TYPE_SYSTEM; | 111 | info->qdev.bus_type = BUS_TYPE_SYSTEM; |
113 | 112 | ||
114 | - assert(size >= sizeof(SysBusDevice)); | ||
115 | - qdev_register(name, size, &info->qdev); | 113 | + assert(info->qdev.size >= sizeof(SysBusDevice)); |
114 | + qdev_register(&info->qdev); | ||
116 | } | 115 | } |
117 | 116 | ||
118 | void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init) | 117 | void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init) |
@@ -120,8 +119,10 @@ void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init) | @@ -120,8 +119,10 @@ void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init) | ||
120 | SysBusDeviceInfo *info; | 119 | SysBusDeviceInfo *info; |
121 | 120 | ||
122 | info = qemu_mallocz(sizeof(*info)); | 121 | info = qemu_mallocz(sizeof(*info)); |
122 | + info->qdev.name = qemu_strdup(name); | ||
123 | + info->qdev.size = size; | ||
123 | info->init = init; | 124 | info->init = init; |
124 | - sysbus_register_withprop(name, size, info); | 125 | + sysbus_register_withprop(info); |
125 | } | 126 | } |
126 | 127 | ||
127 | DeviceState *sysbus_create_varargs(const char *name, | 128 | DeviceState *sysbus_create_varargs(const char *name, |
hw/sysbus.h
@@ -37,8 +37,7 @@ typedef struct { | @@ -37,8 +37,7 @@ typedef struct { | ||
37 | } SysBusDeviceInfo; | 37 | } SysBusDeviceInfo; |
38 | 38 | ||
39 | void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init); | 39 | void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init); |
40 | -void sysbus_register_withprop(const char *name, size_t size, | ||
41 | - SysBusDeviceInfo *info); | 40 | +void sysbus_register_withprop(SysBusDeviceInfo *info); |
42 | void *sysbus_new(void); | 41 | void *sysbus_new(void); |
43 | void sysbus_init_mmio(SysBusDevice *dev, target_phys_addr_t size, int iofunc); | 42 | void sysbus_init_mmio(SysBusDevice *dev, target_phys_addr_t size, int iofunc); |
44 | void sysbus_init_mmio_cb(SysBusDevice *dev, target_phys_addr_t size, | 43 | void sysbus_init_mmio_cb(SysBusDevice *dev, target_phys_addr_t size, |
hw/tmp105.c
@@ -239,6 +239,8 @@ static void tmp105_init(i2c_slave *i2c) | @@ -239,6 +239,8 @@ static void tmp105_init(i2c_slave *i2c) | ||
239 | } | 239 | } |
240 | 240 | ||
241 | static I2CSlaveInfo tmp105_info = { | 241 | static I2CSlaveInfo tmp105_info = { |
242 | + .qdev.name = "tmp105", | ||
243 | + .qdev.size = sizeof(TMP105State), | ||
242 | .init = tmp105_init, | 244 | .init = tmp105_init, |
243 | .event = tmp105_event, | 245 | .event = tmp105_event, |
244 | .recv = tmp105_rx, | 246 | .recv = tmp105_rx, |
@@ -247,7 +249,7 @@ static I2CSlaveInfo tmp105_info = { | @@ -247,7 +249,7 @@ static I2CSlaveInfo tmp105_info = { | ||
247 | 249 | ||
248 | static void tmp105_register_devices(void) | 250 | static void tmp105_register_devices(void) |
249 | { | 251 | { |
250 | - i2c_register_slave("tmp105", sizeof(TMP105State), &tmp105_info); | 252 | + i2c_register_slave(&tmp105_info); |
251 | } | 253 | } |
252 | 254 | ||
253 | device_init(tmp105_register_devices) | 255 | device_init(tmp105_register_devices) |
hw/tosa.c
@@ -252,6 +252,8 @@ static void tosapda_machine_init(void) | @@ -252,6 +252,8 @@ static void tosapda_machine_init(void) | ||
252 | machine_init(tosapda_machine_init); | 252 | machine_init(tosapda_machine_init); |
253 | 253 | ||
254 | static I2CSlaveInfo tosa_dac_info = { | 254 | static I2CSlaveInfo tosa_dac_info = { |
255 | + .qdev.name = "tosa_dac", | ||
256 | + .qdev.size = sizeof(TosaDACState), | ||
255 | .init = tosa_dac_init, | 257 | .init = tosa_dac_init, |
256 | .event = tosa_dac_event, | 258 | .event = tosa_dac_event, |
257 | .recv = tosa_dac_recv, | 259 | .recv = tosa_dac_recv, |
@@ -259,14 +261,16 @@ static I2CSlaveInfo tosa_dac_info = { | @@ -259,14 +261,16 @@ static I2CSlaveInfo tosa_dac_info = { | ||
259 | }; | 261 | }; |
260 | 262 | ||
261 | static SSISlaveInfo tosa_ssp_info = { | 263 | static SSISlaveInfo tosa_ssp_info = { |
264 | + .qdev.name = "tosa-ssp", | ||
265 | + .qdev.size = sizeof(SSISlave), | ||
262 | .init = tosa_ssp_init, | 266 | .init = tosa_ssp_init, |
263 | .transfer = tosa_ssp_tansfer | 267 | .transfer = tosa_ssp_tansfer |
264 | }; | 268 | }; |
265 | 269 | ||
266 | static void tosa_register_devices(void) | 270 | static void tosa_register_devices(void) |
267 | { | 271 | { |
268 | - i2c_register_slave("tosa_dac", sizeof(TosaDACState), &tosa_dac_info); | ||
269 | - ssi_register_slave("tosa-ssp", sizeof(SSISlave), &tosa_ssp_info); | 272 | + i2c_register_slave(&tosa_dac_info); |
273 | + ssi_register_slave(&tosa_ssp_info); | ||
270 | } | 274 | } |
271 | 275 | ||
272 | device_init(tosa_register_devices) | 276 | device_init(tosa_register_devices) |
hw/twl92230.c
@@ -892,6 +892,8 @@ static void twl92230_init(i2c_slave *i2c) | @@ -892,6 +892,8 @@ static void twl92230_init(i2c_slave *i2c) | ||
892 | } | 892 | } |
893 | 893 | ||
894 | static I2CSlaveInfo twl92230_info = { | 894 | static I2CSlaveInfo twl92230_info = { |
895 | + .qdev.name ="twl92230", | ||
896 | + .qdev.size = sizeof(MenelausState), | ||
895 | .init = twl92230_init, | 897 | .init = twl92230_init, |
896 | .event = menelaus_event, | 898 | .event = menelaus_event, |
897 | .recv = menelaus_rx, | 899 | .recv = menelaus_rx, |
@@ -900,7 +902,7 @@ static I2CSlaveInfo twl92230_info = { | @@ -900,7 +902,7 @@ static I2CSlaveInfo twl92230_info = { | ||
900 | 902 | ||
901 | static void twl92230_register_devices(void) | 903 | static void twl92230_register_devices(void) |
902 | { | 904 | { |
903 | - i2c_register_slave("twl92230", sizeof(MenelausState), &twl92230_info); | 905 | + i2c_register_slave(&twl92230_info); |
904 | } | 906 | } |
905 | 907 | ||
906 | device_init(twl92230_register_devices) | 908 | device_init(twl92230_register_devices) |
hw/wm8750.c
@@ -726,6 +726,8 @@ void wm8750_set_bclk_in(void *opaque, int new_hz) | @@ -726,6 +726,8 @@ void wm8750_set_bclk_in(void *opaque, int new_hz) | ||
726 | } | 726 | } |
727 | 727 | ||
728 | static I2CSlaveInfo wm8750_info = { | 728 | static I2CSlaveInfo wm8750_info = { |
729 | + .qdev.name = "wm8750", | ||
730 | + .qdev.size = sizeof(WM8750State), | ||
729 | .init = wm8750_init, | 731 | .init = wm8750_init, |
730 | .event = wm8750_event, | 732 | .event = wm8750_event, |
731 | .recv = wm8750_rx, | 733 | .recv = wm8750_rx, |
@@ -734,7 +736,7 @@ static I2CSlaveInfo wm8750_info = { | @@ -734,7 +736,7 @@ static I2CSlaveInfo wm8750_info = { | ||
734 | 736 | ||
735 | static void wm8750_register_devices(void) | 737 | static void wm8750_register_devices(void) |
736 | { | 738 | { |
737 | - i2c_register_slave("wm8750", sizeof(WM8750State), &wm8750_info); | 739 | + i2c_register_slave(&wm8750_info); |
738 | } | 740 | } |
739 | 741 | ||
740 | device_init(wm8750_register_devices) | 742 | device_init(wm8750_register_devices) |