[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 16/53] qdev: Reuse DEFINE_PROP in all DEFINE_PROP_* macros
From: |
Eduardo Habkost |
Subject: |
[PATCH v3 16/53] qdev: Reuse DEFINE_PROP in all DEFINE_PROP_* macros |
Date: |
Thu, 12 Nov 2020 16:43:13 -0500 |
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>
---
Changes v1 -> v2:
* Redone after UUID property was moved
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
include/hw/qdev-properties-system.h | 19 ++---
include/hw/qdev-properties.h | 114 ++++++++++------------------
2 files changed, 46 insertions(+), 87 deletions(-)
diff --git a/include/hw/qdev-properties-system.h
b/include/hw/qdev-properties-system.h
index 29529dc999..0ac327ae60 100644
--- a/include/hw/qdev-properties-system.h
+++ b/include/hw/qdev-properties-system.h
@@ -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
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index d35d4aae84..1b58e4f922 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -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)
--
2.28.0
- [PATCH v3 06/53] qdev: Don't use dev->id on set_size32() error message, (continued)
- [PATCH v3 06/53] qdev: Don't use dev->id on set_size32() error message, Eduardo Habkost, 2020/11/12
- [PATCH v3 10/53] qdev: Make qdev_find_global_prop() get Object* argument, Eduardo Habkost, 2020/11/12
- [PATCH v3 11/53] qdev: Make check_prop_still_unset() get Object* argument, Eduardo Habkost, 2020/11/12
- [PATCH v3 09/53] qdev: Make qdev_get_prop_ptr() get Object* arg, Eduardo Habkost, 2020/11/12
- [PATCH v3 12/53] qdev: Make error_set_from_qdev_prop_error() get Object* argument, Eduardo Habkost, 2020/11/12
- [PATCH v3 13/53] qdev: Make qdev_propinfo_get_uint16() static, Eduardo Habkost, 2020/11/12
- [PATCH v3 14/53] qdev: Move UUID property to qdev-properties-system.c, Eduardo Habkost, 2020/11/12
- [PATCH v3 17/53] sparc: Use DEFINE_PROP for nwindows property, Eduardo Habkost, 2020/11/12
- [PATCH v3 16/53] qdev: Reuse DEFINE_PROP in all DEFINE_PROP_* macros,
Eduardo Habkost <=
- [PATCH v3 15/53] qdev: Move softmmu properties to qdev-properties-system.h, Eduardo Habkost, 2020/11/12
- [PATCH v3 18/53] qdev: Get just property name at error_set_from_qdev_prop_error(), Eduardo Habkost, 2020/11/12
- [PATCH v3 19/53] qdev: Avoid using prop->name unnecessarily, Eduardo Habkost, 2020/11/12
- [PATCH v3 20/53] qdev: Add name parameter to qdev_class_add_property(), Eduardo Habkost, 2020/11/12
- [PATCH v3 21/53] qdev: Add name argument to PropertyInfo.create method, Eduardo Habkost, 2020/11/12
- [PATCH v3 22/53] qdev: Wrap getters and setters in separate helpers, Eduardo Habkost, 2020/11/12
- [PATCH v3 23/53] qdev: Move dev->realized check to qdev_property_set(), Eduardo Habkost, 2020/11/12
- [PATCH v3 24/53] qdev: Make PropertyInfo.create return ObjectProperty*, Eduardo Habkost, 2020/11/12
- [PATCH v3 25/53] qdev: Make qdev_class_add_property() more flexible, Eduardo Habkost, 2020/11/12
- [PATCH v3 26/53] qdev: Separate generic and device-specific property registration, Eduardo Habkost, 2020/11/12