2012-08-10 17:00:43 +00:00
|
|
|
#ifndef QEMU_QDEV_PROPERTIES_H
|
|
|
|
#define QEMU_QDEV_PROPERTIES_H
|
|
|
|
|
2013-02-04 14:40:22 +00:00
|
|
|
#include "hw/qdev-core.h"
|
2012-08-10 17:00:43 +00:00
|
|
|
|
|
|
|
/*** qdev-properties.c ***/
|
|
|
|
|
|
|
|
extern PropertyInfo qdev_prop_bit;
|
2013-03-07 16:16:18 +00:00
|
|
|
extern PropertyInfo qdev_prop_bool;
|
2012-08-10 17:00:43 +00:00
|
|
|
extern PropertyInfo qdev_prop_uint8;
|
|
|
|
extern PropertyInfo qdev_prop_uint16;
|
|
|
|
extern PropertyInfo qdev_prop_uint32;
|
|
|
|
extern PropertyInfo qdev_prop_int32;
|
|
|
|
extern PropertyInfo qdev_prop_uint64;
|
|
|
|
extern PropertyInfo qdev_prop_hex8;
|
|
|
|
extern PropertyInfo qdev_prop_hex32;
|
|
|
|
extern PropertyInfo qdev_prop_hex64;
|
2013-07-29 14:47:56 +00:00
|
|
|
extern PropertyInfo qdev_prop_size;
|
2012-08-10 17:00:43 +00:00
|
|
|
extern PropertyInfo qdev_prop_string;
|
|
|
|
extern PropertyInfo qdev_prop_chr;
|
|
|
|
extern PropertyInfo qdev_prop_ptr;
|
|
|
|
extern PropertyInfo qdev_prop_macaddr;
|
|
|
|
extern PropertyInfo qdev_prop_losttickpolicy;
|
|
|
|
extern PropertyInfo qdev_prop_bios_chs_trans;
|
|
|
|
extern PropertyInfo qdev_prop_drive;
|
|
|
|
extern PropertyInfo qdev_prop_netdev;
|
|
|
|
extern PropertyInfo qdev_prop_vlan;
|
|
|
|
extern PropertyInfo qdev_prop_pci_devfn;
|
|
|
|
extern PropertyInfo qdev_prop_blocksize;
|
|
|
|
extern PropertyInfo qdev_prop_pci_host_devaddr;
|
2013-03-15 16:41:57 +00:00
|
|
|
extern PropertyInfo qdev_prop_arraylen;
|
2012-08-10 17:00:43 +00:00
|
|
|
|
|
|
|
#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
|
|
|
|
.name = (_name), \
|
|
|
|
.info = &(_prop), \
|
|
|
|
.offset = offsetof(_state, _field) \
|
2013-01-30 11:12:28 +00:00
|
|
|
+ type_check(_type, typeof_field(_state, _field)), \
|
2012-08-10 17:00:43 +00:00
|
|
|
}
|
|
|
|
#define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
|
|
|
|
.name = (_name), \
|
|
|
|
.info = &(_prop), \
|
|
|
|
.offset = offsetof(_state, _field) \
|
|
|
|
+ type_check(_type,typeof_field(_state, _field)), \
|
|
|
|
.qtype = QTYPE_QINT, \
|
|
|
|
.defval = (_type)_defval, \
|
|
|
|
}
|
|
|
|
#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
|
|
|
|
.name = (_name), \
|
|
|
|
.info = &(qdev_prop_bit), \
|
|
|
|
.bitnr = (_bit), \
|
|
|
|
.offset = offsetof(_state, _field) \
|
|
|
|
+ type_check(uint32_t,typeof_field(_state, _field)), \
|
|
|
|
.qtype = QTYPE_QBOOL, \
|
|
|
|
.defval = (bool)_defval, \
|
|
|
|
}
|
|
|
|
|
2013-03-07 16:16:18 +00:00
|
|
|
#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \
|
|
|
|
.name = (_name), \
|
|
|
|
.info = &(qdev_prop_bool), \
|
|
|
|
.offset = offsetof(_state, _field) \
|
|
|
|
+ type_check(bool, typeof_field(_state, _field)), \
|
|
|
|
.qtype = QTYPE_QBOOL, \
|
|
|
|
.defval = (bool)_defval, \
|
|
|
|
}
|
|
|
|
|
2013-03-15 16:41:57 +00:00
|
|
|
#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), \
|
|
|
|
}
|
|
|
|
|
2012-08-10 17:00:43 +00:00
|
|
|
#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) \
|
|
|
|
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
|
|
|
|
#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
|
|
|
|
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
|
|
|
|
#define DEFINE_PROP_INT32(_n, _s, _f, _d) \
|
|
|
|
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t)
|
|
|
|
#define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
|
|
|
|
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
|
|
|
|
#define DEFINE_PROP_HEX8(_n, _s, _f, _d) \
|
|
|
|
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex8, uint8_t)
|
|
|
|
#define DEFINE_PROP_HEX32(_n, _s, _f, _d) \
|
|
|
|
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t)
|
|
|
|
#define DEFINE_PROP_HEX64(_n, _s, _f, _d) \
|
|
|
|
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
|
2013-07-29 14:47:56 +00:00
|
|
|
#define DEFINE_PROP_SIZE(_n, _s, _f, _d) \
|
|
|
|
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_size, uint64_t)
|
2012-08-10 17:00:43 +00:00
|
|
|
#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
|
|
|
|
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
|
|
|
|
|
|
|
|
#define DEFINE_PROP_PTR(_n, _s, _f) \
|
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
|
|
|
|
#define DEFINE_PROP_CHR(_n, _s, _f) \
|
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
|
|
|
|
#define DEFINE_PROP_STRING(_n, _s, _f) \
|
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
|
|
|
|
#define DEFINE_PROP_NETDEV(_n, _s, _f) \
|
2013-01-30 11:12:28 +00:00
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers)
|
2012-08-10 17:00:43 +00:00
|
|
|
#define DEFINE_PROP_VLAN(_n, _s, _f) \
|
2013-01-30 11:12:28 +00:00
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NICPeers)
|
2012-08-10 17:00:43 +00:00
|
|
|
#define DEFINE_PROP_DRIVE(_n, _s, _f) \
|
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
|
|
|
|
#define DEFINE_PROP_MACADDR(_n, _s, _f) \
|
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
|
|
|
|
#define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
|
|
|
|
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
|
|
|
|
LostTickPolicy)
|
|
|
|
#define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
|
|
|
|
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
|
|
|
|
#define DEFINE_PROP_BLOCKSIZE(_n, _s, _f, _d) \
|
|
|
|
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t)
|
|
|
|
#define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
|
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
|
|
|
|
|
|
|
|
#define DEFINE_PROP_END_OF_LIST() \
|
|
|
|
{}
|
|
|
|
|
|
|
|
/* Set properties between creation and init. */
|
|
|
|
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
|
2013-05-01 14:10:24 +00:00
|
|
|
void qdev_prop_parse(DeviceState *dev, const char *name, const char *value,
|
|
|
|
Error **errp);
|
2012-08-10 17:00:43 +00:00
|
|
|
void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
|
|
|
|
void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
|
|
|
|
void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
|
|
|
|
void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
|
|
|
|
void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
|
|
|
|
void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
|
|
|
|
void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value);
|
|
|
|
void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
|
|
|
|
void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value);
|
|
|
|
int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
|
|
|
|
void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value);
|
|
|
|
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
|
|
|
|
void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
|
|
|
|
/* FIXME: Remove opaque pointer properties. */
|
|
|
|
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
|
|
|
|
|
2012-12-05 16:49:11 +00:00
|
|
|
void qdev_prop_register_global(GlobalProperty *prop);
|
2012-08-10 17:00:43 +00:00
|
|
|
void qdev_prop_register_global_list(GlobalProperty *props);
|
2013-05-01 14:10:24 +00:00
|
|
|
void qdev_prop_set_globals(DeviceState *dev, Error **errp);
|
2013-05-01 14:03:19 +00:00
|
|
|
void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename,
|
|
|
|
Error **errp);
|
2012-08-10 17:00:43 +00:00
|
|
|
void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
|
|
|
|
Property *prop, const char *value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @qdev_property_add_static - add a @Property to a device referencing a
|
|
|
|
* field in a struct.
|
|
|
|
*/
|
|
|
|
void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
|
|
|
|
|
2013-03-25 13:40:44 +00:00
|
|
|
/**
|
|
|
|
* @qdev_prop_set_after_realize:
|
|
|
|
* @dev: device
|
|
|
|
* @name: name of property
|
|
|
|
* @errp: indirect pointer to Error to be set
|
|
|
|
* Set the Error object to report that an attempt was made to set a property
|
|
|
|
* on a device after it has already been realized. This is a utility function
|
|
|
|
* which allows property-setter functions to easily report the error in
|
|
|
|
* a friendly format identifying both the device and the property.
|
|
|
|
*/
|
|
|
|
void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
|
|
|
|
Error **errp);
|
2012-08-10 17:00:43 +00:00
|
|
|
#endif
|