| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: rpi_start.S,v 1.5 2012/08/22 12:36:35 jakllsch Exp $ */ | | 1 | /* $NetBSD: rpi_start.S,v 1.6 2012/09/16 14:14:56 skrll Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved. | | 4 | * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved. |
5 | * Written by Hiroyuki Bessho for Genetec Corporation. | | 5 | * Written by Hiroyuki Bessho for Genetec Corporation. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -77,31 +77,27 @@ | | | @@ -77,31 +77,27 @@ |
77 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 77 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
78 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 78 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
79 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 79 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
80 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 80 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
81 | * SUCH DAMAGE. | | 81 | * SUCH DAMAGE. |
82 | */ | | 82 | */ |
83 | | | 83 | |
84 | #include "opt_cputypes.h" | | 84 | #include "opt_cputypes.h" |
85 | | | 85 | |
86 | #include <machine/asm.h> | | 86 | #include <machine/asm.h> |
87 | #include <arm/armreg.h> | | 87 | #include <arm/armreg.h> |
88 | #include "assym.h" | | 88 | #include "assym.h" |
89 | | | 89 | |
90 | RCSID("$NetBSD: rpi_start.S,v 1.5 2012/08/22 12:36:35 jakllsch Exp $") | | 90 | RCSID("$NetBSD: rpi_start.S,v 1.6 2012/09/16 14:14:56 skrll Exp $") |
91 | | | | |
92 | /* Location (in MiB) to put temporary MMU tables just below. */ | | | |
93 | /* Raspberry Pi start.elf will give us anywhere between 128MiB and 240MiB */ | | | |
94 | #define MINSPLIT 128 | | | |
95 | | | 91 | |
96 | /* | | 92 | /* |
97 | * Workaround Erratum 411920 | | 93 | * Workaround Erratum 411920 |
98 | * | | 94 | * |
99 | * - value of arg 'reg' Should Be Zero | | 95 | * - value of arg 'reg' Should Be Zero |
100 | */ | | 96 | */ |
101 | #define Invalidate_I_cache(reg) \ | | 97 | #define Invalidate_I_cache(reg) \ |
102 | .p2align 5; \ | | 98 | .p2align 5; \ |
103 | mcr p15, 0, reg, c7, c5, 0; /* Invalidate Entire I cache */ \ | | 99 | mcr p15, 0, reg, c7, c5, 0; /* Invalidate Entire I cache */ \ |
104 | mcr p15, 0, reg, c7, c5, 0; /* Invalidate Entire I cache */ \ | | 100 | mcr p15, 0, reg, c7, c5, 0; /* Invalidate Entire I cache */ \ |
105 | mcr p15, 0, reg, c7, c5, 0; /* Invalidate Entire I cache */ \ | | 101 | mcr p15, 0, reg, c7, c5, 0; /* Invalidate Entire I cache */ \ |
106 | mcr p15, 0, reg, c7, c5, 0; /* Invalidate Entire I cache */ \ | | 102 | mcr p15, 0, reg, c7, c5, 0; /* Invalidate Entire I cache */ \ |
107 | nop; \ | | 103 | nop; \ |
| @@ -167,26 +163,27 @@ _C_LABEL(rpi_start): | | | @@ -167,26 +163,27 @@ _C_LABEL(rpi_start): |
167 | l1sfrm .req r6 | | 163 | l1sfrm .req r6 |
168 | | | 164 | |
169 | adr itable, mmu_init_table | | 165 | adr itable, mmu_init_table |
170 | ldr l1sfrm, Ll1_s_frame | | 166 | ldr l1sfrm, Ll1_s_frame |
171 | b 3f | | 167 | b 3f |
172 | | | 168 | |
173 | 2: str pa, [l1table, va] | | 169 | 2: str pa, [l1table, va] |
174 | add va, va, #4 | | 170 | add va, va, #4 |
175 | add pa, pa, #(L1_S_SIZE) | | 171 | add pa, pa, #(L1_S_SIZE) |
176 | adds n_sec, n_sec, #-1 | | 172 | adds n_sec, n_sec, #-1 |
177 | bhi 2b | | 173 | bhi 2b |
178 | | | 174 | |
179 | 3: ldmia itable!, {va,pa,n_sec,attr} | | 175 | 3: ldmia itable!, {va,pa,n_sec,attr} |
| | | 176 | mov n_sec, n_sec, lsr #L1_S_SHIFT |
180 | /* Convert va to l1 offset: va = 4 * (va >> L1_S_SHIFT) */ | | 177 | /* Convert va to l1 offset: va = 4 * (va >> L1_S_SHIFT) */ |
181 | mov va, va, LSR #L1_S_SHIFT | | 178 | mov va, va, LSR #L1_S_SHIFT |
182 | mov va, va, LSL #2 | | 179 | mov va, va, LSL #2 |
183 | /* Convert pa to l1 entry: pa = (pa & L1_S_FRAME) | attr */ | | 180 | /* Convert pa to l1 entry: pa = (pa & L1_S_FRAME) | attr */ |
184 | and pa, pa, l1sfrm | | 181 | and pa, pa, l1sfrm |
185 | orr pa, pa, attr | | 182 | orr pa, pa, attr |
186 | cmp n_sec, #0 | | 183 | cmp n_sec, #0 |
187 | bne 2b | | 184 | bne 2b |
188 | | | 185 | |
189 | .unreq va | | 186 | .unreq va |
190 | .unreq pa | | 187 | .unreq pa |
191 | .unreq n_sec | | 188 | .unreq n_sec |
192 | .unreq attr | | 189 | .unreq attr |
| @@ -249,28 +246,28 @@ _C_LABEL(rpi_start): | | | @@ -249,28 +246,28 @@ _C_LABEL(rpi_start): |
249 | * Jump to start in locore.S, which in turn will call initarm and main. | | 246 | * Jump to start in locore.S, which in turn will call initarm and main. |
250 | */ | | 247 | */ |
251 | mov pc, lr | | 248 | mov pc, lr |
252 | nop | | 249 | nop |
253 | nop | | 250 | nop |
254 | nop | | 251 | nop |
255 | nop | | 252 | nop |
256 | | | 253 | |
257 | /* NOTREACHED */ | | 254 | /* NOTREACHED */ |
258 | Ll1_s_frame: | | 255 | Ll1_s_frame: |
259 | .word L1_S_FRAME | | 256 | .word L1_S_FRAME |
260 | | | 257 | |
261 | Ltemp_l1_table: | | 258 | Ltemp_l1_table: |
262 | /* Put the temporary L1 translation table at the end of SDRAM. */ | | 259 | /* Put the temporary L1 translation table just below the kernel. */ |
263 | .word 0x00000000 + MINSPLIT * 0x100000 - L1_TABLE_SIZE | | 260 | .word 0x4000 |
264 | | | 261 | |
265 | Lstart: | | 262 | Lstart: |
266 | .word start | | 263 | .word start |
267 | /* | | 264 | /* |
268 | * Coprocessor register initialization values | | 265 | * Coprocessor register initialization values |
269 | */ | | 266 | */ |
270 | | | 267 | |
271 | /* bits to set in the Control Register */ | | 268 | /* bits to set in the Control Register */ |
272 | Lcontrol_set: | | 269 | Lcontrol_set: |
273 | .word CPU_CONTROL_MMU_ENABLE | \ | | 270 | .word CPU_CONTROL_MMU_ENABLE | \ |
274 | CPU_CONTROL_AFLT_ENABLE | \ | | 271 | CPU_CONTROL_AFLT_ENABLE | \ |
275 | CPU_CONTROL_DC_ENABLE | \ | | 272 | CPU_CONTROL_DC_ENABLE | \ |
276 | CPU_CONTROL_WBUF_ENABLE | /* not defined in 1176 */ \ | | 273 | CPU_CONTROL_WBUF_ENABLE | /* not defined in 1176 */ \ |
| @@ -300,32 +297,32 @@ Lcontrol_wax: | | | @@ -300,32 +297,32 @@ Lcontrol_wax: |
300 | /* bits to disable the caches */ | | 297 | /* bits to disable the caches */ |
301 | Lctl_ID_dis: | | 298 | Lctl_ID_dis: |
302 | .word ~(CPU_CONTROL_IC_ENABLE|CPU_CONTROL_DC_ENABLE) | | 299 | .word ~(CPU_CONTROL_IC_ENABLE|CPU_CONTROL_DC_ENABLE) |
303 | | | 300 | |
304 | /* We'll modify va and pa at run time so we can use relocatable addresses. */ | | 301 | /* We'll modify va and pa at run time so we can use relocatable addresses. */ |
305 | #define MMU_INIT(va,pa,n_sec,attr) \ | | 302 | #define MMU_INIT(va,pa,n_sec,attr) \ |
306 | .word va ; \ | | 303 | .word va ; \ |
307 | .word pa ; \ | | 304 | .word pa ; \ |
308 | .word n_sec ; \ | | 305 | .word n_sec ; \ |
309 | .word attr ; | | 306 | .word attr ; |
310 | | | 307 | |
311 | mmu_init_table: | | 308 | mmu_init_table: |
312 | /* Add 1MB of VA==PA at 0x00000000 so we can keep the kernel going */ | | 309 | /* Add 1MB of VA==PA at 0x00000000 so we can keep the kernel going */ |
313 | MMU_INIT(0x00000000, 0x00000000, | | 310 | MMU_INIT(0x0, 0x0, |
314 | (MINSPLIT * L1_S_SIZE + L1_S_SIZE - 1) / L1_S_SIZE, | | 311 | (_end - KERNEL_BASE + L1_S_SIZE - 1), |
315 | L1_S_PROTO | L1_S_AP_KRW) | | 312 | L1_S_PROTO | L1_S_AP_KRW) |
316 | | | 313 | |
317 | MMU_INIT(KERNEL_BASE, 0x0, | | 314 | MMU_INIT(KERNEL_BASE, 0x0, |
318 | (MINSPLIT * L1_S_SIZE + L1_S_SIZE - 1) / L1_S_SIZE, | | 315 | (_end - KERNEL_BASE + L1_S_SIZE - 1), |
319 | L1_S_PROTO | L1_S_AP_KRW | L1_S_B | L1_S_C) | | 316 | L1_S_PROTO | L1_S_AP_KRW | L1_S_B | L1_S_C) |
320 | | | 317 | |
321 | /* Map the 16MB of peripherals */ | | 318 | /* Map the 16MB of peripherals */ |
322 | MMU_INIT(RPI_KERNEL_IO_VBASE, RPI_KERNEL_IO_PBASE, | | 319 | MMU_INIT(RPI_KERNEL_IO_VBASE, RPI_KERNEL_IO_PBASE, |
323 | (RPI_KERNEL_IO_VSIZE + L1_S_SIZE - 1) / L1_S_SIZE, | | 320 | (RPI_KERNEL_IO_VSIZE + L1_S_SIZE - 1), |
324 | L1_S_PROTO | L1_S_AP_KRW) | | 321 | L1_S_PROTO | L1_S_AP_KRW) |
325 | | | 322 | |
326 | /* end of table */ | | 323 | /* end of table */ |
327 | MMU_INIT(0, 0, 0, 0) | | 324 | MMU_INIT(0, 0, 0, 0) |
328 | | | 325 | |
329 | .globl _C_LABEL(rpi_boot_regs) | | 326 | .globl _C_LABEL(rpi_boot_regs) |
330 | rpi_boot_regs: | | 327 | rpi_boot_regs: |
331 | .space 4 * 4 | | 328 | .space 4 * 4 |