1 #ifndef QEMU_QDEV_PROPERTIES_H
2 #define QEMU_QDEV_PROPERTIES_H
4 #include "hw/qdev-core.h"
6 /*** qdev-properties.c ***/
8 extern PropertyInfo qdev_prop_bit
;
9 extern PropertyInfo qdev_prop_bit64
;
10 extern PropertyInfo qdev_prop_bool
;
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
;
16 extern PropertyInfo qdev_prop_size
;
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_on_off_auto
;
22 extern PropertyInfo qdev_prop_losttickpolicy
;
23 extern PropertyInfo qdev_prop_bios_chs_trans
;
24 extern PropertyInfo qdev_prop_fdc_drive_type
;
25 extern PropertyInfo qdev_prop_drive
;
26 extern PropertyInfo qdev_prop_netdev
;
27 extern PropertyInfo qdev_prop_vlan
;
28 extern PropertyInfo qdev_prop_pci_devfn
;
29 extern PropertyInfo qdev_prop_blocksize
;
30 extern PropertyInfo qdev_prop_pci_host_devaddr
;
31 extern PropertyInfo qdev_prop_arraylen
;
33 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
36 .offset = offsetof(_state, _field) \
37 + type_check(_type, typeof_field(_state, _field)), \
39 #define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
42 .offset = offsetof(_state, _field) \
43 + type_check(_type,typeof_field(_state, _field)), \
44 .qtype = QTYPE_QINT, \
45 .defval = (_type)_defval, \
47 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
49 .info = &(qdev_prop_bit), \
51 .offset = offsetof(_state, _field) \
52 + type_check(uint32_t,typeof_field(_state, _field)), \
53 .qtype = QTYPE_QBOOL, \
54 .defval = (bool)_defval, \
56 #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \
58 .info = &(qdev_prop_bit64), \
60 .offset = offsetof(_state, _field) \
61 + type_check(uint64_t, typeof_field(_state, _field)), \
62 .qtype = QTYPE_QBOOL, \
63 .defval = (bool)_defval, \
66 #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \
68 .info = &(qdev_prop_bool), \
69 .offset = offsetof(_state, _field) \
70 + type_check(bool, typeof_field(_state, _field)), \
71 .qtype = QTYPE_QBOOL, \
72 .defval = (bool)_defval, \
75 #define PROP_ARRAY_LEN_PREFIX "len-"
79 * @_name: name of the array
80 * @_state: name of the device state structure type
81 * @_field: uint32_t field in @_state to hold the array length
82 * @_arrayfield: field in @_state (of type '@_arraytype *') which
83 * will point to the array
84 * @_arrayprop: PropertyInfo defining what property the array elements have
85 * @_arraytype: C type of the array elements
87 * Define device properties for a variable-length array _name. A
88 * static property "len-arrayname" is defined. When the device creator
89 * sets this property to the desired length of array, further dynamic
90 * properties "arrayname[0]", "arrayname[1]", ... are defined so the
91 * device creator can set the array element values. Setting the
92 * "len-arrayname" property more than once is an error.
94 * When the array length is set, the @_field member of the device
95 * struct is set to the array length, and @_arrayfield is set to point
96 * to (zero-initialised) memory allocated for the array. For a zero
97 * length array, @_field will be set to 0 and @_arrayfield to NULL.
98 * It is the responsibility of the device deinit code to free the
99 * @_arrayfield memory.
101 #define DEFINE_PROP_ARRAY(_name, _state, _field, \
102 _arrayfield, _arrayprop, _arraytype) { \
103 .name = (PROP_ARRAY_LEN_PREFIX _name), \
104 .info = &(qdev_prop_arraylen), \
105 .offset = offsetof(_state, _field) \
106 + type_check(uint32_t, typeof_field(_state, _field)), \
107 .qtype = QTYPE_QINT, \
108 .arrayinfo = &(_arrayprop), \
109 .arrayfieldsize = sizeof(_arraytype), \
110 .arrayoffset = offsetof(_state, _arrayfield), \
113 #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
114 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
115 #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
116 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
117 #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
118 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
119 #define DEFINE_PROP_INT32(_n, _s, _f, _d) \
120 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t)
121 #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
122 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
123 #define DEFINE_PROP_SIZE(_n, _s, _f, _d) \
124 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_size, uint64_t)
125 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
126 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
129 * Please avoid pointer properties. If you must use them, you must
130 * cover them in their device's class init function as follows:
132 * - If the property must be set, the device cannot be used with
133 * device_add, so add code like this:
134 * |* Reason: pointer property "NAME-OF-YOUR-PROP" *|
135 * DeviceClass *dc = DEVICE_CLASS(class);
136 * dc->cannot_instantiate_with_device_add_yet = true;
138 * - If the property may safely remain null, document it like this:
140 * * Note: pointer property "interrupt_vector" may remain null, thus
141 * * no need for dc->cannot_instantiate_with_device_add_yet = true;
144 #define DEFINE_PROP_PTR(_n, _s, _f) \
145 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
147 #define DEFINE_PROP_CHR(_n, _s, _f) \
148 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
149 #define DEFINE_PROP_STRING(_n, _s, _f) \
150 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
151 #define DEFINE_PROP_NETDEV(_n, _s, _f) \
152 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers)
153 #define DEFINE_PROP_VLAN(_n, _s, _f) \
154 DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NICPeers)
155 #define DEFINE_PROP_DRIVE(_n, _s, _f) \
156 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockBackend *)
157 #define DEFINE_PROP_MACADDR(_n, _s, _f) \
158 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
159 #define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
160 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
161 #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
162 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
164 #define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
165 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
166 #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \
167 DEFINE_PROP_DEFAULT(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t)
168 #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
169 DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
171 #define DEFINE_PROP_END_OF_LIST() \
174 /* Set properties between creation and init. */
175 void *qdev_get_prop_ptr(DeviceState
*dev
, Property
*prop
);
176 void qdev_prop_set_bit(DeviceState
*dev
, const char *name
, bool value
);
177 void qdev_prop_set_uint8(DeviceState
*dev
, const char *name
, uint8_t value
);
178 void qdev_prop_set_uint16(DeviceState
*dev
, const char *name
, uint16_t value
);
179 void qdev_prop_set_uint32(DeviceState
*dev
, const char *name
, uint32_t value
);
180 void qdev_prop_set_int32(DeviceState
*dev
, const char *name
, int32_t value
);
181 void qdev_prop_set_uint64(DeviceState
*dev
, const char *name
, uint64_t value
);
182 void qdev_prop_set_string(DeviceState
*dev
, const char *name
, const char *value
);
183 void qdev_prop_set_chr(DeviceState
*dev
, const char *name
, CharDriverState
*value
);
184 void qdev_prop_set_netdev(DeviceState
*dev
, const char *name
, NetClientState
*value
);
185 void qdev_prop_set_drive(DeviceState
*dev
, const char *name
,
186 BlockBackend
*value
, Error
**errp
);
187 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
, uint8_t *value
);
188 void qdev_prop_set_enum(DeviceState
*dev
, const char *name
, int value
);
189 /* FIXME: Remove opaque pointer properties. */
190 void qdev_prop_set_ptr(DeviceState
*dev
, const char *name
, void *value
);
192 void qdev_prop_register_global(GlobalProperty
*prop
);
193 void qdev_prop_register_global_list(GlobalProperty
*props
);
194 int qdev_prop_check_globals(void);
195 void qdev_prop_set_globals(DeviceState
*dev
);
196 void error_set_from_qdev_prop_error(Error
**errp
, int ret
, DeviceState
*dev
,
197 Property
*prop
, const char *value
);
200 * qdev_property_add_static:
201 * @dev: Device to add the property to.
202 * @prop: The qdev property definition.
203 * @errp: location to store error information.
205 * Add a static QOM property to @dev for qdev property @prop.
206 * On error, store error in @errp. Static properties access data in a struct.
207 * The type of the QOM property is derived from prop->info.
209 void qdev_property_add_static(DeviceState
*dev
, Property
*prop
, Error
**errp
);
211 void qdev_alias_all_properties(DeviceState
*target
, Object
*source
);
214 * @qdev_prop_set_after_realize:
216 * @name: name of property
217 * @errp: indirect pointer to Error to be set
218 * Set the Error object to report that an attempt was made to set a property
219 * on a device after it has already been realized. This is a utility function
220 * which allows property-setter functions to easily report the error in
221 * a friendly format identifying both the device and the property.
223 void qdev_prop_set_after_realize(DeviceState
*dev
, const char *name
,
227 * qdev_prop_allow_set_link_before_realize:
229 * Set the #Error object if an attempt is made to set the link after realize.
230 * This function should be used as the check() argument to
231 * object_property_add_link().
233 void qdev_prop_allow_set_link_before_realize(Object
*obj
, const char *name
,
234 Object
*val
, Error
**errp
);