diff mbox series

[RFC,3/5] qdev-properties: add r/o 64bit bitfield property

Message ID 20181214165657.749-4-rkagan@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series expose negotiated virtio features in r/o properties | expand

Commit Message

Roman Kagan Dec. 14, 2018, 4:57 p.m. UTC
Add a version 64bit bitfield property with no setter, useful for
introspecting the device state without being able to modify it.

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 include/hw/qdev-properties.h | 9 +++++++++
 hw/core/qdev-properties.c    | 9 ++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 3ab9cd2eb6..24df135ff8 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -9,6 +9,7 @@ 
 
 extern const PropertyInfo qdev_prop_bit;
 extern const PropertyInfo qdev_prop_bit64;
+extern const PropertyInfo qdev_prop_bit64_ro;
 extern const PropertyInfo qdev_prop_bool;
 extern const PropertyInfo qdev_prop_uint8;
 extern const PropertyInfo qdev_prop_uint16;
@@ -96,6 +97,14 @@  extern const PropertyInfo qdev_prop_off_auto_pcibar;
         .defval.u  = (bool)_defval,                                     \
         }
 
+#define DEFINE_PROP_BIT64_RO(_name, _state, _field, _bit) {             \
+        .name      = (_name),                                           \
+        .info      = &(qdev_prop_bit64_ro),                             \
+        .bitnr    = (_bit),                                             \
+        .offset    = offsetof(_state, _field)                           \
+            + type_check(uint64_t, typeof_field(_state, _field)),       \
+        }
+
 #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) {       \
         .name      = (_name),                                    \
         .info      = &(qdev_prop_bool),                          \
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index bd84c4ea4c..bb9bd48e5c 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -146,7 +146,8 @@  const PropertyInfo qdev_prop_bit = {
 
 static uint64_t qdev_get_prop_mask64(Property *prop)
 {
-    assert(prop->info == &qdev_prop_bit64);
+    assert(prop->info == &qdev_prop_bit64 ||
+           prop->info == &qdev_prop_bit64_ro);
     return 0x1ull << prop->bitnr;
 }
 
@@ -201,6 +202,12 @@  const PropertyInfo qdev_prop_bit64 = {
     .set_default_value = set_default_value_bool,
 };
 
+const PropertyInfo qdev_prop_bit64_ro = {
+    .name  = "bool",
+    .description = "on/off",
+    .get   = prop_get_bit64,
+};
+
 /* --- bool --- */
 
 static void get_bool(Object *obj, Visitor *v, const char *name, void *opaque,