From patchwork Mon Jul 15 22:26:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 259295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 18D4B2C017B for ; Tue, 16 Jul 2013 08:39:02 +1000 (EST) Received: from localhost ([::1]:60993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UyrQ3-00058A-WC for incoming@patchwork.ozlabs.org; Mon, 15 Jul 2013 18:39:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35644) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UyrEe-0003Vr-G1 for qemu-devel@nongnu.org; Mon, 15 Jul 2013 18:27:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UyrEd-00027G-Dx for qemu-devel@nongnu.org; Mon, 15 Jul 2013 18:27:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13372) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UyrEd-00026z-66 for qemu-devel@nongnu.org; Mon, 15 Jul 2013 18:27:11 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6FMRAZP019147 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 15 Jul 2013 18:27:10 -0400 Received: from thinkpad.redhat.com (vpn-229-233.phx2.redhat.com [10.3.229.233]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6FMQL4U014418; Mon, 15 Jul 2013 18:27:08 -0400 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Tue, 16 Jul 2013 00:26:13 +0200 Message-Id: <1373927181-24247-21-git-send-email-imammedo@redhat.com> In-Reply-To: <1373927181-24247-1-git-send-email-imammedo@redhat.com> References: <1373927181-24247-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Eduardo Habkost , Vadim Rozenfeld , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH 17/20] qdev: introduce qdev_prop_find_bit() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org helper to find a static property corresponding to a specific bit in a specified field. Signed-off-by: Igor Mammedov --- hw/core/qdev-properties.c | 15 +++++++++++++++ include/hw/qdev-properties.h | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 3a324fb..5c3575b 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -964,6 +964,21 @@ static Property *qdev_prop_find(DeviceState *dev, 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) { diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 39448b7..759141f 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -192,4 +192,17 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp); */ void qdev_prop_set_after_realize(DeviceState *dev, const char *name, Error **errp); + +#define QDEV_PROP_FOREACH(_var, _class) \ + for ((_var) = DEVICE_CLASS((_class))->props; \ + (_var) && (_var)->name; \ + (_var)++) + +#define QDEV_CLASS_FOREACH(_var, _class) \ + 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); #endif