helper to find a static property corresponding to a specific bit in a specified field.
Signed-off-by: Igor Mammedov <imamm...@redhat.com> --- 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 -- 1.8.3.1