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, \
|
DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pcie_link_width, \
|
||||||
PCIExpLinkWidth)
|
PCIExpLinkWidth)
|
||||||
|
|
||||||
#define DEFINE_PROP_UUID(_name, _state, _field) { \
|
#define DEFINE_PROP_UUID(_name, _state, _field) \
|
||||||
.name = (_name), \
|
DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID, \
|
||||||
.info = &qdev_prop_uuid, \
|
.set_default = true)
|
||||||
.offset = offsetof(_state, _field) \
|
|
||||||
+ type_check(QemuUUID, typeof_field(_state, _field)), \
|
|
||||||
.set_default = true, \
|
|
||||||
}
|
|
||||||
#define DEFINE_PROP_AUDIODEV(_n, _s, _f) \
|
#define DEFINE_PROP_AUDIODEV(_n, _s, _f) \
|
||||||
DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
|
DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
|
||||||
|
|
||||||
#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) { \
|
#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) \
|
||||||
.name = (_name), \
|
DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID)
|
||||||
.info = &qdev_prop_uuid, \
|
|
||||||
.offset = offsetof(_state, _field) \
|
|
||||||
+ type_check(QemuUUID, typeof_field(_state, _field)), \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -61,73 +61,46 @@ extern const PropertyInfo qdev_prop_size32;
|
|||||||
extern const PropertyInfo qdev_prop_arraylen;
|
extern const PropertyInfo qdev_prop_arraylen;
|
||||||
extern const PropertyInfo qdev_prop_link;
|
extern const PropertyInfo qdev_prop_link;
|
||||||
|
|
||||||
#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
|
#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) { \
|
||||||
.name = (_name), \
|
.name = (_name), \
|
||||||
.info = &(_prop), \
|
.info = &(_prop), \
|
||||||
.offset = offsetof(_state, _field) \
|
.offset = offsetof(_state, _field) \
|
||||||
+ type_check(_type, typeof_field(_state, _field)), \
|
+ type_check(_type, typeof_field(_state, _field)), \
|
||||||
|
__VA_ARGS__ \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) { \
|
#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \
|
||||||
.name = (_name), \
|
DEFINE_PROP(_name, _state, _field, _prop, _type, \
|
||||||
.info = &(_prop), \
|
.set_default = true, \
|
||||||
.offset = offsetof(_state, _field) \
|
.defval.i = (_type)_defval)
|
||||||
+ type_check(_type,typeof_field(_state, _field)), \
|
|
||||||
.set_default = true, \
|
|
||||||
.defval.i = (_type)_defval, \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
|
#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
|
||||||
.name = (_name), \
|
DEFINE_PROP(_name, _state, _field, _prop, _type)
|
||||||
.info = &(_prop), \
|
|
||||||
.offset = offsetof(_state, _field) \
|
|
||||||
+ type_check(_type, typeof_field(_state, _field)), \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
|
#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) \
|
||||||
.name = (_name), \
|
DEFINE_PROP(_name, _state, _field, qdev_prop_bit, uint32_t, \
|
||||||
.info = &(qdev_prop_bit), \
|
.bitnr = (_bit), \
|
||||||
.bitnr = (_bit), \
|
.set_default = true, \
|
||||||
.offset = offsetof(_state, _field) \
|
.defval.u = (bool)_defval)
|
||||||
+ type_check(uint32_t,typeof_field(_state, _field)), \
|
|
||||||
.set_default = true, \
|
|
||||||
.defval.u = (bool)_defval, \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) { \
|
#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) \
|
||||||
.name = (_name), \
|
DEFINE_PROP(_name, _state, _field, _prop, _type, \
|
||||||
.info = &(_prop), \
|
.set_default = true, \
|
||||||
.offset = offsetof(_state, _field) \
|
.defval.u = (_type)_defval)
|
||||||
+ type_check(_type, typeof_field(_state, _field)), \
|
|
||||||
.set_default = true, \
|
|
||||||
.defval.u = (_type)_defval, \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
|
#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
|
||||||
.name = (_name), \
|
DEFINE_PROP(_name, _state, _field, _prop, _type)
|
||||||
.info = &(_prop), \
|
|
||||||
.offset = offsetof(_state, _field) \
|
|
||||||
+ type_check(_type, typeof_field(_state, _field)), \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \
|
#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) \
|
||||||
.name = (_name), \
|
DEFINE_PROP(_name, _state, _field, qdev_prop_bit64, uint64_t, \
|
||||||
.info = &(qdev_prop_bit64), \
|
.bitnr = (_bit), \
|
||||||
.bitnr = (_bit), \
|
.set_default = true, \
|
||||||
.offset = offsetof(_state, _field) \
|
.defval.u = (bool)_defval)
|
||||||
+ type_check(uint64_t, typeof_field(_state, _field)), \
|
|
||||||
.set_default = true, \
|
|
||||||
.defval.u = (bool)_defval, \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \
|
#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \
|
||||||
.name = (_name), \
|
DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool, \
|
||||||
.info = &(qdev_prop_bool), \
|
.set_default = true, \
|
||||||
.offset = offsetof(_state, _field) \
|
.defval.u = (bool)_defval)
|
||||||
+ type_check(bool, typeof_field(_state, _field)), \
|
|
||||||
.set_default = true, \
|
|
||||||
.defval.u = (bool)_defval, \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PROP_ARRAY_LEN_PREFIX "len-"
|
#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
|
* It is the responsibility of the device deinit code to free the
|
||||||
* @_arrayfield memory.
|
* @_arrayfield memory.
|
||||||
*/
|
*/
|
||||||
#define DEFINE_PROP_ARRAY(_name, _state, _field, \
|
#define DEFINE_PROP_ARRAY(_name, _state, _field, \
|
||||||
_arrayfield, _arrayprop, _arraytype) { \
|
_arrayfield, _arrayprop, _arraytype) \
|
||||||
.name = (PROP_ARRAY_LEN_PREFIX _name), \
|
DEFINE_PROP((PROP_ARRAY_LEN_PREFIX _name), \
|
||||||
.info = &(qdev_prop_arraylen), \
|
_state, _field, qdev_prop_arraylen, uint32_t, \
|
||||||
.set_default = true, \
|
.set_default = true, \
|
||||||
.defval.u = 0, \
|
.defval.u = 0, \
|
||||||
.offset = offsetof(_state, _field) \
|
.arrayinfo = &(_arrayprop), \
|
||||||
+ type_check(uint32_t, typeof_field(_state, _field)), \
|
.arrayfieldsize = sizeof(_arraytype), \
|
||||||
.arrayinfo = &(_arrayprop), \
|
.arrayoffset = offsetof(_state, _arrayfield))
|
||||||
.arrayfieldsize = sizeof(_arraytype), \
|
|
||||||
.arrayoffset = offsetof(_state, _arrayfield), \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) { \
|
#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) \
|
||||||
.name = (_name), \
|
DEFINE_PROP(_name, _state, _field, qdev_prop_link, _ptr_type, \
|
||||||
.info = &(qdev_prop_link), \
|
.link_type = _type)
|
||||||
.offset = offsetof(_state, _field) \
|
|
||||||
+ type_check(_ptr_type, typeof_field(_state, _field)), \
|
|
||||||
.link_type = _type, \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
|
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
|
||||||
DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
|
DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
|
||||||
|
Loading…
Reference in New Issue
Block a user