Revision ee6847d1 hw/qdev.h
b/hw/qdev.h | ||
---|---|---|
4 | 4 |
#include "hw.h" |
5 | 5 |
#include "sys-queue.h" |
6 | 6 |
|
7 |
typedef struct DeviceInfo DeviceInfo; |
|
7 |
typedef struct Property Property; |
|
8 |
|
|
9 |
typedef struct PropertyInfo PropertyInfo; |
|
8 | 10 |
|
9 |
typedef struct DeviceProperty DeviceProperty;
|
|
11 |
typedef struct DeviceInfo DeviceInfo;
|
|
10 | 12 |
|
11 | 13 |
typedef struct BusState BusState; |
12 | 14 |
|
... | ... | |
17 | 19 |
struct DeviceState { |
18 | 20 |
DeviceInfo *info; |
19 | 21 |
BusState *parent_bus; |
20 |
DeviceProperty *props; |
|
21 | 22 |
int num_gpio_out; |
22 | 23 |
qemu_irq *gpio_out; |
23 | 24 |
int num_gpio_in; |
... | ... | |
32 | 33 |
const char *name; |
33 | 34 |
size_t size; |
34 | 35 |
bus_dev_printfn print_dev; |
36 |
Property *props; |
|
35 | 37 |
}; |
36 | 38 |
|
37 | 39 |
struct BusState { |
... | ... | |
42 | 44 |
LIST_ENTRY(BusState) sibling; |
43 | 45 |
}; |
44 | 46 |
|
47 |
struct Property { |
|
48 |
const char *name; |
|
49 |
PropertyInfo *info; |
|
50 |
int offset; |
|
51 |
void *defval; |
|
52 |
}; |
|
53 |
|
|
54 |
enum PropertyType { |
|
55 |
PROP_TYPE_UNSPEC = 0, |
|
56 |
PROP_TYPE_UINT16, |
|
57 |
PROP_TYPE_UINT32, |
|
58 |
PROP_TYPE_TADDR, |
|
59 |
PROP_TYPE_MACADDR, |
|
60 |
PROP_TYPE_PTR, |
|
61 |
}; |
|
62 |
|
|
63 |
struct PropertyInfo { |
|
64 |
const char *name; |
|
65 |
size_t size; |
|
66 |
enum PropertyType type; |
|
67 |
int (*parse)(DeviceState *dev, Property *prop, const char *str); |
|
68 |
int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); |
|
69 |
}; |
|
70 |
|
|
45 | 71 |
/*** Board API. This should go away once we have a machine config file. ***/ |
46 | 72 |
|
47 | 73 |
DeviceState *qdev_create(BusState *bus, const char *name); |
48 | 74 |
void qdev_init(DeviceState *dev); |
49 | 75 |
void qdev_free(DeviceState *dev); |
50 | 76 |
|
51 |
/* Set properties between creation and init. */ |
|
52 |
void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value); |
|
53 |
void qdev_set_prop_dev(DeviceState *dev, const char *name, DeviceState *value); |
|
54 |
void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value); |
|
55 |
void qdev_set_netdev(DeviceState *dev, NICInfo *nd); |
|
56 |
|
|
57 | 77 |
qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); |
58 | 78 |
void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); |
59 | 79 |
|
... | ... | |
61 | 81 |
|
62 | 82 |
/*** Device API. ***/ |
63 | 83 |
|
64 |
typedef enum { |
|
65 |
PROP_TYPE_INT, |
|
66 |
PROP_TYPE_PTR, |
|
67 |
PROP_TYPE_DEV |
|
68 |
} DevicePropType; |
|
69 |
|
|
70 |
typedef struct { |
|
71 |
const char *name; |
|
72 |
DevicePropType type; |
|
73 |
} DevicePropList; |
|
74 |
|
|
75 | 84 |
typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info); |
76 | 85 |
typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv, |
77 | 86 |
int unit); |
... | ... | |
79 | 88 |
struct DeviceInfo { |
80 | 89 |
const char *name; |
81 | 90 |
size_t size; |
82 |
DevicePropList *props;
|
|
91 |
Property *props;
|
|
83 | 92 |
|
84 | 93 |
/* Private to qdev / bus. */ |
85 | 94 |
qdev_initfn init; |
... | ... | |
99 | 108 |
CharDriverState *qdev_init_chardev(DeviceState *dev); |
100 | 109 |
|
101 | 110 |
BusState *qdev_get_parent_bus(DeviceState *dev); |
102 |
uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def); |
|
103 |
DeviceState *qdev_get_prop_dev(DeviceState *dev, const char *name); |
|
104 |
/* FIXME: Remove opaque pointer properties. */ |
|
105 |
void *qdev_get_prop_ptr(DeviceState *dev, const char *name); |
|
106 | 111 |
|
107 | 112 |
/* Convery from a base type to a parent type, with compile time checking. */ |
108 | 113 |
#ifdef __GNUC__ |
... | ... | |
124 | 129 |
|
125 | 130 |
void do_info_qtree(Monitor *mon); |
126 | 131 |
|
132 |
/*** qdev-properties.c ***/ |
|
133 |
|
|
134 |
extern PropertyInfo qdev_prop_uint16; |
|
135 |
extern PropertyInfo qdev_prop_uint32; |
|
136 |
extern PropertyInfo qdev_prop_hex32; |
|
137 |
extern PropertyInfo qdev_prop_ptr; |
|
138 |
extern PropertyInfo qdev_prop_macaddr; |
|
139 |
|
|
140 |
/* Set properties between creation and init. */ |
|
141 |
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop); |
|
142 |
int qdev_prop_parse(DeviceState *dev, const char *name, const char *value); |
|
143 |
void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type); |
|
144 |
void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); |
|
145 |
void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); |
|
146 |
/* FIXME: Remove opaque pointer properties. */ |
|
147 |
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); |
|
148 |
void qdev_prop_set_defaults(DeviceState *dev, Property *props); |
|
149 |
|
|
127 | 150 |
#endif |
Also available in: Unified diff