]> Git Repo - qemu.git/blame - include/hw/qdev-properties.h
crypto: add reload for QCryptoTLSCredsClass
[qemu.git] / include / hw / qdev-properties.h
CommitLineData
074a86fc
AL
1#ifndef QEMU_QDEV_PROPERTIES_H
2#define QEMU_QDEV_PROPERTIES_H
3
83c9f4ca 4#include "hw/qdev-core.h"
074a86fc 5
d3fd6e73
EH
6/**
7 * Property:
8 * @set_default: true if the default value should be set from @defval,
9 * in which case @info->set_default_value must not be NULL
10 * (if false then no default value is set by the property system
11 * and the field retains whatever value it was given by instance_init).
12 * @defval: default value for the property. This is used only if @set_default
13 * is true.
14 */
15struct Property {
16 const char *name;
17 const PropertyInfo *info;
18 ptrdiff_t offset;
19 uint8_t bitnr;
20 bool set_default;
21 union {
22 int64_t i;
23 uint64_t u;
24 } defval;
25 int arrayoffset;
26 const PropertyInfo *arrayinfo;
27 int arrayfieldsize;
28 const char *link_type;
29};
30
31struct PropertyInfo {
32 const char *name;
33 const char *description;
34 const QEnumLookup *enum_table;
40ea00b0 35 int (*print)(Object *obj, Property *prop, char *dest, size_t len);
d3fd6e73 36 void (*set_default_value)(ObjectProperty *op, const Property *prop);
f59c6d22
EH
37 ObjectProperty *(*create)(ObjectClass *oc, const char *name,
38 Property *prop);
d3fd6e73
EH
39 ObjectPropertyAccessor *get;
40 ObjectPropertyAccessor *set;
41 ObjectPropertyRelease *release;
42};
43
44
074a86fc
AL
45/*** qdev-properties.c ***/
46
1b6b7d10
FZ
47extern const PropertyInfo qdev_prop_bit;
48extern const PropertyInfo qdev_prop_bit64;
49extern const PropertyInfo qdev_prop_bool;
79bdf29c 50extern const PropertyInfo qdev_prop_enum;
1b6b7d10
FZ
51extern const PropertyInfo qdev_prop_uint8;
52extern const PropertyInfo qdev_prop_uint16;
53extern const PropertyInfo qdev_prop_uint32;
54extern const PropertyInfo qdev_prop_int32;
55extern const PropertyInfo qdev_prop_uint64;
07d1d063 56extern const PropertyInfo qdev_prop_int64;
1b6b7d10
FZ
57extern const PropertyInfo qdev_prop_size;
58extern const PropertyInfo qdev_prop_string;
1b6b7d10 59extern const PropertyInfo qdev_prop_on_off_auto;
914e74cd 60extern const PropertyInfo qdev_prop_size32;
1b6b7d10
FZ
61extern const PropertyInfo qdev_prop_arraylen;
62extern const PropertyInfo qdev_prop_link;
074a86fc 63
45efa07f 64#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) { \
074a86fc
AL
65 .name = (_name), \
66 .info = &(_prop), \
67 .offset = offsetof(_state, _field) \
1ceef9f2 68 + type_check(_type, typeof_field(_state, _field)), \
45efa07f 69 __VA_ARGS__ \
074a86fc 70 }
3fb2111f 71
45efa07f
EH
72#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \
73 DEFINE_PROP(_name, _state, _field, _prop, _type, \
74 .set_default = true, \
75 .defval.i = (_type)_defval)
3fb2111f 76
45efa07f
EH
77#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
78 DEFINE_PROP(_name, _state, _field, _prop, _type)
5cc56cc6 79
45efa07f
EH
80#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) \
81 DEFINE_PROP(_name, _state, _field, qdev_prop_bit, uint32_t, \
82 .bitnr = (_bit), \
83 .set_default = true, \
84 .defval.u = (bool)_defval)
3fb2111f 85
45efa07f
EH
86#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) \
87 DEFINE_PROP(_name, _state, _field, _prop, _type, \
88 .set_default = true, \
89 .defval.u = (_type)_defval)
3fb2111f 90
45efa07f
EH
91#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
92 DEFINE_PROP(_name, _state, _field, _prop, _type)
5cc56cc6 93
45efa07f
EH
94#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) \
95 DEFINE_PROP(_name, _state, _field, qdev_prop_bit64, uint64_t, \
96 .bitnr = (_bit), \
97 .set_default = true, \
98 .defval.u = (bool)_defval)
074a86fc 99
45efa07f
EH
100#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \
101 DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool, \
102 .set_default = true, \
103 .defval.u = (bool)_defval)
72cc5137 104
0be6bfac
PM
105#define PROP_ARRAY_LEN_PREFIX "len-"
106
107/**
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
116 *
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.
123 *
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.
130 */
45efa07f
EH
131#define DEFINE_PROP_ARRAY(_name, _state, _field, \
132 _arrayfield, _arrayprop, _arraytype) \
133 DEFINE_PROP((PROP_ARRAY_LEN_PREFIX _name), \
134 _state, _field, qdev_prop_arraylen, uint32_t, \
135 .set_default = true, \
136 .defval.u = 0, \
137 .arrayinfo = &(_arrayprop), \
138 .arrayfieldsize = sizeof(_arraytype), \
139 .arrayoffset = offsetof(_state, _arrayfield))
140
141#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) \
142 DEFINE_PROP(_name, _state, _field, qdev_prop_link, _ptr_type, \
143 .link_type = _type)
5b4ff3c6 144
074a86fc 145#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
3fb2111f 146 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
074a86fc 147#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
3fb2111f 148 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
074a86fc 149#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
3fb2111f 150 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
074a86fc 151#define DEFINE_PROP_INT32(_n, _s, _f, _d) \
85bbd1e7 152 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t)
074a86fc 153#define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
3fb2111f 154 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
07d1d063
PX
155#define DEFINE_PROP_INT64(_n, _s, _f, _d) \
156 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int64, int64_t)
e8cd45c7 157#define DEFINE_PROP_SIZE(_n, _s, _f, _d) \
3fb2111f 158 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t)
074a86fc
AL
159#define DEFINE_PROP_STRING(_n, _s, _f) \
160 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
55e8a154 161#define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
85bbd1e7 162 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
914e74cd
RK
163#define DEFINE_PROP_SIZE32(_n, _s, _f, _d) \
164 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size32, uint32_t)
a65f4d40 165
074a86fc
AL
166#define DEFINE_PROP_END_OF_LIST() \
167 {}
168
934df912
MA
169/*
170 * Set properties between creation and realization.
0aca03a3
PMD
171 *
172 * Returns: %true on success, %false on error.
934df912 173 */
73ac1aac
MA
174bool qdev_prop_set_drive_err(DeviceState *dev, const char *name,
175 BlockBackend *value, Error **errp);
934df912
MA
176
177/*
178 * Set properties between creation and realization.
179 * @value must be valid. Each property may be set at most once.
180 */
074a86fc
AL
181void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
182void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
183void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
184void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
185void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
186void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
187void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value);
0ec7b3e7 188void qdev_prop_set_chr(DeviceState *dev, const char *name, Chardev *value);
074a86fc 189void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value);
9b3d111a 190void qdev_prop_set_drive(DeviceState *dev, const char *name,
934df912 191 BlockBackend *value);
606fd0e2
KK
192void qdev_prop_set_macaddr(DeviceState *dev, const char *name,
193 const uint8_t *value);
074a86fc 194void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
074a86fc 195
1e198715 196void *object_field_prop_ptr(Object *obj, Property *prop);
934df912 197
a404b612 198void qdev_prop_register_global(GlobalProperty *prop);
39501275 199const GlobalProperty *qdev_find_global_prop(Object *obj,
1bc13336 200 const char *name);
d828c430 201int qdev_prop_check_globals(void);
25f8dd96 202void qdev_prop_set_globals(DeviceState *dev);
c7525b18 203void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
e68c2cb7 204 const char *name, const char *value);
074a86fc
AL
205
206/**
d9d8d452
C
207 * qdev_property_add_static:
208 * @dev: Device to add the property to.
209 * @prop: The qdev property definition.
d9d8d452
C
210 *
211 * Add a static QOM property to @dev for qdev property @prop.
212 * On error, store error in @errp. Static properties access data in a struct.
213 * The type of the QOM property is derived from prop->info.
074a86fc 214 */
94d912d1 215void qdev_property_add_static(DeviceState *dev, Property *prop);
074a86fc 216
b51238e2
PM
217/**
218 * qdev_alias_all_properties: Create aliases on source for all target properties
219 * @target: Device which has properties to be aliased
220 * @source: Object to add alias properties to
221 *
222 * Add alias properties to the @source object for all qdev properties on
223 * the @target DeviceState.
224 *
225 * This is useful when @target is an internal implementation object
226 * owned by @source, and you want to expose all the properties of that
227 * implementation object as properties on the @source object so that users
228 * of @source can set them.
229 */
67cc7e0a
SH
230void qdev_alias_all_properties(DeviceState *target, Object *source);
231
b000dfbd
PM
232/**
233 * @qdev_prop_set_after_realize:
234 * @dev: device
235 * @name: name of property
236 * @errp: indirect pointer to Error to be set
237 * Set the Error object to report that an attempt was made to set a property
238 * on a device after it has already been realized. This is a utility function
239 * which allows property-setter functions to easily report the error in
240 * a friendly format identifying both the device and the property.
241 */
242void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
243 Error **errp);
39f72ef9
SH
244
245/**
246 * qdev_prop_allow_set_link_before_realize:
247 *
248 * Set the #Error object if an attempt is made to set the link after realize.
249 * This function should be used as the check() argument to
250 * object_property_add_link().
251 */
8f5d58ef
IM
252void qdev_prop_allow_set_link_before_realize(const Object *obj,
253 const char *name,
39f72ef9
SH
254 Object *val, Error **errp);
255
074a86fc 256#endif
This page took 0.482187 seconds and 4 git commands to generate.