proc-macros.S 7.7 KB

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