Operating on DeviceClass instead of DEVICE will allow to find static properties
before DEVICE instance is created. It will be used later in 
compat_normalize_cpu_model()
to convert legacy CPUID features into corresponding static properties.

Signed-off-by: Igor Mammedov <imamm...@redhat.com>
---
 hw/qdev-properties.h  |  4 +++-
 qom/qdev-properties.c | 16 +++++++++-------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/hw/qdev-properties.h b/hw/qdev-properties.h
index ddcf774..b2f7142 100644
--- a/hw/qdev-properties.h
+++ b/hw/qdev-properties.h
@@ -98,7 +98,7 @@ extern PropertyInfo qdev_prop_pci_host_devaddr;
     {}
 
 /* Set properties between creation and init.  */
-void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
+void *qdev_get_prop_ptr(DeviceState *dev, const Property *prop);
 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
@@ -128,4 +128,6 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, 
DeviceState *dev,
  */
 void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
 
+const Property *qdev_prop_find(const DeviceClass *dc, const char *name);
+
 #endif
diff --git a/qom/qdev-properties.c b/qom/qdev-properties.c
index 2e82cb9..cc37479 100644
--- a/qom/qdev-properties.c
+++ b/qom/qdev-properties.c
@@ -6,7 +6,7 @@
 #include "net/hub.h"
 #include "qapi/qapi-visit-core.h"
 
-void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
+void *qdev_get_prop_ptr(DeviceState *dev, const Property *prop)
 {
     void *ptr = dev;
     ptr += prop->offset;
@@ -784,13 +784,13 @@ static Property *qdev_prop_walk(Property *props, const 
char *name)
     return NULL;
 }
 
-static Property *qdev_prop_find(DeviceState *dev, const char *name)
+const Property *qdev_prop_find(const DeviceClass *dc, const char *name)
 {
     ObjectClass *class;
     Property *prop;
 
     /* device properties */
-    class = object_get_class(OBJECT(dev));
+    class = OBJECT_CLASS(dc);
     do {
         prop = qdev_prop_walk(DEVICE_CLASS(class)->props, name);
         if (prop) {
@@ -907,10 +907,11 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char 
*name, uint8_t *value)
 
 void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
 {
-    Property *prop;
+    const Property *prop;
     Error *errp = NULL;
+    DeviceClass *dc = DEVICE_CLASS(object_get_class(OBJECT(dev)));
 
-    prop = qdev_prop_find(dev, name);
+    prop = qdev_prop_find(dc, name);
     object_property_set_str(OBJECT(dev), prop->info->enum_table[value],
                             name, &errp);
     assert_no_error(errp);
@@ -918,10 +919,11 @@ void qdev_prop_set_enum(DeviceState *dev, const char 
*name, int value)
 
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
 {
-    Property *prop;
+    const Property *prop;
     void **ptr;
+    DeviceClass *dc = DEVICE_CLASS(object_get_class(OBJECT(dev)));
 
-    prop = qdev_prop_find(dev, name);
+    prop = qdev_prop_find(dc, name);
     assert(prop && prop->info == &qdev_prop_ptr);
     ptr = qdev_get_prop_ptr(dev, prop);
     *ptr = value;
-- 
1.7.11.7


Reply via email to