1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17: 18:
19:
20: #include <basic.h>
21: #include <tk/tkernel.h>
22: #include <tk/sysdef.h>
23:
24: #define CacheLineSZ 32
25:
26: 27: 28:
29: EXPORT INT GetCacheLineSize( void )
30: {
31: return CacheLineSZ;
32: }
33:
34: 35: 36: 37: 38: 39: 40:
41: EXPORT void FlushCacheM( CONST void *laddr, INT len, UINT mode )
42: {
43: CONST VB *p, *ep;
44:
45: ep = (VB*)laddr + len;
46:
47: if ( (mode & TCM_DCACHE) != 0 ) {
48: p = (VB*)((UINT)laddr & ~(CacheLineSZ - 1));
49: while ( p < ep ) {
50:
51: Asm("mcr p15, 0, %0, cr7, c14, 1":: "r"(p));
52: p += CacheLineSZ;
53: }
54: }
55: if ( (mode & TCM_ICACHE) != 0 ) {
56: p = (VB*)((UINT)laddr & ~(CacheLineSZ - 1));
57: while ( p < ep ) {
58:
59: Asm("mcr p15, 0, %0, cr7, c5, 1":: "r"(p));
60: p += CacheLineSZ;
61: }
62: Asm("mcr p15, 0, %0, cr7, c5, 6":: "r"(0));
63: }
64: DSB();
65: }
66:
67: EXPORT void FlushCache( CONST void *laddr, INT len )
68: {
69: FlushCacheM(laddr, len, TCM_ICACHE|TCM_DCACHE);
70: }
71:
72: 73: 74: 75:
76: EXPORT ER ControlCacheM( void *laddr, INT len, UINT mode )
77: {
78: VB *p, *ep;
79:
80: if ( (mode & ~(CC_FLUSH|CC_INVALIDATE)) != 0 ) return E_PAR;
81:
82: ep = (VB*)laddr + len;
83:
84: p = (VB*)((UINT)laddr & ~(CacheLineSZ - 1));
85: while ( p < ep ) {
86: switch ( mode ) {
87: case CC_FLUSH:
88:
89: Asm("mcr p15, 0, %0, cr7, c10, 1":: "r"(p));
90: break;
91: case CC_INVALIDATE:
92:
93: Asm("mcr p15, 0, %0, cr7, c6, 1":: "r"(p));
94: break;
95: default:
96:
97: Asm("mcr p15, 0, %0, cr7, c14, 1":: "r"(p));
98: }
99:
100:
101: Asm("mcr p15, 0, %0, cr7, c5, 1":: "r"(p));
102:
103: p += CacheLineSZ;
104: }
105: Asm("mcr p15, 0, %0, cr7, c5, 6":: "r"(0));
106: DSB();
107:
108: return E_OK;
109: }