@@ -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)
{
@@ -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
helper to find a static property corresponding to a specific bit in specified field. Signed-off-by: Igor Mammedov <imammedo@redhat.com> --- hw/core/qdev-properties.c | 15 +++++++++++++++ include/hw/qdev-properties.h | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+)