mtk_apusys_apc.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /*
  2. * Copyright (c) 2021, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include <mtk_apusys_apc.h>
  8. #include <mtk_apusys_apc_def.h>
  9. #include <mtk_plat_common.h>
  10. #include <platform_def.h>
  11. static const struct APC_DOM_16 APUSYS_NOC_DAPC_AO[] = {
  12. /* 0~3 */
  13. APUSYS_APC_AO_ATTR("slv07-0",
  14. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  15. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  16. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  17. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION),
  18. APUSYS_APC_AO_ATTR("slv07-1",
  19. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  20. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  21. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  22. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION),
  23. APUSYS_APC_AO_ATTR("slv07-2",
  24. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  25. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  26. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  27. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION),
  28. APUSYS_APC_AO_ATTR("slv07-3",
  29. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  30. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  31. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  32. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION),
  33. /* 16~18 */
  34. APUSYS_APC_AO_ATTR("slv01-0",
  35. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  36. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  37. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  38. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  39. APUSYS_APC_AO_ATTR("slv01-1",
  40. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  41. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  42. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  43. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  44. APUSYS_APC_AO_ATTR("slv01-2",
  45. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  46. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  47. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  48. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  49. /* 19~21 */
  50. APUSYS_APC_AO_ATTR("slv00-0",
  51. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  52. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  53. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  54. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  55. APUSYS_APC_AO_ATTR("slv00-1",
  56. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  57. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  58. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  59. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  60. APUSYS_APC_AO_ATTR("slv00-2",
  61. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  62. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  63. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  64. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  65. /* 22~26 */
  66. APUSYS_APC_AO_ATTR("slv02-0",
  67. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  68. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  69. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  70. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION),
  71. APUSYS_APC_AO_ATTR("slv02-1",
  72. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  73. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  74. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  75. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION),
  76. APUSYS_APC_AO_ATTR("slv02-2",
  77. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  78. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  79. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  80. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION),
  81. APUSYS_APC_AO_ATTR("slv02-3",
  82. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  83. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  84. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  85. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION),
  86. APUSYS_APC_AO_ATTR("slv02-4",
  87. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  88. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  89. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION,
  90. NO_PROTECTION, NO_PROTECTION, NO_PROTECTION, NO_PROTECTION),
  91. };
  92. static int32_t set_slave_noc_dapc(uint32_t slave,
  93. enum APUSYS_APC_DOMAIN_ID domain_id,
  94. enum APUSYS_APC_PERM_TYPE perm)
  95. {
  96. uint32_t apc_register_index;
  97. uint32_t apc_set_index;
  98. uintptr_t base;
  99. uint32_t clr_bit;
  100. uint32_t set_bit;
  101. int32_t ret;
  102. if (perm >= PERM_NUM) {
  103. ERROR("[NOC_DAPC] perm type:0x%x is not supported!\n", perm);
  104. ret = APUSYS_APC_ERR_PERMISSION_NOT_SUPPORTED;
  105. goto exit;
  106. }
  107. apc_register_index = slave / APUSYS_NOC_DAPC_AO_SLAVE_NUM_IN_1_DOM;
  108. apc_set_index = slave % APUSYS_NOC_DAPC_AO_SLAVE_NUM_IN_1_DOM;
  109. clr_bit = 0xFFFFFFFF ^ (0x3U << (apc_set_index * 2));
  110. set_bit = perm << (apc_set_index * 2);
  111. if ((slave < APUSYS_NOC_DAPC_AO_SLAVE_NUM) &&
  112. (domain_id < APUSYS_NOC_DAPC_AO_DOM_NUM)) {
  113. base = APUSYS_NOC_DAPC_AO_BASE +
  114. (domain_id * 0x40) + (apc_register_index * 4);
  115. apuapc_writel(apuapc_readl(base) & clr_bit, base);
  116. apuapc_writel(apuapc_readl(base) | set_bit, base);
  117. ret = APUSYS_APC_OK;
  118. } else {
  119. ERROR("[NOC_DAPC] %s: %s, %s:0x%x, %s:0x%x\n",
  120. __func__, "out of boundary",
  121. "slave", slave,
  122. "domain_id", domain_id);
  123. ret = APUSYS_APC_ERR_OUT_OF_BOUNDARY;
  124. }
  125. exit:
  126. return ret;
  127. }
  128. static void dump_apusys_noc_dapc(void)
  129. {
  130. uint32_t reg_num;
  131. uint32_t d, i;
  132. reg_num = APUSYS_NOC_DAPC_AO_SLAVE_NUM /
  133. APUSYS_NOC_DAPC_AO_SLAVE_NUM_IN_1_DOM;
  134. for (d = 0U; d < APUSYS_NOC_DAPC_AO_DOM_NUM; d++) {
  135. for (i = 0U; i <= reg_num; i++) {
  136. INFO("[NOCDAPC] D%d_APC_%d: 0x%x\n", d, i,
  137. apuapc_readl(APUSYS_NOC_DAPC_AO_BASE +
  138. (d * 0x40) + (i * 4)));
  139. }
  140. }
  141. INFO("[NOCDAPC] APC_CON: 0x%x\n", apuapc_readl(APUSYS_NOC_DAPC_CON));
  142. }
  143. static const struct APC_DOM_16 APUSYS_AO_Devices[] = {
  144. /* 0 */
  145. APUSYS_APC_AO_ATTR("apusys_ao-0",
  146. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  147. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  148. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  149. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  150. APUSYS_APC_AO_ATTR("apusys_ao-1",
  151. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  152. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  153. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  154. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  155. APUSYS_APC_AO_ATTR("apusys_ao-2",
  156. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  157. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  158. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  159. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  160. APUSYS_APC_AO_ATTR("apusys_ao-3",
  161. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  162. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  163. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  164. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  165. APUSYS_APC_AO_ATTR("apusys_ao-4",
  166. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  167. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  168. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  169. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  170. APUSYS_APC_AO_ATTR("apusys_ao-5",
  171. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  172. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  173. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  174. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  175. APUSYS_APC_AO_ATTR("md32_apb_s-0",
  176. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  177. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  178. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  179. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  180. APUSYS_APC_AO_ATTR("md32_apb_s-1",
  181. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  182. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  183. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  184. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  185. APUSYS_APC_AO_ATTR("md32_apb_s-2",
  186. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  187. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  188. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  189. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  190. APUSYS_APC_AO_ATTR("md32_debug_apb",
  191. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  192. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  193. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  194. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  195. /* 10 */
  196. APUSYS_APC_AO_ATTR("apu_conn_config",
  197. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  198. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  199. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  200. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  201. APUSYS_APC_AO_ATTR("apu_sctrl_reviser",
  202. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  203. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  204. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  205. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  206. APUSYS_APC_AO_ATTR("apu_sema_stimer",
  207. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  208. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  209. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  210. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  211. APUSYS_APC_AO_ATTR("apu_emi_config",
  212. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  213. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  214. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  215. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  216. APUSYS_APC_AO_ATTR("apu_adl",
  217. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  218. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  219. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  220. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  221. APUSYS_APC_AO_ATTR("apu_edma_lite0",
  222. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  223. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  224. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  225. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  226. APUSYS_APC_AO_ATTR("apu_edma_lite1",
  227. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  228. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  229. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  230. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  231. APUSYS_APC_AO_ATTR("apu_edma0",
  232. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  233. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  234. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  235. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  236. APUSYS_APC_AO_ATTR("apu_edma0",
  237. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  238. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  239. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  240. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  241. APUSYS_APC_AO_ATTR("apu_dapc_ao",
  242. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  243. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  244. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  245. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  246. /* 20 */
  247. APUSYS_APC_AO_ATTR("apu_dapc",
  248. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  249. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  250. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  251. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  252. APUSYS_APC_AO_ATTR("infra_bcrm",
  253. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  254. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  255. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  256. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  257. APUSYS_APC_AO_ATTR("apb_dbg_ctl",
  258. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  259. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  260. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  261. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  262. APUSYS_APC_AO_ATTR("noc_dapc",
  263. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  264. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  265. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  266. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  267. APUSYS_APC_AO_ATTR("apu_noc_bcrm",
  268. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  269. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  270. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  271. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  272. APUSYS_APC_AO_ATTR("apu_noc_config",
  273. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  274. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  275. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  276. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  277. APUSYS_APC_AO_ATTR("vpu_core0_config-0",
  278. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  279. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  280. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  281. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  282. APUSYS_APC_AO_ATTR("vpu_core0_config-1",
  283. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  284. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  285. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  286. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  287. APUSYS_APC_AO_ATTR("vpu_core1_config-0",
  288. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  289. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  290. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  291. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  292. APUSYS_APC_AO_ATTR("vpu_core1_config-1",
  293. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  294. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  295. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  296. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  297. /* 30 */
  298. APUSYS_APC_AO_ATTR("mdla0_apb-0",
  299. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  300. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  301. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  302. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  303. APUSYS_APC_AO_ATTR("mdla0_apb-1",
  304. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  305. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  306. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  307. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  308. APUSYS_APC_AO_ATTR("mdla0_apb-2",
  309. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  310. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  311. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  312. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  313. APUSYS_APC_AO_ATTR("mdla0_apb-3",
  314. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  315. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  316. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  317. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  318. APUSYS_APC_AO_ATTR("apu_iommu0_r0",
  319. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  320. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  321. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  322. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  323. APUSYS_APC_AO_ATTR("apu_iommu0_r1",
  324. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  325. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  326. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  327. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  328. APUSYS_APC_AO_ATTR("apu_iommu0_r2",
  329. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  330. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  331. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  332. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  333. APUSYS_APC_AO_ATTR("apu_iommu0_r3",
  334. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  335. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  336. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  337. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  338. APUSYS_APC_AO_ATTR("apu_iommu0_r4",
  339. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  340. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  341. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  342. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  343. APUSYS_APC_AO_ATTR("apu_rsi2_config",
  344. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  345. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  346. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  347. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  348. /* 40 */
  349. APUSYS_APC_AO_ATTR("apu_ssc2_config",
  350. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  351. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  352. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  353. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  354. APUSYS_APC_AO_ATTR("vp6_core0_debug_apb",
  355. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  356. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  357. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  358. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  359. APUSYS_APC_AO_ATTR("vp6_core1_debug_apb",
  360. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  361. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  362. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
  363. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN),
  364. };
  365. static int32_t set_slave_apc(uint32_t slave,
  366. enum APUSYS_APC_DOMAIN_ID domain_id,
  367. enum APUSYS_APC_PERM_TYPE perm)
  368. {
  369. uint32_t apc_register_index;
  370. uint32_t apc_set_index;
  371. uintptr_t base;
  372. uint32_t clr_bit;
  373. uint32_t set_bit;
  374. int32_t ret;
  375. if (perm >= PERM_NUM) {
  376. ERROR("[APUAPC] perm type:0x%x is not supported!\n", perm);
  377. ret = APUSYS_APC_ERR_PERMISSION_NOT_SUPPORTED;
  378. goto exit;
  379. }
  380. apc_register_index = slave / APUSYS_APC_SYS0_AO_SLAVE_NUM_IN_1_DOM;
  381. apc_set_index = slave % APUSYS_APC_SYS0_AO_SLAVE_NUM_IN_1_DOM;
  382. clr_bit = 0xFFFFFFFF ^ (0x3U << (apc_set_index * 2));
  383. set_bit = perm << (apc_set_index * 2);
  384. if ((slave < APUSYS_APC_SYS0_AO_SLAVE_NUM) &&
  385. (domain_id < APUSYS_APC_SYS0_AO_DOM_NUM)) {
  386. base = APUSYS_APC_AO_BASE +
  387. (domain_id * 0x40) + (apc_register_index * 4);
  388. apuapc_writel(apuapc_readl(base) & clr_bit, base);
  389. apuapc_writel(apuapc_readl(base) | set_bit, base);
  390. ret = APUSYS_APC_OK;
  391. } else {
  392. ERROR("[APUAPC] %s: %s, %s:0x%x, %s:0x%x\n",
  393. __func__, "out of boundary",
  394. "slave", slave,
  395. "domain_id", domain_id);
  396. ret = APUSYS_APC_ERR_OUT_OF_BOUNDARY;
  397. }
  398. exit:
  399. return ret;
  400. }
  401. static void dump_apusys_ao_apc(void)
  402. {
  403. uint32_t reg_num;
  404. uint32_t d, i;
  405. reg_num = APUSYS_APC_SYS0_AO_SLAVE_NUM /
  406. APUSYS_APC_SYS0_AO_SLAVE_NUM_IN_1_DOM;
  407. for (d = 0U; d < APUSYS_APC_SYS0_AO_DOM_NUM; d++) {
  408. for (i = 0U; i <= reg_num; i++) {
  409. INFO("[APUAPC] D%d_APC_%d: 0x%x\n", d, i,
  410. apuapc_readl(APUSYS_APC_AO_BASE +
  411. (d * 0x40) + (i * 4)));
  412. }
  413. }
  414. INFO("[APUAPC] APC_CON: 0x%x\n", apuapc_readl(APUSYS_APC_CON));
  415. }
  416. static int32_t set_apusys_noc_dapc(void)
  417. {
  418. int32_t ret = 0;
  419. uint32_t i;
  420. uint32_t index;
  421. for (i = 0U; i < ARRAY_SIZE(APUSYS_NOC_DAPC_AO); i++) {
  422. if (i < APUSYS_NOC_DAPC_GAP_BOUNDARY) {
  423. index = i;
  424. } else {
  425. index = i + APUSYS_NOC_DAPC_JUMP_GAP;
  426. }
  427. ret += set_slave_noc_dapc(index, DOMAIN_0,
  428. APUSYS_NOC_DAPC_AO[i].d0_permission);
  429. ret += set_slave_noc_dapc(index, DOMAIN_1,
  430. APUSYS_NOC_DAPC_AO[i].d1_permission);
  431. ret += set_slave_noc_dapc(index, DOMAIN_2,
  432. APUSYS_NOC_DAPC_AO[i].d2_permission);
  433. ret += set_slave_noc_dapc(index, DOMAIN_3,
  434. APUSYS_NOC_DAPC_AO[i].d3_permission);
  435. ret += set_slave_noc_dapc(index, DOMAIN_4,
  436. APUSYS_NOC_DAPC_AO[i].d4_permission);
  437. ret += set_slave_noc_dapc(index, DOMAIN_5,
  438. APUSYS_NOC_DAPC_AO[i].d5_permission);
  439. ret += set_slave_noc_dapc(index, DOMAIN_6,
  440. APUSYS_NOC_DAPC_AO[i].d6_permission);
  441. ret += set_slave_noc_dapc(index, DOMAIN_7,
  442. APUSYS_NOC_DAPC_AO[i].d7_permission);
  443. ret += set_slave_noc_dapc(index, DOMAIN_8,
  444. APUSYS_NOC_DAPC_AO[i].d8_permission);
  445. ret += set_slave_noc_dapc(index, DOMAIN_9,
  446. APUSYS_NOC_DAPC_AO[i].d9_permission);
  447. ret += set_slave_noc_dapc(index, DOMAIN_10,
  448. APUSYS_NOC_DAPC_AO[i].d10_permission);
  449. ret += set_slave_noc_dapc(index, DOMAIN_11,
  450. APUSYS_NOC_DAPC_AO[i].d11_permission);
  451. ret += set_slave_noc_dapc(index, DOMAIN_12,
  452. APUSYS_NOC_DAPC_AO[i].d12_permission);
  453. ret += set_slave_noc_dapc(index, DOMAIN_13,
  454. APUSYS_NOC_DAPC_AO[i].d13_permission);
  455. ret += set_slave_noc_dapc(index, DOMAIN_14,
  456. APUSYS_NOC_DAPC_AO[i].d14_permission);
  457. ret += set_slave_noc_dapc(index, DOMAIN_15,
  458. APUSYS_NOC_DAPC_AO[i].d15_permission);
  459. }
  460. return ret;
  461. }
  462. static int32_t set_apusys_ao_apc(void)
  463. {
  464. int32_t ret = 0;
  465. uint32_t i;
  466. for (i = 0U; i < ARRAY_SIZE(APUSYS_AO_Devices); i++) {
  467. ret += set_slave_apc(i, DOMAIN_0,
  468. APUSYS_AO_Devices[i].d0_permission);
  469. ret += set_slave_apc(i, DOMAIN_1,
  470. APUSYS_AO_Devices[i].d1_permission);
  471. ret += set_slave_apc(i, DOMAIN_2,
  472. APUSYS_AO_Devices[i].d2_permission);
  473. ret += set_slave_apc(i, DOMAIN_3,
  474. APUSYS_AO_Devices[i].d3_permission);
  475. ret += set_slave_apc(i, DOMAIN_4,
  476. APUSYS_AO_Devices[i].d4_permission);
  477. ret += set_slave_apc(i, DOMAIN_5,
  478. APUSYS_AO_Devices[i].d5_permission);
  479. ret += set_slave_apc(i, DOMAIN_6,
  480. APUSYS_AO_Devices[i].d6_permission);
  481. ret += set_slave_apc(i, DOMAIN_7,
  482. APUSYS_AO_Devices[i].d7_permission);
  483. ret += set_slave_apc(i, DOMAIN_8,
  484. APUSYS_AO_Devices[i].d8_permission);
  485. ret += set_slave_apc(i, DOMAIN_9,
  486. APUSYS_AO_Devices[i].d9_permission);
  487. ret += set_slave_apc(i, DOMAIN_10,
  488. APUSYS_AO_Devices[i].d10_permission);
  489. ret += set_slave_apc(i, DOMAIN_11,
  490. APUSYS_AO_Devices[i].d11_permission);
  491. ret += set_slave_apc(i, DOMAIN_12,
  492. APUSYS_AO_Devices[i].d12_permission);
  493. ret += set_slave_apc(i, DOMAIN_13,
  494. APUSYS_AO_Devices[i].d13_permission);
  495. ret += set_slave_apc(i, DOMAIN_14,
  496. APUSYS_AO_Devices[i].d14_permission);
  497. ret += set_slave_apc(i, DOMAIN_15,
  498. APUSYS_AO_Devices[i].d15_permission);
  499. }
  500. return ret;
  501. }
  502. static void set_apusys_apc_lock(void)
  503. {
  504. uint32_t set_bit = 1U << APUSYS_APC_SYS0_LOCK_BIT_APU_SCTRL_REVISER;
  505. /* Lock apu_sctrl_reviser */
  506. set_bit = set_bit | (1U << APUSYS_APC_SYS0_LOCK_BIT_APUSYS_AO_5);
  507. apuapc_writel(set_bit, APUSYS_SYS0_APC_LOCK_0);
  508. }
  509. void set_apusys_apc(void)
  510. {
  511. int32_t ret = 0;
  512. /* Check violation status */
  513. INFO("[APUAPC] vio %d\n", apuapc_readl(APUSYS_APC_CON) & 0x80000000);
  514. /* Initial Permission */
  515. ret = set_apusys_ao_apc();
  516. INFO("[APUAPC] %s - %s!\n", "set_apusys_ao_apc",
  517. ret ? "FAILED" : "SUCCESS");
  518. /* Lock */
  519. set_apusys_apc_lock();
  520. /* Initial NoC Permission */
  521. ret = set_apusys_noc_dapc();
  522. INFO("[APUAPC] %s - %s!\n", "set_apusys_noc_dapc",
  523. ret ? "FAILED" : "SUCCESS");
  524. /* Dump Permission */
  525. dump_apusys_ao_apc();
  526. dump_apusys_noc_dapc();
  527. INFO("[APUAPC] %s done\n", __func__);
  528. }