From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Evans Subject: [PATCH 7/8] kvm tools: Add PPC64 kvm_cpu__emulate_io() Date: Tue, 06 Dec 2011 15:06:50 +1100 Message-ID: <4EDD94DA.8050402@ozlabs.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Return-path: In-Reply-To: Sender: kvm-ppc-owner@vger.kernel.org List-Id: kvm.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(-) 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)