xlat_tables.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2014-2021, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef XLAT_TABLES_H
  7. #define XLAT_TABLES_H
  8. #include <lib/xlat_tables/xlat_tables_defs.h>
  9. #ifndef __ASSEMBLER__
  10. #include <stddef.h>
  11. #include <stdint.h>
  12. #include <lib/xlat_tables/xlat_mmu_helpers.h>
  13. /* Helper macro to define entries for mmap_region_t. It creates
  14. * identity mappings for each region.
  15. */
  16. #define MAP_REGION_FLAT(adr, sz, attr) MAP_REGION(adr, adr, sz, attr)
  17. /* Helper macro to define entries for mmap_region_t. It allows to
  18. * re-map address mappings from 'pa' to 'va' for each region.
  19. */
  20. #define MAP_REGION(pa, va, sz, attr) {(pa), (va), (sz), (attr)}
  21. /*
  22. * Shifts and masks to access fields of an mmap attribute
  23. */
  24. #define MT_TYPE_MASK U(0x7)
  25. #define MT_TYPE(_attr) ((_attr) & MT_TYPE_MASK)
  26. /* Access permissions (RO/RW) */
  27. #define MT_PERM_SHIFT U(3)
  28. /* Security state (SECURE/NS) */
  29. #define MT_SEC_SHIFT U(4)
  30. /* Access permissions for instruction execution (EXECUTE/EXECUTE_NEVER) */
  31. #define MT_EXECUTE_SHIFT U(5)
  32. /*
  33. * Memory mapping attributes
  34. */
  35. /*
  36. * Memory types supported.
  37. * These are organised so that, going down the list, the memory types are
  38. * getting weaker; conversely going up the list the memory types are getting
  39. * stronger.
  40. */
  41. #define MT_DEVICE U(0)
  42. #define MT_NON_CACHEABLE U(1)
  43. #define MT_MEMORY U(2)
  44. /* Values up to 7 are reserved to add new memory types in the future */
  45. #define MT_RO (U(0) << MT_PERM_SHIFT)
  46. #define MT_RW (U(1) << MT_PERM_SHIFT)
  47. #define MT_SECURE (U(0) << MT_SEC_SHIFT)
  48. #define MT_NS (U(1) << MT_SEC_SHIFT)
  49. /*
  50. * Access permissions for instruction execution are only relevant for normal
  51. * read-only memory, i.e. MT_MEMORY | MT_RO. They are ignored (and potentially
  52. * overridden) otherwise:
  53. * - Device memory is always marked as execute-never.
  54. * - Read-write normal memory is always marked as execute-never.
  55. */
  56. #define MT_EXECUTE (U(0) << MT_EXECUTE_SHIFT)
  57. #define MT_EXECUTE_NEVER (U(1) << MT_EXECUTE_SHIFT)
  58. /* Compound attributes for most common usages */
  59. #define MT_CODE (MT_MEMORY | MT_RO | MT_EXECUTE)
  60. #define MT_RO_DATA (MT_MEMORY | MT_RO | MT_EXECUTE_NEVER)
  61. /* Memory type for EL3 regions */
  62. #if ENABLE_RME
  63. #error FEAT_RME requires version 2 of the Translation Tables Library
  64. #else
  65. #define EL3_PAS MT_SECURE
  66. #endif
  67. /*
  68. * Structure for specifying a single region of memory.
  69. */
  70. typedef struct mmap_region {
  71. unsigned long long base_pa;
  72. uintptr_t base_va;
  73. size_t size;
  74. unsigned int attr;
  75. } mmap_region_t;
  76. /* Generic translation table APIs */
  77. void init_xlat_tables(void);
  78. void mmap_add_region(unsigned long long base_pa, uintptr_t base_va,
  79. size_t size, unsigned int attr);
  80. void mmap_add(const mmap_region_t *mm);
  81. #endif /*__ASSEMBLER__*/
  82. #endif /* XLAT_TABLES_H */