1#include <config.h>
2#include <74xx_7xx.h>
3#include <version.h>
4
5#include <ppc_asm.tmpl>
6#include <ppc_defs.h>
7
8#include <asm/cache.h>
9#include <asm/mmu.h>
10
11#ifndef CACHE_LINE_SIZE
12# define CACHE_LINE_SIZE L1_CACHE_BYTES
13#endif
14
15
16#define LG_CACHE_LINE_SIZE 7
17
18#define LG_CACHE_LINE_SIZE 5
19
20#define LG_CACHE_LINE_SIZE 4
21
22#define LG_CACHE_LINE_SIZE 3
23#else
24
25#endif
26
27
28
29
30_GLOBAL(invalidate_l1_instruction_cache)
31 mfspr r3,PVR
32 rlwinm r3,r3,16,16,31
33 cmpi 0,r3,1
34 beqlr
35
36 mfspr r3,HID0
37 ori r3,r3,HID0_ICFI
38 mtspr HID0,r3
39 isync
40 blr
41
42
43
44
45_GLOBAL(invalidate_l1_data_cache)
46 mfspr r3,HID0
47 ori r3,r3,HID0_DCFI
48 mtspr HID0,r3
49 isync
50 blr
51
52
53
54
55_GLOBAL(flush_dcache)
56 lis r3,0
57 lis r5,CACHE_LINE_SIZE
58flush:
59 cmp 0,1,r3,r5
60 bge done
61 lwz r5,0(r3)
62 lis r5,CACHE_LINE_SIZE
63 addi r3,r3,0x4
64 b flush
65done:
66 blr
67
68
69
70
71
72
73
74_GLOBAL(flush_icache_range)
75 mfspr r5,PVR
76 rlwinm r5,r5,16,16,31
77 cmpi 0,r5,1
78 beqlr
79 li r5,CACHE_LINE_SIZE-1
80 andc r3,r3,r5
81 subf r4,r3,r4
82 add r4,r4,r5
83 srwi. r4,r4,LG_CACHE_LINE_SIZE
84 beqlr
85 mtctr r4
86 mr r6,r3
871: dcbst 0,r3
88 addi r3,r3,CACHE_LINE_SIZE
89 bdnz 1b
90 sync
91 mtctr r4
922: icbi 0,r6
93 addi r6,r6,CACHE_LINE_SIZE
94 bdnz 2b
95 sync
96 isync
97 blr
98
99
100
101
102
103
104
105_GLOBAL(clean_dcache_range)
106 li r5,CACHE_LINE_SIZE-1
107 andc r3,r3,r5
108 subf r4,r3,r4
109 add r4,r4,r5
110 srwi. r4,r4,LG_CACHE_LINE_SIZE
111 beqlr
112 mtctr r4
113
114 sync
1151: dcbst 0,r3
116 addi r3,r3,CACHE_LINE_SIZE
117 bdnz 1b
118 sync
119 blr
120
121
122
123
124
125
126
127_GLOBAL(flush_dcache_range)
128 li r5,CACHE_LINE_SIZE-1
129 andc r3,r3,r5
130 subf r4,r3,r4
131 add r4,r4,r5
132 srwi. r4,r4,LG_CACHE_LINE_SIZE
133 beqlr
134 mtctr r4
135
136 sync
1371: dcbf 0,r3
138 addi r3,r3,CACHE_LINE_SIZE
139 bdnz 1b
140 sync
141 blr
142
143
144
145
146
147
148
149
150_GLOBAL(invalidate_dcache_range)
151 li r5,CACHE_LINE_SIZE-1
152 andc r3,r3,r5
153 subf r4,r3,r4
154 add r4,r4,r5
155 srwi. r4,r4,LG_CACHE_LINE_SIZE
156 beqlr
157 mtctr r4
158
159 sync
1601: dcbi 0,r3
161 addi r3,r3,CACHE_LINE_SIZE
162 bdnz 1b
163 sync
164 blr
165
166
167
168
169
170
171
172
173
174_GLOBAL(__flush_page_to_ram)
175 mfspr r5,PVR
176 rlwinm r5,r5,16,16,31
177 cmpi 0,r5,1
178 beqlr
179 rlwinm r3,r3,0,0,19
180 li r4,4096/CACHE_LINE_SIZE
181 mtctr r4
182 mr r6,r3
1830: dcbst 0,r3
184 addi r3,r3,CACHE_LINE_SIZE
185 bdnz 0b
186 sync
187 mtctr r4
1881: icbi 0,r6
189 addi r6,r6,CACHE_LINE_SIZE
190 bdnz 1b
191 sync
192 isync
193 blr
194
195
196
197
198
199
200
201
202
203_GLOBAL(__flush_icache_page)
204 mfspr r5,PVR
205 rlwinm r5,r5,16,16,31
206 cmpi 0,r5,1
207 beqlr
208 li r4,4096/CACHE_LINE_SIZE
209 mtctr r4
2101: icbi 0,r3
211 addi r3,r3,CACHE_LINE_SIZE
212 bdnz 1b
213 sync
214 isync
215 blr
216
217
218
219
220
221
222_GLOBAL(clear_page)
223 li r0,4096/CACHE_LINE_SIZE
224 mtctr r0
2251: dcbz 0,r3
226 addi r3,r3,CACHE_LINE_SIZE
227 bdnz 1b
228 blr
229
230
231
232
233_GLOBAL(icache_enable)
234 mfspr r3, HID0
235 li r5, HID0_ICFI|HID0_ILOCK
236 andc r3, r3, r5
237 ori r3, r3, HID0_ICE
238 ori r5, r3, HID0_ICFI
239 mtspr HID0, r5
240 mtspr HID0, r3
241 isync
242 blr
243
244
245
246
247_GLOBAL(icache_disable)
248 mflr r4
249 bl invalidate_l1_instruction_cache
250 sync
251 mtlr r4
252 mfspr r3, HID0
253 li r5, 0
254 ori r5, r5, HID0_ICE
255 andc r3, r3, r5
256 mtspr HID0, r3
257 isync
258 blr
259
260
261
262
263_GLOBAL(icache_status)
264 mfspr r3, HID0
265 andi. r3, r3, HID0_ICE
266 blr
267
268
269_GLOBAL(l1dcache_enable)
270 mfspr r3, HID0
271 li r5, HID0_DCFI|HID0_DLOCK
272 andc r3, r3, r5
273 mtspr HID0, r3
274 ori r3, r3, HID0_DCE
275 ori r5, r3, HID0_DCFI
276 mtspr HID0, r5
277 mtspr HID0, r3
278 sync
279 blr
280
281
282
283
284
285_GLOBAL(dcache_enable)
286 mfspr r3, HID0
287 li r5, HID0_DCFI|HID0_DLOCK
288 andc r3, r3, r5
289 mtspr HID0, r3
290 ori r3, r3, HID0_DCE
291 ori r5, r3, HID0_DCFI
292 mtspr HID0, r5
293 mtspr HID0, r3
294 sync
295#ifdef CONFIG_SYS_L2
296 mflr r5
297 bl l2cache_enable
298 sync
299 mtlr r5
300#endif
301 blr
302
303
304
305
306
307
308
309_GLOBAL(dcache_disable)
310 mflr r4
311 bl flush_dcache
312 sync
313 mfspr r3, HID0
314 li r5, HID0_DCFI|HID0_DLOCK
315 andc r3, r3, r5
316 mtspr HID0, r3
317 li r5, HID0_DCE|HID0_DCFI
318 andc r3, r3, r5
319 mtspr HID0, r3
320 sync
321#ifdef CONFIG_SYS_L2
322 bl l2cache_disable_no_flush
323#endif
324 mtlr r4
325 blr
326
327
328
329
330_GLOBAL(dcache_status)
331 mfspr r3, HID0
332 andi. r3, r3, HID0_DCE
333 blr
334
335
336
337
338_GLOBAL(l2cache_invalidate)
339 sync
340 mfspr r3, l2cr
341 oris r3, r3, L2CR_L2I@h
342 sync
343 mtspr l2cr, r3
344 sync
345 mfspr r3, PVR
346 sync
347 rlwinm r3, r3, 16,16,31
348 cmpli 0,r3,0x8000
349 beq 0,inv_7450
350 cmpli 0,r3,0x8001
351 beq 0,inv_7450
352 cmpli 0,r3,0x8002
353 beq 0,inv_7450
354 cmpli 0,r3,0x8003
355 beq 0,inv_7450
356 cmpli 0,r3,0x8004
357 beq 0,inv_7450
358invl2:
359 mfspr r3, l2cr
360 andi. r3, r3, L2CR_L2IP
361 bne invl2
362
363 mfspr r3, l2cr
364 rlwinm r3, r3, 0, 11, 9
365 sync
366 mtspr l2cr, r3
367 sync
368 blr
369inv_7450:
370 mfspr r3, l2cr
371 andis. r3, r3, L2CR_L2I@h
372 bne inv_7450
373 blr
374
375
376
377
378
379_GLOBAL(l2cache_enable)
380 mflr r4
381 bl l2cache_invalidate
382 sync
383 lis r3, L2_ENABLE@h
384 ori r3, r3, L2_ENABLE@l
385 mtspr l2cr, r3
386 isync
387 mtlr r4
388 blr
389
390
391
392
393
394_GLOBAL(l2cache_disable)
395 mflr r4
396 bl flush_dcache
397 sync
398 mtlr r4
399l2cache_disable_no_flush:
400 lis r3, L2_INIT@h
401 ori r3, r3, L2_INIT@l
402 mtspr l2cr, r3
403 isync
404 blr
405