KVM: ppc: refactor instruction emulation into generic
Subsystems (2)
PATCH 1/1 KVM: ppc: refactor instruction emulation into generic
# HG changeset patch
# User Hollis Blanchard <[email protected]>
# Date 1222712603 18000
# Node ID 9f2cbab6da565d34560099911f97e66c1249525f
# Parent ff91d7d926813fe9ad9aa0f5c6aec7821ae3bbb7
KVM: ppc: refactor instruction emulation into generic and core-specific pieces
Cores provide 3 emulation hooks, implemented for example in the new 4xx_emulate.c:kvmppc_core_emulate_opkvmppc_core_emulate_mtsprkvmppc_core_emulate_mfspr
Strictly speaking the last two aren't necessary, but provide for more informative error reporting ("unknown SPR").
Long term I'd like to have instruction decoding autogenerated from tables of opcodes, and that way we could aggregate universal, Book E, and core-specific instructions more easily and without redundant switch statements.
arch/powerpc/include/asm/kvm_ppc.h +6 -23
@@ -53,34 +53,12 @@ extern int kvmppc_emulate_instruction(stextern int kvmppc_emulate_instruction (struct kvm_run *run,struct kvm_vcpu *vcpu);extern int kvmppc_emulate_mmio (struct kvm_run *run,struct kvm_vcpu *vcpu); -extern int kvmppc_emul_tlbwe (struct kvm_vcpu *vcpu,u8 ra,u8 rs,u8 ws); -extern int kvmppc_emul_tlbsx (struct kvm_vcpu *vcpu,u8 rt,u8 ra,u8 rb,u8 rc); +extern void kvmppc_emulate_dec (struct kvm_vcpu *vcpu);extern void kvmppc_mmu_map (struct kvm_vcpu *vcpu,u64 gvaddr,gfn_t gfn,u64 asid,u32 flags);extern void kvmppc_mmu_priv_switch (struct kvm_vcpu *vcpu,int usermode);extern void kvmppc_mmu_switch_pid (struct kvm_vcpu *vcpu,u32 pid); - -/* Helper function for "full" MSR writes. No need to call this if only EE is -* changing. */ -static inline void kvmppc_set_msr (struct kvm_vcpu *vcpu,u32 new_msr) -{ -if ((new_msr &MSR_PR ) != (vcpu->arch.msr &MSR_PR )) -kvmppc_mmu_priv_switch (vcpu, new_msr &MSR_PR ); - - vcpu->arch.msr = new_msr; - -if (vcpu->arch.msr &MSR_WE ) -kvm_vcpu_block (vcpu); -} - -static inline void kvmppc_set_pid (struct kvm_vcpu *vcpu,u32 new_pid) -{ -if (vcpu->arch.pid != new_pid) { - vcpu->arch.pid = new_pid; - vcpu->arch.swap_pid =1 ; - } -}/* Core-specific hooks */
@@ -99,4 +77,9 @@ extern void kvmppc_core_queue_external(sextern void kvmppc_core_queue_external (struct kvm_vcpu *vcpu,struct kvm_interrupt *irq); +extern int kvmppc_core_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int op,int *advance); +extern int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,int rs); +extern int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,int rt); +#endif /* __POWERPC_KVM_PPC_H__ */
arch/powerpc/kvm/44x_emulate.c new file +335 -0
335 lines not on this page · raw message
arch/powerpc/kvm/44x_tlb.c +2 -2
@@ -301,7 +301,7 @@ static int tlbe_is_host_safe(const strucreturn 1 ; } -int kvmppc_emul_tlbwe (struct kvm_vcpu *vcpu,u8 ra,u8 rs,u8 ws) +int kvm44x_emul_tlbwe (struct kvm_vcpu *vcpu,u8 ra,u8 rs,u8 ws) {u64 eaddr;u64 raddr;
@@ -363,7 +363,7 @@ int kvmppc_emul_tlbwe(struct kvm_vcpu *vreturn EMULATE_DONE ; } -int kvmppc_emul_tlbsx (struct kvm_vcpu *vcpu,u8 rt,u8 ra,u8 rb,u8 rc) +int kvm44x_emul_tlbsx (struct kvm_vcpu *vcpu,u8 rt,u8 ra,u8 rb,u8 rc) {u32 ea;int index;
arch/powerpc/kvm/44x_tlb.h +3 -0
@@ -30,6 +30,9 @@ extern struct kvmppc_44x_tlbe *kvmppc_44extern struct kvmppc_44x_tlbe *kvmppc_44x_itlb_search (struct kvm_vcpu *vcpu,gva_t eaddr);extern void kvmppc_tlbe_set_modified (struct kvm_vcpu *vcpu,unsigned int i); + +extern int kvm44x_emul_tlbsx (struct kvm_vcpu *vcpu,u8 rt,u8 ra,u8 rb,u8 rc); +extern int kvm44x_emul_tlbwe (struct kvm_vcpu *vcpu,u8 ra,u8 rs,u8 ws);/* TLB helper functions */ static inline unsigned int get_tlb_size (const struct kvmppc_44x_tlbe *tlbe)
arch/powerpc/kvm/Makefile +6 -1
@@ -13,5 +13,10 @@ obj-$(CONFIG_KVM) += kvm.o AFLAGS_booke_interrupts.o := -I$(obj) -kvm-440-objs := booke.o booke_interrupts.o 44x.o 44x_tlb.o +kvm-440-objs := \ + booke.o \ + booke_interrupts.o \ + 44x.o \ + 44x_tlb.o \ + 44x_emulate.o obj-$(CONFIG_KVM_440) += kvm-440.o
arch/powerpc/kvm/booke.c +1 -0
@@ -29,6 +29,7 @@#include <asm/kvm_ppc.h> #include <asm/cacheflush.h> +#include "booke.h" #include "44x_tlb.h" unsigned long kvmppc_booke_handlers;
arch/powerpc/kvm/booke.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* Copyright IBM Corp. 2008 +* +* Authors: Hollis Blanchard <[email protected]> +*/ + +#ifndef __KVM_BOOKE_H__ +#define __KVM_BOOKE_H__ + +#include <linux/types.h> +#include <linux/kvm_host.h> + +/* Helper function for "full" MSR writes. No need to call this if only EE is +* changing. */ +static inline void kvmppc_set_msr (struct kvm_vcpu *vcpu,u32 new_msr) +{ +if ((new_msr &MSR_PR ) != (vcpu->arch.msr &MSR_PR )) +kvmppc_mmu_priv_switch (vcpu, new_msr &MSR_PR ); + + vcpu->arch.msr = new_msr; + +if (vcpu->arch.msr &MSR_WE ) +kvm_vcpu_block (vcpu); +} + +#endif /* __KVM_BOOKE_H__ */
arch/powerpc/kvm/emulate.c +20 -250
390 lines not on this page · raw message