Skip to contentSkip to conversation

Renesas RZ/Five add support to configure PMA and add vendor specific SBI extension

RFC PATCH Superseded Lad Prabhakar 4 participants 14 messages Jan 26, 2023 – Jan 30, 2023

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover Renesas RZ/Five add support to configure PMA and add vendor specific SBI extension

Hi All,

This patch series aims to add support to configure the PMA regions present on the Andes AX45MP core (andes45-pma.c which can be shared with other Andes vendors) and configures the required PMA region for RZ/Five SoC.

This patch series also adds the SBI vendor extension RENESAS_RZFIVE_SBI_EXT_IOCP_SW_WORKAROUND to check if IOCP is present on the core and if un-available it also checks if SW workaround for cache management needs to be applied.

RFC v2 -> RFC v3
-> Fixed review comments pointed by Lin-san
* Used switch case macro
* Added a check to verify the PMA size is power-of-2
* Dropped un-needed calculation done in PMA code for NAPOT.
* Dropped MISA macro
-> Fixed comments pointed by Himanshu
-> Fixed check patch issue

RFC v2 -> RFC v1
-> Fixed review comments pointed by Lin-san -> Implemented PMA as library so that it can be shared

RFC v1:
https://patchwork.ozlabs.org/project/opensbi/patch/20221212094421.14556-1-prabhakar.mahadev-lad.rj at bp.renesas.com/

Cheers,
Prabhakar

Lad Prabhakar (3):
platform: generic: renesas: rzfive: Add support to configure the PMA
platform: generic: renesas: rzfive: Configure the PMA region
platform: generic: renesas: rzfive: Add SBI EXT to check for enabling
IOCP errata

 platform/generic/Kconfig                      |   9 +
 platform/generic/include/andes45-pma.h        |  48 +++
 platform/generic/renesas/rzfive/andes45-pma.c | 350 ++++++++++++++++++
 platform/generic/renesas/rzfive/objects.mk    |   1 +
 platform/generic/renesas/rzfive/rzfive.c      |  90 +++++
 5 files changed, 498 insertions(+)
 create mode 100644 platform/generic/include/andes45-pma.h
 create mode 100644 platform/generic/renesas/rzfive/andes45-pma.c
Signature · 1 line
2.17.1
#1 lore raw

RFC PATCH v3 1/3 platform: generic: renesas: rzfive: Add support to configure the PMA

I/O Coherence Port (IOCP) provides an AXI interface for connecting external non-caching masters, such as DMA controllers. The accesses from IOCP are coherent with D-Caches and L2 Cache.

IOCP is a specification option and is disabled on the Renesas RZ/Five SoC due to this reason IP blocks using DMA will fail.

The Andes AX45MP core has a Programmable Physical Memory Attributes (PMA) block that allows dynamic adjustment of memory attributes in the runtime. It contains a configurable amount of PMA entries implemented as CSR registers to control the attributes of memory locations in interest. Below are the memory attributes supported:
* Device, Non-bufferable
* Device, bufferable
* Memory, Non-cacheable, Non-bufferable
* Memory, Non-cacheable, Bufferable
* Memory, Write-back, No-allocate
* Memory, Write-back, Read-allocate
* Memory, Write-back, Write-allocate
* Memory, Write-back, Read and Write-allocate

More info about PMA (section 10.3):

As a workaround for SoCs with IOCP disabled CMO needs to be handled by software. Firstly OpenSBI configures the memory region as "Memory, Non-cacheable, Bufferable" and passes this region as a global shared dma pool as a DT node. With DMA_GLOBAL_POOL enabled all DMA allocations happen from this region and synchronization callbacks are implemented to synchronize when doing DMA transactions.

Example PMA region passed as a DT node from OpenSBI:

    reserved-memory {
        #address-cells = <2>;
        #size-cells = <2>;
        ranges;

        pma_resv0 at 58000000 {
            compatible = "shared-dma-pool";
            reg = <0x0 0x58000000 0x0 0x08000000>;
            no-map;
            linux,dma-default;
        };
    };
---
 platform/generic/Kconfig                      |   8 +
 platform/generic/include/andes45-pma.h        |  48 +++
 platform/generic/renesas/rzfive/andes45-pma.c | 350 ++++++++++++++++++
 platform/generic/renesas/rzfive/objects.mk    |   1 +
 4 files changed, 407 insertions(+)
 create mode 100644 platform/generic/include/andes45-pma.h
 create mode 100644 platform/generic/renesas/rzfive/andes45-pma.c
platform/generic/Kconfig +8 -0
index c7f198a..9ee9fe3 100644
@@ -51,3 +51,11 @@ config PLATFORM_STARFIVE_JH7110
 	default n
 
 endif
+
+if PLATFORM_RENESAS_RZFIVE
+
+config ANDES45_PMA
+	bool "Andes PMA support"
+	default n
+
+endif
platform/generic/include/andes45-pma.h new file +48 -0

48 lines not on this page · raw message

platform/generic/renesas/rzfive/andes45-pma.c new file +350 -0

350 lines not on this page · raw message

platform/generic/renesas/rzfive/objects.mk +1 -0
index 2e7e37f..fd9e7c4 100644
@@ -6,3 +6,4 @@
 
 carray-platform_override_modules-$(CONFIG_PLATFORM_RENESAS_RZFIVE) += renesas_rzfive
 platform-objs-$(CONFIG_PLATFORM_RENESAS_RZFIVE) += renesas/rzfive/rzfive.o
+platform-objs-$(CONFIG_ANDES45_PMA) += renesas/rzfive/andes45-pma.o
Signature · 1 line
2.17.1
#2 lore raw

RFC PATCH v3 1/3 platform: generic: renesas: rzfive: Add support to configure the PMA

Hi Prabhakar,

Quoted 10 lines
platform/generic/renesas/rzfive/andes45-pma.c new file +10 -0
+static unsigned long
+andes45_pma_setup(const struct andes45_pma_region *pma_region,
+		  unsigned int entry_id)
+{
+	unsigned long size = pma_region->size;
+	unsigned long addr = pma_region->pa;
+	unsigned int pma_cfg_addr;
+	unsigned long pmacfg_val;
+	unsigned long pmaaddr;
+	char *pmaxcfg;

platform/generic/renesas/rzfive/andes45-pma.c line 168

Quoted 10 lines
platform/generic/renesas/rzfive/andes45-pma.c new file +10 -0
+
+	/* Check for 4KiB granularity */
+	if (size < (1 << 12))
+		return SBI_EINVAL;
+
+	/* Check size is power of 2 */
+	if (size & (size - 1))
+		return SBI_EINVAL;
+
+	if (pma_region->flags > 0xff || entry_id > 15)

(pma_region->flags > 0xff) is always false as its type is unsigned char? I guess we can drop the condition and specify the bit-field of flags as 7-bit wide (the MSB is reserved), i.e.

struct andes45_pma_region {
    unsigned long pa;
    unsigned long size;
    u8 flags:7;

[...]

So if someone sets the flags to a value greater than 0x7f, it will cause a compilation error.

Regards,
Peter Lin

#3 lore raw

RFC PATCH v3 1/3 platform: generic: renesas: rzfive: Add support to configure the PMA

Hi Yu-Chien,

Thank you for the review.

Quoted 28 lines · Yu-Chien Peter Lin

Hi Prabhakar,

Quoted 10 lines
platform/generic/renesas/rzfive/andes45-pma.c new file +10 -0
+static unsigned long
+andes45_pma_setup(const struct andes45_pma_region *pma_region,
+               unsigned int entry_id)
+{
+     unsigned long size = pma_region->size;
+     unsigned long addr = pma_region->pa;
+     unsigned int pma_cfg_addr;
+     unsigned long pmacfg_val;
+     unsigned long pmaaddr;
+     char *pmaxcfg;

platform/generic/renesas/rzfive/andes45-pma.c line 168

Quoted 10 lines
platform/generic/renesas/rzfive/andes45-pma.c new file +10 -0
+
+     /* Check for 4KiB granularity */
+     if (size < (1 << 12))
+             return SBI_EINVAL;
+
+     /* Check size is power of 2 */
+     if (size & (size - 1))
+             return SBI_EINVAL;
+
+     if (pma_region->flags > 0xff || entry_id > 15)

(pma_region->flags > 0xff) is always false as its type is unsigned char? I guess we can drop the condition and specify the bit-field of flags as 7-bit wide (the MSB is reserved), i.e.

Quoted 9 lines
struct andes45_pma_region {
    unsigned long pa;
    unsigned long size;
    u8 flags:7;

[...]

So if someone sets the flags to a value greater than 0x7f, it will cause a compilation error.

Good point, I will update this in the next version.

Cheers,
Prabhakar

#4 lore raw

RFC PATCH v3 2/3 platform: generic: renesas: rzfive: Configure the PMA region

In reply to Lad Prabhakar

On the Renesas RZ/Five SoC by default we want to configure 128MiB of memory ranging from 0x58000000 as a non-cacheable + bufferable region in the PMA and populate this region as PMA reserve DT node with shared DMA pool and no-map flags set so that Linux drivers requesting any DMA'able memory go through this region.

PMA node passed to the above stack:

        reserved-memory {
            #address-cells = <2>;
            #size-cells = <2>;
            ranges;

            pma_resv0 at 58000000 {
                compatible = "shared-dma-pool";
                reg = <0x0 0x58000000 0x0 0x08000000>;
                no-map;
                linux,dma-default;
            };
        };
---
 platform/generic/Kconfig                 |  1 +
 platform/generic/renesas/rzfive/rzfive.c | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
platform/generic/Kconfig +1 -0
index 9ee9fe3..bc5c280 100644
@@ -35,6 +35,7 @@ config PLATFORM_ANDES_AE350
 
 config PLATFORM_RENESAS_RZFIVE
 	bool "Renesas RZ/Five support"
+	select ANDES45_PMA
 	default n
 
 config PLATFORM_SIFIVE_FU540
platform/generic/renesas/rzfive/rzfive.c +21 -0
index ee9c9c4..0a8c9f9 100644
@@ -4,10 +4,30 @@
  *
  */
 
+#include <andes45-pma.h>
 #include <platform_override.h>
 #include <sbi/sbi_domain.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 
+static const struct andes45_pma_region renesas_rzfive_pma_regions[] = {
+	{
+		.pa = 0x58000000,
+		.size = 0x8000000,
+		.flags = ANDES45_PMACFG_ETYP_NAPOT |
+			 ANDES45_PMACFG_MTYP_MEM_NON_CACHE_BUF,
+		.dt_populate = true,
+		.shared_dma = true,
+		.no_map = true,
+		.dma_default = true,
+	},
+};
+
+static int renesas_rzfive_final_init(bool cold_boot, const struct fdt_match *match)
+{
+	return andes45_pma_setup_regions(renesas_rzfive_pma_regions,
+					 array_size(renesas_rzfive_pma_regions));
+}
+
 int renesas_rzfive_early_init(bool cold_boot, const struct fdt_match *match)
 {
 	/*
@@ -34,4 +54,5 @@ static const struct fdt_match renesas_rzfive_match[] = {
 const struct platform_override renesas_rzfive = {
 	.match_table = renesas_rzfive_match,
 	.early_init = renesas_rzfive_early_init,
+	.final_init = renesas_rzfive_final_init,
 };
Signature · 1 line
2.17.1
#5 lore raw

RFC PATCH v3 2/3 platform: generic: renesas: rzfive: Configure the PMA region

Quoted 21 lines · Lad Prabhakar

On the Renesas RZ/Five SoC by default we want to configure 128MiB of memory ranging from 0x58000000 as a non-cacheable + bufferable region in the PMA and populate this region as PMA reserve DT node with shared DMA pool and no-map flags set so that Linux drivers requesting any DMA'able memory go through this region.

PMA node passed to the above stack:

        reserved-memory {
            #address-cells = <2>;
            #size-cells = <2>;
            ranges;

            pma_resv0 at 58000000 {
                compatible = "shared-dma-pool";
                reg = <0x0 0x58000000 0x0 0x08000000>;
                no-map;
                linux,dma-default;
            };
        };
Quoted 1 line

Regards,
Peter Lin

Quoted 61 lines
---
 platform/generic/Kconfig                 |  1 +
 platform/generic/renesas/rzfive/rzfive.c | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
platform/generic/Kconfig +1 -0
index 9ee9fe3..bc5c280 100644
@@ -35,6 +35,7 @@ config PLATFORM_ANDES_AE350
 
 config PLATFORM_RENESAS_RZFIVE
 	bool "Renesas RZ/Five support"
+	select ANDES45_PMA
 	default n
 
 config PLATFORM_SIFIVE_FU540
platform/generic/renesas/rzfive/rzfive.c +21 -0
index ee9c9c4..0a8c9f9 100644
@@ -4,10 +4,30 @@
  *
  */
 
+#include <andes45-pma.h>
 #include <platform_override.h>
 #include <sbi/sbi_domain.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 
+static const struct andes45_pma_region renesas_rzfive_pma_regions[] = {
+	{
+		.pa = 0x58000000,
+		.size = 0x8000000,
+		.flags = ANDES45_PMACFG_ETYP_NAPOT |
+			 ANDES45_PMACFG_MTYP_MEM_NON_CACHE_BUF,
+		.dt_populate = true,
+		.shared_dma = true,
+		.no_map = true,
+		.dma_default = true,
+	},
+};
+
+static int renesas_rzfive_final_init(bool cold_boot, const struct fdt_match *match)
+{
+	return andes45_pma_setup_regions(renesas_rzfive_pma_regions,
+					 array_size(renesas_rzfive_pma_regions));
+}
+
 int renesas_rzfive_early_init(bool cold_boot, const struct fdt_match *match)
 {
 	/*
@@ -34,4 +54,5 @@ static const struct fdt_match renesas_rzfive_match[] = {
 const struct platform_override renesas_rzfive = {
 	.match_table = renesas_rzfive_match,
 	.early_init = renesas_rzfive_early_init,
+	.final_init = renesas_rzfive_final_init,
 };
Signature · 1 line
2.17.1
#6 lore raw

RFC PATCH v3 2/3 platform: generic: renesas: rzfive: Configure the PMA region

In reply to Lad Prabhakar
Quoted 45 lines · Lad Prabhakar

On the Renesas RZ/Five SoC by default we want to configure 128MiB of memory ranging from 0x58000000 as a non-cacheable + bufferable region in the PMA and populate this region as PMA reserve DT node with shared DMA pool and no-map flags set so that Linux drivers requesting any DMA'able memory go through this region.

PMA node passed to the above stack:

       reserved-memory {
           #address-cells = <2>;
           #size-cells = <2>;
           ranges;

           pma_resv0 at 58000000 {
               compatible = "shared-dma-pool";
               reg = <0x0 0x58000000 0x0 0x08000000>;
               no-map;
               linux,dma-default;
           };
       };

---
platform/generic/Kconfig | 1 +
platform/generic/renesas/rzfive/rzfive.c | 21 +++++++++++++++++++++

2 files changed, 22 insertions(+)
platform/generic/Kconfig +0 -0
index 9ee9fe3..bc5c280 100644
@@ -35,6 +35,7 @@ config PLATFORM_ANDES_AE350
 

config PLATFORM_RENESAS_RZFIVE
bool "Renesas RZ/Five support"

platform/generic/Kconfig +1 -0
+	select ANDES45_PMA

default n

config PLATFORM_SIFIVE_FU540

platform/generic/renesas/rzfive/rzfive.c +0 -0
index ee9c9c4..0a8c9f9 100644

platform/generic/renesas/rzfive/rzfive.c line 7

Quoted 4 lines
platform/generic/renesas/rzfive/rzfive.c +1 -0
@@ -4,10 +4,30 @@
 *
 */
 
+#include <andes45-pma.h>

This name looks inconsistent.

Jess

Quoted 40 lines
platform/generic/renesas/rzfive/rzfive.c +20 -0
 #include <platform_override.h>
 #include <sbi/sbi_domain.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 
+static const struct andes45_pma_region renesas_rzfive_pma_regions[] = {
+	{
+		.pa = 0x58000000,
+		.size = 0x8000000,
+		.flags = ANDES45_PMACFG_ETYP_NAPOT |
+			 ANDES45_PMACFG_MTYP_MEM_NON_CACHE_BUF,
+		.dt_populate = true,
+		.shared_dma = true,
+		.no_map = true,
+		.dma_default = true,
+	},
+};
+
+static int renesas_rzfive_final_init(bool cold_boot, const struct fdt_match *match)
+{
+	return andes45_pma_setup_regions(renesas_rzfive_pma_regions,
+					 array_size(renesas_rzfive_pma_regions));
+}
+
 int renesas_rzfive_early_init(bool cold_boot, const struct fdt_match *match)
 {
 	/*
@@ -34,4 +54,5 @@ static const struct fdt_match renesas_rzfive_match[] = {
 const struct platform_override renesas_rzfive = {
 	.match_table = renesas_rzfive_match,
 	.early_init = renesas_rzfive_early_init,
+	.final_init = renesas_rzfive_final_init,
 };
Signature · 7 lines
2.17.1


-- 
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
#7 lore raw

RFC PATCH v3 2/3 platform: generic: renesas: rzfive: Configure the PMA region

Hi Jessica,

Thank you for the review.

Quoted 50 lines · Jessica Clarke
Quoted 48 lines · Lad Prabhakar

On the Renesas RZ/Five SoC by default we want to configure 128MiB of memory ranging from 0x58000000 as a non-cacheable + bufferable region in the PMA and populate this region as PMA reserve DT node with shared DMA pool and no-map flags set so that Linux drivers requesting any DMA'able memory go through this region.

PMA node passed to the above stack:

       reserved-memory {
           #address-cells = <2>;
           #size-cells = <2>;
           ranges;

           pma_resv0 at 58000000 {
               compatible = "shared-dma-pool";
               reg = <0x0 0x58000000 0x0 0x08000000>;
               no-map;
               linux,dma-default;
           };
       };

---
platform/generic/Kconfig | 1 +
platform/generic/renesas/rzfive/rzfive.c | 21 +++++++++++++++++++++

2 files changed, 22 insertions(+)
platform/generic/Kconfig +0 -0
index 9ee9fe3..bc5c280 100644
@@ -35,6 +35,7 @@ config PLATFORM_ANDES_AE350
 

config PLATFORM_RENESAS_RZFIVE
bool "Renesas RZ/Five support"
+ select ANDES45_PMA
default n

config PLATFORM_SIFIVE_FU540

platform/generic/renesas/rzfive/rzfive.c +0 -0
index ee9c9c4..0a8c9f9 100644
@@ -4,10 +4,30 @@
 *
 */
 
Quoted 4 lines

platform/generic/renesas/rzfive/rzfive.c line 7

Quoted 1 line
platform/generic/renesas/rzfive/rzfive.c +1 -0
+#include <andes45-pma.h>

This name looks inconsistent.

As the RZ/Five has the Andes AX45MP core and the PMA code will be re-used by other non-coherent Andes AX45MP platforms hence the andes45-pma.h (Also suggested by Andes maintainer)

Cheers,
Prabhakar

#8 lore raw

RFC PATCH v3 2/3 platform: generic: renesas: rzfive: Configure the PMA region

Quoted 56 lines · Prabhakar

Hi Jessica,

Thank you for the review.

Quoted 50 lines · Jessica Clarke
Quoted 48 lines · Lad Prabhakar

On the Renesas RZ/Five SoC by default we want to configure 128MiB of memory ranging from 0x58000000 as a non-cacheable + bufferable region in the PMA and populate this region as PMA reserve DT node with shared DMA pool and no-map flags set so that Linux drivers requesting any DMA'able memory go through this region.

PMA node passed to the above stack:

      reserved-memory {
          #address-cells = <2>;
          #size-cells = <2>;
          ranges;

          pma_resv0 at 58000000 {
              compatible = "shared-dma-pool";
              reg = <0x0 0x58000000 0x0 0x08000000>;
              no-map;
              linux,dma-default;
          };
      };

---
platform/generic/Kconfig | 1 +
platform/generic/renesas/rzfive/rzfive.c | 21 +++++++++++++++++++++

2 files changed, 22 insertions(+)
platform/generic/Kconfig +0 -0
index 9ee9fe3..bc5c280 100644
@@ -35,6 +35,7 @@ config PLATFORM_ANDES_AE350
 

config PLATFORM_RENESAS_RZFIVE
bool "Renesas RZ/Five support"
+ select ANDES45_PMA
default n

config PLATFORM_SIFIVE_FU540

platform/generic/renesas/rzfive/rzfive.c +0 -0
index ee9c9c4..0a8c9f9 100644
@@ -4,10 +4,30 @@
 *
 */
 
Quoted 7 lines
Quoted 4 lines

platform/generic/renesas/rzfive/rzfive.c line 7

Quoted 1 line
platform/generic/renesas/rzfive/rzfive.c +1 -0
+#include <andes45-pma.h>

This name looks inconsistent.

As the RZ/Five has the Andes AX45MP core and the PMA code will be re-used by other non-coherent Andes AX45MP platforms hence the andes45-pma.h (Also suggested by Andes maintainer)

I understand that. I meant the dash should be an underscore.

Jess

#9 lore raw

RFC PATCH v3 2/3 platform: generic: renesas: rzfive: Configure the PMA region

Quoted 62 lines · Jessica Clarke
Quoted 60 lines · Prabhakar

Hi Jessica,

Thank you for the review.

Quoted 54 lines · Jessica Clarke
Quoted 45 lines · Lad Prabhakar

On the Renesas RZ/Five SoC by default we want to configure 128MiB of memory ranging from 0x58000000 as a non-cacheable + bufferable region in the PMA and populate this region as PMA reserve DT node with shared DMA pool and no-map flags set so that Linux drivers requesting any DMA'able memory go through this region.

PMA node passed to the above stack:

      reserved-memory {
          #address-cells = <2>;
          #size-cells = <2>;
          ranges;

          pma_resv0 at 58000000 {
              compatible = "shared-dma-pool";
              reg = <0x0 0x58000000 0x0 0x08000000>;
              no-map;
              linux,dma-default;
          };
      };

---
platform/generic/Kconfig | 1 +
platform/generic/renesas/rzfive/rzfive.c | 21 +++++++++++++++++++++

2 files changed, 22 insertions(+)
platform/generic/Kconfig +0 -0
index 9ee9fe3..bc5c280 100644
@@ -35,6 +35,7 @@ config PLATFORM_ANDES_AE350
 

config PLATFORM_RENESAS_RZFIVE
bool "Renesas RZ/Five support"
+ select ANDES45_PMA
default n

config PLATFORM_SIFIVE_FU540

platform/generic/renesas/rzfive/rzfive.c +0 -0
index ee9c9c4..0a8c9f9 100644

platform/generic/renesas/rzfive/rzfive.c line 7

Quoted 4 lines
platform/generic/renesas/rzfive/rzfive.c +1 -0
@@ -4,10 +4,30 @@
 *
 */
 
+#include <andes45-pma.h>

This name looks inconsistent.

Quoted 6 lines
Quoted 3 lines

As the RZ/Five has the Andes AX45MP core and the PMA code will be re-used by other non-coherent Andes AX45MP platforms hence the andes45-pma.h (Also suggested by Andes maintainer)

I understand that. I meant the dash should be an underscore.

OK, I will rename it andes45_pma.h

Cheers,
Prabhakar

#10 lore raw

RFC PATCH v3 3/3 platform: generic: renesas: rzfive: Add SBI EXT to check for enabling IOCP errata

In reply to Lad Prabhakar

I/O Coherence Port (IOCP) provides an AXI interface for connecting external non-caching masters, such as DMA controllers. The accesses from IOCP are coherent with D-Caches and L2 Cache.

IOCP is a specification option and is disabled on the Renesas RZ/Five SoC due to this reason IP blocks using DMA will fail.

As a workaround for SoCs with IOCP disabled CMO needs to be handled by software. Firstly OpenSBI configures the memory region as "Memory, Non-cacheable, Bufferable" and passes this region as a global shared dma pool as a DT node. With DMA_GLOBAL_POOL enabled all DMA allocations happen from this region and synchronization callbacks are implemented to synchronize when doing DMA transactions.

RENESAS_RZFIVE_SBI_EXT_IOCP_SW_WORKAROUND SBI EXT checks if the IOCP errata should be applied to handle cache management.

---
 platform/generic/renesas/rzfive/rzfive.c | 69 ++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
platform/generic/renesas/rzfive/rzfive.c +69 -0
index 0a8c9f9..627df09 100644
@@ -9,6 +9,34 @@
 #include <sbi/sbi_domain.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 
+#define RENESAS_RZFIVE_SBI_EXT_IOCP_SW_WORKAROUND	0
+
+/* AX45MP registers */
+#define AX45MP_CSR_MICM_CFG			0xfc0
+#define AX45MP_CSR_MDCM_CFG			0xfc1
+#define AX45MP_CSR_MMSC_CFG			0xfc2
+#define AX45MP_CSR_MCACHE_CTL			0x7ca
+
+/* AX45MP register bit offsets and masks */
+#define AX45MP_MISA_20_OFFSET			20
+#define AX45MP_MISA_20_MASK			(0x1 << AX45MP_MISA_20_OFFSET)
+
+#define AX45MP_MICM_CFG_ISZ_OFFSET		6
+#define AX45MP_MICM_CFG_ISZ_MASK		(0x7  << AX45MP_MICM_CFG_ISZ_OFFSET)
+
+#define AX45MP_MDCM_CFG_DSZ_OFFSET		6
+#define AX45MP_MDCM_CFG_DSZ_MASK		(0x7  << AX45MP_MDCM_CFG_DSZ_OFFSET)
+
+#define AX45MP_MMSC_CFG_CCTLCSR_OFFSET		16
+#define AX45MP_MMSC_CFG_CCTLCSR_MASK		(0x1 << AX45MP_MMSC_CFG_CCTLCSR_OFFSET)
+#define AX45MP_MMSC_IOCP_OFFSET			47
+#define AX45MP_MMSC_IOCP_MASK			(0x1ULL << AX45MP_MMSC_IOCP_OFFSET)
+
+#define AX45MP_MCACHE_CTL_CCTL_SUEN_OFFSET	8
+#define AX45MP_MCACHE_CTL_CCTL_SUEN_MASK	(0x1 << AX45MP_MCACHE_CTL_CCTL_SUEN_OFFSET)
+
+#define ANDESTECH_SBI_EXT_ANDES			0x900031e
+
 static const struct andes45_pma_region renesas_rzfive_pma_regions[] = {
 	{
 		.pa = 0x58000000,
@@ -28,6 +56,46 @@ static int renesas_rzfive_final_init(bool cold_boot, const struct fdt_match *mat
 					 array_size(renesas_rzfive_pma_regions));
 }
 
+static bool renesas_rzfive_cpu_cache_controlable(void)
+{
+	return (((csr_read(AX45MP_CSR_MICM_CFG) & AX45MP_MICM_CFG_ISZ_MASK) ||
+		 (csr_read(AX45MP_CSR_MDCM_CFG) & AX45MP_MDCM_CFG_DSZ_MASK)) &&
+		(csr_read(CSR_MISA) & AX45MP_MISA_20_MASK) &&
+		(csr_read(AX45MP_CSR_MMSC_CFG) & AX45MP_MMSC_CFG_CCTLCSR_MASK) &&
+		(csr_read(AX45MP_CSR_MCACHE_CTL) & AX45MP_MCACHE_CTL_CCTL_SUEN_MASK));
+}
+
+static bool renesas_rzfive_cpu_iocp_disabled(void)
+{
+	return (csr_read(AX45MP_CSR_MMSC_CFG) & AX45MP_MMSC_IOCP_MASK) ? false : true;
+}
+
+static bool renesas_rzfive_apply_iocp_sw_workaround(void)
+{
+	return renesas_rzfive_cpu_cache_controlable() & renesas_rzfive_cpu_iocp_disabled();
+}
+
+static int renesas_rzfive_vendor_ext_provider(long extid, long funcid,
+					      const struct sbi_trap_regs *regs,
+					      unsigned long *out_value,
+					      struct sbi_trap_info *out_trap,
+					      const struct fdt_match *match)
+{
+	if (extid != ANDESTECH_SBI_EXT_ANDES)
+		return SBI_EINVAL;
+
+	switch (funcid) {
+	case RENESAS_RZFIVE_SBI_EXT_IOCP_SW_WORKAROUND:
+		*out_value = renesas_rzfive_apply_iocp_sw_workaround();
+		break;
+
+	default:
+		break;
+	}
+
+	return 0;
+}
+
 int renesas_rzfive_early_init(bool cold_boot, const struct fdt_match *match)
 {
 	/*
@@ -55,4 +123,5 @@ const struct platform_override renesas_rzfive = {
 	.match_table = renesas_rzfive_match,
 	.early_init = renesas_rzfive_early_init,
 	.final_init = renesas_rzfive_final_init,
+	.vendor_ext_provider = renesas_rzfive_vendor_ext_provider,
 };
Signature · 1 line
2.17.1
#11 lore raw

RFC PATCH v3 3/3 platform: generic: renesas: rzfive: Add SBI EXT to check for enabling IOCP errata

Hi Prabhakar,

Quoted 45 lines · Lad Prabhakar

I/O Coherence Port (IOCP) provides an AXI interface for connecting external non-caching masters, such as DMA controllers. The accesses from IOCP are coherent with D-Caches and L2 Cache.

IOCP is a specification option and is disabled on the Renesas RZ/Five SoC due to this reason IP blocks using DMA will fail.

As a workaround for SoCs with IOCP disabled CMO needs to be handled by software. Firstly OpenSBI configures the memory region as "Memory, Non-cacheable, Bufferable" and passes this region as a global shared dma pool as a DT node. With DMA_GLOBAL_POOL enabled all DMA allocations happen from this region and synchronization callbacks are implemented to synchronize when doing DMA transactions.

RENESAS_RZFIVE_SBI_EXT_IOCP_SW_WORKAROUND SBI EXT checks if the IOCP errata should be applied to handle cache management.

---
 platform/generic/renesas/rzfive/rzfive.c | 69 ++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
platform/generic/renesas/rzfive/rzfive.c +15 -0
index 0a8c9f9..627df09 100644
@@ -9,6 +9,34 @@
 #include <sbi/sbi_domain.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 
+#define RENESAS_RZFIVE_SBI_EXT_IOCP_SW_WORKAROUND	0
+
+/* AX45MP registers */
+#define AX45MP_CSR_MICM_CFG			0xfc0
+#define AX45MP_CSR_MDCM_CFG			0xfc1
+#define AX45MP_CSR_MMSC_CFG			0xfc2
+#define AX45MP_CSR_MCACHE_CTL			0x7ca
+
+/* AX45MP register bit offsets and masks */
+#define AX45MP_MISA_20_OFFSET			20
+#define AX45MP_MISA_20_MASK			(0x1 << AX45MP_MISA_20_OFFSET)
+
+#define AX45MP_MICM_CFG_ISZ_OFFSET		6
+#define AX45MP_MICM_CFG_ISZ_MASK		(0x7  << AX45MP_MICM_CFG_ISZ_OFFSET)
+

platform/generic/renesas/rzfive/rzfive.c line 36

Quoted 10 lines
platform/generic/renesas/rzfive/rzfive.c +10 -0
+#define AX45MP_MDCM_CFG_DSZ_OFFSET		6
+#define AX45MP_MDCM_CFG_DSZ_MASK		(0x7  << AX45MP_MDCM_CFG_DSZ_OFFSET)
+
+#define AX45MP_MMSC_CFG_CCTLCSR_OFFSET		16
+#define AX45MP_MMSC_CFG_CCTLCSR_MASK		(0x1 << AX45MP_MMSC_CFG_CCTLCSR_OFFSET)
+#define AX45MP_MMSC_IOCP_OFFSET			47
+#define AX45MP_MMSC_IOCP_MASK			(0x1ULL << AX45MP_MMSC_IOCP_OFFSET)
+
+#define AX45MP_MCACHE_CTL_CCTL_SUEN_OFFSET	8
+#define AX45MP_MCACHE_CTL_CCTL_SUEN_MASK	(0x1 << AX45MP_MCACHE_CTL_CCTL_SUEN_OFFSET)

Could you move these CSR to platform/generic/include/andes/andes45.h which is recently merged? Thanks.

Quoted 27 lines
platform/generic/renesas/rzfive/rzfive.c +20 -0
+
+#define ANDESTECH_SBI_EXT_ANDES			0x900031e
+
 static const struct andes45_pma_region renesas_rzfive_pma_regions[] = {
 	{
 		.pa = 0x58000000,
@@ -28,6 +56,46 @@ static int renesas_rzfive_final_init(bool cold_boot, const struct fdt_match *mat
 					 array_size(renesas_rzfive_pma_regions));
 }
 
+static bool renesas_rzfive_cpu_cache_controlable(void)
+{
+	return (((csr_read(AX45MP_CSR_MICM_CFG) & AX45MP_MICM_CFG_ISZ_MASK) ||
+		 (csr_read(AX45MP_CSR_MDCM_CFG) & AX45MP_MDCM_CFG_DSZ_MASK)) &&
+		(csr_read(CSR_MISA) & AX45MP_MISA_20_MASK) &&
+		(csr_read(AX45MP_CSR_MMSC_CFG) & AX45MP_MMSC_CFG_CCTLCSR_MASK) &&
+		(csr_read(AX45MP_CSR_MCACHE_CTL) & AX45MP_MCACHE_CTL_CCTL_SUEN_MASK));
+}
+
+static bool renesas_rzfive_cpu_iocp_disabled(void)
+{
+	return (csr_read(AX45MP_CSR_MMSC_CFG) & AX45MP_MMSC_IOCP_MASK) ? false : true;
+}
+
+static bool renesas_rzfive_apply_iocp_sw_workaround(void)
+{
+	return renesas_rzfive_cpu_cache_controlable() & renesas_rzfive_cpu_iocp_disabled();

platform/generic/renesas/rzfive/rzfive.c static int renesas_rzfive_final_init(bool cold_boot, const struct fdt_match *mat · line 85

Quoted 10 lines
platform/generic/renesas/rzfive/rzfive.c +10 -0
+}
+
+static int renesas_rzfive_vendor_ext_provider(long extid, long funcid,
+					      const struct sbi_trap_regs *regs,
+					      unsigned long *out_value,
+					      struct sbi_trap_info *out_trap,
+					      const struct fdt_match *match)
+{
+	if (extid != ANDESTECH_SBI_EXT_ANDES)
+		return SBI_EINVAL;

This causes compilation error without including sbi/sbi_error.h.

Regards,
Peter Lin

#12 lore raw

RFC PATCH v3 3/3 platform: generic: renesas: rzfive: Add SBI EXT to check for enabling IOCP errata

Hi Yu-Chien,

Thank you for the review.

Quoted 54 lines · Yu-Chien Peter Lin

Hi Prabhakar,

Quoted 50 lines · Lad Prabhakar

I/O Coherence Port (IOCP) provides an AXI interface for connecting external non-caching masters, such as DMA controllers. The accesses from IOCP are coherent with D-Caches and L2 Cache.

IOCP is a specification option and is disabled on the Renesas RZ/Five SoC due to this reason IP blocks using DMA will fail.

As a workaround for SoCs with IOCP disabled CMO needs to be handled by software. Firstly OpenSBI configures the memory region as "Memory, Non-cacheable, Bufferable" and passes this region as a global shared dma pool as a DT node. With DMA_GLOBAL_POOL enabled all DMA allocations happen from this region and synchronization callbacks are implemented to synchronize when doing DMA transactions.

RENESAS_RZFIVE_SBI_EXT_IOCP_SW_WORKAROUND SBI EXT checks if the IOCP errata should be applied to handle cache management.

---
 platform/generic/renesas/rzfive/rzfive.c | 69 ++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
platform/generic/renesas/rzfive/rzfive.c +20 -0
index 0a8c9f9..627df09 100644
@@ -9,6 +9,34 @@
 #include <sbi/sbi_domain.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 
+#define RENESAS_RZFIVE_SBI_EXT_IOCP_SW_WORKAROUND    0
+
+/* AX45MP registers */
+#define AX45MP_CSR_MICM_CFG                  0xfc0
+#define AX45MP_CSR_MDCM_CFG                  0xfc1
+#define AX45MP_CSR_MMSC_CFG                  0xfc2
+#define AX45MP_CSR_MCACHE_CTL                        0x7ca
+
+/* AX45MP register bit offsets and masks */
+#define AX45MP_MISA_20_OFFSET                        20
+#define AX45MP_MISA_20_MASK                  (0x1 << AX45MP_MISA_20_OFFSET)
+
+#define AX45MP_MICM_CFG_ISZ_OFFSET           6
+#define AX45MP_MICM_CFG_ISZ_MASK             (0x7  << AX45MP_MICM_CFG_ISZ_OFFSET)
+
+#define AX45MP_MDCM_CFG_DSZ_OFFSET           6
+#define AX45MP_MDCM_CFG_DSZ_MASK             (0x7  << AX45MP_MDCM_CFG_DSZ_OFFSET)
+
+#define AX45MP_MMSC_CFG_CCTLCSR_OFFSET               16
+#define AX45MP_MMSC_CFG_CCTLCSR_MASK         (0x1 << AX45MP_MMSC_CFG_CCTLCSR_OFFSET)
Quoted 9 lines

platform/generic/renesas/rzfive/rzfive.c line 36

Quoted 5 lines
platform/generic/renesas/rzfive/rzfive.c +5 -0
+#define AX45MP_MMSC_IOCP_OFFSET                      47
+#define AX45MP_MMSC_IOCP_MASK                        (0x1ULL << AX45MP_MMSC_IOCP_OFFSET)
+
+#define AX45MP_MCACHE_CTL_CCTL_SUEN_OFFSET   8
+#define AX45MP_MCACHE_CTL_CCTL_SUEN_MASK     (0x1 << AX45MP_MCACHE_CTL_CCTL_SUEN_OFFSET)

Could you move these CSR to platform/generic/include/andes/andes45.h which is recently merged? Thanks.

Sure will do.

Quoted 31 lines
Quoted 31 lines
platform/generic/renesas/rzfive/rzfive.c +24 -0
+
+#define ANDESTECH_SBI_EXT_ANDES                      0x900031e
+
 static const struct andes45_pma_region renesas_rzfive_pma_regions[] = {
      {
              .pa = 0x58000000,
@@ -28,6 +56,46 @@ static int renesas_rzfive_final_init(bool cold_boot, const struct fdt_match *mat
                                       array_size(renesas_rzfive_pma_regions));
 }
 
+static bool renesas_rzfive_cpu_cache_controlable(void)
+{
+     return (((csr_read(AX45MP_CSR_MICM_CFG) & AX45MP_MICM_CFG_ISZ_MASK) ||
+              (csr_read(AX45MP_CSR_MDCM_CFG) & AX45MP_MDCM_CFG_DSZ_MASK)) &&
+             (csr_read(CSR_MISA) & AX45MP_MISA_20_MASK) &&
+             (csr_read(AX45MP_CSR_MMSC_CFG) & AX45MP_MMSC_CFG_CCTLCSR_MASK) &&
+             (csr_read(AX45MP_CSR_MCACHE_CTL) & AX45MP_MCACHE_CTL_CCTL_SUEN_MASK));
+}
+
+static bool renesas_rzfive_cpu_iocp_disabled(void)
+{
+     return (csr_read(AX45MP_CSR_MMSC_CFG) & AX45MP_MMSC_IOCP_MASK) ? false : true;
+}
+
+static bool renesas_rzfive_apply_iocp_sw_workaround(void)
+{
+     return renesas_rzfive_cpu_cache_controlable() & renesas_rzfive_cpu_iocp_disabled();
+}
+
+static int renesas_rzfive_vendor_ext_provider(long extid, long funcid,
+                                           const struct sbi_trap_regs *regs,
Quoted 9 lines

platform/generic/renesas/rzfive/rzfive.c static int renesas_rzfive_final_init(bool cold_boot, const struct fdt_match *mat · line 85

Quoted 6 lines
platform/generic/renesas/rzfive/rzfive.c +6 -0
+                                           unsigned long *out_value,
+                                           struct sbi_trap_info *out_trap,
+                                           const struct fdt_match *match)
+{
+     if (extid != ANDESTECH_SBI_EXT_ANDES)
+             return SBI_EINVAL;

This causes compilation error without including sbi/sbi_error.h.

Oops. I had a follow up patch which added this and I never hit this issue. I will fix it.

Cheers,
Prabhakar

#13 lore raw

RFC PATCH v3 3/3 platform: generic: renesas: rzfive: Add SBI EXT to check for enabling IOCP errata

In reply to Lad Prabhakar

Hi Anup,

Quoted 23 lines · Lad Prabhakar

I/O Coherence Port (IOCP) provides an AXI interface for connecting external non-caching masters, such as DMA controllers. The accesses from IOCP are coherent with D-Caches and L2 Cache.

IOCP is a specification option and is disabled on the Renesas RZ/Five SoC due to this reason IP blocks using DMA will fail.

As a workaround for SoCs with IOCP disabled CMO needs to be handled by software. Firstly OpenSBI configures the memory region as "Memory, Non-cacheable, Bufferable" and passes this region as a global shared dma pool as a DT node. With DMA_GLOBAL_POOL enabled all DMA allocations happen from this region and synchronization callbacks are implemented to synchronize when doing DMA transactions.

RENESAS_RZFIVE_SBI_EXT_IOCP_SW_WORKAROUND SBI EXT checks if the IOCP errata should be applied to handle cache management.

---
 platform/generic/renesas/rzfive/rzfive.c | 69 ++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

<snip>

platform/generic/renesas/rzfive/rzfive.c static int renesas_rzfive_final_init(bool cold_boot, const struct fdt_match *mat · line 84

Quoted 8 lines
platform/generic/renesas/rzfive/rzfive.c +8 -0
+
+static int renesas_rzfive_vendor_ext_provider(long extid, long funcid,
+                                             const struct sbi_trap_regs *regs,
+                                             unsigned long *out_value,
+                                             struct sbi_trap_info *out_trap,
+                                             const struct fdt_match *match)
+{
+       if (extid != ANDESTECH_SBI_EXT_ANDES)

Should we check extid here is this OK? Is returning SBI_EINVAL in case of extid mismatch is ok or should we panic here?

platform/generic/renesas/rzfive/rzfive.c static int renesas_rzfive_final_init(bool cold_boot, const struct fdt_match *mat · line 92

Quoted 8 lines
platform/generic/renesas/rzfive/rzfive.c +8 -0
+               return SBI_EINVAL;
+
+       switch (funcid) {
+       case RENESAS_RZFIVE_SBI_EXT_IOCP_SW_WORKAROUND:
+               *out_value = renesas_rzfive_apply_iocp_sw_workaround();
+               break;
+
+       default:

Is this a correct behavior or should we do a panic here?

Cheers,
Prabhakar