hw/core/register: add register_array_get_owner
PATCH 1/1 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
--- include/hw/core/register.h | 11 +++++++++++ hw/core/register.c | 5 +++++ hw/nvram/xlnx-versal-efuse-ctrl.c | 4 ++-- hw/nvram/xlnx-zynqmp-efuse.c | 4 ++-- hw/ssi/xlnx-versal-ospi.c | 10 +++------- 5 files changed, 23 insertions(+), 11 deletions(-)
include/hw/core/register.h +11 -0
@@ -207,6 +207,17 @@ RegisterInfoArray *register_init_block64(DeviceState *owner,uint64_t *data, const MemoryRegionOps *ops, bool debug_enabled, uint64_t memory_size); +/** +* register_array_get_owner +* +* Retrieve the device owning the register info array @reg_array. +* +* @reg_array The register info array to retrieve the owner from +* +* Returns: the device owning @reg_array +*/ +DeviceState *register_array_get_owner (const RegisterInfoArray *reg_array); +#endif
hw/core/register.c +5 -0
@@ -320,10 +320,15 @@ static void register_array_finalize(Object *obj)RegisterInfoArray *r_array =REGISTER_ARRAY (obj);g_free (r_array->r); } +DeviceState *register_array_get_owner (const RegisterInfoArray *reg_array) +{ +return DEVICE (OBJECT (reg_array)->parent); +} +static const TypeInfo register_array_info = { .name =TYPE_REGISTER_ARRAY , .parent =TYPE_OBJECT , .instance_size =sizeof (RegisterInfoArray), .instance_finalize = register_array_finalize,
hw/nvram/xlnx-versal-efuse-ctrl.c +2 -2
@@ -617,15 +617,15 @@ static const RegisterAccessInfo efuse_ctrl_regs_info[] = {static void efuse_ctrl_reg_write (void *opaque,hwaddr addr,uint64_t data,unsigned size) {RegisterInfoArray *reg_array = opaque;XlnxVersalEFuseCtrl *s; -Object *dev; +DeviceState *dev;assert (reg_array !=NULL ); - dev = reg_array->mem.owner; + dev =register_array_get_owner (reg_array);assert (dev); s =XLNX_VERSAL_EFUSE_CTRL (dev);if (addr !=A_WR_LOCK && s->regs[R_WR_LOCK ]) {
hw/nvram/xlnx-zynqmp-efuse.c +2 -2
@@ -722,15 +722,15 @@ static RegisterAccessInfo zynqmp_efuse_regs_info[] = {static void zynqmp_efuse_reg_write (void *opaque,hwaddr addr,uint64_t data,unsigned size) {RegisterInfoArray *reg_array = opaque;XlnxZynqMPEFuse *s; -Object *dev; +DeviceState *dev;assert (reg_array !=NULL ); - dev = reg_array->mem.owner; + dev =register_array_get_owner (reg_array);assert (dev); s =XLNX_ZYNQMP_EFUSE (dev);if (addr !=A_WR_LOCK && s->regs[R_WR_LOCK ]) {
hw/ssi/xlnx-versal-ospi.c +3 -7
@@ -1567,19 +1567,15 @@ static RegisterAccessInfo ospi_regs_info[] = { .ro = 0xffffffff, } };/* Return dev-obj from reg-region created by register_init_block32 */ -static XlnxVersalOspi *xilinx_ospi_of_mr (void *mr_accessor) +static XlnxVersalOspi *xilinx_ospi_of_mr (void *opaque) { -RegisterInfoArray *reg_array = mr_accessor; -Object *dev; +RegisterInfoArray *reg_array =REGISTER_ARRAY (opaque); - dev = reg_array->mem.owner; -assert (dev); - -return XILINX_VERSAL_OSPI (dev); +return XILINX_VERSAL_OSPI (register_array_get_owner (reg_array)); }static void ospi_write (void *opaque,hwaddr addr,uint64_t value,unsigned int size) {
Signature · 1 line
2.53.0
Quoted 4 lines · Luc Michel
Add the
register_array_get_ownerfunction to the register API. This function can be used to retrieve the device owning the given RegisterInfoArray.
Quoted 8 lines
This was previously done inline by some devices.
5c6367bc1c8850f74812eeaaf87cff9911be58demodified 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.
Quoted 18 lines
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/3423Signed-off-by Luc Michel <[email protected]>--- include/hw/core/register.h | 11 +++++++++++ hw/core/register.c | 5 +++++ hw/nvram/xlnx-versal-efuse-ctrl.c | 4 ++-- hw/nvram/xlnx-zynqmp-efuse.c | 4 ++-- hw/ssi/xlnx-versal-ospi.c | 10 +++------- 5 files changed, 23 insertions(+), 11 deletions(-)hw/core/register.c +0
-0
hw/core/register.c static void register_array_finalize(Object *obj) · line 327
Quoted 8 lines
hw/core/register.c +3
-0@@ -320,10 +320,15 @@ static void register_array_finalize(Object *obj)RegisterInfoArray *r_array =REGISTER_ARRAY (obj);g_free (r_array->r); } +DeviceState *register_array_get_owner (const RegisterInfoArray *reg_array) +{ +return DEVICE (OBJECT (reg_array)->parent);
Odd, we have object_class_get_parent() but no object_get_parent().
hw/core/register.c static void register_array_finalize(Object *obj) · line 328
Quoted 1 line
hw/core/register.c +1
-0+}
Quoted 11 lines · Luc Michel
Add the
register_array_get_ownerfunction 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.
5c6367bc1c8850f74812eeaaf87cff9911be58demodified 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.
Quoted 7 lines
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/3423Signed-off-by Luc Michel <[email protected]>
Alistair
Quoted 125 lines
--- include/hw/core/register.h | 11 +++++++++++ hw/core/register.c | 5 +++++ hw/nvram/xlnx-versal-efuse-ctrl.c | 4 ++-- hw/nvram/xlnx-zynqmp-efuse.c | 4 ++-- hw/ssi/xlnx-versal-ospi.c | 10 +++------- 5 files changed, 23 insertions(+), 11 deletions(-)include/hw/core/register.h +11
-0@@ -207,6 +207,17 @@ RegisterInfoArray *register_init_block64(DeviceState *owner,uint64_t *data, const MemoryRegionOps *ops, bool debug_enabled, uint64_t memory_size); +/** +* register_array_get_owner +* +* Retrieve the device owning the register info array @reg_array. +* +* @reg_array The register info array to retrieve the owner from +* +* Returns: the device owning @reg_array +*/ +DeviceState *register_array_get_owner (const RegisterInfoArray *reg_array); +#endif hw/core/register.c +5
-0@@ -320,10 +320,15 @@ static void register_array_finalize(Object *obj)RegisterInfoArray *r_array =REGISTER_ARRAY (obj);g_free (r_array->r); } +DeviceState *register_array_get_owner (const RegisterInfoArray *reg_array) +{ +return DEVICE (OBJECT (reg_array)->parent); +} +static const TypeInfo register_array_info = { .name =TYPE_REGISTER_ARRAY , .parent =TYPE_OBJECT , .instance_size =sizeof (RegisterInfoArray), .instance_finalize = register_array_finalize,hw/nvram/xlnx-versal-efuse-ctrl.c +2
-2@@ -617,15 +617,15 @@ static const RegisterAccessInfo efuse_ctrl_regs_info[] = {static void efuse_ctrl_reg_write (void *opaque,hwaddr addr,uint64_t data,unsigned size) {RegisterInfoArray *reg_array = opaque;XlnxVersalEFuseCtrl *s; -Object *dev; +DeviceState *dev;assert (reg_array !=NULL ); - dev = reg_array->mem.owner; + dev =register_array_get_owner (reg_array);assert (dev); s =XLNX_VERSAL_EFUSE_CTRL (dev);if (addr !=A_WR_LOCK && s->regs[R_WR_LOCK ]) {hw/nvram/xlnx-zynqmp-efuse.c +2
-2@@ -722,15 +722,15 @@ static RegisterAccessInfo zynqmp_efuse_regs_info[] = {static void zynqmp_efuse_reg_write (void *opaque,hwaddr addr,uint64_t data,unsigned size) {RegisterInfoArray *reg_array = opaque;XlnxZynqMPEFuse *s; -Object *dev; +DeviceState *dev;assert (reg_array !=NULL ); - dev = reg_array->mem.owner; + dev =register_array_get_owner (reg_array);assert (dev); s =XLNX_ZYNQMP_EFUSE (dev);if (addr !=A_WR_LOCK && s->regs[R_WR_LOCK ]) {hw/ssi/xlnx-versal-ospi.c +3
-8@@ -1567,19 +1567,15 @@ static RegisterAccessInfo ospi_regs_info[] = { .ro = 0xffffffff, } };/* Return dev-obj from reg-region created by register_init_block32 */ -static XlnxVersalOspi *xilinx_ospi_of_mr (void *mr_accessor) +static XlnxVersalOspi *xilinx_ospi_of_mr (void *opaque) { -RegisterInfoArray *reg_array = mr_accessor; -Object *dev; +RegisterInfoArray *reg_array =REGISTER_ARRAY (opaque); - dev = reg_array->mem.owner; -assert (dev); - -return XILINX_VERSAL_OSPI (dev); +return XILINX_VERSAL_OSPI (register_array_get_owner (reg_array)); }static void ospi_write (void *opaque,hwaddr addr,uint64_t value,unsigned int size) { --2.53.0
Quoted 16 lines · Luc Michel
Add the
register_array_get_ownerfunction 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.
5c6367bc1c8850f74812eeaaf87cff9911be58demodified 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
Quoted 8 lines
Signed-off-by Luc Michel <[email protected]>--- include/hw/core/register.h | 11 +++++++++++ hw/core/register.c | 5 +++++ hw/nvram/xlnx-versal-efuse-ctrl.c | 4 ++-- hw/nvram/xlnx-zynqmp-efuse.c | 4 ++-- hw/ssi/xlnx-versal-ospi.c | 10 +++------- 5 files changed, 23 insertions(+), 11 deletions(-)
Thanks for the fix!
Quoted 16 lines · Luc Michel
Add the
register_array_get_ownerfunction 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.
5c6367bc1c8850f74812eeaaf87cff9911be58demodified 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
Quoted 8 lines
Signed-off-by Luc Michel <[email protected]>--- include/hw/core/register.h | 11 +++++++++++ hw/core/register.c | 5 +++++ hw/nvram/xlnx-versal-efuse-ctrl.c | 4 ++-- hw/nvram/xlnx-zynqmp-efuse.c | 4 ++-- hw/ssi/xlnx-versal-ospi.c | 10 +++------- 5 files changed, 23 insertions(+), 11 deletions(-)
This looks like a qemu-stable material (for 11.0.x series), I'm picking it up. Please let me know if I shouldn't.
Thanks,
/mjt
Quoted 26 lines · Michael Tokarev
Quoted 16 lines · Luc Michel
Add the
register_array_get_ownerfunction 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.
5c6367bc1c8850f74812eeaaf87cff9911be58demodified 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/3423Quoted 8 lines
Signed-off-by Luc Michel <[email protected]>--- include/hw/core/register.h | 11 +++++++++++ hw/core/register.c | 5 +++++ hw/nvram/xlnx-versal-efuse-ctrl.c | 4 ++-- hw/nvram/xlnx-zynqmp-efuse.c | 4 ++-- hw/ssi/xlnx-versal-ospi.c | 10 +++------- 5 files changed, 23 insertions(+), 11 deletions(-)
Quoted 2 lines
This looks like a qemu-stable material (for 11.0.x series), I'm picking it up. Please let me know if I shouldn't.
Indeed, thank you!
Luc
Quoted 4 lines
Thanks,
/mjt