]>
Commit | Line | Data |
---|---|---|
074a86fc AL |
1 | #ifndef QEMU_QDEV_PROPERTIES_H |
2 | #define QEMU_QDEV_PROPERTIES_H | |
3 | ||
83c9f4ca | 4 | #include "hw/qdev-core.h" |
074a86fc AL |
5 | |
6 | /*** qdev-properties.c ***/ | |
7 | ||
8 | extern PropertyInfo qdev_prop_bit; | |
fdba6d96 | 9 | extern PropertyInfo qdev_prop_bit64; |
72cc5137 | 10 | extern PropertyInfo qdev_prop_bool; |
074a86fc AL |
11 | extern PropertyInfo qdev_prop_uint8; |
12 | extern PropertyInfo qdev_prop_uint16; | |
13 | extern PropertyInfo qdev_prop_uint32; | |
14 | extern PropertyInfo qdev_prop_int32; | |
15 | extern PropertyInfo qdev_prop_uint64; | |
e8cd45c7 | 16 | extern PropertyInfo qdev_prop_size; |
074a86fc AL |
17 | extern PropertyInfo qdev_prop_string; |
18 | extern PropertyInfo qdev_prop_chr; | |
19 | extern PropertyInfo qdev_prop_ptr; | |
20 | extern PropertyInfo qdev_prop_macaddr; | |
55e8a154 | 21 | extern PropertyInfo qdev_prop_on_off_auto; |
074a86fc | 22 | extern PropertyInfo qdev_prop_losttickpolicy; |
8c398252 | 23 | extern PropertyInfo qdev_prop_blockdev_on_error; |
074a86fc | 24 | extern PropertyInfo qdev_prop_bios_chs_trans; |
a73275dd | 25 | extern PropertyInfo qdev_prop_fdc_drive_type; |
074a86fc AL |
26 | extern PropertyInfo qdev_prop_drive; |
27 | extern PropertyInfo qdev_prop_netdev; | |
28 | extern PropertyInfo qdev_prop_vlan; | |
29 | extern PropertyInfo qdev_prop_pci_devfn; | |
30 | extern PropertyInfo qdev_prop_blocksize; | |
31 | extern PropertyInfo qdev_prop_pci_host_devaddr; | |
0be6bfac | 32 | extern PropertyInfo qdev_prop_arraylen; |
074a86fc AL |
33 | |
34 | #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ | |
35 | .name = (_name), \ | |
36 | .info = &(_prop), \ | |
37 | .offset = offsetof(_state, _field) \ | |
1ceef9f2 | 38 | + type_check(_type, typeof_field(_state, _field)), \ |
074a86fc | 39 | } |
3fb2111f | 40 | |
85bbd1e7 | 41 | #define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) { \ |
074a86fc AL |
42 | .name = (_name), \ |
43 | .info = &(_prop), \ | |
44 | .offset = offsetof(_state, _field) \ | |
45 | + type_check(_type,typeof_field(_state, _field)), \ | |
76318657 | 46 | .defval.i = (_type)_defval, \ |
074a86fc | 47 | } |
3fb2111f | 48 | |
074a86fc AL |
49 | #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \ |
50 | .name = (_name), \ | |
51 | .info = &(qdev_prop_bit), \ | |
52 | .bitnr = (_bit), \ | |
53 | .offset = offsetof(_state, _field) \ | |
54 | + type_check(uint32_t,typeof_field(_state, _field)), \ | |
3fb2111f MAL |
55 | .defval.u = (bool)_defval, \ |
56 | } | |
57 | ||
58 | #define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) { \ | |
59 | .name = (_name), \ | |
60 | .info = &(_prop), \ | |
61 | .offset = offsetof(_state, _field) \ | |
62 | + type_check(_type, typeof_field(_state, _field)), \ | |
63 | .defval.u = (_type)_defval, \ | |
074a86fc | 64 | } |
3fb2111f | 65 | |
fdba6d96 GH |
66 | #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \ |
67 | .name = (_name), \ | |
8aedc369 | 68 | .info = &(qdev_prop_bit64), \ |
fdba6d96 GH |
69 | .bitnr = (_bit), \ |
70 | .offset = offsetof(_state, _field) \ | |
71 | + type_check(uint64_t, typeof_field(_state, _field)), \ | |
3fb2111f | 72 | .defval.u = (bool)_defval, \ |
fdba6d96 | 73 | } |
074a86fc | 74 | |
72cc5137 IM |
75 | #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \ |
76 | .name = (_name), \ | |
77 | .info = &(qdev_prop_bool), \ | |
78 | .offset = offsetof(_state, _field) \ | |
79 | + type_check(bool, typeof_field(_state, _field)), \ | |
3fb2111f | 80 | .defval.u = (bool)_defval, \ |
72cc5137 IM |
81 | } |
82 | ||
0be6bfac PM |
83 | #define PROP_ARRAY_LEN_PREFIX "len-" |
84 | ||
85 | /** | |
86 | * DEFINE_PROP_ARRAY: | |
87 | * @_name: name of the array | |
88 | * @_state: name of the device state structure type | |
89 | * @_field: uint32_t field in @_state to hold the array length | |
90 | * @_arrayfield: field in @_state (of type '@_arraytype *') which | |
91 | * will point to the array | |
92 | * @_arrayprop: PropertyInfo defining what property the array elements have | |
93 | * @_arraytype: C type of the array elements | |
94 | * | |
95 | * Define device properties for a variable-length array _name. A | |
96 | * static property "len-arrayname" is defined. When the device creator | |
97 | * sets this property to the desired length of array, further dynamic | |
98 | * properties "arrayname[0]", "arrayname[1]", ... are defined so the | |
99 | * device creator can set the array element values. Setting the | |
100 | * "len-arrayname" property more than once is an error. | |
101 | * | |
102 | * When the array length is set, the @_field member of the device | |
103 | * struct is set to the array length, and @_arrayfield is set to point | |
104 | * to (zero-initialised) memory allocated for the array. For a zero | |
105 | * length array, @_field will be set to 0 and @_arrayfield to NULL. | |
106 | * It is the responsibility of the device deinit code to free the | |
107 | * @_arrayfield memory. | |
108 | */ | |
109 | #define DEFINE_PROP_ARRAY(_name, _state, _field, \ | |
110 | _arrayfield, _arrayprop, _arraytype) { \ | |
111 | .name = (PROP_ARRAY_LEN_PREFIX _name), \ | |
112 | .info = &(qdev_prop_arraylen), \ | |
113 | .offset = offsetof(_state, _field) \ | |
114 | + type_check(uint32_t, typeof_field(_state, _field)), \ | |
0be6bfac PM |
115 | .arrayinfo = &(_arrayprop), \ |
116 | .arrayfieldsize = sizeof(_arraytype), \ | |
117 | .arrayoffset = offsetof(_state, _arrayfield), \ | |
118 | } | |
119 | ||
074a86fc | 120 | #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ |
3fb2111f | 121 | DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t) |
074a86fc | 122 | #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \ |
3fb2111f | 123 | DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t) |
074a86fc | 124 | #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \ |
3fb2111f | 125 | DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t) |
074a86fc | 126 | #define DEFINE_PROP_INT32(_n, _s, _f, _d) \ |
85bbd1e7 | 127 | DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t) |
074a86fc | 128 | #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \ |
3fb2111f | 129 | DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint64, uint64_t) |
e8cd45c7 | 130 | #define DEFINE_PROP_SIZE(_n, _s, _f, _d) \ |
3fb2111f | 131 | DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t) |
074a86fc | 132 | #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \ |
85bbd1e7 | 133 | DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t) |
074a86fc | 134 | |
c272758f MA |
135 | /* |
136 | * Please avoid pointer properties. If you must use them, you must | |
137 | * cover them in their device's class init function as follows: | |
138 | * | |
139 | * - If the property must be set, the device cannot be used with | |
140 | * device_add, so add code like this: | |
141 | * |* Reason: pointer property "NAME-OF-YOUR-PROP" *| | |
142 | * DeviceClass *dc = DEVICE_CLASS(class); | |
e90f2a8c | 143 | * dc->user_creatable = false; |
c272758f MA |
144 | * |
145 | * - If the property may safely remain null, document it like this: | |
146 | * |* | |
147 | * * Note: pointer property "interrupt_vector" may remain null, thus | |
e90f2a8c | 148 | * * no need for dc->user_creatable = false; |
c272758f MA |
149 | * *| |
150 | */ | |
074a86fc AL |
151 | #define DEFINE_PROP_PTR(_n, _s, _f) \ |
152 | DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*) | |
c272758f | 153 | |
074a86fc | 154 | #define DEFINE_PROP_CHR(_n, _s, _f) \ |
becdfa00 | 155 | DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharBackend) |
074a86fc AL |
156 | #define DEFINE_PROP_STRING(_n, _s, _f) \ |
157 | DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*) | |
158 | #define DEFINE_PROP_NETDEV(_n, _s, _f) \ | |
1ceef9f2 | 159 | DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers) |
074a86fc | 160 | #define DEFINE_PROP_VLAN(_n, _s, _f) \ |
1ceef9f2 | 161 | DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NICPeers) |
074a86fc | 162 | #define DEFINE_PROP_DRIVE(_n, _s, _f) \ |
4be74634 | 163 | DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockBackend *) |
074a86fc AL |
164 | #define DEFINE_PROP_MACADDR(_n, _s, _f) \ |
165 | DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) | |
55e8a154 | 166 | #define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \ |
85bbd1e7 | 167 | DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto) |
074a86fc | 168 | #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \ |
85bbd1e7 | 169 | DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_losttickpolicy, \ |
074a86fc | 170 | LostTickPolicy) |
8c398252 | 171 | #define DEFINE_PROP_BLOCKDEV_ON_ERROR(_n, _s, _f, _d) \ |
85bbd1e7 | 172 | DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_blockdev_on_error, \ |
8c398252 | 173 | BlockdevOnError) |
074a86fc | 174 | #define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \ |
85bbd1e7 | 175 | DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int) |
0eb28a42 | 176 | #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \ |
3fb2111f | 177 | DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t) |
074a86fc AL |
178 | #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \ |
179 | DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress) | |
ed03d749 FK |
180 | #define DEFINE_PROP_MEMORY_REGION(_n, _s, _f) \ |
181 | DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *) | |
074a86fc AL |
182 | |
183 | #define DEFINE_PROP_END_OF_LIST() \ | |
184 | {} | |
185 | ||
186 | /* Set properties between creation and init. */ | |
187 | void *qdev_get_prop_ptr(DeviceState *dev, Property *prop); | |
074a86fc AL |
188 | void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value); |
189 | void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value); | |
190 | void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); | |
191 | void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); | |
192 | void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value); | |
193 | void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value); | |
194 | void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value); | |
0ec7b3e7 | 195 | void qdev_prop_set_chr(DeviceState *dev, const char *name, Chardev *value); |
074a86fc | 196 | void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value); |
9b3d111a MA |
197 | void qdev_prop_set_drive(DeviceState *dev, const char *name, |
198 | BlockBackend *value, Error **errp); | |
606fd0e2 KK |
199 | void qdev_prop_set_macaddr(DeviceState *dev, const char *name, |
200 | const uint8_t *value); | |
074a86fc AL |
201 | void qdev_prop_set_enum(DeviceState *dev, const char *name, int value); |
202 | /* FIXME: Remove opaque pointer properties. */ | |
203 | void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); | |
204 | ||
a404b612 | 205 | void qdev_prop_register_global(GlobalProperty *prop); |
074a86fc | 206 | void qdev_prop_register_global_list(GlobalProperty *props); |
d828c430 | 207 | int qdev_prop_check_globals(void); |
25f8dd96 | 208 | void qdev_prop_set_globals(DeviceState *dev); |
074a86fc AL |
209 | void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, |
210 | Property *prop, const char *value); | |
211 | ||
60d7caca PX |
212 | /** |
213 | * register_compat_prop: | |
214 | * | |
215 | * Register internal (not user-provided) global property, changing the | |
216 | * default value of a given property in a device type. This can be used | |
217 | * for enabling machine-type compatibility or for enabling | |
218 | * accelerator-specific defaults in devices. | |
219 | * | |
220 | * The property values set using this function must be always valid and | |
221 | * never report setter errors, as the property will have | |
222 | * GlobalProperty::errp set to &error_abort. | |
223 | * | |
224 | * User-provided global properties should override internal global | |
225 | * properties, so callers of this function should ensure that it is | |
226 | * called before user-provided global properties are registered. | |
227 | * | |
228 | * @driver: Device type to be affected | |
229 | * @property: Property whose default value is going to be changed | |
230 | * @value: New default value for the property | |
231 | */ | |
232 | void register_compat_prop(const char *driver, const char *property, | |
233 | const char *value); | |
9ffea096 PX |
234 | /* |
235 | * register_compat_props_array(): using register_compat_prop(), which | |
236 | * only registers internal global properties (which has lower priority | |
237 | * than user-provided global properties) | |
238 | */ | |
239 | void register_compat_props_array(GlobalProperty *prop); | |
60d7caca | 240 | |
074a86fc | 241 | /** |
d9d8d452 C |
242 | * qdev_property_add_static: |
243 | * @dev: Device to add the property to. | |
244 | * @prop: The qdev property definition. | |
245 | * @errp: location to store error information. | |
246 | * | |
247 | * Add a static QOM property to @dev for qdev property @prop. | |
248 | * On error, store error in @errp. Static properties access data in a struct. | |
249 | * The type of the QOM property is derived from prop->info. | |
074a86fc AL |
250 | */ |
251 | void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp); | |
252 | ||
67cc7e0a SH |
253 | void qdev_alias_all_properties(DeviceState *target, Object *source); |
254 | ||
b000dfbd PM |
255 | /** |
256 | * @qdev_prop_set_after_realize: | |
257 | * @dev: device | |
258 | * @name: name of property | |
259 | * @errp: indirect pointer to Error to be set | |
260 | * Set the Error object to report that an attempt was made to set a property | |
261 | * on a device after it has already been realized. This is a utility function | |
262 | * which allows property-setter functions to easily report the error in | |
263 | * a friendly format identifying both the device and the property. | |
264 | */ | |
265 | void qdev_prop_set_after_realize(DeviceState *dev, const char *name, | |
266 | Error **errp); | |
39f72ef9 SH |
267 | |
268 | /** | |
269 | * qdev_prop_allow_set_link_before_realize: | |
270 | * | |
271 | * Set the #Error object if an attempt is made to set the link after realize. | |
272 | * This function should be used as the check() argument to | |
273 | * object_property_add_link(). | |
274 | */ | |
8f5d58ef IM |
275 | void qdev_prop_allow_set_link_before_realize(const Object *obj, |
276 | const char *name, | |
39f72ef9 SH |
277 | Object *val, Error **errp); |
278 | ||
074a86fc | 279 | #endif |