qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 34/37] qdev: introduce QDEV_FIND_PROP_FROM_BIT and q


From: Igor Mammedov
Subject: [Qemu-devel] [PATCH 34/37] qdev: introduce QDEV_FIND_PROP_FROM_BIT and qdev_prop_find_bit()
Date: Mon, 22 Oct 2012 17:03:20 +0200

it allows to find bit static property corresponding to a specific bit
in specified field.

Signed-off-by: Igor Mammedov <address@hidden>
---
  * 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(+)

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)
 {
-- 
1.7.11.7




reply via email to

[Prev in Thread] Current Thread [Next in Thread]