1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Andes Technology Corporation
10 #include <asm/cache.h>
11 #include <dm/uclass-internal.h>
15 #ifdef CONFIG_RISCV_NDS_CACHE
16 #if CONFIG_IS_ENABLED(RISCV_MMODE)
18 #define CCTL_REG_MCCTLCOMMAND_NUM 0x7cc
20 /* D-cache operation */
21 #define CCTL_L1D_WBINVAL_ALL 6
25 #ifdef CONFIG_V5L2_CACHE
26 static void _cache_enable(void)
28 struct udevice *dev = NULL;
30 uclass_find_first_device(UCLASS_CACHE, &dev);
36 static void _cache_disable(void)
38 struct udevice *dev = NULL;
40 uclass_find_first_device(UCLASS_CACHE, &dev);
47 void flush_dcache_all(void)
49 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
50 #ifdef CONFIG_RISCV_NDS_CACHE
51 #if CONFIG_IS_ENABLED(RISCV_MMODE)
52 csr_write(CCTL_REG_MCCTLCOMMAND_NUM, CCTL_L1D_WBINVAL_ALL);
58 void flush_dcache_range(unsigned long start, unsigned long end)
63 void invalidate_dcache_range(unsigned long start, unsigned long end)
68 void icache_enable(void)
70 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
71 #ifdef CONFIG_RISCV_NDS_CACHE
72 #if CONFIG_IS_ENABLED(RISCV_MMODE)
74 "csrr t1, mcache_ctl\n\t"
76 "csrw mcache_ctl, t0\n\t"
83 void icache_disable(void)
85 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
86 #ifdef CONFIG_RISCV_NDS_CACHE
87 #if CONFIG_IS_ENABLED(RISCV_MMODE)
90 "csrr t1, mcache_ctl\n\t"
91 "andi t0, t1, ~0x1\n\t"
92 "csrw mcache_ctl, t0\n\t"
99 void dcache_enable(void)
101 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
102 #ifdef CONFIG_RISCV_NDS_CACHE
103 #if CONFIG_IS_ENABLED(RISCV_MMODE)
105 "csrr t1, mcache_ctl\n\t"
106 "ori t0, t1, 0x2\n\t"
107 "csrw mcache_ctl, t0\n\t"
110 #ifdef CONFIG_V5L2_CACHE
117 void dcache_disable(void)
119 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
120 #ifdef CONFIG_RISCV_NDS_CACHE
121 #if CONFIG_IS_ENABLED(RISCV_MMODE)
122 csr_write(CCTL_REG_MCCTLCOMMAND_NUM, CCTL_L1D_WBINVAL_ALL);
124 "csrr t1, mcache_ctl\n\t"
125 "andi t0, t1, ~0x2\n\t"
126 "csrw mcache_ctl, t0\n\t"
129 #ifdef CONFIG_V5L2_CACHE
136 int icache_status(void)
140 #ifdef CONFIG_RISCV_NDS_CACHE
141 #if CONFIG_IS_ENABLED(RISCV_MMODE)
143 "csrr t1, mcache_ctl\n\t"
144 "andi %0, t1, 0x01\n\t"
155 int dcache_status(void)
159 #ifdef CONFIG_RISCV_NDS_CACHE
160 #if CONFIG_IS_ENABLED(RISCV_MMODE)
162 "csrr t1, mcache_ctl\n\t"
163 "andi %0, t1, 0x02\n\t"