2012-08-11 01:00:43 +08:00
|
|
|
#ifndef QEMU_QDEV_PROPERTIES_H
|
|
|
|
#define QEMU_QDEV_PROPERTIES_H
|
|
|
|
|
2013-02-04 22:40:22 +08:00
|
|
|
#include "hw/qdev-core.h"
|
2012-08-11 01:00:43 +08:00
|
|
|
|
|
|
|
/*** qdev-properties.c ***/
|
|
|
|
|
|
|
|
extern PropertyInfo qdev_prop_bit;
|
2015-06-01 16:45:39 +08:00
|
|
|
extern PropertyInfo qdev_prop_bit64;
|
2013-03-08 00:16:18 +08:00
|
|
|
extern PropertyInfo qdev_prop_bool;
|
2012-08-11 01:00:43 +08: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;
|
2013-07-29 22:47:56 +08:00
|
|
|
extern PropertyInfo qdev_prop_size;
|
2012-08-11 01:00:43 +08:00
|
|
|
extern PropertyInfo qdev_prop_string;
|
|
|
|
extern PropertyInfo qdev_prop_chr;
|
|
|
|
extern PropertyInfo qdev_prop_ptr;
|
|
|
|
extern PropertyInfo qdev_prop_macaddr;
|
2016-03-16 02:34:49 +08:00
|
|
|
extern PropertyInfo qdev_prop_on_off_auto;
|
2012-08-11 01:00:43 +08:00
|
|
|
extern PropertyInfo qdev_prop_losttickpolicy;
|
2016-06-29 23:41:35 +08:00
|
|
|
extern PropertyInfo qdev_prop_blockdev_on_error;
|
2012-08-11 01:00:43 +08:00
|
|
|
extern PropertyInfo qdev_prop_bios_chs_trans;
|
2016-01-23 04:51:00 +08:00
|
|
|
extern PropertyInfo qdev_prop_fdc_drive_type;
|
2012-08-11 01:00:43 +08:00
|
|
|
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-16 00:41:57 +08:00
|
|
|
extern PropertyInfo qdev_prop_arraylen;
|
2012-08-11 01:00:43 +08:00
|
|
|
|
|
|
|
#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
|
|
|
|
.name = (_name), \
|
|
|
|
.info = &(_prop), \
|
|
|
|
.offset = offsetof(_state, _field) \
|
2013-01-30 19:12:28 +08:00
|
|
|
+ type_check(_type, typeof_field(_state, _field)), \
|
2012-08-11 01:00:43 +08:00
|
|
|
}
|
2017-06-08 00:36:09 +08:00
|
|
|
|
2017-06-08 00:36:07 +08:00
|
|
|
#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) { \
|
2012-08-11 01:00:43 +08:00
|
|
|
.name = (_name), \
|
|
|
|
.info = &(_prop), \
|
|
|
|
.offset = offsetof(_state, _field) \
|
|
|
|
+ type_check(_type,typeof_field(_state, _field)), \
|
2017-06-08 00:36:08 +08:00
|
|
|
.defval.i = (_type)_defval, \
|
2012-08-11 01:00:43 +08:00
|
|
|
}
|
2017-06-08 00:36:09 +08:00
|
|
|
|
2012-08-11 01:00:43 +08:00
|
|
|
#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)), \
|
2017-06-08 00:36:09 +08:00
|
|
|
.defval.u = (bool)_defval, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) { \
|
|
|
|
.name = (_name), \
|
|
|
|
.info = &(_prop), \
|
|
|
|
.offset = offsetof(_state, _field) \
|
|
|
|
+ type_check(_type, typeof_field(_state, _field)), \
|
|
|
|
.defval.u = (_type)_defval, \
|
2012-08-11 01:00:43 +08:00
|
|
|
}
|
2017-06-08 00:36:09 +08:00
|
|
|
|
2015-06-01 16:45:39 +08:00
|
|
|
#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \
|
|
|
|
.name = (_name), \
|
2015-07-09 19:01:14 +08:00
|
|
|
.info = &(qdev_prop_bit64), \
|
2015-06-01 16:45:39 +08:00
|
|
|
.bitnr = (_bit), \
|
|
|
|
.offset = offsetof(_state, _field) \
|
|
|
|
+ type_check(uint64_t, typeof_field(_state, _field)), \
|
2017-06-08 00:36:09 +08:00
|
|
|
.defval.u = (bool)_defval, \
|
2015-06-01 16:45:39 +08:00
|
|
|
}
|
2012-08-11 01:00:43 +08:00
|
|
|
|
2013-03-08 00:16:18 +08: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)), \
|
2017-06-08 00:36:09 +08:00
|
|
|
.defval.u = (bool)_defval, \
|
2013-03-08 00:16:18 +08:00
|
|
|
}
|
|
|
|
|
2013-03-16 00:41:57 +08: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)), \
|
|
|
|
.arrayinfo = &(_arrayprop), \
|
|
|
|
.arrayfieldsize = sizeof(_arraytype), \
|
|
|
|
.arrayoffset = offsetof(_state, _arrayfield), \
|
|
|
|
}
|
|
|
|
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
|
2017-06-08 00:36:09 +08:00
|
|
|
DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
|
2017-06-08 00:36:09 +08:00
|
|
|
DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
|
2017-06-08 00:36:09 +08:00
|
|
|
DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_INT32(_n, _s, _f, _d) \
|
2017-06-08 00:36:07 +08:00
|
|
|
DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t)
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
|
2017-06-08 00:36:09 +08:00
|
|
|
DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
|
2013-07-29 22:47:56 +08:00
|
|
|
#define DEFINE_PROP_SIZE(_n, _s, _f, _d) \
|
2017-06-08 00:36:09 +08:00
|
|
|
DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t)
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
|
2017-06-08 00:36:07 +08:00
|
|
|
DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
|
2012-08-11 01:00:43 +08:00
|
|
|
|
2013-11-29 17:43:45 +08:00
|
|
|
/*
|
|
|
|
* Please avoid pointer properties. If you must use them, you must
|
|
|
|
* cover them in their device's class init function as follows:
|
|
|
|
*
|
|
|
|
* - If the property must be set, the device cannot be used with
|
|
|
|
* device_add, so add code like this:
|
|
|
|
* |* Reason: pointer property "NAME-OF-YOUR-PROP" *|
|
|
|
|
* DeviceClass *dc = DEVICE_CLASS(class);
|
2017-05-04 04:35:44 +08:00
|
|
|
* dc->user_creatable = false;
|
2013-11-29 17:43:45 +08:00
|
|
|
*
|
|
|
|
* - If the property may safely remain null, document it like this:
|
|
|
|
* |*
|
|
|
|
* * Note: pointer property "interrupt_vector" may remain null, thus
|
2017-05-04 04:35:44 +08:00
|
|
|
* * no need for dc->user_creatable = false;
|
2013-11-29 17:43:45 +08:00
|
|
|
* *|
|
|
|
|
*/
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_PTR(_n, _s, _f) \
|
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
|
2013-11-29 17:43:45 +08:00
|
|
|
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_CHR(_n, _s, _f) \
|
2016-10-22 17:52:51 +08:00
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharBackend)
|
2012-08-11 01:00:43 +08:00
|
|
|
#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 19:12:28 +08:00
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers)
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_VLAN(_n, _s, _f) \
|
2013-01-30 19:12:28 +08:00
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NICPeers)
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_DRIVE(_n, _s, _f) \
|
2014-10-07 19:59:18 +08:00
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockBackend *)
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_MACADDR(_n, _s, _f) \
|
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
|
2016-03-16 02:34:49 +08:00
|
|
|
#define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
|
2017-06-08 00:36:07 +08:00
|
|
|
DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
|
2017-06-08 00:36:07 +08:00
|
|
|
DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
|
2012-08-11 01:00:43 +08:00
|
|
|
LostTickPolicy)
|
2016-06-29 23:41:35 +08:00
|
|
|
#define DEFINE_PROP_BLOCKDEV_ON_ERROR(_n, _s, _f, _d) \
|
2017-06-08 00:36:07 +08:00
|
|
|
DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_blockdev_on_error, \
|
2016-06-29 23:41:35 +08:00
|
|
|
BlockdevOnError)
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
|
2017-06-08 00:36:07 +08:00
|
|
|
DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
|
2015-02-16 19:47:58 +08:00
|
|
|
#define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \
|
2017-06-08 00:36:09 +08:00
|
|
|
DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t)
|
2012-08-11 01:00:43 +08:00
|
|
|
#define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
|
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
|
2017-02-16 22:06:24 +08:00
|
|
|
#define DEFINE_PROP_MEMORY_REGION(_n, _s, _f) \
|
|
|
|
DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *)
|
2012-08-11 01:00:43 +08:00
|
|
|
|
|
|
|
#define DEFINE_PROP_END_OF_LIST() \
|
|
|
|
{}
|
|
|
|
|
|
|
|
/* Set properties between creation and init. */
|
|
|
|
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
|
|
|
|
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);
|
2016-12-07 21:20:22 +08:00
|
|
|
void qdev_prop_set_chr(DeviceState *dev, const char *name, Chardev *value);
|
2012-08-11 01:00:43 +08:00
|
|
|
void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value);
|
2015-03-10 02:17:26 +08:00
|
|
|
void qdev_prop_set_drive(DeviceState *dev, const char *name,
|
|
|
|
BlockBackend *value, Error **errp);
|
2017-03-11 04:05:49 +08:00
|
|
|
void qdev_prop_set_macaddr(DeviceState *dev, const char *name,
|
|
|
|
const uint8_t *value);
|
2012-08-11 01:00:43 +08:00
|
|
|
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-06 00:49:11 +08:00
|
|
|
void qdev_prop_register_global(GlobalProperty *prop);
|
2012-08-11 01:00:43 +08:00
|
|
|
void qdev_prop_register_global_list(GlobalProperty *props);
|
2014-08-09 03:03:30 +08:00
|
|
|
int qdev_prop_check_globals(void);
|
2015-01-20 17:04:07 +08:00
|
|
|
void qdev_prop_set_globals(DeviceState *dev);
|
2012-08-11 01:00:43 +08:00
|
|
|
void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
|
|
|
|
Property *prop, const char *value);
|
|
|
|
|
2017-06-27 12:10:10 +08:00
|
|
|
/**
|
|
|
|
* register_compat_prop:
|
|
|
|
*
|
|
|
|
* Register internal (not user-provided) global property, changing the
|
|
|
|
* default value of a given property in a device type. This can be used
|
|
|
|
* for enabling machine-type compatibility or for enabling
|
|
|
|
* accelerator-specific defaults in devices.
|
|
|
|
*
|
|
|
|
* The property values set using this function must be always valid and
|
|
|
|
* never report setter errors, as the property will have
|
|
|
|
* GlobalProperty::errp set to &error_abort.
|
|
|
|
*
|
|
|
|
* User-provided global properties should override internal global
|
|
|
|
* properties, so callers of this function should ensure that it is
|
|
|
|
* called before user-provided global properties are registered.
|
|
|
|
*
|
|
|
|
* @driver: Device type to be affected
|
|
|
|
* @property: Property whose default value is going to be changed
|
|
|
|
* @value: New default value for the property
|
|
|
|
*/
|
|
|
|
void register_compat_prop(const char *driver, const char *property,
|
|
|
|
const char *value);
|
|
|
|
|
2012-08-11 01:00:43 +08:00
|
|
|
/**
|
2016-04-17 15:45:54 +08:00
|
|
|
* qdev_property_add_static:
|
|
|
|
* @dev: Device to add the property to.
|
|
|
|
* @prop: The qdev property definition.
|
|
|
|
* @errp: location to store error information.
|
|
|
|
*
|
|
|
|
* Add a static QOM property to @dev for qdev property @prop.
|
|
|
|
* On error, store error in @errp. Static properties access data in a struct.
|
|
|
|
* The type of the QOM property is derived from prop->info.
|
2012-08-11 01:00:43 +08:00
|
|
|
*/
|
|
|
|
void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
|
|
|
|
|
2014-06-18 17:58:32 +08:00
|
|
|
void qdev_alias_all_properties(DeviceState *target, Object *source);
|
|
|
|
|
2013-03-25 21:40:44 +08: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);
|
2014-03-19 15:58:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* qdev_prop_allow_set_link_before_realize:
|
|
|
|
*
|
|
|
|
* Set the #Error object if an attempt is made to set the link after realize.
|
|
|
|
* This function should be used as the check() argument to
|
|
|
|
* object_property_add_link().
|
|
|
|
*/
|
|
|
|
void qdev_prop_allow_set_link_before_realize(Object *obj, const char *name,
|
|
|
|
Object *val, Error **errp);
|
|
|
|
|
2012-08-11 01:00:43 +08:00
|
|
|
#endif
|