Whilst ARM neither needs or wants a complete x86 legacy ioport emulation,
the 8250 is a useful alternative to virtio-console, so carve out 64k at the
bottom of our virtual memory map where we can add ioports if we choose.

Signed-off-by: Will Deacon <will.dea...@arm.com>
---
 tools/kvm/arm/include/arm-common/kvm-arch.h | 12 ++++++++++--
 tools/kvm/arm/kvm-cpu.c                     |  9 +++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/tools/kvm/arm/include/arm-common/kvm-arch.h 
b/tools/kvm/arm/include/arm-common/kvm-arch.h
index 7860e17..03ead5b 100644
--- a/tools/kvm/arm/include/arm-common/kvm-arch.h
+++ b/tools/kvm/arm/include/arm-common/kvm-arch.h
@@ -5,7 +5,8 @@
 #include <linux/const.h>
 #include <linux/types.h>
 
-#define ARM_MMIO_AREA          _AC(0x0000000000000000, UL)
+#define ARM_IOPORT_AREA                _AC(0x0000000000000000, UL)
+#define ARM_MMIO_AREA          _AC(0x0000000000010000, UL)
 #define ARM_AXI_AREA           _AC(0x0000000040000000, UL)
 #define ARM_MEMORY_AREA                _AC(0x0000000080000000, UL)
 
@@ -16,7 +17,8 @@
 #define ARM_GIC_CPUI_BASE      (ARM_GIC_DIST_BASE - ARM_GIC_CPUI_SIZE)
 #define ARM_GIC_SIZE           (ARM_GIC_DIST_SIZE + ARM_GIC_CPUI_SIZE)
 
-#define ARM_VIRTIO_MMIO_SIZE   (ARM_AXI_AREA - ARM_GIC_SIZE)
+#define ARM_IOPORT_SIZE                (ARM_MMIO_AREA - ARM_IOPORT_AREA)
+#define ARM_VIRTIO_MMIO_SIZE   (ARM_AXI_AREA - (ARM_MMIO_AREA + ARM_GIC_SIZE))
 #define ARM_PCI_MMIO_SIZE      (ARM_MEMORY_AREA - ARM_AXI_AREA)
 
 #define KVM_PCI_MMIO_AREA      ARM_AXI_AREA
@@ -24,6 +26,12 @@
 
 #define VIRTIO_DEFAULT_TRANS   VIRTIO_MMIO
 
+static inline bool arm_addr_in_ioport_region(u64 phys_addr)
+{
+       u64 limit = ARM_IOPORT_AREA + ARM_IOPORT_SIZE;
+       return phys_addr >= ARM_IOPORT_AREA && phys_addr < limit;
+}
+
 static inline bool arm_addr_in_virtio_mmio_region(u64 phys_addr)
 {
        u64 limit = KVM_VIRTIO_MMIO_AREA + ARM_VIRTIO_MMIO_SIZE;
diff --git a/tools/kvm/arm/kvm-cpu.c b/tools/kvm/arm/kvm-cpu.c
index 6d4f306..d31e7b1 100644
--- a/tools/kvm/arm/kvm-cpu.c
+++ b/tools/kvm/arm/kvm-cpu.c
@@ -101,10 +101,15 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)
 bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len,
                           u8 is_write)
 {
-       if (arm_addr_in_virtio_mmio_region(phys_addr))
+       if (arm_addr_in_virtio_mmio_region(phys_addr)) {
                return kvm__emulate_mmio(kvm, phys_addr, data, len, is_write);
-       else if (arm_addr_in_pci_mmio_region(phys_addr))
+       } else if (arm_addr_in_ioport_region(phys_addr)) {
+               int direction = is_write ? KVM_EXIT_IO_OUT : KVM_EXIT_IO_IN;
+               u16 port = phys_addr & USHRT_MAX;
+               return kvm__emulate_io(kvm, port, data, direction, len, 1);
+       } else if (arm_addr_in_pci_mmio_region(phys_addr)) {
                die("PCI emulation not supported on ARM!");
+       }
 
        return false;
 }
-- 
1.8.0

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to