migrate_32.S 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. *
  14. * This routine is a helper for migrating the home of a set of pages to
  15. * a new cpu. See the documentation in homecache.c for more information.
  16. */
  17. #include <linux/linkage.h>
  18. #include <linux/threads.h>
  19. #include <asm/page.h>
  20. #include <asm/types.h>
  21. #include <asm/asm-offsets.h>
  22. #include <hv/hypervisor.h>
  23. .text
  24. /*
  25. * First, some definitions that apply to all the code in the file.
  26. */
  27. /* Locals (caller-save) */
  28. #define r_tmp r10
  29. #define r_save_sp r11
  30. /* What we save where in the stack frame; must include all callee-saves. */
  31. #define FRAME_SP 4
  32. #define FRAME_R30 8
  33. #define FRAME_R31 12
  34. #define FRAME_R32 16
  35. #define FRAME_R33 20
  36. #define FRAME_R34 24
  37. #define FRAME_R35 28
  38. #define FRAME_SIZE 32
  39. /*
  40. * On entry:
  41. *
  42. * r0 low word of the new context PA to install (moved to r_context_lo)
  43. * r1 high word of the new context PA to install (moved to r_context_hi)
  44. * r2 low word of PTE to use for context access (moved to r_access_lo)
  45. * r3 high word of PTE to use for context access (moved to r_access_lo)
  46. * r4 ASID to use for new context (moved to r_asid)
  47. * r5 pointer to cpumask with just this cpu set in it (r_my_cpumask)
  48. */
  49. /* Arguments (caller-save) */
  50. #define r_context_lo_in r0
  51. #define r_context_hi_in r1
  52. #define r_access_lo_in r2
  53. #define r_access_hi_in r3
  54. #define r_asid_in r4
  55. #define r_my_cpumask r5
  56. /* Locals (callee-save); must not be more than FRAME_xxx above. */
  57. #define r_save_ics r30
  58. #define r_context_lo r31
  59. #define r_context_hi r32
  60. #define r_access_lo r33
  61. #define r_access_hi r34
  62. #define r_asid r35
  63. STD_ENTRY(flush_and_install_context)
  64. /*
  65. * Create a stack frame; we can't touch it once we flush the
  66. * cache until we install the new page table and flush the TLB.
  67. */
  68. {
  69. move r_save_sp, sp
  70. sw sp, lr
  71. addi sp, sp, -FRAME_SIZE
  72. }
  73. addi r_tmp, sp, FRAME_SP
  74. {
  75. sw r_tmp, r_save_sp
  76. addi r_tmp, sp, FRAME_R30
  77. }
  78. {
  79. sw r_tmp, r30
  80. addi r_tmp, sp, FRAME_R31
  81. }
  82. {
  83. sw r_tmp, r31
  84. addi r_tmp, sp, FRAME_R32
  85. }
  86. {
  87. sw r_tmp, r32
  88. addi r_tmp, sp, FRAME_R33
  89. }
  90. {
  91. sw r_tmp, r33
  92. addi r_tmp, sp, FRAME_R34
  93. }
  94. {
  95. sw r_tmp, r34
  96. addi r_tmp, sp, FRAME_R35
  97. }
  98. sw r_tmp, r35
  99. /* Move some arguments to callee-save registers. */
  100. {
  101. move r_context_lo, r_context_lo_in
  102. move r_context_hi, r_context_hi_in
  103. }
  104. {
  105. move r_access_lo, r_access_lo_in
  106. move r_access_hi, r_access_hi_in
  107. }
  108. move r_asid, r_asid_in
  109. /* Disable interrupts, since we can't use our stack. */
  110. {
  111. mfspr r_save_ics, INTERRUPT_CRITICAL_SECTION
  112. movei r_tmp, 1
  113. }
  114. mtspr INTERRUPT_CRITICAL_SECTION, r_tmp
  115. /* First, flush our L2 cache. */
  116. {
  117. move r0, zero /* cache_pa */
  118. move r1, zero
  119. }
  120. {
  121. auli r2, zero, ha16(HV_FLUSH_EVICT_L2) /* cache_control */
  122. move r3, r_my_cpumask /* cache_cpumask */
  123. }
  124. {
  125. move r4, zero /* tlb_va */
  126. move r5, zero /* tlb_length */
  127. }
  128. {
  129. move r6, zero /* tlb_pgsize */
  130. move r7, zero /* tlb_cpumask */
  131. }
  132. {
  133. move r8, zero /* asids */
  134. move r9, zero /* asidcount */
  135. }
  136. jal hv_flush_remote
  137. bnz r0, .Ldone
  138. /* Now install the new page table. */
  139. {
  140. move r0, r_context_lo
  141. move r1, r_context_hi
  142. }
  143. {
  144. move r2, r_access_lo
  145. move r3, r_access_hi
  146. }
  147. {
  148. move r4, r_asid
  149. movei r5, HV_CTX_DIRECTIO
  150. }
  151. jal hv_install_context
  152. bnz r0, .Ldone
  153. /* Finally, flush the TLB. */
  154. {
  155. movei r0, 0 /* preserve_global */
  156. jal hv_flush_all
  157. }
  158. .Ldone:
  159. /* Reset interrupts back how they were before. */
  160. mtspr INTERRUPT_CRITICAL_SECTION, r_save_ics
  161. /* Restore the callee-saved registers and return. */
  162. addli lr, sp, FRAME_SIZE
  163. {
  164. lw lr, lr
  165. addli r_tmp, sp, FRAME_R30
  166. }
  167. {
  168. lw r30, r_tmp
  169. addli r_tmp, sp, FRAME_R31
  170. }
  171. {
  172. lw r31, r_tmp
  173. addli r_tmp, sp, FRAME_R32
  174. }
  175. {
  176. lw r32, r_tmp
  177. addli r_tmp, sp, FRAME_R33
  178. }
  179. {
  180. lw r33, r_tmp
  181. addli r_tmp, sp, FRAME_R34
  182. }
  183. {
  184. lw r34, r_tmp
  185. addli r_tmp, sp, FRAME_R35
  186. }
  187. {
  188. lw r35, r_tmp
  189. addi sp, sp, FRAME_SIZE
  190. }
  191. jrp lr
  192. STD_ENDPROC(flush_and_install_context)