devapc.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include <devapc.h>
  8. #include <drivers/console.h>
  9. #include <lib/mmio.h>
  10. static void set_master_transaction(uint32_t master_index,
  11. enum TRANSACTION transaction_type)
  12. {
  13. uintptr_t base;
  14. uint32_t master_register_index;
  15. uint32_t master_set_index;
  16. uint32_t set_bit;
  17. master_register_index = master_index / (MOD_NO_IN_1_DEVAPC * 2);
  18. master_set_index = master_index % (MOD_NO_IN_1_DEVAPC * 2);
  19. base = DEVAPC_INFRA_MAS_SEC_0 + master_register_index * 4;
  20. set_bit = 0x1 << master_set_index;
  21. if (transaction_type == SECURE_TRANSACTION)
  22. mmio_setbits_32(base, set_bit);
  23. else
  24. mmio_clrbits_32(base, set_bit);
  25. }
  26. static void set_master_domain(uint32_t master_index, enum MASK_DOM domain)
  27. {
  28. uintptr_t base;
  29. uint32_t domain_reg;
  30. uint32_t domain_index;
  31. uint32_t clr_bit;
  32. uint32_t set_bit;
  33. domain_reg = master_index / MASTER_MOD_NO_IN_1_DEVAPC;
  34. domain_index = master_index % MASTER_MOD_NO_IN_1_DEVAPC;
  35. clr_bit = 0xF << (4 * domain_index);
  36. set_bit = domain << (4 * domain_index);
  37. base = DEVAPC_INFRA_MAS_DOM_0 + domain_reg * 4;
  38. mmio_clrsetbits_32(base, clr_bit, set_bit);
  39. }
  40. static void set_master_domain_remap_infra(enum MASK_DOM domain_emi_view,
  41. enum MASK_DOM domain_infra_view)
  42. {
  43. uintptr_t base;
  44. uint32_t clr_bit;
  45. uint32_t set_bit;
  46. if (domain_emi_view < DOMAIN_10) {
  47. base = DEVAPC_INFRA_DOM_RMP_0;
  48. clr_bit = 0x7 << (domain_emi_view * 3);
  49. set_bit = domain_infra_view << (domain_emi_view * 3);
  50. mmio_clrsetbits_32(base, clr_bit, set_bit);
  51. } else if (domain_emi_view > DOMAIN_10) {
  52. base = DEVAPC_INFRA_DOM_RMP_1;
  53. domain_emi_view = domain_emi_view - DOMAIN_11;
  54. clr_bit = 0x7 << (domain_emi_view * 3 + 1);
  55. set_bit = domain_infra_view << (domain_emi_view * 3 + 1);
  56. mmio_clrsetbits_32(base, clr_bit, set_bit);
  57. } else {
  58. base = DEVAPC_INFRA_DOM_RMP_0;
  59. clr_bit = 0x3 << (domain_emi_view * 3);
  60. set_bit = domain_infra_view << (domain_emi_view * 3);
  61. mmio_clrsetbits_32(base, clr_bit, set_bit);
  62. base = DEVAPC_INFRA_DOM_RMP_1;
  63. set_bit = (domain_infra_view & 0x4) >> 2;
  64. mmio_clrsetbits_32(base, 0x1, set_bit);
  65. }
  66. }
  67. static void set_master_domain_remap_mm(enum MASK_DOM domain_emi_view,
  68. enum MASK_DOM domain_mm_view)
  69. {
  70. uintptr_t base;
  71. uint32_t clr_bit;
  72. uint32_t set_bit;
  73. base = DEVAPC_MM_DOM_RMP_0;
  74. clr_bit = 0x3 << (domain_emi_view * 2);
  75. set_bit = domain_mm_view << (domain_emi_view * 2);
  76. mmio_clrsetbits_32(base, clr_bit, set_bit);
  77. }
  78. static void set_module_apc(enum DAPC_SLAVE_TYPE slave_type, uint32_t module,
  79. enum MASK_DOM domain_num,
  80. enum APC_ATTR permission_control)
  81. {
  82. uintptr_t base;
  83. uint32_t apc_index;
  84. uint32_t apc_set_index;
  85. uint32_t clr_bit;
  86. uint32_t set_bit;
  87. apc_index = module / MOD_NO_IN_1_DEVAPC;
  88. apc_set_index = module % MOD_NO_IN_1_DEVAPC;
  89. clr_bit = 0x3 << (apc_set_index * 2);
  90. set_bit = permission_control << (apc_set_index * 2);
  91. if (slave_type == DAPC_INFRA_SLAVE && module <= SLAVE_INFRA_MAX_INDEX)
  92. base = DEVAPC_INFRA_D0_APC_0 + domain_num * 0x100 +
  93. apc_index * 4;
  94. else if (slave_type == DAPC_MM_SLAVE && module <= SLAVE_MM_MAX_INDEX)
  95. base = DEVAPC_MM_D0_APC_0 + domain_num * 0x100 + apc_index * 4;
  96. else
  97. return;
  98. mmio_clrsetbits_32(base, clr_bit, set_bit);
  99. }
  100. static void set_default_master_transaction(void)
  101. {
  102. set_master_transaction(MASTER_SSPM, SECURE_TRANSACTION);
  103. }
  104. static void set_default_master_domain(void)
  105. {
  106. set_master_domain(MASTER_SCP, DOMAIN_1);
  107. set_master_domain_remap_infra(DOMAIN_1, DOMAIN_1);
  108. set_master_domain_remap_mm(DOMAIN_1, DOMAIN_1);
  109. set_master_domain(MASTER_SPM, DOMAIN_2);
  110. set_master_domain_remap_infra(DOMAIN_2, DOMAIN_2);
  111. set_master_domain_remap_mm(DOMAIN_2, DOMAIN_2);
  112. set_master_domain(MASTER_SSPM, DOMAIN_2);
  113. set_master_domain_remap_infra(DOMAIN_2, DOMAIN_2);
  114. set_master_domain_remap_mm(DOMAIN_2, DOMAIN_2);
  115. }
  116. static void set_default_slave_permission(void)
  117. {
  118. uint32_t module_index;
  119. uint32_t infra_size;
  120. uint32_t mm_size;
  121. infra_size = sizeof(D_APC_INFRA_Devices) / sizeof(struct DEVICE_INFO);
  122. mm_size = sizeof(D_APC_MM_Devices) / sizeof(struct DEVICE_INFO);
  123. for (module_index = 0; module_index < infra_size; module_index++) {
  124. if (D_APC_INFRA_Devices[module_index].d0_permission > 0) {
  125. set_module_apc(DAPC_INFRA_SLAVE, module_index, DOMAIN_0,
  126. D_APC_INFRA_Devices[module_index].d0_permission);
  127. }
  128. if (D_APC_INFRA_Devices[module_index].d1_permission > 0) {
  129. set_module_apc(DAPC_INFRA_SLAVE, module_index, DOMAIN_1,
  130. D_APC_INFRA_Devices[module_index].d1_permission);
  131. }
  132. if (D_APC_INFRA_Devices[module_index].d2_permission > 0) {
  133. set_module_apc(DAPC_INFRA_SLAVE, module_index, DOMAIN_2,
  134. D_APC_INFRA_Devices[module_index].d2_permission);
  135. }
  136. }
  137. for (module_index = 0; module_index < mm_size; module_index++) {
  138. if (D_APC_MM_Devices[module_index].d0_permission > 0) {
  139. set_module_apc(DAPC_MM_SLAVE, module_index, DOMAIN_0,
  140. D_APC_MM_Devices[module_index].d0_permission);
  141. }
  142. if (D_APC_MM_Devices[module_index].d1_permission > 0) {
  143. set_module_apc(DAPC_MM_SLAVE, module_index, DOMAIN_1,
  144. D_APC_MM_Devices[module_index].d1_permission);
  145. }
  146. if (D_APC_MM_Devices[module_index].d2_permission > 0) {
  147. set_module_apc(DAPC_MM_SLAVE, module_index, DOMAIN_2,
  148. D_APC_MM_Devices[module_index].d2_permission);
  149. }
  150. }
  151. }
  152. static void dump_devapc(void)
  153. {
  154. int i;
  155. INFO("[DEVAPC] dump DEVAPC registers:\n");
  156. for (i = 0; i < 13; i++) {
  157. INFO("[DEVAPC] (INFRA)D0_APC_%d = 0x%x, "
  158. "(INFRA)D1_APC_%d = 0x%x, "
  159. "(INFRA)D2_APC_%d = 0x%x\n",
  160. i, mmio_read_32(DEVAPC_INFRA_D0_APC_0 + i * 4),
  161. i, mmio_read_32(DEVAPC_INFRA_D0_APC_0 + 0x100 + i * 4),
  162. i, mmio_read_32(DEVAPC_INFRA_D0_APC_0 + 0x200 + i * 4));
  163. }
  164. for (i = 0; i < 9; i++) {
  165. INFO("[DEVAPC] (MM)D0_APC_%d = 0x%x, "
  166. "(MM)D1_APC_%d = 0x%x, "
  167. "(MM)D2_APC_%d = 0x%x\n",
  168. i, mmio_read_32(DEVAPC_MM_D0_APC_0 + i * 4),
  169. i, mmio_read_32(DEVAPC_MM_D0_APC_0 + 0x100 + i * 4),
  170. i, mmio_read_32(DEVAPC_MM_D0_APC_0 + 0x200 + i * 4));
  171. }
  172. for (i = 0; i < 4; i++) {
  173. INFO("[DEVAPC] MAS_DOM_%d = 0x%x\n", i,
  174. mmio_read_32(DEVAPC_INFRA_MAS_DOM_0 + i * 4));
  175. }
  176. INFO("[DEVAPC] MAS_SEC_0 = 0x%x\n",
  177. mmio_read_32(DEVAPC_INFRA_MAS_SEC_0));
  178. INFO("[DEVAPC] (INFRA)MAS_DOMAIN_REMAP_0 = 0x%x, "
  179. "(INFRA)MAS_DOMAIN_REMAP_1 = 0x%x\n",
  180. mmio_read_32(DEVAPC_INFRA_DOM_RMP_0),
  181. mmio_read_32(DEVAPC_INFRA_DOM_RMP_1));
  182. INFO("[DEVAPC] (MM)MAS_DOMAIN_REMAP_0 = 0x%x\n",
  183. mmio_read_32(DEVAPC_MM_DOM_RMP_0));
  184. }
  185. void devapc_init(void)
  186. {
  187. mmio_write_32(DEVAPC_INFRA_APC_CON, 0x80000001);
  188. mmio_write_32(DEVAPC_MM_APC_CON, 0x80000001);
  189. mmio_write_32(DEVAPC_MD_APC_CON, 0x80000001);
  190. set_default_master_transaction();
  191. set_default_master_domain();
  192. set_default_slave_permission();
  193. dump_devapc();
  194. }