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>
24 #include <asm/asm-offsets.h>
25 #include <asm/exception-64s.h>
27 /*****************************************************************************
29 * Real Mode handlers that need to be in the linear mapping *
31 ****************************************************************************/
33 .globl kvmppc_skip_interrupt
34 kvmppc_skip_interrupt:
42 .globl kvmppc_skip_Hinterrupt
43 kvmppc_skip_Hinterrupt:
52 * Call kvmppc_handler_trampoline_enter in real mode.
53 * Must be called with interrupts hard-disabled.
57 * LR = return address to continue at after eventually re-enabling MMU
59 _GLOBAL(kvmppc_hv_entry_trampoline)
61 LOAD_REG_ADDR(r5, kvmppc_hv_entry)
66 mtmsrd r0,1 /* clear RI in MSR */
72 #define VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE))
74 /******************************************************************************
78 *****************************************************************************/
84 * We come in here when wakened from nap mode on a secondary hw thread.
85 * Relocation is off and most register values are lost.
86 * r13 points to the PACA.
88 .globl kvm_start_guest
90 ld r1,PACAEMERGSP(r13)
91 subi r1,r1,STACK_FRAME_OVERHEAD
93 /* get vcpu pointer */
94 ld r4, HSTATE_KVM_VCPU(r13)
96 /* We got here with an IPI; clear it */
97 ld r5, HSTATE_XICS_PHYS(r13)
101 lwzcix r8, r5, r7 /* ack the interrupt */
103 stbcix r0, r5, r6 /* clear it */
104 stwcix r8, r5, r7 /* EOI it */
106 .global kvmppc_hv_entry
115 * all other volatile GPRS = free
118 std r0, HSTATE_VMHANDLER(r13)
120 ld r14, VCPU_GPR(r14)(r4)
121 ld r15, VCPU_GPR(r15)(r4)
122 ld r16, VCPU_GPR(r16)(r4)
123 ld r17, VCPU_GPR(r17)(r4)
124 ld r18, VCPU_GPR(r18)(r4)
125 ld r19, VCPU_GPR(r19)(r4)
126 ld r20, VCPU_GPR(r20)(r4)
127 ld r21, VCPU_GPR(r21)(r4)
128 ld r22, VCPU_GPR(r22)(r4)
129 ld r23, VCPU_GPR(r23)(r4)
130 ld r24, VCPU_GPR(r24)(r4)
131 ld r25, VCPU_GPR(r25)(r4)
132 ld r26, VCPU_GPR(r26)(r4)
133 ld r27, VCPU_GPR(r27)(r4)
134 ld r28, VCPU_GPR(r28)(r4)
135 ld r29, VCPU_GPR(r29)(r4)
136 ld r30, VCPU_GPR(r30)(r4)
137 ld r31, VCPU_GPR(r31)(r4)
139 /* Load guest PMU registers */
140 /* R4 is live here (vcpu pointer) */
142 sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
143 mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */
145 lwz r3, VCPU_PMC(r4) /* always load up guest PMU registers */
146 lwz r5, VCPU_PMC + 4(r4) /* to prevent information leak */
147 lwz r6, VCPU_PMC + 8(r4)
148 lwz r7, VCPU_PMC + 12(r4)
149 lwz r8, VCPU_PMC + 16(r4)
150 lwz r9, VCPU_PMC + 20(r4)
152 lwz r10, VCPU_PMC + 24(r4)
153 lwz r11, VCPU_PMC + 28(r4)
154 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
164 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
166 ld r5, VCPU_MMCR + 8(r4)
167 ld r6, VCPU_MMCR + 16(r4)
173 /* Load up FP, VMX and VSX registers */
177 /* Switch DSCR to guest value */
180 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
183 * Set the decrementer to the guest decrementer.
185 ld r8,VCPU_DEC_EXPIRES(r4)
191 ld r5, VCPU_SPRG0(r4)
192 ld r6, VCPU_SPRG1(r4)
193 ld r7, VCPU_SPRG2(r4)
194 ld r8, VCPU_SPRG3(r4)
200 /* Save R1 in the PACA */
201 std r1, HSTATE_HOST_R1(r13)
203 /* Increment yield count if they have a VPA */
207 lwz r5, LPPACA_YIELDCOUNT(r3)
209 stw r5, LPPACA_YIELDCOUNT(r3)
211 /* Load up DAR and DSISR */
213 lwz r6, VCPU_DSISR(r4)
217 /* Set partition DABR */
224 /* Restore AMR and UAMOR, set AMOR to all 1s */
231 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
241 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
243 * POWER7 host -> guest partition switch code.
244 * We don't have to lock against concurrent tlbies,
245 * but we do have to coordinate across hardware threads.
247 /* Increment entry count iff exit count is zero. */
248 ld r5,HSTATE_KVM_VCORE(r13)
249 addi r9,r5,VCORE_ENTRY_EXIT
251 cmpwi r3,0x100 /* any threads starting to exit? */
252 bge secondary_too_late /* if so we're too late to the party */
257 /* Primary thread switches to guest partition. */
258 ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
264 li r0,LPID_RSVD /* switch to reserved LPID */
267 mtspr SPRN_SDR1,r6 /* switch to partition page table */
271 stb r0,VCORE_IN_GUEST(r5) /* signal secondaries to continue */
274 /* Secondary threads wait for primary to have done partition switch */
275 20: lbz r0,VCORE_IN_GUEST(r5)
279 /* Set LPCR. Set the MER bit if there is a pending external irq. */
280 10: ld r8,KVM_LPCR(r9)
281 ld r0,VCPU_PENDING_EXC(r4)
282 li r7,(1 << BOOK3S_IRQPRIO_EXTERNAL)
283 oris r7,r7,(1 << BOOK3S_IRQPRIO_EXTERNAL_LEVEL)@h
287 11: mtspr SPRN_LPCR,r8
292 /* Check if HDEC expires soon */
295 li r12,BOOK3S_INTERRUPT_HV_DECREMENTER
300 * Invalidate the TLB if we could possibly have stale TLB
301 * entries for this partition on this core due to the use
303 * XXX maybe only need this on primary thread?
305 ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
306 lwz r5,VCPU_VCPUID(r4)
307 lhz r6,PACAPACAINDEX(r13)
308 rldimi r6,r5,0,62 /* XXX map as if threads 1:1 p:v */
309 lhz r8,VCPU_LAST_CPU(r4)
310 sldi r7,r6,1 /* see if this is the same vcpu */
311 add r7,r7,r9 /* as last ran on this pcpu */
312 lhz r0,KVM_LAST_VCPU(r7)
313 cmpw r6,r8 /* on the same cpu core as last time? */
315 cmpw r0,r5 /* same vcpu as this core last ran? */
317 3: sth r6,VCPU_LAST_CPU(r4) /* if not, invalidate partition TLB */
318 sth r5,KVM_LAST_VCPU(r7)
321 li r7,0x800 /* IS field = 0b10 */
329 /* Save purr/spurr */
332 std r5,HSTATE_PURR(r13)
333 std r6,HSTATE_SPURR(r13)
341 * PPC970 host -> guest partition switch code.
342 * We have to lock against concurrent tlbies,
343 * using native_tlbie_lock to lock against host tlbies
344 * and kvm->arch.tlbie_lock to lock against guest tlbies.
345 * We also have to invalidate the TLB since its
346 * entries aren't tagged with the LPID.
348 30: ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
350 /* first take native_tlbie_lock */
353 .tc native_tlbie_lock[TC],native_tlbie_lock
355 ld r3,toc_tlbie_lock@toc(2)
356 lwz r8,PACA_LOCK_TOKEN(r13)
364 ld r7,KVM_LPCR(r9) /* use kvm->arch.lpcr to store HID4 */
366 rotldi r0,r0,HID4_LPID5_SH /* all lpid bits in HID4 = 1 */
370 mtspr SPRN_HID4,r0 /* switch to reserved LPID */
373 stw r0,0(r3) /* drop native_tlbie_lock */
375 /* invalidate the whole TLB */
384 /* Take the guest's tlbie_lock */
385 addi r3,r9,KVM_TLBIE_LOCK
393 mtspr SPRN_SDR1,r6 /* switch to partition page table */
395 /* Set up HID4 with the guest's LPID etc. */
400 /* drop the guest's tlbie_lock */
404 /* Check if HDEC expires soon */
407 li r12,BOOK3S_INTERRUPT_HV_DECREMENTER
411 /* Enable HDEC interrupts */
414 rldimi r0,r3, HID0_HDICE_SH, 64-HID0_HDICE_SH-1
424 /* Load up guest SLB entries */
425 31: lwz r5,VCPU_SLB_MAX(r4)
430 1: ld r8,VCPU_SLB_E(r6)
433 addi r6,r6,VCPU_SLB_SIZE
437 /* Restore state of CTRL run bit; assume 1 on entry */
451 /* Move SRR0 and SRR1 into the respective regs */
459 ld r11, VCPU_MSR(r4) /* r10 = vcpu->arch.msr & ~MSR_HV */
460 rldicl r11, r11, 63 - MSR_HV_LG, 1
461 rotldi r11, r11, 1 + MSR_HV_LG
468 /* Activate guest mode, so faults get handled by KVM */
469 li r9, KVM_GUEST_MODE_GUEST
470 stb r9, HSTATE_IN_GUEST(r13)
479 ld r0, VCPU_GPR(r0)(r4)
480 ld r1, VCPU_GPR(r1)(r4)
481 ld r2, VCPU_GPR(r2)(r4)
482 ld r3, VCPU_GPR(r3)(r4)
483 ld r5, VCPU_GPR(r5)(r4)
484 ld r6, VCPU_GPR(r6)(r4)
485 ld r7, VCPU_GPR(r7)(r4)
486 ld r8, VCPU_GPR(r8)(r4)
487 ld r9, VCPU_GPR(r9)(r4)
488 ld r10, VCPU_GPR(r10)(r4)
489 ld r11, VCPU_GPR(r11)(r4)
490 ld r12, VCPU_GPR(r12)(r4)
491 ld r13, VCPU_GPR(r13)(r4)
493 ld r4, VCPU_GPR(r4)(r4)
498 /******************************************************************************
502 *****************************************************************************/
505 * We come here from the first-level interrupt handlers.
507 .globl kvmppc_interrupt
511 * R12 = interrupt vector
513 * guest CR, R12 saved in shadow VCPU SCRATCH1/0
514 * guest R13 saved in SPRN_SCRATCH0
516 /* abuse host_r2 as third scratch area; we get r2 from PACATOC(r13) */
517 std r9, HSTATE_HOST_R2(r13)
518 ld r9, HSTATE_KVM_VCPU(r13)
522 std r0, VCPU_GPR(r0)(r9)
523 std r1, VCPU_GPR(r1)(r9)
524 std r2, VCPU_GPR(r2)(r9)
525 std r3, VCPU_GPR(r3)(r9)
526 std r4, VCPU_GPR(r4)(r9)
527 std r5, VCPU_GPR(r5)(r9)
528 std r6, VCPU_GPR(r6)(r9)
529 std r7, VCPU_GPR(r7)(r9)
530 std r8, VCPU_GPR(r8)(r9)
531 ld r0, HSTATE_HOST_R2(r13)
532 std r0, VCPU_GPR(r9)(r9)
533 std r10, VCPU_GPR(r10)(r9)
534 std r11, VCPU_GPR(r11)(r9)
535 ld r3, HSTATE_SCRATCH0(r13)
536 lwz r4, HSTATE_SCRATCH1(r13)
537 std r3, VCPU_GPR(r12)(r9)
540 /* Restore R1/R2 so we can handle faults */
541 ld r1, HSTATE_HOST_R1(r13)
546 std r10, VCPU_SRR0(r9)
547 std r11, VCPU_SRR1(r9)
548 andi. r0, r12, 2 /* need to read HSRR0/1? */
550 mfspr r10, SPRN_HSRR0
551 mfspr r11, SPRN_HSRR1
553 1: std r10, VCPU_PC(r9)
554 std r11, VCPU_MSR(r9)
558 std r3, VCPU_GPR(r13)(r9)
561 /* Unset guest mode */
562 li r0, KVM_GUEST_MODE_NONE
563 stb r0, HSTATE_IN_GUEST(r13)
565 stw r12,VCPU_TRAP(r9)
567 /* See if this is a leftover HDEC interrupt */
568 cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER
574 /* See if this is something we can handle in real mode */
575 cmpwi r12,BOOK3S_INTERRUPT_SYSCALL
576 beq hcall_try_real_mode
579 /* Check for mediated interrupts (could be done earlier really ...) */
581 cmpwi r12,BOOK3S_INTERRUPT_EXTERNAL
588 bne bounce_ext_interrupt
590 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
597 std r5,VCPU_DEC_EXPIRES(r9)
599 /* Save HEIR (HV emulation assist reg) in last_inst
600 if this is an HEI (HV emulation interrupt, e40) */
603 cmpwi r12,BOOK3S_INTERRUPT_H_EMUL_ASSIST
606 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
607 11: stw r3,VCPU_LAST_INST(r9)
609 /* Save more register state */
617 stw r7, VCPU_DSISR(r9)
619 /* grab HDAR & HDSISR if HV data storage interrupt (HDSI) */
621 cmpwi r12,BOOK3S_INTERRUPT_H_DATA_STORAGE
623 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
624 7: std r6, VCPU_FAULT_DAR(r9)
625 stw r7, VCPU_FAULT_DSISR(r9)
627 /* Save guest CTRL register, set runlatch to 1 */
635 /* Read the guest SLB and save it away */
636 lwz r0,VCPU_SLB_NR(r9) /* number of entries in SLB */
642 andis. r0,r8,SLB_ESID_V@h
644 add r8,r8,r6 /* put index in */
646 std r8,VCPU_SLB_E(r7)
647 std r3,VCPU_SLB_V(r7)
648 addi r7,r7,VCPU_SLB_SIZE
652 stw r5,VCPU_SLB_MAX(r9)
655 * Save the guest PURR/SPURR
663 std r6,VCPU_SPURR(r9)
668 * Restore host PURR/SPURR and add guest times
669 * so that the time in the guest gets accounted.
671 ld r3,HSTATE_PURR(r13)
672 ld r4,HSTATE_SPURR(r13)
677 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_201)
688 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
690 * POWER7 guest -> host partition switch code.
691 * We don't have to lock against tlbies but we do
692 * have to coordinate the hardware threads.
694 /* Increment the threads-exiting-guest count in the 0xff00
695 bits of vcore->entry_exit_count */
697 ld r5,HSTATE_KVM_VCORE(r13)
698 addi r6,r5,VCORE_ENTRY_EXIT
705 * At this point we have an interrupt that we have to pass
706 * up to the kernel or qemu; we can't handle it in real mode.
707 * Thus we have to do a partition switch, so we have to
708 * collect the other threads, if we are the first thread
709 * to take an interrupt. To do this, we set the HDEC to 0,
710 * which causes an HDEC interrupt in all threads within 2ns
711 * because the HDEC register is shared between all 4 threads.
712 * However, we don't need to bother if this is an HDEC
713 * interrupt, since the other threads will already be on their
714 * way here in that case.
716 cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER
718 cmpwi r3,0x100 /* Are we the first here? */
726 /* Secondary threads wait for primary to do partition switch */
727 ld r4,VCPU_KVM(r9) /* pointer to struct kvm */
728 ld r5,HSTATE_KVM_VCORE(r13)
733 13: lbz r3,VCORE_IN_GUEST(r5)
739 /* Primary thread waits for all the secondaries to exit guest */
740 15: lwz r3,VCORE_ENTRY_EXIT(r5)
747 /* Primary thread switches back to host partition */
748 ld r6,KVM_HOST_SDR1(r4)
749 lwz r7,KVM_HOST_LPID(r4)
750 li r8,LPID_RSVD /* switch to reserved LPID */
753 mtspr SPRN_SDR1,r6 /* switch to partition page table */
757 stb r0,VCORE_IN_GUEST(r5)
758 lis r8,0x7fff /* MAX_INT@h */
761 16: ld r8,KVM_HOST_LPCR(r4)
767 * PPC970 guest -> host partition switch code.
768 * We have to lock against concurrent tlbies, and
769 * we have to flush the whole TLB.
771 32: ld r4,VCPU_KVM(r9) /* pointer to struct kvm */
773 /* Take the guest's tlbie_lock */
774 lwz r8,PACA_LOCK_TOKEN(r13)
775 addi r3,r4,KVM_TLBIE_LOCK
783 ld r7,KVM_HOST_LPCR(r4) /* use kvm->arch.host_lpcr for HID4 */
785 rotldi r0,r0,HID4_LPID5_SH /* all lpid bits in HID4 = 1 */
789 mtspr SPRN_HID4,r0 /* switch to reserved LPID */
792 stw r0,0(r3) /* drop guest tlbie_lock */
794 /* invalidate the whole TLB */
803 /* take native_tlbie_lock */
804 ld r3,toc_tlbie_lock@toc(2)
812 ld r6,KVM_HOST_SDR1(r4)
813 mtspr SPRN_SDR1,r6 /* switch to host page table */
815 /* Set up host HID4 value */
820 stw r0,0(r3) /* drop native_tlbie_lock */
822 lis r8,0x7fff /* MAX_INT@h */
825 /* Disable HDEC interrupts */
828 rldimi r0,r3, HID0_HDICE_SH, 64-HID0_HDICE_SH-1
838 /* load host SLB entries */
839 33: ld r8,PACA_SLBSHADOWPTR(r13)
842 ld r5,SLBSHADOW_SAVEAREA(r8)
843 ld r6,SLBSHADOW_SAVEAREA+8(r8)
844 andis. r7,r5,SLB_ESID_V@h
850 /* Save and reset AMR and UAMOR before turning on the MMU */
855 std r6,VCPU_UAMOR(r9)
858 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
860 /* Restore host DABR and DABRX */
861 ld r5,HSTATE_DABR(r13)
866 /* Switch DSCR back to host value */
869 ld r7, HSTATE_DSCR(r13)
870 std r8, VCPU_DSCR(r7)
872 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
874 /* Save non-volatile GPRs */
875 std r14, VCPU_GPR(r14)(r9)
876 std r15, VCPU_GPR(r15)(r9)
877 std r16, VCPU_GPR(r16)(r9)
878 std r17, VCPU_GPR(r17)(r9)
879 std r18, VCPU_GPR(r18)(r9)
880 std r19, VCPU_GPR(r19)(r9)
881 std r20, VCPU_GPR(r20)(r9)
882 std r21, VCPU_GPR(r21)(r9)
883 std r22, VCPU_GPR(r22)(r9)
884 std r23, VCPU_GPR(r23)(r9)
885 std r24, VCPU_GPR(r24)(r9)
886 std r25, VCPU_GPR(r25)(r9)
887 std r26, VCPU_GPR(r26)(r9)
888 std r27, VCPU_GPR(r27)(r9)
889 std r28, VCPU_GPR(r28)(r9)
890 std r29, VCPU_GPR(r29)(r9)
891 std r30, VCPU_GPR(r30)(r9)
892 std r31, VCPU_GPR(r31)(r9)
899 std r3, VCPU_SPRG0(r9)
900 std r4, VCPU_SPRG1(r9)
901 std r5, VCPU_SPRG2(r9)
902 std r6, VCPU_SPRG3(r9)
904 /* Increment yield count if they have a VPA */
905 ld r8, VCPU_VPA(r9) /* do they have a VPA? */
908 lwz r3, LPPACA_YIELDCOUNT(r8)
910 stw r3, LPPACA_YIELDCOUNT(r8)
912 /* Save PMU registers if requested */
913 /* r8 and cr0.eq are live here */
915 sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
916 mfspr r4, SPRN_MMCR0 /* save MMCR0 */
917 mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */
919 beq 21f /* if no VPA, save PMU stuff anyway */
920 lbz r7, LPPACA_PMCINUSE(r8)
921 cmpwi r7, 0 /* did they ask for PMU stuff to be saved? */
923 std r3, VCPU_MMCR(r9) /* if not, set saved MMCR0 to FC */
925 21: mfspr r5, SPRN_MMCR1
927 std r4, VCPU_MMCR(r9)
928 std r5, VCPU_MMCR + 8(r9)
929 std r6, VCPU_MMCR + 16(r9)
939 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
941 stw r4, VCPU_PMC + 4(r9)
942 stw r5, VCPU_PMC + 8(r9)
943 stw r6, VCPU_PMC + 12(r9)
944 stw r7, VCPU_PMC + 16(r9)
945 stw r8, VCPU_PMC + 20(r9)
947 stw r10, VCPU_PMC + 24(r9)
948 stw r11, VCPU_PMC + 28(r9)
949 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
955 /* Secondary threads go off to take a nap on POWER7 */
960 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
963 * Reload DEC. HDEC interrupts were disabled when
964 * we reloaded the host's LPCR value.
966 ld r3, HSTATE_DECEXP(r13)
971 /* Reload the host's PMU registers */
972 ld r3, PACALPPACAPTR(r13) /* is the host using the PMU? */
973 lbz r4, LPPACA_PMCINUSE(r3)
975 beq 23f /* skip if not */
976 lwz r3, HSTATE_PMC(r13)
977 lwz r4, HSTATE_PMC + 4(r13)
978 lwz r5, HSTATE_PMC + 8(r13)
979 lwz r6, HSTATE_PMC + 12(r13)
980 lwz r8, HSTATE_PMC + 16(r13)
981 lwz r9, HSTATE_PMC + 20(r13)
983 lwz r10, HSTATE_PMC + 24(r13)
984 lwz r11, HSTATE_PMC + 28(r13)
985 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
995 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
996 ld r3, HSTATE_MMCR(r13)
997 ld r4, HSTATE_MMCR + 8(r13)
998 ld r5, HSTATE_MMCR + 16(r13)
1000 mtspr SPRN_MMCRA, r5
1001 mtspr SPRN_MMCR0, r3
1005 * For external and machine check interrupts, we need
1006 * to call the Linux handler to process the interrupt.
1007 * We do that by jumping to the interrupt vector address
1008 * which we have in r12. The [h]rfid at the end of the
1009 * handler will return to the book3s_hv_interrupts.S code.
1010 * For other interrupts we do the rfid to get back
1011 * to the book3s_interrupts.S code here.
1013 ld r8, HSTATE_VMHANDLER(r13)
1014 ld r7, HSTATE_HOST_MSR(r13)
1016 cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL
1018 cmpwi r12, BOOK3S_INTERRUPT_MACHINE_CHECK
1020 /* RFI into the highmem handler, or branch to interrupt handler */
1025 mtmsrd r6, 1 /* Clear RI in MSR */
1034 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
1035 mtspr SPRN_HSRR0, r8
1036 mtspr SPRN_HSRR1, r7
1039 6: mfspr r6,SPRN_HDAR
1040 mfspr r7,SPRN_HDSISR
1044 * Try to handle an hcall in real mode.
1045 * Returns to the guest if we handle it, or continues on up to
1046 * the kernel if we can't (i.e. if we don't have a handler for
1047 * it, or if the handler returns H_TOO_HARD).
1049 .globl hcall_try_real_mode
1050 hcall_try_real_mode:
1051 ld r3,VCPU_GPR(r3)(r9)
1055 cmpldi r3,hcall_real_table_end - hcall_real_table
1057 LOAD_REG_ADDR(r4, hcall_real_table)
1063 mr r3,r9 /* get vcpu pointer */
1064 ld r4,VCPU_GPR(r4)(r9)
1067 beq hcall_real_fallback
1068 ld r4,HSTATE_KVM_VCPU(r13)
1069 std r3,VCPU_GPR(r3)(r4)
1074 /* We've attempted a real mode hcall, but it's punted it back
1075 * to userspace. We need to restore some clobbered volatiles
1076 * before resuming the pass-it-to-qemu path */
1077 hcall_real_fallback:
1078 li r12,BOOK3S_INTERRUPT_SYSCALL
1079 ld r9, HSTATE_KVM_VCPU(r13)
1080 ld r11, VCPU_MSR(r9)
1084 .globl hcall_real_table
1086 .long 0 /* 0 - unused */
1087 .long .kvmppc_h_remove - hcall_real_table
1088 .long .kvmppc_h_enter - hcall_real_table
1089 .long .kvmppc_h_read - hcall_real_table
1090 .long 0 /* 0x10 - H_CLEAR_MOD */
1091 .long 0 /* 0x14 - H_CLEAR_REF */
1092 .long .kvmppc_h_protect - hcall_real_table
1093 .long 0 /* 0x1c - H_GET_TCE */
1094 .long .kvmppc_h_put_tce - hcall_real_table
1095 .long 0 /* 0x24 - H_SET_SPRG0 */
1096 .long .kvmppc_h_set_dabr - hcall_real_table
1159 .long .kvmppc_h_bulk_remove - hcall_real_table
1160 hcall_real_table_end:
1166 bounce_ext_interrupt:
1170 li r10,BOOK3S_INTERRUPT_EXTERNAL
1171 LOAD_REG_IMMEDIATE(r11,MSR_SF | MSR_ME);
1174 _GLOBAL(kvmppc_h_set_dabr)
1175 std r4,VCPU_DABR(r3)
1181 ld r5,HSTATE_KVM_VCORE(r13)
1183 13: lbz r3,VCORE_IN_GUEST(r5)
1187 ld r11,PACA_SLBSHADOWPTR(r13)
1189 .rept SLB_NUM_BOLTED
1190 ld r5,SLBSHADOW_SAVEAREA(r11)
1191 ld r6,SLBSHADOW_SAVEAREA+8(r11)
1192 andis. r7,r5,SLB_ESID_V@h
1200 /* Clear any pending IPI */
1201 50: ld r5, HSTATE_XICS_PHYS(r13)
1206 /* increment the nap count and then go to nap mode */
1207 ld r4, HSTATE_KVM_VCORE(r13)
1208 addi r4, r4, VCORE_NAP_COUNT
1209 lwsync /* make previous updates visible */
1219 ori r4, r4, LPCR_PECE0 /* exit nap on interrupt */
1222 std r0, HSTATE_SCRATCH0(r13)
1224 ld r0, HSTATE_SCRATCH0(r13)
1231 * Save away FP, VMX and VSX registers.
1234 _GLOBAL(kvmppc_save_fp)
1237 #ifdef CONFIG_ALTIVEC
1239 oris r8,r8,MSR_VEC@h
1240 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1244 oris r8,r8,MSR_VSX@h
1245 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1253 li r6,reg*16+VCPU_VSRS
1261 stfd reg,reg*8+VCPU_FPRS(r3)
1265 ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX)
1268 stfd fr0,VCPU_FPSCR(r3)
1270 #ifdef CONFIG_ALTIVEC
1274 li r6,reg*16+VCPU_VRS
1281 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1283 mfspr r6,SPRN_VRSAVE
1284 stw r6,VCPU_VRSAVE(r3)
1290 * Load up FP, VMX and VSX registers
1293 .globl kvmppc_load_fp
1297 #ifdef CONFIG_ALTIVEC
1299 oris r8,r8,MSR_VEC@h
1300 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1304 oris r8,r8,MSR_VSX@h
1305 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1309 lfd fr0,VCPU_FPSCR(r4)
1315 li r7,reg*16+VCPU_VSRS
1323 lfd reg,reg*8+VCPU_FPRS(r4)
1327 ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX)
1330 #ifdef CONFIG_ALTIVEC
1337 li r7,reg*16+VCPU_VRS
1341 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1343 lwz r7,VCPU_VRSAVE(r4)
1344 mtspr SPRN_VRSAVE,r7