head-nommu.S 7.6 KB

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