Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/kernel/head-nommu.S |
| 3 | * |
| 4 | * Copyright (C) 1994-2002 Russell King |
| 5 | * Copyright (C) 2003-2006 Hyok S. Choi |
| 6 | * |
| 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. |
| 10 | * |
| 11 | * Common kernel startup code (non-paged MM) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 12 | * |
| 13 | */ |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 14 | #include <linux/linkage.h> |
| 15 | #include <linux/init.h> |
| 16 | |
| 17 | #include <asm/assembler.h> |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 18 | #include <asm/ptrace.h> |
Uwe Zeisberger | 2eb9d31 | 2006-05-05 15:11:14 +0100 | [diff] [blame] | 19 | #include <asm/asm-offsets.h> |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame] | 20 | #include <asm/memory.h> |
Russell King | 15d07dc | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 21 | #include <asm/cp15.h> |
Hyok S. Choi | 3b920ce | 2006-04-24 09:45:35 +0100 | [diff] [blame] | 22 | #include <asm/thread_info.h> |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 23 | #include <asm/v7m.h> |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame] | 24 | #include <asm/mpu.h> |
Jonathan Austin | 9dfc28b | 2013-04-18 18:37:24 +0100 | [diff] [blame] | 25 | #include <asm/page.h> |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 26 | |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 27 | /* |
| 28 | * Kernel startup entry point. |
| 29 | * --------------------------- |
| 30 | * |
| 31 | * This is normally called from the decompressor code. The requirements |
| 32 | * are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0, |
| 33 | * r1 = machine nr. |
| 34 | * |
| 35 | * See linux/arch/arm/tools/mach-types for the complete list of machine |
| 36 | * numbers for r1. |
| 37 | * |
| 38 | */ |
Dave Martin | 540b573 | 2011-07-13 15:53:30 +0100 | [diff] [blame] | 39 | |
Tim Abbott | 2abc1c5 | 2009-10-02 16:32:46 -0400 | [diff] [blame] | 40 | __HEAD |
Uwe Kleine-König | bc7dea0 | 2011-12-09 20:52:10 +0100 | [diff] [blame] | 41 | |
| 42 | #ifdef CONFIG_CPU_THUMBONLY |
| 43 | .thumb |
| 44 | ENTRY(stext) |
| 45 | #else |
| 46 | .arm |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 47 | ENTRY(stext) |
Dave Martin | 540b573 | 2011-07-13 15:53:30 +0100 | [diff] [blame] | 48 | |
Russell King | 14327c6 | 2015-04-21 14:17:25 +0100 | [diff] [blame] | 49 | THUMB( badr r9, 1f ) @ Kernel is always entered in ARM. |
Dave Martin | 540b573 | 2011-07-13 15:53:30 +0100 | [diff] [blame] | 50 | THUMB( bx r9 ) @ If this is a Thumb-2 kernel, |
| 51 | THUMB( .thumb ) @ switch to Thumb now. |
| 52 | THUMB(1: ) |
Uwe Kleine-König | bc7dea0 | 2011-12-09 20:52:10 +0100 | [diff] [blame] | 53 | #endif |
Dave Martin | 540b573 | 2011-07-13 15:53:30 +0100 | [diff] [blame] | 54 | |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 55 | setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 @ ensure svc mode |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 56 | @ and irqs disabled |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 57 | #if defined(CONFIG_CPU_CP15) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 58 | mrc p15, 0, r9, c0, c0 @ get processor id |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 59 | #elif defined(CONFIG_CPU_V7M) |
| 60 | ldr r9, =BASEADDR_V7M_SCB |
| 61 | ldr r9, [r9, V7M_SCB_CPUID] |
| 62 | #else |
| 63 | ldr r9, =CONFIG_PROCESSOR_ID |
Hyok S. Choi | f12d0d7 | 2006-09-26 17:36:37 +0900 | [diff] [blame] | 64 | #endif |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 65 | bl __lookup_processor_type @ r5=procinfo r9=cpuid |
| 66 | movs r10, r5 @ invalid processor (r5=0)? |
| 67 | beq __error_p @ yes, error 'p' |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 68 | |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame] | 69 | #ifdef CONFIG_ARM_MPU |
| 70 | /* Calculate the size of a region covering just the kernel */ |
Russell King | b713aa0 | 2013-12-10 19:21:08 +0000 | [diff] [blame] | 71 | ldr r5, =PLAT_PHYS_OFFSET @ Region start: PHYS_OFFSET |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame] | 72 | ldr r6, =(_end) @ Cover whole kernel |
| 73 | sub r6, r6, r5 @ Minimum size of region to map |
| 74 | clz r6, r6 @ Region size must be 2^N... |
| 75 | rsb r6, r6, #31 @ ...so round up region size |
| 76 | lsl r6, r6, #MPU_RSR_SZ @ Put size in right field |
| 77 | orr r6, r6, #(1 << MPU_RSR_EN) @ Set region enabled bit |
| 78 | bl __setup_mpu |
| 79 | #endif |
Stefan Agner | 970d96f | 2015-06-02 20:43:24 +0100 | [diff] [blame] | 80 | |
Russell King | 14327c6 | 2015-04-21 14:17:25 +0100 | [diff] [blame] | 81 | badr lr, 1f @ return (PIC) address |
Russell King | 0a9024e | 2015-04-19 20:28:53 +0100 | [diff] [blame] | 82 | ldr r12, [r10, #PROCINFO_INITFUNC] |
| 83 | add r12, r12, r10 |
| 84 | ret r12 |
Stefan Agner | 970d96f | 2015-06-02 20:43:24 +0100 | [diff] [blame] | 85 | 1: bl __after_proc_init |
| 86 | b __mmap_switched |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 87 | ENDPROC(stext) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 88 | |
Will Deacon | 01fafca | 2012-02-28 11:50:32 +0000 | [diff] [blame] | 89 | #ifdef CONFIG_SMP |
Russell King | 2449189 | 2013-07-31 11:37:17 +0100 | [diff] [blame] | 90 | .text |
Will Deacon | 01fafca | 2012-02-28 11:50:32 +0000 | [diff] [blame] | 91 | ENTRY(secondary_startup) |
| 92 | /* |
| 93 | * Common entry point for secondary CPUs. |
| 94 | * |
| 95 | * Ensure that we're in SVC mode, and IRQs are disabled. Lookup |
| 96 | * the processor type - there is no need to check the machine type |
| 97 | * as it has already been validated by the primary processor. |
| 98 | */ |
| 99 | setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 |
| 100 | #ifndef CONFIG_CPU_CP15 |
| 101 | ldr r9, =CONFIG_PROCESSOR_ID |
| 102 | #else |
| 103 | mrc p15, 0, r9, c0, c0 @ get processor id |
| 104 | #endif |
| 105 | bl __lookup_processor_type @ r5=procinfo r9=cpuid |
| 106 | movs r10, r5 @ invalid processor? |
| 107 | beq __error_p @ yes, error 'p' |
| 108 | |
Stefan Agner | 970d96f | 2015-06-02 20:43:24 +0100 | [diff] [blame] | 109 | ldr r7, __secondary_data |
Jonathan Austin | eb08375 | 2013-02-22 18:51:30 +0000 | [diff] [blame] | 110 | |
| 111 | #ifdef CONFIG_ARM_MPU |
| 112 | /* Use MPU region info supplied by __cpu_up */ |
| 113 | ldr r6, [r7] @ get secondary_data.mpu_szr |
| 114 | bl __setup_mpu @ Initialize the MPU |
| 115 | #endif |
| 116 | |
Stefan Agner | 970d96f | 2015-06-02 20:43:24 +0100 | [diff] [blame] | 117 | badr lr, 1f @ return (PIC) address |
Russell King | 0a9024e | 2015-04-19 20:28:53 +0100 | [diff] [blame] | 118 | ldr r12, [r10, #PROCINFO_INITFUNC] |
| 119 | add r12, r12, r10 |
| 120 | ret r12 |
Stefan Agner | 970d96f | 2015-06-02 20:43:24 +0100 | [diff] [blame] | 121 | 1: bl __after_proc_init |
Russell King | b2c3e38 | 2015-04-04 20:09:46 +0100 | [diff] [blame] | 122 | ldr sp, [r7, #12] @ set up the stack pointer |
Will Deacon | 01fafca | 2012-02-28 11:50:32 +0000 | [diff] [blame] | 123 | mov fp, #0 |
| 124 | b secondary_start_kernel |
Stefan Agner | 970d96f | 2015-06-02 20:43:24 +0100 | [diff] [blame] | 125 | ENDPROC(secondary_startup) |
Will Deacon | 01fafca | 2012-02-28 11:50:32 +0000 | [diff] [blame] | 126 | |
| 127 | .type __secondary_data, %object |
| 128 | __secondary_data: |
| 129 | .long secondary_data |
Will Deacon | 01fafca | 2012-02-28 11:50:32 +0000 | [diff] [blame] | 130 | #endif /* CONFIG_SMP */ |
| 131 | |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 132 | /* |
| 133 | * Set the Control Register and Read the process ID. |
| 134 | */ |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 135 | __after_proc_init: |
Hyok S. Choi | f12d0d7 | 2006-09-26 17:36:37 +0900 | [diff] [blame] | 136 | #ifdef CONFIG_CPU_CP15 |
Catalin Marinas | 05efde9 | 2009-07-24 12:34:59 +0100 | [diff] [blame] | 137 | /* |
| 138 | * CP15 system control register value returned in r0 from |
| 139 | * the CPU init function. |
| 140 | */ |
Armando Visconti | 76e0920 | 2012-12-04 10:34:39 +0100 | [diff] [blame] | 141 | #if defined(CONFIG_ALIGNMENT_TRAP) && __LINUX_ARM_ARCH__ < 6 |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 142 | orr r0, r0, #CR_A |
| 143 | #else |
| 144 | bic r0, r0, #CR_A |
| 145 | #endif |
| 146 | #ifdef CONFIG_CPU_DCACHE_DISABLE |
| 147 | bic r0, r0, #CR_C |
| 148 | #endif |
| 149 | #ifdef CONFIG_CPU_BPREDICT_DISABLE |
| 150 | bic r0, r0, #CR_Z |
| 151 | #endif |
| 152 | #ifdef CONFIG_CPU_ICACHE_DISABLE |
| 153 | bic r0, r0, #CR_I |
| 154 | #endif |
Hyok S. Choi | 6afd6fa | 2006-09-28 21:46:34 +0900 | [diff] [blame] | 155 | #ifdef CONFIG_CPU_HIGH_VECTOR |
| 156 | orr r0, r0, #CR_V |
| 157 | #else |
| 158 | bic r0, r0, #CR_V |
| 159 | #endif |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 160 | mcr p15, 0, r0, c1, c0, 0 @ write control reg |
Hyok S. Choi | f12d0d7 | 2006-09-26 17:36:37 +0900 | [diff] [blame] | 161 | #endif /* CONFIG_CPU_CP15 */ |
Stefan Agner | 970d96f | 2015-06-02 20:43:24 +0100 | [diff] [blame] | 162 | ret lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 163 | ENDPROC(__after_proc_init) |
Hyok S. Choi | 3b920ce | 2006-04-24 09:45:35 +0100 | [diff] [blame] | 164 | .ltorg |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 165 | |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame] | 166 | #ifdef CONFIG_ARM_MPU |
| 167 | |
| 168 | |
| 169 | /* Set which MPU region should be programmed */ |
| 170 | .macro set_region_nr tmp, rgnr |
| 171 | mov \tmp, \rgnr @ Use static region numbers |
| 172 | mcr p15, 0, \tmp, c6, c2, 0 @ Write RGNR |
| 173 | .endm |
| 174 | |
| 175 | /* Setup a single MPU region, either D or I side (D-side for unified) */ |
| 176 | .macro setup_region bar, acr, sr, side = MPU_DATA_SIDE |
| 177 | mcr p15, 0, \bar, c6, c1, (0 + \side) @ I/DRBAR |
| 178 | mcr p15, 0, \acr, c6, c1, (4 + \side) @ I/DRACR |
| 179 | mcr p15, 0, \sr, c6, c1, (2 + \side) @ I/DRSR |
| 180 | .endm |
| 181 | |
| 182 | /* |
| 183 | * Setup the MPU and initial MPU Regions. We create the following regions: |
| 184 | * Region 0: Use this for probing the MPU details, so leave disabled. |
| 185 | * Region 1: Background region - covers the whole of RAM as strongly ordered |
| 186 | * Region 2: Normal, Shared, cacheable for RAM. From PHYS_OFFSET, size from r6 |
Jonathan Austin | 9dfc28b | 2013-04-18 18:37:24 +0100 | [diff] [blame] | 187 | * Region 3: Normal, shared, inaccessible from PL0 to protect the vectors page |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame] | 188 | * |
| 189 | * r6: Value to be written to DRSR (and IRSR if required) for MPU_RAM_REGION |
| 190 | */ |
| 191 | |
| 192 | ENTRY(__setup_mpu) |
| 193 | |
| 194 | /* Probe for v7 PMSA compliance */ |
| 195 | mrc p15, 0, r0, c0, c1, 4 @ Read ID_MMFR0 |
| 196 | and r0, r0, #(MMFR0_PMSA) @ PMSA field |
| 197 | teq r0, #(MMFR0_PMSAv7) @ PMSA v7 |
| 198 | bne __error_p @ Fail: ARM_MPU on NOT v7 PMSA |
| 199 | |
| 200 | /* Determine whether the D/I-side memory map is unified. We set the |
| 201 | * flags here and continue to use them for the rest of this function */ |
| 202 | mrc p15, 0, r0, c0, c0, 4 @ MPUIR |
| 203 | ands r5, r0, #MPUIR_DREGION_SZMASK @ 0 size d region => No MPU |
| 204 | beq __error_p @ Fail: ARM_MPU and no MPU |
| 205 | tst r0, #MPUIR_nU @ MPUIR_nU = 0 for unified |
| 206 | |
| 207 | /* Setup second region first to free up r6 */ |
| 208 | set_region_nr r0, #MPU_RAM_REGION |
| 209 | isb |
| 210 | /* Full access from PL0, PL1, shared for CONFIG_SMP, cacheable */ |
Russell King | b713aa0 | 2013-12-10 19:21:08 +0000 | [diff] [blame] | 211 | ldr r0, =PLAT_PHYS_OFFSET @ RAM starts at PHYS_OFFSET |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame] | 212 | ldr r5,=(MPU_AP_PL1RW_PL0RW | MPU_RGN_NORMAL) |
| 213 | |
| 214 | setup_region r0, r5, r6, MPU_DATA_SIDE @ PHYS_OFFSET, shared, enabled |
| 215 | beq 1f @ Memory-map not unified |
| 216 | setup_region r0, r5, r6, MPU_INSTR_SIDE @ PHYS_OFFSET, shared, enabled |
| 217 | 1: isb |
| 218 | |
| 219 | /* First/background region */ |
| 220 | set_region_nr r0, #MPU_BG_REGION |
| 221 | isb |
| 222 | /* Execute Never, strongly ordered, inaccessible to PL0, rw PL1 */ |
| 223 | mov r0, #0 @ BG region starts at 0x0 |
| 224 | ldr r5,=(MPU_ACR_XN | MPU_RGN_STRONGLY_ORDERED | MPU_AP_PL1RW_PL0NA) |
| 225 | mov r6, #MPU_RSR_ALL_MEM @ 4GB region, enabled |
| 226 | |
| 227 | setup_region r0, r5, r6, MPU_DATA_SIDE @ 0x0, BG region, enabled |
| 228 | beq 2f @ Memory-map not unified |
| 229 | setup_region r0, r5, r6, MPU_INSTR_SIDE @ 0x0, BG region, enabled |
| 230 | 2: isb |
| 231 | |
Jonathan Austin | 9dfc28b | 2013-04-18 18:37:24 +0100 | [diff] [blame] | 232 | /* Vectors region */ |
| 233 | set_region_nr r0, #MPU_VECTORS_REGION |
| 234 | isb |
| 235 | /* Shared, inaccessible to PL0, rw PL1 */ |
| 236 | mov r0, #CONFIG_VECTORS_BASE @ Cover from VECTORS_BASE |
| 237 | ldr r5,=(MPU_AP_PL1RW_PL0NA | MPU_RGN_NORMAL) |
| 238 | /* Writing N to bits 5:1 (RSR_SZ) --> region size 2^N+1 */ |
| 239 | mov r6, #(((PAGE_SHIFT - 1) << MPU_RSR_SZ) | 1 << MPU_RSR_EN) |
| 240 | |
| 241 | setup_region r0, r5, r6, MPU_DATA_SIDE @ VECTORS_BASE, PL0 NA, enabled |
| 242 | beq 3f @ Memory-map not unified |
| 243 | setup_region r0, r5, r6, MPU_INSTR_SIDE @ VECTORS_BASE, PL0 NA, enabled |
| 244 | 3: isb |
| 245 | |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame] | 246 | /* Enable the MPU */ |
| 247 | mrc p15, 0, r0, c1, c0, 0 @ Read SCTLR |
| 248 | bic r0, r0, #CR_BR @ Disable the 'default mem-map' |
| 249 | orr r0, r0, #CR_M @ Set SCTRL.M (MPU on) |
| 250 | mcr p15, 0, r0, c1, c0, 0 @ Enable MPU |
| 251 | isb |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 252 | ret lr |
Jonathan Austin | 67c9845 | 2013-02-22 17:48:56 +0000 | [diff] [blame] | 253 | ENDPROC(__setup_mpu) |
| 254 | #endif |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 255 | #include "head-common.S" |