misc.S 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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. #ifdef CONFIG_MMU
  70. /*
  71. * If we have to deal with cache aliasing, we use temporary memory mappings
  72. * to ensure that the source and destination pages have the same color as
  73. * the virtual address. We use way 0 and 1 for temporary mappings in such cases.
  74. *
  75. * The temporary DTLB entries shouldn't be flushed by interrupts, but are
  76. * flushed by preemptive task switches. Special code in the
  77. * fast_second_level_miss handler re-established the temporary mapping.
  78. * It requires that the PPNs for the destination and source addresses are
  79. * in a6, and a7, respectively.
  80. */
  81. /* TLB miss exceptions are treated special in the following region */
  82. ENTRY(__tlbtemp_mapping_start)
  83. #if (DCACHE_WAY_SIZE > PAGE_SIZE)
  84. /*
  85. * clear_user_page (void *addr, unsigned long vaddr, struct page *page)
  86. * a2 a3 a4
  87. */
  88. ENTRY(clear_user_page)
  89. entry a1, 32
  90. /* Mark page dirty and determine alias. */
  91. movi a7, (1 << PG_ARCH_1)
  92. l32i a5, a4, PAGE_FLAGS
  93. xor a6, a2, a3
  94. extui a3, a3, PAGE_SHIFT, DCACHE_ALIAS_ORDER
  95. extui a6, a6, PAGE_SHIFT, DCACHE_ALIAS_ORDER
  96. or a5, a5, a7
  97. slli a3, a3, PAGE_SHIFT
  98. s32i a5, a4, PAGE_FLAGS
  99. /* Skip setting up a temporary DTLB if not aliased. */
  100. beqz a6, 1f
  101. /* Invalidate kernel page. */
  102. mov a10, a2
  103. call8 __invalidate_dcache_page
  104. /* Setup a temporary DTLB with the color of the VPN */
  105. movi a4, -PAGE_OFFSET + (PAGE_KERNEL | _PAGE_HW_WRITE)
  106. movi a5, TLBTEMP_BASE_1 # virt
  107. add a6, a2, a4 # ppn
  108. add a2, a5, a3 # add 'color'
  109. wdtlb a6, a2
  110. dsync
  111. 1: movi a3, 0
  112. __loopi a2, a7, PAGE_SIZE, 32
  113. s32i a3, a2, 0
  114. s32i a3, a2, 4
  115. s32i a3, a2, 8
  116. s32i a3, a2, 12
  117. s32i a3, a2, 16
  118. s32i a3, a2, 20
  119. s32i a3, a2, 24
  120. s32i a3, a2, 28
  121. __endla a2, a7, 32
  122. bnez a6, 1f
  123. retw
  124. /* We need to invalidate the temporary idtlb entry, if any. */
  125. 1: addi a2, a2, -PAGE_SIZE
  126. idtlb a2
  127. dsync
  128. retw
  129. /*
  130. * copy_page_user (void *to, void *from, unsigned long vaddr, struct page *page)
  131. * a2 a3 a4 a5
  132. */
  133. ENTRY(copy_user_page)
  134. entry a1, 32
  135. /* Mark page dirty and determine alias for destination. */
  136. movi a8, (1 << PG_ARCH_1)
  137. l32i a9, a5, PAGE_FLAGS
  138. xor a6, a2, a4
  139. xor a7, a3, a4
  140. extui a4, a4, PAGE_SHIFT, DCACHE_ALIAS_ORDER
  141. extui a6, a6, PAGE_SHIFT, DCACHE_ALIAS_ORDER
  142. extui a7, a7, PAGE_SHIFT, DCACHE_ALIAS_ORDER
  143. or a9, a9, a8
  144. slli a4, a4, PAGE_SHIFT
  145. s32i a9, a5, PAGE_FLAGS
  146. movi a5, -PAGE_OFFSET + (PAGE_KERNEL | _PAGE_HW_WRITE)
  147. beqz a6, 1f
  148. /* Invalidate dcache */
  149. mov a10, a2
  150. call8 __invalidate_dcache_page
  151. /* Setup a temporary DTLB with a matching color. */
  152. movi a8, TLBTEMP_BASE_1 # base
  153. add a6, a2, a5 # ppn
  154. add a2, a8, a4 # add 'color'
  155. wdtlb a6, a2
  156. dsync
  157. /* Skip setting up a temporary DTLB for destination if not aliased. */
  158. 1: beqz a7, 1f
  159. /* Setup a temporary DTLB with a matching color. */
  160. movi a8, TLBTEMP_BASE_2 # base
  161. add a7, a3, a5 # ppn
  162. add a3, a8, a4
  163. addi a8, a3, 1 # way1
  164. wdtlb a7, a8
  165. dsync
  166. 1: __loopi a2, a4, PAGE_SIZE, 32
  167. l32i a8, a3, 0
  168. l32i a9, a3, 4
  169. s32i a8, a2, 0
  170. s32i a9, a2, 4
  171. l32i a8, a3, 8
  172. l32i a9, a3, 12
  173. s32i a8, a2, 8
  174. s32i a9, a2, 12
  175. l32i a8, a3, 16
  176. l32i a9, a3, 20
  177. s32i a8, a2, 16
  178. s32i a9, a2, 20
  179. l32i a8, a3, 24
  180. l32i a9, a3, 28
  181. s32i a8, a2, 24
  182. s32i a9, a2, 28
  183. addi a2, a2, 32
  184. addi a3, a3, 32
  185. __endl a2, a4
  186. /* We need to invalidate any temporary mapping! */
  187. bnez a6, 1f
  188. bnez a7, 2f
  189. retw
  190. 1: addi a2, a2, -PAGE_SIZE
  191. idtlb a2
  192. dsync
  193. bnez a7, 2f
  194. retw
  195. 2: addi a3, a3, -PAGE_SIZE+1
  196. idtlb a3
  197. dsync
  198. retw
  199. #endif
  200. #if (DCACHE_WAY_SIZE > PAGE_SIZE)
  201. /*
  202. * void __flush_invalidate_dcache_page_alias (addr, phys)
  203. * a2 a3
  204. */
  205. ENTRY(__flush_invalidate_dcache_page_alias)
  206. entry sp, 16
  207. movi a7, 0 # required for exception handler
  208. addi a6, a3, (PAGE_KERNEL | _PAGE_HW_WRITE)
  209. mov a4, a2
  210. wdtlb a6, a2
  211. dsync
  212. ___flush_invalidate_dcache_page a2 a3
  213. idtlb a4
  214. dsync
  215. retw
  216. #endif
  217. ENTRY(__tlbtemp_mapping_itlb)
  218. #if (ICACHE_WAY_SIZE > PAGE_SIZE)
  219. ENTRY(__invalidate_icache_page_alias)
  220. entry sp, 16
  221. addi a6, a3, (PAGE_KERNEL_EXEC | _PAGE_HW_WRITE)
  222. mov a4, a2
  223. witlb a6, a2
  224. isync
  225. ___invalidate_icache_page a2 a3
  226. iitlb a4
  227. isync
  228. retw
  229. #endif
  230. /* End of special treatment in tlb miss exception */
  231. ENTRY(__tlbtemp_mapping_end)
  232. #endif /* CONFIG_MMU
  233. /*
  234. * void __invalidate_icache_page(ulong start)
  235. */
  236. ENTRY(__invalidate_icache_page)
  237. entry sp, 16
  238. ___invalidate_icache_page a2 a3
  239. isync
  240. retw
  241. /*
  242. * void __invalidate_dcache_page(ulong start)
  243. */
  244. ENTRY(__invalidate_dcache_page)
  245. entry sp, 16
  246. ___invalidate_dcache_page a2 a3
  247. dsync
  248. retw
  249. /*
  250. * void __flush_invalidate_dcache_page(ulong start)
  251. */
  252. ENTRY(__flush_invalidate_dcache_page)
  253. entry sp, 16
  254. ___flush_invalidate_dcache_page a2 a3
  255. dsync
  256. retw
  257. /*
  258. * void __flush_dcache_page(ulong start)
  259. */
  260. ENTRY(__flush_dcache_page)
  261. entry sp, 16
  262. ___flush_dcache_page a2 a3
  263. dsync
  264. retw
  265. /*
  266. * void __invalidate_icache_range(ulong start, ulong size)
  267. */
  268. ENTRY(__invalidate_icache_range)
  269. entry sp, 16
  270. ___invalidate_icache_range a2 a3 a4
  271. isync
  272. retw
  273. /*
  274. * void __flush_invalidate_dcache_range(ulong start, ulong size)
  275. */
  276. ENTRY(__flush_invalidate_dcache_range)
  277. entry sp, 16
  278. ___flush_invalidate_dcache_range a2 a3 a4
  279. dsync
  280. retw
  281. /*
  282. * void _flush_dcache_range(ulong start, ulong size)
  283. */
  284. ENTRY(__flush_dcache_range)
  285. entry sp, 16
  286. ___flush_dcache_range a2 a3 a4
  287. dsync
  288. retw
  289. /*
  290. * void _invalidate_dcache_range(ulong start, ulong size)
  291. */
  292. ENTRY(__invalidate_dcache_range)
  293. entry sp, 16
  294. ___invalidate_dcache_range a2 a3 a4
  295. retw
  296. /*
  297. * void _invalidate_icache_all(void)
  298. */
  299. ENTRY(__invalidate_icache_all)
  300. entry sp, 16
  301. ___invalidate_icache_all a2 a3
  302. isync
  303. retw
  304. /*
  305. * void _flush_invalidate_dcache_all(void)
  306. */
  307. ENTRY(__flush_invalidate_dcache_all)
  308. entry sp, 16
  309. ___flush_invalidate_dcache_all a2 a3
  310. dsync
  311. retw
  312. /*
  313. * void _invalidate_dcache_all(void)
  314. */
  315. ENTRY(__invalidate_dcache_all)
  316. entry sp, 16
  317. ___invalidate_dcache_all a2 a3
  318. dsync
  319. retw