qdev scsi bus infrastructure
[qemu] / hw / qdev.h
1 #ifndef QDEV_H
2 #define QDEV_H
3
4 #include "hw.h"
5
6 typedef struct DeviceType DeviceType;
7
8 typedef struct DeviceProperty DeviceProperty;
9
10 typedef struct ChildBusList ChildBusList;
11
12 /* This structure should not be accessed directly.  We declare it here
13    so that it can be embedded in individual device state structures.  */
14 struct DeviceState
15 {
16     const char *name;
17     DeviceType *type;
18     void *bus;
19     DeviceProperty *props;
20     int num_irq_sink;
21     qemu_irq *irq_sink;
22     int num_gpio_out;
23     qemu_irq *gpio_out;
24     int num_gpio_in;
25     qemu_irq *gpio_in;
26     ChildBusList *child_bus;
27 };
28
29 /*** Board API.  This should go away once we have a machine config file.  ***/
30
31 DeviceState *qdev_create(void *bus, const char *name);
32 void qdev_init(DeviceState *dev);
33
34 /* Set properties between creation and init.  */
35 void qdev_set_prop_int(DeviceState *dev, const char *name, int value);
36 void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value);
37
38 qemu_irq qdev_get_irq_sink(DeviceState *dev, int n);
39 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
40 void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
41
42 void *qdev_get_child_bus(DeviceState *dev, const char *name);
43
44 /*** Device API.  ***/
45
46 typedef void (*qdev_initfn)(DeviceState *dev, void *opaque);
47 typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
48               int unit);
49
50 DeviceType *qdev_register(const char *name, int size, qdev_initfn init,
51                           void *opaque);
52
53 /* Register device properties.  */
54 void qdev_init_irq_sink(DeviceState *dev, qemu_irq_handler handler, int nirq);
55 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
56 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
57 void qdev_attach_child_bus(DeviceState *dev, const char *name, void *bus);
58
59 void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
60
61 CharDriverState *qdev_init_chardev(DeviceState *dev);
62
63 void *qdev_get_bus(DeviceState *dev);
64 uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def);
65 void *qdev_get_prop_ptr(DeviceState *dev, const char *name);
66
67 /* Convery from a base type to a parent type, with compile time checking.  */
68 #ifdef __GNUC__
69 #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
70     char __attribute__((unused)) offset_must_be_zero[ \
71         -offsetof(type, field)]; \
72     container_of(dev, type, field);}))
73 #else
74 #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
75 #endif
76
77 #endif