tizen 2.4 release
[kernel/u-boot-tm1.git] / arch / arm / cpu / arm926ejs / sc8800g / mmu_asm.S
1 /* ============================================================================\r
2 @\r
3 @ Enable the MMU function\r
4 @\r
5 @ @Liu Jun 2005-07-27\r
6 @ Spreadtrum Communications Inc.\r
7 @\r
8 @ NOTE:\r
9 @ 1. The ARM9 data cache must be used together with MMU, while the instruction\r
10 @    cache can be used independently.\r
11 @\r
12 @ Related Files:\r
13 @      mmu_c.c          Create the MMU page table\r
14 @\r
15 @ ============================================================================\r
16 */\r
17 \r
18 @AREA mmu_functions, CODE, READONLY\r
19 @    CODE32\r
20 \r
21 #include <config.h>\r
22 @   Initialize the MMU\r
23 @\r
24 .globl g_mmu_page_table\r
25 @    IMPORT  mmu_create_page_table\r
26 .globl MMU_EnableIDCM\r
27 .globl MMU_InvalideDCACHEALL
28 .globl MMU_InvalideICACHEALL    
29 .globl Dcache_InvalRegion
30
31 @============================================================================
32 @ Dcache_InvalRegion
33 @
34 @ PROTOTYPE
35 @   void Dcache_InvalRegion(void *addr, unsigned int length)@
36 @
37 @ steve.zhan
38 @ DESCRIPTION
39 @   Invalidate a memory region in the cache.
40 @============================================================================
41 Dcache_InvalRegion:
42     STMFD sp!, {a1-a2, lr}               @ save lr_USR and non-callee
43     ADD    r1, r0, r1                     @ End address
44     BIC    r0, r0, #0x1f                  @ Align start address
45 loop_loop:
46     CMP    r0, r1
47     MCRLT  p15, 0x0, r0, c7, c6, 0x1      @ Invalidate cache line using MVA
48     ADDLT  r0, r0, #0x20                  @ Add a cache line
49     BLT    loop_loop
50     LDMFD sp!, {a1-a2, PC}               @ restore registers    
51     
52 MMU_InvalideDCACHEALL:
53     STMFD sp!, {a1, lr}               @ save lr_USR and non-callee
54 tcv_a: 
55     MRC p15, 0, r15, c7, c14, 3          @ test clean and invalidate
56     BNE tcv_a
57     
58     MOV     r0, #0
59     MCR     p15, 0, r0, c8, c7, 0        @flush i+d-TLBs    
60
61     LDMFD sp!, {a1, PC}               @ restore registers    
62
63
64 MMU_InvalideICACHEALL:
65     STMFD   sp!, {a1-a4, lr}            @ save lr_USR and non-callee
66     
67     MOV     r0, #0    
68     MCR     p15, 0, r0, c7, c5, 0       @Invalidate(flush)the ICache
69     MCR     p15, 0, r0, c8, c5, 0       @flush ITLB only
70     NOP                                 @next few instructions may be via cache.
71     NOP
72     NOP
73     NOP
74     NOP
75
76     LDMFD   sp!, {a1-a4, PC}             @ restore registers
77     
78
79 MMU_EnableIDCM:\r
80 @ save lr_USR and non-callee\r
81         STMFD   sp!, {a1-a4, lr}               \r
82 \r
83 @   Set the MMU page table address\r
84     LDR     r2, =g_mmu_page_table\r
85     LDR     r2, [r2]\r
86     MCR     p15, 0, r2, c2, c0, 0\r
87     \r
88 @   Domain Access Control: set all domains to manager\r
89 @\r
90 @   NOTE:\r
91 @   We must set domain access before enble MMU, otherwise Bus-Error will occur!\r
92     LDR     r0, =0xFFFFFFFF\r
93     MCR     p15, 0, r0, c3, c0, 0\r
94     \r
95 @   Enable the ICache, DCache, write buffer, MMU\r
96     MRC     p15, 0, r0, c1, c0, 0\r
97     LDR     r1, =0x107D\r
98     ORR     r0, r0, r1\r
99     MCR     p15, 0, r0, c1, c0, 0 \r
100     \r
101 @   Delay for the operations to finish\r
102     NOP\r
103     NOP\r
104     NOP\r
105     NOP\r
106     NOP\r
107 \r
108 @   Return\r
109         LDMFD   sp!, {a1-a4, PC}             @ restore registers \r
110 \r
111 .globl  MMU_DisableIDCM\r
112 MMU_DisableIDCM:\r
113 \r
114 @ save lr_USR and non-callee\r
115         STMFD   sp!, {a1-a4, lr}               \r
116 \r
117 @   Disable the ICache, DCache, write buffer, MMU\r
118     MRC     p15, 0, r0, c1, c0, 0\r
119     LDR     r1, =0x1005\r
120     BIC     r0, r0, r1\r
121     ORR     r0, r0, #0x8     @Bit_7 must be one when write c1@\r
122     MCR     p15, 0, r0, c1, c0, 0\r
123 \r
124 @write back data in data cache to memory system @\r
125 tcv_loop:\r
126     MRC p15, 0, r15, c7, c14, 3 @ test clean and invalidate\r
127         BNE tcv_loop\r
128 \r
129 @   Invalidate the ICache and DCache\r
130         MOV     r0, #0\r
131     MCR     p15, 0, r0, c7, c7, 0\r
132 \r
133 @   Delay for the operations to finish\r
134     NOP\r
135     NOP\r
136     NOP\r
137 \r
138 @   Return\r
139         LDMFD   sp!, {a1-a4, PC}             @ restore registers \r
140 \r