From: Matt Evans <matt@ozlabs.org>
To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org
Subject: [PATCH 7/8] kvm tools: Add PPC64 kvm_cpu__emulate_io()
Date: Tue, 06 Dec 2011 15:06:50 +1100 [thread overview]
Message-ID: <4EDD94DA.8050402@ozlabs.org> (raw)
In-Reply-To: <cover.1323143103.git.matt@ozlabs.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 <matt@ozlabs.org>
---
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 <string.h>
#include <errno.h>
#include <stdio.h>
+#include <assert.h>
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)
next prev parent reply other threads:[~2011-12-06 4:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1323143103.git.matt@ozlabs.org>
2011-12-06 4:05 ` [PATCH 1/8] kvm tools: Add initial SPAPR PPC64 architecture support Matt Evans
2011-12-06 18:03 ` Scott Wood
2011-12-06 18:33 ` Pekka Enberg
2011-12-06 18:54 ` Scott Wood
2011-12-07 7:35 ` Matt Evans
2011-12-07 18:31 ` Scott Wood
2011-12-08 2:57 ` Matt Evans
2011-12-06 4:06 ` [PATCH 2/8] kvm tools: Generate SPAPR PPC64 guest device tree Matt Evans
2011-12-06 4:06 ` [PATCH 3/8] kvm tools: Add SPAPR PPC64 hcall & rtascall structure Matt Evans
2011-12-06 4:06 ` [PATCH 4/8] kvm tools: Add SPAPR PPC64 HV console Matt Evans
2011-12-06 4:06 ` [PATCH 5/8] kvm tools: Add PPC64 XICS interrupt controller support Matt Evans
2011-12-06 4:06 ` [PATCH 6/8] kvm tools: Add PPC64 PCI Host Bridge Matt Evans
2011-12-06 4:06 ` Matt Evans [this message]
2011-12-06 4:06 ` [PATCH 8/8] kvm tools: Make virtio-pci's ioeventfd__add_event() fall back gracefully if ioeventfds unavailable Matt Evans
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4EDD94DA.8050402@ozlabs.org \
--to=matt@ozlabs.org \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).