1 /*
2  * Copyright (c) 2021, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 #include <errno.h>
9 #include <stdbool.h>
10 #include <stdint.h>
11 #include <stdio.h>
12 
13 #include <common/debug.h>
14 #include <lib/utils_def.h>
15 #include <lib/xlat_tables/xlat_tables_defs.h>
16 #include <lib/xlat_tables/xlat_tables_v2.h>
17 #include "xlat_mpu_private.h"
18 
19 #include <fvp_r_arch_helpers.h>
20 #include <platform_def.h>
21 
22 #warning "xlat_mpu library is currently experimental and its API may change in future."
23 
24 
xlat_mmap_print(__unused const mmap_region_t * mmap)25 void xlat_mmap_print(__unused const mmap_region_t *mmap)
26 {
27 	/* Empty */
28 }
29 
30 #if LOG_LEVEL < LOG_LEVEL_VERBOSE
31 
xlat_tables_print(__unused xlat_ctx_t * ctx)32 void xlat_tables_print(__unused xlat_ctx_t *ctx)
33 {
34 	/* Empty */
35 }
36 
37 #else /* if LOG_LEVEL >= LOG_LEVEL_VERBOSE */
38 
xlat_tables_print_internal(__unused xlat_ctx_t * ctx)39 static void xlat_tables_print_internal(__unused xlat_ctx_t *ctx)
40 {
41 	int region_to_use = 0;
42 	uintptr_t region_base;
43 	size_t region_size;
44 	uint64_t prenr_el2_value = 0U;
45 
46 	/*
47 	 * Keep track of how many invalid descriptors are counted in a row.
48 	 * Whenever multiple invalid descriptors are found, only the first one
49 	 * is printed, and a line is added to inform about how many descriptors
50 	 * have been omitted.
51 	 */
52 
53 	/*
54 	 * TODO:  Remove this WARN() and comment when these API calls are more
55 	 *        completely implemented and tested!
56 	 */
57 	WARN("%s in this early version of xlat_mpu library may not produce reliable results!",
58 	     __func__);
59 
60 	/*
61 	 * Sequence through all regions and print those in-use (PRENR has an
62 	 * enable bit for each MPU region, 1 for in-use or 0 for unused):
63 	 */
64 	prenr_el2_value = read_prenr_el2();
65 	for (region_to_use = 0;  region_to_use < N_MPU_REGIONS;
66 	     region_to_use++) {
67 		if (((prenr_el2_value >> region_to_use) & 1U) == 0U) {
68 			continue;
69 		}
70 		region_base = read_prbar_el2() & PRBAR_PRLAR_ADDR_MASK;
71 		region_size = read_prlar_el2() & PRBAR_PRLAR_ADDR_MASK;
72 		printf("Address:  0x%llx, size:  0x%llx ",
73 			(long long) region_base,
74 			(long long) region_size);
75 	}
76 }
77 
xlat_tables_print(__unused xlat_ctx_t * ctx)78 void xlat_tables_print(__unused xlat_ctx_t *ctx)
79 {
80 	xlat_tables_print_internal(ctx);
81 }
82 
83 #endif /* LOG_LEVEL >= LOG_LEVEL_VERBOSE */
84