qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: qemu-devel@nongnu.org
Cc: den@openvz.org, "Michael S. Tsirkin" <mst@redhat.com>,
	Eric Blake <eblake@redhat.com>
Subject: [Qemu-devel] [RFC 1/2] qdev: add read-only bit/bit64 property
Date: Wed, 11 May 2016 12:52:03 +0300	[thread overview]
Message-ID: <1462960324-4655-2-git-send-email-den@openvz.org> (raw)
In-Reply-To: <1462960324-4655-1-git-send-email-den@openvz.org>

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 --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),                                    \
-- 
2.5.0

  reply	other threads:[~2016-05-11  9:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-11  9:52 [Qemu-devel] [RFC for 2.7 0/2] virtio: show guest features in 'info qtree' Denis V. Lunev
2016-05-11  9:52 ` Denis V. Lunev [this message]
2016-05-11  9:52 ` [Qemu-devel] [RFC 2/2] virtio: show features acked by guest in 'info qtree' dump Denis V. Lunev
2016-05-11 17:24   ` Michael S. Tsirkin
2016-05-11 10:34 ` [Qemu-devel] [RFC for 2.7 0/2] virtio: show guest features in 'info qtree' Cornelia Huck
2016-05-11 11:06   ` Denis V. Lunev
2016-05-11 12:02     ` Cornelia Huck
2016-05-11 13:49       ` Denis V. Lunev
2016-05-11 14:27         ` Cornelia Huck
2016-05-11 10:39 ` Denis V. Lunev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462960324-4655-2-git-send-email-den@openvz.org \
    --to=den@openvz.org \
    --cc=eblake@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).