Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright SUSE Linux Products GmbH 2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2010-2011 Freescale Semiconductor, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Authors: Alexander Graf <agraf@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <asm/ppc_asm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <asm/kvm_asm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/reg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/asm-offsets.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/asm-compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define KVM_MAGIC_PAGE		(-4096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define LL64(reg, offs, reg2)	ld	reg, (offs)(reg2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define STL64(reg, offs, reg2)	std	reg, (offs)(reg2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define LL64(reg, offs, reg2)	lwz	reg, (offs + 4)(reg2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define STL64(reg, offs, reg2)	stw	reg, (offs + 4)(reg2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define SCRATCH_SAVE							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	/* Enable critical section. We are critical if			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	   shared->critical == r1 */					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	STL64(r1, KVM_MAGIC_PAGE + KVM_MAGIC_CRITICAL, 0);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	/* Save state */						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	PPC_STL	r31, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH1)(0);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	PPC_STL	r30, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH2)(0);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	mfcr	r31;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	stw	r31, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH3)(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define SCRATCH_RESTORE							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	/* Restore state */						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	PPC_LL	r31, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH1)(0);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	lwz	r30, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH3)(0);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	mtcr	r30;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	PPC_LL	r30, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH2)(0);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	/* Disable critical section. We are critical if			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	   shared->critical == r1 and r2 is always != r1 */		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	STL64(r2, KVM_MAGIC_PAGE + KVM_MAGIC_CRITICAL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) .global kvm_template_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) kvm_template_start:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) .global kvm_emulate_mtmsrd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) kvm_emulate_mtmsrd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	SCRATCH_SAVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	/* Put MSR & ~(MSR_EE|MSR_RI) in r31 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	LL64(r31, KVM_MAGIC_PAGE + KVM_MAGIC_MSR, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	lis	r30, (~(MSR_EE | MSR_RI))@h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	ori	r30, r30, (~(MSR_EE | MSR_RI))@l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	and	r31, r31, r30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	/* OR the register's (MSR_EE|MSR_RI) on MSR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) kvm_emulate_mtmsrd_reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	ori	r30, r0, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	andi.	r30, r30, (MSR_EE|MSR_RI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	or	r31, r31, r30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	/* Put MSR back into magic page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	STL64(r31, KVM_MAGIC_PAGE + KVM_MAGIC_MSR, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	/* Check if we have to fetch an interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	lwz	r31, (KVM_MAGIC_PAGE + KVM_MAGIC_INT)(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	cmpwi	r31, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	beq+	no_check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	/* Check if we may trigger an interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	andi.	r30, r30, MSR_EE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	beq	no_check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	SCRATCH_RESTORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/* Nag hypervisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) kvm_emulate_mtmsrd_orig_ins:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	tlbsync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	b	kvm_emulate_mtmsrd_branch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) no_check:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	SCRATCH_RESTORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	/* Go back to caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) kvm_emulate_mtmsrd_branch:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	b	.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) kvm_emulate_mtmsrd_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) .global kvm_emulate_mtmsrd_branch_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) kvm_emulate_mtmsrd_branch_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	.long (kvm_emulate_mtmsrd_branch - kvm_emulate_mtmsrd) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .global kvm_emulate_mtmsrd_reg_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) kvm_emulate_mtmsrd_reg_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	.long (kvm_emulate_mtmsrd_reg - kvm_emulate_mtmsrd) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .global kvm_emulate_mtmsrd_orig_ins_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) kvm_emulate_mtmsrd_orig_ins_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	.long (kvm_emulate_mtmsrd_orig_ins - kvm_emulate_mtmsrd) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .global kvm_emulate_mtmsrd_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) kvm_emulate_mtmsrd_len:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	.long (kvm_emulate_mtmsrd_end - kvm_emulate_mtmsrd) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define MSR_SAFE_BITS (MSR_EE | MSR_RI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define MSR_CRITICAL_BITS ~MSR_SAFE_BITS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .global kvm_emulate_mtmsr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) kvm_emulate_mtmsr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	SCRATCH_SAVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	/* Fetch old MSR in r31 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	LL64(r31, KVM_MAGIC_PAGE + KVM_MAGIC_MSR, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	/* Find the changed bits between old and new MSR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) kvm_emulate_mtmsr_reg1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	ori	r30, r0, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	xor	r31, r30, r31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	/* Check if we need to really do mtmsr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	LOAD_REG_IMMEDIATE(r30, MSR_CRITICAL_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	and.	r31, r31, r30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/* No critical bits changed? Maybe we can stay in the guest. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	beq	maybe_stay_in_guest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) do_mtmsr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	SCRATCH_RESTORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	/* Just fire off the mtmsr if it's critical */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) kvm_emulate_mtmsr_orig_ins:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	mtmsr	r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	b	kvm_emulate_mtmsr_branch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) maybe_stay_in_guest:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	/* Get the target register in r30 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) kvm_emulate_mtmsr_reg2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	ori	r30, r0, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	/* Put MSR into magic page because we don't call mtmsr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	STL64(r30, KVM_MAGIC_PAGE + KVM_MAGIC_MSR, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/* Check if we have to fetch an interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	lwz	r31, (KVM_MAGIC_PAGE + KVM_MAGIC_INT)(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	cmpwi	r31, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	beq+	no_mtmsr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* Check if we may trigger an interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	andi.	r31, r30, MSR_EE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	bne	do_mtmsr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) no_mtmsr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	SCRATCH_RESTORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	/* Go back to caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) kvm_emulate_mtmsr_branch:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	b	.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) kvm_emulate_mtmsr_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) .global kvm_emulate_mtmsr_branch_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) kvm_emulate_mtmsr_branch_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	.long (kvm_emulate_mtmsr_branch - kvm_emulate_mtmsr) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) .global kvm_emulate_mtmsr_reg1_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) kvm_emulate_mtmsr_reg1_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	.long (kvm_emulate_mtmsr_reg1 - kvm_emulate_mtmsr) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .global kvm_emulate_mtmsr_reg2_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) kvm_emulate_mtmsr_reg2_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	.long (kvm_emulate_mtmsr_reg2 - kvm_emulate_mtmsr) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) .global kvm_emulate_mtmsr_orig_ins_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) kvm_emulate_mtmsr_orig_ins_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	.long (kvm_emulate_mtmsr_orig_ins - kvm_emulate_mtmsr) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) .global kvm_emulate_mtmsr_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) kvm_emulate_mtmsr_len:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	.long (kvm_emulate_mtmsr_end - kvm_emulate_mtmsr) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #ifdef CONFIG_BOOKE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* also used for wrteei 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .global kvm_emulate_wrtee
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) kvm_emulate_wrtee:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	SCRATCH_SAVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	/* Fetch old MSR in r31 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	LL64(r31, KVM_MAGIC_PAGE + KVM_MAGIC_MSR, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	/* Insert new MSR[EE] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) kvm_emulate_wrtee_reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	ori	r30, r0, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	rlwimi	r31, r30, 0, MSR_EE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	 * If MSR[EE] is now set, check for a pending interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	 * We could skip this if MSR[EE] was already on, but that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	 * should be rare, so don't bother.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	andi.	r30, r30, MSR_EE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	/* Put MSR into magic page because we don't call wrtee */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	STL64(r31, KVM_MAGIC_PAGE + KVM_MAGIC_MSR, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	beq	no_wrtee
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	/* Check if we have to fetch an interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	lwz	r30, (KVM_MAGIC_PAGE + KVM_MAGIC_INT)(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	cmpwi	r30, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	bne	do_wrtee
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) no_wrtee:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	SCRATCH_RESTORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	/* Go back to caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) kvm_emulate_wrtee_branch:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	b	.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) do_wrtee:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	SCRATCH_RESTORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* Just fire off the wrtee if it's critical */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) kvm_emulate_wrtee_orig_ins:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	wrtee	r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	b	kvm_emulate_wrtee_branch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) kvm_emulate_wrtee_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .global kvm_emulate_wrtee_branch_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) kvm_emulate_wrtee_branch_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	.long (kvm_emulate_wrtee_branch - kvm_emulate_wrtee) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .global kvm_emulate_wrtee_reg_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) kvm_emulate_wrtee_reg_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	.long (kvm_emulate_wrtee_reg - kvm_emulate_wrtee) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) .global kvm_emulate_wrtee_orig_ins_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) kvm_emulate_wrtee_orig_ins_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	.long (kvm_emulate_wrtee_orig_ins - kvm_emulate_wrtee) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) .global kvm_emulate_wrtee_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) kvm_emulate_wrtee_len:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	.long (kvm_emulate_wrtee_end - kvm_emulate_wrtee) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) .global kvm_emulate_wrteei_0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) kvm_emulate_wrteei_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	SCRATCH_SAVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	/* Fetch old MSR in r31 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	LL64(r31, KVM_MAGIC_PAGE + KVM_MAGIC_MSR, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	/* Remove MSR_EE from old MSR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	rlwinm	r31, r31, 0, ~MSR_EE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	/* Write new MSR value back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	STL64(r31, KVM_MAGIC_PAGE + KVM_MAGIC_MSR, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	SCRATCH_RESTORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	/* Go back to caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) kvm_emulate_wrteei_0_branch:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	b	.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) kvm_emulate_wrteei_0_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) .global kvm_emulate_wrteei_0_branch_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) kvm_emulate_wrteei_0_branch_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	.long (kvm_emulate_wrteei_0_branch - kvm_emulate_wrteei_0) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) .global kvm_emulate_wrteei_0_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) kvm_emulate_wrteei_0_len:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	.long (kvm_emulate_wrteei_0_end - kvm_emulate_wrteei_0) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #endif /* CONFIG_BOOKE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) #ifdef CONFIG_PPC_BOOK3S_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .global kvm_emulate_mtsrin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) kvm_emulate_mtsrin:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	SCRATCH_SAVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	LL64(r31, KVM_MAGIC_PAGE + KVM_MAGIC_MSR, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	andi.	r31, r31, MSR_DR | MSR_IR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	beq	kvm_emulate_mtsrin_reg1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	SCRATCH_RESTORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) kvm_emulate_mtsrin_orig_ins:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	b	kvm_emulate_mtsrin_branch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) kvm_emulate_mtsrin_reg1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	/* rX >> 26 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	rlwinm  r30,r0,6,26,29
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) kvm_emulate_mtsrin_reg2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	stw	r0, (KVM_MAGIC_PAGE + KVM_MAGIC_SR)(r30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	SCRATCH_RESTORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	/* Go back to caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) kvm_emulate_mtsrin_branch:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	b	.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) kvm_emulate_mtsrin_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .global kvm_emulate_mtsrin_branch_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) kvm_emulate_mtsrin_branch_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	.long (kvm_emulate_mtsrin_branch - kvm_emulate_mtsrin) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .global kvm_emulate_mtsrin_reg1_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) kvm_emulate_mtsrin_reg1_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	.long (kvm_emulate_mtsrin_reg1 - kvm_emulate_mtsrin) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) .global kvm_emulate_mtsrin_reg2_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) kvm_emulate_mtsrin_reg2_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	.long (kvm_emulate_mtsrin_reg2 - kvm_emulate_mtsrin) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) .global kvm_emulate_mtsrin_orig_ins_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) kvm_emulate_mtsrin_orig_ins_offs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	.long (kvm_emulate_mtsrin_orig_ins - kvm_emulate_mtsrin) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .global kvm_emulate_mtsrin_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) kvm_emulate_mtsrin_len:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	.long (kvm_emulate_mtsrin_end - kvm_emulate_mtsrin) / 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) #endif /* CONFIG_PPC_BOOK3S_32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	.balign 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	.global kvm_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) kvm_tmp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	.space	(64 * 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) .global kvm_tmp_end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) kvm_tmp_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) .global kvm_template_end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) kvm_template_end: