relocate_kernel.S 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. * copy new kernel into place and then call hv_reexec
  15. *
  16. */
  17. #include <linux/linkage.h>
  18. #include <arch/chip.h>
  19. #include <asm/page.h>
  20. #include <hv/hypervisor.h>
  21. #define ___hvb MEM_SV_INTRPT + HV_GLUE_START_CPA
  22. #define ___hv_dispatch(f) (___hvb + (HV_DISPATCH_ENTRY_SIZE * f))
  23. #define ___hv_console_putc ___hv_dispatch(HV_DISPATCH_CONSOLE_PUTC)
  24. #define ___hv_halt ___hv_dispatch(HV_DISPATCH_HALT)
  25. #define ___hv_reexec ___hv_dispatch(HV_DISPATCH_REEXEC)
  26. #define ___hv_flush_remote ___hv_dispatch(HV_DISPATCH_FLUSH_REMOTE)
  27. #undef RELOCATE_NEW_KERNEL_VERBOSE
  28. STD_ENTRY(relocate_new_kernel)
  29. move r30, r0 /* page list */
  30. move r31, r1 /* address of page we are on */
  31. move r32, r2 /* start address of new kernel */
  32. shri r1, r1, PAGE_SHIFT
  33. addi r1, r1, 1
  34. shli sp, r1, PAGE_SHIFT
  35. addi sp, sp, -8
  36. /* we now have a stack (whether we need one or not) */
  37. moveli r40, lo16(___hv_console_putc)
  38. auli r40, r40, ha16(___hv_console_putc)
  39. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  40. moveli r0, 'r'
  41. jalr r40
  42. moveli r0, '_'
  43. jalr r40
  44. moveli r0, 'n'
  45. jalr r40
  46. moveli r0, '_'
  47. jalr r40
  48. moveli r0, 'k'
  49. jalr r40
  50. moveli r0, '\n'
  51. jalr r40
  52. #endif
  53. /*
  54. * Throughout this code r30 is pointer to the element of page
  55. * list we are working on.
  56. *
  57. * Normally we get to the next element of the page list by
  58. * incrementing r30 by four. The exception is if the element
  59. * on the page list is an IND_INDIRECTION in which case we use
  60. * the element with the low bits masked off as the new value
  61. * of r30.
  62. *
  63. * To get this started, we need the value passed to us (which
  64. * will always be an IND_INDIRECTION) in memory somewhere with
  65. * r30 pointing at it. To do that, we push the value passed
  66. * to us on the stack and make r30 point to it.
  67. */
  68. sw sp, r30
  69. move r30, sp
  70. addi sp, sp, -8
  71. #if CHIP_HAS_CBOX_HOME_MAP()
  72. /*
  73. * On TILEPro, we need to flush all tiles' caches, since we may
  74. * have been doing hash-for-home caching there. Note that we
  75. * must do this _after_ we're completely done modifying any memory
  76. * other than our output buffer (which we know is locally cached).
  77. * We want the caches to be fully clean when we do the reexec,
  78. * because the hypervisor is going to do this flush again at that
  79. * point, and we don't want that second flush to overwrite any memory.
  80. */
  81. {
  82. move r0, zero /* cache_pa */
  83. move r1, zero
  84. }
  85. {
  86. auli r2, zero, ha16(HV_FLUSH_EVICT_L2) /* cache_control */
  87. movei r3, -1 /* cache_cpumask; -1 means all client tiles */
  88. }
  89. {
  90. move r4, zero /* tlb_va */
  91. move r5, zero /* tlb_length */
  92. }
  93. {
  94. move r6, zero /* tlb_pgsize */
  95. move r7, zero /* tlb_cpumask */
  96. }
  97. {
  98. move r8, zero /* asids */
  99. moveli r20, lo16(___hv_flush_remote)
  100. }
  101. {
  102. move r9, zero /* asidcount */
  103. auli r20, r20, ha16(___hv_flush_remote)
  104. }
  105. jalr r20
  106. #endif
  107. /* r33 is destination pointer, default to zero */
  108. moveli r33, 0
  109. .Lloop: lw r10, r30
  110. andi r9, r10, 0xf /* low 4 bits tell us what type it is */
  111. xor r10, r10, r9 /* r10 is now value with low 4 bits stripped */
  112. seqi r0, r9, 0x1 /* IND_DESTINATION */
  113. bzt r0, .Ltry2
  114. move r33, r10
  115. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  116. moveli r0, 'd'
  117. jalr r40
  118. #endif
  119. addi r30, r30, 4
  120. j .Lloop
  121. .Ltry2:
  122. seqi r0, r9, 0x2 /* IND_INDIRECTION */
  123. bzt r0, .Ltry4
  124. move r30, r10
  125. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  126. moveli r0, 'i'
  127. jalr r40
  128. #endif
  129. j .Lloop
  130. .Ltry4:
  131. seqi r0, r9, 0x4 /* IND_DONE */
  132. bzt r0, .Ltry8
  133. mf
  134. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  135. moveli r0, 'D'
  136. jalr r40
  137. moveli r0, '\n'
  138. jalr r40
  139. #endif
  140. move r0, r32
  141. moveli r1, 0 /* arg to hv_reexec is 64 bits */
  142. moveli r41, lo16(___hv_reexec)
  143. auli r41, r41, ha16(___hv_reexec)
  144. jalr r41
  145. /* we should not get here */
  146. moveli r0, '?'
  147. jalr r40
  148. moveli r0, '\n'
  149. jalr r40
  150. j .Lhalt
  151. .Ltry8: seqi r0, r9, 0x8 /* IND_SOURCE */
  152. bz r0, .Lerr /* unknown type */
  153. /* copy page at r10 to page at r33 */
  154. move r11, r33
  155. moveli r0, lo16(PAGE_SIZE)
  156. auli r0, r0, ha16(PAGE_SIZE)
  157. add r33, r33, r0
  158. /* copy word at r10 to word at r11 until r11 equals r33 */
  159. /* We know page size must be multiple of 16, so we can unroll
  160. * 16 times safely without any edge case checking.
  161. *
  162. * Issue a flush of the destination every 16 words to avoid
  163. * incoherence when starting the new kernel. (Now this is
  164. * just good paranoia because the hv_reexec call will also
  165. * take care of this.)
  166. */
  167. 1:
  168. { lw r0, r10; addi r10, r10, 4 }
  169. { sw r11, r0; addi r11, r11, 4 }
  170. { lw r0, r10; addi r10, r10, 4 }
  171. { sw r11, r0; addi r11, r11, 4 }
  172. { lw r0, r10; addi r10, r10, 4 }
  173. { sw r11, r0; addi r11, r11, 4 }
  174. { lw r0, r10; addi r10, r10, 4 }
  175. { sw r11, r0; addi r11, r11, 4 }
  176. { lw r0, r10; addi r10, r10, 4 }
  177. { sw r11, r0; addi r11, r11, 4 }
  178. { lw r0, r10; addi r10, r10, 4 }
  179. { sw r11, r0; addi r11, r11, 4 }
  180. { lw r0, r10; addi r10, r10, 4 }
  181. { sw r11, r0; addi r11, r11, 4 }
  182. { lw r0, r10; addi r10, r10, 4 }
  183. { sw r11, r0; addi r11, r11, 4 }
  184. { lw r0, r10; addi r10, r10, 4 }
  185. { sw r11, r0; addi r11, r11, 4 }
  186. { lw r0, r10; addi r10, r10, 4 }
  187. { sw r11, r0; addi r11, r11, 4 }
  188. { lw r0, r10; addi r10, r10, 4 }
  189. { sw r11, r0; addi r11, r11, 4 }
  190. { lw r0, r10; addi r10, r10, 4 }
  191. { sw r11, r0; addi r11, r11, 4 }
  192. { lw r0, r10; addi r10, r10, 4 }
  193. { sw r11, r0; addi r11, r11, 4 }
  194. { lw r0, r10; addi r10, r10, 4 }
  195. { sw r11, r0; addi r11, r11, 4 }
  196. { lw r0, r10; addi r10, r10, 4 }
  197. { sw r11, r0; addi r11, r11, 4 }
  198. { lw r0, r10; addi r10, r10, 4 }
  199. { sw r11, r0 }
  200. { flush r11 ; addi r11, r11, 4 }
  201. seq r0, r33, r11
  202. bzt r0, 1b
  203. #ifdef RELOCATE_NEW_KERNEL_VERBOSE
  204. moveli r0, 's'
  205. jalr r40
  206. #endif
  207. addi r30, r30, 4
  208. j .Lloop
  209. .Lerr: moveli r0, 'e'
  210. jalr r40
  211. moveli r0, 'r'
  212. jalr r40
  213. moveli r0, 'r'
  214. jalr r40
  215. moveli r0, '\n'
  216. jalr r40
  217. .Lhalt:
  218. moveli r41, lo16(___hv_halt)
  219. auli r41, r41, ha16(___hv_halt)
  220. jalr r41
  221. STD_ENDPROC(relocate_new_kernel)
  222. .section .rodata,"a"
  223. .globl relocate_new_kernel_size
  224. relocate_new_kernel_size:
  225. .long .Lend_relocate_new_kernel - relocate_new_kernel