Skip to contentSkip to conversation

hw/core/register: add register_array_get_owner

PATCH In review Luc Michel 5 participants 6 messages Apr 24 – May 1 Arm/Zynq architecture

lore
Share & tools
lore

Luc Michel

author
#0 lore raw

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
index 1f265f4ed71..c6f648fe95e 100644
@@ -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
index c3f3c936e70..99ca5e17758 100644
@@ -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
index 69acdfa3047..f5d5587cb65 100644
@@ -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
index e6bc54fc6bd..028120f824d 100644
@@ -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
index 467f0ce7033..e25e4c26c2e 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Luc Michel

Add the register_array_get_owner function 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. 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.

Fixes 5c6367bc1c8 ("hw/core/register: add the REGISTER_ARRAY type")
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/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(-)
hw/core/register.c +0 -0
index c3f3c936e70..99ca5e17758 100644

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
+}
Reviewed-by on v1 1/1
#2 lore raw
In reply to Luc Michel
Quoted 11 lines · Luc Michel

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.

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/3423

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
index 1f265f4ed71..c6f648fe95e 100644
@@ -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
index c3f3c936e70..99ca5e17758 100644
@@ -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
index 69acdfa3047..f5d5587cb65 100644
@@ -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
index e6bc54fc6bd..028120f824d 100644
@@ -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
index 467f0ce7033..e25e4c26c2e 100644
@@ -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

Tested-by on v1 1/1
#3 lore raw
In reply to Luc Michel
Quoted 16 lines · Luc Michel

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

Quoted 8 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(-)

Thanks for the fix!

#4 lore raw
In reply to Luc Michel
Quoted 16 lines · Luc Michel

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

Quoted 8 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(-)

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

author
#5 lore raw
Quoted 26 lines · Michael Tokarev
Quoted 16 lines · Luc Michel

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

Quoted 8 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(-)
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