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 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_enum; 12 extern const PropertyInfo qdev_prop_uint8; 13 extern const PropertyInfo qdev_prop_uint16; 14 extern const PropertyInfo qdev_prop_uint32; 15 extern const PropertyInfo qdev_prop_int32; 16 extern const PropertyInfo qdev_prop_uint64; 17 extern const PropertyInfo qdev_prop_int64; 18 extern const PropertyInfo qdev_prop_size; 19 extern const PropertyInfo qdev_prop_string; 20 extern const PropertyInfo qdev_prop_chr; 21 extern const PropertyInfo qdev_prop_tpm; 22 extern const PropertyInfo qdev_prop_macaddr; 23 extern const PropertyInfo qdev_prop_reserved_region; 24 extern const PropertyInfo qdev_prop_on_off_auto; 25 extern const PropertyInfo qdev_prop_multifd_compression; 26 extern const PropertyInfo qdev_prop_losttickpolicy; 27 extern const PropertyInfo qdev_prop_blockdev_on_error; 28 extern const PropertyInfo qdev_prop_bios_chs_trans; 29 extern const PropertyInfo qdev_prop_fdc_drive_type; 30 extern const PropertyInfo qdev_prop_drive; 31 extern const PropertyInfo qdev_prop_drive_iothread; 32 extern const PropertyInfo qdev_prop_netdev; 33 extern const PropertyInfo qdev_prop_pci_devfn; 34 extern const PropertyInfo qdev_prop_size32; 35 extern const PropertyInfo qdev_prop_blocksize; 36 extern const PropertyInfo qdev_prop_pci_host_devaddr; 37 extern const PropertyInfo qdev_prop_uuid; 38 extern const PropertyInfo qdev_prop_arraylen; 39 extern const PropertyInfo qdev_prop_audiodev; 40 extern const PropertyInfo qdev_prop_link; 41 extern const PropertyInfo qdev_prop_off_auto_pcibar; 42 extern const PropertyInfo qdev_prop_pcie_link_speed; 43 extern const PropertyInfo qdev_prop_pcie_link_width; 44 45 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ 46 .name = (_name), \ 47 .info = &(_prop), \ 48 .offset = offsetof(_state, _field) \ 49 + type_check(_type, typeof_field(_state, _field)), \ 50 } 51 52 #define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) { \ 53 .name = (_name), \ 54 .info = &(_prop), \ 55 .offset = offsetof(_state, _field) \ 56 + type_check(_type,typeof_field(_state, _field)), \ 57 .set_default = true, \ 58 .defval.i = (_type)_defval, \ 59 } 60 61 #define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \ 62 .name = (_name), \ 63 .info = &(_prop), \ 64 .offset = offsetof(_state, _field) \ 65 + type_check(_type, typeof_field(_state, _field)), \ 66 } 67 68 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \ 69 .name = (_name), \ 70 .info = &(qdev_prop_bit), \ 71 .bitnr = (_bit), \ 72 .offset = offsetof(_state, _field) \ 73 + type_check(uint32_t,typeof_field(_state, _field)), \ 74 .set_default = true, \ 75 .defval.u = (bool)_defval, \ 76 } 77 78 #define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) { \ 79 .name = (_name), \ 80 .info = &(_prop), \ 81 .offset = offsetof(_state, _field) \ 82 + type_check(_type, typeof_field(_state, _field)), \ 83 .set_default = true, \ 84 .defval.u = (_type)_defval, \ 85 } 86 87 #define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \ 88 .name = (_name), \ 89 .info = &(_prop), \ 90 .offset = offsetof(_state, _field) \ 91 + type_check(_type, typeof_field(_state, _field)), \ 92 } 93 94 #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \ 95 .name = (_name), \ 96 .info = &(qdev_prop_bit64), \ 97 .bitnr = (_bit), \ 98 .offset = offsetof(_state, _field) \ 99 + type_check(uint64_t, typeof_field(_state, _field)), \ 100 .set_default = true, \ 101 .defval.u = (bool)_defval, \ 102 } 103 104 #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \ 105 .name = (_name), \ 106 .info = &(qdev_prop_bool), \ 107 .offset = offsetof(_state, _field) \ 108 + type_check(bool, typeof_field(_state, _field)), \ 109 .set_default = true, \ 110 .defval.u = (bool)_defval, \ 111 } 112 113 #define PROP_ARRAY_LEN_PREFIX "len-" 114 115 /** 116 * DEFINE_PROP_ARRAY: 117 * @_name: name of the array 118 * @_state: name of the device state structure type 119 * @_field: uint32_t field in @_state to hold the array length 120 * @_arrayfield: field in @_state (of type '@_arraytype *') which 121 * will point to the array 122 * @_arrayprop: PropertyInfo defining what property the array elements have 123 * @_arraytype: C type of the array elements 124 * 125 * Define device properties for a variable-length array _name. A 126 * static property "len-arrayname" is defined. When the device creator 127 * sets this property to the desired length of array, further dynamic 128 * properties "arrayname[0]", "arrayname[1]", ... are defined so the 129 * device creator can set the array element values. Setting the 130 * "len-arrayname" property more than once is an error. 131 * 132 * When the array length is set, the @_field member of the device 133 * struct is set to the array length, and @_arrayfield is set to point 134 * to (zero-initialised) memory allocated for the array. For a zero 135 * length array, @_field will be set to 0 and @_arrayfield to NULL. 136 * It is the responsibility of the device deinit code to free the 137 * @_arrayfield memory. 138 */ 139 #define DEFINE_PROP_ARRAY(_name, _state, _field, \ 140 _arrayfield, _arrayprop, _arraytype) { \ 141 .name = (PROP_ARRAY_LEN_PREFIX _name), \ 142 .info = &(qdev_prop_arraylen), \ 143 .set_default = true, \ 144 .defval.u = 0, \ 145 .offset = offsetof(_state, _field) \ 146 + type_check(uint32_t, typeof_field(_state, _field)), \ 147 .arrayinfo = &(_arrayprop), \ 148 .arrayfieldsize = sizeof(_arraytype), \ 149 .arrayoffset = offsetof(_state, _arrayfield), \ 150 } 151 152 #define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) { \ 153 .name = (_name), \ 154 .info = &(qdev_prop_link), \ 155 .offset = offsetof(_state, _field) \ 156 + type_check(_ptr_type, typeof_field(_state, _field)), \ 157 .link_type = _type, \ 158 } 159 160 #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ 161 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t) 162 #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \ 163 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t) 164 #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \ 165 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t) 166 #define DEFINE_PROP_INT32(_n, _s, _f, _d) \ 167 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t) 168 #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \ 169 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint64, uint64_t) 170 #define DEFINE_PROP_INT64(_n, _s, _f, _d) \ 171 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int64, int64_t) 172 #define DEFINE_PROP_SIZE(_n, _s, _f, _d) \ 173 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t) 174 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \ 175 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t) 176 177 #define DEFINE_PROP_CHR(_n, _s, _f) \ 178 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharBackend) 179 #define DEFINE_PROP_STRING(_n, _s, _f) \ 180 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*) 181 #define DEFINE_PROP_NETDEV(_n, _s, _f) \ 182 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers) 183 #define DEFINE_PROP_DRIVE(_n, _s, _f) \ 184 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockBackend *) 185 #define DEFINE_PROP_DRIVE_IOTHREAD(_n, _s, _f) \ 186 DEFINE_PROP(_n, _s, _f, qdev_prop_drive_iothread, BlockBackend *) 187 #define DEFINE_PROP_MACADDR(_n, _s, _f) \ 188 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) 189 #define DEFINE_PROP_RESERVED_REGION(_n, _s, _f) \ 190 DEFINE_PROP(_n, _s, _f, qdev_prop_reserved_region, ReservedRegion) 191 #define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \ 192 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto) 193 #define DEFINE_PROP_MULTIFD_COMPRESSION(_n, _s, _f, _d) \ 194 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_multifd_compression, \ 195 MultiFDCompression) 196 #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \ 197 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_losttickpolicy, \ 198 LostTickPolicy) 199 #define DEFINE_PROP_BLOCKDEV_ON_ERROR(_n, _s, _f, _d) \ 200 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_blockdev_on_error, \ 201 BlockdevOnError) 202 #define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \ 203 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int) 204 #define DEFINE_PROP_SIZE32(_n, _s, _f, _d) \ 205 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size32, uint32_t) 206 #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \ 207 DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint32_t) 208 #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \ 209 DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress) 210 #define DEFINE_PROP_OFF_AUTO_PCIBAR(_n, _s, _f, _d) \ 211 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_off_auto_pcibar, \ 212 OffAutoPCIBAR) 213 #define DEFINE_PROP_PCIE_LINK_SPEED(_n, _s, _f, _d) \ 214 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pcie_link_speed, \ 215 PCIExpLinkSpeed) 216 #define DEFINE_PROP_PCIE_LINK_WIDTH(_n, _s, _f, _d) \ 217 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pcie_link_width, \ 218 PCIExpLinkWidth) 219 220 #define DEFINE_PROP_UUID(_name, _state, _field) { \ 221 .name = (_name), \ 222 .info = &qdev_prop_uuid, \ 223 .offset = offsetof(_state, _field) \ 224 + type_check(QemuUUID, typeof_field(_state, _field)), \ 225 .set_default = true, \ 226 } 227 #define DEFINE_PROP_AUDIODEV(_n, _s, _f) \ 228 DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard) 229 230 #define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) { \ 231 .name = (_name), \ 232 .info = &qdev_prop_uuid, \ 233 .offset = offsetof(_state, _field) \ 234 + type_check(QemuUUID, typeof_field(_state, _field)), \ 235 } 236 237 #define DEFINE_PROP_END_OF_LIST() \ 238 {} 239 240 /* 241 * Set properties between creation and realization. 242 * 243 * Returns: %true on success, %false on error. 244 */ 245 bool qdev_prop_set_drive_err(DeviceState *dev, const char *name, 246 BlockBackend *value, Error **errp); 247 248 /* 249 * Set properties between creation and realization. 250 * @value must be valid. Each property may be set at most once. 251 */ 252 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value); 253 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value); 254 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); 255 void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); 256 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value); 257 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value); 258 void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value); 259 void qdev_prop_set_chr(DeviceState *dev, const char *name, Chardev *value); 260 void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value); 261 void qdev_prop_set_drive(DeviceState *dev, const char *name, 262 BlockBackend *value); 263 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, 264 const uint8_t *value); 265 void qdev_prop_set_enum(DeviceState *dev, const char *name, int value); 266 267 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop); 268 269 void qdev_prop_register_global(GlobalProperty *prop); 270 const GlobalProperty *qdev_find_global_prop(DeviceState *dev, 271 const char *name); 272 int qdev_prop_check_globals(void); 273 void qdev_prop_set_globals(DeviceState *dev); 274 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, 275 Property *prop, const char *value); 276 277 /** 278 * qdev_property_add_static: 279 * @dev: Device to add the property to. 280 * @prop: The qdev property definition. 281 * 282 * Add a static QOM property to @dev for qdev property @prop. 283 * On error, store error in @errp. Static properties access data in a struct. 284 * The type of the QOM property is derived from prop->info. 285 */ 286 void qdev_property_add_static(DeviceState *dev, Property *prop); 287 288 /** 289 * qdev_alias_all_properties: Create aliases on source for all target properties 290 * @target: Device which has properties to be aliased 291 * @source: Object to add alias properties to 292 * 293 * Add alias properties to the @source object for all qdev properties on 294 * the @target DeviceState. 295 * 296 * This is useful when @target is an internal implementation object 297 * owned by @source, and you want to expose all the properties of that 298 * implementation object as properties on the @source object so that users 299 * of @source can set them. 300 */ 301 void qdev_alias_all_properties(DeviceState *target, Object *source); 302 303 /** 304 * @qdev_prop_set_after_realize: 305 * @dev: device 306 * @name: name of property 307 * @errp: indirect pointer to Error to be set 308 * Set the Error object to report that an attempt was made to set a property 309 * on a device after it has already been realized. This is a utility function 310 * which allows property-setter functions to easily report the error in 311 * a friendly format identifying both the device and the property. 312 */ 313 void qdev_prop_set_after_realize(DeviceState *dev, const char *name, 314 Error **errp); 315 316 /** 317 * qdev_prop_allow_set_link_before_realize: 318 * 319 * Set the #Error object if an attempt is made to set the link after realize. 320 * This function should be used as the check() argument to 321 * object_property_add_link(). 322 */ 323 void qdev_prop_allow_set_link_before_realize(const Object *obj, 324 const char *name, 325 Object *val, Error **errp); 326 327 #endif 328