qdev: add no_user, alias and desc
[qemu] / hw / qdev.h
1 #ifndef QDEV_H
2 #define QDEV_H
3
4 #include "hw.h"
5 #include "sys-queue.h"
6
7 typedef struct Property Property;
8
9 typedef struct PropertyInfo PropertyInfo;
10
11 typedef struct CompatProperty CompatProperty;
12
13 typedef struct DeviceInfo DeviceInfo;
14
15 typedef struct BusState BusState;
16
17 typedef struct BusInfo BusInfo;
18
19 /* This structure should not be accessed directly.  We declare it here
20    so that it can be embedded in individual device state structures.  */
21 struct DeviceState {
22     DeviceInfo *info;
23     BusState *parent_bus;
24     int num_gpio_out;
25     qemu_irq *gpio_out;
26     int num_gpio_in;
27     qemu_irq *gpio_in;
28     LIST_HEAD(, BusState) child_bus;
29     NICInfo *nd;
30     LIST_ENTRY(DeviceState) sibling;
31 };
32
33 typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
34 struct BusInfo {
35     const char *name;
36     size_t size;
37     bus_dev_printfn print_dev;
38     Property *props;
39 };
40
41 struct BusState {
42     DeviceState *parent;
43     BusInfo *info;
44     const char *name;
45     LIST_HEAD(, DeviceState) children;
46     LIST_ENTRY(BusState) sibling;
47 };
48
49 struct Property {
50     const char   *name;
51     PropertyInfo *info;
52     int          offset;
53     void         *defval;
54 };
55
56 enum PropertyType {
57     PROP_TYPE_UNSPEC = 0,
58     PROP_TYPE_UINT16,
59     PROP_TYPE_UINT32,
60     PROP_TYPE_TADDR,
61     PROP_TYPE_MACADDR,
62     PROP_TYPE_PTR,
63 };
64
65 struct PropertyInfo {
66     const char *name;
67     size_t size;
68     enum PropertyType type;
69     int (*parse)(DeviceState *dev, Property *prop, const char *str);
70     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
71 };
72
73 struct CompatProperty {
74     const char *driver;
75     const char *property;
76     const char *value;
77 };
78
79 /*** Board API.  This should go away once we have a machine config file.  ***/
80
81 DeviceState *qdev_create(BusState *bus, const char *name);
82 void qdev_init(DeviceState *dev);
83 void qdev_free(DeviceState *dev);
84
85 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
86 void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
87
88 BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
89
90 /*** Device API.  ***/
91
92 typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
93 typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
94               int unit);
95
96 struct DeviceInfo {
97     const char *name;
98     const char *alias;
99     const char *desc;
100     size_t size;
101     Property *props;
102     int no_user;
103
104     /* Private to qdev / bus.  */
105     qdev_initfn init;
106     BusInfo *bus_info;
107     struct DeviceInfo *next;
108 };
109
110 void qdev_register(DeviceInfo *info);
111
112 /* Register device properties.  */
113 /* GPIO inputs also double as IRQ sinks.  */
114 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
115 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
116
117 void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
118
119 CharDriverState *qdev_init_chardev(DeviceState *dev);
120
121 BusState *qdev_get_parent_bus(DeviceState *dev);
122
123 /* Convery from a base type to a parent type, with compile time checking.  */
124 #ifdef __GNUC__
125 #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
126     char __attribute__((unused)) offset_must_be_zero[ \
127         -offsetof(type, field)]; \
128     container_of(dev, type, field);}))
129 #else
130 #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
131 #endif
132
133 /*** BUS API. ***/
134
135 BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);
136
137 #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
138
139 /*** monitor commands ***/
140
141 void do_info_qtree(Monitor *mon);
142
143 /*** qdev-properties.c ***/
144
145 extern PropertyInfo qdev_prop_uint16;
146 extern PropertyInfo qdev_prop_uint32;
147 extern PropertyInfo qdev_prop_hex32;
148 extern PropertyInfo qdev_prop_ptr;
149 extern PropertyInfo qdev_prop_macaddr;
150
151 /* Set properties between creation and init.  */
152 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
153 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
154 void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type);
155 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
156 void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
157 /* FIXME: Remove opaque pointer properties.  */
158 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
159 void qdev_prop_set_defaults(DeviceState *dev, Property *props);
160
161 void qdev_prop_register_compat(CompatProperty *props);
162 void qdev_prop_set_compat(DeviceState *dev);
163
164 #endif