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 /* Increment yield count if they have a VPA */
412 lwz r5, LPPACA_YIELDCOUNT(r3)
414 stw r5, LPPACA_YIELDCOUNT(r3)
416 stb r6, VCPU_VPA_DIRTY(r4)
418 /* Load up DAR and DSISR */
420 lwz r6, VCPU_DSISR(r4)
425 /* Restore AMR and UAMOR, set AMOR to all 1s */
432 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
442 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
444 * POWER7 host -> guest partition switch code.
445 * We don't have to lock against concurrent tlbies,
446 * but we do have to coordinate across hardware threads.
448 /* Increment entry count iff exit count is zero. */
449 ld r5,HSTATE_KVM_VCORE(r13)
450 addi r9,r5,VCORE_ENTRY_EXIT
452 cmpwi r3,0x100 /* any threads starting to exit? */
453 bge secondary_too_late /* if so we're too late to the party */
458 /* Primary thread switches to guest partition. */
459 ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
465 li r0,LPID_RSVD /* switch to reserved LPID */
468 mtspr SPRN_SDR1,r6 /* switch to partition page table */
472 /* See if we need to flush the TLB */
473 lhz r6,PACAPACAINDEX(r13) /* test_bit(cpu, need_tlb_flush) */
474 clrldi r7,r6,64-6 /* extract bit number (6 bits) */
475 srdi r6,r6,6 /* doubleword number */
476 sldi r6,r6,3 /* address offset */
478 addi r6,r6,KVM_NEED_FLUSH /* dword in kvm->arch.need_tlb_flush */
484 23: ldarx r7,0,r6 /* if set, clear the bit */
488 li r6,128 /* and flush the TLB */
490 li r7,0x800 /* IS field = 0b10 */
497 /* Add timebase offset onto timebase */
498 22: ld r8,VCORE_TB_OFFSET(r5)
501 mftb r6 /* current host timebase */
503 mtspr SPRN_TBU40,r8 /* update upper 40 bits */
504 mftb r7 /* check if lower 24 bits overflowed */
509 addis r8,r8,0x100 /* if so, increment upper 40 bits */
513 stb r0,VCORE_IN_GUEST(r5) /* signal secondaries to continue */
516 /* Secondary threads wait for primary to have done partition switch */
517 20: lbz r0,VCORE_IN_GUEST(r5)
521 /* Set LPCR and RMOR. */
522 10: ld r8,KVM_LPCR(r9)
528 /* Check if HDEC expires soon */
531 li r12,BOOK3S_INTERRUPT_HV_DECREMENTER
535 /* Save purr/spurr */
538 std r5,HSTATE_PURR(r13)
539 std r6,HSTATE_SPURR(r13)
547 * PPC970 host -> guest partition switch code.
548 * We have to lock against concurrent tlbies,
549 * using native_tlbie_lock to lock against host tlbies
550 * and kvm->arch.tlbie_lock to lock against guest tlbies.
551 * We also have to invalidate the TLB since its
552 * entries aren't tagged with the LPID.
554 30: ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
556 /* first take native_tlbie_lock */
559 .tc native_tlbie_lock[TC],native_tlbie_lock
561 ld r3,toc_tlbie_lock@toc(2)
562 #ifdef __BIG_ENDIAN__
563 lwz r8,PACA_LOCK_TOKEN(r13)
565 lwz r8,PACAPACAINDEX(r13)
574 ld r7,KVM_LPCR(r9) /* use kvm->arch.lpcr to store HID4 */
576 rotldi r0,r0,HID4_LPID5_SH /* all lpid bits in HID4 = 1 */
580 mtspr SPRN_HID4,r0 /* switch to reserved LPID */
583 stw r0,0(r3) /* drop native_tlbie_lock */
585 /* invalidate the whole TLB */
594 /* Take the guest's tlbie_lock */
595 addi r3,r9,KVM_TLBIE_LOCK
603 mtspr SPRN_SDR1,r6 /* switch to partition page table */
605 /* Set up HID4 with the guest's LPID etc. */
610 /* drop the guest's tlbie_lock */
614 /* Check if HDEC expires soon */
617 li r12,BOOK3S_INTERRUPT_HV_DECREMENTER
621 /* Enable HDEC interrupts */
624 rldimi r0,r3, HID0_HDICE_SH, 64-HID0_HDICE_SH-1
634 /* Load up guest SLB entries */
635 31: lwz r5,VCPU_SLB_MAX(r4)
640 1: ld r8,VCPU_SLB_E(r6)
643 addi r6,r6,VCPU_SLB_SIZE
647 /* Restore state of CTRL run bit; assume 1 on entry */
663 kvmppc_cede_reentry: /* r4 = vcpu, r13 = paca */
667 /* r11 = vcpu->arch.msr & ~MSR_HV */
668 rldicl r11, r11, 63 - MSR_HV_LG, 1
669 rotldi r11, r11, 1 + MSR_HV_LG
672 /* Check if we can deliver an external or decrementer interrupt now */
673 ld r0,VCPU_PENDING_EXC(r4)
674 lis r8,(1 << BOOK3S_IRQPRIO_EXTERNAL_LEVEL)@h
684 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
686 li r0,BOOK3S_INTERRUPT_EXTERNAL
690 li r11,(MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
696 li r0,BOOK3S_INTERRUPT_DECREMENTER
699 /* Move SRR0 and SRR1 into the respective regs */
700 5: mtspr SPRN_SRR0, r6
705 stb r0,VCPU_CEDED(r4) /* cancel cede */
709 /* Activate guest mode, so faults get handled by KVM */
710 li r9, KVM_GUEST_MODE_GUEST
711 stb r9, HSTATE_IN_GUEST(r13)
718 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
725 ld r0, VCPU_GPR(R0)(r4)
726 ld r1, VCPU_GPR(R1)(r4)
727 ld r2, VCPU_GPR(R2)(r4)
728 ld r3, VCPU_GPR(R3)(r4)
729 ld r5, VCPU_GPR(R5)(r4)
730 ld r6, VCPU_GPR(R6)(r4)
731 ld r7, VCPU_GPR(R7)(r4)
732 ld r8, VCPU_GPR(R8)(r4)
733 ld r9, VCPU_GPR(R9)(r4)
734 ld r10, VCPU_GPR(R10)(r4)
735 ld r11, VCPU_GPR(R11)(r4)
736 ld r12, VCPU_GPR(R12)(r4)
737 ld r13, VCPU_GPR(R13)(r4)
739 ld r4, VCPU_GPR(R4)(r4)
744 /******************************************************************************
748 *****************************************************************************/
751 * We come here from the first-level interrupt handlers.
753 .globl kvmppc_interrupt
757 * R12 = interrupt vector
759 * guest CR, R12 saved in shadow VCPU SCRATCH1/0
760 * guest R13 saved in SPRN_SCRATCH0
762 /* abuse host_r2 as third scratch area; we get r2 from PACATOC(r13) */
763 std r9, HSTATE_HOST_R2(r13)
764 ld r9, HSTATE_KVM_VCPU(r13)
768 std r0, VCPU_GPR(R0)(r9)
769 std r1, VCPU_GPR(R1)(r9)
770 std r2, VCPU_GPR(R2)(r9)
771 std r3, VCPU_GPR(R3)(r9)
772 std r4, VCPU_GPR(R4)(r9)
773 std r5, VCPU_GPR(R5)(r9)
774 std r6, VCPU_GPR(R6)(r9)
775 std r7, VCPU_GPR(R7)(r9)
776 std r8, VCPU_GPR(R8)(r9)
777 ld r0, HSTATE_HOST_R2(r13)
778 std r0, VCPU_GPR(R9)(r9)
779 std r10, VCPU_GPR(R10)(r9)
780 std r11, VCPU_GPR(R11)(r9)
781 ld r3, HSTATE_SCRATCH0(r13)
782 lwz r4, HSTATE_SCRATCH1(r13)
783 std r3, VCPU_GPR(R12)(r9)
786 ld r3, HSTATE_CFAR(r13)
787 std r3, VCPU_CFAR(r9)
788 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
790 /* Restore R1/R2 so we can handle faults */
791 ld r1, HSTATE_HOST_R1(r13)
796 std r10, VCPU_SRR0(r9)
797 std r11, VCPU_SRR1(r9)
798 andi. r0, r12, 2 /* need to read HSRR0/1? */
800 mfspr r10, SPRN_HSRR0
801 mfspr r11, SPRN_HSRR1
803 1: std r10, VCPU_PC(r9)
804 std r11, VCPU_MSR(r9)
808 std r3, VCPU_GPR(R13)(r9)
811 /* Unset guest mode */
812 li r0, KVM_GUEST_MODE_NONE
813 stb r0, HSTATE_IN_GUEST(r13)
815 stw r12,VCPU_TRAP(r9)
817 /* Save HEIR (HV emulation assist reg) in last_inst
818 if this is an HEI (HV emulation interrupt, e40) */
819 li r3,KVM_INST_FETCH_FAILED
821 cmpwi r12,BOOK3S_INTERRUPT_H_EMUL_ASSIST
824 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
825 11: stw r3,VCPU_LAST_INST(r9)
827 /* these are volatile across C function calls */
834 /* If this is a page table miss then see if it's theirs or ours */
835 cmpwi r12, BOOK3S_INTERRUPT_H_DATA_STORAGE
837 cmpwi r12, BOOK3S_INTERRUPT_H_INST_STORAGE
839 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
841 /* See if this is a leftover HDEC interrupt */
842 cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER
848 /* See if this is an hcall we can handle in real mode */
849 cmpwi r12,BOOK3S_INTERRUPT_SYSCALL
850 beq hcall_try_real_mode
852 /* Only handle external interrupts here on arch 206 and later */
854 b ext_interrupt_to_host
855 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206)
857 /* External interrupt ? */
858 cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL
859 bne+ ext_interrupt_to_host
861 /* External interrupt, first check for host_ipi. If this is
862 * set, we know the host wants us out so let's do it now
867 bgt ext_interrupt_to_host
869 /* Allright, looks like an IPI for the guest, we need to set MER */
870 /* Check if any CPU is heading out to the host, if so head out too */
871 ld r5, HSTATE_KVM_VCORE(r13)
872 lwz r0, VCORE_ENTRY_EXIT(r5)
874 bge ext_interrupt_to_host
876 /* See if there is a pending interrupt for the guest */
878 ld r0, VCPU_PENDING_EXC(r9)
879 /* Insert EXTERNAL_LEVEL bit into LPCR at the MER bit position */
880 rldicl. r0, r0, 64 - BOOK3S_IRQPRIO_EXTERNAL_LEVEL, 63
881 rldimi r8, r0, LPCR_MER_SH, 63 - LPCR_MER_SH
884 /* And if the guest EE is set, we can deliver immediately, else
885 * we return to the guest with MER set
887 andi. r0, r11, MSR_EE
891 li r10, BOOK3S_INTERRUPT_EXTERNAL
892 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
898 ext_interrupt_to_host:
900 guest_exit_cont: /* r9 = vcpu, r12 = trap, r13 = paca */
901 /* Save more register state */
905 stw r7, VCPU_DSISR(r9)
907 /* don't overwrite fault_dar/fault_dsisr if HDSI */
908 cmpwi r12,BOOK3S_INTERRUPT_H_DATA_STORAGE
910 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
911 std r6, VCPU_FAULT_DAR(r9)
912 stw r7, VCPU_FAULT_DSISR(r9)
914 /* See if it is a machine check */
915 cmpwi r12, BOOK3S_INTERRUPT_MACHINE_CHECK
916 beq machine_check_realmode
919 /* Save guest CTRL register, set runlatch to 1 */
920 6: mfspr r6,SPRN_CTRLF
927 /* Read the guest SLB and save it away */
928 lwz r0,VCPU_SLB_NR(r9) /* number of entries in SLB */
934 andis. r0,r8,SLB_ESID_V@h
936 add r8,r8,r6 /* put index in */
938 std r8,VCPU_SLB_E(r7)
939 std r3,VCPU_SLB_V(r7)
940 addi r7,r7,VCPU_SLB_SIZE
944 stw r5,VCPU_SLB_MAX(r9)
947 * Save the guest PURR/SPURR
955 std r6,VCPU_SPURR(r9)
960 * Restore host PURR/SPURR and add guest times
961 * so that the time in the guest gets accounted.
963 ld r3,HSTATE_PURR(r13)
964 ld r4,HSTATE_SPURR(r13)
969 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_201)
977 hdec_soon: /* r9 = vcpu, r12 = trap, r13 = paca */
980 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
982 * POWER7 guest -> host partition switch code.
983 * We don't have to lock against tlbies but we do
984 * have to coordinate the hardware threads.
986 /* Increment the threads-exiting-guest count in the 0xff00
987 bits of vcore->entry_exit_count */
989 ld r5,HSTATE_KVM_VCORE(r13)
990 addi r6,r5,VCORE_ENTRY_EXIT
998 * At this point we have an interrupt that we have to pass
999 * up to the kernel or qemu; we can't handle it in real mode.
1000 * Thus we have to do a partition switch, so we have to
1001 * collect the other threads, if we are the first thread
1002 * to take an interrupt. To do this, we set the HDEC to 0,
1003 * which causes an HDEC interrupt in all threads within 2ns
1004 * because the HDEC register is shared between all 4 threads.
1005 * However, we don't need to bother if this is an HDEC
1006 * interrupt, since the other threads will already be on their
1007 * way here in that case.
1009 cmpwi r3,0x100 /* Are we the first here? */
1011 cmpwi r3,1 /* Are any other threads in the guest? */
1013 cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER
1019 * Send an IPI to any napping threads, since an HDEC interrupt
1020 * doesn't wake CPUs up from nap.
1022 lwz r3,VCORE_NAPPING_THREADS(r5)
1023 lwz r4,VCPU_PTID(r9)
1026 andc. r3,r3,r0 /* no sense IPI'ing ourselves */
1028 mulli r4,r4,PACA_SIZE /* get paca for thread 0 */
1032 ld r8,HSTATE_XICS_PHYS(r6) /* get thread's XICS reg addr */
1035 stbcix r0,r7,r8 /* trigger the IPI */
1037 addi r6,r6,PACA_SIZE
1040 /* Secondary threads wait for primary to do partition switch */
1041 43: ld r4,VCPU_KVM(r9) /* pointer to struct kvm */
1042 ld r5,HSTATE_KVM_VCORE(r13)
1043 lwz r3,VCPU_PTID(r9)
1047 13: lbz r3,VCORE_IN_GUEST(r5)
1053 /* Primary thread waits for all the secondaries to exit guest */
1054 15: lwz r3,VCORE_ENTRY_EXIT(r5)
1061 /* Primary thread switches back to host partition */
1062 ld r6,KVM_HOST_SDR1(r4)
1063 lwz r7,KVM_HOST_LPID(r4)
1064 li r8,LPID_RSVD /* switch to reserved LPID */
1067 mtspr SPRN_SDR1,r6 /* switch to partition page table */
1071 /* Subtract timebase offset from timebase */
1072 ld r8,VCORE_TB_OFFSET(r5)
1075 mftb r6 /* current host timebase */
1077 mtspr SPRN_TBU40,r8 /* update upper 40 bits */
1078 mftb r7 /* check if lower 24 bits overflowed */
1083 addis r8,r8,0x100 /* if so, increment upper 40 bits */
1086 /* Signal secondary CPUs to continue */
1088 stb r0,VCORE_IN_GUEST(r5)
1089 lis r8,0x7fff /* MAX_INT@h */
1092 16: ld r8,KVM_HOST_LPCR(r4)
1098 * PPC970 guest -> host partition switch code.
1099 * We have to lock against concurrent tlbies, and
1100 * we have to flush the whole TLB.
1102 32: ld r4,VCPU_KVM(r9) /* pointer to struct kvm */
1104 /* Take the guest's tlbie_lock */
1105 #ifdef __BIG_ENDIAN__
1106 lwz r8,PACA_LOCK_TOKEN(r13)
1108 lwz r8,PACAPACAINDEX(r13)
1110 addi r3,r4,KVM_TLBIE_LOCK
1118 ld r7,KVM_HOST_LPCR(r4) /* use kvm->arch.host_lpcr for HID4 */
1120 rotldi r0,r0,HID4_LPID5_SH /* all lpid bits in HID4 = 1 */
1124 mtspr SPRN_HID4,r0 /* switch to reserved LPID */
1127 stw r0,0(r3) /* drop guest tlbie_lock */
1129 /* invalidate the whole TLB */
1138 /* take native_tlbie_lock */
1139 ld r3,toc_tlbie_lock@toc(2)
1147 ld r6,KVM_HOST_SDR1(r4)
1148 mtspr SPRN_SDR1,r6 /* switch to host page table */
1150 /* Set up host HID4 value */
1155 stw r0,0(r3) /* drop native_tlbie_lock */
1157 lis r8,0x7fff /* MAX_INT@h */
1160 /* Disable HDEC interrupts */
1163 rldimi r0,r3, HID0_HDICE_SH, 64-HID0_HDICE_SH-1
1173 /* load host SLB entries */
1174 33: ld r8,PACA_SLBSHADOWPTR(r13)
1176 .rept SLB_NUM_BOLTED
1177 ld r5,SLBSHADOW_SAVEAREA(r8)
1178 ld r6,SLBSHADOW_SAVEAREA+8(r8)
1179 andis. r7,r5,SLB_ESID_V@h
1190 std r5,VCPU_DEC_EXPIRES(r9)
1192 /* Save and reset AMR and UAMOR before turning on the MMU */
1197 std r6,VCPU_UAMOR(r9)
1200 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
1202 /* Switch DSCR back to host value */
1205 ld r7, HSTATE_DSCR(r13)
1206 std r8, VCPU_DSCR(r7)
1208 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
1210 /* Save non-volatile GPRs */
1211 std r14, VCPU_GPR(R14)(r9)
1212 std r15, VCPU_GPR(R15)(r9)
1213 std r16, VCPU_GPR(R16)(r9)
1214 std r17, VCPU_GPR(R17)(r9)
1215 std r18, VCPU_GPR(R18)(r9)
1216 std r19, VCPU_GPR(R19)(r9)
1217 std r20, VCPU_GPR(R20)(r9)
1218 std r21, VCPU_GPR(R21)(r9)
1219 std r22, VCPU_GPR(R22)(r9)
1220 std r23, VCPU_GPR(R23)(r9)
1221 std r24, VCPU_GPR(R24)(r9)
1222 std r25, VCPU_GPR(R25)(r9)
1223 std r26, VCPU_GPR(R26)(r9)
1224 std r27, VCPU_GPR(R27)(r9)
1225 std r28, VCPU_GPR(R28)(r9)
1226 std r29, VCPU_GPR(R29)(r9)
1227 std r30, VCPU_GPR(R30)(r9)
1228 std r31, VCPU_GPR(R31)(r9)
1231 mfspr r3, SPRN_SPRG0
1232 mfspr r4, SPRN_SPRG1
1233 mfspr r5, SPRN_SPRG2
1234 mfspr r6, SPRN_SPRG3
1235 std r3, VCPU_SPRG0(r9)
1236 std r4, VCPU_SPRG1(r9)
1237 std r5, VCPU_SPRG2(r9)
1238 std r6, VCPU_SPRG3(r9)
1244 /* Increment yield count if they have a VPA */
1245 ld r8, VCPU_VPA(r9) /* do they have a VPA? */
1248 lwz r3, LPPACA_YIELDCOUNT(r8)
1250 stw r3, LPPACA_YIELDCOUNT(r8)
1252 stb r3, VCPU_VPA_DIRTY(r9)
1254 /* Save PMU registers if requested */
1255 /* r8 and cr0.eq are live here */
1257 sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
1258 mfspr r4, SPRN_MMCR0 /* save MMCR0 */
1259 mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */
1260 mfspr r6, SPRN_MMCRA
1262 /* On P7, clear MMCRA in order to disable SDAR updates */
1264 mtspr SPRN_MMCRA, r7
1265 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
1267 beq 21f /* if no VPA, save PMU stuff anyway */
1268 lbz r7, LPPACA_PMCINUSE(r8)
1269 cmpwi r7, 0 /* did they ask for PMU stuff to be saved? */
1271 std r3, VCPU_MMCR(r9) /* if not, set saved MMCR0 to FC */
1273 21: mfspr r5, SPRN_MMCR1
1276 std r4, VCPU_MMCR(r9)
1277 std r5, VCPU_MMCR + 8(r9)
1278 std r6, VCPU_MMCR + 16(r9)
1279 std r7, VCPU_SIAR(r9)
1280 std r8, VCPU_SDAR(r9)
1288 mfspr r10, SPRN_PMC7
1289 mfspr r11, SPRN_PMC8
1290 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
1291 stw r3, VCPU_PMC(r9)
1292 stw r4, VCPU_PMC + 4(r9)
1293 stw r5, VCPU_PMC + 8(r9)
1294 stw r6, VCPU_PMC + 12(r9)
1295 stw r7, VCPU_PMC + 16(r9)
1296 stw r8, VCPU_PMC + 20(r9)
1298 stw r10, VCPU_PMC + 24(r9)
1299 stw r11, VCPU_PMC + 28(r9)
1300 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
1302 ld r0, 112+PPC_LR_STKOFF(r1)
1307 ld r5,HSTATE_KVM_VCORE(r13)
1309 13: lbz r3,VCORE_IN_GUEST(r5)
1313 li r0, KVM_GUEST_MODE_NONE
1314 stb r0, HSTATE_IN_GUEST(r13)
1315 ld r11,PACA_SLBSHADOWPTR(r13)
1317 .rept SLB_NUM_BOLTED
1318 ld r5,SLBSHADOW_SAVEAREA(r11)
1319 ld r6,SLBSHADOW_SAVEAREA+8(r11)
1320 andis. r7,r5,SLB_ESID_V@h
1328 * Check whether an HDSI is an HPTE not found fault or something else.
1329 * If it is an HPTE not found fault that is due to the guest accessing
1330 * a page that they have mapped but which we have paged out, then
1331 * we continue on with the guest exit path. In all other cases,
1332 * reflect the HDSI to the guest as a DSI.
1336 mfspr r6, SPRN_HDSISR
1337 /* HPTE not found fault or protection fault? */
1338 andis. r0, r6, (DSISR_NOHPTE | DSISR_PROTFAULT)@h
1339 beq 1f /* if not, send it to the guest */
1340 andi. r0, r11, MSR_DR /* data relocation enabled? */
1343 PPC_SLBFEE_DOT(R5, R0) /* if so, look up SLB */
1344 bne 1f /* if no SLB entry found */
1345 4: std r4, VCPU_FAULT_DAR(r9)
1346 stw r6, VCPU_FAULT_DSISR(r9)
1348 /* Search the hash table. */
1349 mr r3, r9 /* vcpu pointer */
1350 li r7, 1 /* data fault */
1351 bl .kvmppc_hpte_hv_fault
1352 ld r9, HSTATE_KVM_VCPU(r13)
1354 ld r11, VCPU_MSR(r9)
1355 li r12, BOOK3S_INTERRUPT_H_DATA_STORAGE
1356 cmpdi r3, 0 /* retry the instruction */
1358 cmpdi r3, -1 /* handle in kernel mode */
1360 cmpdi r3, -2 /* MMIO emulation; need instr word */
1363 /* Synthesize a DSI for the guest */
1364 ld r4, VCPU_FAULT_DAR(r9)
1366 1: mtspr SPRN_DAR, r4
1367 mtspr SPRN_DSISR, r6
1368 mtspr SPRN_SRR0, r10
1369 mtspr SPRN_SRR1, r11
1370 li r10, BOOK3S_INTERRUPT_DATA_STORAGE
1371 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
1373 fast_interrupt_c_return:
1374 6: ld r7, VCPU_CTR(r9)
1375 lwz r8, VCPU_XER(r9)
1381 3: ld r5, VCPU_KVM(r9) /* not relocated, use VRMA */
1382 ld r5, KVM_VRMA_SLB_V(r5)
1385 /* If this is for emulated MMIO, load the instruction word */
1386 2: li r8, KVM_INST_FETCH_FAILED /* In case lwz faults */
1388 /* Set guest mode to 'jump over instruction' so if lwz faults
1389 * we'll just continue at the next IP. */
1390 li r0, KVM_GUEST_MODE_SKIP
1391 stb r0, HSTATE_IN_GUEST(r13)
1393 /* Do the access with MSR:DR enabled */
1395 ori r4, r3, MSR_DR /* Enable paging for data */
1400 /* Store the result */
1401 stw r8, VCPU_LAST_INST(r9)
1403 /* Unset guest mode. */
1404 li r0, KVM_GUEST_MODE_NONE
1405 stb r0, HSTATE_IN_GUEST(r13)
1409 * Similarly for an HISI, reflect it to the guest as an ISI unless
1410 * it is an HPTE not found fault for a page that we have paged out.
1413 andis. r0, r11, SRR1_ISI_NOPT@h
1415 andi. r0, r11, MSR_IR /* instruction relocation enabled? */
1418 PPC_SLBFEE_DOT(R5, R0) /* if so, look up SLB */
1419 bne 1f /* if no SLB entry found */
1421 /* Search the hash table. */
1422 mr r3, r9 /* vcpu pointer */
1425 li r7, 0 /* instruction fault */
1426 bl .kvmppc_hpte_hv_fault
1427 ld r9, HSTATE_KVM_VCPU(r13)
1429 ld r11, VCPU_MSR(r9)
1430 li r12, BOOK3S_INTERRUPT_H_INST_STORAGE
1431 cmpdi r3, 0 /* retry the instruction */
1432 beq fast_interrupt_c_return
1433 cmpdi r3, -1 /* handle in kernel mode */
1436 /* Synthesize an ISI for the guest */
1438 1: mtspr SPRN_SRR0, r10
1439 mtspr SPRN_SRR1, r11
1440 li r10, BOOK3S_INTERRUPT_INST_STORAGE
1441 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
1443 b fast_interrupt_c_return
1445 3: ld r6, VCPU_KVM(r9) /* not relocated, use VRMA */
1446 ld r5, KVM_VRMA_SLB_V(r6)
1450 * Try to handle an hcall in real mode.
1451 * Returns to the guest if we handle it, or continues on up to
1452 * the kernel if we can't (i.e. if we don't have a handler for
1453 * it, or if the handler returns H_TOO_HARD).
1455 .globl hcall_try_real_mode
1456 hcall_try_real_mode:
1457 ld r3,VCPU_GPR(R3)(r9)
1461 cmpldi r3,hcall_real_table_end - hcall_real_table
1463 LOAD_REG_ADDR(r4, hcall_real_table)
1469 mr r3,r9 /* get vcpu pointer */
1470 ld r4,VCPU_GPR(R4)(r9)
1473 beq hcall_real_fallback
1474 ld r4,HSTATE_KVM_VCPU(r13)
1475 std r3,VCPU_GPR(R3)(r4)
1480 /* We've attempted a real mode hcall, but it's punted it back
1481 * to userspace. We need to restore some clobbered volatiles
1482 * before resuming the pass-it-to-qemu path */
1483 hcall_real_fallback:
1484 li r12,BOOK3S_INTERRUPT_SYSCALL
1485 ld r9, HSTATE_KVM_VCPU(r13)
1489 .globl hcall_real_table
1491 .long 0 /* 0 - unused */
1492 .long .kvmppc_h_remove - hcall_real_table
1493 .long .kvmppc_h_enter - hcall_real_table
1494 .long .kvmppc_h_read - hcall_real_table
1495 .long 0 /* 0x10 - H_CLEAR_MOD */
1496 .long 0 /* 0x14 - H_CLEAR_REF */
1497 .long .kvmppc_h_protect - hcall_real_table
1498 .long 0 /* 0x1c - H_GET_TCE */
1499 .long .kvmppc_h_put_tce - hcall_real_table
1500 .long 0 /* 0x24 - H_SET_SPRG0 */
1501 .long .kvmppc_h_set_dabr - hcall_real_table
1516 #ifdef CONFIG_KVM_XICS
1517 .long .kvmppc_rm_h_eoi - hcall_real_table
1518 .long .kvmppc_rm_h_cppr - hcall_real_table
1519 .long .kvmppc_rm_h_ipi - hcall_real_table
1520 .long 0 /* 0x70 - H_IPOLL */
1521 .long .kvmppc_rm_h_xirr - hcall_real_table
1523 .long 0 /* 0x64 - H_EOI */
1524 .long 0 /* 0x68 - H_CPPR */
1525 .long 0 /* 0x6c - H_IPI */
1526 .long 0 /* 0x70 - H_IPOLL */
1527 .long 0 /* 0x74 - H_XIRR */
1555 .long .kvmppc_h_cede - hcall_real_table
1572 .long .kvmppc_h_bulk_remove - hcall_real_table
1573 hcall_real_table_end:
1579 _GLOBAL(kvmppc_h_set_dabr)
1580 std r4,VCPU_DABR(r3)
1581 /* Work around P7 bug where DABR can get corrupted on mtspr */
1582 1: mtspr SPRN_DABR,r4
1590 _GLOBAL(kvmppc_h_cede)
1592 std r11,VCPU_MSR(r3)
1594 stb r0,VCPU_CEDED(r3)
1595 sync /* order setting ceded vs. testing prodded */
1596 lbz r5,VCPU_PRODDED(r3)
1598 bne kvm_cede_prodded
1599 li r0,0 /* set trap to 0 to say hcall is handled */
1600 stw r0,VCPU_TRAP(r3)
1602 std r0,VCPU_GPR(R3)(r3)
1604 b kvm_cede_exit /* just send it up to host on 970 */
1605 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206)
1608 * Set our bit in the bitmask of napping threads unless all the
1609 * other threads are already napping, in which case we send this
1612 ld r5,HSTATE_KVM_VCORE(r13)
1613 lwz r6,VCPU_PTID(r3)
1614 lwz r8,VCORE_ENTRY_EXIT(r5)
1618 addi r6,r5,VCORE_NAPPING_THREADS
1627 stb r0,HSTATE_NAPPING(r13)
1628 /* order napping_threads update vs testing entry_exit_count */
1631 lwz r7,VCORE_ENTRY_EXIT(r5)
1633 bge 33f /* another thread already exiting */
1636 * Although not specifically required by the architecture, POWER7
1637 * preserves the following registers in nap mode, even if an SMT mode
1638 * switch occurs: SLB entries, PURR, SPURR, AMOR, UAMOR, AMR, SPRG0-3,
1639 * DAR, DSISR, DABR, DABRX, DSCR, PMCx, MMCRx, SIAR, SDAR.
1641 /* Save non-volatile GPRs */
1642 std r14, VCPU_GPR(R14)(r3)
1643 std r15, VCPU_GPR(R15)(r3)
1644 std r16, VCPU_GPR(R16)(r3)
1645 std r17, VCPU_GPR(R17)(r3)
1646 std r18, VCPU_GPR(R18)(r3)
1647 std r19, VCPU_GPR(R19)(r3)
1648 std r20, VCPU_GPR(R20)(r3)
1649 std r21, VCPU_GPR(R21)(r3)
1650 std r22, VCPU_GPR(R22)(r3)
1651 std r23, VCPU_GPR(R23)(r3)
1652 std r24, VCPU_GPR(R24)(r3)
1653 std r25, VCPU_GPR(R25)(r3)
1654 std r26, VCPU_GPR(R26)(r3)
1655 std r27, VCPU_GPR(R27)(r3)
1656 std r28, VCPU_GPR(R28)(r3)
1657 std r29, VCPU_GPR(R29)(r3)
1658 std r30, VCPU_GPR(R30)(r3)
1659 std r31, VCPU_GPR(R31)(r3)
1665 * Take a nap until a decrementer or external interrupt occurs,
1666 * with PECE1 (wake on decr) and PECE0 (wake on external) set in LPCR
1669 stb r0,HSTATE_HWTHREAD_REQ(r13)
1671 ori r5,r5,LPCR_PECE0 | LPCR_PECE1
1675 std r0, HSTATE_SCRATCH0(r13)
1677 ld r0, HSTATE_SCRATCH0(r13)
1684 /* get vcpu pointer */
1685 ld r4, HSTATE_KVM_VCPU(r13)
1687 /* Woken by external or decrementer interrupt */
1688 ld r1, HSTATE_HOST_R1(r13)
1690 /* load up FP state */
1694 ld r14, VCPU_GPR(R14)(r4)
1695 ld r15, VCPU_GPR(R15)(r4)
1696 ld r16, VCPU_GPR(R16)(r4)
1697 ld r17, VCPU_GPR(R17)(r4)
1698 ld r18, VCPU_GPR(R18)(r4)
1699 ld r19, VCPU_GPR(R19)(r4)
1700 ld r20, VCPU_GPR(R20)(r4)
1701 ld r21, VCPU_GPR(R21)(r4)
1702 ld r22, VCPU_GPR(R22)(r4)
1703 ld r23, VCPU_GPR(R23)(r4)
1704 ld r24, VCPU_GPR(R24)(r4)
1705 ld r25, VCPU_GPR(R25)(r4)
1706 ld r26, VCPU_GPR(R26)(r4)
1707 ld r27, VCPU_GPR(R27)(r4)
1708 ld r28, VCPU_GPR(R28)(r4)
1709 ld r29, VCPU_GPR(R29)(r4)
1710 ld r30, VCPU_GPR(R30)(r4)
1711 ld r31, VCPU_GPR(R31)(r4)
1713 /* clear our bit in vcore->napping_threads */
1714 33: ld r5,HSTATE_KVM_VCORE(r13)
1715 lwz r3,VCPU_PTID(r4)
1718 addi r6,r5,VCORE_NAPPING_THREADS
1724 stb r0,HSTATE_NAPPING(r13)
1726 /* Check the wake reason in SRR1 to see why we got here */
1728 rlwinm r3, r3, 44-31, 0x7 /* extract wake reason field */
1729 cmpwi r3, 4 /* was it an external interrupt? */
1730 li r12, BOOK3S_INTERRUPT_EXTERNAL
1733 ld r11, VCPU_MSR(r9)
1734 beq do_ext_interrupt /* if so */
1736 /* see if any other thread is already exiting */
1737 lwz r0,VCORE_ENTRY_EXIT(r5)
1739 blt kvmppc_cede_reentry /* if not go back to guest */
1741 /* some threads are exiting, so go to the guest exit path */
1742 b hcall_real_fallback
1744 /* cede when already previously prodded case */
1747 stb r0,VCPU_PRODDED(r3)
1748 sync /* order testing prodded vs. clearing ceded */
1749 stb r0,VCPU_CEDED(r3)
1753 /* we've ceded but we want to give control to the host */
1755 b hcall_real_fallback
1757 /* Try to handle a machine check in real mode */
1758 machine_check_realmode:
1759 mr r3, r9 /* get vcpu pointer */
1760 bl .kvmppc_realmode_machine_check
1762 cmpdi r3, 0 /* continue exiting from guest? */
1763 ld r9, HSTATE_KVM_VCPU(r13)
1764 li r12, BOOK3S_INTERRUPT_MACHINE_CHECK
1766 /* If not, deliver a machine check. SRR0/1 are already set */
1767 li r10, BOOK3S_INTERRUPT_MACHINE_CHECK
1768 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
1770 b fast_interrupt_c_return
1773 * Determine what sort of external interrupt is pending (if any).
1775 * 0 if no interrupt is pending
1776 * 1 if an interrupt is pending that needs to be handled by the host
1777 * -1 if there was a guest wakeup IPI (which has now been cleared)
1780 /* see if a host IPI is pending */
1782 lbz r0, HSTATE_HOST_IPI(r13)
1786 /* Now read the interrupt from the ICP */
1787 ld r6, HSTATE_XICS_PHYS(r13)
1792 rlwinm. r3, r0, 0, 0xffffff
1794 beq 1f /* if nothing pending in the ICP */
1796 /* We found something in the ICP...
1798 * If it's not an IPI, stash it in the PACA and return to
1799 * the host, we don't (yet) handle directing real external
1800 * interrupts directly to the guest
1802 cmpwi r3, XICS_IPI /* if there is, is it an IPI? */
1806 /* It's an IPI, clear the MFRR and EOI it */
1809 stbcix r3, r6, r8 /* clear the IPI */
1810 stwcix r0, r6, r7 /* EOI it */
1813 /* We need to re-check host IPI now in case it got set in the
1814 * meantime. If it's clear, we bounce the interrupt to the
1817 lbz r0, HSTATE_HOST_IPI(r13)
1821 /* OK, it's an IPI for us */
1825 42: /* It's not an IPI and it's for the host, stash it in the PACA
1826 * before exit, it will be picked up by the host ICP driver
1828 stw r0, HSTATE_SAVED_XIRR(r13)
1831 43: /* We raced with the host, we need to resend that IPI, bummer */
1833 stbcix r0, r6, r8 /* set the IPI */
1838 * Save away FP, VMX and VSX registers.
1841 _GLOBAL(kvmppc_save_fp)
1844 #ifdef CONFIG_ALTIVEC
1846 oris r8,r8,MSR_VEC@h
1847 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1851 oris r8,r8,MSR_VSX@h
1852 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1860 li r6,reg*16+VCPU_VSRS
1868 stfd reg,reg*8+VCPU_FPRS(r3)
1872 ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX)
1875 stfd fr0,VCPU_FPSCR(r3)
1877 #ifdef CONFIG_ALTIVEC
1881 li r6,reg*16+VCPU_VRS
1888 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1890 mfspr r6,SPRN_VRSAVE
1891 stw r6,VCPU_VRSAVE(r3)
1897 * Load up FP, VMX and VSX registers
1900 .globl kvmppc_load_fp
1904 #ifdef CONFIG_ALTIVEC
1906 oris r8,r8,MSR_VEC@h
1907 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1911 oris r8,r8,MSR_VSX@h
1912 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1916 lfd fr0,VCPU_FPSCR(r4)
1922 li r7,reg*16+VCPU_VSRS
1930 lfd reg,reg*8+VCPU_FPRS(r4)
1934 ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX)
1937 #ifdef CONFIG_ALTIVEC
1944 li r7,reg*16+VCPU_VRS
1948 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1950 lwz r7,VCPU_VRSAVE(r4)
1951 mtspr SPRN_VRSAVE,r7