proc-macros.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. * cache_line_size - get the cache line size from the CSIDR register
  57. * (available on ARMv7+). It assumes that the CSSR register was configured
  58. * to access the L1 data cache CSIDR.
  59. */
  60. .macro dcache_line_size, reg, tmp
  61. mrc p15, 1, \tmp, c0, c0, 0 @ read CSIDR
  62. and \tmp, \tmp, #7 @ cache line size encoding
  63. mov \reg, #16 @ size offset
  64. mov \reg, \reg, lsl \tmp @ actual cache line size
  65. .endm
  66. /*
  67. * Sanity check the PTE configuration for the code below - which makes
  68. * certain assumptions about how these bits are layed out.
  69. */
  70. #ifdef CONFIG_MMU
  71. #if L_PTE_SHARED != PTE_EXT_SHARED
  72. #error PTE shared bit mismatch
  73. #endif
  74. #if (L_PTE_EXEC+L_PTE_USER+L_PTE_WRITE+L_PTE_DIRTY+L_PTE_YOUNG+\
  75. L_PTE_FILE+L_PTE_PRESENT) > L_PTE_SHARED
  76. #error Invalid Linux PTE bit settings
  77. #endif
  78. #endif /* CONFIG_MMU */
  79. /*
  80. * The ARMv6 and ARMv7 set_pte_ext translation function.
  81. *
  82. * Permission translation:
  83. * YUWD APX AP1 AP0 SVC User
  84. * 0xxx 0 0 0 no acc no acc
  85. * 100x 1 0 1 r/o no acc
  86. * 10x0 1 0 1 r/o no acc
  87. * 1011 0 0 1 r/w no acc
  88. * 110x 0 1 0 r/w r/o
  89. * 11x0 0 1 0 r/w r/o
  90. * 1111 0 1 1 r/w r/w
  91. *
  92. * If !CONFIG_CPU_USE_DOMAINS, the following permissions are changed:
  93. * 110x 1 1 1 r/o r/o
  94. * 11x0 1 1 1 r/o r/o
  95. */
  96. .macro armv6_mt_table pfx
  97. \pfx\()_mt_table:
  98. .long 0x00 @ L_PTE_MT_UNCACHED
  99. .long PTE_EXT_TEX(1) @ L_PTE_MT_BUFFERABLE
  100. .long PTE_CACHEABLE @ L_PTE_MT_WRITETHROUGH
  101. .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEBACK
  102. .long PTE_BUFFERABLE @ L_PTE_MT_DEV_SHARED
  103. .long 0x00 @ unused
  104. .long 0x00 @ L_PTE_MT_MINICACHE (not present)
  105. .long PTE_EXT_TEX(1) | PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEALLOC
  106. .long 0x00 @ unused
  107. .long PTE_EXT_TEX(1) @ L_PTE_MT_DEV_WC
  108. .long 0x00 @ unused
  109. .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_DEV_CACHED
  110. .long PTE_EXT_TEX(2) @ L_PTE_MT_DEV_NONSHARED
  111. .long 0x00 @ unused
  112. .long 0x00 @ unused
  113. .long 0x00 @ unused
  114. .endm
  115. .macro armv6_set_pte_ext pfx
  116. str r1, [r0], #-2048 @ linux version
  117. bic r3, r1, #0x000003fc
  118. bic r3, r3, #PTE_TYPE_MASK
  119. orr r3, r3, r2
  120. orr r3, r3, #PTE_EXT_AP0 | 2
  121. adr ip, \pfx\()_mt_table
  122. and r2, r1, #L_PTE_MT_MASK
  123. ldr r2, [ip, r2]
  124. tst r1, #L_PTE_WRITE
  125. tstne r1, #L_PTE_DIRTY
  126. orreq r3, r3, #PTE_EXT_APX
  127. tst r1, #L_PTE_USER
  128. orrne r3, r3, #PTE_EXT_AP1
  129. #ifdef CONFIG_CPU_USE_DOMAINS
  130. @ allow kernel read/write access to read-only user pages
  131. tstne r3, #PTE_EXT_APX
  132. bicne r3, r3, #PTE_EXT_APX | PTE_EXT_AP0
  133. #endif
  134. tst r1, #L_PTE_EXEC
  135. orreq r3, r3, #PTE_EXT_XN
  136. orr r3, r3, r2
  137. tst r1, #L_PTE_YOUNG
  138. tstne r1, #L_PTE_PRESENT
  139. moveq r3, #0
  140. str r3, [r0]
  141. mcr p15, 0, r0, c7, c10, 1 @ flush_pte
  142. .endm
  143. /*
  144. * The ARMv3, ARMv4 and ARMv5 set_pte_ext translation function,
  145. * covering most CPUs except Xscale and Xscale 3.
  146. *
  147. * Permission translation:
  148. * YUWD AP SVC User
  149. * 0xxx 0x00 no acc no acc
  150. * 100x 0x00 r/o no acc
  151. * 10x0 0x00 r/o no acc
  152. * 1011 0x55 r/w no acc
  153. * 110x 0xaa r/w r/o
  154. * 11x0 0xaa r/w r/o
  155. * 1111 0xff r/w r/w
  156. */
  157. .macro armv3_set_pte_ext wc_disable=1
  158. str r1, [r0], #-2048 @ linux version
  159. eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  160. bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits
  161. bic r2, r2, #PTE_TYPE_MASK
  162. orr r2, r2, #PTE_TYPE_SMALL
  163. tst r3, #L_PTE_USER @ user?
  164. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  165. tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ write and dirty?
  166. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  167. tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young?
  168. movne r2, #0
  169. .if \wc_disable
  170. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  171. tst r2, #PTE_CACHEABLE
  172. bicne r2, r2, #PTE_BUFFERABLE
  173. #endif
  174. .endif
  175. str r2, [r0] @ hardware version
  176. .endm
  177. /*
  178. * Xscale set_pte_ext translation, split into two halves to cope
  179. * with work-arounds. r3 must be preserved by code between these
  180. * two macros.
  181. *
  182. * Permission translation:
  183. * YUWD AP SVC User
  184. * 0xxx 00 no acc no acc
  185. * 100x 00 r/o no acc
  186. * 10x0 00 r/o no acc
  187. * 1011 01 r/w no acc
  188. * 110x 10 r/w r/o
  189. * 11x0 10 r/w r/o
  190. * 1111 11 r/w r/w
  191. */
  192. .macro xscale_set_pte_ext_prologue
  193. str r1, [r0], #-2048 @ linux version
  194. eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  195. bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits
  196. orr r2, r2, #PTE_TYPE_EXT @ extended page
  197. tst r3, #L_PTE_USER @ user?
  198. orrne r2, r2, #PTE_EXT_AP_URO_SRW @ yes -> user r/o, system r/w
  199. tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ write and dirty?
  200. orreq r2, r2, #PTE_EXT_AP_UNO_SRW @ yes -> user n/a, system r/w
  201. @ combined with user -> user r/w
  202. .endm
  203. .macro xscale_set_pte_ext_epilogue
  204. tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young?
  205. movne r2, #0 @ no -> fault
  206. str r2, [r0] @ hardware version
  207. mov ip, #0
  208. mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line
  209. mcr p15, 0, ip, c7, c10, 4 @ data write barrier
  210. .endm