Skip to contentSkip to conversation

andes: csr.h: Clean up CSR definition

PATCH Superseded Leo Yu-Chi Liang 1 participant 5 messages Dec 25, 2023 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 andes: csr.h: Clean up CSR definition

---
 arch/riscv/include/asm/arch-andes/csr.h | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
arch/riscv/include/asm/arch-andes/csr.h +8 -11
index 393d51c6dd..93aa8b2343 100644
@@ -15,17 +15,14 @@
 #define CSR_MARCHID 0xf12
 #define CSR_MCCTLCOMMAND 0x7cc
 
-#define MCACHE_CTL_IC_EN_OFFSET 0
-#define MCACHE_CTL_DC_EN_OFFSET 1
-#define MCACHE_CTL_CCTL_SUEN_OFFSET 8
-#define MCACHE_CTL_DC_COHEN_OFFSET 19
-#define MCACHE_CTL_DC_COHSTA_OFFSET 20
-
-#define MCACHE_CTL_IC_EN BIT(MCACHE_CTL_IC_EN_OFFSET)
-#define MCACHE_CTL_DC_EN BIT(MCACHE_CTL_DC_EN_OFFSET)
-#define MCACHE_CTL_CCTL_SUEN BIT(MCACHE_CTL_CCTL_SUEN_OFFSET)
-#define MCACHE_CTL_DC_COHEN BIT(MCACHE_CTL_DC_COHEN_OFFSET)
-#define MCACHE_CTL_DC_COHSTA BIT(MCACHE_CTL_DC_COHSTA_OFFSET)
+/* mcache_ctl register */
+
+#define MCACHE_CTL_IC_EN		BIT(0)
+#define MCACHE_CTL_DC_EN		BIT(1)
+#define MCACHE_CTL_CCTL_SUEN		BIT(8)
+#define MCACHE_CTL_DC_COHEN		BIT(19)
+#define MCACHE_CTL_DC_COHSTA		BIT(20)
+
 
 #define CCTL_L1D_WBINVAL_ALL 6
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/5 andes: ae350: Implement cache switch via Kconfig

Kconfig provides SYS_[I|D]CACHE_OFF config options to switch off caches. Implement the corresponding options.

---
 arch/riscv/cpu/andesv5/cpu.c  | 9 +++++++--
 board/AndesTech/ae350/ae350.c | 3 ++-
 2 files changed, 9 insertions(+), 3 deletions(-)
arch/riscv/cpu/andesv5/cpu.c +7 -2
index 63bc24cdfc..50cd31905d 100644
@@ -32,8 +32,13 @@ void harts_early_init(void)
 	if (CONFIG_IS_ENABLED(RISCV_MMODE)) {
 		unsigned long mcache_ctl_val = csr_read(CSR_MCACHE_CTL);
 
-		mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_IC_EN |
-				   MCACHE_CTL_DC_EN | MCACHE_CTL_CCTL_SUEN);
+		mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_CCTL_SUEN | \
+
+	if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
+		mcache_ctl |= MCACHE_CTL_IC_EN;
+
+	if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) {
+		mcache_ctl |= MCACHE_CTL_DC_EN;
 
 		csr_write(CSR_MCACHE_CTL, mcache_ctl_val);
 
board/AndesTech/ae350/ae350.c +2 -1
index 772c6bf1ee..bef9e3149e 100644
@@ -102,7 +102,8 @@ void *board_fdt_blob_setup(int *err)
 void spl_board_init()
 {
 	/* enable v5l2 cache */
-	enable_caches();
+	if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
+		enable_caches();
 }
 #endif
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/5 andes: cpu: Enable memboost feature

In reply to Leo Yu-Chi Liang

Andes CPU has memboost feature including prefetch, write-around and non-blocking load. Enable them by default.

---
 arch/riscv/cpu/andesv5/cpu.c            | 7 +++++++
 arch/riscv/include/asm/arch-andes/csr.h | 6 ++++++
 2 files changed, 13 insertions(+)
arch/riscv/cpu/andesv5/cpu.c +7 -0
index 50cd31905d..c9288dcb51 100644
@@ -31,8 +31,11 @@ void harts_early_init(void)
 	/* Enable I/D-cache in SPL */
 	if (CONFIG_IS_ENABLED(RISCV_MMODE)) {
 		unsigned long mcache_ctl_val = csr_read(CSR_MCACHE_CTL);
+		unsigned long mmisc_ctl_val = csr_read(CSR_MMISC_CTL);
 
 		mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_CCTL_SUEN | \
+				MCACHE_CTL_IC_PREFETCH_EN | MCACHE_CTL_DC_PREFETCH_EN | \
+				MCACHE_CTL_DC_WAROUND_EN | MCACHE_CTL_L2C_WAROUND_EN | \
 
 	if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
 		mcache_ctl |= MCACHE_CTL_IC_EN;
@@ -51,4 +54,8 @@ void harts_early_init(void)
 			while (!(csr_read(CSR_MCACHE_CTL) & MCACHE_CTL_DC_COHSTA));
 		}
 	}
+		mmisc_ctl_val |= MMISC_CTL_NON_BLOCKING_EN;
+
+		csr_write(CSR_MMISC_CTL, mmisc_ctl_val);
+	}
 }
arch/riscv/include/asm/arch-andes/csr.h +6 -0
index 93aa8b2343..755504c3c4 100644
@@ -20,9 +20,15 @@
 #define MCACHE_CTL_IC_EN		BIT(0)
 #define MCACHE_CTL_DC_EN		BIT(1)
 #define MCACHE_CTL_CCTL_SUEN		BIT(8)
+#define MCACHE_CTL_IC_PREFETCH_EN	BIT(9)
+#define MCACHE_CTL_DC_PREFETCH_EN	BIT(10)
+#define MCACHE_CTL_DC_WAROUND_EN	BIT(13)
+#define MCACHE_CTL_L2C_WAROUND_EN	BIT(15)
 #define MCACHE_CTL_DC_COHEN		BIT(19)
 #define MCACHE_CTL_DC_COHSTA		BIT(20)
 
+/* mmisc_ctl register */
+#define MMISC_CTL_NON_BLOCKING_EN	BIT(8)
 
 #define CCTL_L1D_WBINVAL_ALL 6
 
Signature · 1 line
2.34.1
#3 lore raw

PATCH 4/5 andes: cpu: Enable cache and TLB ECC support

In reply to Leo Yu-Chi Liang

Andes CPU supports cache and TLB ECC.
Enable them by default.

---
 arch/riscv/cpu/andesv5/cpu.c            | 1 +
 arch/riscv/include/asm/arch-andes/csr.h | 3 +++
 2 files changed, 4 insertions(+)
arch/riscv/cpu/andesv5/cpu.c +1 -0
index c9288dcb51..c011c00a94 100644
@@ -36,6 +36,7 @@ void harts_early_init(void)
 		mcache_ctl_val |= (MCACHE_CTL_DC_COHEN | MCACHE_CTL_CCTL_SUEN | \
 				MCACHE_CTL_IC_PREFETCH_EN | MCACHE_CTL_DC_PREFETCH_EN | \
 				MCACHE_CTL_DC_WAROUND_EN | MCACHE_CTL_L2C_WAROUND_EN | \
+				MCACHE_CTL_IC_ECCEN | MCACHE_CTL_DC_ECCEN | MCACHE_CTL_TLB_ECCEN);
 
 	if (!CONFIG_IS_ENABLED(SYS_ICACHE_OFF))
 		mcache_ctl |= MCACHE_CTL_IC_EN;
arch/riscv/include/asm/arch-andes/csr.h +3 -0
index 755504c3c4..1a34618066 100644
@@ -19,11 +19,14 @@
 
 #define MCACHE_CTL_IC_EN		BIT(0)
 #define MCACHE_CTL_DC_EN		BIT(1)
+#define MCACHE_CTL_IC_ECCEN		BIT(3)
+#define MCACHE_CTL_DC_ECCEN		BIT(5)
 #define MCACHE_CTL_CCTL_SUEN		BIT(8)
 #define MCACHE_CTL_IC_PREFETCH_EN	BIT(9)
 #define MCACHE_CTL_DC_PREFETCH_EN	BIT(10)
 #define MCACHE_CTL_DC_WAROUND_EN	BIT(13)
 #define MCACHE_CTL_L2C_WAROUND_EN	BIT(15)
+#define MCACHE_CTL_TLB_ECCEN		BIT(18)
 #define MCACHE_CTL_DC_COHEN		BIT(19)
 #define MCACHE_CTL_DC_COHSTA		BIT(20)
 
Signature · 1 line
2.34.1
#4 lore raw

PATCH 5/5 andes: ae350: Save cpu name to env

In reply to Leo Yu-Chi Liang

Detect CPU name through marchid and then save it to env.

---
 board/AndesTech/ae350/ae350.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
board/AndesTech/ae350/ae350.c +20 -0
index bef9e3149e..9faf46d96e 100644
@@ -28,6 +28,26 @@ DECLARE_GLOBAL_DATA_PTR;
  * Miscellaneous platform dependent initializations
  */
 
+int misc_init_r(void)
+{
+    long csr_marchid = 0;
+    const long mask_64 = 0x8000;
+    const long mask_cpu = 0xff;
+    char cpu_name[10] = {};
+
+#if CONFIG_IS_ENABLED(RISCV_SMODE)
+    sbi_get_marchid(&csr_marchid);
+#elif CONFIG_IS_ENABLED(RISCV_MMODE)
+    csr_marchid = csr_read(CSR_MARCHID);
+#endif
+    if (mask_64 & csr_marchid)
+        snprintf(cpu_name, sizeof(cpu_name), "ax%lx", (mask_cpu & csr_marchid));
+    else
+        snprintf(cpu_name, sizeof(cpu_name), "a%lx", (mask_cpu & csr_marchid));
+
+    return env_set("cpu", cpu_name);
+}
+
 #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
 #define ANDES_SPL_FDT_ADDR	(CONFIG_TEXT_BASE - 0x100000)
 void spl_perform_fixups(struct spl_image_info *spl_image)
Signature · 1 line
2.34.1