root / include / hw / qdev-properties.h @ 3bd88451
History | View | Annotate | Download (9.1 kB)
1 |
#ifndef QEMU_QDEV_PROPERTIES_H
|
---|---|
2 |
#define QEMU_QDEV_PROPERTIES_H
|
3 |
|
4 |
#include "hw/qdev-core.h" |
5 |
|
6 |
/*** qdev-properties.c ***/
|
7 |
|
8 |
extern PropertyInfo qdev_prop_bit;
|
9 |
extern PropertyInfo qdev_prop_uint8;
|
10 |
extern PropertyInfo qdev_prop_uint16;
|
11 |
extern PropertyInfo qdev_prop_uint32;
|
12 |
extern PropertyInfo qdev_prop_int32;
|
13 |
extern PropertyInfo qdev_prop_uint64;
|
14 |
extern PropertyInfo qdev_prop_hex8;
|
15 |
extern PropertyInfo qdev_prop_hex32;
|
16 |
extern PropertyInfo qdev_prop_hex64;
|
17 |
extern PropertyInfo qdev_prop_string;
|
18 |
extern PropertyInfo qdev_prop_chr;
|
19 |
extern PropertyInfo qdev_prop_ptr;
|
20 |
extern PropertyInfo qdev_prop_macaddr;
|
21 |
extern PropertyInfo qdev_prop_losttickpolicy;
|
22 |
extern PropertyInfo qdev_prop_bios_chs_trans;
|
23 |
extern PropertyInfo qdev_prop_drive;
|
24 |
extern PropertyInfo qdev_prop_netdev;
|
25 |
extern PropertyInfo qdev_prop_vlan;
|
26 |
extern PropertyInfo qdev_prop_pci_devfn;
|
27 |
extern PropertyInfo qdev_prop_blocksize;
|
28 |
extern PropertyInfo qdev_prop_pci_host_devaddr;
|
29 |
extern PropertyInfo qdev_prop_arraylen;
|
30 |
|
31 |
#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
|
32 |
.name = (_name), \ |
33 |
.info = &(_prop), \ |
34 |
.offset = offsetof(_state, _field) \ |
35 |
+ type_check(_type, typeof_field(_state, _field)), \ |
36 |
} |
37 |
#define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
|
38 |
.name = (_name), \ |
39 |
.info = &(_prop), \ |
40 |
.offset = offsetof(_state, _field) \ |
41 |
+ type_check(_type,typeof_field(_state, _field)), \ |
42 |
.qtype = QTYPE_QINT, \ |
43 |
.defval = (_type)_defval, \ |
44 |
} |
45 |
#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
|
46 |
.name = (_name), \ |
47 |
.info = &(qdev_prop_bit), \ |
48 |
.bitnr = (_bit), \ |
49 |
.offset = offsetof(_state, _field) \ |
50 |
+ type_check(uint32_t,typeof_field(_state, _field)), \ |
51 |
.qtype = QTYPE_QBOOL, \ |
52 |
.defval = (bool)_defval, \
|
53 |
} |
54 |
|
55 |
#define PROP_ARRAY_LEN_PREFIX "len-" |
56 |
|
57 |
/**
|
58 |
* DEFINE_PROP_ARRAY:
|
59 |
* @_name: name of the array
|
60 |
* @_state: name of the device state structure type
|
61 |
* @_field: uint32_t field in @_state to hold the array length
|
62 |
* @_arrayfield: field in @_state (of type '@_arraytype *') which
|
63 |
* will point to the array
|
64 |
* @_arrayprop: PropertyInfo defining what property the array elements have
|
65 |
* @_arraytype: C type of the array elements
|
66 |
*
|
67 |
* Define device properties for a variable-length array _name. A
|
68 |
* static property "len-arrayname" is defined. When the device creator
|
69 |
* sets this property to the desired length of array, further dynamic
|
70 |
* properties "arrayname[0]", "arrayname[1]", ... are defined so the
|
71 |
* device creator can set the array element values. Setting the
|
72 |
* "len-arrayname" property more than once is an error.
|
73 |
*
|
74 |
* When the array length is set, the @_field member of the device
|
75 |
* struct is set to the array length, and @_arrayfield is set to point
|
76 |
* to (zero-initialised) memory allocated for the array. For a zero
|
77 |
* length array, @_field will be set to 0 and @_arrayfield to NULL.
|
78 |
* It is the responsibility of the device deinit code to free the
|
79 |
* @_arrayfield memory.
|
80 |
*/
|
81 |
#define DEFINE_PROP_ARRAY(_name, _state, _field, \
|
82 |
_arrayfield, _arrayprop, _arraytype) { \ |
83 |
.name = (PROP_ARRAY_LEN_PREFIX _name), \ |
84 |
.info = &(qdev_prop_arraylen), \ |
85 |
.offset = offsetof(_state, _field) \ |
86 |
+ type_check(uint32_t, typeof_field(_state, _field)), \ |
87 |
.qtype = QTYPE_QINT, \ |
88 |
.arrayinfo = &(_arrayprop), \ |
89 |
.arrayfieldsize = sizeof(_arraytype), \
|
90 |
.arrayoffset = offsetof(_state, _arrayfield), \ |
91 |
} |
92 |
|
93 |
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
|
94 |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t) |
95 |
#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
|
96 |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t) |
97 |
#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
|
98 |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t) |
99 |
#define DEFINE_PROP_INT32(_n, _s, _f, _d) \
|
100 |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t) |
101 |
#define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
|
102 |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t) |
103 |
#define DEFINE_PROP_HEX8(_n, _s, _f, _d) \
|
104 |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex8, uint8_t) |
105 |
#define DEFINE_PROP_HEX32(_n, _s, _f, _d) \
|
106 |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t) |
107 |
#define DEFINE_PROP_HEX64(_n, _s, _f, _d) \
|
108 |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t) |
109 |
#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
|
110 |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t) |
111 |
|
112 |
#define DEFINE_PROP_PTR(_n, _s, _f) \
|
113 |
DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
|
114 |
#define DEFINE_PROP_CHR(_n, _s, _f) \
|
115 |
DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*) |
116 |
#define DEFINE_PROP_STRING(_n, _s, _f) \
|
117 |
DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
|
118 |
#define DEFINE_PROP_NETDEV(_n, _s, _f) \
|
119 |
DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers) |
120 |
#define DEFINE_PROP_VLAN(_n, _s, _f) \
|
121 |
DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NICPeers) |
122 |
#define DEFINE_PROP_DRIVE(_n, _s, _f) \
|
123 |
DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *) |
124 |
#define DEFINE_PROP_MACADDR(_n, _s, _f) \
|
125 |
DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) |
126 |
#define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
|
127 |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \ |
128 |
LostTickPolicy) |
129 |
#define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
|
130 |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
|
131 |
#define DEFINE_PROP_BLOCKSIZE(_n, _s, _f, _d) \
|
132 |
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t) |
133 |
#define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
|
134 |
DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress) |
135 |
|
136 |
#define DEFINE_PROP_END_OF_LIST() \
|
137 |
{} |
138 |
|
139 |
/* Set properties between creation and init. */
|
140 |
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
|
141 |
int qdev_prop_parse(DeviceState *dev, const char *name, const char *value); |
142 |
void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value); |
143 |
void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value); |
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 |
void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value); |
147 |
void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value); |
148 |
void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value); |
149 |
void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value); |
150 |
void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value); |
151 |
int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT; |
152 |
void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value); |
153 |
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value); |
154 |
void qdev_prop_set_enum(DeviceState *dev, const char *name, int value); |
155 |
/* FIXME: Remove opaque pointer properties. */
|
156 |
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); |
157 |
|
158 |
void qdev_prop_register_global(GlobalProperty *prop);
|
159 |
void qdev_prop_register_global_list(GlobalProperty *props);
|
160 |
void qdev_prop_set_globals(DeviceState *dev);
|
161 |
void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, |
162 |
Property *prop, const char *value); |
163 |
|
164 |
/**
|
165 |
* @qdev_property_add_static - add a @Property to a device referencing a
|
166 |
* field in a struct.
|
167 |
*/
|
168 |
void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
|
169 |
|
170 |
/**
|
171 |
* @qdev_prop_set_after_realize:
|
172 |
* @dev: device
|
173 |
* @name: name of property
|
174 |
* @errp: indirect pointer to Error to be set
|
175 |
* Set the Error object to report that an attempt was made to set a property
|
176 |
* on a device after it has already been realized. This is a utility function
|
177 |
* which allows property-setter functions to easily report the error in
|
178 |
* a friendly format identifying both the device and the property.
|
179 |
*/
|
180 |
void qdev_prop_set_after_realize(DeviceState *dev, const char *name, |
181 |
Error **errp); |
182 |
#endif
|