From: Nikhil Devshatwar <[email protected]>

Add the iommu hooks for ARM and ARM64 architectures with
dummy implementations.
Update the Kbuild to include new iommu files

Introduce following hooks:
iommu_map_memory - Setup iommu mapping for the memory region
iommu_unmap_memory - Unmap the iommu mapping for the mem region
iommu_config_commit - Commit all the changes to the mem mapping

Call the map/unmap iommu functions in addition to CPU map/unmap and
config_commit.
Also add iommu_units in the platform data for ARM cells.

Signed-off-by: Nikhil Devshatwar <[email protected]>
Signed-off-by: Lokesh Vutla <[email protected]>
---
 hypervisor/arch/arm-common/Kbuild             |  2 +-
 hypervisor/arch/arm-common/control.c          |  6 ++++
 .../arch/arm-common/include/asm/iommu.h       | 26 +++++++++++++++
 hypervisor/arch/arm-common/iommu.c            | 32 +++++++++++++++++++
 hypervisor/arch/arm-common/mmu_cell.c         | 25 +++++++++++++++
 hypervisor/include/jailhouse/control.h        |  1 +
 hypervisor/setup.c                            |  2 +-
 include/jailhouse/cell-config.h               |  2 ++
 8 files changed, 94 insertions(+), 2 deletions(-)
 create mode 100644 hypervisor/arch/arm-common/include/asm/iommu.h
 create mode 100644 hypervisor/arch/arm-common/iommu.c

diff --git a/hypervisor/arch/arm-common/Kbuild 
b/hypervisor/arch/arm-common/Kbuild
index 78b9e512..6f57ef02 100644
--- a/hypervisor/arch/arm-common/Kbuild
+++ b/hypervisor/arch/arm-common/Kbuild
@@ -17,6 +17,6 @@ ccflags-$(CONFIG_JAILHOUSE_GCOV) += -fprofile-arcs 
-ftest-coverage
 objs-y += dbg-write.o lib.o psci.o control.o paging.o mmu_cell.o setup.o
 objs-y += irqchip.o pci.o ivshmem.o uart-pl011.o uart-xuartps.o uart-mvebu.o
 objs-y += uart-hscif.o uart-scifa.o uart-imx.o
-objs-y += gic-v2.o gic-v3.o smccc.o
+objs-y += gic-v2.o gic-v3.o smccc.o iommu.o
 
 common-objs-y = $(addprefix ../arm-common/,$(objs-y))
diff --git a/hypervisor/arch/arm-common/control.c 
b/hypervisor/arch/arm-common/control.c
index b59c05d6..d712b049 100644
--- a/hypervisor/arch/arm-common/control.c
+++ b/hypervisor/arch/arm-common/control.c
@@ -16,6 +16,7 @@
 #include <jailhouse/printk.h>
 #include <asm/control.h>
 #include <asm/psci.h>
+#include <asm/iommu.h>
 
 static void enter_cpu_off(struct public_per_cpu *cpu_public)
 {
@@ -208,7 +209,12 @@ void arch_flush_cell_vcpu_caches(struct cell *cell)
 
 void arch_config_commit(struct cell *cell_added_removed)
 {
+       u8 err;
+
        irqchip_config_commit(cell_added_removed);
+       err = iommu_config_commit(cell_added_removed);
+       if (err)
+               printk("WARNING: iommu_config_commit failed\n");
 }
 
 void __attribute__((noreturn)) arch_panic_stop(void)
diff --git a/hypervisor/arch/arm-common/include/asm/iommu.h 
b/hypervisor/arch/arm-common/include/asm/iommu.h
new file mode 100644
index 00000000..d33ec17c
--- /dev/null
+++ b/hypervisor/arch/arm-common/include/asm/iommu.h
@@ -0,0 +1,26 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) 2018 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors:
+ *  Nikhil Devshatwar <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#ifndef _JAILHOUSE_ASM_IOMMU_H
+#define _JAILHOUSE_ASM_IOMMU_H
+
+#include <jailhouse/types.h>
+#include <jailhouse/utils.h>
+#include <jailhouse/config.h>
+#include <jailhouse/cell-config.h>
+
+int iommu_map_memory_region(struct cell *cell,
+                           const struct jailhouse_memory *mem);
+int iommu_unmap_memory_region(struct cell *cell,
+                             const struct jailhouse_memory *mem);
+int iommu_config_commit(struct cell *cell);
+#endif
diff --git a/hypervisor/arch/arm-common/iommu.c 
b/hypervisor/arch/arm-common/iommu.c
new file mode 100644
index 00000000..5bc9e6a9
--- /dev/null
+++ b/hypervisor/arch/arm-common/iommu.c
@@ -0,0 +1,32 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) 2018 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors:
+ *  Nikhil Devshatwar <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <jailhouse/control.h>
+#include <jailhouse/config.h>
+#include <asm/iommu.h>
+
+int iommu_map_memory_region(struct cell *cell,
+                           const struct jailhouse_memory *mem)
+{
+       return 0;
+}
+
+int iommu_unmap_memory_region(struct cell *cell,
+                             const struct jailhouse_memory *mem)
+{
+       return 0;
+}
+
+int iommu_config_commit(struct cell *cell)
+{
+       return 0;
+}
diff --git a/hypervisor/arch/arm-common/mmu_cell.c 
b/hypervisor/arch/arm-common/mmu_cell.c
index 36a3016f..d51f92ca 100644
--- a/hypervisor/arch/arm-common/mmu_cell.c
+++ b/hypervisor/arch/arm-common/mmu_cell.c
@@ -15,12 +15,14 @@
 #include <jailhouse/printk.h>
 #include <asm/sysregs.h>
 #include <asm/control.h>
+#include <asm/iommu.h>
 
 int arch_map_memory_region(struct cell *cell,
                           const struct jailhouse_memory *mem)
 {
        u64 phys_start = mem->phys_start;
        u32 flags = PTE_FLAG_VALID | PTE_ACCESS_FLAG;
+       int err = 0;
 
        if (mem->flags & JAILHOUSE_MEM_READ)
                flags |= S2_PTE_ACCESS_RO;
@@ -37,6 +39,17 @@ int arch_map_memory_region(struct cell *cell,
                flags |= S2_PAGE_ACCESS_XN;
        */
 
+       /*
+        * Entire hypervisor memory is mapped to empty_page to avoid faults
+        * at the shutdown. We don't need this in the IOMMU mapping
+        * Skip mapping empty_page in the iommu mapping
+        */
+       if (mem->phys_start != paging_hvirt2phys(empty_page)) {
+               err = iommu_map_memory_region(cell, mem);
+               if (err)
+                       return err;
+       }
+
        return paging_create(&cell->arch.mm, phys_start, mem->size,
                             mem->virt_start, flags, PAGING_COHERENT);
 }
@@ -44,6 +57,18 @@ int arch_map_memory_region(struct cell *cell,
 int arch_unmap_memory_region(struct cell *cell,
                             const struct jailhouse_memory *mem)
 {
+       int err = 0;
+
+       /*
+        * empty_page is not mapped in the iommu
+        * Skip all the calls to unmap as well
+        */
+       if (mem->phys_start != paging_hvirt2phys(empty_page)) {
+               err = iommu_unmap_memory_region(cell, mem);
+               if (err)
+                       return err;
+       }
+
        return paging_destroy(&cell->arch.mm, mem->virt_start, mem->size,
                              PAGING_COHERENT);
 }
diff --git a/hypervisor/include/jailhouse/control.h 
b/hypervisor/include/jailhouse/control.h
index 72518f6a..43dee950 100644
--- a/hypervisor/include/jailhouse/control.h
+++ b/hypervisor/include/jailhouse/control.h
@@ -20,6 +20,7 @@
 
 extern volatile unsigned long panic_in_progress;
 extern unsigned long panic_cpu;
+extern const u8 empty_page[PAGE_SIZE];
 
 /**
  * @defgroup Control Control Subsystem
diff --git a/hypervisor/setup.c b/hypervisor/setup.c
index 99a2b0c3..e3b1b3c8 100644
--- a/hypervisor/setup.c
+++ b/hypervisor/setup.c
@@ -24,7 +24,7 @@
 
 extern u8 __text_start[], __page_pool[];
 
-static const __attribute__((aligned(PAGE_SIZE))) u8 empty_page[PAGE_SIZE];
+const __attribute__((aligned(PAGE_SIZE))) u8 empty_page[PAGE_SIZE];
 
 static DEFINE_SPINLOCK(init_lock);
 static unsigned int master_cpu_id = -1;
diff --git a/include/jailhouse/cell-config.h b/include/jailhouse/cell-config.h
index 781aac88..c988f7c5 100644
--- a/include/jailhouse/cell-config.h
+++ b/include/jailhouse/cell-config.h
@@ -258,6 +258,8 @@ struct jailhouse_system {
                                u64 gich_base;
                                u64 gicv_base;
                                u64 gicr_base;
+                               struct jailhouse_iommu
+                                       iommu_units[JAILHOUSE_MAX_IOMMU_UNITS];
                        } __attribute__((packed)) arm;
                } __attribute__((packed));
        } __attribute__((packed)) platform_info;
-- 
2.17.1

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/20190705144225.7126-3-p-yadav1%40ti.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to