From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UyrEc-0003Qc-2c for qemu-devel@nongnu.org; Mon, 15 Jul 2013 18:27:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UyrEa-00026T-Nu for qemu-devel@nongnu.org; Mon, 15 Jul 2013 18:27:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34157) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UyrEa-00026I-Ec for qemu-devel@nongnu.org; Mon, 15 Jul 2013 18:27:08 -0400 From: Igor Mammedov Date: Tue, 16 Jul 2013 00:26:12 +0200 Message-Id: <1373927181-24247-20-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> Subject: [Qemu-devel] [PATCH 17/20] qdev: introduce QDEV_FIND_PROP_FROM_BIT and qdev_prop_find_bit() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Eduardo Habkost , Vadim Rozenfeld , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= helper to find a static property corresponding to a specific bit in specified field. Signed-off-by: Igor Mammedov --- hw/core/qdev-properties.c | 15 +++++++++++++++ include/hw/qdev-properties.h | 18 ++++++++++++++++++ 2 files changed, 33 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..cf57e3a 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -192,4 +192,22 @@ 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); +#define QDEV_FIND_PROP_FROM_BIT(_class, _state, _field, _bitnr) \ + qdev_prop_find_bit(_class, \ + offsetof(_state, _field) + \ + type_check(uint32_t, typeof_field(_state, _field)), \ + _bitnr) #endif -- 1.8.3.1