Commit 4d6ae6741e4fb3bf809466a5afaa7f5183dc6ffd

Authored by Paul Brook
1 parent aae9460e

qdev child bus support

Signed-off-by: Paul Brook <paul@codesourcery.com>
Showing 2 changed files with 36 additions and 0 deletions
hw/qdev.c
@@ -46,6 +46,12 @@ struct DeviceType { @@ -46,6 +46,12 @@ struct DeviceType {
46 DeviceType *next; 46 DeviceType *next;
47 }; 47 };
48 48
  49 +struct ChildBusList {
  50 + const char *name;
  51 + void *ptr;
  52 + ChildBusList *next;
  53 +};
  54 +
49 static DeviceType *device_type_list; 55 static DeviceType *device_type_list;
50 56
51 /* Register a new device type. */ 57 /* Register a new device type. */
@@ -235,3 +241,27 @@ BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type) @@ -235,3 +241,27 @@ BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type)
235 } 241 }
236 return drives_table[index].bdrv; 242 return drives_table[index].bdrv;
237 } 243 }
  244 +
  245 +void *qdev_get_child_bus(DeviceState *dev, const char *name)
  246 +{
  247 + ChildBusList *bus;
  248 +
  249 + for (bus = dev->child_bus; bus; bus = bus->next) {
  250 + if (strcmp(name, bus->name) == 0) {
  251 + return bus->ptr;
  252 + }
  253 + }
  254 + return NULL;
  255 +}
  256 +
  257 +void qdev_attach_child_bus(DeviceState *dev, const char *name, void *bus)
  258 +{
  259 + ChildBusList *p;
  260 +
  261 + assert(!qdev_get_child_bus(dev, name));
  262 + p = qemu_mallocz(sizeof(*p));
  263 + p->name = qemu_strdup(name);
  264 + p->ptr = bus;
  265 + p->next = dev->child_bus;
  266 + dev->child_bus = p;
  267 +}
hw/qdev.h
@@ -7,6 +7,8 @@ typedef struct DeviceType DeviceType; @@ -7,6 +7,8 @@ typedef struct DeviceType DeviceType;
7 7
8 typedef struct DeviceProperty DeviceProperty; 8 typedef struct DeviceProperty DeviceProperty;
9 9
  10 +typedef struct ChildBusList ChildBusList;
  11 +
10 /* This structure should not be accessed directly. We declare it here 12 /* This structure should not be accessed directly. We declare it here
11 so that it can be embedded in individual device state structures. */ 13 so that it can be embedded in individual device state structures. */
12 struct DeviceState 14 struct DeviceState
@@ -21,6 +23,7 @@ struct DeviceState @@ -21,6 +23,7 @@ struct DeviceState
21 qemu_irq *gpio_out; 23 qemu_irq *gpio_out;
22 int num_gpio_in; 24 int num_gpio_in;
23 qemu_irq *gpio_in; 25 qemu_irq *gpio_in;
  26 + ChildBusList *child_bus;
24 }; 27 };
25 28
26 /*** Board API. This should go away once we have a machine config file. ***/ 29 /*** Board API. This should go away once we have a machine config file. ***/
@@ -36,6 +39,8 @@ qemu_irq qdev_get_irq_sink(DeviceState *dev, int n); @@ -36,6 +39,8 @@ qemu_irq qdev_get_irq_sink(DeviceState *dev, int n);
36 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); 39 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
37 void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); 40 void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
38 41
  42 +void *qdev_get_child_bus(DeviceState *dev, const char *name);
  43 +
39 /*** Device API. ***/ 44 /*** Device API. ***/
40 45
41 typedef void (*qdev_initfn)(DeviceState *dev, void *opaque); 46 typedef void (*qdev_initfn)(DeviceState *dev, void *opaque);
@@ -47,6 +52,7 @@ DeviceType *qdev_register(const char *name, int size, qdev_initfn init, @@ -47,6 +52,7 @@ DeviceType *qdev_register(const char *name, int size, qdev_initfn init,
47 void qdev_init_irq_sink(DeviceState *dev, qemu_irq_handler handler, int nirq); 52 void qdev_init_irq_sink(DeviceState *dev, qemu_irq_handler handler, int nirq);
48 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); 53 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
49 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); 54 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
  55 +void qdev_attach_child_bus(DeviceState *dev, const char *name, void *bus);
50 56
51 CharDriverState *qdev_init_chardev(DeviceState *dev); 57 CharDriverState *qdev_init_chardev(DeviceState *dev);
52 58