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 PropertyInfo qdev_prop_bit; 9 extern PropertyInfo qdev_prop_bool; 10 extern PropertyInfo qdev_prop_uint8; 11 extern PropertyInfo qdev_prop_uint16; 12 extern PropertyInfo qdev_prop_uint32; 13 extern PropertyInfo qdev_prop_int32; 14 extern PropertyInfo qdev_prop_uint64; 15 extern PropertyInfo qdev_prop_hex8; 16 extern PropertyInfo qdev_prop_hex32; 17 extern PropertyInfo qdev_prop_hex64; 18 extern PropertyInfo qdev_prop_string; 19 extern PropertyInfo qdev_prop_chr; 20 extern PropertyInfo qdev_prop_ptr; 21 extern PropertyInfo qdev_prop_macaddr; 22 extern PropertyInfo qdev_prop_losttickpolicy; 23 extern PropertyInfo qdev_prop_bios_chs_trans; 24 extern PropertyInfo qdev_prop_drive; 25 extern PropertyInfo qdev_prop_netdev; 26 extern PropertyInfo qdev_prop_vlan; 27 extern PropertyInfo qdev_prop_pci_devfn; 28 extern PropertyInfo qdev_prop_blocksize; 29 extern PropertyInfo qdev_prop_pci_host_devaddr; 30 extern PropertyInfo qdev_prop_arraylen; 31 32 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ 33 .name = (_name), \ 34 .info = &(_prop), \ 35 .offset = offsetof(_state, _field) \ 36 + type_check(_type, typeof_field(_state, _field)), \ 37 } 38 #define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \ 39 .name = (_name), \ 40 .info = &(_prop), \ 41 .offset = offsetof(_state, _field) \ 42 + type_check(_type,typeof_field(_state, _field)), \ 43 .qtype = QTYPE_QINT, \ 44 .defval = (_type)_defval, \ 45 } 46 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \ 47 .name = (_name), \ 48 .info = &(qdev_prop_bit), \ 49 .bitnr = (_bit), \ 50 .offset = offsetof(_state, _field) \ 51 + type_check(uint32_t,typeof_field(_state, _field)), \ 52 .qtype = QTYPE_QBOOL, \ 53 .defval = (bool)_defval, \ 54 } 55 56 #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \ 57 .name = (_name), \ 58 .info = &(qdev_prop_bool), \ 59 .offset = offsetof(_state, _field) \ 60 + type_check(bool, typeof_field(_state, _field)), \ 61 .qtype = QTYPE_QBOOL, \ 62 .defval = (bool)_defval, \ 63 } 64 65 #define PROP_ARRAY_LEN_PREFIX "len-" 66 67 /** 68 * DEFINE_PROP_ARRAY: 69 * @_name: name of the array 70 * @_state: name of the device state structure type 71 * @_field: uint32_t field in @_state to hold the array length 72 * @_arrayfield: field in @_state (of type '@_arraytype *') which 73 * will point to the array 74 * @_arrayprop: PropertyInfo defining what property the array elements have 75 * @_arraytype: C type of the array elements 76 * 77 * Define device properties for a variable-length array _name. A 78 * static property "len-arrayname" is defined. When the device creator 79 * sets this property to the desired length of array, further dynamic 80 * properties "arrayname[0]", "arrayname[1]", ... are defined so the 81 * device creator can set the array element values. Setting the 82 * "len-arrayname" property more than once is an error. 83 * 84 * When the array length is set, the @_field member of the device 85 * struct is set to the array length, and @_arrayfield is set to point 86 * to (zero-initialised) memory allocated for the array. For a zero 87 * length array, @_field will be set to 0 and @_arrayfield to NULL. 88 * It is the responsibility of the device deinit code to free the 89 * @_arrayfield memory. 90 */ 91 #define DEFINE_PROP_ARRAY(_name, _state, _field, \ 92 _arrayfield, _arrayprop, _arraytype) { \ 93 .name = (PROP_ARRAY_LEN_PREFIX _name), \ 94 .info = &(qdev_prop_arraylen), \ 95 .offset = offsetof(_state, _field) \ 96 + type_check(uint32_t, typeof_field(_state, _field)), \ 97 .qtype = QTYPE_QINT, \ 98 .arrayinfo = &(_arrayprop), \ 99 .arrayfieldsize = sizeof(_arraytype), \ 100 .arrayoffset = offsetof(_state, _arrayfield), \ 101 } 102 103 #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ 104 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t) 105 #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \ 106 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t) 107 #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \ 108 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t) 109 #define DEFINE_PROP_INT32(_n, _s, _f, _d) \ 110 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t) 111 #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \ 112 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t) 113 #define DEFINE_PROP_HEX8(_n, _s, _f, _d) \ 114 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex8, uint8_t) 115 #define DEFINE_PROP_HEX32(_n, _s, _f, _d) \ 116 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t) 117 #define DEFINE_PROP_HEX64(_n, _s, _f, _d) \ 118 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t) 119 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \ 120 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t) 121 122 #define DEFINE_PROP_PTR(_n, _s, _f) \ 123 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*) 124 #define DEFINE_PROP_CHR(_n, _s, _f) \ 125 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*) 126 #define DEFINE_PROP_STRING(_n, _s, _f) \ 127 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*) 128 #define DEFINE_PROP_NETDEV(_n, _s, _f) \ 129 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers) 130 #define DEFINE_PROP_VLAN(_n, _s, _f) \ 131 DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NICPeers) 132 #define DEFINE_PROP_DRIVE(_n, _s, _f) \ 133 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *) 134 #define DEFINE_PROP_MACADDR(_n, _s, _f) \ 135 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) 136 #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \ 137 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \ 138 LostTickPolicy) 139 #define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \ 140 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int) 141 #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f, _d) \ 142 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t) 143 #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \ 144 DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress) 145 146 #define DEFINE_PROP_END_OF_LIST() \ 147 {} 148 149 /* Set properties between creation and init. */ 150 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop); 151 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value); 152 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value); 153 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value); 154 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); 155 void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); 156 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value); 157 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value); 158 void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value); 159 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value); 160 void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value); 161 int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT; 162 void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value); 163 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value); 164 void qdev_prop_set_enum(DeviceState *dev, const char *name, int value); 165 /* FIXME: Remove opaque pointer properties. */ 166 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); 167 168 void qdev_prop_register_global(GlobalProperty *prop); 169 void qdev_prop_register_global_list(GlobalProperty *props); 170 void qdev_prop_set_globals(DeviceState *dev); 171 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, 172 Property *prop, const char *value); 173 174 /** 175 * @qdev_property_add_static - add a @Property to a device referencing a 176 * field in a struct. 177 */ 178 void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp); 179 180 /** 181 * @qdev_prop_set_after_realize: 182 * @dev: device 183 * @name: name of property 184 * @errp: indirect pointer to Error to be set 185 * Set the Error object to report that an attempt was made to set a property 186 * on a device after it has already been realized. This is a utility function 187 * which allows property-setter functions to easily report the error in 188 * a friendly format identifying both the device and the property. 189 */ 190 void qdev_prop_set_after_realize(DeviceState *dev, const char *name, 191 Error **errp); 192 #endif 193