From patchwork Wed May 11 09:52:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 9066951 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 12D17BF29F for ; Wed, 11 May 2016 09:52:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5852B201B9 for ; Wed, 11 May 2016 09:52:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2FC1720123 for ; Wed, 11 May 2016 09:52:37 +0000 (UTC) Received: from localhost ([::1]:51311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0Qol-0001Fd-Fx for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 May 2016 05:52:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0Qob-0001C6-56 for qemu-devel@nongnu.org; Wed, 11 May 2016 05:52:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0QoV-0000ul-3G for qemu-devel@nongnu.org; Wed, 11 May 2016 05:52:24 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:25121 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0QoU-0000tW-Le for qemu-devel@nongnu.org; Wed, 11 May 2016 05:52:19 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u4B9q52b026714; Wed, 11 May 2016 12:52:08 +0300 (MSK) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Date: Wed, 11 May 2016 12:52:03 +0300 Message-Id: <1462960324-4655-2-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1462960324-4655-1-git-send-email-den@openvz.org> References: <1462960324-4655-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [RFC 1/2] qdev: add read-only bit/bit64 property X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: den@openvz.org, "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 CC: Michael S. Tsirkin CC: Eric Blake --- 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), \