VHE: Add helper to get attributes of a stage 1 va range.
This patch adds a new helper function mm_get_mode, similar to
mm_vm_get_mode, to get the attributes of a stage 1 va range. This is
useful to be able to get memory attributes of a EL0 partitions va range
for example. This patchset modifies the existing function
mm_vm_get_attrs to take flags as an argument so that the same function
can work with stage 1 tables as well. Also added helper function to
convert attributes to mode for stage 1 similar to stage 2 helper
function.
Change-Id: I9dd23a7728830641bec46970fb6fa711240f8516
Signed-off-by: Raghu Krishnamurthy <raghu.ncstate@gmail.com>
diff --git a/src/mm.c b/src/mm.c
index 00b1d14..c9c54db 100644
--- a/src/mm.c
+++ b/src/mm.c
@@ -790,17 +790,16 @@
}
/**
- * Gets the attributes applies to the given range of addresses in the stage-2
- * table.
+ * Gets the attributes applied to the given range of addresses in the page
+ * tables.
*
* The value returned in `attrs` is only valid if the function returns true.
*
* Returns true if the whole range has the same attributes and false otherwise.
*/
-static bool mm_vm_get_attrs(struct mm_ptable *t, ptable_addr_t begin,
- ptable_addr_t end, uint64_t *attrs)
+static bool mm_get_attrs(struct mm_ptable *t, ptable_addr_t begin,
+ ptable_addr_t end, uint64_t *attrs, int flags)
{
- int flags = 0;
uint8_t max_level = mm_max_level(flags);
uint8_t root_level = max_level + 1;
size_t root_table_size = mm_entry_size(root_level);
@@ -992,7 +991,7 @@
uint64_t attrs;
bool ret;
- ret = mm_vm_get_attrs(t, ipa_addr(begin), ipa_addr(end), &attrs);
+ ret = mm_get_attrs(t, ipa_addr(begin), ipa_addr(end), &attrs, 0);
if (ret) {
*mode = arch_mm_stage2_attrs_to_mode(attrs);
}
@@ -1000,6 +999,27 @@
return ret;
}
+/**
+ * Gets the mode of the given range of virtual addresses if they
+ * are mapped with the same mode.
+ *
+ * Returns true if the range is mapped with the same mode and false otherwise.
+ */
+bool mm_get_mode(struct mm_ptable *t, vaddr_t begin, vaddr_t end,
+ uint32_t *mode)
+{
+ uint64_t attrs;
+ bool ret;
+
+ ret = mm_get_attrs(t, va_addr(begin), va_addr(end), &attrs,
+ MM_FLAG_STAGE1);
+ if (ret) {
+ *mode = arch_mm_stage1_attrs_to_mode(attrs);
+ }
+
+ return ret;
+}
+
static struct mm_stage1_locked mm_stage1_lock_unsafe(void)
{
return (struct mm_stage1_locked){.ptable = &ptable};