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 setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 @ ensure svc mode
58 #if defined(CONFIG_CPU_CP15)
59 mrc p15, 0, r9, c0, c0 @ get processor id
60 #elif defined(CONFIG_CPU_V7M)
61 ldr r9, =BASEADDR_V7M_SCB
62 ldr r9, [r9, V7M_SCB_CPUID]
64 ldr r9, =CONFIG_PROCESSOR_ID
66 bl __lookup_processor_type @ r5=procinfo r9=cpuid
67 movs r10, r5 @ invalid processor (r5=0)?
68 beq __error_p @ yes, error 'p'
71 /* Calculate the size of a region covering just the kernel */
72 ldr r5, =PLAT_PHYS_OFFSET @ Region start: PHYS_OFFSET
73 ldr r6, =(_end) @ Cover whole kernel
74 sub r6, r6, r5 @ Minimum size of region to map
75 clz r6, r6 @ Region size must be 2^N...
76 rsb r6, r6, #31 @ ...so round up region size
77 lsl r6, r6, #MPU_RSR_SZ @ Put size in right field
78 orr r6, r6, #(1 << MPU_RSR_EN) @ Set region enabled bit
82 badr lr, 1f @ return (PIC) address
83 ldr r12, [r10, #PROCINFO_INITFUNC]
86 1: bl __after_proc_init
92 ENTRY(secondary_startup)
94 * Common entry point for secondary CPUs.
96 * Ensure that we're in SVC mode, and IRQs are disabled. Lookup
97 * the processor type - there is no need to check the machine type
98 * as it has already been validated by the primary processor.
100 setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, 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 /* Use MPU region info supplied by __cpu_up */
114 ldr r6, [r7] @ get secondary_data.mpu_rgn_info
115 bl __secondary_setup_mpu @ Initialize the MPU
118 badr lr, 1f @ return (PIC) address
119 ldr r12, [r10, #PROCINFO_INITFUNC]
122 1: bl __after_proc_init
123 ldr sp, [r7, #12] @ set up the stack pointer
125 b secondary_start_kernel
126 ENDPROC(secondary_startup)
128 .type __secondary_data, %object
131 #endif /* CONFIG_SMP */
134 * Set the Control Register and Read the process ID.
137 #ifdef CONFIG_CPU_CP15
139 * CP15 system control register value returned in r0 from
140 * the CPU init function.
142 #if defined(CONFIG_ALIGNMENT_TRAP) && __LINUX_ARM_ARCH__ < 6
147 #ifdef CONFIG_CPU_DCACHE_DISABLE
150 #ifdef CONFIG_CPU_BPREDICT_DISABLE
153 #ifdef CONFIG_CPU_ICACHE_DISABLE
156 mcr p15, 0, r0, c1, c0, 0 @ write control reg
157 #elif defined (CONFIG_CPU_V7M)
158 /* For V7M systems we want to modify the CCR similarly to the SCTLR */
159 #ifdef CONFIG_CPU_DCACHE_DISABLE
160 bic r0, r0, #V7M_SCB_CCR_DC
162 #ifdef CONFIG_CPU_BPREDICT_DISABLE
163 bic r0, r0, #V7M_SCB_CCR_BP
165 #ifdef CONFIG_CPU_ICACHE_DISABLE
166 bic r0, r0, #V7M_SCB_CCR_IC
168 movw r3, #:lower16:(BASEADDR_V7M_SCB + V7M_SCB_CCR)
169 movt r3, #:upper16:(BASEADDR_V7M_SCB + V7M_SCB_CCR)
171 #endif /* CONFIG_CPU_CP15 elif CONFIG_CPU_V7M */
173 ENDPROC(__after_proc_init)
176 #ifdef CONFIG_ARM_MPU
179 #ifndef CONFIG_CPU_V7M
180 /* Set which MPU region should be programmed */
181 .macro set_region_nr tmp, rgnr, unused
182 mov \tmp, \rgnr @ Use static region numbers
183 mcr p15, 0, \tmp, c6, c2, 0 @ Write RGNR
186 /* Setup a single MPU region, either D or I side (D-side for unified) */
187 .macro setup_region bar, acr, sr, side = MPU_DATA_SIDE, unused
188 mcr p15, 0, \bar, c6, c1, (0 + \side) @ I/DRBAR
189 mcr p15, 0, \acr, c6, c1, (4 + \side) @ I/DRACR
190 mcr p15, 0, \sr, c6, c1, (2 + \side) @ I/DRSR
193 .macro set_region_nr tmp, rgnr, base
195 str \tmp, [\base, #MPU_RNR]
198 .macro setup_region bar, acr, sr, unused, base
201 str \bar, [\base, #MPU_RBAR]
202 str \acr, [\base, #MPU_RASR]
207 * Setup the MPU and initial MPU Regions. We create the following regions:
208 * Region 0: Use this for probing the MPU details, so leave disabled.
209 * Region 1: Background region - covers the whole of RAM as strongly ordered
210 * Region 2: Normal, Shared, cacheable for RAM. From PHYS_OFFSET, size from r6
211 * Region 3: Normal, shared, inaccessible from PL0 to protect the vectors page
213 * r6: Value to be written to DRSR (and IRSR if required) for MPU_RAM_REGION
218 /* Probe for v7 PMSA compliance */
219 M_CLASS(movw r12, #:lower16:BASEADDR_V7M_SCB)
220 M_CLASS(movt r12, #:upper16:BASEADDR_V7M_SCB)
222 AR_CLASS(mrc p15, 0, r0, c0, c1, 4) @ Read ID_MMFR0
223 M_CLASS(ldr r0, [r12, 0x50])
224 and r0, r0, #(MMFR0_PMSA) @ PMSA field
225 teq r0, #(MMFR0_PMSAv7) @ PMSA v7
228 /* Determine whether the D/I-side memory map is unified. We set the
229 * flags here and continue to use them for the rest of this function */
230 AR_CLASS(mrc p15, 0, r0, c0, c0, 4) @ MPUIR
231 M_CLASS(ldr r0, [r12, #MPU_TYPE])
232 ands r5, r0, #MPUIR_DREGION_SZMASK @ 0 size d region => No MPU
234 tst r0, #MPUIR_nU @ MPUIR_nU = 0 for unified
236 /* Setup second region first to free up r6 */
237 set_region_nr r0, #MPU_RAM_REGION, r12
239 /* Full access from PL0, PL1, shared for CONFIG_SMP, cacheable */
240 ldr r0, =PLAT_PHYS_OFFSET @ RAM starts at PHYS_OFFSET
241 ldr r5,=(MPU_AP_PL1RW_PL0RW | MPU_RGN_NORMAL)
243 setup_region r0, r5, r6, MPU_DATA_SIDE, r12 @ PHYS_OFFSET, shared, enabled
244 beq 1f @ Memory-map not unified
245 setup_region r0, r5, r6, MPU_INSTR_SIDE, r12 @ PHYS_OFFSET, shared, enabled
248 /* First/background region */
249 set_region_nr r0, #MPU_BG_REGION, r12
251 /* Execute Never, strongly ordered, inaccessible to PL0, rw PL1 */
252 mov r0, #0 @ BG region starts at 0x0
253 ldr r5,=(MPU_ACR_XN | MPU_RGN_STRONGLY_ORDERED | MPU_AP_PL1RW_PL0NA)
254 mov r6, #MPU_RSR_ALL_MEM @ 4GB region, enabled
256 setup_region r0, r5, r6, MPU_DATA_SIDE, r12 @ 0x0, BG region, enabled
257 beq 2f @ Memory-map not unified
258 setup_region r0, r5, r6, MPU_INSTR_SIDE r12 @ 0x0, BG region, enabled
261 #ifdef CONFIG_XIP_KERNEL
262 set_region_nr r0, #MPU_ROM_REGION, r12
265 ldr r5,=(MPU_AP_PL1RO_PL0NA | MPU_RGN_NORMAL)
267 ldr r0, =CONFIG_XIP_PHYS_ADDR @ ROM start
268 ldr r6, =(_exiprom) @ ROM end
269 sub r6, r6, r0 @ Minimum size of region to map
270 clz r6, r6 @ Region size must be 2^N...
271 rsb r6, r6, #31 @ ...so round up region size
272 lsl r6, r6, #MPU_RSR_SZ @ Put size in right field
273 orr r6, r6, #(1 << MPU_RSR_EN) @ Set region enabled bit
275 setup_region r0, r5, r6, MPU_DATA_SIDE, r12 @ XIP_PHYS_ADDR, shared, enabled
276 beq 3f @ Memory-map not unified
277 setup_region r0, r5, r6, MPU_INSTR_SIDE, r12 @ XIP_PHYS_ADDR, shared, enabled
282 AR_CLASS(mrc p15, 0, r0, c1, c0, 0) @ Read SCTLR
283 AR_CLASS(bic r0, r0, #CR_BR) @ Disable the 'default mem-map'
284 AR_CLASS(orr r0, r0, #CR_M) @ Set SCTRL.M (MPU on)
285 AR_CLASS(mcr p15, 0, r0, c1, c0, 0) @ Enable MPU
287 M_CLASS(ldr r0, [r12, #MPU_CTRL])
288 M_CLASS(bic r0, #MPU_CTRL_PRIVDEFENA)
289 M_CLASS(orr r0, #MPU_CTRL_ENABLE)
290 M_CLASS(str r0, [r12, #MPU_CTRL])
298 * r6: pointer at mpu_rgn_info
301 ENTRY(__secondary_setup_mpu)
302 /* Probe for v7 PMSA compliance */
303 mrc p15, 0, r0, c0, c1, 4 @ Read ID_MMFR0
304 and r0, r0, #(MMFR0_PMSA) @ PMSA field
305 teq r0, #(MMFR0_PMSAv7) @ PMSA v7
308 /* Determine whether the D/I-side memory map is unified. We set the
309 * flags here and continue to use them for the rest of this function */
310 mrc p15, 0, r0, c0, c0, 4 @ MPUIR
311 ands r5, r0, #MPUIR_DREGION_SZMASK @ 0 size d region => No MPU
314 ldr r4, [r6, #MPU_RNG_INFO_USED]
315 mov r5, #MPU_RNG_SIZE
316 add r3, r6, #MPU_RNG_INFO_RNGS
320 tst r0, #MPUIR_nU @ MPUIR_nU = 0 for unified
321 sub r3, r3, #MPU_RNG_SIZE
327 ldr r0, [r3, #MPU_RGN_DRBAR]
328 ldr r6, [r3, #MPU_RGN_DRSR]
329 ldr r5, [r3, #MPU_RGN_DRACR]
331 setup_region r0, r5, r6, MPU_DATA_SIDE
333 setup_region r0, r5, r6, MPU_INSTR_SIDE
336 mrc p15, 0, r0, c0, c0, 4 @ Reevaluate the MPUIR
341 mrc p15, 0, r0, c1, c0, 0 @ Read SCTLR
342 bic r0, r0, #CR_BR @ Disable the 'default mem-map'
343 orr r0, r0, #CR_M @ Set SCTRL.M (MPU on)
344 mcr p15, 0, r0, c1, c0, 0 @ Enable MPU
348 ENDPROC(__secondary_setup_mpu)
350 #endif /* CONFIG_SMP */
351 #endif /* CONFIG_ARM_MPU */
352 #include "head-common.S"