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#include <common.h>
28#include <command.h>
29#include <asm/processor.h>
30#include <asm/io.h>
31
32
33
34
35
36#define jump_to_P2() \
37do { \
38 unsigned long __dummy; \
39 __asm__ __volatile__( \
40 "mov.l 1f, %0\n\t" \
41 "or %1, %0\n\t" \
42 "jmp @%0\n\t" \
43 " nop\n\t" \
44 ".balign 4\n" \
45 "1: .long 2f\n" \
46 "2:" \
47 : "=&r" (__dummy) \
48 : "r" (0x20000000)); \
49} while (0)
50
51
52
53
54#define back_to_P1() \
55do { \
56 unsigned long __dummy; \
57 __asm__ __volatile__( \
58 "nop;nop;nop;nop;nop;nop;nop\n\t" \
59 "mov.l 1f, %0\n\t" \
60 "jmp @%0\n\t" \
61 " nop\n\t" \
62 ".balign 4\n" \
63 "1: .long 2f\n" \
64 "2:" \
65 : "=&r" (__dummy)); \
66} while (0)
67
68#define CACHE_VALID 1
69#define CACHE_UPDATED 2
70
71static inline void cache_wback_all(void)
72{
73 unsigned long addr, data, i, j;
74
75 jump_to_P2();
76 for (i = 0; i < CACHE_OC_NUM_ENTRIES; i++) {
77 for (j = 0; j < CACHE_OC_NUM_WAYS; j++) {
78 addr = CACHE_OC_ADDRESS_ARRAY
79 | (j << CACHE_OC_WAY_SHIFT)
80 | (i << CACHE_OC_ENTRY_SHIFT);
81 data = inl(addr);
82 if (data & CACHE_UPDATED) {
83 data &= ~CACHE_UPDATED;
84 outl(data, addr);
85 }
86 }
87 }
88 back_to_P1();
89}
90
91
92#define CACHE_ENABLE 0
93#define CACHE_DISABLE 1
94
95int cache_control(unsigned int cmd)
96{
97 unsigned long ccr;
98
99 jump_to_P2();
100 ccr = inl(CCR);
101
102 if (ccr & CCR_CACHE_ENABLE)
103 cache_wback_all();
104
105 if (cmd == CACHE_DISABLE)
106 outl(CCR_CACHE_STOP, CCR);
107 else
108 outl(CCR_CACHE_INIT, CCR);
109 back_to_P1();
110
111 return 0;
112}
113