VHE: Add helper apis to mm module for stage 1 mappings
Add helper apis for preparing and committing identity mappings to stage
1 tables.
Change-Id: Ic983d9baaa62128f92a14f5669939209b08bc923
Signed-off-by: Raghu Krishnamurthy <raghu.ncstate@gmail.com>
diff --git a/inc/hf/mm.h b/inc/hf/mm.h
index 209346d..b440d6f 100644
--- a/inc/hf/mm.h
+++ b/inc/hf/mm.h
@@ -101,6 +101,12 @@
bool mm_vm_init(struct mm_ptable *t, struct mpool *ppool);
void mm_vm_fini(struct mm_ptable *t, struct mpool *ppool);
+
+bool mm_identity_prepare(struct mm_ptable *t, paddr_t begin, paddr_t end,
+ uint32_t mode, struct mpool *ppool);
+void *mm_identity_commit(struct mm_ptable *t, paddr_t begin, paddr_t end,
+ uint32_t mode, struct mpool *ppool);
+
bool mm_vm_identity_map(struct mm_ptable *t, paddr_t begin, paddr_t end,
uint32_t mode, struct mpool *ppool, ipaddr_t *ipa);
bool mm_vm_identity_prepare(struct mm_ptable *t, paddr_t begin, paddr_t end,
diff --git a/src/mm.c b/src/mm.c
index ffc3d24..c1e7059 100644
--- a/src/mm.c
+++ b/src/mm.c
@@ -850,6 +850,39 @@
/**
* See `mm_ptable_identity_prepare`.
*
+ * This must be called before `mm_identity_commit` for the same mapping.
+ *
+ * Returns true on success, or false if the update would fail.
+ */
+bool mm_identity_prepare(struct mm_ptable *t, paddr_t begin, paddr_t end,
+ uint32_t mode, struct mpool *ppool)
+{
+ int flags = MM_FLAG_STAGE1 | mm_mode_to_flags(mode);
+
+ return mm_ptable_identity_prepare(t, begin, end,
+ arch_mm_mode_to_stage1_attrs(mode),
+ flags, ppool);
+}
+
+/**
+ * See `mm_ptable_identity_commit`.
+ *
+ * `mm_identity_prepare` must be called before this for the same mapping.
+ */
+void *mm_identity_commit(struct mm_ptable *t, paddr_t begin, paddr_t end,
+ uint32_t mode, struct mpool *ppool)
+{
+ int flags = MM_FLAG_STAGE1 | mm_mode_to_flags(mode);
+
+ mm_ptable_identity_commit(t, begin, end,
+ arch_mm_mode_to_stage1_attrs(mode), flags,
+ ppool);
+ return ptr_from_va(va_from_pa(begin));
+}
+
+/**
+ * See `mm_ptable_identity_prepare`.
+ *
* This must be called before `mm_vm_identity_commit` for the same mapping.
*
* Returns true on success, or false if the update would fail.