proc-macros.S 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\
  85. L_PTE_FILE+L_PTE_PRESENT) > L_PTE_SHARED
  86. #error Invalid Linux PTE bit settings
  87. #endif
  88. #endif /* CONFIG_MMU */
  89. /*
  90. * The ARMv6 and ARMv7 set_pte_ext translation function.
  91. *
  92. * Permission translation:
  93. * YUWD APX AP1 AP0 SVC User
  94. * 0xxx 0 0 0 no acc no acc
  95. * 100x 1 0 1 r/o no acc
  96. * 10x0 1 0 1 r/o no acc
  97. * 1011 0 0 1 r/w no acc
  98. * 110x 0 1 0 r/w r/o
  99. * 11x0 0 1 0 r/w r/o
  100. * 1111 0 1 1 r/w r/w
  101. *
  102. * If !CONFIG_CPU_USE_DOMAINS, the following permissions are changed:
  103. * 110x 1 1 1 r/o r/o
  104. * 11x0 1 1 1 r/o r/o
  105. */
  106. .macro armv6_mt_table pfx
  107. \pfx\()_mt_table:
  108. .long 0x00 @ L_PTE_MT_UNCACHED
  109. .long PTE_EXT_TEX(1) @ L_PTE_MT_BUFFERABLE
  110. .long PTE_CACHEABLE @ L_PTE_MT_WRITETHROUGH
  111. .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEBACK
  112. .long PTE_BUFFERABLE @ L_PTE_MT_DEV_SHARED
  113. .long 0x00 @ unused
  114. .long 0x00 @ L_PTE_MT_MINICACHE (not present)
  115. .long PTE_EXT_TEX(1) | PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEALLOC
  116. .long 0x00 @ unused
  117. .long PTE_EXT_TEX(1) @ L_PTE_MT_DEV_WC
  118. .long 0x00 @ unused
  119. .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_DEV_CACHED
  120. .long PTE_EXT_TEX(2) @ L_PTE_MT_DEV_NONSHARED
  121. .long 0x00 @ unused
  122. .long 0x00 @ unused
  123. .long 0x00 @ unused
  124. .endm
  125. .macro armv6_set_pte_ext pfx
  126. str r1, [r0], #2048 @ linux version
  127. bic r3, r1, #0x000003fc
  128. bic r3, r3, #PTE_TYPE_MASK
  129. orr r3, r3, r2
  130. orr r3, r3, #PTE_EXT_AP0 | 2
  131. adr ip, \pfx\()_mt_table
  132. and r2, r1, #L_PTE_MT_MASK
  133. ldr r2, [ip, r2]
  134. eor r1, r1, #L_PTE_DIRTY
  135. tst r1, #L_PTE_DIRTY|L_PTE_RDONLY
  136. orrne r3, r3, #PTE_EXT_APX
  137. tst r1, #L_PTE_USER
  138. orrne r3, r3, #PTE_EXT_AP1
  139. #ifdef CONFIG_CPU_USE_DOMAINS
  140. @ allow kernel read/write access to read-only user pages
  141. tstne r3, #PTE_EXT_APX
  142. bicne r3, r3, #PTE_EXT_APX | PTE_EXT_AP0
  143. #endif
  144. tst r1, #L_PTE_XN
  145. orrne r3, r3, #PTE_EXT_XN
  146. orr r3, r3, r2
  147. tst r1, #L_PTE_YOUNG
  148. tstne r1, #L_PTE_PRESENT
  149. moveq r3, #0
  150. str r3, [r0]
  151. mcr p15, 0, r0, c7, c10, 1 @ flush_pte
  152. .endm
  153. /*
  154. * The ARMv3, ARMv4 and ARMv5 set_pte_ext translation function,
  155. * covering most CPUs except Xscale and Xscale 3.
  156. *
  157. * Permission translation:
  158. * YUWD AP SVC User
  159. * 0xxx 0x00 no acc no acc
  160. * 100x 0x00 r/o no acc
  161. * 10x0 0x00 r/o no acc
  162. * 1011 0x55 r/w no acc
  163. * 110x 0xaa r/w r/o
  164. * 11x0 0xaa r/w r/o
  165. * 1111 0xff r/w r/w
  166. */
  167. .macro armv3_set_pte_ext wc_disable=1
  168. str r1, [r0], #2048 @ linux version
  169. eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY
  170. bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits
  171. bic r2, r2, #PTE_TYPE_MASK
  172. orr r2, r2, #PTE_TYPE_SMALL
  173. tst r3, #L_PTE_USER @ user?
  174. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  175. tst r3, #L_PTE_RDONLY | L_PTE_DIRTY @ write and dirty?
  176. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  177. tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young?
  178. movne r2, #0
  179. .if \wc_disable
  180. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  181. tst r2, #PTE_CACHEABLE
  182. bicne r2, r2, #PTE_BUFFERABLE
  183. #endif
  184. .endif
  185. str r2, [r0] @ hardware version
  186. .endm
  187. /*
  188. * Xscale set_pte_ext translation, split into two halves to cope
  189. * with work-arounds. r3 must be preserved by code between these
  190. * two macros.
  191. *
  192. * Permission translation:
  193. * YUWD AP SVC User
  194. * 0xxx 00 no acc no acc
  195. * 100x 00 r/o no acc
  196. * 10x0 00 r/o no acc
  197. * 1011 01 r/w no acc
  198. * 110x 10 r/w r/o
  199. * 11x0 10 r/w r/o
  200. * 1111 11 r/w r/w
  201. */
  202. .macro xscale_set_pte_ext_prologue
  203. str r1, [r0] @ linux version
  204. eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY
  205. bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits
  206. orr r2, r2, #PTE_TYPE_EXT @ extended page
  207. tst r3, #L_PTE_USER @ user?
  208. orrne r2, r2, #PTE_EXT_AP_URO_SRW @ yes -> user r/o, system r/w
  209. tst r3, #L_PTE_RDONLY | L_PTE_DIRTY @ write and dirty?
  210. orreq r2, r2, #PTE_EXT_AP_UNO_SRW @ yes -> user n/a, system r/w
  211. @ combined with user -> user r/w
  212. .endm
  213. .macro xscale_set_pte_ext_epilogue
  214. tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young?
  215. movne r2, #0 @ no -> fault
  216. str r2, [r0, #2048]! @ hardware version
  217. mov ip, #0
  218. mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line
  219. mcr p15, 0, ip, c7, c10, 4 @ data write barrier
  220. .endm
  221. .macro define_processor_functions name:req, dabort:req, pabort:req, nommu=0, suspend=0
  222. .type \name\()_processor_functions, #object
  223. .align 2
  224. ENTRY(\name\()_processor_functions)
  225. .word \dabort
  226. .word \pabort
  227. .word cpu_\name\()_proc_init
  228. .word cpu_\name\()_proc_fin
  229. .word cpu_\name\()_reset
  230. .word cpu_\name\()_do_idle
  231. .word cpu_\name\()_dcache_clean_area
  232. .word cpu_\name\()_switch_mm
  233. .if \nommu
  234. .word 0
  235. .else
  236. .word cpu_\name\()_set_pte_ext
  237. .endif
  238. .if \suspend
  239. .word cpu_\name\()_suspend_size
  240. #ifdef CONFIG_PM_SLEEP
  241. .word cpu_\name\()_do_suspend
  242. .word cpu_\name\()_do_resume
  243. #else
  244. .word 0
  245. .word 0
  246. #endif
  247. .else
  248. .word 0
  249. .word 0
  250. .word 0
  251. .endif
  252. .size \name\()_processor_functions, . - \name\()_processor_functions
  253. .endm
  254. .macro define_cache_functions name:req
  255. .align 2
  256. .type \name\()_cache_fns, #object
  257. ENTRY(\name\()_cache_fns)
  258. .long \name\()_flush_icache_all
  259. .long \name\()_flush_kern_cache_all
  260. .long \name\()_flush_user_cache_all
  261. .long \name\()_flush_user_cache_range
  262. .long \name\()_coherent_kern_range
  263. .long \name\()_coherent_user_range
  264. .long \name\()_flush_kern_dcache_area
  265. .long \name\()_dma_map_area
  266. .long \name\()_dma_unmap_area
  267. .long \name\()_dma_flush_range
  268. .size \name\()_cache_fns, . - \name\()_cache_fns
  269. .endm
  270. .macro define_tlb_functions name:req, flags_up:req, flags_smp
  271. .type \name\()_tlb_fns, #object
  272. ENTRY(\name\()_tlb_fns)
  273. .long \name\()_flush_user_tlb_range
  274. .long \name\()_flush_kern_tlb_range
  275. .ifnb \flags_smp
  276. ALT_SMP(.long \flags_smp )
  277. ALT_UP(.long \flags_up )
  278. .else
  279. .long \flags_up
  280. .endif
  281. .size \name\()_tlb_fns, . - \name\()_tlb_fns
  282. .endm