Path: blob/master/arch/powerpc/kvm/book3s_hv_interrupts.S
26451 views
/* SPDX-License-Identifier: GPL-2.0-only */1/*2*3* Copyright 2011 Paul Mackerras, IBM Corp. <[email protected]>4*5* Derived from book3s_interrupts.S, which is:6* Copyright SUSE Linux Products GmbH 20097*8* Authors: Alexander Graf <[email protected]>9*/1011#include <linux/linkage.h>12#include <asm/ppc_asm.h>13#include <asm/kvm_asm.h>14#include <asm/reg.h>15#include <asm/page.h>16#include <asm/asm-offsets.h>17#include <asm/exception-64s.h>18#include <asm/ppc-opcode.h>19#include <asm/asm-compat.h>20#include <asm/feature-fixups.h>2122/*****************************************************************************23* *24* Guest entry / exit code that is in kernel module memory (vmalloc) *25* *26****************************************************************************/2728/* Registers:29* none30*/31_GLOBAL(__kvmppc_vcore_entry)3233/* Write correct stack frame */34mflr r035std r0,PPC_LR_STKOFF(r1)3637/* Save host state to the stack */38stdu r1, -SWITCH_FRAME_SIZE(r1)3940/* Save non-volatile registers (r14 - r31) and CR */41SAVE_NVGPRS(r1)42mfcr r343std r3, _CCR(r1)4445/* Save host DSCR */46mfspr r3, SPRN_DSCR47std r3, HSTATE_DSCR(r13)4849BEGIN_FTR_SECTION50/* Save host DABR */51mfspr r3, SPRN_DABR52std r3, HSTATE_DABR(r13)53END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)5455/* Save host PMU registers */56bl kvmhv_save_host_pmu5758/*59* Put whatever is in the decrementer into the60* hypervisor decrementer.61* Because of a hardware deviation in P8,62* we need to set LPCR[HDICE] before writing HDEC.63*/64ld r5, HSTATE_KVM_VCORE(r13)65ld r6, VCORE_KVM(r5)66ld r9, KVM_HOST_LPCR(r6)67ori r8, r9, LPCR_HDICE68mtspr SPRN_LPCR, r869isync70mfspr r8,SPRN_DEC71mftb r772extsw r8,r873mtspr SPRN_HDEC,r874add r8,r8,r775std r8,HSTATE_DECEXP(r13)7677/* Jump to partition switch code */78bl kvmppc_hv_entry_trampoline79nop8081/*82* We return here in virtual mode after the guest exits83* with something that we can't handle in real mode.84* Interrupts are still hard-disabled.85*/8687/*88* Register usage at this point:89*90* R1 = host R191* R2 = host R292* R3 = trap number on this thread93* R12 = exit handler id94* R13 = PACA95*/9697/* Restore non-volatile host registers (r14 - r31) and CR */98REST_NVGPRS(r1)99ld r4, _CCR(r1)100mtcr r4101102addi r1, r1, SWITCH_FRAME_SIZE103ld r0, PPC_LR_STKOFF(r1)104mtlr r0105blr106107/*108* void kvmhv_save_host_pmu(void)109*/110SYM_FUNC_START_LOCAL(kvmhv_save_host_pmu)111BEGIN_FTR_SECTION112/* Work around P8 PMAE bug */113li r3, -1114clrrdi r3, r3, 10115mfspr r8, SPRN_MMCR2116mtspr SPRN_MMCR2, r3 /* freeze all counters using MMCR2 */117isync118END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)119li r3, 1120sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */121mfspr r7, SPRN_MMCR0 /* save MMCR0 */122mtspr SPRN_MMCR0, r3 /* freeze all counters, disable interrupts */123mfspr r6, SPRN_MMCRA124/* Clear MMCRA in order to disable SDAR updates */125li r5, 0126mtspr SPRN_MMCRA, r5127isync128lbz r5, PACA_PMCINUSE(r13) /* is the host using the PMU? */129cmpwi r5, 0130beq 31f /* skip if not */131mfspr r5, SPRN_MMCR1132mfspr r9, SPRN_SIAR133mfspr r10, SPRN_SDAR134std r7, HSTATE_MMCR0(r13)135std r5, HSTATE_MMCR1(r13)136std r6, HSTATE_MMCRA(r13)137std r9, HSTATE_SIAR(r13)138std r10, HSTATE_SDAR(r13)139BEGIN_FTR_SECTION140mfspr r9, SPRN_SIER141std r8, HSTATE_MMCR2(r13)142std r9, HSTATE_SIER(r13)143END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)144mfspr r3, SPRN_PMC1145mfspr r5, SPRN_PMC2146mfspr r6, SPRN_PMC3147mfspr r7, SPRN_PMC4148mfspr r8, SPRN_PMC5149mfspr r9, SPRN_PMC6150stw r3, HSTATE_PMC1(r13)151stw r5, HSTATE_PMC2(r13)152stw r6, HSTATE_PMC3(r13)153stw r7, HSTATE_PMC4(r13)154stw r8, HSTATE_PMC5(r13)155stw r9, HSTATE_PMC6(r13)15631: blr157SYM_FUNC_END(kvmhv_save_host_pmu)158159160