misc.S 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. /*
  2. * arch/xtensa/mm/misc.S
  3. *
  4. * Miscellaneous assembly functions.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. *
  10. * Copyright (C) 2001 - 2007 Tensilica Inc.
  11. *
  12. * Chris Zankel <chris@zankel.net>
  13. */
  14. #include <linux/linkage.h>
  15. #include <asm/page.h>
  16. #include <asm/pgtable.h>
  17. #include <asm/asmmacro.h>
  18. #include <asm/cacheasm.h>
  19. #include <asm/tlbflush.h>
  20. /*
  21. * clear_page and clear_user_page are the same for non-cache-aliased configs.
  22. *
  23. * clear_page (unsigned long page)
  24. * a2
  25. */
  26. ENTRY(clear_page)
  27. entry a1, 16
  28. movi a3, 0
  29. __loopi a2, a7, PAGE_SIZE, 32
  30. s32i a3, a2, 0
  31. s32i a3, a2, 4
  32. s32i a3, a2, 8
  33. s32i a3, a2, 12
  34. s32i a3, a2, 16
  35. s32i a3, a2, 20
  36. s32i a3, a2, 24
  37. s32i a3, a2, 28
  38. __endla a2, a7, 32
  39. retw
  40. /*
  41. * copy_page and copy_user_page are the same for non-cache-aliased configs.
  42. *
  43. * copy_page (void *to, void *from)
  44. * a2 a3
  45. */
  46. ENTRY(copy_page)
  47. entry a1, 16
  48. __loopi a2, a4, PAGE_SIZE, 32
  49. l32i a8, a3, 0
  50. l32i a9, a3, 4
  51. s32i a8, a2, 0
  52. s32i a9, a2, 4
  53. l32i a8, a3, 8
  54. l32i a9, a3, 12
  55. s32i a8, a2, 8
  56. s32i a9, a2, 12
  57. l32i a8, a3, 16
  58. l32i a9, a3, 20
  59. s32i a8, a2, 16
  60. s32i a9, a2, 20
  61. l32i a8, a3, 24
  62. l32i a9, a3, 28
  63. s32i a8, a2, 24
  64. s32i a9, a2, 28
  65. addi a2, a2, 32
  66. addi a3, a3, 32
  67. __endl a2, a4
  68. retw
  69. /*
  70. * If we have to deal with cache aliasing, we use temporary memory mappings
  71. * to ensure that the source and destination pages have the same color as
  72. * the virtual address. We use way 0 and 1 for temporary mappings in such cases.
  73. *
  74. * The temporary DTLB entries shouldn't be flushed by interrupts, but are
  75. * flushed by preemptive task switches. Special code in the
  76. * fast_second_level_miss handler re-established the temporary mapping.
  77. * It requires that the PPNs for the destination and source addresses are
  78. * in a6, and a7, respectively.
  79. */
  80. /* TLB miss exceptions are treated special in the following region */
  81. ENTRY(__tlbtemp_mapping_start)
  82. #if (DCACHE_WAY_SIZE > PAGE_SIZE)
  83. /*
  84. * clear_user_page (void *addr, unsigned long vaddr, struct page *page)
  85. * a2 a3 a4
  86. */
  87. ENTRY(clear_user_page)
  88. entry a1, 32
  89. /* Mark page dirty and determine alias. */
  90. movi a7, (1 << PG_ARCH_1)
  91. l32i a5, a4, PAGE_FLAGS
  92. xor a6, a2, a3
  93. extui a3, a3, PAGE_SHIFT, DCACHE_ALIAS_ORDER
  94. extui a6, a6, PAGE_SHIFT, DCACHE_ALIAS_ORDER
  95. or a5, a5, a7
  96. slli a3, a3, PAGE_SHIFT
  97. s32i a5, a4, PAGE_FLAGS
  98. /* Skip setting up a temporary DTLB if not aliased. */
  99. beqz a6, 1f
  100. /* Invalidate kernel page. */
  101. mov a10, a2
  102. call8 __invalidate_dcache_page
  103. /* Setup a temporary DTLB with the color of the VPN */
  104. movi a4, -PAGE_OFFSET + (PAGE_KERNEL | _PAGE_HW_WRITE)
  105. movi a5, TLBTEMP_BASE_1 # virt
  106. add a6, a2, a4 # ppn
  107. add a2, a5, a3 # add 'color'
  108. wdtlb a6, a2
  109. dsync
  110. 1: movi a3, 0
  111. __loopi a2, a7, PAGE_SIZE, 32
  112. s32i a3, a2, 0
  113. s32i a3, a2, 4
  114. s32i a3, a2, 8
  115. s32i a3, a2, 12
  116. s32i a3, a2, 16
  117. s32i a3, a2, 20
  118. s32i a3, a2, 24
  119. s32i a3, a2, 28
  120. __endla a2, a7, 32
  121. bnez a6, 1f
  122. retw
  123. /* We need to invalidate the temporary idtlb entry, if any. */
  124. 1: addi a2, a2, -PAGE_SIZE
  125. idtlb a2
  126. dsync
  127. retw
  128. /*
  129. * copy_page_user (void *to, void *from, unsigned long vaddr, struct page *page)
  130. * a2 a3 a4 a5
  131. */
  132. ENTRY(copy_user_page)
  133. entry a1, 32
  134. /* Mark page dirty and determine alias for destination. */
  135. movi a8, (1 << PG_ARCH_1)
  136. l32i a9, a5, PAGE_FLAGS
  137. xor a6, a2, a4
  138. xor a7, a3, a4
  139. extui a4, a4, PAGE_SHIFT, DCACHE_ALIAS_ORDER
  140. extui a6, a6, PAGE_SHIFT, DCACHE_ALIAS_ORDER
  141. extui a7, a7, PAGE_SHIFT, DCACHE_ALIAS_ORDER
  142. or a9, a9, a8
  143. slli a4, a4, PAGE_SHIFT
  144. s32i a9, a5, PAGE_FLAGS
  145. movi a5, -PAGE_OFFSET + (PAGE_KERNEL | _PAGE_HW_WRITE)
  146. beqz a6, 1f
  147. /* Invalidate dcache */
  148. mov a10, a2
  149. call8 __invalidate_dcache_page
  150. /* Setup a temporary DTLB with a matching color. */
  151. movi a8, TLBTEMP_BASE_1 # base
  152. add a6, a2, a5 # ppn
  153. add a2, a8, a4 # add 'color'
  154. wdtlb a6, a2
  155. dsync
  156. /* Skip setting up a temporary DTLB for destination if not aliased. */
  157. 1: beqz a7, 1f
  158. /* Setup a temporary DTLB with a matching color. */
  159. movi a8, TLBTEMP_BASE_2 # base
  160. add a7, a3, a5 # ppn
  161. add a3, a8, a4
  162. addi a8, a3, 1 # way1
  163. wdtlb a7, a8
  164. dsync
  165. 1: __loopi a2, a4, PAGE_SIZE, 32
  166. l32i a8, a3, 0
  167. l32i a9, a3, 4
  168. s32i a8, a2, 0
  169. s32i a9, a2, 4
  170. l32i a8, a3, 8
  171. l32i a9, a3, 12
  172. s32i a8, a2, 8
  173. s32i a9, a2, 12
  174. l32i a8, a3, 16
  175. l32i a9, a3, 20
  176. s32i a8, a2, 16
  177. s32i a9, a2, 20
  178. l32i a8, a3, 24
  179. l32i a9, a3, 28
  180. s32i a8, a2, 24
  181. s32i a9, a2, 28
  182. addi a2, a2, 32
  183. addi a3, a3, 32
  184. __endl a2, a4
  185. /* We need to invalidate any temporary mapping! */
  186. bnez a6, 1f
  187. bnez a7, 2f
  188. retw
  189. 1: addi a2, a2, -PAGE_SIZE
  190. idtlb a2
  191. dsync
  192. bnez a7, 2f
  193. retw
  194. 2: addi a3, a3, -PAGE_SIZE+1
  195. idtlb a3
  196. dsync
  197. retw
  198. #endif
  199. #if (DCACHE_WAY_SIZE > PAGE_SIZE)
  200. /*
  201. * void __flush_invalidate_dcache_page_alias (addr, phys)
  202. * a2 a3
  203. */
  204. ENTRY(__flush_invalidate_dcache_page_alias)
  205. entry sp, 16
  206. movi a7, 0 # required for exception handler
  207. addi a6, a3, (PAGE_KERNEL | _PAGE_HW_WRITE)
  208. mov a4, a2
  209. wdtlb a6, a2
  210. dsync
  211. ___flush_invalidate_dcache_page a2 a3
  212. idtlb a4
  213. dsync
  214. retw
  215. #endif
  216. ENTRY(__tlbtemp_mapping_itlb)
  217. #if (ICACHE_WAY_SIZE > PAGE_SIZE)
  218. ENTRY(__invalidate_icache_page_alias)
  219. entry sp, 16
  220. addi a6, a3, (PAGE_KERNEL_EXEC | _PAGE_HW_WRITE)
  221. mov a4, a2
  222. witlb a6, a2
  223. isync
  224. ___invalidate_icache_page a2 a3
  225. iitlb a4
  226. isync
  227. retw
  228. #endif
  229. /* End of special treatment in tlb miss exception */
  230. ENTRY(__tlbtemp_mapping_end)
  231. /*
  232. * void __invalidate_icache_page(ulong start)
  233. */
  234. ENTRY(__invalidate_icache_page)
  235. entry sp, 16
  236. ___invalidate_icache_page a2 a3
  237. isync
  238. retw
  239. /*
  240. * void __invalidate_dcache_page(ulong start)
  241. */
  242. ENTRY(__invalidate_dcache_page)
  243. entry sp, 16
  244. ___invalidate_dcache_page a2 a3
  245. dsync
  246. retw
  247. /*
  248. * void __flush_invalidate_dcache_page(ulong start)
  249. */
  250. ENTRY(__flush_invalidate_dcache_page)
  251. entry sp, 16
  252. ___flush_invalidate_dcache_page a2 a3
  253. dsync
  254. retw
  255. /*
  256. * void __flush_dcache_page(ulong start)
  257. */
  258. ENTRY(__flush_dcache_page)
  259. entry sp, 16
  260. ___flush_dcache_page a2 a3
  261. dsync
  262. retw
  263. /*
  264. * void __invalidate_icache_range(ulong start, ulong size)
  265. */
  266. ENTRY(__invalidate_icache_range)
  267. entry sp, 16
  268. ___invalidate_icache_range a2 a3 a4
  269. isync
  270. retw
  271. /*
  272. * void __flush_invalidate_dcache_range(ulong start, ulong size)
  273. */
  274. ENTRY(__flush_invalidate_dcache_range)
  275. entry sp, 16
  276. ___flush_invalidate_dcache_range a2 a3 a4
  277. dsync
  278. retw
  279. /*
  280. * void _flush_dcache_range(ulong start, ulong size)
  281. */
  282. ENTRY(__flush_dcache_range)
  283. entry sp, 16
  284. ___flush_dcache_range a2 a3 a4
  285. dsync
  286. retw
  287. /*
  288. * void _invalidate_dcache_range(ulong start, ulong size)
  289. */
  290. ENTRY(__invalidate_dcache_range)
  291. entry sp, 16
  292. ___invalidate_dcache_range a2 a3 a4
  293. retw
  294. /*
  295. * void _invalidate_icache_all(void)
  296. */
  297. ENTRY(__invalidate_icache_all)
  298. entry sp, 16
  299. ___invalidate_icache_all a2 a3
  300. isync
  301. retw
  302. /*
  303. * void _flush_invalidate_dcache_all(void)
  304. */
  305. ENTRY(__flush_invalidate_dcache_all)
  306. entry sp, 16
  307. ___flush_invalidate_dcache_all a2 a3
  308. dsync
  309. retw
  310. /*
  311. * void _invalidate_dcache_all(void)
  312. */
  313. ENTRY(__invalidate_dcache_all)
  314. entry sp, 16
  315. ___invalidate_dcache_all a2 a3
  316. dsync
  317. retw