proc-macros.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. .macro armv6_mt_table pfx
  93. \pfx\()_mt_table:
  94. .long 0x00 @ L_PTE_MT_UNCACHED
  95. .long PTE_EXT_TEX(1) @ L_PTE_MT_BUFFERABLE
  96. .long PTE_CACHEABLE @ L_PTE_MT_WRITETHROUGH
  97. .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEBACK
  98. .long PTE_BUFFERABLE @ L_PTE_MT_DEV_SHARED
  99. .long 0x00 @ unused
  100. .long 0x00 @ L_PTE_MT_MINICACHE (not present)
  101. .long PTE_EXT_TEX(1) | PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_WRITEALLOC
  102. .long 0x00 @ unused
  103. .long PTE_EXT_TEX(1) @ L_PTE_MT_DEV_WC
  104. .long 0x00 @ unused
  105. .long PTE_CACHEABLE | PTE_BUFFERABLE @ L_PTE_MT_DEV_CACHED
  106. .long PTE_EXT_TEX(2) @ L_PTE_MT_DEV_NONSHARED
  107. .long 0x00 @ unused
  108. .long 0x00 @ unused
  109. .long 0x00 @ unused
  110. .endm
  111. .macro armv6_set_pte_ext pfx
  112. str r1, [r0], #-2048 @ linux version
  113. bic r3, r1, #0x000003fc
  114. bic r3, r3, #PTE_TYPE_MASK
  115. orr r3, r3, r2
  116. orr r3, r3, #PTE_EXT_AP0 | 2
  117. adr ip, \pfx\()_mt_table
  118. and r2, r1, #L_PTE_MT_MASK
  119. ldr r2, [ip, r2]
  120. tst r1, #L_PTE_WRITE
  121. tstne r1, #L_PTE_DIRTY
  122. orreq r3, r3, #PTE_EXT_APX
  123. tst r1, #L_PTE_USER
  124. orrne r3, r3, #PTE_EXT_AP1
  125. tstne r3, #PTE_EXT_APX
  126. bicne r3, r3, #PTE_EXT_APX | PTE_EXT_AP0
  127. tst r1, #L_PTE_EXEC
  128. orreq r3, r3, #PTE_EXT_XN
  129. orr r3, r3, r2
  130. tst r1, #L_PTE_YOUNG
  131. tstne r1, #L_PTE_PRESENT
  132. moveq r3, #0
  133. str r3, [r0]
  134. mcr p15, 0, r0, c7, c10, 1 @ flush_pte
  135. .endm
  136. /*
  137. * The ARMv3, ARMv4 and ARMv5 set_pte_ext translation function,
  138. * covering most CPUs except Xscale and Xscale 3.
  139. *
  140. * Permission translation:
  141. * YUWD AP SVC User
  142. * 0xxx 0x00 no acc no acc
  143. * 100x 0x00 r/o no acc
  144. * 10x0 0x00 r/o no acc
  145. * 1011 0x55 r/w no acc
  146. * 110x 0xaa r/w r/o
  147. * 11x0 0xaa r/w r/o
  148. * 1111 0xff r/w r/w
  149. */
  150. .macro armv3_set_pte_ext wc_disable=1
  151. str r1, [r0], #-2048 @ linux version
  152. eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  153. bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits
  154. bic r2, r2, #PTE_TYPE_MASK
  155. orr r2, r2, #PTE_TYPE_SMALL
  156. tst r3, #L_PTE_USER @ user?
  157. orrne r2, r2, #PTE_SMALL_AP_URO_SRW
  158. tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ write and dirty?
  159. orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
  160. tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young?
  161. movne r2, #0
  162. .if \wc_disable
  163. #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  164. tst r2, #PTE_CACHEABLE
  165. bicne r2, r2, #PTE_BUFFERABLE
  166. #endif
  167. .endif
  168. str r2, [r0] @ hardware version
  169. .endm
  170. /*
  171. * Xscale set_pte_ext translation, split into two halves to cope
  172. * with work-arounds. r3 must be preserved by code between these
  173. * two macros.
  174. *
  175. * Permission translation:
  176. * YUWD AP SVC User
  177. * 0xxx 00 no acc no acc
  178. * 100x 00 r/o no acc
  179. * 10x0 00 r/o no acc
  180. * 1011 01 r/w no acc
  181. * 110x 10 r/w r/o
  182. * 11x0 10 r/w r/o
  183. * 1111 11 r/w r/w
  184. */
  185. .macro xscale_set_pte_ext_prologue
  186. str r1, [r0], #-2048 @ linux version
  187. eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
  188. bic r2, r1, #PTE_SMALL_AP_MASK @ keep C, B bits
  189. orr r2, r2, #PTE_TYPE_EXT @ extended page
  190. tst r3, #L_PTE_USER @ user?
  191. orrne r2, r2, #PTE_EXT_AP_URO_SRW @ yes -> user r/o, system r/w
  192. tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ write and dirty?
  193. orreq r2, r2, #PTE_EXT_AP_UNO_SRW @ yes -> user n/a, system r/w
  194. @ combined with user -> user r/w
  195. .endm
  196. .macro xscale_set_pte_ext_epilogue
  197. tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ present and young?
  198. movne r2, #0 @ no -> fault
  199. str r2, [r0] @ hardware version
  200. mov ip, #0
  201. mcr p15, 0, r0, c7, c10, 1 @ clean L1 D line
  202. mcr p15, 0, ip, c7, c10, 4 @ data write barrier
  203. .endm