Patchwork [17/20] qdev: introduce qdev_prop_find_bit()

login
register
mail settings
Submitter Igor Mammedov
Date July 15, 2013, 10:26 p.m.
Message ID <1373927181-24247-21-git-send-email-imammedo@redhat.com>
Download mbox | patch
Permalink /patch/259295/
State New
Headers show

Comments

Igor Mammedov - July 15, 2013, 10:26 p.m.
helper to find a static property corresponding to a specific bit
in a specified field.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/core/qdev-properties.c    | 15 +++++++++++++++
 include/hw/qdev-properties.h | 13 +++++++++++++
 2 files changed, 28 insertions(+)

Patch

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 3a324fb..5c3575b 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -964,6 +964,21 @@  static Property *qdev_prop_find(DeviceState *dev, const char *name)
     return NULL;
 }
 
+const Property *qdev_prop_find_bit(const DeviceClass *dc, const int offset,
+                                   const uint8_t bitnr)
+{
+    const Property *prop;
+
+    QDEV_CLASS_FOREACH(dc, dc) {
+        QDEV_PROP_FOREACH(prop, dc) {
+            if (prop->offset == offset && prop->bitnr == bitnr) {
+                return prop;
+            }
+        }
+    }
+    return NULL;
+}
+
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value)
 {
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 39448b7..759141f 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -192,4 +192,17 @@  void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
  */
 void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
                                  Error **errp);
+
+#define QDEV_PROP_FOREACH(_var, _class)                                       \
+    for ((_var) = DEVICE_CLASS((_class))->props;                              \
+         (_var) && (_var)->name;                                              \
+         (_var)++)
+
+#define QDEV_CLASS_FOREACH(_var, _class)                                      \
+    for ((_var) = (_class);                                                   \
+         (_var) != DEVICE_CLASS(object_class_by_name(TYPE_DEVICE));           \
+         (_var) = DEVICE_CLASS(object_class_get_parent(OBJECT_CLASS((_var)))))
+
+const Property *qdev_prop_find_bit(const DeviceClass *dc, const int offset,
+                                   const uint8_t bitnr);
 #endif