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