All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Daniel P. Berrange" <berrange@redhat.com>,
	"John Snow" <jsnow@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Stefan Berger" <stefanb@linux.ibm.com>
Subject: [PATCH v4 03/32] qdev: Move property code to qdev-properties.[ch]
Date: Fri, 11 Dec 2020 17:05:00 -0500	[thread overview]
Message-ID: <20201211220529.2290218-4-ehabkost@redhat.com> (raw)
In-Reply-To: <20201211220529.2290218-1-ehabkost@redhat.com>

Move everything related to Property and PropertyInfo to
qdev-properties.[ch] to make it easier to refactor that code.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
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-core.h       |  37 -----------
 include/hw/qdev-properties.h |  38 +++++++++++
 hw/core/qdev-properties.c    | 120 +++++++++++++++++++++++++++++++++++
 hw/core/qdev.c               | 120 -----------------------------------
 softmmu/qdev-monitor.c       |   1 +
 5 files changed, 159 insertions(+), 157 deletions(-)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 9fbb22a48d..8f91faebc3 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -276,43 +276,6 @@ struct BusState {
     ResettableState reset;
 };
 
-/**
- * Property:
- * @set_default: true if the default value should be set from @defval,
- *    in which case @info->set_default_value must not be NULL
- *    (if false then no default value is set by the property system
- *     and the field retains whatever value it was given by instance_init).
- * @defval: default value for the property. This is used only if @set_default
- *     is true.
- */
-struct Property {
-    const char   *name;
-    const PropertyInfo *info;
-    ptrdiff_t    offset;
-    uint8_t      bitnr;
-    bool         set_default;
-    union {
-        int64_t i;
-        uint64_t u;
-    } defval;
-    int          arrayoffset;
-    const PropertyInfo *arrayinfo;
-    int          arrayfieldsize;
-    const char   *link_type;
-};
-
-struct PropertyInfo {
-    const char *name;
-    const char *description;
-    const QEnumLookup *enum_table;
-    int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
-    void (*set_default_value)(ObjectProperty *op, const Property *prop);
-    void (*create)(ObjectClass *oc, Property *prop);
-    ObjectPropertyAccessor *get;
-    ObjectPropertyAccessor *set;
-    ObjectPropertyRelease *release;
-};
-
 /**
  * GlobalProperty:
  * @used: Set to true if property was used when initializing a device.
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 4437450065..db7ce51dd5 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -3,6 +3,44 @@
 
 #include "hw/qdev-core.h"
 
+/**
+ * Property:
+ * @set_default: true if the default value should be set from @defval,
+ *    in which case @info->set_default_value must not be NULL
+ *    (if false then no default value is set by the property system
+ *     and the field retains whatever value it was given by instance_init).
+ * @defval: default value for the property. This is used only if @set_default
+ *     is true.
+ */
+struct Property {
+    const char   *name;
+    const PropertyInfo *info;
+    ptrdiff_t    offset;
+    uint8_t      bitnr;
+    bool         set_default;
+    union {
+        int64_t i;
+        uint64_t u;
+    } defval;
+    int          arrayoffset;
+    const PropertyInfo *arrayinfo;
+    int          arrayfieldsize;
+    const char   *link_type;
+};
+
+struct PropertyInfo {
+    const char *name;
+    const char *description;
+    const QEnumLookup *enum_table;
+    int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
+    void (*set_default_value)(ObjectProperty *op, const Property *prop);
+    void (*create)(ObjectClass *oc, Property *prop);
+    ObjectPropertyAccessor *get;
+    ObjectPropertyAccessor *set;
+    ObjectPropertyRelease *release;
+};
+
+
 /*** qdev-properties.c ***/
 
 extern const PropertyInfo qdev_prop_bit;
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 509cbf155d..12a053e732 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -929,3 +929,123 @@ const PropertyInfo qdev_prop_link = {
     .name = "link",
     .create = create_link_property,
 };
+
+void qdev_property_add_static(DeviceState *dev, Property *prop)
+{
+    Object *obj = OBJECT(dev);
+    ObjectProperty *op;
+
+    assert(!prop->info->create);
+
+    op = object_property_add(obj, prop->name, prop->info->name,
+                             prop->info->get, prop->info->set,
+                             prop->info->release,
+                             prop);
+
+    object_property_set_description(obj, prop->name,
+                                    prop->info->description);
+
+    if (prop->set_default) {
+        prop->info->set_default_value(op, prop);
+        if (op->init) {
+            op->init(obj, op);
+        }
+    }
+}
+
+static void qdev_class_add_property(DeviceClass *klass, Property *prop)
+{
+    ObjectClass *oc = OBJECT_CLASS(klass);
+
+    if (prop->info->create) {
+        prop->info->create(oc, prop);
+    } else {
+        ObjectProperty *op;
+
+        op = object_class_property_add(oc,
+                                       prop->name, prop->info->name,
+                                       prop->info->get, prop->info->set,
+                                       prop->info->release,
+                                       prop);
+        if (prop->set_default) {
+            prop->info->set_default_value(op, prop);
+        }
+    }
+    object_class_property_set_description(oc, prop->name,
+                                          prop->info->description);
+}
+
+/**
+ * Legacy property handling
+ */
+
+static void qdev_get_legacy_property(Object *obj, Visitor *v,
+                                     const char *name, void *opaque,
+                                     Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+
+    char buffer[1024];
+    char *ptr = buffer;
+
+    prop->info->print(dev, prop, buffer, sizeof(buffer));
+    visit_type_str(v, name, &ptr, errp);
+}
+
+/**
+ * qdev_class_add_legacy_property:
+ * @dev: Device to add the property to.
+ * @prop: The qdev property definition.
+ *
+ * Add a legacy QOM property to @dev for qdev property @prop.
+ *
+ * Legacy properties are string versions of QOM properties.  The format of
+ * the string depends on the property type.  Legacy properties are only
+ * needed for "info qtree".
+ *
+ * Do not use this in new code!  QOM Properties added through this interface
+ * will be given names in the "legacy" namespace.
+ */
+static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop)
+{
+    g_autofree char *name = NULL;
+
+    /* Register pointer properties as legacy properties */
+    if (!prop->info->print && prop->info->get) {
+        return;
+    }
+
+    name = g_strdup_printf("legacy-%s", prop->name);
+    object_class_property_add(OBJECT_CLASS(dc), name, "str",
+        prop->info->print ? qdev_get_legacy_property : prop->info->get,
+        NULL, NULL, prop);
+}
+
+void device_class_set_props(DeviceClass *dc, Property *props)
+{
+    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);
+    }
+}
+
+void qdev_alias_all_properties(DeviceState *target, Object *source)
+{
+    ObjectClass *class;
+    Property *prop;
+
+    class = object_get_class(OBJECT(target));
+    do {
+        DeviceClass *dc = DEVICE_CLASS(class);
+
+        for (prop = dc->props_; prop && prop->name; prop++) {
+            object_property_add_alias(source, prop->name,
+                                      OBJECT(target), prop->name);
+        }
+        class = object_class_get_parent(class);
+    } while (class != object_class_by_name(TYPE_DEVICE));
+}
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index cbdff0b6c6..d3611e7c03 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -705,115 +705,6 @@ char *qdev_get_dev_path(DeviceState *dev)
     return NULL;
 }
 
-/**
- * Legacy property handling
- */
-
-static void qdev_get_legacy_property(Object *obj, Visitor *v,
-                                     const char *name, void *opaque,
-                                     Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-
-    char buffer[1024];
-    char *ptr = buffer;
-
-    prop->info->print(dev, prop, buffer, sizeof(buffer));
-    visit_type_str(v, name, &ptr, errp);
-}
-
-/**
- * qdev_class_add_legacy_property:
- * @dev: Device to add the property to.
- * @prop: The qdev property definition.
- *
- * Add a legacy QOM property to @dev for qdev property @prop.
- *
- * Legacy properties are string versions of QOM properties.  The format of
- * the string depends on the property type.  Legacy properties are only
- * needed for "info qtree".
- *
- * Do not use this in new code!  QOM Properties added through this interface
- * will be given names in the "legacy" namespace.
- */
-static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop)
-{
-    g_autofree char *name = NULL;
-
-    /* Register pointer properties as legacy properties */
-    if (!prop->info->print && prop->info->get) {
-        return;
-    }
-
-    name = g_strdup_printf("legacy-%s", prop->name);
-    object_class_property_add(OBJECT_CLASS(dc), name, "str",
-        prop->info->print ? qdev_get_legacy_property : prop->info->get,
-        NULL, NULL, prop);
-}
-
-void qdev_property_add_static(DeviceState *dev, Property *prop)
-{
-    Object *obj = OBJECT(dev);
-    ObjectProperty *op;
-
-    assert(!prop->info->create);
-
-    op = object_property_add(obj, prop->name, prop->info->name,
-                             prop->info->get, prop->info->set,
-                             prop->info->release,
-                             prop);
-
-    object_property_set_description(obj, prop->name,
-                                    prop->info->description);
-
-    if (prop->set_default) {
-        prop->info->set_default_value(op, prop);
-        if (op->init) {
-            op->init(obj, op);
-        }
-    }
-}
-
-static void qdev_class_add_property(DeviceClass *klass, Property *prop)
-{
-    ObjectClass *oc = OBJECT_CLASS(klass);
-
-    if (prop->info->create) {
-        prop->info->create(oc, prop);
-    } else {
-        ObjectProperty *op;
-
-        op = object_class_property_add(oc,
-                                       prop->name, prop->info->name,
-                                       prop->info->get, prop->info->set,
-                                       prop->info->release,
-                                       prop);
-        if (prop->set_default) {
-            prop->info->set_default_value(op, prop);
-        }
-    }
-    object_class_property_set_description(oc, prop->name,
-                                          prop->info->description);
-}
-
-void qdev_alias_all_properties(DeviceState *target, Object *source)
-{
-    ObjectClass *class;
-    Property *prop;
-
-    class = object_get_class(OBJECT(target));
-    do {
-        DeviceClass *dc = DEVICE_CLASS(class);
-
-        for (prop = dc->props_; prop && prop->name; prop++) {
-            object_property_add_alias(source, prop->name,
-                                      OBJECT(target), prop->name);
-        }
-        class = object_class_get_parent(class);
-    } while (class != object_class_by_name(TYPE_DEVICE));
-}
-
 static bool device_get_realized(Object *obj, Error **errp)
 {
     DeviceState *dev = DEVICE(obj);
@@ -1208,17 +1099,6 @@ static void device_class_init(ObjectClass *class, void *data)
                                    offsetof(DeviceState, parent_bus), NULL, 0);
 }
 
-void device_class_set_props(DeviceClass *dc, Property *props)
-{
-    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);
-    }
-}
-
 void device_class_set_parent_reset(DeviceClass *dc,
                                    DeviceReset dev_reset,
                                    DeviceReset *parent_reset)
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index 832e254842..8c072e3efc 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -38,6 +38,7 @@
 #include "migration/misc.h"
 #include "migration/migration.h"
 #include "qemu/cutils.h"
+#include "hw/qdev-properties.h"
 #include "hw/clock.h"
 
 /*
-- 
2.28.0



  parent reply	other threads:[~2020-12-11 22:14 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 22:04 [PATCH v4 00/32] qdev property code cleanup Eduardo Habkost
2020-12-11 22:04 ` [PATCH v4 01/32] cs4231: Get rid of empty property array Eduardo Habkost
2020-12-15  8:22   ` Gerd Hoffmann
2020-12-11 22:04 ` [PATCH v4 02/32] cpu: Move cpu_common_props to hw/core/cpu.c Eduardo Habkost
2020-12-11 22:05 ` Eduardo Habkost [this message]
2020-12-11 22:05 ` [PATCH v4 04/32] qdev: Check dev->realized at set_size() Eduardo Habkost
2020-12-11 22:05 ` [PATCH v4 05/32] sparc: Check dev->realized at sparc_set_nwindows() Eduardo Habkost
2020-12-15 11:45   ` Mark Cave-Ayland
2020-12-11 22:05 ` [PATCH v4 06/32] qdev: Don't use dev->id on set_size32() error message Eduardo Habkost
2020-12-11 22:05 ` [PATCH v4 07/32] qdev: Make PropertyInfo.print method get Object* argument Eduardo Habkost
2020-12-11 22:05 ` [PATCH v4 08/32] qdev: Make bit_prop_set() " Eduardo Habkost
2020-12-11 22:05 ` [PATCH v4 09/32] qdev: Make qdev_get_prop_ptr() get Object* arg Eduardo Habkost
2020-12-11 22:05   ` Eduardo Habkost
2020-12-14  7:46   ` Paul Durrant
2020-12-14  7:46     ` Paul Durrant
2020-12-11 22:05 ` [PATCH v4 10/32] qdev: Make qdev_find_global_prop() get Object* argument Eduardo Habkost
2020-12-11 22:05 ` [PATCH v4 11/32] qdev: Make check_prop_still_unset() " Eduardo Habkost
2020-12-11 22:05 ` [PATCH v4 12/32] qdev: Make error_set_from_qdev_prop_error() " Eduardo Habkost
2020-12-11 22:05 ` [PATCH v4 13/32] qdev: Make qdev_propinfo_get_uint16() static Eduardo Habkost
2020-12-11 22:05 ` [PATCH v4 14/32] qdev: Move UUID property to qdev-properties-system.c Eduardo Habkost
2020-12-14 14:18   ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 15/32] qdev: Move softmmu properties to qdev-properties-system.h Eduardo Habkost
2020-12-14 14:25   ` Igor Mammedov
2020-12-14 17:40     ` Eduardo Habkost
2020-12-15 14:40   ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 16/32] qdev: Reuse DEFINE_PROP in all DEFINE_PROP_* macros Eduardo Habkost
2020-12-14 14:32   ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 17/32] sparc: Use DEFINE_PROP for nwindows property Eduardo Habkost
2020-12-14 14:42   ` Igor Mammedov
2020-12-14 17:30     ` Eduardo Habkost
2020-12-15 14:39       ` Igor Mammedov
2020-12-15 11:52   ` Mark Cave-Ayland
2020-12-11 22:05 ` [PATCH v4 18/32] qdev: Get just property name at error_set_from_qdev_prop_error() Eduardo Habkost
2020-12-14 10:41   ` Cornelia Huck
2020-12-14 14:44   ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 19/32] qdev: Avoid using prop->name unnecessarily Eduardo Habkost
2020-12-14 14:45   ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 20/32] qdev: Add name parameter to qdev_class_add_property() Eduardo Habkost
2020-12-11 22:05 ` [PATCH v4 21/32] qdev: Add name argument to PropertyInfo.create method Eduardo Habkost
2020-12-14 14:47   ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 22/32] qdev: Wrap getters and setters in separate helpers Eduardo Habkost
2020-12-15 14:42   ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 23/32] qdev: Move dev->realized check to qdev_property_set() Eduardo Habkost
2020-12-11 22:05   ` Eduardo Habkost
2020-12-14  7:46   ` Paul Durrant
2020-12-14  7:46     ` Paul Durrant
2020-12-14 10:46   ` Cornelia Huck
2020-12-14 10:46     ` Cornelia Huck
2020-12-14 14:55   ` Igor Mammedov
2020-12-14 14:55     ` Igor Mammedov
2020-12-14 17:24     ` Eduardo Habkost
2020-12-14 17:24       ` Eduardo Habkost
2020-12-15 14:24       ` Igor Mammedov
2020-12-15 14:24         ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 24/32] qdev: Make PropertyInfo.create return ObjectProperty* Eduardo Habkost
2020-12-14 14:57   ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 25/32] qdev: Make qdev_class_add_property() more flexible Eduardo Habkost
2020-12-14 15:00   ` Igor Mammedov
2020-12-14 18:28     ` Eduardo Habkost
2020-12-15 14:25       ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 26/32] qdev: Separate generic and device-specific property registration Eduardo Habkost
2020-12-15 14:33   ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 27/32] qdev: Rename qdev_propinfo_* to field_prop_* Eduardo Habkost
2020-12-15 14:35   ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 28/32] qdev: Move qdev_prop_tpm declaration to tpm_prop.h Eduardo Habkost
2020-12-15 14:36   ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 29/32] qdev: Rename qdev_prop_* to prop_info_* Eduardo Habkost
2020-12-11 22:05 ` [PATCH v4 30/32] qdev: Rename qdev_get_prop_ptr() to object_field_prop_ptr() Eduardo Habkost
2020-12-11 22:05   ` Eduardo Habkost
2020-12-14  7:47   ` Paul Durrant
2020-12-14  7:47     ` Paul Durrant
2020-12-14 10:56   ` Cornelia Huck
2020-12-14 10:56     ` Cornelia Huck
2020-12-14 15:13   ` Igor Mammedov
2020-12-14 15:13     ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 31/32] qdev: Avoid unnecessary DeviceState* variable at set_prop_arraylen() Eduardo Habkost
2020-12-14 15:11   ` Igor Mammedov
2020-12-11 22:05 ` [PATCH v4 32/32] tests: Add unit test for qdev array properties Eduardo Habkost
2020-12-14 19:42 ` [PATCH v4 00/32] qdev property code cleanup Eduardo Habkost
2020-12-15 15:40   ` Eduardo Habkost
2020-12-15 16:57     ` Eduardo Habkost

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201211220529.2290218-4-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.