diff options
Diffstat (limited to 'firmware/target/arm/s3c2440/gigabeat-fx/mmu-meg-fx.c')
-rw-r--r-- | firmware/target/arm/s3c2440/gigabeat-fx/mmu-meg-fx.c | 235 |
1 files changed, 0 insertions, 235 deletions
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/mmu-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/mmu-meg-fx.c deleted file mode 100644 index c47c1330bc..0000000000 --- a/firmware/target/arm/s3c2440/gigabeat-fx/mmu-meg-fx.c +++ /dev/null | |||
@@ -1,235 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include "s3c2440.h" | ||
3 | #include "mmu-meg-fx.h" | ||
4 | #include "panic.h" | ||
5 | |||
6 | static void enable_mmu(void); | ||
7 | static void set_ttb(void); | ||
8 | static void set_page_tables(void); | ||
9 | static void map_section(unsigned int pa, unsigned int va, int mb, int cache_flags); | ||
10 | |||
11 | #define SECTION_ADDRESS_MASK (-1 << 20) | ||
12 | #define CACHE_ALL (1 << 3 | 1 << 2 ) | ||
13 | #define CACHE_NONE 0 | ||
14 | #define BUFFERED (1 << 2) | ||
15 | #define MB (1 << 20) | ||
16 | |||
17 | void memory_init(void) { | ||
18 | set_ttb(); | ||
19 | set_page_tables(); | ||
20 | enable_mmu(); | ||
21 | } | ||
22 | |||
23 | unsigned int* ttb_base = (unsigned int *) TTB_BASE; | ||
24 | const int ttb_size = 4096; | ||
25 | |||
26 | void set_ttb() { | ||
27 | int i; | ||
28 | int* ttbPtr; | ||
29 | int domain_access; | ||
30 | |||
31 | /* must be 16Kb (0x4000) aligned */ | ||
32 | ttb_base = (int*) TTB_BASE; | ||
33 | for (i=0; i<ttb_size; i++,ttbPtr++) | ||
34 | ttbPtr = 0; | ||
35 | asm volatile("mcr p15, 0, %0, c2, c0, 0" : : "r" (ttb_base)); | ||
36 | |||
37 | /* set domain D0 to "client" permission access */ | ||
38 | |||
39 | domain_access = 3; | ||
40 | asm volatile("mcr p15, 0, %0, c3, c0, 0" : : "r" (domain_access)); | ||
41 | |||
42 | } | ||
43 | |||
44 | void set_page_tables() { | ||
45 | |||
46 | map_section(0, 0, 0x1000, CACHE_NONE); /* map every memory region to itself */ | ||
47 | map_section(0x30000000, 0, 32, CACHE_ALL); /* map RAM to 0 and enable caching for it */ | ||
48 | map_section((int)FRAME, (int)FRAME, 1, BUFFERED); /* enable buffered writing for the framebuffer */ | ||
49 | } | ||
50 | |||
51 | void map_section(unsigned int pa, unsigned int va, int mb, int cache_flags) { | ||
52 | unsigned int* ttbPtr; | ||
53 | int i; | ||
54 | int section_no; | ||
55 | |||
56 | section_no = va >> 20; /* sections are 1Mb size */ | ||
57 | ttbPtr = ttb_base + section_no; | ||
58 | pa &= SECTION_ADDRESS_MASK; /* align to 1Mb */ | ||
59 | for(i=0; i<mb; i++, pa += MB) { | ||
60 | *(ttbPtr + i) = | ||
61 | pa | | ||
62 | 1 << 10 | /* superuser - r/w, user - no access */ | ||
63 | 0 << 5 | /* domain 0th */ | ||
64 | 1 << 4 | /* should be "1" */ | ||
65 | cache_flags | | ||
66 | 1 << 1; /* Section signature */ | ||
67 | } | ||
68 | } | ||
69 | |||
70 | static void enable_mmu(void) { | ||
71 | int regread; | ||
72 | |||
73 | asm volatile( | ||
74 | "MRC p15, 0, %r0, c1, c0, 0\n" /* Read reg1, control register */ | ||
75 | : /* outputs */ | ||
76 | "=r"(regread) | ||
77 | : /* inputs */ | ||
78 | : /* clobbers */ | ||
79 | "r0" | ||
80 | ); | ||
81 | |||
82 | if ( !(regread & 0x04) || !(regread & 0x00001000) ) /* Was the ICache or DCache Enabled? */ | ||
83 | clean_dcache(); /* If so we need to clean the DCache before invalidating below */ | ||
84 | |||
85 | asm volatile("mov r0, #0\n" | ||
86 | "mcr p15, 0, r0, c8, c7, 0\n" /* invalidate TLB */ | ||
87 | |||
88 | "mcr p15, 0, r0, c7, c7,0\n" /* invalidate both icache and dcache */ | ||
89 | |||
90 | "mrc p15, 0, r0, c1, c0, 0\n" | ||
91 | "orr r0, r0, #1<<0\n" /* enable mmu bit, icache and dcache */ | ||
92 | "orr r0, r0, #1<<2\n" /* enable dcache */ | ||
93 | "orr r0, r0, #1<<12\n" /* enable icache */ | ||
94 | "mcr p15, 0, r0, c1, c0, 0" : : : "r0"); | ||
95 | asm volatile("nop \n nop \n nop \n nop"); | ||
96 | } | ||
97 | |||
98 | /* Invalidate DCache for this range */ | ||
99 | /* Will do write back */ | ||
100 | void invalidate_dcache_range(const void *base, unsigned int size) { | ||
101 | unsigned int addr = (((int) base) & ~31); /* Align start to cache line*/ | ||
102 | unsigned int end = ((addr+size) & ~31)+64; /* Align end to cache line, pad */ | ||
103 | asm volatile( | ||
104 | "inv_start: \n" | ||
105 | "mcr p15, 0, %0, c7, c14, 1 \n" /* Clean and invalidate this line */ | ||
106 | "add %0, %0, #32 \n" | ||
107 | "cmp %0, %1 \n" | ||
108 | "mcrne p15, 0, %0, c7, c14, 1 \n" /* Clean and invalidate this line */ | ||
109 | "addne %0, %0, #32 \n" | ||
110 | "cmpne %0, %1 \n" | ||
111 | "mcrne p15, 0, %0, c7, c14, 1 \n" /* Clean and invalidate this line */ | ||
112 | "addne %0, %0, #32 \n" | ||
113 | "cmpne %0, %1 \n" | ||
114 | "mcrne p15, 0, %0, c7, c14, 1 \n" /* Clean and invalidate this line */ | ||
115 | "addne %0, %0, #32 \n" | ||
116 | "cmpne %0, %1 \n" | ||
117 | "mcrne p15, 0, %0, c7, c14, 1 \n" /* Clean and invalidate this line */ | ||
118 | "addne %0, %0, #32 \n" | ||
119 | "cmpne %0, %1 \n" | ||
120 | "mcrne p15, 0, %0, c7, c14, 1 \n" /* Clean and invalidate this line */ | ||
121 | "addne %0, %0, #32 \n" | ||
122 | "cmpne %0, %1 \n" | ||
123 | "mcrne p15, 0, %0, c7, c14, 1 \n" /* Clean and invalidate this line */ | ||
124 | "addne %0, %0, #32 \n" | ||
125 | "cmpne %0, %1 \n" | ||
126 | "mcrne p15, 0, %0, c7, c14, 1 \n" /* Clean and invalidate this line */ | ||
127 | "addne %0, %0, #32 \n" | ||
128 | "cmpne %0, %1 \n" | ||
129 | "bne inv_start \n" | ||
130 | "mov %0, #0\n" | ||
131 | "mcr p15,0,%0,c7,c10,4\n" /* Drain write buffer */ | ||
132 | : : "r" (addr), "r" (end)); | ||
133 | } | ||
134 | |||
135 | /* clean DCache for this range */ | ||
136 | /* forces DCache writeback for the specified range */ | ||
137 | void clean_dcache_range(const void *base, unsigned int size) { | ||
138 | unsigned int addr = (int) base; | ||
139 | unsigned int end = addr+size+32; | ||
140 | asm volatile( | ||
141 | "bic %0, %0, #31 \n" | ||
142 | "clean_start: \n" | ||
143 | "mcr p15, 0, %0, c7, c10, 1 \n" /* Clean this line */ | ||
144 | "add %0, %0, #32 \n" | ||
145 | "cmp %0, %1 \n" | ||
146 | "mcrlo p15, 0, %0, c7, c10, 1 \n" /* Clean this line */ | ||
147 | "addlo %0, %0, #32 \n" | ||
148 | "cmplo %0, %1 \n" | ||
149 | "mcrlo p15, 0, %0, c7, c10, 1 \n" /* Clean this line */ | ||
150 | "addlo %0, %0, #32 \n" | ||
151 | "cmplo %0, %1 \n" | ||
152 | "mcrlo p15, 0, %0, c7, c10, 1 \n" /* Clean this line */ | ||
153 | "addlo %0, %0, #32 \n" | ||
154 | "cmplo %0, %1 \n" | ||
155 | "mcrlo p15, 0, %0, c7, c10, 1 \n" /* Clean this line */ | ||
156 | "addlo %0, %0, #32 \n" | ||
157 | "cmplo %0, %1 \n" | ||
158 | "mcrlo p15, 0, %0, c7, c10, 1 \n" /* Clean this line */ | ||
159 | "addlo %0, %0, #32 \n" | ||
160 | "cmplo %0, %1 \n" | ||
161 | "mcrlo p15, 0, %0, c7, c10, 1 \n" /* Clean this line */ | ||
162 | "addlo %0, %0, #32 \n" | ||
163 | "cmplo %0, %1 \n" | ||
164 | "mcrlo p15, 0, %0, c7, c10, 1 \n" /* Clean this line */ | ||
165 | "addlo %0, %0, #32 \n" | ||
166 | "cmplo %0, %1 \n" | ||
167 | "blo clean_start \n" | ||
168 | "mov %0, #0\n" | ||
169 | "mcr p15,0,%0,c7,c10,4 \n" /* Drain write buffer */ | ||
170 | : : "r" (addr), "r" (end)); | ||
171 | } | ||
172 | |||
173 | /* Dump DCache for this range */ | ||
174 | /* Will *NOT* do write back */ | ||
175 | void dump_dcache_range(const void *base, unsigned int size) { | ||
176 | unsigned int addr = (int) base; | ||
177 | unsigned int end = addr+size; | ||
178 | asm volatile( | ||
179 | "tst %0, #31 \n" /* Check to see if low five bits are set */ | ||
180 | "bic %0, %0, #31 \n" /* Clear them */ | ||
181 | "mcrne p15, 0, %0, c7, c14, 1 \n" /* Clean and invalidate this line, if those bits were set */ | ||
182 | "add %0, %0, #32 \n" /* Move to the next cache line */ | ||
183 | "tst %1, #31 \n" /* Check last line for bits set */ | ||
184 | "bic %1, %1, #31 \n" /* Clear those bits */ | ||
185 | "mcrne p15, 0, %1, c7, c14, 1 \n" /* Clean and invalidate this line, if not cache aligned */ | ||
186 | "dump_start: \n" | ||
187 | "mcr p15, 0, %0, c7, c6, 1 \n" /* Invalidate this line */ | ||
188 | "add %0, %0, #32 \n" /* Next cache line */ | ||
189 | "cmp %0, %1 \n" | ||
190 | "bne dump_start \n" | ||
191 | "dump_end: \n" | ||
192 | "mcr p15,0,%0,c7,c10,4 \n" /* Drain write buffer */ | ||
193 | : : "r" (addr), "r" (end)); | ||
194 | } | ||
195 | /* Cleans entire DCache */ | ||
196 | void clean_dcache(void) | ||
197 | { | ||
198 | unsigned int index, addr; | ||
199 | |||
200 | for(index = 0; index <= 63; index++) { | ||
201 | addr = (0 << 5) | (index << 26); | ||
202 | asm volatile( | ||
203 | "mcr p15, 0, %0, c7, c10, 2 \n" /* Clean this entry by index */ | ||
204 | : : "r" (addr)); | ||
205 | addr = (1 << 5) | (index << 26); | ||
206 | asm volatile( | ||
207 | "mcr p15, 0, %0, c7, c10, 2 \n" /* Clean this entry by index */ | ||
208 | : : "r" (addr)); | ||
209 | addr = (2 << 5) | (index << 26); | ||
210 | asm volatile( | ||
211 | "mcr p15, 0, %0, c7, c10, 2 \n" /* Clean this entry by index */ | ||
212 | : : "r" (addr)); | ||
213 | addr = (3 << 5) | (index << 26); | ||
214 | asm volatile( | ||
215 | "mcr p15, 0, %0, c7, c10, 2 \n" /* Clean this entry by index */ | ||
216 | : : "r" (addr)); | ||
217 | addr = (4 << 5) | (index << 26); | ||
218 | asm volatile( | ||
219 | "mcr p15, 0, %0, c7, c10, 2 \n" /* Clean this entry by index */ | ||
220 | : : "r" (addr)); | ||
221 | addr = (5 << 5) | (index << 26); | ||
222 | asm volatile( | ||
223 | "mcr p15, 0, %0, c7, c10, 2 \n" /* Clean this entry by index */ | ||
224 | : : "r" (addr)); | ||
225 | addr = (6 << 5) | (index << 26); | ||
226 | asm volatile( | ||
227 | "mcr p15, 0, %0, c7, c10, 2 \n" /* Clean this entry by index */ | ||
228 | : : "r" (addr)); | ||
229 | addr = (7 << 5) | (index << 26); | ||
230 | asm volatile( | ||
231 | "mcr p15, 0, %0, c7, c10, 2 \n" /* Clean this entry by index */ | ||
232 | : : "r" (addr)); | ||
233 | } | ||
234 | } | ||
235 | |||