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