proc-macros.S 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #if L_PTE_SHARED != PTE_EXT_SHARED
  71. #error PTE shared bit mismatch
  72. #endif
  73. #if L_PTE_BUFFERABLE != PTE_BUFFERABLE
  74. #error PTE bufferable bit mismatch
  75. #endif
  76. #if L_PTE_CACHEABLE != PTE_CACHEABLE
  77. #error PTE cacheable bit mismatch
  78. #endif
  79. #if (L_PTE_EXEC+L_PTE_USER+L_PTE_WRITE+L_PTE_DIRTY+L_PTE_YOUNG+\
  80. L_PTE_FILE+L_PTE_PRESENT) > L_PTE_SHARED
  81. #error Invalid Linux PTE bit settings
  82. #endif
  83. /*
  84. * The ARMv6 and ARMv7 set_pte_ext translation function.
  85. *
  86. * Permission translation:
  87. * YUWD APX AP1 AP0 SVC User
  88. * 0xxx 0 0 0 no acc no acc
  89. * 100x 1 0 1 r/o no acc
  90. * 10x0 1 0 1 r/o no acc
  91. * 1011 0 0 1 r/w no acc
  92. * 110x 0 1 0 r/w r/o
  93. * 11x0 0 1 0 r/w r/o
  94. * 1111 0 1 1 r/w r/w
  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. tstne r3, #PTE_EXT_APX
  130. bicne r3, r3, #PTE_EXT_APX | PTE_EXT_AP0
  131. tst r1, #L_PTE_EXEC
  132. orreq r3, r3, #PTE_EXT_XN
  133. orr r3, r3, r2
  134. tst r1, #L_PTE_YOUNG
  135. tstne r1, #L_PTE_PRESENT
  136. moveq r3, #0
  137. str r3, [r0]
  138. mcr p15, 0, r0, c7, c10, 1 @ flush_pte
  139. .endm
  140. /*
  141. * The ARMv3, ARMv4 and ARMv5 set_pte_ext translation function,
  142. * covering most CPUs except Xscale and Xscale 3.
  143. *
  144. * Permission translation:
  145. * YUWD AP SVC User
  146. * 0xxx 0x00 no acc no acc
  147. * 100x 0x00 r/o no acc
  148. * 10x0 0x00 r/o no acc
  149. * 1011 0x55 r/w no acc
  150. * 110x 0xaa r/w r/o
  151. * 11x0 0xaa r/w r/o
  152. * 1111 0xff r/w r/w
  153. */
  154. .macro armv3_set_pte_ext wc_disable=1
  155. str r1, [r0], #-2048 @ linux version
  156. eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  157. bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits
  158. bic r2, r2, #PTE_TYPE_MASK
  159. orr r2, r2, #PTE_TYPE_SMALL
  160. tst r3, #L_PTE_USER @ user?
  161. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  162. tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ write and dirty?
  163. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  164. tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young?
  165. movne r2, #0
  166. .if \wc_disable
  167. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  168. tst r2, #PTE_CACHEABLE
  169. bicne r2, r2, #PTE_BUFFERABLE
  170. #endif
  171. .endif
  172. str r2, [r0] @ hardware version
  173. .endm
  174. /*
  175. * Xscale set_pte_ext translation, split into two halves to cope
  176. * with work-arounds. r3 must be preserved by code between these
  177. * two macros.
  178. *
  179. * Permission translation:
  180. * YUWD AP SVC User
  181. * 0xxx 00 no acc no acc
  182. * 100x 00 r/o no acc
  183. * 10x0 00 r/o no acc
  184. * 1011 01 r/w no acc
  185. * 110x 10 r/w r/o
  186. * 11x0 10 r/w r/o
  187. * 1111 11 r/w r/w
  188. */
  189. .macro xscale_set_pte_ext_prologue
  190. str r1, [r0], #-2048 @ linux version
  191. eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  192. bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits
  193. orr r2, r2, #PTE_TYPE_EXT @ extended page
  194. tst r3, #L_PTE_USER @ user?
  195. orrne r2, r2, #PTE_EXT_AP_URO_SRW @ yes -> user r/o, system r/w
  196. tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ write and dirty?
  197. orreq r2, r2, #PTE_EXT_AP_UNO_SRW @ yes -> user n/a, system r/w
  198. @ combined with user -> user r/w
  199. .endm
  200. .macro xscale_set_pte_ext_epilogue
  201. tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young?
  202. movne r2, #0 @ no -> fault
  203. str r2, [r0] @ hardware version
  204. mov ip, #0
  205. mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line
  206. mcr p15, 0, ip, c7, c10, 4 @ data write barrier
  207. .endm