proc-v6.S 8.1 KB

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