xlat_mpu_utils.c 2.1 KB

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