qdev: Reuse DEFINE_PROP in all DEFINE_PROP_* macros
Instead of duplicating the code that sets name, info, offset, and does type checking, make DEFINE_PROP accept a variable number of arguments and reuse it in all DEFINE_PROP_* macros. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Igor Mammedov <imammedo@redhat.com> Message-Id: <20201211220529.2290218-17-ehabkost@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
parent
ce35e2295e
commit
45efa07f0f
@ -63,22 +63,15 @@ extern const PropertyInfo qdev_prop_pcie_link_width;
|
||||
DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pcie_link_width, \
|
||||
PCIExpLinkWidth)
|
||||
|
||||
#define DEFINE_PROP_UUID(_name, _state, _field) { \
|
||||
.name = (_name), \
|
||||
.info = &qdev_prop_uuid, \
|
||||
.offset = offsetof(_state, _field) \
|
||||
+ type_check(QemuUUID, typeof_field(_state, _field)), \
|
||||
.set_default = true, \
|
||||
}
|
||||
#define DEFINE_PROP_UUID(_name, _state, _field) \
|
||||
DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID, \
|
||||
.set_default = true)
|
||||
|
||||
#define DEFINE_PROP_AUDIODEV(_n, _s, _f) \
|
||||
DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
|
||||
|
||||
#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) { \
|
||||
.name = (_name), \
|
||||
.info = &qdev_prop_uuid, \
|
||||
.offset = offsetof(_state, _field) \
|
||||
+ type_check(QemuUUID, typeof_field(_state, _field)), \
|
||||
}
|
||||
#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) \
|
||||
DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID)
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -61,73 +61,46 @@ extern const PropertyInfo qdev_prop_size32;
|
||||
extern const PropertyInfo qdev_prop_arraylen;
|
||||
extern const PropertyInfo qdev_prop_link;
|
||||
|
||||
#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
|
||||
#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) { \
|
||||
.name = (_name), \
|
||||
.info = &(_prop), \
|
||||
.offset = offsetof(_state, _field) \
|
||||
+ type_check(_type, typeof_field(_state, _field)), \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) { \
|
||||
.name = (_name), \
|
||||
.info = &(_prop), \
|
||||
.offset = offsetof(_state, _field) \
|
||||
+ type_check(_type,typeof_field(_state, _field)), \
|
||||
.set_default = true, \
|
||||
.defval.i = (_type)_defval, \
|
||||
}
|
||||
#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \
|
||||
DEFINE_PROP(_name, _state, _field, _prop, _type, \
|
||||
.set_default = true, \
|
||||
.defval.i = (_type)_defval)
|
||||
|
||||
#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
|
||||
.name = (_name), \
|
||||
.info = &(_prop), \
|
||||
.offset = offsetof(_state, _field) \
|
||||
+ type_check(_type, typeof_field(_state, _field)), \
|
||||
}
|
||||
#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
|
||||
DEFINE_PROP(_name, _state, _field, _prop, _type)
|
||||
|
||||
#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)), \
|
||||
.set_default = true, \
|
||||
.defval.u = (bool)_defval, \
|
||||
}
|
||||
#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) \
|
||||
DEFINE_PROP(_name, _state, _field, qdev_prop_bit, uint32_t, \
|
||||
.bitnr = (_bit), \
|
||||
.set_default = true, \
|
||||
.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)), \
|
||||
.set_default = true, \
|
||||
.defval.u = (_type)_defval, \
|
||||
}
|
||||
#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) \
|
||||
DEFINE_PROP(_name, _state, _field, _prop, _type, \
|
||||
.set_default = true, \
|
||||
.defval.u = (_type)_defval)
|
||||
|
||||
#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
|
||||
.name = (_name), \
|
||||
.info = &(_prop), \
|
||||
.offset = offsetof(_state, _field) \
|
||||
+ type_check(_type, typeof_field(_state, _field)), \
|
||||
}
|
||||
#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
|
||||
DEFINE_PROP(_name, _state, _field, _prop, _type)
|
||||
|
||||
#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \
|
||||
.name = (_name), \
|
||||
.info = &(qdev_prop_bit64), \
|
||||
.bitnr = (_bit), \
|
||||
.offset = offsetof(_state, _field) \
|
||||
+ type_check(uint64_t, typeof_field(_state, _field)), \
|
||||
.set_default = true, \
|
||||
.defval.u = (bool)_defval, \
|
||||
}
|
||||
#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) \
|
||||
DEFINE_PROP(_name, _state, _field, qdev_prop_bit64, uint64_t, \
|
||||
.bitnr = (_bit), \
|
||||
.set_default = true, \
|
||||
.defval.u = (bool)_defval)
|
||||
|
||||
#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)), \
|
||||
.set_default = true, \
|
||||
.defval.u = (bool)_defval, \
|
||||
}
|
||||
#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \
|
||||
DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool, \
|
||||
.set_default = true, \
|
||||
.defval.u = (bool)_defval)
|
||||
|
||||
#define PROP_ARRAY_LEN_PREFIX "len-"
|
||||
|
||||
@ -155,26 +128,19 @@ extern const PropertyInfo qdev_prop_link;
|
||||
* 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), \
|
||||
.set_default = true, \
|
||||
.defval.u = 0, \
|
||||
.offset = offsetof(_state, _field) \
|
||||
+ type_check(uint32_t, typeof_field(_state, _field)), \
|
||||
.arrayinfo = &(_arrayprop), \
|
||||
.arrayfieldsize = sizeof(_arraytype), \
|
||||
.arrayoffset = offsetof(_state, _arrayfield), \
|
||||
}
|
||||
#define DEFINE_PROP_ARRAY(_name, _state, _field, \
|
||||
_arrayfield, _arrayprop, _arraytype) \
|
||||
DEFINE_PROP((PROP_ARRAY_LEN_PREFIX _name), \
|
||||
_state, _field, qdev_prop_arraylen, uint32_t, \
|
||||
.set_default = true, \
|
||||
.defval.u = 0, \
|
||||
.arrayinfo = &(_arrayprop), \
|
||||
.arrayfieldsize = sizeof(_arraytype), \
|
||||
.arrayoffset = offsetof(_state, _arrayfield))
|
||||
|
||||
#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) { \
|
||||
.name = (_name), \
|
||||
.info = &(qdev_prop_link), \
|
||||
.offset = offsetof(_state, _field) \
|
||||
+ type_check(_ptr_type, typeof_field(_state, _field)), \
|
||||
.link_type = _type, \
|
||||
}
|
||||
#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) \
|
||||
DEFINE_PROP(_name, _state, _field, qdev_prop_link, _ptr_type, \
|
||||
.link_type = _type)
|
||||
|
||||
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
|
||||
DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
|
||||
|
Loading…
Reference in New Issue
Block a user