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.
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.
11 * Copyright 2011 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
13 * Derived from book3s_rmhandlers.S and other files, which are:
15 * Copyright SUSE Linux Products GmbH 2009
17 * Authors: Alexander Graf <agraf@suse.de>
20 #include <asm/ppc_asm.h>
21 #include <asm/kvm_asm.h>
25 #include <asm/ptrace.h>
26 #include <asm/hvcall.h>
27 #include <asm/asm-offsets.h>
28 #include <asm/exception-64s.h>
29 #include <asm/kvm_book3s_asm.h>
30 #include <asm/mmu-hash64.h>
32 #ifdef __LITTLE_ENDIAN__
33 #error Need to fix lppaca and SLB shadow accesses in little endian mode
36 /*****************************************************************************
38 * Real Mode handlers that need to be in the linear mapping *
40 ****************************************************************************/
42 .globl kvmppc_skip_interrupt
43 kvmppc_skip_interrupt:
51 .globl kvmppc_skip_Hinterrupt
52 kvmppc_skip_Hinterrupt:
61 * Call kvmppc_hv_entry in real mode.
62 * Must be called with interrupts hard-disabled.
66 * LR = return address to continue at after eventually re-enabling MMU
68 _GLOBAL(kvmppc_hv_entry_trampoline)
70 std r0, PPC_LR_STKOFF(r1)
73 LOAD_REG_ADDR(r5, kvmppc_call_hv_entry)
78 mtmsrd r0,1 /* clear RI in MSR */
86 /* Back from guest - restore host state and return to caller */
88 /* Restore host DABR and DABRX */
89 ld r5,HSTATE_DABR(r13)
99 * Reload DEC. HDEC interrupts were disabled when
100 * we reloaded the host's LPCR value.
102 ld r3, HSTATE_DECEXP(r13)
107 /* Reload the host's PMU registers */
108 ld r3, PACALPPACAPTR(r13) /* is the host using the PMU? */
109 lbz r4, LPPACA_PMCINUSE(r3)
111 beq 23f /* skip if not */
112 lwz r3, HSTATE_PMC(r13)
113 lwz r4, HSTATE_PMC + 4(r13)
114 lwz r5, HSTATE_PMC + 8(r13)
115 lwz r6, HSTATE_PMC + 12(r13)
116 lwz r8, HSTATE_PMC + 16(r13)
117 lwz r9, HSTATE_PMC + 20(r13)
119 lwz r10, HSTATE_PMC + 24(r13)
120 lwz r11, HSTATE_PMC + 28(r13)
121 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
131 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
132 ld r3, HSTATE_MMCR(r13)
133 ld r4, HSTATE_MMCR + 8(r13)
134 ld r5, HSTATE_MMCR + 16(r13)
142 * For external and machine check interrupts, we need
143 * to call the Linux handler to process the interrupt.
144 * We do that by jumping to absolute address 0x500 for
145 * external interrupts, or the machine_check_fwnmi label
146 * for machine checks (since firmware might have patched
147 * the vector area at 0x200). The [h]rfid at the end of the
148 * handler will return to the book3s_hv_interrupts.S code.
149 * For other interrupts we do the rfid to get back
150 * to the book3s_hv_interrupts.S code here.
152 ld r8, 112+PPC_LR_STKOFF(r1)
154 ld r7, HSTATE_HOST_MSR(r13)
156 cmpwi cr1, r12, BOOK3S_INTERRUPT_MACHINE_CHECK
157 cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL
160 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
162 /* RFI into the highmem handler, or branch to interrupt handler */
166 mtmsrd r6, 1 /* Clear RI in MSR */
169 beqa 0x500 /* external interrupt (PPC970) */
170 beq cr1, 13f /* machine check */
173 /* On POWER7, we have external interrupts set to use HSRR0/1 */
174 11: mtspr SPRN_HSRR0, r8
178 13: b machine_check_fwnmi
182 * We come in here when wakened from nap mode on a secondary hw thread.
183 * Relocation is off and most register values are lost.
184 * r13 points to the PACA.
186 .globl kvm_start_guest
188 ld r1,PACAEMERGSP(r13)
189 subi r1,r1,STACK_FRAME_OVERHEAD
192 li r0,KVM_HWTHREAD_IN_KVM
193 stb r0,HSTATE_HWTHREAD_STATE(r13)
195 /* NV GPR values from power7_idle() will no longer be valid */
197 stb r0,PACA_NAPSTATELOST(r13)
199 /* were we napping due to cede? */
200 lbz r0,HSTATE_NAPPING(r13)
205 * We weren't napping due to cede, so this must be a secondary
206 * thread being woken up to run a guest, or being woken up due
207 * to a stray IPI. (Or due to some machine check or hypervisor
208 * maintenance interrupt while the core is in KVM.)
211 /* Check the wake reason in SRR1 to see why we got here */
213 rlwinm r3,r3,44-31,0x7 /* extract wake reason field */
214 cmpwi r3,4 /* was it an external interrupt? */
216 ld r5,HSTATE_XICS_PHYS(r13)
217 li r7,XICS_XIRR /* if it was an external interrupt, */
218 lwzcix r8,r5,r7 /* get and ack the interrupt */
220 clrldi. r9,r8,40 /* get interrupt source ID. */
221 beq 28f /* none there? */
222 cmpwi r9,XICS_IPI /* was it an IPI? */
226 stbcix r0,r5,r6 /* clear IPI */
227 stwcix r8,r5,r7 /* EOI the interrupt */
228 sync /* order loading of vcpu after that */
230 /* get vcpu pointer, NULL if we have no vcpu to run */
231 ld r4,HSTATE_KVM_VCPU(r13)
233 /* if we have no vcpu to run, go back to sleep */
237 27: /* XXX should handle hypervisor maintenance interrupts etc. here */
239 28: /* SRR1 said external but ICP said nope?? */
241 29: /* External non-IPI interrupt to offline secondary thread? help?? */
242 stw r8,HSTATE_SAVED_XIRR(r13)
245 30: bl kvmppc_hv_entry
247 /* Back from the guest, go back to nap */
248 /* Clear our vcpu pointer so we don't come back in early */
250 std r0, HSTATE_KVM_VCPU(r13)
252 /* Clear any pending IPI - we're an offline thread */
253 ld r5, HSTATE_XICS_PHYS(r13)
255 lwzcix r3, r5, r7 /* ack any pending interrupt */
256 rlwinm. r0, r3, 0, 0xffffff /* any pending? */
261 stbcix r0, r5, r6 /* clear the IPI */
262 stwcix r3, r5, r7 /* EOI it */
265 /* increment the nap count and then go to nap mode */
266 ld r4, HSTATE_KVM_VCORE(r13)
267 addi r4, r4, VCORE_NAP_COUNT
268 lwsync /* make previous updates visible */
275 li r0, KVM_HWTHREAD_IN_NAP
276 stb r0, HSTATE_HWTHREAD_STATE(r13)
279 rlwimi r4, r3, 0, LPCR_PECE0 | LPCR_PECE1
282 std r0, HSTATE_SCRATCH0(r13)
284 ld r0, HSTATE_SCRATCH0(r13)
290 /******************************************************************************
294 *****************************************************************************/
296 .global kvmppc_hv_entry
305 * all other volatile GPRS = free
308 std r0, PPC_LR_STKOFF(r1)
311 /* Set partition DABR */
312 /* Do this before re-enabling PMU to avoid P7 DABR corruption bug */
319 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
321 /* Load guest PMU registers */
322 /* R4 is live here (vcpu pointer) */
324 sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
325 mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */
327 lwz r3, VCPU_PMC(r4) /* always load up guest PMU registers */
328 lwz r5, VCPU_PMC + 4(r4) /* to prevent information leak */
329 lwz r6, VCPU_PMC + 8(r4)
330 lwz r7, VCPU_PMC + 12(r4)
331 lwz r8, VCPU_PMC + 16(r4)
332 lwz r9, VCPU_PMC + 20(r4)
334 lwz r10, VCPU_PMC + 24(r4)
335 lwz r11, VCPU_PMC + 28(r4)
336 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
346 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
348 ld r5, VCPU_MMCR + 8(r4)
349 ld r6, VCPU_MMCR + 16(r4)
359 /* Load up FP, VMX and VSX registers */
362 ld r14, VCPU_GPR(R14)(r4)
363 ld r15, VCPU_GPR(R15)(r4)
364 ld r16, VCPU_GPR(R16)(r4)
365 ld r17, VCPU_GPR(R17)(r4)
366 ld r18, VCPU_GPR(R18)(r4)
367 ld r19, VCPU_GPR(R19)(r4)
368 ld r20, VCPU_GPR(R20)(r4)
369 ld r21, VCPU_GPR(R21)(r4)
370 ld r22, VCPU_GPR(R22)(r4)
371 ld r23, VCPU_GPR(R23)(r4)
372 ld r24, VCPU_GPR(R24)(r4)
373 ld r25, VCPU_GPR(R25)(r4)
374 ld r26, VCPU_GPR(R26)(r4)
375 ld r27, VCPU_GPR(R27)(r4)
376 ld r28, VCPU_GPR(R28)(r4)
377 ld r29, VCPU_GPR(R29)(r4)
378 ld r30, VCPU_GPR(R30)(r4)
379 ld r31, VCPU_GPR(R31)(r4)
382 /* Switch DSCR to guest value */
385 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
388 * Set the decrementer to the guest decrementer.
390 ld r8,VCPU_DEC_EXPIRES(r4)
396 ld r5, VCPU_SPRG0(r4)
397 ld r6, VCPU_SPRG1(r4)
398 ld r7, VCPU_SPRG2(r4)
399 ld r8, VCPU_SPRG3(r4)
405 /* Save R1 in the PACA */
406 std r1, HSTATE_HOST_R1(r13)
408 /* Load up DAR and DSISR */
410 lwz r6, VCPU_DSISR(r4)
415 /* Restore AMR and UAMOR, set AMOR to all 1s */
422 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
432 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
434 * POWER7 host -> guest partition switch code.
435 * We don't have to lock against concurrent tlbies,
436 * but we do have to coordinate across hardware threads.
438 /* Increment entry count iff exit count is zero. */
439 ld r5,HSTATE_KVM_VCORE(r13)
440 addi r9,r5,VCORE_ENTRY_EXIT
442 cmpwi r3,0x100 /* any threads starting to exit? */
443 bge secondary_too_late /* if so we're too late to the party */
448 /* Primary thread switches to guest partition. */
449 ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
455 li r0,LPID_RSVD /* switch to reserved LPID */
458 mtspr SPRN_SDR1,r6 /* switch to partition page table */
462 /* See if we need to flush the TLB */
463 lhz r6,PACAPACAINDEX(r13) /* test_bit(cpu, need_tlb_flush) */
464 clrldi r7,r6,64-6 /* extract bit number (6 bits) */
465 srdi r6,r6,6 /* doubleword number */
466 sldi r6,r6,3 /* address offset */
468 addi r6,r6,KVM_NEED_FLUSH /* dword in kvm->arch.need_tlb_flush */
474 23: ldarx r7,0,r6 /* if set, clear the bit */
478 li r6,128 /* and flush the TLB */
480 li r7,0x800 /* IS field = 0b10 */
487 /* Add timebase offset onto timebase */
488 22: ld r8,VCORE_TB_OFFSET(r5)
491 mftb r6 /* current host timebase */
493 mtspr SPRN_TBU40,r8 /* update upper 40 bits */
494 mftb r7 /* check if lower 24 bits overflowed */
499 addis r8,r8,0x100 /* if so, increment upper 40 bits */
502 /* Load guest PCR value to select appropriate compat mode */
503 37: ld r7, VCORE_PCR(r5)
509 stb r0,VCORE_IN_GUEST(r5) /* signal secondaries to continue */
512 /* Secondary threads wait for primary to have done partition switch */
513 20: lbz r0,VCORE_IN_GUEST(r5)
517 /* Set LPCR and RMOR. */
518 10: ld r8,VCORE_LPCR(r5)
524 /* Increment yield count if they have a VPA */
528 lwz r5, LPPACA_YIELDCOUNT(r3)
530 stw r5, LPPACA_YIELDCOUNT(r3)
532 stb r6, VCPU_VPA_DIRTY(r4)
534 /* Check if HDEC expires soon */
537 li r12,BOOK3S_INTERRUPT_HV_DECREMENTER
541 /* Save purr/spurr */
544 std r5,HSTATE_PURR(r13)
545 std r6,HSTATE_SPURR(r13)
553 * PPC970 host -> guest partition switch code.
554 * We have to lock against concurrent tlbies,
555 * using native_tlbie_lock to lock against host tlbies
556 * and kvm->arch.tlbie_lock to lock against guest tlbies.
557 * We also have to invalidate the TLB since its
558 * entries aren't tagged with the LPID.
560 30: ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
562 /* first take native_tlbie_lock */
565 .tc native_tlbie_lock[TC],native_tlbie_lock
567 ld r3,toc_tlbie_lock@toc(2)
568 #ifdef __BIG_ENDIAN__
569 lwz r8,PACA_LOCK_TOKEN(r13)
571 lwz r8,PACAPACAINDEX(r13)
580 ld r5,HSTATE_KVM_VCORE(r13)
581 ld r7,VCORE_LPCR(r5) /* use vcore->lpcr to store HID4 */
583 rotldi r0,r0,HID4_LPID5_SH /* all lpid bits in HID4 = 1 */
587 mtspr SPRN_HID4,r0 /* switch to reserved LPID */
590 stw r0,0(r3) /* drop native_tlbie_lock */
592 /* invalidate the whole TLB */
601 /* Take the guest's tlbie_lock */
602 addi r3,r9,KVM_TLBIE_LOCK
610 mtspr SPRN_SDR1,r6 /* switch to partition page table */
612 /* Set up HID4 with the guest's LPID etc. */
617 /* drop the guest's tlbie_lock */
621 /* Check if HDEC expires soon */
624 li r12,BOOK3S_INTERRUPT_HV_DECREMENTER
628 /* Enable HDEC interrupts */
631 rldimi r0,r3, HID0_HDICE_SH, 64-HID0_HDICE_SH-1
641 /* Load up guest SLB entries */
642 31: lwz r5,VCPU_SLB_MAX(r4)
647 1: ld r8,VCPU_SLB_E(r6)
650 addi r6,r6,VCPU_SLB_SIZE
654 /* Restore state of CTRL run bit; assume 1 on entry */
670 kvmppc_cede_reentry: /* r4 = vcpu, r13 = paca */
674 /* r11 = vcpu->arch.msr & ~MSR_HV */
675 rldicl r11, r11, 63 - MSR_HV_LG, 1
676 rotldi r11, r11, 1 + MSR_HV_LG
679 /* Check if we can deliver an external or decrementer interrupt now */
680 ld r0,VCPU_PENDING_EXC(r4)
681 lis r8,(1 << BOOK3S_IRQPRIO_EXTERNAL_LEVEL)@h
691 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
693 li r0,BOOK3S_INTERRUPT_EXTERNAL
697 li r11,(MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
703 li r0,BOOK3S_INTERRUPT_DECREMENTER
706 /* Move SRR0 and SRR1 into the respective regs */
707 5: mtspr SPRN_SRR0, r6
712 stb r0,VCPU_CEDED(r4) /* cancel cede */
716 /* Activate guest mode, so faults get handled by KVM */
717 li r9, KVM_GUEST_MODE_GUEST
718 stb r9, HSTATE_IN_GUEST(r13)
725 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
728 END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
735 ld r1, VCPU_GPR(R1)(r4)
736 ld r2, VCPU_GPR(R2)(r4)
737 ld r3, VCPU_GPR(R3)(r4)
738 ld r5, VCPU_GPR(R5)(r4)
739 ld r6, VCPU_GPR(R6)(r4)
740 ld r7, VCPU_GPR(R7)(r4)
741 ld r8, VCPU_GPR(R8)(r4)
742 ld r9, VCPU_GPR(R9)(r4)
743 ld r10, VCPU_GPR(R10)(r4)
744 ld r11, VCPU_GPR(R11)(r4)
745 ld r12, VCPU_GPR(R12)(r4)
746 ld r13, VCPU_GPR(R13)(r4)
750 END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
751 ld r0, VCPU_GPR(R0)(r4)
752 ld r4, VCPU_GPR(R4)(r4)
757 /******************************************************************************
761 *****************************************************************************/
764 * We come here from the first-level interrupt handlers.
766 .globl kvmppc_interrupt
770 * R12 = interrupt vector
772 * guest CR, R12 saved in shadow VCPU SCRATCH1/0
773 * guest R13 saved in SPRN_SCRATCH0
775 /* abuse host_r2 as third scratch area; we get r2 from PACATOC(r13) */
776 std r9, HSTATE_HOST_R2(r13)
777 ld r9, HSTATE_KVM_VCPU(r13)
781 std r0, VCPU_GPR(R0)(r9)
782 std r1, VCPU_GPR(R1)(r9)
783 std r2, VCPU_GPR(R2)(r9)
784 std r3, VCPU_GPR(R3)(r9)
785 std r4, VCPU_GPR(R4)(r9)
786 std r5, VCPU_GPR(R5)(r9)
787 std r6, VCPU_GPR(R6)(r9)
788 std r7, VCPU_GPR(R7)(r9)
789 std r8, VCPU_GPR(R8)(r9)
790 ld r0, HSTATE_HOST_R2(r13)
791 std r0, VCPU_GPR(R9)(r9)
792 std r10, VCPU_GPR(R10)(r9)
793 std r11, VCPU_GPR(R11)(r9)
794 ld r3, HSTATE_SCRATCH0(r13)
795 lwz r4, HSTATE_SCRATCH1(r13)
796 std r3, VCPU_GPR(R12)(r9)
799 ld r3, HSTATE_CFAR(r13)
800 std r3, VCPU_CFAR(r9)
801 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
803 ld r4, HSTATE_PPR(r13)
805 END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
807 /* Restore R1/R2 so we can handle faults */
808 ld r1, HSTATE_HOST_R1(r13)
813 std r10, VCPU_SRR0(r9)
814 std r11, VCPU_SRR1(r9)
815 andi. r0, r12, 2 /* need to read HSRR0/1? */
817 mfspr r10, SPRN_HSRR0
818 mfspr r11, SPRN_HSRR1
820 1: std r10, VCPU_PC(r9)
821 std r11, VCPU_MSR(r9)
825 std r3, VCPU_GPR(R13)(r9)
828 /* Unset guest mode */
829 li r0, KVM_GUEST_MODE_NONE
830 stb r0, HSTATE_IN_GUEST(r13)
832 stw r12,VCPU_TRAP(r9)
834 /* Save HEIR (HV emulation assist reg) in last_inst
835 if this is an HEI (HV emulation interrupt, e40) */
836 li r3,KVM_INST_FETCH_FAILED
838 cmpwi r12,BOOK3S_INTERRUPT_H_EMUL_ASSIST
841 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
842 11: stw r3,VCPU_LAST_INST(r9)
844 /* these are volatile across C function calls */
851 /* If this is a page table miss then see if it's theirs or ours */
852 cmpwi r12, BOOK3S_INTERRUPT_H_DATA_STORAGE
854 cmpwi r12, BOOK3S_INTERRUPT_H_INST_STORAGE
856 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
858 /* See if this is a leftover HDEC interrupt */
859 cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER
865 /* See if this is an hcall we can handle in real mode */
866 cmpwi r12,BOOK3S_INTERRUPT_SYSCALL
867 beq hcall_try_real_mode
869 /* Only handle external interrupts here on arch 206 and later */
871 b ext_interrupt_to_host
872 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206)
874 /* External interrupt ? */
875 cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL
876 bne+ ext_interrupt_to_host
878 /* External interrupt, first check for host_ipi. If this is
879 * set, we know the host wants us out so let's do it now
884 bgt ext_interrupt_to_host
886 /* Allright, looks like an IPI for the guest, we need to set MER */
887 /* Check if any CPU is heading out to the host, if so head out too */
888 ld r5, HSTATE_KVM_VCORE(r13)
889 lwz r0, VCORE_ENTRY_EXIT(r5)
891 bge ext_interrupt_to_host
893 /* See if there is a pending interrupt for the guest */
895 ld r0, VCPU_PENDING_EXC(r9)
896 /* Insert EXTERNAL_LEVEL bit into LPCR at the MER bit position */
897 rldicl. r0, r0, 64 - BOOK3S_IRQPRIO_EXTERNAL_LEVEL, 63
898 rldimi r8, r0, LPCR_MER_SH, 63 - LPCR_MER_SH
901 /* And if the guest EE is set, we can deliver immediately, else
902 * we return to the guest with MER set
904 andi. r0, r11, MSR_EE
908 li r10, BOOK3S_INTERRUPT_EXTERNAL
909 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
915 ext_interrupt_to_host:
917 guest_exit_cont: /* r9 = vcpu, r12 = trap, r13 = paca */
918 /* Save more register state */
922 stw r7, VCPU_DSISR(r9)
924 /* don't overwrite fault_dar/fault_dsisr if HDSI */
925 cmpwi r12,BOOK3S_INTERRUPT_H_DATA_STORAGE
927 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
928 std r6, VCPU_FAULT_DAR(r9)
929 stw r7, VCPU_FAULT_DSISR(r9)
931 /* See if it is a machine check */
932 cmpwi r12, BOOK3S_INTERRUPT_MACHINE_CHECK
933 beq machine_check_realmode
936 /* Save guest CTRL register, set runlatch to 1 */
937 6: mfspr r6,SPRN_CTRLF
944 /* Read the guest SLB and save it away */
945 lwz r0,VCPU_SLB_NR(r9) /* number of entries in SLB */
951 andis. r0,r8,SLB_ESID_V@h
953 add r8,r8,r6 /* put index in */
955 std r8,VCPU_SLB_E(r7)
956 std r3,VCPU_SLB_V(r7)
957 addi r7,r7,VCPU_SLB_SIZE
961 stw r5,VCPU_SLB_MAX(r9)
964 * Save the guest PURR/SPURR
972 std r6,VCPU_SPURR(r9)
977 * Restore host PURR/SPURR and add guest times
978 * so that the time in the guest gets accounted.
980 ld r3,HSTATE_PURR(r13)
981 ld r4,HSTATE_SPURR(r13)
986 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_201)
994 hdec_soon: /* r9 = vcpu, r12 = trap, r13 = paca */
997 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
999 * POWER7 guest -> host partition switch code.
1000 * We don't have to lock against tlbies but we do
1001 * have to coordinate the hardware threads.
1003 /* Increment the threads-exiting-guest count in the 0xff00
1004 bits of vcore->entry_exit_count */
1006 ld r5,HSTATE_KVM_VCORE(r13)
1007 addi r6,r5,VCORE_ENTRY_EXIT
1015 * At this point we have an interrupt that we have to pass
1016 * up to the kernel or qemu; we can't handle it in real mode.
1017 * Thus we have to do a partition switch, so we have to
1018 * collect the other threads, if we are the first thread
1019 * to take an interrupt. To do this, we set the HDEC to 0,
1020 * which causes an HDEC interrupt in all threads within 2ns
1021 * because the HDEC register is shared between all 4 threads.
1022 * However, we don't need to bother if this is an HDEC
1023 * interrupt, since the other threads will already be on their
1024 * way here in that case.
1026 cmpwi r3,0x100 /* Are we the first here? */
1028 cmpwi r3,1 /* Are any other threads in the guest? */
1030 cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER
1036 * Send an IPI to any napping threads, since an HDEC interrupt
1037 * doesn't wake CPUs up from nap.
1039 lwz r3,VCORE_NAPPING_THREADS(r5)
1040 lwz r4,VCPU_PTID(r9)
1043 andc. r3,r3,r0 /* no sense IPI'ing ourselves */
1045 mulli r4,r4,PACA_SIZE /* get paca for thread 0 */
1049 ld r8,HSTATE_XICS_PHYS(r6) /* get thread's XICS reg addr */
1052 stbcix r0,r7,r8 /* trigger the IPI */
1054 addi r6,r6,PACA_SIZE
1057 /* Secondary threads wait for primary to do partition switch */
1058 43: ld r4,VCPU_KVM(r9) /* pointer to struct kvm */
1059 ld r5,HSTATE_KVM_VCORE(r13)
1060 lwz r3,VCPU_PTID(r9)
1064 13: lbz r3,VCORE_IN_GUEST(r5)
1070 /* Primary thread waits for all the secondaries to exit guest */
1071 15: lwz r3,VCORE_ENTRY_EXIT(r5)
1078 /* Primary thread switches back to host partition */
1079 ld r6,KVM_HOST_SDR1(r4)
1080 lwz r7,KVM_HOST_LPID(r4)
1081 li r8,LPID_RSVD /* switch to reserved LPID */
1084 mtspr SPRN_SDR1,r6 /* switch to partition page table */
1088 /* Subtract timebase offset from timebase */
1089 ld r8,VCORE_TB_OFFSET(r5)
1092 mftb r6 /* current host timebase */
1094 mtspr SPRN_TBU40,r8 /* update upper 40 bits */
1095 mftb r7 /* check if lower 24 bits overflowed */
1100 addis r8,r8,0x100 /* if so, increment upper 40 bits */
1104 17: ld r0, VCORE_PCR(r5)
1110 /* Signal secondary CPUs to continue */
1111 stb r0,VCORE_IN_GUEST(r5)
1112 lis r8,0x7fff /* MAX_INT@h */
1115 16: ld r8,KVM_HOST_LPCR(r4)
1121 * PPC970 guest -> host partition switch code.
1122 * We have to lock against concurrent tlbies, and
1123 * we have to flush the whole TLB.
1125 32: ld r4,VCPU_KVM(r9) /* pointer to struct kvm */
1127 /* Take the guest's tlbie_lock */
1128 #ifdef __BIG_ENDIAN__
1129 lwz r8,PACA_LOCK_TOKEN(r13)
1131 lwz r8,PACAPACAINDEX(r13)
1133 addi r3,r4,KVM_TLBIE_LOCK
1141 ld r7,KVM_HOST_LPCR(r4) /* use kvm->arch.host_lpcr for HID4 */
1143 rotldi r0,r0,HID4_LPID5_SH /* all lpid bits in HID4 = 1 */
1147 mtspr SPRN_HID4,r0 /* switch to reserved LPID */
1150 stw r0,0(r3) /* drop guest tlbie_lock */
1152 /* invalidate the whole TLB */
1161 /* take native_tlbie_lock */
1162 ld r3,toc_tlbie_lock@toc(2)
1170 ld r6,KVM_HOST_SDR1(r4)
1171 mtspr SPRN_SDR1,r6 /* switch to host page table */
1173 /* Set up host HID4 value */
1178 stw r0,0(r3) /* drop native_tlbie_lock */
1180 lis r8,0x7fff /* MAX_INT@h */
1183 /* Disable HDEC interrupts */
1186 rldimi r0,r3, HID0_HDICE_SH, 64-HID0_HDICE_SH-1
1196 /* load host SLB entries */
1197 33: ld r8,PACA_SLBSHADOWPTR(r13)
1199 .rept SLB_NUM_BOLTED
1200 ld r5,SLBSHADOW_SAVEAREA(r8)
1201 ld r6,SLBSHADOW_SAVEAREA+8(r8)
1202 andis. r7,r5,SLB_ESID_V@h
1213 std r5,VCPU_DEC_EXPIRES(r9)
1215 /* Save and reset AMR and UAMOR before turning on the MMU */
1220 std r6,VCPU_UAMOR(r9)
1223 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
1225 /* Switch DSCR back to host value */
1228 ld r7, HSTATE_DSCR(r13)
1229 std r8, VCPU_DSCR(r7)
1231 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
1233 /* Save non-volatile GPRs */
1234 std r14, VCPU_GPR(R14)(r9)
1235 std r15, VCPU_GPR(R15)(r9)
1236 std r16, VCPU_GPR(R16)(r9)
1237 std r17, VCPU_GPR(R17)(r9)
1238 std r18, VCPU_GPR(R18)(r9)
1239 std r19, VCPU_GPR(R19)(r9)
1240 std r20, VCPU_GPR(R20)(r9)
1241 std r21, VCPU_GPR(R21)(r9)
1242 std r22, VCPU_GPR(R22)(r9)
1243 std r23, VCPU_GPR(R23)(r9)
1244 std r24, VCPU_GPR(R24)(r9)
1245 std r25, VCPU_GPR(R25)(r9)
1246 std r26, VCPU_GPR(R26)(r9)
1247 std r27, VCPU_GPR(R27)(r9)
1248 std r28, VCPU_GPR(R28)(r9)
1249 std r29, VCPU_GPR(R29)(r9)
1250 std r30, VCPU_GPR(R30)(r9)
1251 std r31, VCPU_GPR(R31)(r9)
1254 mfspr r3, SPRN_SPRG0
1255 mfspr r4, SPRN_SPRG1
1256 mfspr r5, SPRN_SPRG2
1257 mfspr r6, SPRN_SPRG3
1258 std r3, VCPU_SPRG0(r9)
1259 std r4, VCPU_SPRG1(r9)
1260 std r5, VCPU_SPRG2(r9)
1261 std r6, VCPU_SPRG3(r9)
1267 /* Increment yield count if they have a VPA */
1268 ld r8, VCPU_VPA(r9) /* do they have a VPA? */
1271 lwz r3, LPPACA_YIELDCOUNT(r8)
1273 stw r3, LPPACA_YIELDCOUNT(r8)
1275 stb r3, VCPU_VPA_DIRTY(r9)
1277 /* Save PMU registers if requested */
1278 /* r8 and cr0.eq are live here */
1280 sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
1281 mfspr r4, SPRN_MMCR0 /* save MMCR0 */
1282 mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */
1283 mfspr r6, SPRN_MMCRA
1285 /* On P7, clear MMCRA in order to disable SDAR updates */
1287 mtspr SPRN_MMCRA, r7
1288 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
1290 beq 21f /* if no VPA, save PMU stuff anyway */
1291 lbz r7, LPPACA_PMCINUSE(r8)
1292 cmpwi r7, 0 /* did they ask for PMU stuff to be saved? */
1294 std r3, VCPU_MMCR(r9) /* if not, set saved MMCR0 to FC */
1296 21: mfspr r5, SPRN_MMCR1
1299 std r4, VCPU_MMCR(r9)
1300 std r5, VCPU_MMCR + 8(r9)
1301 std r6, VCPU_MMCR + 16(r9)
1302 std r7, VCPU_SIAR(r9)
1303 std r8, VCPU_SDAR(r9)
1311 mfspr r10, SPRN_PMC7
1312 mfspr r11, SPRN_PMC8
1313 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
1314 stw r3, VCPU_PMC(r9)
1315 stw r4, VCPU_PMC + 4(r9)
1316 stw r5, VCPU_PMC + 8(r9)
1317 stw r6, VCPU_PMC + 12(r9)
1318 stw r7, VCPU_PMC + 16(r9)
1319 stw r8, VCPU_PMC + 20(r9)
1321 stw r10, VCPU_PMC + 24(r9)
1322 stw r11, VCPU_PMC + 28(r9)
1323 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
1325 ld r0, 112+PPC_LR_STKOFF(r1)
1330 ld r5,HSTATE_KVM_VCORE(r13)
1332 13: lbz r3,VCORE_IN_GUEST(r5)
1336 li r0, KVM_GUEST_MODE_NONE
1337 stb r0, HSTATE_IN_GUEST(r13)
1338 ld r11,PACA_SLBSHADOWPTR(r13)
1340 .rept SLB_NUM_BOLTED
1341 ld r5,SLBSHADOW_SAVEAREA(r11)
1342 ld r6,SLBSHADOW_SAVEAREA+8(r11)
1343 andis. r7,r5,SLB_ESID_V@h
1351 * Check whether an HDSI is an HPTE not found fault or something else.
1352 * If it is an HPTE not found fault that is due to the guest accessing
1353 * a page that they have mapped but which we have paged out, then
1354 * we continue on with the guest exit path. In all other cases,
1355 * reflect the HDSI to the guest as a DSI.
1359 mfspr r6, SPRN_HDSISR
1360 /* HPTE not found fault or protection fault? */
1361 andis. r0, r6, (DSISR_NOHPTE | DSISR_PROTFAULT)@h
1362 beq 1f /* if not, send it to the guest */
1363 andi. r0, r11, MSR_DR /* data relocation enabled? */
1366 PPC_SLBFEE_DOT(R5, R0) /* if so, look up SLB */
1367 bne 1f /* if no SLB entry found */
1368 4: std r4, VCPU_FAULT_DAR(r9)
1369 stw r6, VCPU_FAULT_DSISR(r9)
1371 /* Search the hash table. */
1372 mr r3, r9 /* vcpu pointer */
1373 li r7, 1 /* data fault */
1374 bl .kvmppc_hpte_hv_fault
1375 ld r9, HSTATE_KVM_VCPU(r13)
1377 ld r11, VCPU_MSR(r9)
1378 li r12, BOOK3S_INTERRUPT_H_DATA_STORAGE
1379 cmpdi r3, 0 /* retry the instruction */
1381 cmpdi r3, -1 /* handle in kernel mode */
1383 cmpdi r3, -2 /* MMIO emulation; need instr word */
1386 /* Synthesize a DSI for the guest */
1387 ld r4, VCPU_FAULT_DAR(r9)
1389 1: mtspr SPRN_DAR, r4
1390 mtspr SPRN_DSISR, r6
1391 mtspr SPRN_SRR0, r10
1392 mtspr SPRN_SRR1, r11
1393 li r10, BOOK3S_INTERRUPT_DATA_STORAGE
1394 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
1396 fast_interrupt_c_return:
1397 6: ld r7, VCPU_CTR(r9)
1398 lwz r8, VCPU_XER(r9)
1404 3: ld r5, VCPU_KVM(r9) /* not relocated, use VRMA */
1405 ld r5, KVM_VRMA_SLB_V(r5)
1408 /* If this is for emulated MMIO, load the instruction word */
1409 2: li r8, KVM_INST_FETCH_FAILED /* In case lwz faults */
1411 /* Set guest mode to 'jump over instruction' so if lwz faults
1412 * we'll just continue at the next IP. */
1413 li r0, KVM_GUEST_MODE_SKIP
1414 stb r0, HSTATE_IN_GUEST(r13)
1416 /* Do the access with MSR:DR enabled */
1418 ori r4, r3, MSR_DR /* Enable paging for data */
1423 /* Store the result */
1424 stw r8, VCPU_LAST_INST(r9)
1426 /* Unset guest mode. */
1427 li r0, KVM_GUEST_MODE_NONE
1428 stb r0, HSTATE_IN_GUEST(r13)
1432 * Similarly for an HISI, reflect it to the guest as an ISI unless
1433 * it is an HPTE not found fault for a page that we have paged out.
1436 andis. r0, r11, SRR1_ISI_NOPT@h
1438 andi. r0, r11, MSR_IR /* instruction relocation enabled? */
1441 PPC_SLBFEE_DOT(R5, R0) /* if so, look up SLB */
1442 bne 1f /* if no SLB entry found */
1444 /* Search the hash table. */
1445 mr r3, r9 /* vcpu pointer */
1448 li r7, 0 /* instruction fault */
1449 bl .kvmppc_hpte_hv_fault
1450 ld r9, HSTATE_KVM_VCPU(r13)
1452 ld r11, VCPU_MSR(r9)
1453 li r12, BOOK3S_INTERRUPT_H_INST_STORAGE
1454 cmpdi r3, 0 /* retry the instruction */
1455 beq fast_interrupt_c_return
1456 cmpdi r3, -1 /* handle in kernel mode */
1459 /* Synthesize an ISI for the guest */
1461 1: mtspr SPRN_SRR0, r10
1462 mtspr SPRN_SRR1, r11
1463 li r10, BOOK3S_INTERRUPT_INST_STORAGE
1464 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
1466 b fast_interrupt_c_return
1468 3: ld r6, VCPU_KVM(r9) /* not relocated, use VRMA */
1469 ld r5, KVM_VRMA_SLB_V(r6)
1473 * Try to handle an hcall in real mode.
1474 * Returns to the guest if we handle it, or continues on up to
1475 * the kernel if we can't (i.e. if we don't have a handler for
1476 * it, or if the handler returns H_TOO_HARD).
1478 .globl hcall_try_real_mode
1479 hcall_try_real_mode:
1480 ld r3,VCPU_GPR(R3)(r9)
1484 cmpldi r3,hcall_real_table_end - hcall_real_table
1486 LOAD_REG_ADDR(r4, hcall_real_table)
1492 mr r3,r9 /* get vcpu pointer */
1493 ld r4,VCPU_GPR(R4)(r9)
1496 beq hcall_real_fallback
1497 ld r4,HSTATE_KVM_VCPU(r13)
1498 std r3,VCPU_GPR(R3)(r4)
1503 /* We've attempted a real mode hcall, but it's punted it back
1504 * to userspace. We need to restore some clobbered volatiles
1505 * before resuming the pass-it-to-qemu path */
1506 hcall_real_fallback:
1507 li r12,BOOK3S_INTERRUPT_SYSCALL
1508 ld r9, HSTATE_KVM_VCPU(r13)
1512 .globl hcall_real_table
1514 .long 0 /* 0 - unused */
1515 .long .kvmppc_h_remove - hcall_real_table
1516 .long .kvmppc_h_enter - hcall_real_table
1517 .long .kvmppc_h_read - hcall_real_table
1518 .long 0 /* 0x10 - H_CLEAR_MOD */
1519 .long 0 /* 0x14 - H_CLEAR_REF */
1520 .long .kvmppc_h_protect - hcall_real_table
1521 .long 0 /* 0x1c - H_GET_TCE */
1522 .long .kvmppc_h_put_tce - hcall_real_table
1523 .long 0 /* 0x24 - H_SET_SPRG0 */
1524 .long .kvmppc_h_set_dabr - hcall_real_table
1539 #ifdef CONFIG_KVM_XICS
1540 .long .kvmppc_rm_h_eoi - hcall_real_table
1541 .long .kvmppc_rm_h_cppr - hcall_real_table
1542 .long .kvmppc_rm_h_ipi - hcall_real_table
1543 .long 0 /* 0x70 - H_IPOLL */
1544 .long .kvmppc_rm_h_xirr - hcall_real_table
1546 .long 0 /* 0x64 - H_EOI */
1547 .long 0 /* 0x68 - H_CPPR */
1548 .long 0 /* 0x6c - H_IPI */
1549 .long 0 /* 0x70 - H_IPOLL */
1550 .long 0 /* 0x74 - H_XIRR */
1578 .long .kvmppc_h_cede - hcall_real_table
1595 .long .kvmppc_h_bulk_remove - hcall_real_table
1596 hcall_real_table_end:
1602 _GLOBAL(kvmppc_h_set_dabr)
1603 std r4,VCPU_DABR(r3)
1604 /* Work around P7 bug where DABR can get corrupted on mtspr */
1605 1: mtspr SPRN_DABR,r4
1613 _GLOBAL(kvmppc_h_cede)
1615 std r11,VCPU_MSR(r3)
1617 stb r0,VCPU_CEDED(r3)
1618 sync /* order setting ceded vs. testing prodded */
1619 lbz r5,VCPU_PRODDED(r3)
1621 bne kvm_cede_prodded
1622 li r0,0 /* set trap to 0 to say hcall is handled */
1623 stw r0,VCPU_TRAP(r3)
1625 std r0,VCPU_GPR(R3)(r3)
1627 b kvm_cede_exit /* just send it up to host on 970 */
1628 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206)
1631 * Set our bit in the bitmask of napping threads unless all the
1632 * other threads are already napping, in which case we send this
1635 ld r5,HSTATE_KVM_VCORE(r13)
1636 lwz r6,VCPU_PTID(r3)
1637 lwz r8,VCORE_ENTRY_EXIT(r5)
1641 addi r6,r5,VCORE_NAPPING_THREADS
1650 stb r0,HSTATE_NAPPING(r13)
1651 /* order napping_threads update vs testing entry_exit_count */
1654 lwz r7,VCORE_ENTRY_EXIT(r5)
1656 bge 33f /* another thread already exiting */
1659 * Although not specifically required by the architecture, POWER7
1660 * preserves the following registers in nap mode, even if an SMT mode
1661 * switch occurs: SLB entries, PURR, SPURR, AMOR, UAMOR, AMR, SPRG0-3,
1662 * DAR, DSISR, DABR, DABRX, DSCR, PMCx, MMCRx, SIAR, SDAR.
1664 /* Save non-volatile GPRs */
1665 std r14, VCPU_GPR(R14)(r3)
1666 std r15, VCPU_GPR(R15)(r3)
1667 std r16, VCPU_GPR(R16)(r3)
1668 std r17, VCPU_GPR(R17)(r3)
1669 std r18, VCPU_GPR(R18)(r3)
1670 std r19, VCPU_GPR(R19)(r3)
1671 std r20, VCPU_GPR(R20)(r3)
1672 std r21, VCPU_GPR(R21)(r3)
1673 std r22, VCPU_GPR(R22)(r3)
1674 std r23, VCPU_GPR(R23)(r3)
1675 std r24, VCPU_GPR(R24)(r3)
1676 std r25, VCPU_GPR(R25)(r3)
1677 std r26, VCPU_GPR(R26)(r3)
1678 std r27, VCPU_GPR(R27)(r3)
1679 std r28, VCPU_GPR(R28)(r3)
1680 std r29, VCPU_GPR(R29)(r3)
1681 std r30, VCPU_GPR(R30)(r3)
1682 std r31, VCPU_GPR(R31)(r3)
1688 * Take a nap until a decrementer or external interrupt occurs,
1689 * with PECE1 (wake on decr) and PECE0 (wake on external) set in LPCR
1692 stb r0,HSTATE_HWTHREAD_REQ(r13)
1694 ori r5,r5,LPCR_PECE0 | LPCR_PECE1
1698 std r0, HSTATE_SCRATCH0(r13)
1700 ld r0, HSTATE_SCRATCH0(r13)
1707 /* get vcpu pointer */
1708 ld r4, HSTATE_KVM_VCPU(r13)
1710 /* Woken by external or decrementer interrupt */
1711 ld r1, HSTATE_HOST_R1(r13)
1713 /* load up FP state */
1717 ld r14, VCPU_GPR(R14)(r4)
1718 ld r15, VCPU_GPR(R15)(r4)
1719 ld r16, VCPU_GPR(R16)(r4)
1720 ld r17, VCPU_GPR(R17)(r4)
1721 ld r18, VCPU_GPR(R18)(r4)
1722 ld r19, VCPU_GPR(R19)(r4)
1723 ld r20, VCPU_GPR(R20)(r4)
1724 ld r21, VCPU_GPR(R21)(r4)
1725 ld r22, VCPU_GPR(R22)(r4)
1726 ld r23, VCPU_GPR(R23)(r4)
1727 ld r24, VCPU_GPR(R24)(r4)
1728 ld r25, VCPU_GPR(R25)(r4)
1729 ld r26, VCPU_GPR(R26)(r4)
1730 ld r27, VCPU_GPR(R27)(r4)
1731 ld r28, VCPU_GPR(R28)(r4)
1732 ld r29, VCPU_GPR(R29)(r4)
1733 ld r30, VCPU_GPR(R30)(r4)
1734 ld r31, VCPU_GPR(R31)(r4)
1736 /* clear our bit in vcore->napping_threads */
1737 33: ld r5,HSTATE_KVM_VCORE(r13)
1738 lwz r3,VCPU_PTID(r4)
1741 addi r6,r5,VCORE_NAPPING_THREADS
1747 stb r0,HSTATE_NAPPING(r13)
1749 /* Check the wake reason in SRR1 to see why we got here */
1751 rlwinm r3, r3, 44-31, 0x7 /* extract wake reason field */
1752 cmpwi r3, 4 /* was it an external interrupt? */
1753 li r12, BOOK3S_INTERRUPT_EXTERNAL
1756 ld r11, VCPU_MSR(r9)
1757 beq do_ext_interrupt /* if so */
1759 /* see if any other thread is already exiting */
1760 lwz r0,VCORE_ENTRY_EXIT(r5)
1762 blt kvmppc_cede_reentry /* if not go back to guest */
1764 /* some threads are exiting, so go to the guest exit path */
1765 b hcall_real_fallback
1767 /* cede when already previously prodded case */
1770 stb r0,VCPU_PRODDED(r3)
1771 sync /* order testing prodded vs. clearing ceded */
1772 stb r0,VCPU_CEDED(r3)
1776 /* we've ceded but we want to give control to the host */
1778 b hcall_real_fallback
1780 /* Try to handle a machine check in real mode */
1781 machine_check_realmode:
1782 mr r3, r9 /* get vcpu pointer */
1783 bl .kvmppc_realmode_machine_check
1785 cmpdi r3, 0 /* continue exiting from guest? */
1786 ld r9, HSTATE_KVM_VCPU(r13)
1787 li r12, BOOK3S_INTERRUPT_MACHINE_CHECK
1789 /* If not, deliver a machine check. SRR0/1 are already set */
1790 li r10, BOOK3S_INTERRUPT_MACHINE_CHECK
1791 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
1793 b fast_interrupt_c_return
1796 * Determine what sort of external interrupt is pending (if any).
1798 * 0 if no interrupt is pending
1799 * 1 if an interrupt is pending that needs to be handled by the host
1800 * -1 if there was a guest wakeup IPI (which has now been cleared)
1803 /* see if a host IPI is pending */
1805 lbz r0, HSTATE_HOST_IPI(r13)
1809 /* Now read the interrupt from the ICP */
1810 ld r6, HSTATE_XICS_PHYS(r13)
1815 rlwinm. r3, r0, 0, 0xffffff
1817 beq 1f /* if nothing pending in the ICP */
1819 /* We found something in the ICP...
1821 * If it's not an IPI, stash it in the PACA and return to
1822 * the host, we don't (yet) handle directing real external
1823 * interrupts directly to the guest
1825 cmpwi r3, XICS_IPI /* if there is, is it an IPI? */
1829 /* It's an IPI, clear the MFRR and EOI it */
1832 stbcix r3, r6, r8 /* clear the IPI */
1833 stwcix r0, r6, r7 /* EOI it */
1836 /* We need to re-check host IPI now in case it got set in the
1837 * meantime. If it's clear, we bounce the interrupt to the
1840 lbz r0, HSTATE_HOST_IPI(r13)
1844 /* OK, it's an IPI for us */
1848 42: /* It's not an IPI and it's for the host, stash it in the PACA
1849 * before exit, it will be picked up by the host ICP driver
1851 stw r0, HSTATE_SAVED_XIRR(r13)
1854 43: /* We raced with the host, we need to resend that IPI, bummer */
1856 stbcix r0, r6, r8 /* set the IPI */
1861 * Save away FP, VMX and VSX registers.
1864 _GLOBAL(kvmppc_save_fp)
1867 #ifdef CONFIG_ALTIVEC
1869 oris r8,r8,MSR_VEC@h
1870 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1874 oris r8,r8,MSR_VSX@h
1875 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1883 li r6,reg*16+VCPU_VSRS
1891 stfd reg,reg*8+VCPU_FPRS(r3)
1895 ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX)
1898 stfd fr0,VCPU_FPSCR(r3)
1900 #ifdef CONFIG_ALTIVEC
1904 li r6,reg*16+VCPU_VRS
1911 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1913 mfspr r6,SPRN_VRSAVE
1914 stw r6,VCPU_VRSAVE(r3)
1920 * Load up FP, VMX and VSX registers
1923 .globl kvmppc_load_fp
1927 #ifdef CONFIG_ALTIVEC
1929 oris r8,r8,MSR_VEC@h
1930 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1934 oris r8,r8,MSR_VSX@h
1935 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1939 lfd fr0,VCPU_FPSCR(r4)
1945 li r7,reg*16+VCPU_VSRS
1953 lfd reg,reg*8+VCPU_FPRS(r4)
1957 ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX)
1960 #ifdef CONFIG_ALTIVEC
1967 li r7,reg*16+VCPU_VRS
1971 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1973 lwz r7,VCPU_VRSAVE(r4)
1974 mtspr SPRN_VRSAVE,r7