1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Andes Technology Corporation
4 * Rick Chen, Andes Technology Corporation <rick@andestech.com>
10 #include <dm/uclass-internal.h>
14 #ifdef CONFIG_RISCV_NDS_CACHE
15 #if CONFIG_IS_ENABLED(RISCV_MMODE)
17 #define CCTL_REG_MCCTLCOMMAND_NUM 0x7cc
19 /* D-cache operation */
20 #define CCTL_L1D_WBINVAL_ALL 6
24 #ifdef CONFIG_V5L2_CACHE
25 static void _cache_enable(void)
27 struct udevice
*dev
= NULL
;
29 uclass_find_first_device(UCLASS_CACHE
, &dev
);
35 static void _cache_disable(void)
37 struct udevice
*dev
= NULL
;
39 uclass_find_first_device(UCLASS_CACHE
, &dev
);
46 void flush_dcache_all(void)
48 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
49 #ifdef CONFIG_RISCV_NDS_CACHE
50 #if CONFIG_IS_ENABLED(RISCV_MMODE)
51 csr_write(CCTL_REG_MCCTLCOMMAND_NUM
, CCTL_L1D_WBINVAL_ALL
);
57 void flush_dcache_range(unsigned long start
, unsigned long end
)
62 void invalidate_dcache_range(unsigned long start
, unsigned long end
)
67 void icache_enable(void)
69 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
70 #ifdef CONFIG_RISCV_NDS_CACHE
71 #if CONFIG_IS_ENABLED(RISCV_MMODE)
73 "csrr t1, mcache_ctl\n\t"
75 "csrw mcache_ctl, t0\n\t"
82 void icache_disable(void)
84 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
85 #ifdef CONFIG_RISCV_NDS_CACHE
86 #if CONFIG_IS_ENABLED(RISCV_MMODE)
89 "csrr t1, mcache_ctl\n\t"
90 "andi t0, t1, ~0x1\n\t"
91 "csrw mcache_ctl, t0\n\t"
98 void dcache_enable(void)
100 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
101 #ifdef CONFIG_RISCV_NDS_CACHE
102 #if CONFIG_IS_ENABLED(RISCV_MMODE)
104 "csrr t1, mcache_ctl\n\t"
105 "ori t0, t1, 0x2\n\t"
106 "csrw mcache_ctl, t0\n\t"
109 #ifdef CONFIG_V5L2_CACHE
116 void dcache_disable(void)
118 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
119 #ifdef CONFIG_RISCV_NDS_CACHE
120 #if CONFIG_IS_ENABLED(RISCV_MMODE)
121 csr_write(CCTL_REG_MCCTLCOMMAND_NUM
, CCTL_L1D_WBINVAL_ALL
);
123 "csrr t1, mcache_ctl\n\t"
124 "andi t0, t1, ~0x2\n\t"
125 "csrw mcache_ctl, t0\n\t"
128 #ifdef CONFIG_V5L2_CACHE
135 int icache_status(void)
139 #ifdef CONFIG_RISCV_NDS_CACHE
140 #if CONFIG_IS_ENABLED(RISCV_MMODE)
142 "csrr t1, mcache_ctl\n\t"
143 "andi %0, t1, 0x01\n\t"
154 int dcache_status(void)
158 #ifdef CONFIG_RISCV_NDS_CACHE
159 #if CONFIG_IS_ENABLED(RISCV_MMODE)
161 "csrr t1, mcache_ctl\n\t"
162 "andi %0, t1, 0x02\n\t"