@@ -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
@@ -14,7 +14,7 @@
/* Architecture-specific kvm_cpu definitions. */
#include <linux/kvm.h> /* for struct kvm_regs */
-
+#include <stdbool.h>
#include <pthread.h>
#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 */
@@ -24,6 +24,7 @@
#include <string.h>
#include <errno.h>
#include <stdio.h>
+#include <assert.h>
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)
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/include/kvm/kvm-cpu-arch.h | 10 ++++++++- tools/kvm/powerpc/kvm-cpu.c | 29 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletions(-)