[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/33] qdev: Add qdev_prop_set_array()
|
From: |
Peter Maydell |
|
Subject: |
[PULL 04/33] qdev: Add qdev_prop_set_array() |
|
Date: |
Thu, 2 Nov 2023 17:38:06 +0000 |
From: Kevin Wolf <kwolf@redhat.com>
Instead of exposing the ugly hack of how we represent arrays in qdev (a
static "foo-len" property and after it is set, dynamically created
"foo[i]" properties) to boards, add an interface that allows setting the
whole array at once.
Once all internal users of devices with array properties have been
converted to use this function, we can change the implementation to move
away from this hack.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20231030114802.3671871-4-peter.maydell@linaro.org
---
include/hw/qdev-properties.h | 3 +++
hw/core/qdev-properties.c | 21 +++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index e1df08876c6..7fa2fdb7c94 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -206,6 +206,9 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char
*name,
const uint8_t *value);
void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
+/* Takes ownership of @values */
+void qdev_prop_set_array(DeviceState *dev, const char *name, QList *values);
+
void *object_field_prop_ptr(Object *obj, Property *prop);
void qdev_prop_register_global(GlobalProperty *prop);
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 357b8761b54..950ef48e013 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -3,12 +3,14 @@
#include "qapi/error.h"
#include "qapi/qapi-types-misc.h"
#include "qapi/qmp/qerror.h"
+#include "qapi/qmp/qlist.h"
#include "qemu/ctype.h"
#include "qemu/error-report.h"
#include "qapi/visitor.h"
#include "qemu/units.h"
#include "qemu/cutils.h"
#include "qdev-prop-internal.h"
+#include "qom/qom-qobject.h"
void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
Error **errp)
@@ -739,6 +741,25 @@ void qdev_prop_set_enum(DeviceState *dev, const char
*name, int value)
&error_abort);
}
+void qdev_prop_set_array(DeviceState *dev, const char *name, QList *values)
+{
+ const QListEntry *entry;
+ g_autofree char *prop_len = g_strdup_printf("len-%s", name);
+ uint32_t i = 0;
+
+ object_property_set_int(OBJECT(dev), prop_len, qlist_size(values),
+ &error_abort);
+
+ QLIST_FOREACH_ENTRY(values, entry) {
+ g_autofree char *prop_idx = g_strdup_printf("%s[%u]", name, i);
+ object_property_set_qobject(OBJECT(dev), prop_idx, entry->value,
+ &error_abort);
+ i++;
+ }
+
+ qobject_unref(values);
+}
+
static GPtrArray *global_props(void)
{
static GPtrArray *gp;
--
2.34.1
- [PULL 12/33] docs/specs/standard-vga: Convert to rST, (continued)
- [PULL 12/33] docs/specs/standard-vga: Convert to rST, Peter Maydell, 2023/11/02
- [PULL 20/33] hw/misc/imx7_snvs: Trace MMIO access, Peter Maydell, 2023/11/02
- [PULL 02/33] hw/input/stellaris_input: Rename to stellaris_gamepad, Peter Maydell, 2023/11/02
- [PULL 33/33] tests/qtest: Introduce tests for AMD/Xilinx Versal TRNG device, Peter Maydell, 2023/11/02
- [PULL 22/33] hw/i2c/pm_smbus: Convert DPRINTF to trace events, Peter Maydell, 2023/11/02
- [PULL 26/33] target/arm: Fix SVE STR increment, Peter Maydell, 2023/11/02
- [PULL 29/33] hw/char/stm32f2xx_usart: Add more definitions for CR1 register, Peter Maydell, 2023/11/02
- [PULL 13/33] docs/specs/virt-ctlr: Convert to rST, Peter Maydell, 2023/11/02
- [PULL 25/33] target/arm: Make FEAT_MOPS SET* insns handle Xs == XZR correctly, Peter Maydell, 2023/11/02
- [PULL 16/33] MAINTAINERS: Make sure that gicv3_internal.h is covered, too, Peter Maydell, 2023/11/02
- [PULL 04/33] qdev: Add qdev_prop_set_array(),
Peter Maydell <=
- [PULL 21/33] hw/misc/imx6_ccm: Convert DPRINTF to trace events, Peter Maydell, 2023/11/02
- [PULL 23/33] target/arm: Enable FEAT_MOPS insns in user-mode emulation, Peter Maydell, 2023/11/02
- [PULL 27/33] hw/char/stm32f2xx_usart: Extract common IRQ update code to update_irq(), Peter Maydell, 2023/11/02
- Re: [PULL 00/33] target-arm queue, Stefan Hajnoczi, 2023/11/02