fix(lib/xlat): Assertions for `is_mmu_enabled`.

The runtime checks for some of the xlat APIs for
is_mmu_enabled() are replaced with assertions so as to make it
consistent across the RMM codebase.

Also, added assertions to some APIs to ensure that the
preconditions for calling the API are adhered to.

Modified the unit tests to check the above added assertion.

Signed-off-by: Soby Mathew <soby.mathew@arm.com>
Change-Id: I03aecef79a8dd259a0755808b16f0218d44f4180
diff --git a/lib/xlat/tests/xlat_tests_base_g2.cpp b/lib/xlat/tests/xlat_tests_base_g2.cpp
index fd11679..1360403 100644
--- a/lib/xlat/tests/xlat_tests_base_g2.cpp
+++ b/lib/xlat/tests/xlat_tests_base_g2.cpp
@@ -2225,7 +2225,6 @@
 	 * and overwrite it to test different failure conditions on
 	 * xlat_arch_setup_mmu_cfg():
 	 *
-	 *	- Call xlat_arch_setup_mmu_cfg() with the MMU enabled.
 	 *	- Call xlat_arch_setup_mmu_cfg() with an uninitialized
 	 *	  context configuration.
 	 *	- Call xlat_arch_setup_mmu_cfg() for a CPU which
@@ -2256,18 +2255,6 @@
 			       XLAT_TESTS_MAX_TABLES);
 	CHECK_TRUE(retval == 0);
 
-	/* Force the MMU enblement */
-	xlat_enable_mmu_el2();
-
-	/* Try to initialize MMU for the given context */
-	retval = xlat_arch_setup_mmu_cfg(&ctx);
-
-	/* Verify that the MMU has failed to be initialized */
-	CHECK_TRUE(retval == -EPERM);
-
-	/* Restore SCTLR_EL2 to disable the MMU */
-	write_sctlr_el2(0ULL);
-
 	/* Force the context to be uninitialized */
 	ctx.cfg->initialized = false;
 
@@ -2378,6 +2365,55 @@
 	test_helpers_fail_if_no_assert_failed();
 }
 
+void xlat_arch_setup_mmu_cfg_tc6(void)
+{
+	struct xlat_ctx ctx;
+	struct xlat_ctx_cfg cfg;
+	struct xlat_ctx_tbls tbls;
+	uintptr_t start_va, end_va;
+	int retval;
+	struct xlat_mmap_region init_mmap;
+	uint64_t max_va_size =	XLAT_TEST_MAX_VA_SIZE();
+
+	/***************************************************************
+	 * TEST CASE 6:
+	 * Generate a valid translation context for one of the regions
+	 * and call xlat_arch_setup_mmu_cfg() with the MMU enabled.
+	 *
+	 ***************************************************************/
+
+	/* Clean the data structures */
+	memset((void *)&ctx, 0, sizeof(struct xlat_ctx));
+	memset((void *)&cfg, 0, sizeof(struct xlat_ctx_cfg));
+	memset((void *)&tbls, 0, sizeof(struct xlat_ctx_tbls));
+
+	/* VA space boundaries */
+	start_va = xlat_test_helpers_get_start_va(VA_LOW_REGION, max_va_size);
+	end_va = start_va + max_va_size - 1UL;
+
+	/* Generate only a single mmap region for each region */
+	xlat_test_helpers_rand_mmap_array(&init_mmap, 1U, start_va, end_va);
+
+	retval = xlat_ctx_cfg_init(&cfg, VA_LOW_REGION, &init_mmap,
+					1U, max_va_size);
+	CHECK_TRUE(retval == 0);
+
+	retval = xlat_ctx_init(&ctx, &cfg, &tbls,
+				xlat_test_helpers_tbls(),
+				XLAT_TESTS_MAX_TABLES);
+	CHECK_TRUE(retval == 0);
+
+	/* Force the MMU enablement */
+	xlat_enable_mmu_el2();
+
+	test_helpers_expect_assert_fail(true);
+
+	/* Try to initialize MMU for the given context */
+	retval = xlat_arch_setup_mmu_cfg(&ctx);
+
+	test_helpers_fail_if_no_assert_failed();
+}
+
 void xlat_get_oa_from_tte_tc1(void)
 {
 	uint64_t test_tte, val_addr, output_addr;