apusys_devapc.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * Copyright (c) 2023, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /* TF-A system header */
  7. #include <common/debug.h>
  8. #include <lib/utils_def.h>
  9. /* Vendor header */
  10. #include "apusys.h"
  11. #include "apusys_devapc.h"
  12. #include "apusys_devapc_def.h"
  13. #include <platform_def.h>
  14. #define DUMP_APUSYS_DAPC (0)
  15. static const struct apc_dom_16 APU_NOC_DAPC_RCX[] = {
  16. /* ctrl index = 0 */
  17. SLAVE_MD32_SRAM("slv16-0"),
  18. SLAVE_MD32_SRAM("slv16-1"),
  19. SLAVE_MD32_SRAM("slv16-2"),
  20. SLAVE_MD32_SRAM("slv16-3"),
  21. SLAVE_MD32_SRAM("slv16-4"),
  22. };
  23. static const struct apc_dom_16 APU_CTRL_DAPC_AO[] = {
  24. /* ctrl index = 0 */
  25. SLAVE_VCORE("apu_ao_ctl_o-0"),
  26. SLAVE_RPC("apu_ao_ctl_o-2"),
  27. SLAVE_PCU("apu_ao_ctl_o-3"),
  28. SLAVE_AO_CTRL("apu_ao_ctl_o-4"),
  29. SLAVE_PLL("apu_ao_ctl_o-5"),
  30. SLAVE_ACC("apu_ao_ctl_o-6"),
  31. SLAVE_SEC("apu_ao_ctl_o-7"),
  32. SLAVE_ARE0("apu_ao_ctl_o-8"),
  33. SLAVE_ARE1("apu_ao_ctl_o-9"),
  34. SLAVE_ARE2("apu_ao_ctl_o-10"),
  35. /* ctrl index = 10 */
  36. SLAVE_UNKNOWN("apu_ao_ctl_o-11"),
  37. SLAVE_AO_BCRM("apu_ao_ctl_o-12"),
  38. SLAVE_AO_DAPC_WRAP("apu_ao_ctl_o-13"),
  39. SLAVE_AO_DAPC_CON("apu_ao_ctl_o-14"),
  40. SLAVE_RCX_ACX_BULK("apu_ao_ctl_o-15"),
  41. SLAVE_UNKNOWN("apu_ao_ctl_o-16"),
  42. SLAVE_UNKNOWN("apu_ao_ctl_o-17"),
  43. SLAVE_APU_BULK("apu_ao_ctl_o-18"),
  44. SLAVE_ACX0_BCRM("apu_ao_ctl_o-20"),
  45. SLAVE_RPCTOP_LITE_ACX0("apu_ao_ctl_o-21"),
  46. /* ctrl index = 20 */
  47. SLAVE_ACX1_BCRM("apu_ao_ctl_o-22"),
  48. SLAVE_RPCTOP_LITE_ACX1("apu_ao_ctl_o-23"),
  49. SLAVE_RCX_TO_ACX0_0("apu_rcx2acx0_o-0"),
  50. SLAVE_RCX_TO_ACX0_1("apu_rcx2acx0_o-1"),
  51. SLAVE_SAE_TO_ACX0_0("apu_sae2acx0_o-0"),
  52. SLAVE_SAE_TO_ACX0_1("apu_sae2acx0_o-1"),
  53. SLAVE_RCX_TO_ACX1_0("apu_rcx2acx1_o-0"),
  54. SLAVE_RCX_TO_ACX1_1("apu_rcx2acx1_o-1"),
  55. SLAVE_SAE_TO_ACX1_0("apu_sae2acx1_o-0"),
  56. SLAVE_SAE_TO_ACX1_1("apu_sae2acx1_o-1"),
  57. };
  58. static const struct apc_dom_16 APU_CTRL_DAPC_RCX[] = {
  59. /* ctrl index = 0 */
  60. SLAVE_MD32_SYSCTRL0("md32_apb_s-0"),
  61. SLAVE_MD32_SYSCTRL1("md32_apb_s-1"),
  62. SLAVE_MD32_WDT("md32_apb_s-2"),
  63. SLAVE_MD32_CACHE("md32_apb_s-3"),
  64. SLAVE_RPC("apusys_ao-0"),
  65. SLAVE_PCU("apusys_ao-1"),
  66. SLAVE_AO_CTRL("apusys_ao-2"),
  67. SLAVE_PLL("apusys_ao-3"),
  68. SLAVE_ACC("apusys_ao-4"),
  69. SLAVE_SEC("apusys_ao-5"),
  70. /* ctrl index = 10 */
  71. SLAVE_ARE0("apusys_ao-6"),
  72. SLAVE_ARE1("apusys_ao-7"),
  73. SLAVE_ARE2("apusys_ao-8"),
  74. SLAVE_UNKNOWN("apusys_ao-9"),
  75. SLAVE_AO_BCRM("apusys_ao-10"),
  76. SLAVE_AO_DAPC_WRAP("apusys_ao-11"),
  77. SLAVE_AO_DAPC_CON("apusys_ao-12"),
  78. SLAVE_VCORE("apusys_ao-13"),
  79. SLAVE_ACX0_BCRM("apusys_ao-15"),
  80. SLAVE_ACX1_BCRM("apusys_ao-16"),
  81. /* ctrl index = 20 */
  82. SLAVE_NOC_AXI("noc_axi"),
  83. SLAVE_MD32_DBG("md32_dbg"),
  84. SLAVE_DBG_CRTL("apb_infra_dbg"),
  85. SLAVE_IOMMU0_BANK0("apu_n_mmu_r0"),
  86. SLAVE_IOMMU0_BANK1("apu_n_mmu_r1"),
  87. SLAVE_IOMMU0_BANK2("apu_n_mmu_r2"),
  88. SLAVE_IOMMU0_BANK3("apu_n_mmu_r3"),
  89. SLAVE_IOMMU0_BANK4("apu_n_mmu_r4"),
  90. SLAVE_IOMMU1_BANK0("apu_s_mmu_r0"),
  91. SLAVE_IOMMU1_BANK1("apu_s_mmu_r1"),
  92. /* ctrl index = 30 */
  93. SLAVE_IOMMU1_BANK2("apu_s_mmu_r2"),
  94. SLAVE_IOMMU1_BANK3("apu_s_mmu_r3"),
  95. SLAVE_IOMMU1_BANK4("apu_s_mmu_r4"),
  96. SLAVE_S0_SSC("apu_s0_ssc_cfg"),
  97. SLAVE_N0_SSC("apu_n0_ssc_cfg"),
  98. SLAVE_ACP_SSC("apu_acp_ssc_cfg"),
  99. SLAVE_S1_SSC("apu_s1_ssc_cfg"),
  100. SLAVE_N1_SSC("apu_n1_ssc_cfg"),
  101. SLAVE_CFG("apu_rcx_cfg"),
  102. SLAVE_SEMA_STIMER("apu_sema_stimer"),
  103. /* ctrl index = 40 */
  104. SLAVE_EMI_CFG("apu_emi_cfg"),
  105. SLAVE_LOG("apu_logtop"),
  106. SLAVE_CPE_SENSOR("apu_cpe_sensor"),
  107. SLAVE_CPE_COEF("apu_cpe_coef"),
  108. SLAVE_CPE_CTRL("apu_cpe_ctrl"),
  109. SLAVE_UNKNOWN("apu_xpu_rsi"),
  110. SLAVE_DFD_REG_SOC("apu_dfd"),
  111. SLAVE_SENSOR_WRAP_ACX0_DLA0("apu_sen_ac0_dla0"),
  112. SLAVE_SENSOR_WRAP_ACX0_DLA1("apu_sen_ac0_dla1"),
  113. SLAVE_SENSOR_WRAP_ACX0_VPU0("apu_sen_ac0_vpu"),
  114. /* ctrl index = 50 */
  115. SLAVE_SENSOR_WRAP_ACX1_DLA0("apu_sen_ac1_dla0"),
  116. SLAVE_SENSOR_WRAP_ACX1_DLA1("apu_sen_ac1_dla1"),
  117. SLAVE_SENSOR_WRAP_ACX1_VPU0("apu_sen_ac1_vpu"),
  118. SLAVE_REVISER("noc_cfg-0"),
  119. SLAVE_NOC("noc_cfg-1"),
  120. SLAVE_BCRM("infra_bcrm"),
  121. SLAVE_DAPC_WRAP("infra_dapc_wrap"),
  122. SLAVE_DAPC_CON("infra_dapc_con"),
  123. SLAVE_NOC_DAPC_WRAP("noc_dapc_wrap"),
  124. SLAVE_NOC_DAPC_CON("noc_dapc_con"),
  125. /* ctrl index = 60 */
  126. SLAVE_NOC_BCRM("noc_bcrm"),
  127. SLAVE_ACS("apu_rcx_acs"),
  128. SLAVE_HSE("apu_hse"),
  129. };
  130. static enum apusys_apc_err_status set_slave_ao_ctrl_apc(uint32_t slave,
  131. enum apusys_apc_domain_id domain_id,
  132. enum apusys_apc_perm_type perm)
  133. {
  134. uint32_t apc_register_index;
  135. uint32_t apc_set_index;
  136. uint32_t base;
  137. uint32_t clr_bit;
  138. uint32_t set_bit;
  139. if ((perm < 0) || (perm >= PERM_NUM)) {
  140. ERROR(MODULE_TAG "%s: permission type:0x%x is not supported!\n", __func__, perm);
  141. return APUSYS_APC_ERR_GENERIC;
  142. }
  143. if ((slave >= APU_CTRL_DAPC_AO_SLAVE_NUM) ||
  144. ((domain_id < 0) || (domain_id >= APU_CTRL_DAPC_AO_DOM_NUM))) {
  145. ERROR(MODULE_TAG "%s: out of boundary, slave:0x%x, domain_id:0x%x\n",
  146. __func__, slave, domain_id);
  147. return APUSYS_APC_ERR_GENERIC;
  148. }
  149. apc_register_index = slave / APU_CTRL_DAPC_AO_SLAVE_NUM_IN_1_DOM;
  150. apc_set_index = slave % APU_CTRL_DAPC_AO_SLAVE_NUM_IN_1_DOM;
  151. clr_bit = (DEVAPC_MASK << (apc_set_index * DEVAPC_DOM_SHIFT));
  152. set_bit = (uint32_t)perm << (apc_set_index * DEVAPC_DOM_SHIFT);
  153. base = (APU_CTRL_DAPC_AO_BASE + domain_id * DEVAPC_DOM_SIZE +
  154. apc_register_index * DEVAPC_REG_SIZE);
  155. mmio_clrsetbits_32(base, clr_bit, set_bit);
  156. return APUSYS_APC_OK;
  157. }
  158. static enum apusys_apc_err_status set_slave_noc_dapc_rcx(uint32_t slave,
  159. enum apusys_apc_domain_id domain_id,
  160. enum apusys_apc_perm_type perm)
  161. {
  162. uint32_t apc_register_index;
  163. uint32_t apc_set_index;
  164. uint32_t base;
  165. uint32_t clr_bit;
  166. uint32_t set_bit;
  167. if ((perm >= PERM_NUM) || (perm < 0)) {
  168. ERROR(MODULE_TAG "%s: permission type:0x%x is not supported!\n", __func__, perm);
  169. return APUSYS_APC_ERR_GENERIC;
  170. }
  171. if ((slave >= APU_NOC_DAPC_RCX_SLAVE_NUM) ||
  172. ((domain_id < 0) || (domain_id >= APU_NOC_DAPC_RCX_DOM_NUM))) {
  173. ERROR(MODULE_TAG "%s: out of boundary, slave:0x%x, domain_id:0x%x\n",
  174. __func__, slave, domain_id);
  175. return APUSYS_APC_ERR_GENERIC;
  176. }
  177. apc_register_index = slave / APU_NOC_DAPC_RCX_SLAVE_NUM_IN_1_DOM;
  178. apc_set_index = slave % APU_NOC_DAPC_RCX_SLAVE_NUM_IN_1_DOM;
  179. clr_bit = (DEVAPC_MASK << (apc_set_index * DEVAPC_DOM_SHIFT));
  180. set_bit = ((uint32_t)perm) << (apc_set_index * DEVAPC_DOM_SHIFT);
  181. base = (APU_NOC_DAPC_RCX_BASE + domain_id * DEVAPC_DOM_SIZE +
  182. apc_register_index * DEVAPC_REG_SIZE);
  183. mmio_clrsetbits_32(base, clr_bit, set_bit);
  184. return APUSYS_APC_OK;
  185. }
  186. static enum apusys_apc_err_status set_slave_rcx_ctrl_apc(uint32_t slave,
  187. enum apusys_apc_domain_id domain_id,
  188. enum apusys_apc_perm_type perm)
  189. {
  190. uint32_t apc_register_index;
  191. uint32_t apc_set_index;
  192. uint32_t base;
  193. uint32_t clr_bit;
  194. uint32_t set_bit;
  195. if ((perm < 0) || (perm >= PERM_NUM)) {
  196. ERROR(MODULE_TAG "%s: permission type:0x%x is not supported!\n", __func__, perm);
  197. return APUSYS_APC_ERR_GENERIC;
  198. }
  199. if ((slave >= APU_CTRL_DAPC_RCX_SLAVE_NUM) ||
  200. ((domain_id < 0) || (domain_id >= APU_CTRL_DAPC_RCX_DOM_NUM))) {
  201. ERROR(MODULE_TAG "%s: out of boundary, slave:0x%x, domain_id:0x%x\n",
  202. __func__, slave, domain_id);
  203. return APUSYS_APC_ERR_GENERIC;
  204. }
  205. apc_register_index = slave / APU_CTRL_DAPC_RCX_SLAVE_NUM_IN_1_DOM;
  206. apc_set_index = slave % APU_CTRL_DAPC_RCX_SLAVE_NUM_IN_1_DOM;
  207. clr_bit = (DEVAPC_MASK << (apc_set_index * DEVAPC_DOM_SHIFT));
  208. set_bit = (uint32_t)perm << (apc_set_index * DEVAPC_DOM_SHIFT);
  209. base = (APU_CTRL_DAPC_RCX_BASE + domain_id * DEVAPC_DOM_SIZE +
  210. apc_register_index * DEVAPC_REG_SIZE);
  211. mmio_clrsetbits_32(base, clr_bit, set_bit);
  212. return APUSYS_APC_OK;
  213. }
  214. static void apusys_devapc_init(const char *name, uint32_t base)
  215. {
  216. mmio_write_32(APUSYS_DAPC_CON(base), APUSYS_DAPC_CON_VIO_MASK);
  217. }
  218. int apusys_devapc_ao_init(void)
  219. {
  220. enum apusys_apc_err_status ret;
  221. apusys_devapc_init("APUAPC_CTRL_AO", APU_CTRL_DAPC_AO_BASE);
  222. ret = SET_APUSYS_DAPC_V1(APU_CTRL_DAPC_AO, set_slave_ao_ctrl_apc);
  223. if (ret != APUSYS_APC_OK) {
  224. ERROR(MODULE_TAG "%s: set_apusys_ao_ctrl_dap FAILED!\n", __func__);
  225. return -1;
  226. }
  227. #if DUMP_APUSYS_DAPC
  228. DUMP_APUSYS_DAPC_V1(APU_CTRL_DAPC_AO);
  229. #endif
  230. return 0;
  231. }
  232. int apusys_devapc_rcx_init(void)
  233. {
  234. enum apusys_apc_err_status ret;
  235. apusys_devapc_init("APUAPC_CTRL_RCX", APU_CTRL_DAPC_RCX_BASE);
  236. apusys_devapc_init("APUAPC_NOC_RCX", APU_NOC_DAPC_RCX_BASE);
  237. ret = SET_APUSYS_DAPC_V1(APU_CTRL_DAPC_RCX, set_slave_rcx_ctrl_apc);
  238. if (ret != APUSYS_APC_OK) {
  239. ERROR(MODULE_TAG "%s: set_slave_rcx_ctrl_apc FAILED!\n", __func__);
  240. return -1;
  241. }
  242. #if DUMP_APUSYS_DAPC
  243. DUMP_APUSYS_DAPC_V1(APU_CTRL_DAPC_RCX);
  244. #endif
  245. ret = SET_APUSYS_DAPC_V1(APU_NOC_DAPC_RCX, set_slave_noc_dapc_rcx);
  246. if (ret != APUSYS_APC_OK) {
  247. ERROR(MODULE_TAG "%s: set_slave_noc_dapc_rcx FAILED\n", __func__);
  248. return -1;
  249. }
  250. #if DUMP_APUSYS_DAPC
  251. DUMP_APUSYS_DAPC_V1(APU_NOC_DAPC_RCX);
  252. #endif
  253. return 0;
  254. }