blob: 228fc55f56bc9bf9667a400474d87c66e1e8d2e4 [file] [log] [blame]
Rick Chen842d5802018-11-07 09:34:06 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2017 Andes Technology Corporation
4 * Rick Chen, Andes Technology Corporation <rick@andestech.com>
5 */
6
7#include <common.h>
8
Lukas Auer6280e322019-01-04 01:37:29 +01009void flush_dcache_all(void)
10{
11 /*
12 * Andes' AX25 does not have a coherence agent. U-Boot must use data
13 * cache flush and invalidate functions to keep data in the system
14 * coherent.
15 * The implementation of the fence instruction in the AX25 flushes the
16 * data cache and is used for this purpose.
17 */
18 asm volatile ("fence" ::: "memory");
19}
20
21void flush_dcache_range(unsigned long start, unsigned long end)
22{
23 flush_dcache_all();
24}
25
26void invalidate_dcache_range(unsigned long start, unsigned long end)
27{
28 flush_dcache_all();
29}
30
Rick Chen842d5802018-11-07 09:34:06 +080031void icache_enable(void)
32{
33#ifndef CONFIG_SYS_ICACHE_OFF
Bin Meng4b284ad2018-12-12 06:12:28 -080034#ifdef CONFIG_RISCV_NDS_CACHE
Rick Chen842d5802018-11-07 09:34:06 +080035 asm volatile (
36 "csrr t1, mcache_ctl\n\t"
37 "ori t0, t1, 0x1\n\t"
38 "csrw mcache_ctl, t0\n\t"
39 );
40#endif
41#endif
42}
43
44void icache_disable(void)
45{
46#ifndef CONFIG_SYS_ICACHE_OFF
Bin Meng4b284ad2018-12-12 06:12:28 -080047#ifdef CONFIG_RISCV_NDS_CACHE
Rick Chen842d5802018-11-07 09:34:06 +080048 asm volatile (
49 "fence.i\n\t"
50 "csrr t1, mcache_ctl\n\t"
51 "andi t0, t1, ~0x1\n\t"
52 "csrw mcache_ctl, t0\n\t"
53 );
54#endif
55#endif
56}
57
58void dcache_enable(void)
59{
60#ifndef CONFIG_SYS_DCACHE_OFF
Bin Meng4b284ad2018-12-12 06:12:28 -080061#ifdef CONFIG_RISCV_NDS_CACHE
Rick Chen842d5802018-11-07 09:34:06 +080062 asm volatile (
63 "csrr t1, mcache_ctl\n\t"
64 "ori t0, t1, 0x2\n\t"
65 "csrw mcache_ctl, t0\n\t"
66 );
67#endif
68#endif
69}
70
71void dcache_disable(void)
72{
73#ifndef CONFIG_SYS_DCACHE_OFF
Bin Meng4b284ad2018-12-12 06:12:28 -080074#ifdef CONFIG_RISCV_NDS_CACHE
Rick Chen842d5802018-11-07 09:34:06 +080075 asm volatile (
76 "fence\n\t"
77 "csrr t1, mcache_ctl\n\t"
78 "andi t0, t1, ~0x2\n\t"
79 "csrw mcache_ctl, t0\n\t"
80 );
81#endif
82#endif
83}
84
85int icache_status(void)
86{
87 int ret = 0;
88
Bin Meng4b284ad2018-12-12 06:12:28 -080089#ifdef CONFIG_RISCV_NDS_CACHE
Rick Chen842d5802018-11-07 09:34:06 +080090 asm volatile (
91 "csrr t1, mcache_ctl\n\t"
92 "andi %0, t1, 0x01\n\t"
93 : "=r" (ret)
94 :
95 : "memory"
96 );
97#endif
98
99 return ret;
100}
101
102int dcache_status(void)
103{
104 int ret = 0;
105
Bin Meng4b284ad2018-12-12 06:12:28 -0800106#ifdef CONFIG_RISCV_NDS_CACHE
Rick Chen842d5802018-11-07 09:34:06 +0800107 asm volatile (
108 "csrr t1, mcache_ctl\n\t"
109 "andi %0, t1, 0x02\n\t"
110 : "=r" (ret)
111 :
112 : "memory"
113 );
114#endif
115
116 return ret;
117}