refactor(mm): document quirks
Log when quirks are triggered, and document them in `mm_test.cc`.
Change-Id: I591f43ae2e650d6a58c5823b7f69288717069f89
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
diff --git a/src/mm.c b/src/mm.c
index 99a5144..04b33d9 100644
--- a/src/mm.c
+++ b/src/mm.c
@@ -456,9 +456,27 @@
/* Cap end to stay within the bounds of the page table. */
if (end > ptable_end) {
+ dlog_verbose(
+ "ptable_map: input range end falls outside of ptable "
+ "address space (%#016lx > %#016lx), capping to ptable "
+ "address space end\n",
+ end, ptable_end);
end = ptable_end;
}
+ if (begin >= end) {
+ dlog_verbose(
+ "ptable_map: input range is backwards (%#016lx >= "
+ "%#016lx), request will have no effect\n",
+ begin, end);
+ } else if (pa_addr(pa_begin) >= pa_addr(pa_end)) {
+ dlog_verbose(
+ "ptable_map: input range was backwards (%#016lx >= "
+ "%#016lx), but due to rounding the range %#016lx to "
+ "%#016lx will be mapped\n",
+ begin, end, pa_addr(pa_begin), pa_addr(pa_end));
+ }
+
while (begin < end) {
if (!mm_map_level(ptable, begin, end, attrs, root_table,
root_level - 1, flags, ppool)) {
@@ -900,6 +918,13 @@
struct mm_page_table *root_table;
bool got_attrs = false;
+ if (begin >= end) {
+ dlog_verbose(
+ "mm_get: input range is backwards (%#016lx >= "
+ "%#016lx)\n",
+ begin, end);
+ }
+
begin = mm_round_down_to_page(begin);
end = mm_round_up_to_page(end);
diff --git a/src/mm_test.cc b/src/mm_test.cc
index 99bf08a..d060139 100644
--- a/src/mm_test.cc
+++ b/src/mm_test.cc
@@ -300,8 +300,11 @@
/**
* Mapping a reverse range, i.e. the end comes before the start, is treated as
* an empty range so no mappings are made.
+ *
+ * This serves as a form of documentation of behaviour rather than a
+ * requirement. Check whether any code relies on this before changing it.
*/
-TEST_F(mm, map_reverse_range)
+TEST_F(mm, map_reverse_range_quirk)
{
constexpr mm_mode_t mode = 0;
ipaddr_t ipa = ipa_init(-1);
@@ -320,7 +323,7 @@
* This serves as a form of documentation of behaviour rather than a
* requirement. Check whether any code relies on this before changing it.
*/
-TEST_F(mm, map_reverse_range_quirk)
+TEST_F(mm, map_reverse_range_rounded_quirk)
{
constexpr mm_mode_t mode = 0;
ipaddr_t ipa = ipa_init(-1);
@@ -922,8 +925,11 @@
/**
* The mode of unmapped addresses can be retrieved and is set to invalid,
* unowned and shared.
+ *
+ * This serves as a form of documentation of behaviour rather than a
+ * requirement. Check whether any code relies on this before changing it.
*/
-TEST_F(mm, get_mode_empty)
+TEST_F(mm, get_mode_empty_quirk)
{
constexpr int default_mode =
MM_MODE_INVALID | MM_MODE_UNOWNED | MM_MODE_SHARED;