2 * linux/arch/arm/kernel/head-nommu.S
4 * Copyright (C) 1994-2002 Russell King
5 * Copyright (C) 2003-2006 Hyok S. Choi
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Common kernel startup code (non-paged MM)
14 #include <linux/linkage.h>
15 #include <linux/init.h>
16 #include <linux/errno.h>
18 #include <asm/assembler.h>
19 #include <asm/ptrace.h>
20 #include <asm/asm-offsets.h>
21 #include <asm/memory.h>
23 #include <asm/thread_info.h>
29 * Kernel startup entry point.
30 * ---------------------------
32 * This is normally called from the decompressor code. The requirements
33 * are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0,
36 * See linux/arch/arm/tools/mach-types for the complete list of machine
43 #ifdef CONFIG_CPU_THUMBONLY
50 THUMB( badr r9, 1f ) @ Kernel is always entered in ARM.
51 THUMB( bx r9 ) @ If this is a Thumb-2 kernel,
52 THUMB( .thumb ) @ switch to Thumb now.
56 #ifdef CONFIG_ARM_VIRT_EXT
59 @ ensure svc mode and all interrupts masked
60 safe_svcmode_maskall r9
62 #if defined(CONFIG_CPU_CP15)
63 mrc p15, 0, r9, c0, c0 @ get processor id
64 #elif defined(CONFIG_CPU_V7M)
65 ldr r9, =BASEADDR_V7M_SCB
66 ldr r9, [r9, V7M_SCB_CPUID]
68 ldr r9, =CONFIG_PROCESSOR_ID
70 bl __lookup_processor_type @ r5=procinfo r9=cpuid
71 movs r10, r5 @ invalid processor (r5=0)?
72 beq __error_p @ yes, error 'p'
78 badr lr, 1f @ return (PIC) address
79 ldr r12, [r10, #PROCINFO_INITFUNC]
82 1: ldr lr, =__mmap_switched
88 ENTRY(secondary_startup)
90 * Common entry point for secondary CPUs.
92 * Ensure that we're in SVC mode, and IRQs are disabled. Lookup
93 * the processor type - there is no need to check the machine type
94 * as it has already been validated by the primary processor.
96 #ifdef CONFIG_ARM_VIRT_EXT
97 bl __hyp_stub_install_secondary
99 safe_svcmode_maskall r9
101 #ifndef CONFIG_CPU_CP15
102 ldr r9, =CONFIG_PROCESSOR_ID
104 mrc p15, 0, r9, c0, c0 @ get processor id
106 bl __lookup_processor_type @ r5=procinfo r9=cpuid
107 movs r10, r5 @ invalid processor?
108 beq __error_p @ yes, error 'p'
110 ldr r7, __secondary_data
112 #ifdef CONFIG_ARM_MPU
113 bl __secondary_setup_mpu @ Initialize the MPU
116 badr lr, 1f @ return (PIC) address
117 ldr r12, [r10, #PROCINFO_INITFUNC]
120 1: bl __after_proc_init
121 ldr sp, [r7, #12] @ set up the stack pointer
123 b secondary_start_kernel
124 ENDPROC(secondary_startup)
126 .type __secondary_data, %object
129 #endif /* CONFIG_SMP */
132 * Set the Control Register and Read the process ID.
136 M_CLASS(movw r12, #:lower16:BASEADDR_V7M_SCB)
137 M_CLASS(movt r12, #:upper16:BASEADDR_V7M_SCB)
138 #ifdef CONFIG_ARM_MPU
139 M_CLASS(ldr r3, [r12, 0x50])
140 AR_CLASS(mrc p15, 0, r3, c0, c1, 4) @ Read ID_MMFR0
141 and r3, r3, #(MMFR0_PMSA) @ PMSA field
142 teq r3, #(MMFR0_PMSAv7) @ PMSA v7
144 teq r3, #(MMFR0_PMSAv8) @ PMSA v8
146 * Memory region attributes for PMSAv8:
150 * DEVICE_nGnRnE 000 00000000
151 * NORMAL 001 11111111
153 ldreq r3, =PMSAv8_MAIR(0x00, PMSAv8_RGN_DEVICE_nGnRnE) | \
154 PMSAv8_MAIR(0xff, PMSAv8_RGN_NORMAL)
155 AR_CLASS(mcreq p15, 0, r3, c10, c2, 0) @ MAIR 0
156 M_CLASS(streq r3, [r12, #PMSAv8_MAIR0])
158 AR_CLASS(mcreq p15, 0, r3, c10, c2, 1) @ MAIR 1
159 M_CLASS(streq r3, [r12, #PMSAv8_MAIR1])
163 #ifdef CONFIG_CPU_CP15
165 * CP15 system control register value returned in r0 from
166 * the CPU init function.
169 #ifdef CONFIG_ARM_MPU
170 biceq r0, r0, #CR_BR @ Disable the 'default mem-map'
171 orreq r0, r0, #CR_M @ Set SCTRL.M (MPU on)
173 #if defined(CONFIG_ALIGNMENT_TRAP) && __LINUX_ARM_ARCH__ < 6
178 #ifdef CONFIG_CPU_DCACHE_DISABLE
181 #ifdef CONFIG_CPU_BPREDICT_DISABLE
184 #ifdef CONFIG_CPU_ICACHE_DISABLE
187 mcr p15, 0, r0, c1, c0, 0 @ write control reg
189 #elif defined (CONFIG_CPU_V7M)
190 #ifdef CONFIG_ARM_MPU
191 ldreq r3, [r12, MPU_CTRL]
192 biceq r3, #MPU_CTRL_PRIVDEFENA
193 orreq r3, #MPU_CTRL_ENABLE
194 streq r3, [r12, MPU_CTRL]
197 /* For V7M systems we want to modify the CCR similarly to the SCTLR */
198 #ifdef CONFIG_CPU_DCACHE_DISABLE
199 bic r0, r0, #V7M_SCB_CCR_DC
201 #ifdef CONFIG_CPU_BPREDICT_DISABLE
202 bic r0, r0, #V7M_SCB_CCR_BP
204 #ifdef CONFIG_CPU_ICACHE_DISABLE
205 bic r0, r0, #V7M_SCB_CCR_IC
207 str r0, [r12, V7M_SCB_CCR]
208 /* Pass exc_ret to __mmap_switched */
210 #endif /* CONFIG_CPU_CP15 elif CONFIG_CPU_V7M */
212 ENDPROC(__after_proc_init)
215 #ifdef CONFIG_ARM_MPU
218 #ifndef CONFIG_CPU_V7M
219 /* Set which MPU region should be programmed */
220 .macro set_region_nr tmp, rgnr, unused
221 mov \tmp, \rgnr @ Use static region numbers
222 mcr p15, 0, \tmp, c6, c2, 0 @ Write RGNR
225 /* Setup a single MPU region, either D or I side (D-side for unified) */
226 .macro setup_region bar, acr, sr, side = PMSAv7_DATA_SIDE, unused
227 mcr p15, 0, \bar, c6, c1, (0 + \side) @ I/DRBAR
228 mcr p15, 0, \acr, c6, c1, (4 + \side) @ I/DRACR
229 mcr p15, 0, \sr, c6, c1, (2 + \side) @ I/DRSR
232 .macro set_region_nr tmp, rgnr, base
234 str \tmp, [\base, #PMSAv7_RNR]
237 .macro setup_region bar, acr, sr, unused, base
240 str \bar, [\base, #PMSAv7_RBAR]
241 str \acr, [\base, #PMSAv7_RASR]
246 * Setup the MPU and initial MPU Regions. We create the following regions:
247 * Region 0: Use this for probing the MPU details, so leave disabled.
248 * Region 1: Background region - covers the whole of RAM as strongly ordered
249 * Region 2: Normal, Shared, cacheable for RAM. From PHYS_OFFSET, size from r6
250 * Region 3: Normal, shared, inaccessible from PL0 to protect the vectors page
252 * r6: Value to be written to DRSR (and IRSR if required) for PMSAv7_RAM_REGION
258 /* Probe for v7 PMSA compliance */
259 M_CLASS(movw r12, #:lower16:BASEADDR_V7M_SCB)
260 M_CLASS(movt r12, #:upper16:BASEADDR_V7M_SCB)
262 AR_CLASS(mrc p15, 0, r0, c0, c1, 4) @ Read ID_MMFR0
263 M_CLASS(ldr r0, [r12, 0x50])
264 and r0, r0, #(MMFR0_PMSA) @ PMSA field
265 teq r0, #(MMFR0_PMSAv7) @ PMSA v7
267 teq r0, #(MMFR0_PMSAv8) @ PMSA v8
273 ENTRY(__setup_pmsa_v7)
274 /* Calculate the size of a region covering just the kernel */
275 ldr r5, =PLAT_PHYS_OFFSET @ Region start: PHYS_OFFSET
276 ldr r6, =(_end) @ Cover whole kernel
277 sub r6, r6, r5 @ Minimum size of region to map
278 clz r6, r6 @ Region size must be 2^N...
279 rsb r6, r6, #31 @ ...so round up region size
280 lsl r6, r6, #PMSAv7_RSR_SZ @ Put size in right field
281 orr r6, r6, #(1 << PMSAv7_RSR_EN) @ Set region enabled bit
283 /* Determine whether the D/I-side memory map is unified. We set the
284 * flags here and continue to use them for the rest of this function */
285 AR_CLASS(mrc p15, 0, r0, c0, c0, 4) @ MPUIR
286 M_CLASS(ldr r0, [r12, #MPU_TYPE])
287 ands r5, r0, #MPUIR_DREGION_SZMASK @ 0 size d region => No MPU
289 tst r0, #MPUIR_nU @ MPUIR_nU = 0 for unified
291 /* Setup second region first to free up r6 */
292 set_region_nr r0, #PMSAv7_RAM_REGION, r12
294 /* Full access from PL0, PL1, shared for CONFIG_SMP, cacheable */
295 ldr r0, =PLAT_PHYS_OFFSET @ RAM starts at PHYS_OFFSET
296 ldr r5,=(PMSAv7_AP_PL1RW_PL0RW | PMSAv7_RGN_NORMAL)
298 setup_region r0, r5, r6, PMSAv7_DATA_SIDE, r12 @ PHYS_OFFSET, shared, enabled
299 beq 1f @ Memory-map not unified
300 setup_region r0, r5, r6, PMSAv7_INSTR_SIDE, r12 @ PHYS_OFFSET, shared, enabled
303 /* First/background region */
304 set_region_nr r0, #PMSAv7_BG_REGION, r12
306 /* Execute Never, strongly ordered, inaccessible to PL0, rw PL1 */
307 mov r0, #0 @ BG region starts at 0x0
308 ldr r5,=(PMSAv7_ACR_XN | PMSAv7_RGN_STRONGLY_ORDERED | PMSAv7_AP_PL1RW_PL0NA)
309 mov r6, #PMSAv7_RSR_ALL_MEM @ 4GB region, enabled
311 setup_region r0, r5, r6, PMSAv7_DATA_SIDE, r12 @ 0x0, BG region, enabled
312 beq 2f @ Memory-map not unified
313 setup_region r0, r5, r6, PMSAv7_INSTR_SIDE r12 @ 0x0, BG region, enabled
316 #ifdef CONFIG_XIP_KERNEL
317 set_region_nr r0, #PMSAv7_ROM_REGION, r12
320 ldr r5,=(PMSAv7_AP_PL1RO_PL0NA | PMSAv7_RGN_NORMAL)
322 ldr r0, =CONFIG_XIP_PHYS_ADDR @ ROM start
323 ldr r6, =(_exiprom) @ ROM end
324 sub r6, r6, r0 @ Minimum size of region to map
325 clz r6, r6 @ Region size must be 2^N...
326 rsb r6, r6, #31 @ ...so round up region size
327 lsl r6, r6, #PMSAv7_RSR_SZ @ Put size in right field
328 orr r6, r6, #(1 << PMSAv7_RSR_EN) @ Set region enabled bit
330 setup_region r0, r5, r6, PMSAv7_DATA_SIDE, r12 @ XIP_PHYS_ADDR, shared, enabled
331 beq 3f @ Memory-map not unified
332 setup_region r0, r5, r6, PMSAv7_INSTR_SIDE, r12 @ XIP_PHYS_ADDR, shared, enabled
336 ENDPROC(__setup_pmsa_v7)
338 ENTRY(__setup_pmsa_v8)
340 AR_CLASS(mcr p15, 0, r0, c6, c2, 1) @ PRSEL
341 M_CLASS(str r0, [r12, #PMSAv8_RNR])
344 #ifdef CONFIG_XIP_KERNEL
345 ldr r5, =CONFIG_XIP_PHYS_ADDR @ ROM start
346 ldr r6, =(_exiprom) @ ROM end
348 bic r6, r6, #(PMSAv8_MINALIGN - 1)
350 orr r5, r5, #(PMSAv8_AP_PL1RW_PL0NA | PMSAv8_RGN_SHARED)
351 orr r6, r6, #(PMSAv8_LAR_IDX(PMSAv8_RGN_NORMAL) | PMSAv8_LAR_EN)
353 AR_CLASS(mcr p15, 0, r5, c6, c8, 0) @ PRBAR0
354 AR_CLASS(mcr p15, 0, r6, c6, c8, 1) @ PRLAR0
355 M_CLASS(str r5, [r12, #PMSAv8_RBAR_A(0)])
356 M_CLASS(str r6, [r12, #PMSAv8_RLAR_A(0)])
359 ldr r5, =KERNEL_START
362 bic r6, r6, #(PMSAv8_MINALIGN - 1)
364 orr r5, r5, #(PMSAv8_AP_PL1RW_PL0NA | PMSAv8_RGN_SHARED)
365 orr r6, r6, #(PMSAv8_LAR_IDX(PMSAv8_RGN_NORMAL) | PMSAv8_LAR_EN)
367 AR_CLASS(mcr p15, 0, r5, c6, c8, 4) @ PRBAR1
368 AR_CLASS(mcr p15, 0, r6, c6, c8, 5) @ PRLAR1
369 M_CLASS(str r5, [r12, #PMSAv8_RBAR_A(1)])
370 M_CLASS(str r6, [r12, #PMSAv8_RLAR_A(1)])
372 /* Setup Background: 0x0 - min(KERNEL_START, XIP_PHYS_ADDR) */
373 #ifdef CONFIG_XIP_KERNEL
374 ldr r6, =KERNEL_START
375 ldr r5, =CONFIG_XIP_PHYS_ADDR
379 ldr r6, =KERNEL_START
386 bic r6, r6, #(PMSAv8_MINALIGN - 1)
388 orr r5, r5, #(PMSAv8_AP_PL1RW_PL0NA | PMSAv8_RGN_SHARED | PMSAv8_BAR_XN)
389 orr r6, r6, #(PMSAv8_LAR_IDX(PMSAv8_RGN_DEVICE_nGnRnE) | PMSAv8_LAR_EN)
391 AR_CLASS(mcr p15, 0, r5, c6, c9, 0) @ PRBAR2
392 AR_CLASS(mcr p15, 0, r6, c6, c9, 1) @ PRLAR2
393 M_CLASS(str r5, [r12, #PMSAv8_RBAR_A(2)])
394 M_CLASS(str r6, [r12, #PMSAv8_RLAR_A(2)])
397 /* Setup Background: max(KERNEL_END, _exiprom) - 0xffffffff */
398 #ifdef CONFIG_XIP_KERNEL
407 bic r6, r6, #(PMSAv8_MINALIGN - 1)
409 orr r5, r5, #(PMSAv8_AP_PL1RW_PL0NA | PMSAv8_RGN_SHARED | PMSAv8_BAR_XN)
410 orr r6, r6, #(PMSAv8_LAR_IDX(PMSAv8_RGN_DEVICE_nGnRnE) | PMSAv8_LAR_EN)
412 AR_CLASS(mcr p15, 0, r5, c6, c9, 4) @ PRBAR3
413 AR_CLASS(mcr p15, 0, r6, c6, c9, 5) @ PRLAR3
414 M_CLASS(str r5, [r12, #PMSAv8_RBAR_A(3)])
415 M_CLASS(str r6, [r12, #PMSAv8_RLAR_A(3)])
417 #ifdef CONFIG_XIP_KERNEL
418 /* Setup Background: min(_exiprom, KERNEL_END) - max(KERNEL_START, XIP_PHYS_ADDR) */
424 ldr r6, =KERNEL_START
425 ldr r0, =CONFIG_XIP_PHYS_ADDR
430 bic r6, r6, #(PMSAv8_MINALIGN - 1)
432 orr r5, r5, #(PMSAv8_AP_PL1RW_PL0NA | PMSAv8_RGN_SHARED | PMSAv8_BAR_XN)
433 orr r6, r6, #(PMSAv8_LAR_IDX(PMSAv8_RGN_DEVICE_nGnRnE) | PMSAv8_LAR_EN)
435 #ifdef CONFIG_CPU_V7M
436 /* There is no alias for n == 4 */
438 str r0, [r12, #PMSAv8_RNR] @ PRSEL
441 str r5, [r12, #PMSAv8_RBAR_A(0)]
442 str r6, [r12, #PMSAv8_RLAR_A(0)]
444 mcr p15, 0, r5, c6, c10, 0 @ PRBAR4
445 mcr p15, 0, r6, c6, c10, 1 @ PRLAR4
449 ENDPROC(__setup_pmsa_v8)
453 * r6: pointer at mpu_rgn_info
457 ENTRY(__secondary_setup_mpu)
458 /* Use MPU region info supplied by __cpu_up */
459 ldr r6, [r7] @ get secondary_data.mpu_rgn_info
461 /* Probe for v7 PMSA compliance */
462 mrc p15, 0, r0, c0, c1, 4 @ Read ID_MMFR0
463 and r0, r0, #(MMFR0_PMSA) @ PMSA field
464 teq r0, #(MMFR0_PMSAv7) @ PMSA v7
465 beq __secondary_setup_pmsa_v7
466 teq r0, #(MMFR0_PMSAv8) @ PMSA v8
467 beq __secondary_setup_pmsa_v8
469 ENDPROC(__secondary_setup_mpu)
472 * r6: pointer at mpu_rgn_info
474 ENTRY(__secondary_setup_pmsa_v7)
475 /* Determine whether the D/I-side memory map is unified. We set the
476 * flags here and continue to use them for the rest of this function */
477 mrc p15, 0, r0, c0, c0, 4 @ MPUIR
478 ands r5, r0, #MPUIR_DREGION_SZMASK @ 0 size d region => No MPU
481 ldr r4, [r6, #MPU_RNG_INFO_USED]
482 mov r5, #MPU_RNG_SIZE
483 add r3, r6, #MPU_RNG_INFO_RNGS
487 tst r0, #MPUIR_nU @ MPUIR_nU = 0 for unified
488 sub r3, r3, #MPU_RNG_SIZE
494 ldr r0, [r3, #MPU_RGN_DRBAR]
495 ldr r6, [r3, #MPU_RGN_DRSR]
496 ldr r5, [r3, #MPU_RGN_DRACR]
498 setup_region r0, r5, r6, PMSAv7_DATA_SIDE
500 setup_region r0, r5, r6, PMSAv7_INSTR_SIDE
503 mrc p15, 0, r0, c0, c0, 4 @ Reevaluate the MPUIR
508 ENDPROC(__secondary_setup_pmsa_v7)
510 ENTRY(__secondary_setup_pmsa_v8)
511 ldr r4, [r6, #MPU_RNG_INFO_USED]
512 #ifndef CONFIG_XIP_KERNEL
515 mov r5, #MPU_RNG_SIZE
516 add r3, r6, #MPU_RNG_INFO_RNGS
520 sub r3, r3, #MPU_RNG_SIZE
523 mcr p15, 0, r4, c6, c2, 1 @ PRSEL
526 ldr r5, [r3, #MPU_RGN_PRBAR]
527 ldr r6, [r3, #MPU_RGN_PRLAR]
529 mcr p15, 0, r5, c6, c3, 0 @ PRBAR
530 mcr p15, 0, r6, c6, c3, 1 @ PRLAR
536 ENDPROC(__secondary_setup_pmsa_v8)
537 #endif /* CONFIG_SMP */
538 #endif /* CONFIG_ARM_MPU */
539 #include "head-common.S"