]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
riscv: cache: Implement dcache for cv1800b
authorKongyang Liu <seashell11234455@gmail.com>
Sat, 9 Mar 2024 16:54:57 +0000 (00:54 +0800)
committerLeo Yu-Chi Liang <ycliang@andestech.com>
Tue, 9 Apr 2024 03:30:02 +0000 (11:30 +0800)
Add dcache operations invalidate_dcache_range and flush_dcache_range for
cv1800b.

Signed-off-by: Kongyang Liu <seashell11234455@gmail.com>
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
arch/riscv/cpu/cv1800b/Makefile
arch/riscv/cpu/cv1800b/cache.c [new file with mode: 0644]

index da12e0f64e1b8b6c13abafc89633f626c5ff739d..95beb34b51af76b41c53ef513f5b3a984fdc1a42 100644 (file)
@@ -4,3 +4,4 @@
 
 obj-y += dram.o
 obj-y += cpu.o
+obj-y += cache.o
diff --git a/arch/riscv/cpu/cv1800b/cache.c b/arch/riscv/cpu/cv1800b/cache.c
new file mode 100644 (file)
index 0000000..b8051e2
--- /dev/null
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>
+ */
+
+#include <cpu_func.h>
+
+/*
+ * dcache.ipa rs1 (invalidate)
+ * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
+ *   0000001    01010      rs1       000      00000  0001011
+ *
+ * dcache.cpa rs1 (clean)
+ * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
+ *   0000001    01001      rs1       000      00000  0001011
+ *
+ * dcache.cipa rs1 (clean then invalidate)
+ * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
+ *   0000001    01011      rs1       000      00000  0001011
+ *
+ * sync.s
+ * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
+ *   0000000    11001     00000      000      00000  0001011
+ */
+#define DCACHE_IPA_A0  ".long 0x02a5000b"
+#define DCACHE_CPA_A0  ".long 0x0295000b"
+#define DCACHE_CIPA_A0 ".long 0x02b5000b"
+
+#define SYNC_S         ".long 0x0190000b"
+
+void invalidate_dcache_range(unsigned long start, unsigned long end)
+{
+       register unsigned long i asm("a0") = start & ~(CONFIG_SYS_CACHELINE_SIZE - 1);
+       for (; i < end; i += CONFIG_SYS_CACHELINE_SIZE)
+               __asm__ __volatile__(DCACHE_IPA_A0);
+       __asm__ __volatile__(SYNC_S);
+}
+
+void flush_dcache_range(unsigned long start, unsigned long end)
+{
+       register unsigned long i asm("a0") = start & ~(CONFIG_SYS_CACHELINE_SIZE - 1);
+       for (; i < end; i += CONFIG_SYS_CACHELINE_SIZE)
+               __asm__ __volatile__(DCACHE_CPA_A0);
+       __asm__ __volatile__(SYNC_S);
+}