bookehv_interrupts.S 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. *
  15. * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
  16. *
  17. * Author: Varun Sethi <varun.sethi@freescale.com>
  18. * Author: Scott Wood <scotwood@freescale.com>
  19. * Author: Mihai Caraman <mihai.caraman@freescale.com>
  20. *
  21. * This file is derived from arch/powerpc/kvm/booke_interrupts.S
  22. */
  23. #include <asm/ppc_asm.h>
  24. #include <asm/kvm_asm.h>
  25. #include <asm/reg.h>
  26. #include <asm/page.h>
  27. #include <asm/asm-compat.h>
  28. #include <asm/asm-offsets.h>
  29. #include <asm/bitsperlong.h>
  30. #ifdef CONFIG_64BIT
  31. #include <asm/exception-64e.h>
  32. #include <asm/hw_irq.h>
  33. #include <asm/irqflags.h>
  34. #else
  35. #include "../kernel/head_booke.h" /* for THREAD_NORMSAVE() */
  36. #endif
  37. #define LONGBYTES (BITS_PER_LONG / 8)
  38. #define VCPU_GUEST_SPRG(n) (VCPU_GUEST_SPRGS + (n * LONGBYTES))
  39. /* The host stack layout: */
  40. #define HOST_R1 0 /* Implied by stwu. */
  41. #define HOST_CALLEE_LR PPC_LR_STKOFF
  42. #define HOST_RUN (HOST_CALLEE_LR + LONGBYTES)
  43. /*
  44. * r2 is special: it holds 'current', and it made nonvolatile in the
  45. * kernel with the -ffixed-r2 gcc option.
  46. */
  47. #define HOST_R2 (HOST_RUN + LONGBYTES)
  48. #define HOST_CR (HOST_R2 + LONGBYTES)
  49. #define HOST_NV_GPRS (HOST_CR + LONGBYTES)
  50. #define __HOST_NV_GPR(n) (HOST_NV_GPRS + ((n - 14) * LONGBYTES))
  51. #define HOST_NV_GPR(n) __HOST_NV_GPR(__REG_##n)
  52. #define HOST_MIN_STACK_SIZE (HOST_NV_GPR(R31) + LONGBYTES)
  53. #define HOST_STACK_SIZE ((HOST_MIN_STACK_SIZE + 15) & ~15) /* Align. */
  54. /* LR in caller stack frame. */
  55. #define HOST_STACK_LR (HOST_STACK_SIZE + PPC_LR_STKOFF)
  56. #define NEED_EMU 0x00000001 /* emulation -- save nv regs */
  57. #define NEED_DEAR 0x00000002 /* save faulting DEAR */
  58. #define NEED_ESR 0x00000004 /* save faulting ESR */
  59. /*
  60. * On entry:
  61. * r4 = vcpu, r5 = srr0, r6 = srr1
  62. * saved in vcpu: cr, ctr, r3-r13
  63. */
  64. .macro kvm_handler_common intno, srr0, flags
  65. /* Restore host stack pointer */
  66. PPC_STL r1, VCPU_GPR(R1)(r4)
  67. PPC_STL r2, VCPU_GPR(R2)(r4)
  68. PPC_LL r1, VCPU_HOST_STACK(r4)
  69. PPC_LL r2, HOST_R2(r1)
  70. mfspr r10, SPRN_PID
  71. lwz r8, VCPU_HOST_PID(r4)
  72. PPC_LL r11, VCPU_SHARED(r4)
  73. PPC_STL r14, VCPU_GPR(R14)(r4) /* We need a non-volatile GPR. */
  74. li r14, \intno
  75. stw r10, VCPU_GUEST_PID(r4)
  76. mtspr SPRN_PID, r8
  77. #ifdef CONFIG_KVM_EXIT_TIMING
  78. /* save exit time */
  79. 1: mfspr r7, SPRN_TBRU
  80. mfspr r8, SPRN_TBRL
  81. mfspr r9, SPRN_TBRU
  82. cmpw r9, r7
  83. stw r8, VCPU_TIMING_EXIT_TBL(r4)
  84. bne- 1b
  85. stw r9, VCPU_TIMING_EXIT_TBU(r4)
  86. #endif
  87. oris r8, r6, MSR_CE@h
  88. PPC_STD(r6, VCPU_SHARED_MSR, r11)
  89. ori r8, r8, MSR_ME | MSR_RI
  90. PPC_STL r5, VCPU_PC(r4)
  91. /*
  92. * Make sure CE/ME/RI are set (if appropriate for exception type)
  93. * whether or not the guest had it set. Since mfmsr/mtmsr are
  94. * somewhat expensive, skip in the common case where the guest
  95. * had all these bits set (and thus they're still set if
  96. * appropriate for the exception type).
  97. */
  98. cmpw r6, r8
  99. beq 1f
  100. mfmsr r7
  101. .if \srr0 != SPRN_MCSRR0 && \srr0 != SPRN_CSRR0
  102. oris r7, r7, MSR_CE@h
  103. .endif
  104. .if \srr0 != SPRN_MCSRR0
  105. ori r7, r7, MSR_ME | MSR_RI
  106. .endif
  107. mtmsr r7
  108. 1:
  109. .if \flags & NEED_EMU
  110. PPC_STL r15, VCPU_GPR(R15)(r4)
  111. PPC_STL r16, VCPU_GPR(R16)(r4)
  112. PPC_STL r17, VCPU_GPR(R17)(r4)
  113. PPC_STL r18, VCPU_GPR(R18)(r4)
  114. PPC_STL r19, VCPU_GPR(R19)(r4)
  115. PPC_STL r20, VCPU_GPR(R20)(r4)
  116. PPC_STL r21, VCPU_GPR(R21)(r4)
  117. PPC_STL r22, VCPU_GPR(R22)(r4)
  118. PPC_STL r23, VCPU_GPR(R23)(r4)
  119. PPC_STL r24, VCPU_GPR(R24)(r4)
  120. PPC_STL r25, VCPU_GPR(R25)(r4)
  121. PPC_STL r26, VCPU_GPR(R26)(r4)
  122. PPC_STL r27, VCPU_GPR(R27)(r4)
  123. PPC_STL r28, VCPU_GPR(R28)(r4)
  124. PPC_STL r29, VCPU_GPR(R29)(r4)
  125. PPC_STL r30, VCPU_GPR(R30)(r4)
  126. PPC_STL r31, VCPU_GPR(R31)(r4)
  127. /*
  128. * We don't use external PID support. lwepx faults would need to be
  129. * handled by KVM and this implies aditional code in DO_KVM (for
  130. * DTB_MISS, DSI and LRAT) to check ESR[EPID] and EPLC[EGS] which
  131. * is too intrusive for the host. Get last instuction in
  132. * kvmppc_get_last_inst().
  133. */
  134. li r9, KVM_INST_FETCH_FAILED
  135. stw r9, VCPU_LAST_INST(r4)
  136. .endif
  137. .if \flags & NEED_ESR
  138. mfspr r8, SPRN_ESR
  139. PPC_STL r8, VCPU_FAULT_ESR(r4)
  140. .endif
  141. .if \flags & NEED_DEAR
  142. mfspr r9, SPRN_DEAR
  143. PPC_STL r9, VCPU_FAULT_DEAR(r4)
  144. .endif
  145. b kvmppc_resume_host
  146. .endm
  147. #ifdef CONFIG_64BIT
  148. /* Exception types */
  149. #define EX_GEN 1
  150. #define EX_GDBELL 2
  151. #define EX_DBG 3
  152. #define EX_MC 4
  153. #define EX_CRIT 5
  154. #define EX_TLB 6
  155. /*
  156. * For input register values, see arch/powerpc/include/asm/kvm_booke_hv_asm.h
  157. */
  158. .macro kvm_handler intno type scratch, paca_ex, ex_r10, ex_r11, srr0, srr1, flags
  159. _GLOBAL(kvmppc_handler_\intno\()_\srr1)
  160. mr r11, r4
  161. /*
  162. * Get vcpu from Paca: paca->__current.thread->kvm_vcpu
  163. */
  164. PPC_LL r4, PACACURRENT(r13)
  165. PPC_LL r4, (THREAD + THREAD_KVM_VCPU)(r4)
  166. stw r10, VCPU_CR(r4)
  167. PPC_STL r11, VCPU_GPR(R4)(r4)
  168. PPC_STL r5, VCPU_GPR(R5)(r4)
  169. PPC_STL r6, VCPU_GPR(R6)(r4)
  170. PPC_STL r8, VCPU_GPR(R8)(r4)
  171. PPC_STL r9, VCPU_GPR(R9)(r4)
  172. .if \type == EX_TLB
  173. PPC_LL r5, EX_TLB_R13(r12)
  174. PPC_LL r6, EX_TLB_R10(r12)
  175. PPC_LL r8, EX_TLB_R11(r12)
  176. mfspr r12, \scratch
  177. .else
  178. mfspr r5, \scratch
  179. PPC_LL r6, (\paca_ex + \ex_r10)(r13)
  180. PPC_LL r8, (\paca_ex + \ex_r11)(r13)
  181. .endif
  182. PPC_STL r5, VCPU_GPR(R13)(r4)
  183. PPC_STL r3, VCPU_GPR(R3)(r4)
  184. PPC_STL r7, VCPU_GPR(R7)(r4)
  185. PPC_STL r12, VCPU_GPR(R12)(r4)
  186. PPC_STL r6, VCPU_GPR(R10)(r4)
  187. PPC_STL r8, VCPU_GPR(R11)(r4)
  188. mfctr r5
  189. PPC_STL r5, VCPU_CTR(r4)
  190. mfspr r5, \srr0
  191. mfspr r6, \srr1
  192. kvm_handler_common \intno, \srr0, \flags
  193. .endm
  194. #define EX_PARAMS(type) \
  195. EX_##type, \
  196. SPRN_SPRG_##type##_SCRATCH, \
  197. PACA_EX##type, \
  198. EX_R10, \
  199. EX_R11
  200. #define EX_PARAMS_TLB \
  201. EX_TLB, \
  202. SPRN_SPRG_GEN_SCRATCH, \
  203. PACA_EXTLB, \
  204. EX_TLB_R10, \
  205. EX_TLB_R11
  206. kvm_handler BOOKE_INTERRUPT_CRITICAL, EX_PARAMS(CRIT), \
  207. SPRN_CSRR0, SPRN_CSRR1, 0
  208. kvm_handler BOOKE_INTERRUPT_MACHINE_CHECK, EX_PARAMS(MC), \
  209. SPRN_MCSRR0, SPRN_MCSRR1, 0
  210. kvm_handler BOOKE_INTERRUPT_DATA_STORAGE, EX_PARAMS(GEN), \
  211. SPRN_SRR0, SPRN_SRR1,(NEED_EMU | NEED_DEAR | NEED_ESR)
  212. kvm_handler BOOKE_INTERRUPT_INST_STORAGE, EX_PARAMS(GEN), \
  213. SPRN_SRR0, SPRN_SRR1, NEED_ESR
  214. kvm_handler BOOKE_INTERRUPT_EXTERNAL, EX_PARAMS(GEN), \
  215. SPRN_SRR0, SPRN_SRR1, 0
  216. kvm_handler BOOKE_INTERRUPT_ALIGNMENT, EX_PARAMS(GEN), \
  217. SPRN_SRR0, SPRN_SRR1,(NEED_DEAR | NEED_ESR)
  218. kvm_handler BOOKE_INTERRUPT_PROGRAM, EX_PARAMS(GEN), \
  219. SPRN_SRR0, SPRN_SRR1, (NEED_ESR | NEED_EMU)
  220. kvm_handler BOOKE_INTERRUPT_FP_UNAVAIL, EX_PARAMS(GEN), \
  221. SPRN_SRR0, SPRN_SRR1, 0
  222. kvm_handler BOOKE_INTERRUPT_AP_UNAVAIL, EX_PARAMS(GEN), \
  223. SPRN_SRR0, SPRN_SRR1, 0
  224. kvm_handler BOOKE_INTERRUPT_DECREMENTER, EX_PARAMS(GEN), \
  225. SPRN_SRR0, SPRN_SRR1, 0
  226. kvm_handler BOOKE_INTERRUPT_FIT, EX_PARAMS(GEN), \
  227. SPRN_SRR0, SPRN_SRR1, 0
  228. kvm_handler BOOKE_INTERRUPT_WATCHDOG, EX_PARAMS(CRIT),\
  229. SPRN_CSRR0, SPRN_CSRR1, 0
  230. /*
  231. * Only bolted TLB miss exception handlers are supported for now
  232. */
  233. kvm_handler BOOKE_INTERRUPT_DTLB_MISS, EX_PARAMS_TLB, \
  234. SPRN_SRR0, SPRN_SRR1, (NEED_EMU | NEED_DEAR | NEED_ESR)
  235. kvm_handler BOOKE_INTERRUPT_ITLB_MISS, EX_PARAMS_TLB, \
  236. SPRN_SRR0, SPRN_SRR1, 0
  237. kvm_handler BOOKE_INTERRUPT_ALTIVEC_UNAVAIL, EX_PARAMS(GEN), \
  238. SPRN_SRR0, SPRN_SRR1, 0
  239. kvm_handler BOOKE_INTERRUPT_ALTIVEC_ASSIST, EX_PARAMS(GEN), \
  240. SPRN_SRR0, SPRN_SRR1, 0
  241. kvm_handler BOOKE_INTERRUPT_PERFORMANCE_MONITOR, EX_PARAMS(GEN), \
  242. SPRN_SRR0, SPRN_SRR1, 0
  243. kvm_handler BOOKE_INTERRUPT_DOORBELL, EX_PARAMS(GEN), \
  244. SPRN_SRR0, SPRN_SRR1, 0
  245. kvm_handler BOOKE_INTERRUPT_DOORBELL_CRITICAL, EX_PARAMS(CRIT), \
  246. SPRN_CSRR0, SPRN_CSRR1, 0
  247. kvm_handler BOOKE_INTERRUPT_HV_PRIV, EX_PARAMS(GEN), \
  248. SPRN_SRR0, SPRN_SRR1, NEED_EMU
  249. kvm_handler BOOKE_INTERRUPT_HV_SYSCALL, EX_PARAMS(GEN), \
  250. SPRN_SRR0, SPRN_SRR1, 0
  251. kvm_handler BOOKE_INTERRUPT_GUEST_DBELL, EX_PARAMS(GDBELL), \
  252. SPRN_GSRR0, SPRN_GSRR1, 0
  253. kvm_handler BOOKE_INTERRUPT_GUEST_DBELL_CRIT, EX_PARAMS(CRIT), \
  254. SPRN_CSRR0, SPRN_CSRR1, 0
  255. kvm_handler BOOKE_INTERRUPT_DEBUG, EX_PARAMS(DBG), \
  256. SPRN_DSRR0, SPRN_DSRR1, 0
  257. kvm_handler BOOKE_INTERRUPT_DEBUG, EX_PARAMS(CRIT), \
  258. SPRN_CSRR0, SPRN_CSRR1, 0
  259. kvm_handler BOOKE_INTERRUPT_LRAT_ERROR, EX_PARAMS(GEN), \
  260. SPRN_SRR0, SPRN_SRR1, (NEED_EMU | NEED_DEAR | NEED_ESR)
  261. #else
  262. /*
  263. * For input register values, see arch/powerpc/include/asm/kvm_booke_hv_asm.h
  264. */
  265. .macro kvm_handler intno srr0, srr1, flags
  266. _GLOBAL(kvmppc_handler_\intno\()_\srr1)
  267. PPC_LL r11, THREAD_KVM_VCPU(r10)
  268. PPC_STL r3, VCPU_GPR(R3)(r11)
  269. mfspr r3, SPRN_SPRG_RSCRATCH0
  270. PPC_STL r4, VCPU_GPR(R4)(r11)
  271. PPC_LL r4, THREAD_NORMSAVE(0)(r10)
  272. PPC_STL r5, VCPU_GPR(R5)(r11)
  273. stw r13, VCPU_CR(r11)
  274. mfspr r5, \srr0
  275. PPC_STL r3, VCPU_GPR(R10)(r11)
  276. PPC_LL r3, THREAD_NORMSAVE(2)(r10)
  277. PPC_STL r6, VCPU_GPR(R6)(r11)
  278. PPC_STL r4, VCPU_GPR(R11)(r11)
  279. mfspr r6, \srr1
  280. PPC_STL r7, VCPU_GPR(R7)(r11)
  281. PPC_STL r8, VCPU_GPR(R8)(r11)
  282. PPC_STL r9, VCPU_GPR(R9)(r11)
  283. PPC_STL r3, VCPU_GPR(R13)(r11)
  284. mfctr r7
  285. PPC_STL r12, VCPU_GPR(R12)(r11)
  286. PPC_STL r7, VCPU_CTR(r11)
  287. mr r4, r11
  288. kvm_handler_common \intno, \srr0, \flags
  289. .endm
  290. .macro kvm_lvl_handler intno scratch srr0, srr1, flags
  291. _GLOBAL(kvmppc_handler_\intno\()_\srr1)
  292. mfspr r10, SPRN_SPRG_THREAD
  293. PPC_LL r11, THREAD_KVM_VCPU(r10)
  294. PPC_STL r3, VCPU_GPR(R3)(r11)
  295. mfspr r3, \scratch
  296. PPC_STL r4, VCPU_GPR(R4)(r11)
  297. PPC_LL r4, GPR9(r8)
  298. PPC_STL r5, VCPU_GPR(R5)(r11)
  299. stw r9, VCPU_CR(r11)
  300. mfspr r5, \srr0
  301. PPC_STL r3, VCPU_GPR(R8)(r11)
  302. PPC_LL r3, GPR10(r8)
  303. PPC_STL r6, VCPU_GPR(R6)(r11)
  304. PPC_STL r4, VCPU_GPR(R9)(r11)
  305. mfspr r6, \srr1
  306. PPC_LL r4, GPR11(r8)
  307. PPC_STL r7, VCPU_GPR(R7)(r11)
  308. PPC_STL r3, VCPU_GPR(R10)(r11)
  309. mfctr r7
  310. PPC_STL r12, VCPU_GPR(R12)(r11)
  311. PPC_STL r13, VCPU_GPR(R13)(r11)
  312. PPC_STL r4, VCPU_GPR(R11)(r11)
  313. PPC_STL r7, VCPU_CTR(r11)
  314. mr r4, r11
  315. kvm_handler_common \intno, \srr0, \flags
  316. .endm
  317. kvm_lvl_handler BOOKE_INTERRUPT_CRITICAL, \
  318. SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0
  319. kvm_lvl_handler BOOKE_INTERRUPT_MACHINE_CHECK, \
  320. SPRN_SPRG_RSCRATCH_MC, SPRN_MCSRR0, SPRN_MCSRR1, 0
  321. kvm_handler BOOKE_INTERRUPT_DATA_STORAGE, \
  322. SPRN_SRR0, SPRN_SRR1, (NEED_EMU | NEED_DEAR | NEED_ESR)
  323. kvm_handler BOOKE_INTERRUPT_INST_STORAGE, SPRN_SRR0, SPRN_SRR1, NEED_ESR
  324. kvm_handler BOOKE_INTERRUPT_EXTERNAL, SPRN_SRR0, SPRN_SRR1, 0
  325. kvm_handler BOOKE_INTERRUPT_ALIGNMENT, \
  326. SPRN_SRR0, SPRN_SRR1, (NEED_DEAR | NEED_ESR)
  327. kvm_handler BOOKE_INTERRUPT_PROGRAM, SPRN_SRR0, SPRN_SRR1, (NEED_ESR | NEED_EMU)
  328. kvm_handler BOOKE_INTERRUPT_FP_UNAVAIL, SPRN_SRR0, SPRN_SRR1, 0
  329. kvm_handler BOOKE_INTERRUPT_SYSCALL, SPRN_SRR0, SPRN_SRR1, 0
  330. kvm_handler BOOKE_INTERRUPT_AP_UNAVAIL, SPRN_SRR0, SPRN_SRR1, 0
  331. kvm_handler BOOKE_INTERRUPT_DECREMENTER, SPRN_SRR0, SPRN_SRR1, 0
  332. kvm_handler BOOKE_INTERRUPT_FIT, SPRN_SRR0, SPRN_SRR1, 0
  333. kvm_lvl_handler BOOKE_INTERRUPT_WATCHDOG, \
  334. SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0
  335. kvm_handler BOOKE_INTERRUPT_DTLB_MISS, \
  336. SPRN_SRR0, SPRN_SRR1, (NEED_EMU | NEED_DEAR | NEED_ESR)
  337. kvm_handler BOOKE_INTERRUPT_ITLB_MISS, SPRN_SRR0, SPRN_SRR1, 0
  338. kvm_handler BOOKE_INTERRUPT_PERFORMANCE_MONITOR, SPRN_SRR0, SPRN_SRR1, 0
  339. kvm_handler BOOKE_INTERRUPT_DOORBELL, SPRN_SRR0, SPRN_SRR1, 0
  340. kvm_lvl_handler BOOKE_INTERRUPT_DOORBELL_CRITICAL, \
  341. SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0
  342. kvm_handler BOOKE_INTERRUPT_HV_PRIV, SPRN_SRR0, SPRN_SRR1, NEED_EMU
  343. kvm_handler BOOKE_INTERRUPT_HV_SYSCALL, SPRN_SRR0, SPRN_SRR1, 0
  344. kvm_handler BOOKE_INTERRUPT_GUEST_DBELL, SPRN_GSRR0, SPRN_GSRR1, 0
  345. kvm_lvl_handler BOOKE_INTERRUPT_GUEST_DBELL_CRIT, \
  346. SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0
  347. kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \
  348. SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0
  349. kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \
  350. SPRN_SPRG_RSCRATCH_DBG, SPRN_DSRR0, SPRN_DSRR1, 0
  351. #endif
  352. /* Registers:
  353. * SPRG_SCRATCH0: guest r10
  354. * r4: vcpu pointer
  355. * r11: vcpu->arch.shared
  356. * r14: KVM exit number
  357. */
  358. _GLOBAL(kvmppc_resume_host)
  359. /* Save remaining volatile guest register state to vcpu. */
  360. mfspr r3, SPRN_VRSAVE
  361. PPC_STL r0, VCPU_GPR(R0)(r4)
  362. mflr r5
  363. mfspr r6, SPRN_SPRG4
  364. PPC_STL r5, VCPU_LR(r4)
  365. mfspr r7, SPRN_SPRG5
  366. stw r3, VCPU_VRSAVE(r4)
  367. #ifdef CONFIG_64BIT
  368. PPC_LL r3, PACA_SPRG_VDSO(r13)
  369. #endif
  370. mfspr r5, SPRN_SPRG9
  371. PPC_STD(r6, VCPU_SHARED_SPRG4, r11)
  372. mfspr r8, SPRN_SPRG6
  373. PPC_STD(r7, VCPU_SHARED_SPRG5, r11)
  374. mfspr r9, SPRN_SPRG7
  375. #ifdef CONFIG_64BIT
  376. mtspr SPRN_SPRG_VDSO_WRITE, r3
  377. #endif
  378. PPC_STD(r5, VCPU_SPRG9, r4)
  379. PPC_STD(r8, VCPU_SHARED_SPRG6, r11)
  380. mfxer r3
  381. PPC_STD(r9, VCPU_SHARED_SPRG7, r11)
  382. /* save guest MAS registers and restore host mas4 & mas6 */
  383. mfspr r5, SPRN_MAS0
  384. PPC_STL r3, VCPU_XER(r4)
  385. mfspr r6, SPRN_MAS1
  386. stw r5, VCPU_SHARED_MAS0(r11)
  387. mfspr r7, SPRN_MAS2
  388. stw r6, VCPU_SHARED_MAS1(r11)
  389. PPC_STD(r7, VCPU_SHARED_MAS2, r11)
  390. mfspr r5, SPRN_MAS3
  391. mfspr r6, SPRN_MAS4
  392. stw r5, VCPU_SHARED_MAS7_3+4(r11)
  393. mfspr r7, SPRN_MAS6
  394. stw r6, VCPU_SHARED_MAS4(r11)
  395. mfspr r5, SPRN_MAS7
  396. lwz r6, VCPU_HOST_MAS4(r4)
  397. stw r7, VCPU_SHARED_MAS6(r11)
  398. lwz r8, VCPU_HOST_MAS6(r4)
  399. mtspr SPRN_MAS4, r6
  400. stw r5, VCPU_SHARED_MAS7_3+0(r11)
  401. mtspr SPRN_MAS6, r8
  402. /* Enable MAS register updates via exception */
  403. mfspr r3, SPRN_EPCR
  404. rlwinm r3, r3, 0, ~SPRN_EPCR_DMIUH
  405. mtspr SPRN_EPCR, r3
  406. isync
  407. #ifdef CONFIG_64BIT
  408. /*
  409. * We enter with interrupts disabled in hardware, but
  410. * we need to call RECONCILE_IRQ_STATE to ensure
  411. * that the software state is kept in sync.
  412. */
  413. RECONCILE_IRQ_STATE(r3,r5)
  414. #endif
  415. /* Switch to kernel stack and jump to handler. */
  416. PPC_LL r3, HOST_RUN(r1)
  417. mr r5, r14 /* intno */
  418. mr r14, r4 /* Save vcpu pointer. */
  419. bl kvmppc_handle_exit
  420. /* Restore vcpu pointer and the nonvolatiles we used. */
  421. mr r4, r14
  422. PPC_LL r14, VCPU_GPR(R14)(r4)
  423. andi. r5, r3, RESUME_FLAG_NV
  424. beq skip_nv_load
  425. PPC_LL r15, VCPU_GPR(R15)(r4)
  426. PPC_LL r16, VCPU_GPR(R16)(r4)
  427. PPC_LL r17, VCPU_GPR(R17)(r4)
  428. PPC_LL r18, VCPU_GPR(R18)(r4)
  429. PPC_LL r19, VCPU_GPR(R19)(r4)
  430. PPC_LL r20, VCPU_GPR(R20)(r4)
  431. PPC_LL r21, VCPU_GPR(R21)(r4)
  432. PPC_LL r22, VCPU_GPR(R22)(r4)
  433. PPC_LL r23, VCPU_GPR(R23)(r4)
  434. PPC_LL r24, VCPU_GPR(R24)(r4)
  435. PPC_LL r25, VCPU_GPR(R25)(r4)
  436. PPC_LL r26, VCPU_GPR(R26)(r4)
  437. PPC_LL r27, VCPU_GPR(R27)(r4)
  438. PPC_LL r28, VCPU_GPR(R28)(r4)
  439. PPC_LL r29, VCPU_GPR(R29)(r4)
  440. PPC_LL r30, VCPU_GPR(R30)(r4)
  441. PPC_LL r31, VCPU_GPR(R31)(r4)
  442. skip_nv_load:
  443. /* Should we return to the guest? */
  444. andi. r5, r3, RESUME_FLAG_HOST
  445. beq lightweight_exit
  446. srawi r3, r3, 2 /* Shift -ERR back down. */
  447. heavyweight_exit:
  448. /* Not returning to guest. */
  449. PPC_LL r5, HOST_STACK_LR(r1)
  450. lwz r6, HOST_CR(r1)
  451. /*
  452. * We already saved guest volatile register state; now save the
  453. * non-volatiles.
  454. */
  455. PPC_STL r15, VCPU_GPR(R15)(r4)
  456. PPC_STL r16, VCPU_GPR(R16)(r4)
  457. PPC_STL r17, VCPU_GPR(R17)(r4)
  458. PPC_STL r18, VCPU_GPR(R18)(r4)
  459. PPC_STL r19, VCPU_GPR(R19)(r4)
  460. PPC_STL r20, VCPU_GPR(R20)(r4)
  461. PPC_STL r21, VCPU_GPR(R21)(r4)
  462. PPC_STL r22, VCPU_GPR(R22)(r4)
  463. PPC_STL r23, VCPU_GPR(R23)(r4)
  464. PPC_STL r24, VCPU_GPR(R24)(r4)
  465. PPC_STL r25, VCPU_GPR(R25)(r4)
  466. PPC_STL r26, VCPU_GPR(R26)(r4)
  467. PPC_STL r27, VCPU_GPR(R27)(r4)
  468. PPC_STL r28, VCPU_GPR(R28)(r4)
  469. PPC_STL r29, VCPU_GPR(R29)(r4)
  470. PPC_STL r30, VCPU_GPR(R30)(r4)
  471. PPC_STL r31, VCPU_GPR(R31)(r4)
  472. /* Load host non-volatile register state from host stack. */
  473. PPC_LL r14, HOST_NV_GPR(R14)(r1)
  474. PPC_LL r15, HOST_NV_GPR(R15)(r1)
  475. PPC_LL r16, HOST_NV_GPR(R16)(r1)
  476. PPC_LL r17, HOST_NV_GPR(R17)(r1)
  477. PPC_LL r18, HOST_NV_GPR(R18)(r1)
  478. PPC_LL r19, HOST_NV_GPR(R19)(r1)
  479. PPC_LL r20, HOST_NV_GPR(R20)(r1)
  480. PPC_LL r21, HOST_NV_GPR(R21)(r1)
  481. PPC_LL r22, HOST_NV_GPR(R22)(r1)
  482. PPC_LL r23, HOST_NV_GPR(R23)(r1)
  483. PPC_LL r24, HOST_NV_GPR(R24)(r1)
  484. PPC_LL r25, HOST_NV_GPR(R25)(r1)
  485. PPC_LL r26, HOST_NV_GPR(R26)(r1)
  486. PPC_LL r27, HOST_NV_GPR(R27)(r1)
  487. PPC_LL r28, HOST_NV_GPR(R28)(r1)
  488. PPC_LL r29, HOST_NV_GPR(R29)(r1)
  489. PPC_LL r30, HOST_NV_GPR(R30)(r1)
  490. PPC_LL r31, HOST_NV_GPR(R31)(r1)
  491. /* Return to kvm_vcpu_run(). */
  492. mtlr r5
  493. mtcr r6
  494. addi r1, r1, HOST_STACK_SIZE
  495. /* r3 still contains the return code from kvmppc_handle_exit(). */
  496. blr
  497. /* Registers:
  498. * r3: kvm_run pointer
  499. * r4: vcpu pointer
  500. */
  501. _GLOBAL(__kvmppc_vcpu_run)
  502. stwu r1, -HOST_STACK_SIZE(r1)
  503. PPC_STL r1, VCPU_HOST_STACK(r4) /* Save stack pointer to vcpu. */
  504. /* Save host state to stack. */
  505. PPC_STL r3, HOST_RUN(r1)
  506. mflr r3
  507. mfcr r5
  508. PPC_STL r3, HOST_STACK_LR(r1)
  509. stw r5, HOST_CR(r1)
  510. /* Save host non-volatile register state to stack. */
  511. PPC_STL r14, HOST_NV_GPR(R14)(r1)
  512. PPC_STL r15, HOST_NV_GPR(R15)(r1)
  513. PPC_STL r16, HOST_NV_GPR(R16)(r1)
  514. PPC_STL r17, HOST_NV_GPR(R17)(r1)
  515. PPC_STL r18, HOST_NV_GPR(R18)(r1)
  516. PPC_STL r19, HOST_NV_GPR(R19)(r1)
  517. PPC_STL r20, HOST_NV_GPR(R20)(r1)
  518. PPC_STL r21, HOST_NV_GPR(R21)(r1)
  519. PPC_STL r22, HOST_NV_GPR(R22)(r1)
  520. PPC_STL r23, HOST_NV_GPR(R23)(r1)
  521. PPC_STL r24, HOST_NV_GPR(R24)(r1)
  522. PPC_STL r25, HOST_NV_GPR(R25)(r1)
  523. PPC_STL r26, HOST_NV_GPR(R26)(r1)
  524. PPC_STL r27, HOST_NV_GPR(R27)(r1)
  525. PPC_STL r28, HOST_NV_GPR(R28)(r1)
  526. PPC_STL r29, HOST_NV_GPR(R29)(r1)
  527. PPC_STL r30, HOST_NV_GPR(R30)(r1)
  528. PPC_STL r31, HOST_NV_GPR(R31)(r1)
  529. /* Load guest non-volatiles. */
  530. PPC_LL r14, VCPU_GPR(R14)(r4)
  531. PPC_LL r15, VCPU_GPR(R15)(r4)
  532. PPC_LL r16, VCPU_GPR(R16)(r4)
  533. PPC_LL r17, VCPU_GPR(R17)(r4)
  534. PPC_LL r18, VCPU_GPR(R18)(r4)
  535. PPC_LL r19, VCPU_GPR(R19)(r4)
  536. PPC_LL r20, VCPU_GPR(R20)(r4)
  537. PPC_LL r21, VCPU_GPR(R21)(r4)
  538. PPC_LL r22, VCPU_GPR(R22)(r4)
  539. PPC_LL r23, VCPU_GPR(R23)(r4)
  540. PPC_LL r24, VCPU_GPR(R24)(r4)
  541. PPC_LL r25, VCPU_GPR(R25)(r4)
  542. PPC_LL r26, VCPU_GPR(R26)(r4)
  543. PPC_LL r27, VCPU_GPR(R27)(r4)
  544. PPC_LL r28, VCPU_GPR(R28)(r4)
  545. PPC_LL r29, VCPU_GPR(R29)(r4)
  546. PPC_LL r30, VCPU_GPR(R30)(r4)
  547. PPC_LL r31, VCPU_GPR(R31)(r4)
  548. lightweight_exit:
  549. PPC_STL r2, HOST_R2(r1)
  550. mfspr r3, SPRN_PID
  551. stw r3, VCPU_HOST_PID(r4)
  552. lwz r3, VCPU_GUEST_PID(r4)
  553. mtspr SPRN_PID, r3
  554. PPC_LL r11, VCPU_SHARED(r4)
  555. /* Disable MAS register updates via exception */
  556. mfspr r3, SPRN_EPCR
  557. oris r3, r3, SPRN_EPCR_DMIUH@h
  558. mtspr SPRN_EPCR, r3
  559. isync
  560. /* Save host mas4 and mas6 and load guest MAS registers */
  561. mfspr r3, SPRN_MAS4
  562. stw r3, VCPU_HOST_MAS4(r4)
  563. mfspr r3, SPRN_MAS6
  564. stw r3, VCPU_HOST_MAS6(r4)
  565. lwz r3, VCPU_SHARED_MAS0(r11)
  566. lwz r5, VCPU_SHARED_MAS1(r11)
  567. PPC_LD(r6, VCPU_SHARED_MAS2, r11)
  568. lwz r7, VCPU_SHARED_MAS7_3+4(r11)
  569. lwz r8, VCPU_SHARED_MAS4(r11)
  570. mtspr SPRN_MAS0, r3
  571. mtspr SPRN_MAS1, r5
  572. mtspr SPRN_MAS2, r6
  573. mtspr SPRN_MAS3, r7
  574. mtspr SPRN_MAS4, r8
  575. lwz r3, VCPU_SHARED_MAS6(r11)
  576. lwz r5, VCPU_SHARED_MAS7_3+0(r11)
  577. mtspr SPRN_MAS6, r3
  578. mtspr SPRN_MAS7, r5
  579. /*
  580. * Host interrupt handlers may have clobbered these guest-readable
  581. * SPRGs, so we need to reload them here with the guest's values.
  582. */
  583. lwz r3, VCPU_VRSAVE(r4)
  584. PPC_LD(r5, VCPU_SHARED_SPRG4, r11)
  585. mtspr SPRN_VRSAVE, r3
  586. PPC_LD(r6, VCPU_SHARED_SPRG5, r11)
  587. mtspr SPRN_SPRG4W, r5
  588. PPC_LD(r7, VCPU_SHARED_SPRG6, r11)
  589. mtspr SPRN_SPRG5W, r6
  590. PPC_LD(r8, VCPU_SHARED_SPRG7, r11)
  591. mtspr SPRN_SPRG6W, r7
  592. PPC_LD(r5, VCPU_SPRG9, r4)
  593. mtspr SPRN_SPRG7W, r8
  594. mtspr SPRN_SPRG9, r5
  595. /* Load some guest volatiles. */
  596. PPC_LL r3, VCPU_LR(r4)
  597. PPC_LL r5, VCPU_XER(r4)
  598. PPC_LL r6, VCPU_CTR(r4)
  599. lwz r7, VCPU_CR(r4)
  600. PPC_LL r8, VCPU_PC(r4)
  601. PPC_LD(r9, VCPU_SHARED_MSR, r11)
  602. PPC_LL r0, VCPU_GPR(R0)(r4)
  603. PPC_LL r1, VCPU_GPR(R1)(r4)
  604. PPC_LL r2, VCPU_GPR(R2)(r4)
  605. PPC_LL r10, VCPU_GPR(R10)(r4)
  606. PPC_LL r11, VCPU_GPR(R11)(r4)
  607. PPC_LL r12, VCPU_GPR(R12)(r4)
  608. PPC_LL r13, VCPU_GPR(R13)(r4)
  609. mtlr r3
  610. mtxer r5
  611. mtctr r6
  612. mtsrr0 r8
  613. mtsrr1 r9
  614. #ifdef CONFIG_KVM_EXIT_TIMING
  615. /* save enter time */
  616. 1:
  617. mfspr r6, SPRN_TBRU
  618. mfspr r9, SPRN_TBRL
  619. mfspr r8, SPRN_TBRU
  620. cmpw r8, r6
  621. stw r9, VCPU_TIMING_LAST_ENTER_TBL(r4)
  622. bne 1b
  623. stw r8, VCPU_TIMING_LAST_ENTER_TBU(r4)
  624. #endif
  625. /*
  626. * Don't execute any instruction which can change CR after
  627. * below instruction.
  628. */
  629. mtcr r7
  630. /* Finish loading guest volatiles and jump to guest. */
  631. PPC_LL r5, VCPU_GPR(R5)(r4)
  632. PPC_LL r6, VCPU_GPR(R6)(r4)
  633. PPC_LL r7, VCPU_GPR(R7)(r4)
  634. PPC_LL r8, VCPU_GPR(R8)(r4)
  635. PPC_LL r9, VCPU_GPR(R9)(r4)
  636. PPC_LL r3, VCPU_GPR(R3)(r4)
  637. PPC_LL r4, VCPU_GPR(R4)(r4)
  638. rfi