proc-v6.S 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * linux/arch/arm/mm/proc-v6.S
  4. *
  5. * Copyright (C) 2001 Deep Blue Solutions Ltd.
  6. * Modified by Catalin Marinas for noMMU support
  7. *
  8. * This is the "shell" of the ARMv6 processor support.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/cfi_types.h>
  12. #include <linux/linkage.h>
  13. #include <linux/pgtable.h>
  14. #include <asm/assembler.h>
  15. #include <asm/asm-offsets.h>
  16. #include <asm/hwcap.h>
  17. #include <asm/pgtable-hwdef.h>
  18. #include "proc-macros.S"
  19. #define D_CACHE_LINE_SIZE 32
  20. #define TTB_C (1 << 0)
  21. #define TTB_S (1 << 1)
  22. #define TTB_IMP (1 << 2)
  23. #define TTB_RGN_NC (0 << 3)
  24. #define TTB_RGN_WBWA (1 << 3)
  25. #define TTB_RGN_WT (2 << 3)
  26. #define TTB_RGN_WB (3 << 3)
  27. #define TTB_FLAGS_UP TTB_RGN_WBWA
  28. #define PMD_FLAGS_UP PMD_SECT_WB
  29. #define TTB_FLAGS_SMP TTB_RGN_WBWA|TTB_S
  30. #define PMD_FLAGS_SMP PMD_SECT_WBWA|PMD_SECT_S
  31. .arch armv6
  32. SYM_TYPED_FUNC_START(cpu_v6_proc_init)
  33. ret lr
  34. SYM_FUNC_END(cpu_v6_proc_init)
  35. SYM_TYPED_FUNC_START(cpu_v6_proc_fin)
  36. mrc p15, 0, r0, c1, c0, 0 @ ctrl register
  37. bic r0, r0, #0x1000 @ ...i............
  38. bic r0, r0, #0x0006 @ .............ca.
  39. mcr p15, 0, r0, c1, c0, 0 @ disable caches
  40. ret lr
  41. SYM_FUNC_END(cpu_v6_proc_fin)
  42. /*
  43. * cpu_v6_reset(loc)
  44. *
  45. * Perform a soft reset of the system. Put the CPU into the
  46. * same state as it would be if it had been reset, and branch
  47. * to what would be the reset vector.
  48. *
  49. * - loc - location to jump to for soft reset
  50. */
  51. .align 5
  52. .pushsection .idmap.text, "ax"
  53. SYM_TYPED_FUNC_START(cpu_v6_reset)
  54. mrc p15, 0, r1, c1, c0, 0 @ ctrl register
  55. bic r1, r1, #0x1 @ ...............m
  56. mcr p15, 0, r1, c1, c0, 0 @ disable MMU
  57. mov r1, #0
  58. mcr p15, 0, r1, c7, c5, 4 @ ISB
  59. ret r0
  60. SYM_FUNC_END(cpu_v6_reset)
  61. .popsection
  62. /*
  63. * cpu_v6_do_idle()
  64. *
  65. * Idle the processor (eg, wait for interrupt).
  66. *
  67. * IRQs are already disabled.
  68. */
  69. SYM_TYPED_FUNC_START(cpu_v6_do_idle)
  70. mov r1, #0
  71. mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  72. mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  73. ret lr
  74. SYM_FUNC_END(cpu_v6_do_idle)
  75. SYM_TYPED_FUNC_START(cpu_v6_dcache_clean_area)
  76. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  77. add r0, r0, #D_CACHE_LINE_SIZE
  78. subs r1, r1, #D_CACHE_LINE_SIZE
  79. bhi 1b
  80. ret lr
  81. SYM_FUNC_END(cpu_v6_dcache_clean_area)
  82. /*
  83. * cpu_v6_switch_mm(pgd_phys, tsk)
  84. *
  85. * Set the translation table base pointer to be pgd_phys
  86. *
  87. * - pgd_phys - physical address of new TTB
  88. *
  89. * It is assumed that:
  90. * - we are not using split page tables
  91. */
  92. SYM_TYPED_FUNC_START(cpu_v6_switch_mm)
  93. #ifdef CONFIG_MMU
  94. mov r2, #0
  95. mmid r1, r1 @ get mm->context.id
  96. ALT_SMP(orr r0, r0, #TTB_FLAGS_SMP)
  97. ALT_UP(orr r0, r0, #TTB_FLAGS_UP)
  98. mcr p15, 0, r2, c7, c5, 6 @ flush BTAC/BTB
  99. mcr p15, 0, r2, c7, c10, 4 @ drain write buffer
  100. mcr p15, 0, r0, c2, c0, 0 @ set TTB 0
  101. #ifdef CONFIG_PID_IN_CONTEXTIDR
  102. mrc p15, 0, r2, c13, c0, 1 @ read current context ID
  103. bic r2, r2, #0xff @ extract the PID
  104. and r1, r1, #0xff
  105. orr r1, r1, r2 @ insert into new context ID
  106. #endif
  107. mcr p15, 0, r1, c13, c0, 1 @ set context ID
  108. #endif
  109. ret lr
  110. SYM_FUNC_END(cpu_v6_switch_mm)
  111. /*
  112. * cpu_v6_set_pte_ext(ptep, pte, ext)
  113. *
  114. * Set a level 2 translation table entry.
  115. *
  116. * - ptep - pointer to level 2 translation table entry
  117. * (hardware version is stored at -1024 bytes)
  118. * - pte - PTE value to store
  119. * - ext - value for extended PTE bits
  120. */
  121. armv6_mt_table cpu_v6
  122. SYM_TYPED_FUNC_START(cpu_v6_set_pte_ext)
  123. #ifdef CONFIG_MMU
  124. armv6_set_pte_ext cpu_v6
  125. #endif
  126. ret lr
  127. SYM_FUNC_END(cpu_v6_set_pte_ext)
  128. /* Suspend/resume support: taken from arch/arm/mach-s3c64xx/sleep.S */
  129. .globl cpu_v6_suspend_size
  130. .equ cpu_v6_suspend_size, 4 * 6
  131. #ifdef CONFIG_ARM_CPU_SUSPEND
  132. SYM_TYPED_FUNC_START(cpu_v6_do_suspend)
  133. stmfd sp!, {r4 - r9, lr}
  134. mrc p15, 0, r4, c13, c0, 0 @ FCSE/PID
  135. #ifdef CONFIG_MMU
  136. mrc p15, 0, r5, c3, c0, 0 @ Domain ID
  137. mrc p15, 0, r6, c2, c0, 1 @ Translation table base 1
  138. #endif
  139. mrc p15, 0, r7, c1, c0, 1 @ auxiliary control register
  140. mrc p15, 0, r8, c1, c0, 2 @ co-processor access control
  141. mrc p15, 0, r9, c1, c0, 0 @ control register
  142. stmia r0, {r4 - r9}
  143. ldmfd sp!, {r4- r9, pc}
  144. SYM_FUNC_END(cpu_v6_do_suspend)
  145. SYM_TYPED_FUNC_START(cpu_v6_do_resume)
  146. mov ip, #0
  147. mcr p15, 0, ip, c7, c14, 0 @ clean+invalidate D cache
  148. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  149. mcr p15, 0, ip, c7, c15, 0 @ clean+invalidate cache
  150. mcr p15, 0, ip, c7, c10, 4 @ drain write buffer
  151. mcr p15, 0, ip, c13, c0, 1 @ set reserved context ID
  152. ldmia r0, {r4 - r9}
  153. mcr p15, 0, r4, c13, c0, 0 @ FCSE/PID
  154. #ifdef CONFIG_MMU
  155. mcr p15, 0, r5, c3, c0, 0 @ Domain ID
  156. ALT_SMP(orr r1, r1, #TTB_FLAGS_SMP)
  157. ALT_UP(orr r1, r1, #TTB_FLAGS_UP)
  158. mcr p15, 0, r1, c2, c0, 0 @ Translation table base 0
  159. mcr p15, 0, r6, c2, c0, 1 @ Translation table base 1
  160. mcr p15, 0, ip, c2, c0, 2 @ TTB control register
  161. #endif
  162. mcr p15, 0, r7, c1, c0, 1 @ auxiliary control register
  163. mcr p15, 0, r8, c1, c0, 2 @ co-processor access control
  164. mcr p15, 0, ip, c7, c5, 4 @ ISB
  165. mov r0, r9 @ control register
  166. b cpu_resume_mmu
  167. SYM_FUNC_END(cpu_v6_do_resume)
  168. #endif
  169. string cpu_v6_name, "ARMv6-compatible processor"
  170. .align
  171. /*
  172. * __v6_setup
  173. *
  174. * Initialise TLB, Caches, and MMU state ready to switch the MMU
  175. * on. Return in r0 the new CP15 C1 control register setting.
  176. *
  177. * We automatically detect if we have a Harvard cache, and use the
  178. * Harvard cache control instructions insead of the unified cache
  179. * control instructions.
  180. *
  181. * This should be able to cover all ARMv6 cores.
  182. *
  183. * It is assumed that:
  184. * - cache type register is implemented
  185. */
  186. __v6_setup:
  187. #ifdef CONFIG_SMP
  188. ALT_SMP(mrc p15, 0, r0, c1, c0, 1) @ Enable SMP/nAMP mode
  189. ALT_UP(nop)
  190. orr r0, r0, #0x20
  191. ALT_SMP(mcr p15, 0, r0, c1, c0, 1)
  192. ALT_UP(nop)
  193. #endif
  194. mov r0, #0
  195. mcr p15, 0, r0, c7, c14, 0 @ clean+invalidate D cache
  196. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  197. mcr p15, 0, r0, c7, c15, 0 @ clean+invalidate cache
  198. #ifdef CONFIG_MMU
  199. mcr p15, 0, r0, c8, c7, 0 @ invalidate I + D TLBs
  200. mcr p15, 0, r0, c2, c0, 2 @ TTB control register
  201. ALT_SMP(orr r4, r4, #TTB_FLAGS_SMP)
  202. ALT_UP(orr r4, r4, #TTB_FLAGS_UP)
  203. ALT_SMP(orr r8, r8, #TTB_FLAGS_SMP)
  204. ALT_UP(orr r8, r8, #TTB_FLAGS_UP)
  205. mcr p15, 0, r8, c2, c0, 1 @ load TTB1
  206. #endif /* CONFIG_MMU */
  207. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer and
  208. @ complete invalidations
  209. adr r5, v6_crval
  210. ldmia r5, {r5, r6}
  211. ARM_BE8(orr r6, r6, #1 << 25) @ big-endian page tables
  212. mrc p15, 0, r0, c1, c0, 0 @ read control register
  213. bic r0, r0, r5 @ clear bits them
  214. orr r0, r0, r6 @ set them
  215. #ifdef CONFIG_ARM_ERRATA_364296
  216. /*
  217. * Workaround for the 364296 ARM1136 r0p2 erratum (possible cache data
  218. * corruption with hit-under-miss enabled). The conditional code below
  219. * (setting the undocumented bit 31 in the auxiliary control register
  220. * and the FI bit in the control register) disables hit-under-miss
  221. * without putting the processor into full low interrupt latency mode.
  222. */
  223. ldr r6, =0x4107b362 @ id for ARM1136 r0p2
  224. mrc p15, 0, r5, c0, c0, 0 @ get processor id
  225. teq r5, r6 @ check for the faulty core
  226. mrceq p15, 0, r5, c1, c0, 1 @ load aux control reg
  227. orreq r5, r5, #(1 << 31) @ set the undocumented bit 31
  228. mcreq p15, 0, r5, c1, c0, 1 @ write aux control reg
  229. orreq r0, r0, #(1 << 21) @ low interrupt latency configuration
  230. #endif
  231. ret lr @ return to head.S:__ret
  232. /*
  233. * V X F I D LR
  234. * .... ...E PUI. .T.T 4RVI ZFRS BLDP WCAM
  235. * rrrr rrrx xxx0 0101 xxxx xxxx x111 xxxx < forced
  236. * 0 110 0011 1.00 .111 1101 < we want
  237. */
  238. .type v6_crval, #object
  239. v6_crval:
  240. crval clear=0x01e0fb7f, mmuset=0x00c0387d, ucset=0x00c0187c
  241. __INITDATA
  242. @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
  243. define_processor_functions v6, dabort=v6_early_abort, pabort=v6_pabort, suspend=1
  244. .section ".rodata"
  245. string cpu_arch_name, "armv6"
  246. string cpu_elf_name, "v6"
  247. .align
  248. .section ".proc.info.init", "a"
  249. /*
  250. * Match any ARMv6 processor core.
  251. */
  252. .type __v6_proc_info, #object
  253. __v6_proc_info:
  254. .long 0x0007b000
  255. .long 0x0007f000
  256. ALT_SMP(.long \
  257. PMD_TYPE_SECT | \
  258. PMD_SECT_AP_WRITE | \
  259. PMD_SECT_AP_READ | \
  260. PMD_FLAGS_SMP)
  261. ALT_UP(.long \
  262. PMD_TYPE_SECT | \
  263. PMD_SECT_AP_WRITE | \
  264. PMD_SECT_AP_READ | \
  265. PMD_FLAGS_UP)
  266. .long PMD_TYPE_SECT | \
  267. PMD_SECT_XN | \
  268. PMD_SECT_AP_WRITE | \
  269. PMD_SECT_AP_READ
  270. initfn __v6_setup, __v6_proc_info
  271. .long cpu_arch_name
  272. .long cpu_elf_name
  273. /* See also feat_v6_fixup() for HWCAP_TLS */
  274. .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_JAVA|HWCAP_TLS
  275. .long cpu_v6_name
  276. .long v6_processor_functions
  277. .long v6wbi_tlb_fns
  278. .long v6_user_fns
  279. .long v6_cache_fns
  280. .size __v6_proc_info, . - __v6_proc_info