[PATCH v4 2/3] xilink-zynq-devcfg: Fix up for memory address range size not set correctly

Chao Liu posted 3 patches 2 weeks, 1 day ago
[PATCH v4 2/3] xilink-zynq-devcfg: Fix up for memory address range size not set correctly
Posted by Chao Liu 2 weeks, 1 day ago
Signed-off-by: Chao Liu <chao.liu@yeah.net>
---
 hw/dma/xlnx-zynq-devcfg.c         | 2 +-
 include/hw/dma/xlnx-zynq-devcfg.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/dma/xlnx-zynq-devcfg.c b/hw/dma/xlnx-zynq-devcfg.c
index b8544d0731..e5eff9abc0 100644
--- a/hw/dma/xlnx-zynq-devcfg.c
+++ b/hw/dma/xlnx-zynq-devcfg.c
@@ -365,7 +365,7 @@ static void xlnx_zynq_devcfg_init(Object *obj)
 
     sysbus_init_irq(sbd, &s->irq);
 
-    memory_region_init(&s->iomem, obj, "devcfg", XLNX_ZYNQ_DEVCFG_R_MAX * 4);
+    memory_region_init(&s->iomem, obj, "devcfg", XLNX_ZYNQ_DEVCFG_R_MAX);
     reg_array =
         register_init_block32(DEVICE(obj), xlnx_zynq_devcfg_regs_info,
                               ARRAY_SIZE(xlnx_zynq_devcfg_regs_info),
diff --git a/include/hw/dma/xlnx-zynq-devcfg.h b/include/hw/dma/xlnx-zynq-devcfg.h
index e4cf085d70..fc26132069 100644
--- a/include/hw/dma/xlnx-zynq-devcfg.h
+++ b/include/hw/dma/xlnx-zynq-devcfg.h
@@ -35,7 +35,7 @@
 
 OBJECT_DECLARE_SIMPLE_TYPE(XlnxZynqDevcfg, XLNX_ZYNQ_DEVCFG)
 
-#define XLNX_ZYNQ_DEVCFG_R_MAX (0x100 / 4)
+#define XLNX_ZYNQ_DEVCFG_R_MAX 0x100
 
 #define XLNX_ZYNQ_DEVCFG_DMA_CMD_FIFO_LEN 10
 
-- 
2.46.1
Re: [PATCH v4 2/3] xilink-zynq-devcfg: Fix up for memory address range size not set correctly
Posted by Peter Maydell 1 week, 1 day ago
On Mon, 7 Oct 2024 at 12:25, Chao Liu <chao.liu@yeah.net> wrote:
>
> Signed-off-by: Chao Liu <chao.liu@yeah.net>
> ---
>  hw/dma/xlnx-zynq-devcfg.c         | 2 +-
>  include/hw/dma/xlnx-zynq-devcfg.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/dma/xlnx-zynq-devcfg.c b/hw/dma/xlnx-zynq-devcfg.c
> index b8544d0731..e5eff9abc0 100644
> --- a/hw/dma/xlnx-zynq-devcfg.c
> +++ b/hw/dma/xlnx-zynq-devcfg.c
> @@ -365,7 +365,7 @@ static void xlnx_zynq_devcfg_init(Object *obj)
>
>      sysbus_init_irq(sbd, &s->irq);
>
> -    memory_region_init(&s->iomem, obj, "devcfg", XLNX_ZYNQ_DEVCFG_R_MAX * 4);
> +    memory_region_init(&s->iomem, obj, "devcfg", XLNX_ZYNQ_DEVCFG_R_MAX);
>      reg_array =
>          register_init_block32(DEVICE(obj), xlnx_zynq_devcfg_regs_info,
>                                ARRAY_SIZE(xlnx_zynq_devcfg_regs_info),
> diff --git a/include/hw/dma/xlnx-zynq-devcfg.h b/include/hw/dma/xlnx-zynq-devcfg.h
> index e4cf085d70..fc26132069 100644
> --- a/include/hw/dma/xlnx-zynq-devcfg.h
> +++ b/include/hw/dma/xlnx-zynq-devcfg.h
> @@ -35,7 +35,7 @@
>
>  OBJECT_DECLARE_SIMPLE_TYPE(XlnxZynqDevcfg, XLNX_ZYNQ_DEVCFG)
>
> -#define XLNX_ZYNQ_DEVCFG_R_MAX (0x100 / 4)
> +#define XLNX_ZYNQ_DEVCFG_R_MAX 0x100

This doesn't look right. The device tree in Linux says this
device is 0x100 bytes long. In QEMU the _R_MAX type constant
generally is the number of (32-bit) registers, hence the
division by 4 here to go from bytes to words, and the multiply
by 4 to get the memory_region_init() argument which is bytes
again.

What is this patch trying to fix?

("What is this change fixing" is the kind of thing you
should explain in the commit message.)

thanks
-- PMM