vspace: extend map object to io and ept structures
This will allow the same code to be used irrespective of the type of
paging structions used
diff --git a/libsel4vspace/include/vspace/mapping.h b/libsel4vspace/include/vspace/mapping.h
index 8d2e206..a1063c4 100644
--- a/libsel4vspace/include/vspace/mapping.h
+++ b/libsel4vspace/include/vspace/mapping.h
@@ -42,6 +42,8 @@
vspace_map_fn_t map_fn;
} vspace_map_obj_t;
+typedef int (*vspace_get_map_obj_fn)(seL4_Word failed_bits, vspace_map_obj_t *obj);
+
/*
* Populate a map object for a specific number of failed bits.
*
@@ -51,6 +53,10 @@
* @return 0 on success, EINVAL if failed_bits is invalid.
*/
int vspace_get_map_obj(seL4_Word failed_bits, vspace_map_obj_t *obj);
+/* As per vspace_get_map_obj but returns operations and sizes for an iospace (IOMMU). */
+int vspace_get_iospace_map_obj(UNUSED seL4_Word failed_bits, vspace_map_obj_t *obj);
+/* As per vspace_get_map_obj but returns operations and sizes for virtual page tables */
+int vspace_get_ept_map_obj(seL4_Word failed_bits, vspace_map_obj_t *obj);
static inline seL4_Error vspace_map_obj(vspace_map_obj_t *obj, seL4_CPtr cap,
seL4_CPtr vspace, seL4_Word vaddr, seL4_Word attr)
diff --git a/libsel4vspace/src/arch/arm/mapping.c b/libsel4vspace/src/arch/arm/mapping.c
new file mode 100644
index 0000000..285ef23
--- /dev/null
+++ b/libsel4vspace/src/arch/arm/mapping.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2018, Data61
+ * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
+ * ABN 41 687 119 230.
+ *
+ * This software may be distributed and modified according to the terms of
+ * the BSD 2-Clause license. Note that NO WARRANTY is provided.
+ * See "LICENSE_BSD2.txt" for details.
+ *
+ * @TAG(DATA61_BSD)
+ */
+
+#include <autoconf.h>
+#include <vspace/mapping.h>
+
+static seL4_Error vspace_map_io(seL4_CPtr cap, seL4_CPtr iospace_root, seL4_Word vaddr, UNUSED seL4_Word attr)
+{
+#ifdef CONFIG_ARM_SMMU
+ return seL4_ARM_IOPageTable_Map(cap, iospace_root, vaddr);
+#endif
+}
+
+int vspace_get_iospace_map_obj(UNUSED seL4_Word failed_bits, vspace_map_obj_t *obj)
+{
+ if (unlikely(obj == NULL) || !config_set(CONFIG_IOMMU)) {
+ return EINVAL;
+ }
+#ifdef CONFIG_ARM_SMMU
+ obj->size_bits = seL4_IOPageTableBits;
+ obj->type = seL4_ARM_IOPageTableObject;
+ obj->map_fn = vspace_map_io;
+ return 0;
+#endif
+}
diff --git a/libsel4vspace/src/arch/x86/mapping.c b/libsel4vspace/src/arch/x86/mapping.c
new file mode 100644
index 0000000..7334eb9
--- /dev/null
+++ b/libsel4vspace/src/arch/x86/mapping.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2018, Data61
+ * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
+ * ABN 41 687 119 230.
+ *
+ * This software may be distributed and modified according to the terms of
+ * the BSD 2-Clause license. Note that NO WARRANTY is provided.
+ * See "LICENSE_BSD2.txt" for details.
+ *
+ * @TAG(DATA61_BSD)
+ */
+
+#include <autoconf.h>
+#include <vspace/mapping.h>
+
+static seL4_Error vspace_map_io(seL4_CPtr cap, seL4_CPtr iospace_root, seL4_Word vaddr, UNUSED seL4_Word attr)
+{
+#ifdef CONFIG_IOMMU
+ return seL4_X86_IOPageTable_Map(cap, iospace_root, vaddr);
+#endif
+}
+
+int vspace_get_iospace_map_obj(UNUSED seL4_Word failed_bits, vspace_map_obj_t *obj)
+{
+ if (unlikely(obj == NULL) || !config_set(CONFIG_IOMMU)) {
+ return EINVAL;
+ }
+#ifdef CONFIG_IOMMU
+ obj->size_bits = seL4_IOPageTableBits;
+ obj->type = seL4_X86_IOPageTableObject;
+ obj->map_fn = vspace_map_io;
+ return 0;
+#endif
+}
+
+int vspace_get_ept_map_obj(seL4_Word failed_bits, vspace_map_obj_t *obj)
+{
+ switch (failed_bits) {
+#ifdef CONFIG_VTX
+ case SEL4_MAPPING_LOOKUP_NO_PT:
+ obj->size_bits = seL4_X86_EPTPTBits;
+ obj->type = seL4_X86_EPTPTObject;
+ obj->map_fn = seL4_X86_EPTPT_Map;
+ return 0;
+ case SEL4_MAPPING_LOOKUP_NO_PD:
+ obj->size_bits = seL4_X86_EPTPDBits;
+ obj->type = seL4_X86_EPTPDObject;
+ obj->map_fn = seL4_X86_EPTPD_Map;
+ return 0;
+ case SEL4_MAPPING_LOOKUP_NO_PDPT:
+ obj->size_bits = seL4_EPTPDPTBits,
+ obj->type = seL4_X86_EPTPDPTObject;
+ obj->map_fn = seL4_X86_EPTPDPT_Map;
+ return 0;
+#endif
+ default:
+ return EINVAL;
+ }
+}