proc-macros.S 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*
  2. * We need constants.h for:
  3. * VMA_VM_MM
  4. * VMA_VM_FLAGS
  5. * VM_EXEC
  6. */
  7. #include <asm/asm-offsets.h>
  8. #include <asm/thread_info.h>
  9. #ifdef CONFIG_CPU_V7M
  10. #include <asm/v7m.h>
  11. #endif
  12. /*
  13. * vma_vm_mm - get mm pointer from vma pointer (vma->vm_mm)
  14. */
  15. .macro vma_vm_mm, rd, rn
  16. ldr \rd, [\rn, #VMA_VM_MM]
  17. .endm
  18. /*
  19. * vma_vm_flags - get vma->vm_flags
  20. */
  21. .macro vma_vm_flags, rd, rn
  22. ldr \rd, [\rn, #VMA_VM_FLAGS]
  23. .endm
  24. .macro tsk_mm, rd, rn
  25. ldr \rd, [\rn, #TI_TASK]
  26. ldr \rd, [\rd, #TSK_ACTIVE_MM]
  27. .endm
  28. /*
  29. * act_mm - get current->active_mm
  30. */
  31. .macro act_mm, rd
  32. bic \rd, sp, #8128
  33. bic \rd, \rd, #63
  34. ldr \rd, [\rd, #TI_TASK]
  35. ldr \rd, [\rd, #TSK_ACTIVE_MM]
  36. .endm
  37. /*
  38. * mmid - get context id from mm pointer (mm->context.id)
  39. * note, this field is 64bit, so in big-endian the two words are swapped too.
  40. */
  41. .macro mmid, rd, rn
  42. #ifdef __ARMEB__
  43. ldr \rd, [\rn, #MM_CONTEXT_ID + 4 ]
  44. #else
  45. ldr \rd, [\rn, #MM_CONTEXT_ID]
  46. #endif
  47. .endm
  48. /*
  49. * mask_asid - mask the ASID from the context ID
  50. */
  51. .macro asid, rd, rn
  52. and \rd, \rn, #255
  53. .endm
  54. .macro crval, clear, mmuset, ucset
  55. #ifdef CONFIG_MMU
  56. .word \clear
  57. .word \mmuset
  58. #else
  59. .word \clear
  60. .word \ucset
  61. #endif
  62. .endm
  63. /*
  64. * dcache_line_size - get the minimum D-cache line size from the CTR register
  65. * on ARMv7.
  66. */
  67. .macro dcache_line_size, reg, tmp
  68. #ifdef CONFIG_CPU_V7M
  69. movw \tmp, #:lower16:BASEADDR_V7M_SCB + V7M_SCB_CTR
  70. movt \tmp, #:upper16:BASEADDR_V7M_SCB + V7M_SCB_CTR
  71. ldr \tmp, [\tmp]
  72. #else
  73. mrc p15, 0, \tmp, c0, c0, 1 @ read ctr
  74. #endif
  75. lsr \tmp, \tmp, #16
  76. and \tmp, \tmp, #0xf @ cache line size encoding
  77. mov \reg, #4 @ bytes per word
  78. mov \reg, \reg, lsl \tmp @ actual cache line size
  79. .endm
  80. /*
  81. * icache_line_size - get the minimum I-cache line size from the CTR register
  82. * on ARMv7.
  83. */
  84. .macro icache_line_size, reg, tmp
  85. #ifdef CONFIG_CPU_V7M
  86. movw \tmp, #:lower16:BASEADDR_V7M_SCB + V7M_SCB_CTR
  87. movt \tmp, #:upper16:BASEADDR_V7M_SCB + V7M_SCB_CTR
  88. ldr \tmp, [\tmp]
  89. #else
  90. mrc p15, 0, \tmp, c0, c0, 1 @ read ctr
  91. #endif
  92. and \tmp, \tmp, #0xf @ cache line size encoding
  93. mov \reg, #4 @ bytes per word
  94. mov \reg, \reg, lsl \tmp @ actual cache line size
  95. .endm
  96. /*
  97. * Sanity check the PTE configuration for the code below - which makes
  98. * certain assumptions about how these bits are laid out.
  99. */
  100. #ifdef CONFIG_MMU
  101. #if L_PTE_SHARED != PTE_EXT_SHARED
  102. #error PTE shared bit mismatch
  103. #endif
  104. #if !defined (CONFIG_ARM_LPAE) && \
  105. (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
  106. L_PTE_PRESENT) > L_PTE_SHARED
  107. #error Invalid Linux PTE bit settings
  108. #endif
  109. #endif /* CONFIG_MMU */
  110. /*
  111. * The ARMv6 and ARMv7 set_pte_ext translation function.
  112. *
  113. * Permission translation:
  114. * YUWD APX AP1 AP0 SVC User
  115. * 0xxx 0 0 0 no acc no acc
  116. * 100x 1 0 1 r/o no acc
  117. * 10x0 1 0 1 r/o no acc
  118. * 1011 0 0 1 r/w no acc
  119. * 110x 1 1 1 r/o r/o
  120. * 11x0 1 1 1 r/o r/o
  121. * 1111 0 1 1 r/w r/w
  122. */
  123. .macro armv6_mt_table pfx
  124. \pfx\()_mt_table:
  125. .long 0x00 @ L_PTE_MT_UNCACHED
  126. .long PTE_EXT_TEX(1) @ L_PTE_MT_BUFFERABLE
  127. .long PTE_CACHEABLE @ L_PTE_MT_WRITETHROUGH
  128. .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEBACK
  129. .long PTE_BUFFERABLE @ L_PTE_MT_DEV_SHARED
  130. .long 0x00 @ unused
  131. .long 0x00 @ L_PTE_MT_MINICACHE (not present)
  132. .long PTE_EXT_TEX(1) | PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEALLOC
  133. .long 0x00 @ unused
  134. .long PTE_EXT_TEX(1) @ L_PTE_MT_DEV_WC
  135. .long 0x00 @ unused
  136. .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_DEV_CACHED
  137. .long PTE_EXT_TEX(2) @ L_PTE_MT_DEV_NONSHARED
  138. .long 0x00 @ unused
  139. .long 0x00 @ unused
  140. .long PTE_CACHEABLE | PTE_BUFFERABLE | PTE_EXT_APX @ L_PTE_MT_VECTORS
  141. .endm
  142. .macro armv6_set_pte_ext pfx
  143. str r1, [r0], #2048 @ linux version
  144. bic r3, r1, #0x000003fc
  145. bic r3, r3, #PTE_TYPE_MASK
  146. orr r3, r3, r2
  147. orr r3, r3, #PTE_EXT_AP0 | 2
  148. adr ip, \pfx\()_mt_table
  149. and r2, r1, #L_PTE_MT_MASK
  150. ldr r2, [ip, r2]
  151. eor r1, r1, #L_PTE_DIRTY
  152. tst r1, #L_PTE_DIRTY|L_PTE_RDONLY
  153. orrne r3, r3, #PTE_EXT_APX
  154. tst r1, #L_PTE_USER
  155. orrne r3, r3, #PTE_EXT_AP1
  156. tstne r3, #PTE_EXT_APX
  157. @ user read-only -> kernel read-only
  158. bicne r3, r3, #PTE_EXT_AP0
  159. tst r1, #L_PTE_XN
  160. orrne r3, r3, #PTE_EXT_XN
  161. eor r3, r3, r2
  162. tst r1, #L_PTE_YOUNG
  163. tstne r1, #L_PTE_PRESENT
  164. moveq r3, #0
  165. tstne r1, #L_PTE_NONE
  166. movne r3, #0
  167. str r3, [r0]
  168. mcr p15, 0, r0, c7, c10, 1 @ flush_pte
  169. .endm
  170. /*
  171. * The ARMv3, ARMv4 and ARMv5 set_pte_ext translation function,
  172. * covering most CPUs except Xscale and Xscale 3.
  173. *
  174. * Permission translation:
  175. * YUWD AP SVC User
  176. * 0xxx 0x00 no acc no acc
  177. * 100x 0x00 r/o no acc
  178. * 10x0 0x00 r/o no acc
  179. * 1011 0x55 r/w no acc
  180. * 110x 0xaa r/w r/o
  181. * 11x0 0xaa r/w r/o
  182. * 1111 0xff r/w r/w
  183. */
  184. .macro armv3_set_pte_ext wc_disable=1
  185. str r1, [r0], #2048 @ linux version
  186. eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY
  187. bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits
  188. bic r2, r2, #PTE_TYPE_MASK
  189. orr r2, r2, #PTE_TYPE_SMALL
  190. tst r3, #L_PTE_USER @ user?
  191. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  192. tst r3, #L_PTE_RDONLY | L_PTE_DIRTY @ write and dirty?
  193. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  194. tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young?
  195. movne r2, #0
  196. .if \wc_disable
  197. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  198. tst r2, #PTE_CACHEABLE
  199. bicne r2, r2, #PTE_BUFFERABLE
  200. #endif
  201. .endif
  202. str r2, [r0] @ hardware version
  203. .endm
  204. /*
  205. * Xscale set_pte_ext translation, split into two halves to cope
  206. * with work-arounds. r3 must be preserved by code between these
  207. * two macros.
  208. *
  209. * Permission translation:
  210. * YUWD AP SVC User
  211. * 0xxx 00 no acc no acc
  212. * 100x 00 r/o no acc
  213. * 10x0 00 r/o no acc
  214. * 1011 01 r/w no acc
  215. * 110x 10 r/w r/o
  216. * 11x0 10 r/w r/o
  217. * 1111 11 r/w r/w
  218. */
  219. .macro xscale_set_pte_ext_prologue
  220. str r1, [r0] @ linux version
  221. eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY
  222. bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits
  223. orr r2, r2, #PTE_TYPE_EXT @ extended page
  224. tst r3, #L_PTE_USER @ user?
  225. orrne r2, r2, #PTE_EXT_AP_URO_SRW @ yes -> user r/o, system r/w
  226. tst r3, #L_PTE_RDONLY | L_PTE_DIRTY @ write and dirty?
  227. orreq r2, r2, #PTE_EXT_AP_UNO_SRW @ yes -> user n/a, system r/w
  228. @ combined with user -> user r/w
  229. .endm
  230. .macro xscale_set_pte_ext_epilogue
  231. tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young?
  232. movne r2, #0 @ no -> fault
  233. str r2, [r0, #2048]! @ hardware version
  234. mov ip, #0
  235. mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line
  236. mcr p15, 0, ip, c7, c10, 4 @ data write barrier
  237. .endm
  238. .macro define_processor_functions name:req, dabort:req, pabort:req, nommu=0, suspend=0
  239. .type \name\()_processor_functions, #object
  240. .align 2
  241. ENTRY(\name\()_processor_functions)
  242. .word \dabort
  243. .word \pabort
  244. .word cpu_\name\()_proc_init
  245. .word cpu_\name\()_proc_fin
  246. .word cpu_\name\()_reset
  247. .word cpu_\name\()_do_idle
  248. .word cpu_\name\()_dcache_clean_area
  249. .word cpu_\name\()_switch_mm
  250. .if \nommu
  251. .word 0
  252. .else
  253. .word cpu_\name\()_set_pte_ext
  254. .endif
  255. .if \suspend
  256. .word cpu_\name\()_suspend_size
  257. #ifdef CONFIG_ARM_CPU_SUSPEND
  258. .word cpu_\name\()_do_suspend
  259. .word cpu_\name\()_do_resume
  260. #else
  261. .word 0
  262. .word 0
  263. #endif
  264. .else
  265. .word 0
  266. .word 0
  267. .word 0
  268. .endif
  269. .size \name\()_processor_functions, . - \name\()_processor_functions
  270. .endm
  271. .macro define_cache_functions name:req
  272. .align 2
  273. .type \name\()_cache_fns, #object
  274. ENTRY(\name\()_cache_fns)
  275. .long \name\()_flush_icache_all
  276. .long \name\()_flush_kern_cache_all
  277. .long \name\()_flush_kern_cache_louis
  278. .long \name\()_flush_user_cache_all
  279. .long \name\()_flush_user_cache_range
  280. .long \name\()_coherent_kern_range
  281. .long \name\()_coherent_user_range
  282. .long \name\()_flush_kern_dcache_area
  283. .long \name\()_dma_map_area
  284. .long \name\()_dma_unmap_area
  285. .long \name\()_dma_flush_range
  286. .size \name\()_cache_fns, . - \name\()_cache_fns
  287. .endm
  288. .macro define_tlb_functions name:req, flags_up:req, flags_smp
  289. .type \name\()_tlb_fns, #object
  290. ENTRY(\name\()_tlb_fns)
  291. .long \name\()_flush_user_tlb_range
  292. .long \name\()_flush_kern_tlb_range
  293. .ifnb \flags_smp
  294. ALT_SMP(.long \flags_smp )
  295. ALT_UP(.long \flags_up )
  296. .else
  297. .long \flags_up
  298. .endif
  299. .size \name\()_tlb_fns, . - \name\()_tlb_fns
  300. .endm
  301. .macro globl_equ x, y
  302. .globl \x
  303. .equ \x, \y
  304. .endm
  305. .macro initfn, func, base
  306. .long \func - \base
  307. .endm
  308. /*
  309. * Macro to calculate the log2 size for the protection region
  310. * registers. This calculates rd = log2(size) - 1. tmp must
  311. * not be the same register as rd.
  312. */
  313. .macro pr_sz, rd, size, tmp
  314. mov \tmp, \size, lsr #12
  315. mov \rd, #11
  316. 1: movs \tmp, \tmp, lsr #1
  317. addne \rd, \rd, #1
  318. bne 1b
  319. .endm
  320. /*
  321. * Macro to generate a protection region register value
  322. * given a pre-masked address, size, and enable bit.
  323. * Corrupts size.
  324. */
  325. .macro pr_val, dest, addr, size, enable
  326. pr_sz \dest, \size, \size @ calculate log2(size) - 1
  327. orr \dest, \addr, \dest, lsl #1 @ mask in the region size
  328. orr \dest, \dest, \enable
  329. .endm