Patchwork [34/37] qdev: introduce QDEV_FIND_PROP_FROM_BIT and qdev_prop_find_bit()

login
register
mail settings
Submitter Igor Mammedov
Date Oct. 22, 2012, 3:03 p.m.
Message ID <1350918203-25198-35-git-send-email-imammedo@redhat.com>
Download mbox | patch
Permalink /patch/193169/
State New
Headers show

Comments

Igor Mammedov - Oct. 22, 2012, 3:03 p.m.
it allows to find bit static property corresponding to a specific bit
in specified field.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
  * it will be used by next commit to print cpuid feature names for
    unavailable feature bits.
---
 hw/qdev-properties.h  |  8 ++++++++
 qom/qdev-properties.c | 15 +++++++++++++++
 2 files changed, 23 insertions(+)

Patch

diff --git a/hw/qdev-properties.h b/hw/qdev-properties.h
index 19b55c0..88b6782 100644
--- a/hw/qdev-properties.h
+++ b/hw/qdev-properties.h
@@ -144,4 +144,12 @@  const Property *qdev_prop_find(const DeviceClass *dc, const char *name);
     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);
+#define QDEV_FIND_PROP_FROM_BIT(_class, _state, _field, _bitnr)               \
+    qdev_prop_find_bit(_class,                                                \
+                       offsetof(_state, _field) +                             \
+                       type_check(uint32_t, typeof_field(_state, _field)),    \
+                       _bitnr)
 #endif
diff --git a/qom/qdev-properties.c b/qom/qdev-properties.c
index 3d3eefa..2e589c6 100644
--- a/qom/qdev-properties.c
+++ b/qom/qdev-properties.c
@@ -787,6 +787,21 @@  const Property *qdev_prop_find(const DeviceClass *dc, 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)
 {