@samitouri / QOSamiQemu / commits / 57abf6b1d5

hw/core/register: add register_array_get_owner

Add the register_array_get_owner function to the register API. This function can be used to retrieve the device owning the given RegisterInfoArray. This was previously done inline by some devices. 5c6367bc1c8850f74812eeaaf87cff9911be58de modified the way register blocks are created and parented to the device. Since this is an implementation detail of the register API, it makes sense to have a function for this. Use it in the Versal OSPI and Versal/ZynqMP eFuse models instead of tinkering with the API internals. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3421 Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3422 Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3423 Signed-off-by: Luc Michel <luc.michel@amd.com> Tested-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Fixes: 5c6367bc1c8 ("hw/core/register: add the REGISTER_ARRAY type") Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20260424155646.533334-1-luc.michel@amd.com> Signed-off-by: Thomas Huth <thuth@redhat.com>

Luc Michel committed Apr 24, 2026 at 17:56 UTC 57abf6b1d5762380765673a17cba74c481cc4b29
5 files changed +23 -11
hw/core/register.c
+5
@@ -322,6 +322,11 @@ static void register_array_finalize(Object *obj)
322 g_free(r_array->r);
323 }
324
325 +DeviceState *register_array_get_owner(const RegisterInfoArray *reg_array)
326 +{
327 + return DEVICE(OBJECT(reg_array)->parent);
328 +}
329 +
330 static const TypeInfo register_array_info = {
331 .name = TYPE_REGISTER_ARRAY,
332 .parent = TYPE_OBJECT,
hw/nvram/xlnx-versal-efuse-ctrl.c
+2 -2
@@ -619,11 +619,11 @@ static void efuse_ctrl_reg_write(void *opaque, hwaddr addr,
619 {
620 RegisterInfoArray *reg_array = opaque;
621 XlnxVersalEFuseCtrl *s;
622 - Object *dev;
622 + DeviceState *dev;
623
624 assert(reg_array != NULL);
625
626 - dev = reg_array->mem.owner;
626 + dev = register_array_get_owner(reg_array);
627 assert(dev);
628
629 s = XLNX_VERSAL_EFUSE_CTRL(dev);
hw/nvram/xlnx-zynqmp-efuse.c
+2 -2
@@ -724,11 +724,11 @@ static void zynqmp_efuse_reg_write(void *opaque, hwaddr addr,
724 {
725 RegisterInfoArray *reg_array = opaque;
726 XlnxZynqMPEFuse *s;
727 - Object *dev;
727 + DeviceState *dev;
728
729 assert(reg_array != NULL);
730
731 - dev = reg_array->mem.owner;
731 + dev = register_array_get_owner(reg_array);
732 assert(dev);
733
734 s = XLNX_ZYNQMP_EFUSE(dev);
hw/ssi/xlnx-versal-ospi.c
+3 -7
@@ -1569,15 +1569,11 @@ static RegisterAccessInfo ospi_regs_info[] = {
1569 };
1570
1571 /* Return dev-obj from reg-region created by register_init_block32 */
1572 -static XlnxVersalOspi *xilinx_ospi_of_mr(void *mr_accessor)
1572 +static XlnxVersalOspi *xilinx_ospi_of_mr(void *opaque)
1573 {
1574 - RegisterInfoArray *reg_array = mr_accessor;
1575 - Object *dev;
1574 + RegisterInfoArray *reg_array = REGISTER_ARRAY(opaque);
1575
1577 - dev = reg_array->mem.owner;
1578 - assert(dev);
1579 -
1580 - return XILINX_VERSAL_OSPI(dev);
1576 + return XILINX_VERSAL_OSPI(register_array_get_owner(reg_array));
1577 }
1578
1579 static void ospi_write(void *opaque, hwaddr addr, uint64_t value,
include/hw/core/register.h
+11
@@ -209,4 +209,15 @@ RegisterInfoArray *register_init_block64(DeviceState *owner,
209 bool debug_enabled,
210 uint64_t memory_size);
211
212 +/**
213 + * register_array_get_owner
214 + *
215 + * Retrieve the device owning the register info array @reg_array.
216 + *
217 + * @reg_array The register info array to retrieve the owner from
218 + *
219 + * Returns: the device owning @reg_array
220 + */
221 +DeviceState *register_array_get_owner(const RegisterInfoArray *reg_array);
222 +
223 #endif