diff mbox

[RFC,1/2] qdev: add read-only bit/bit64 property

Message ID 1462960324-4655-2-git-send-email-den@openvz.org (mailing list archive)
State New, archived
Headers show

Commit Message

Denis V. Lunev May 11, 2016, 9:52 a.m. UTC
It would be very nice to expose VirtIO feature bits negotiated with guest
in 'info qtree'. Bits are exposed using QDEV framework using properties.
Though the usage of DEFINE_PROP_BIT is not welcome here. In this case
this bit could be set from the command line, which is badly wrong.

The patch adds read-only bit property, which will be used in the
subsequent patch for VirtIO net.

Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Michael S. Tsirkin <mst@redhat.com>
CC: Eric Blake <eblake@redhat.com>
--
 hw/core/qdev-properties.c    | 29 +++++++++++++++++++++++++++--
 include/hw/qdev-properties.h | 18 ++++++++++++++++++
 2 files changed, 45 insertions(+), 2 deletions(-)
---
 hw/core/qdev-properties.c    | 29 +++++++++++++++++++++++++++--
 include/hw/qdev-properties.h | 18 ++++++++++++++++++
 2 files changed, 45 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 737d29c..d1827eb 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -73,7 +73,7 @@  static void set_enum(Object *obj, Visitor *v, const char *name, void *opaque,
 
 static uint32_t qdev_get_prop_mask(Property *prop)
 {
-    assert(prop->info == &qdev_prop_bit);
+    assert(prop->info == &qdev_prop_bit || prop->info == &qdev_prop_ro_bit);
     return 0x1 << prop->bitnr;
 }
 
@@ -127,11 +127,24 @@  PropertyInfo qdev_prop_bit = {
     .set   = prop_set_bit,
 };
 
+
+static void prop_noset_bit(Object *obj, Visitor *v, const char *name,
+                         void *opaque, Error **errp)
+{
+}
+
+PropertyInfo qdev_prop_ro_bit = {
+    .name  = "bool",
+    .description = "on/off",
+    .get   = prop_get_bit,
+    .set   = prop_noset_bit,
+};
+
 /* Bit64 */
 
 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_ro_bit64);
     return 0x1ull << prop->bitnr;
 }
 
@@ -185,6 +198,18 @@  PropertyInfo qdev_prop_bit64 = {
     .set   = prop_set_bit64,
 };
 
+static void prop_noset_bit64(Object *obj, Visitor *v, const char *name,
+                             void *opaque, Error **errp)
+{
+}
+
+PropertyInfo qdev_prop_ro_bit64 = {
+    .name  = "bool",
+    .description = "on/off",
+    .get   = prop_get_bit64,
+    .set   = prop_noset_bit64,
+};
+
 /* --- bool --- */
 
 static void get_bool(Object *obj, Visitor *v, const char *name, void *opaque,
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 0586cac..8344ea5 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -6,7 +6,9 @@ 
 /*** qdev-properties.c ***/
 
 extern PropertyInfo qdev_prop_bit;
+extern PropertyInfo qdev_prop_ro_bit;
 extern PropertyInfo qdev_prop_bit64;
+extern PropertyInfo qdev_prop_ro_bit64;
 extern PropertyInfo qdev_prop_bool;
 extern PropertyInfo qdev_prop_uint8;
 extern PropertyInfo qdev_prop_uint16;
@@ -53,6 +55,14 @@  extern PropertyInfo qdev_prop_arraylen;
         .qtype     = QTYPE_QBOOL,                                \
         .defval    = (bool)_defval,                              \
         }
+#define DEFINE_PROP_RO_BIT(_name, _state, _field, _bit) {        \
+        .name      = (_name),                                    \
+        .info      = &(qdev_prop_ro_bit),                        \
+        .bitnr    = (_bit),                                      \
+        .offset    = offsetof(_state, _field)                    \
+            + type_check(uint32_t,typeof_field(_state, _field)), \
+        .qtype     = QTYPE_QBOOL,                                \
+        }
 #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) {       \
         .name      = (_name),                                           \
         .info      = &(qdev_prop_bit64),                                \
@@ -62,6 +72,14 @@  extern PropertyInfo qdev_prop_arraylen;
         .qtype     = QTYPE_QBOOL,                                       \
         .defval    = (bool)_defval,                                     \
         }
+#define DEFINE_PROP_RO_BIT64(_name, _state, _field, _bit) {             \
+        .name      = (_name),                                           \
+        .info      = &(qdev_prop_ro_bit64),                             \
+        .bitnr    = (_bit),                                             \
+        .offset    = offsetof(_state, _field)                           \
+            + type_check(uint64_t, typeof_field(_state, _field)),       \
+        .qtype     = QTYPE_QBOOL,                                       \
+        }
 
 #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) {       \
         .name      = (_name),                                    \