From patchwork Tue Dec 6 04:06: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: 129530 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 39C8F1007D5 for ; Tue, 6 Dec 2011 15:06:03 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932893Ab1LFEGB (ORCPT ); Mon, 5 Dec 2011 23:06:01 -0500 Received: from ozlabs.org ([203.10.76.45]:38560 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932877Ab1LFEGA (ORCPT ); Mon, 5 Dec 2011 23:06:00 -0500 Received: from [10.61.2.183] (ibmaus65.lnk.telstra.net [165.228.126.9]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPSA id 040571007D5; Tue, 6 Dec 2011 15:05:59 +1100 (EST) Message-ID: <4EDD94DA.8050402@ozlabs.org> Date: Tue, 06 Dec 2011 15:06:50 +1100 From: Matt Evans User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110921 Thunderbird/3.1.15 MIME-Version: 1.0 To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Subject: [PATCH 7/8] kvm tools: Add PPC64 kvm_cpu__emulate_io() References: In-Reply-To: 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/kvm-cpu.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 6ffffc8..9b875dd 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -131,6 +131,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/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c index 63cd106..0cf4dc8 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; @@ -177,6 +178,39 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu) return ret; } +bool kvm_cpu__emulate_io(struct kvm_cpu *cpu, struct kvm_run *kvm_run) +{ + bool ret = false; + u64 phys_addr; + + /* We'll never get KVM_EXIT_IO, it's x86-specific. All IO is MM! :P + * So, look at our windows here & split addresses into I/O or MMIO. + */ + assert(kvm_run->exit_reason == KVM_EXIT_MMIO); + + phys_addr = cpu->kvm_run->mmio.phys_addr; + if ((phys_addr >= SPAPR_PCI_IO_WIN_ADDR) && + (phys_addr < SPAPR_PCI_IO_WIN_ADDR + SPAPR_PCI_IO_WIN_SIZE)) { + ret = kvm__emulate_io(cpu->kvm, phys_addr - SPAPR_PCI_IO_WIN_ADDR, + cpu->kvm_run->mmio.data, + cpu->kvm_run->mmio.is_write ? + KVM_EXIT_IO_OUT : KVM_EXIT_IO_IN, + cpu->kvm_run->mmio.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(cpu->kvm, + cpu->kvm_run->mmio.phys_addr - SPAPR_PCI_MEM_WIN_ADDR, + cpu->kvm_run->mmio.data, + cpu->kvm_run->mmio.len, + cpu->kvm_run->mmio.is_write); + } else { + pr_warning("MMIO %s unknown address %lx (size %d)!\n", + cpu->kvm_run->mmio.is_write ? "write to" : "read from", + phys_addr, cpu->kvm_run->mmio.len); + } + return ret; +} + #define CONDSTR_BIT(m, b) (((m) & MSR_##b) ? #b" " : "") void kvm_cpu__show_registers(struct kvm_cpu *vcpu)