From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Evans Subject: [PATCH V4 7/7] kvm tools: Add PPC64 kvm_cpu__emulate_io() Date: Tue, 31 Jan 2012 17:34:42 +1100 Message-ID: <1327991682-18503-8-git-send-email-matt@ozlabs.org> References: <1327991682-18503-1-git-send-email-matt@ozlabs.org> Cc: penberg@kernel.org, asias.hejun@gmail.com, levinsasha928@gmail.com, gorcunov@gmail.com, david@gibson.dropbear.id.au, aik@ozlabs.ru To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Return-path: Received: from ozlabs.org ([203.10.76.45]:36337 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752027Ab2AaGfQ (ORCPT ); Tue, 31 Jan 2012 01:35:16 -0500 In-Reply-To: <1327991682-18503-1-git-send-email-matt@ozlabs.org> Sender: kvm-owner@vger.kernel.org List-ID: This is the final piece of the puzzle for PPC SPAPR PCI; this function splits MMIO accesses into the two PHB windows & directs things to MMIO/IO emulation as appropriate. Signed-off-by: Matt Evans --- tools/kvm/Makefile | 1 + tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h | 10 +++++++++- tools/kvm/powerpc/kvm-cpu.c | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletions(-) diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 2d97b66..332b374 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -137,6 +137,7 @@ ifeq ($(uname_M), ppc64) OBJS += powerpc/spapr_hcall.o OBJS += powerpc/spapr_rtas.o OBJS += powerpc/spapr_hvcons.o + OBJS += powerpc/spapr_pci.o OBJS += powerpc/xics.o # We use libfdt, but it's sometimes not packaged 64bit. It's small too, # so just build it in: diff --git a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h index c1c6539..7520c04 100644 --- a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h +++ b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h @@ -14,7 +14,7 @@ /* Architecture-specific kvm_cpu definitions. */ #include /* for struct kvm_regs */ - +#include #include #define MSR_SF (1UL<<63) @@ -65,4 +65,12 @@ struct kvm_cpu { void kvm_cpu__irq(struct kvm_cpu *vcpu, int pin, int level); +/* This is never actually called on PPC. */ +static inline bool kvm_cpu__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int size, u32 count) +{ + return false; +} + +bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, u8 is_write); + #endif /* KVM__KVM_CPU_ARCH_H */ diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c index 7dd1679..2505c69 100644 --- a/tools/kvm/powerpc/kvm-cpu.c +++ b/tools/kvm/powerpc/kvm-cpu.c @@ -15,6 +15,7 @@ #include "kvm/kvm.h" #include "spapr.h" +#include "spapr_pci.h" #include "xics.h" #include @@ -24,6 +25,7 @@ #include #include #include +#include static int debug_fd; @@ -192,6 +194,26 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu) return ret; } +bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, u8 is_write) +{ + /* + * FIXME: This function will need to be split in order to support + * various PowerPC platforms/PHB types, etc. It currently assumes SPAPR + * PPC64 guest. + */ + bool ret = false; + + if ((phys_addr >= SPAPR_PCI_WIN_START) && + (phys_addr < SPAPR_PCI_WIN_END)) { + ret = spapr_phb_mmio(kvm, phys_addr, data, len, is_write); + } else { + pr_warning("MMIO %s unknown address %llx (size %d)!\n", + is_write ? "write to" : "read from", + phys_addr, len); + } + return ret; +} + #define CONDSTR_BIT(m, b) (((m) & MSR_##b) ? #b" " : "") void kvm_cpu__show_registers(struct kvm_cpu *vcpu) -- 1.7.0.4