1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <common.h>
34#include <command.h>
35#include <watchdog.h>
36#include <asm/cache.h>
37
38#include <faraday/ftwdt010_wdt.h>
39
40
41
42
43
44
45
46int cleanup_before_linux(void)
47{
48 disable_interrupts();
49
50#ifdef CONFIG_MMU
51
52 icache_disable();
53 dcache_disable();
54
55
56 invalidate_icac();
57 invalidate_dcac();
58#endif
59
60 return 0;
61}
62
63int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
64{
65 disable_interrupts();
66
67
68
69
70
71
72#ifdef CONFIG_FTWDT010_WATCHDOG
73
74
75
76
77
78 ftwdt010_wdt_reset();
79 while (1)
80 ;
81#endif
82
83
84}
85
86static inline unsigned long CACHE_LINE_SIZE(enum cache_t cache)
87{
88 if (cache == ICACHE)
89 return 8 << (((GET_ICM_CFG() & ICM_CFG_MSK_ISZ) \
90 >> ICM_CFG_OFF_ISZ) - 1);
91 else
92 return 8 << (((GET_DCM_CFG() & DCM_CFG_MSK_DSZ) \
93 >> DCM_CFG_OFF_DSZ) - 1);
94}
95
96void dcache_flush_range(unsigned long start, unsigned long end)
97{
98 unsigned long line_size;
99
100 line_size = CACHE_LINE_SIZE(DCACHE);
101
102 while (end > start) {
103 __asm__ volatile ("\n\tcctl %0, L1D_VA_WB" : : "r"(start));
104 __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL" : : "r"(start));
105 start += line_size;
106 }
107}
108
109void icache_inval_range(unsigned long start, unsigned long end)
110{
111 unsigned long line_size;
112
113 line_size = CACHE_LINE_SIZE(ICACHE);
114 while (end > start) {
115 __asm__ volatile ("\n\tcctl %0, L1I_VA_INVAL" : : "r"(start));
116 start += line_size;
117 }
118}
119
120void flush_cache(unsigned long addr, unsigned long size)
121{
122 dcache_flush_range(addr, addr + size);
123 icache_inval_range(addr, addr + size);
124}
125
126void icache_enable(void)
127{
128 __asm__ __volatile__ (
129 "mfsr $p0, $mr8\n\t"
130 "ori $p0, $p0, 0x01\n\t"
131 "mtsr $p0, $mr8\n\t"
132 "isb\n\t"
133 );
134}
135
136void icache_disable(void)
137{
138 __asm__ __volatile__ (
139 "mfsr $p0, $mr8\n\t"
140 "li $p1, ~0x01\n\t"
141 "and $p0, $p0, $p1\n\t"
142 "mtsr $p0, $mr8\n\t"
143 "isb\n\t"
144 );
145}
146
147int icache_status(void)
148{
149 int ret;
150
151 __asm__ __volatile__ (
152 "mfsr $p0, $mr8\n\t"
153 "andi %0, $p0, 0x01\n\t"
154 : "=r" (ret)
155 :
156 : "memory"
157 );
158
159 return ret;
160}
161
162void dcache_enable(void)
163{
164 __asm__ __volatile__ (
165 "mfsr $p0, $mr8\n\t"
166 "ori $p0, $p0, 0x02\n\t"
167 "mtsr $p0, $mr8\n\t"
168 "isb\n\t"
169 );
170}
171
172void dcache_disable(void)
173{
174 __asm__ __volatile__ (
175 "mfsr $p0, $mr8\n\t"
176 "li $p1, ~0x02\n\t"
177 "and $p0, $p0, $p1\n\t"
178 "mtsr $p0, $mr8\n\t"
179 "isb\n\t"
180 );
181}
182
183int dcache_status(void)
184{
185 int ret;
186
187 __asm__ __volatile__ (
188 "mfsr $p0, $mr8\n\t"
189 "andi %0, $p0, 0x02\n\t"
190 : "=r" (ret)
191 :
192 : "memory"
193 );
194
195 return ret;
196}
197