From patchwork Tue Jan 31 06:34:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Evans X-Patchwork-Id: 138694 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 78B631007D4 for ; Tue, 31 Jan 2012 17:35:25 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752147Ab2AaGfT (ORCPT ); Tue, 31 Jan 2012 01:35:19 -0500 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 Received: from localhost.localdomain (unknown [165.228.126.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPSA id D53F11007DA; Tue, 31 Jan 2012 17:35:14 +1100 (EST) From: Matt Evans To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: penberg@kernel.org, asias.hejun@gmail.com, levinsasha928@gmail.com, gorcunov@gmail.com, david@gibson.dropbear.id.au, aik@ozlabs.ru 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> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1327991682-18503-1-git-send-email-matt@ozlabs.org> References: <1327991682-18503-1-git-send-email-matt@ozlabs.org> Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org 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)