mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 16:53:55 -06:00
qdev: Implement (variable length) array properties
Add support for declaring array properties for qdev devices. These work by defining an initial static property 'len-arrayname' which the user of the device should set to the desired size of the array. When this property is set, memory is allocated for the array elements, and dynamic properties "arrayname[0]", "arrayname[1]"... are created so the user of the device can then set the values of the individual array elements. Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
1f56f50ac4
commit
0be6bfac62
3 changed files with 146 additions and 0 deletions
|
@ -26,6 +26,7 @@ extern PropertyInfo qdev_prop_vlan;
|
|||
extern PropertyInfo qdev_prop_pci_devfn;
|
||||
extern PropertyInfo qdev_prop_blocksize;
|
||||
extern PropertyInfo qdev_prop_pci_host_devaddr;
|
||||
extern PropertyInfo qdev_prop_arraylen;
|
||||
|
||||
#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
|
||||
.name = (_name), \
|
||||
|
@ -51,6 +52,44 @@ extern PropertyInfo qdev_prop_pci_host_devaddr;
|
|||
.defval = (bool)_defval, \
|
||||
}
|
||||
|
||||
#define PROP_ARRAY_LEN_PREFIX "len-"
|
||||
|
||||
/**
|
||||
* DEFINE_PROP_ARRAY:
|
||||
* @_name: name of the array
|
||||
* @_state: name of the device state structure type
|
||||
* @_field: uint32_t field in @_state to hold the array length
|
||||
* @_arrayfield: field in @_state (of type '@_arraytype *') which
|
||||
* will point to the array
|
||||
* @_arrayprop: PropertyInfo defining what property the array elements have
|
||||
* @_arraytype: C type of the array elements
|
||||
*
|
||||
* Define device properties for a variable-length array _name. A
|
||||
* static property "len-arrayname" is defined. When the device creator
|
||||
* sets this property to the desired length of array, further dynamic
|
||||
* properties "arrayname[0]", "arrayname[1]", ... are defined so the
|
||||
* device creator can set the array element values. Setting the
|
||||
* "len-arrayname" property more than once is an error.
|
||||
*
|
||||
* When the array length is set, the @_field member of the device
|
||||
* struct is set to the array length, and @_arrayfield is set to point
|
||||
* to (zero-initialised) memory allocated for the array. For a zero
|
||||
* length array, @_field will be set to 0 and @_arrayfield to NULL.
|
||||
* It is the responsibility of the device deinit code to free the
|
||||
* @_arrayfield memory.
|
||||
*/
|
||||
#define DEFINE_PROP_ARRAY(_name, _state, _field, \
|
||||
_arrayfield, _arrayprop, _arraytype) { \
|
||||
.name = (PROP_ARRAY_LEN_PREFIX _name), \
|
||||
.info = &(qdev_prop_arraylen), \
|
||||
.offset = offsetof(_state, _field) \
|
||||
+ type_check(uint32_t, typeof_field(_state, _field)), \
|
||||
.qtype = QTYPE_QINT, \
|
||||
.arrayinfo = &(_arrayprop), \
|
||||
.arrayfieldsize = sizeof(_arraytype), \
|
||||
.arrayoffset = offsetof(_state, _arrayfield), \
|
||||
}
|
||||
|
||||
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
|
||||
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
|
||||
#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue