[PATCH v3 1/8] hw/net:ftgmac100: update memory region size to 64KB

Jamin Lin via posted 8 patches 2 months, 2 weeks ago
Maintainers: "Cédric Le Goater" <clg@kaod.org>, Peter Maydell <peter.maydell@linaro.org>, Steven Lee <steven_lee@aspeedtech.com>, Troy Lee <leetroy@gmail.com>, Jamin Lin <jamin_lin@aspeedtech.com>, Andrew Jeffery <andrew@codeconstruct.com.au>, Joel Stanley <joel@jms.id.au>, Alistair Francis <alistair@alistair23.me>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Jason Wang <jasowang@redhat.com>, Cleber Rosa <crosa@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Beraldo Leal <bleal@redhat.com>
[PATCH v3 1/8] hw/net:ftgmac100: update memory region size to 64KB
Posted by Jamin Lin via 2 months, 2 weeks ago
According to the datasheet of ASPEED SOCs,
one MAC controller owns 128KB of register space for AST2500.
However, one MAC controller only owns 64KB of register space for AST2600
and AST2700. It set the memory region size 128KB and it occupied another
controllers Address Spaces.

Update one MAC controller memory region size to 0x1000
because AST2500 did not use register spaces over than 64KB.

Introduce a new container region size to 0x1000 and its range
is from 0 to 0xfff. This container is mapped a sub region
for the current set of register.
This sub region range is from 0 to 0xff.

Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
---
 hw/net/ftgmac100.c         | 11 ++++++++---
 include/hw/net/ftgmac100.h |  4 ++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c
index 25e4c0cd5b..9e1f12cd33 100644
--- a/hw/net/ftgmac100.c
+++ b/hw/net/ftgmac100.c
@@ -1107,9 +1107,14 @@ static void ftgmac100_realize(DeviceState *dev, Error **errp)
         s->rxdes0_edorr = FTGMAC100_RXDES0_EDORR;
     }
 
-    memory_region_init_io(&s->iomem, OBJECT(dev), &ftgmac100_ops, s,
-                          TYPE_FTGMAC100, 0x2000);
-    sysbus_init_mmio(sbd, &s->iomem);
+    memory_region_init(&s->iomem_container, OBJECT(s),
+                       TYPE_FTGMAC100 ".container", FTGMAC100_MEM_SIZE);
+    sysbus_init_mmio(sbd, &s->iomem_container);
+
+    memory_region_init_io(&s->iomem, OBJECT(s), &ftgmac100_ops, s,
+                          TYPE_FTGMAC100 ".regs", FTGMAC100_REG_MEM_SIZE);
+    memory_region_add_subregion(&s->iomem_container, 0x0, &s->iomem);
+
     sysbus_init_irq(sbd, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
diff --git a/include/hw/net/ftgmac100.h b/include/hw/net/ftgmac100.h
index 765d1538a4..269446e858 100644
--- a/include/hw/net/ftgmac100.h
+++ b/include/hw/net/ftgmac100.h
@@ -14,6 +14,9 @@
 #define TYPE_FTGMAC100 "ftgmac100"
 OBJECT_DECLARE_SIMPLE_TYPE(FTGMAC100State, FTGMAC100)
 
+#define FTGMAC100_MEM_SIZE 0x1000
+#define FTGMAC100_REG_MEM_SIZE 0x100
+
 #include "hw/sysbus.h"
 #include "net/net.h"
 
@@ -30,6 +33,7 @@ struct FTGMAC100State {
     NICState *nic;
     NICConf conf;
     qemu_irq irq;
+    MemoryRegion iomem_container;
     MemoryRegion iomem;
 
     uint8_t frame[FTGMAC100_MAX_FRAME_SIZE];
-- 
2.34.1
Re: [PATCH v3 1/8] hw/net:ftgmac100: update memory region size to 64KB
Posted by Cédric Le Goater 2 months, 2 weeks ago
On 7/4/24 10:29 AM, Jamin Lin wrote:
> According to the datasheet of ASPEED SOCs,
> one MAC controller owns 128KB of register space for AST2500.
> However, one MAC controller only owns 64KB of register space for AST2600
> and AST2700. It set the memory region size 128KB and it occupied another
> controllers Address Spaces.
> 
> Update one MAC controller memory region size to 0x1000
> because AST2500 did not use register spaces over than 64KB.
> 
> Introduce a new container region size to 0x1000 and its range
> is from 0 to 0xfff. This container is mapped a sub region
> for the current set of register.
> This sub region range is from 0 to 0xff.
> 
> Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/net/ftgmac100.c         | 11 ++++++++---
>   include/hw/net/ftgmac100.h |  4 ++++
>   2 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c
> index 25e4c0cd5b..9e1f12cd33 100644
> --- a/hw/net/ftgmac100.c
> +++ b/hw/net/ftgmac100.c
> @@ -1107,9 +1107,14 @@ static void ftgmac100_realize(DeviceState *dev, Error **errp)
>           s->rxdes0_edorr = FTGMAC100_RXDES0_EDORR;
>       }
>   
> -    memory_region_init_io(&s->iomem, OBJECT(dev), &ftgmac100_ops, s,
> -                          TYPE_FTGMAC100, 0x2000);
> -    sysbus_init_mmio(sbd, &s->iomem);
> +    memory_region_init(&s->iomem_container, OBJECT(s),
> +                       TYPE_FTGMAC100 ".container", FTGMAC100_MEM_SIZE);
> +    sysbus_init_mmio(sbd, &s->iomem_container);
> +
> +    memory_region_init_io(&s->iomem, OBJECT(s), &ftgmac100_ops, s,
> +                          TYPE_FTGMAC100 ".regs", FTGMAC100_REG_MEM_SIZE);
> +    memory_region_add_subregion(&s->iomem_container, 0x0, &s->iomem);
> +
>       sysbus_init_irq(sbd, &s->irq);
>       qemu_macaddr_default_if_unset(&s->conf.macaddr);
>   
> diff --git a/include/hw/net/ftgmac100.h b/include/hw/net/ftgmac100.h
> index 765d1538a4..269446e858 100644
> --- a/include/hw/net/ftgmac100.h
> +++ b/include/hw/net/ftgmac100.h
> @@ -14,6 +14,9 @@
>   #define TYPE_FTGMAC100 "ftgmac100"
>   OBJECT_DECLARE_SIMPLE_TYPE(FTGMAC100State, FTGMAC100)
>   
> +#define FTGMAC100_MEM_SIZE 0x1000
> +#define FTGMAC100_REG_MEM_SIZE 0x100
> +
>   #include "hw/sysbus.h"
>   #include "net/net.h"
>   
> @@ -30,6 +33,7 @@ struct FTGMAC100State {
>       NICState *nic;
>       NICConf conf;
>       qemu_irq irq;
> +    MemoryRegion iomem_container;
>       MemoryRegion iomem;
>   
>       uint8_t frame[FTGMAC100_MAX_FRAME_SIZE];