plat_tzc380.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright 2018-2021 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include <plat_tzc380.h>
  8. #pragma weak populate_tzc380_reg_list
  9. #ifdef DEFAULT_TZASC_CONFIG
  10. /*
  11. * Typical Memory map of DRAM0
  12. * |-----------NXP_NS_DRAM_ADDR ( = NXP_DRAM0_ADDR)----------|
  13. * | |
  14. * | |
  15. * | Non-SECURE REGION |
  16. * | |
  17. * | |
  18. * | |
  19. * |------- (NXP_NS_DRAM_ADDR + NXP_NS_DRAM_SIZE - 1) -------|
  20. * |-----------------NXP_SECURE_DRAM_ADDR--------------------|
  21. * | |
  22. * | |
  23. * | |
  24. * | SECURE REGION (= 64MB) |
  25. * | |
  26. * | |
  27. * | |
  28. * |--- (NXP_SECURE_DRAM_ADDR + NXP_SECURE_DRAM_SIZE - 1)----|
  29. * |-----------------NXP_SP_SHRD_DRAM_ADDR-------------------|
  30. * | |
  31. * | Secure EL1 Payload SHARED REGION (= 2MB) |
  32. * | |
  33. * |-----------(NXP_DRAM0_ADDR + NXP_DRAM0_SIZE - 1)---------|
  34. *
  35. *
  36. *
  37. * Typical Memory map of DRAM1
  38. * |---------------------NXP_DRAM1_ADDR----------------------|
  39. * | |
  40. * | |
  41. * | Non-SECURE REGION |
  42. * | |
  43. * | |
  44. * |---(NXP_DRAM1_ADDR + Dynamically calculated Size - 1) ---|
  45. *
  46. *
  47. * Typical Memory map of DRAM2
  48. * |---------------------NXP_DRAM2_ADDR----------------------|
  49. * | |
  50. * | |
  51. * | Non-SECURE REGION |
  52. * | |
  53. * | |
  54. * |---(NXP_DRAM2_ADDR + Dynamically calculated Size - 1) ---|
  55. */
  56. /*****************************************************************************
  57. * This function sets up access permissions on memory regions
  58. *
  59. * Input:
  60. * tzc380_reg_list : TZC380 Region List
  61. * dram_idx : DRAM index
  62. * list_idx : TZC380 Region List Index
  63. * dram_start_addr : Start address of DRAM at dram_idx.
  64. * dram_size : Size of DRAM at dram_idx.
  65. * secure_dram_sz : Secure DRAM Size
  66. * shrd_dram_sz : Shared DRAM Size
  67. *
  68. * Out:
  69. * list_idx : last populated index + 1
  70. *
  71. ****************************************************************************/
  72. int populate_tzc380_reg_list(struct tzc380_reg *tzc380_reg_list,
  73. int dram_idx, int list_idx,
  74. uint64_t dram_start_addr,
  75. uint64_t dram_size,
  76. uint32_t secure_dram_sz,
  77. uint32_t shrd_dram_sz)
  78. {
  79. /* Region 0: Default region marked as Non-Secure */
  80. if (list_idx == 0) {
  81. tzc380_reg_list[list_idx].secure = TZC_ATTR_SP_NS_RW;
  82. tzc380_reg_list[list_idx].enabled = TZC_ATTR_REGION_DISABLE;
  83. tzc380_reg_list[list_idx].addr = UL(0x0);
  84. tzc380_reg_list[list_idx].size = 0x0;
  85. tzc380_reg_list[list_idx].sub_mask = 0x0; /* all enabled */
  86. list_idx++;
  87. }
  88. /* Continue with list entries for index > 0 */
  89. if (dram_idx == 0) {
  90. /*
  91. * Region 1: Secure Region on DRAM 1 for 2MB out of 2MB,
  92. * excluding 0 sub-region(=256KB).
  93. */
  94. tzc380_reg_list[list_idx].secure = TZC_ATTR_SP_S_RW;
  95. tzc380_reg_list[list_idx].enabled = TZC_ATTR_REGION_ENABLE;
  96. tzc380_reg_list[list_idx].addr = dram_start_addr + dram_size;
  97. tzc380_reg_list[list_idx].size = TZC_REGION_SIZE_2M;
  98. tzc380_reg_list[list_idx].sub_mask = 0x0; /* all enabled */
  99. list_idx++;
  100. /*
  101. * Region 2: Secure Region on DRAM 1 for 54MB out of 64MB,
  102. * excluding 1 sub-rgion(=8MB) of 8MB.
  103. */
  104. tzc380_reg_list[list_idx].secure = TZC_ATTR_SP_S_RW;
  105. tzc380_reg_list[list_idx].enabled = TZC_ATTR_REGION_ENABLE;
  106. tzc380_reg_list[list_idx].addr = dram_start_addr + dram_size + shrd_dram_sz;
  107. tzc380_reg_list[list_idx].size = TZC_REGION_SIZE_64M;
  108. tzc380_reg_list[list_idx].sub_mask = 0x80; /* Disable sub-region 7 */
  109. list_idx++;
  110. /*
  111. * Region 3: Secure Region on DRAM 1 for 6MB out of 8MB,
  112. * excluding 2 sub-rgion(=1MB) of 2MB.
  113. */
  114. tzc380_reg_list[list_idx].secure = TZC_ATTR_SP_S_RW;
  115. tzc380_reg_list[list_idx].enabled = TZC_ATTR_REGION_ENABLE;
  116. tzc380_reg_list[list_idx].addr = dram_start_addr + dram_size + secure_dram_sz;
  117. tzc380_reg_list[list_idx].size = TZC_REGION_SIZE_8M;
  118. tzc380_reg_list[list_idx].sub_mask = 0xC0; /* Disable sub-region 6 & 7 */
  119. list_idx++;
  120. }
  121. return list_idx;
  122. }
  123. #else
  124. int populate_tzc380_reg_list(struct tzc380_reg *tzc380_reg_list,
  125. int dram_idx, int list_idx,
  126. uint64_t dram_start_addr,
  127. uint64_t dram_size,
  128. uint32_t secure_dram_sz,
  129. uint32_t shrd_dram_sz)
  130. {
  131. ERROR("tzc380_reg_list used is not a default list\n");
  132. ERROR("%s needs to be over-written.\n", __func__);
  133. return 0;
  134. }
  135. #endif /* DEFAULT_TZASC_CONFIG */
  136. void mem_access_setup(uintptr_t base, uint32_t total_regions,
  137. struct tzc380_reg *tzc380_reg_list)
  138. {
  139. uint32_t indx = 0;
  140. unsigned int attr_value;
  141. VERBOSE("Configuring TrustZone Controller tzc380\n");
  142. tzc380_init(base);
  143. tzc380_set_action(TZC_ACTION_NONE);
  144. for (indx = 0; indx < total_regions; indx++) {
  145. attr_value = tzc380_reg_list[indx].secure |
  146. TZC_ATTR_SUBREG_DIS(tzc380_reg_list[indx].sub_mask) |
  147. TZC_ATTR_REGION_SIZE(tzc380_reg_list[indx].size) |
  148. tzc380_reg_list[indx].enabled;
  149. tzc380_configure_region(indx, tzc380_reg_list[indx].addr,
  150. attr_value);
  151. }
  152. tzc380_set_action(TZC_ACTION_ERR);
  153. }