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