[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 25/44] qdev: Separate generic and device-specific property reg
From: |
Eduardo Habkost |
Subject: |
[PATCH v2 25/44] qdev: Separate generic and device-specific property registration |
Date: |
Wed, 4 Nov 2020 11:00:02 -0500 |
qdev_class_add_property() and qdev_property_add_static() will
have code that's specific for device types.
object_class_property_add_field() and object_property_add_static()
will be generic and part of the QOM field property API. Note
that the new functions have a `name` parameter because the plan
is to eventually get rid of the Property.name field.
The declarations for the new functions are being added to
qdev-properties.h, but they will be moved to a QOM header later.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
* Patch redone after changes in previous patches in the series
* Rename new functions to object*_property_add_field()
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
hw/core/qdev-prop-internal.h | 13 +++++++++++++
include/hw/qdev-properties.h | 16 ++++++++++++++++
hw/core/qdev-properties.c | 25 +++++++++++++++++--------
3 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/hw/core/qdev-prop-internal.h b/hw/core/qdev-prop-internal.h
index 9cf5cc1d51..0e16d28171 100644
--- a/hw/core/qdev-prop-internal.h
+++ b/hw/core/qdev-prop-internal.h
@@ -27,4 +27,17 @@ void qdev_propinfo_get_int32(Object *obj, Visitor *v, const
char *name,
void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp);
+/**
+ * object_property_add_field: Add a field property to an object instance
+ * @obj: object instance
+ * @name: property name
+ * @prop: property definition
+ *
+ * This function should not be used in new code. Please add class properties
+ * instead, using object_class_add_field().
+ */
+ObjectProperty *
+object_property_add_field(Object *obj, const char *name,
+ Property *prop);
+
#endif
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index aae882317a..bbc5244ed0 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -167,6 +167,22 @@ extern const PropertyInfo qdev_prop_link;
#define DEFINE_PROP_END_OF_LIST() \
{}
+/**
+ * object_class_property_add_field: Add a field property to object class
+ * @oc: object class
+ * @name: property name
+ * @prop: property definition
+ *
+ * Add a field property to an object class. A field property is
+ * a property that will change a field at a specific offset of the
+ * object instance struct.
+ *
+ * *@prop must exist for the life time of @oc.
+ */
+ObjectProperty *
+object_class_property_add_field(ObjectClass *oc, const char *name,
+ Property *prop);
+
/*
* Set properties between creation and realization.
*
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index a5d5d74f32..e9e2a34f3b 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -835,20 +835,20 @@ const PropertyInfo qdev_prop_link = {
.create = create_link_property,
};
-void qdev_property_add_static(DeviceState *dev, Property *prop)
+ObjectProperty *
+object_property_add_field(Object *obj, const char *name, Property *prop)
{
- Object *obj = OBJECT(dev);
ObjectProperty *op;
assert(!prop->info->create);
- op = object_property_add(obj, prop->name, prop->info->name,
+ op = object_property_add(obj, name, prop->info->name,
field_prop_getter(prop->info),
field_prop_setter(prop->info),
prop->info->release,
prop);
- object_property_set_description(obj, prop->name,
+ object_property_set_description(obj, name,
prop->info->description);
if (prop->set_default) {
@@ -857,12 +857,14 @@ void qdev_property_add_static(DeviceState *dev, Property
*prop)
op->init(obj, op);
}
}
+
+ return op;
}
-static void qdev_class_add_property(DeviceClass *klass, const char *name,
- Property *prop)
+ObjectProperty *
+object_class_property_add_field(ObjectClass *oc, const char *name,
+ Property *prop)
{
- ObjectClass *oc = OBJECT_CLASS(klass);
ObjectProperty *op;
if (prop->info->create) {
@@ -882,6 +884,12 @@ static void qdev_class_add_property(DeviceClass *klass,
const char *name,
object_class_property_set_description(oc, name,
prop->info->description);
}
+ return op;
+}
+
+void qdev_property_add_static(DeviceState *dev, Property *prop)
+{
+ object_property_add_field(OBJECT(dev), prop->name, prop);
}
/**
@@ -932,12 +940,13 @@ static void qdev_class_add_legacy_property(DeviceClass
*dc, Property *prop)
void device_class_set_props(DeviceClass *dc, Property *props)
{
+ ObjectClass *oc = OBJECT_CLASS(dc);
Property *prop;
dc->props_ = props;
for (prop = props; prop && prop->name; prop++) {
qdev_class_add_legacy_property(dc, prop);
- qdev_class_add_property(dc, prop->name, prop);
+ object_class_property_add_field(oc, prop->name, prop);
}
}
--
2.28.0
- Re: [PATCH v2 41/44] qdev: Move base property types to qom/property-types.c, (continued)
- [PATCH v2 34/44] qdev: Make qdev_propinfo_get_uint16() static, Eduardo Habkost, 2020/11/04
- [PATCH v2 43/44] tests: Use field properties at check-qom-proplist test case, Eduardo Habkost, 2020/11/04
- [PATCH v2 19/44] qdev: Add name parameter to qdev_class_add_property(), Eduardo Habkost, 2020/11/04
- [PATCH v2 24/44] qdev: Make qdev_class_add_property() more flexible, Eduardo Habkost, 2020/11/04
- [PATCH v2 30/44] qdev: Get rid of ArrayElementProperty struct, Eduardo Habkost, 2020/11/04
- [PATCH v2 44/44] machine: Register most properties as field properties, Eduardo Habkost, 2020/11/04
- [PATCH v2 38/44] qdev: Rename qdev_prop_* to prop_info_*, Eduardo Habkost, 2020/11/04
- [PATCH v2 37/44] qdev: Move qdev_prop_tpm declaration to tpm_prop.h, Eduardo Habkost, 2020/11/04
- [PATCH v2 25/44] qdev: Separate generic and device-specific property registration,
Eduardo Habkost <=
- [PATCH v2 35/44] qdev: Rename qdev_propinfo_* to field_prop_*, Eduardo Habkost, 2020/11/04
- [PATCH v2 42/44] qom: Include static property API reference in documentation, Eduardo Habkost, 2020/11/04
- [PATCH v2 36/44] qdev: Rename qdev_get_prop_ptr() to object_field_prop_ptr(), Eduardo Habkost, 2020/11/04
- Re: [PATCH v2 00/44] Make qdev static property API usable by any QOM type, no-reply, 2020/11/04
- Re: [PATCH v2 00/44] Make qdev static property API usable by any QOM type, Kevin Wolf, 2020/11/06