From patchwork Tue Dec 13 07:10:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Evans X-Patchwork-Id: 131027 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 7203D1007D3 for ; Tue, 13 Dec 2011 18:10:23 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753454Ab1LMHKP (ORCPT ); Tue, 13 Dec 2011 02:10:15 -0500 Received: from ozlabs.org ([203.10.76.45]:52831 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751521Ab1LMHKO (ORCPT ); Tue, 13 Dec 2011 02:10:14 -0500 Received: from localhost.localdomain (ibmaus65.lnk.telstra.net [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 194351007D6; Tue, 13 Dec 2011 18:10:13 +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 V2 6/6] kvm tools: Add PPC64 kvm_cpu__emulate_io() Date: Tue, 13 Dec 2011 18:10:50 +1100 Message-Id: <1323760250-13237-7-git-send-email-matt@ozlabs.org> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1323760250-13237-1-git-send-email-matt@ozlabs.org> References: <1323760250-13237-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 | 29 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletions(-) diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 0d42acf..6f3485b 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -134,6 +134,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 ARCH_INCLUDE := powerpc/include CFLAGS += -m64 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 5ef1cbf..4da4990 100644 --- a/tools/kvm/powerpc/kvm-cpu.c +++ b/tools/kvm/powerpc/kvm-cpu.c @@ -24,6 +24,7 @@ #include #include #include +#include static int debug_fd; @@ -173,6 +174,34 @@ 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_IO_WIN_ADDR) && + (phys_addr < SPAPR_PCI_IO_WIN_ADDR + SPAPR_PCI_IO_WIN_SIZE)) { + ret = kvm__emulate_io(kvm, phys_addr - SPAPR_PCI_IO_WIN_ADDR, + data, is_write ? KVM_EXIT_IO_OUT : + KVM_EXIT_IO_IN, + len, 1); + } else if ((phys_addr >= SPAPR_PCI_MEM_WIN_ADDR) && + (phys_addr < SPAPR_PCI_MEM_WIN_ADDR + + SPAPR_PCI_MEM_WIN_SIZE)) { + ret = kvm__emulate_mmio(kvm, phys_addr - SPAPR_PCI_MEM_WIN_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)