apusys_dapc_v1.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Copyright (c) 2023-2024, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef APUSYS_DAPC_V1_H
  7. #define APUSYS_DAPC_V1_H
  8. #include <lib/mmio.h>
  9. /******************************************************************************
  10. * STRUCTURE DEFINITION
  11. ******************************************************************************/
  12. enum apusys_apc_err_status {
  13. APUSYS_APC_OK = 0x0,
  14. APUSYS_APC_ERR_GENERIC = 0x1000,
  15. APUSYS_APC_ERR_INVALID_CMD = 0x1001,
  16. APUSYS_APC_ERR_SLAVE_TYPE_NOT_SUPPORTED = 0x1002,
  17. APUSYS_APC_ERR_SLAVE_IDX_NOT_SUPPORTED = 0x1003,
  18. APUSYS_APC_ERR_DOMAIN_NOT_SUPPORTED = 0x1004,
  19. APUSYS_APC_ERR_PERMISSION_NOT_SUPPORTED = 0x1005,
  20. APUSYS_APC_ERR_OUT_OF_BOUNDARY = 0x1006,
  21. APUSYS_APC_ERR_REQ_TYPE_NOT_SUPPORTED = 0x1007,
  22. };
  23. enum apusys_apc_perm_type {
  24. NO_PROTECTION = 0,
  25. SEC_RW_ONLY = 1,
  26. SEC_RW_NS_R = 2,
  27. FORBIDDEN = 3,
  28. PERM_NUM = 4,
  29. };
  30. enum apusys_apc_domain_id {
  31. DOMAIN_0 = 0,
  32. DOMAIN_1 = 1,
  33. DOMAIN_2 = 2,
  34. DOMAIN_3 = 3,
  35. DOMAIN_4 = 4,
  36. DOMAIN_5 = 5,
  37. DOMAIN_6 = 6,
  38. DOMAIN_7 = 7,
  39. DOMAIN_8 = 8,
  40. DOMAIN_9 = 9,
  41. DOMAIN_10 = 10,
  42. DOMAIN_11 = 11,
  43. DOMAIN_12 = 12,
  44. DOMAIN_13 = 13,
  45. DOMAIN_14 = 14,
  46. DOMAIN_15 = 15,
  47. };
  48. struct apc_dom_16 {
  49. unsigned char d0_permission;
  50. unsigned char d1_permission;
  51. unsigned char d2_permission;
  52. unsigned char d3_permission;
  53. unsigned char d4_permission;
  54. unsigned char d5_permission;
  55. unsigned char d6_permission;
  56. unsigned char d7_permission;
  57. unsigned char d8_permission;
  58. unsigned char d9_permission;
  59. unsigned char d10_permission;
  60. unsigned char d11_permission;
  61. unsigned char d12_permission;
  62. unsigned char d13_permission;
  63. unsigned char d14_permission;
  64. unsigned char d15_permission;
  65. };
  66. #define APUSYS_APC_AO_ATTR(DEV_NAME, \
  67. PERM_ATTR0, PERM_ATTR1, PERM_ATTR2, PERM_ATTR3, \
  68. PERM_ATTR4, PERM_ATTR5, PERM_ATTR6, PERM_ATTR7, \
  69. PERM_ATTR8, PERM_ATTR9, PERM_ATTR10, PERM_ATTR11, \
  70. PERM_ATTR12, PERM_ATTR13, PERM_ATTR14, PERM_ATTR15) \
  71. {(unsigned char)PERM_ATTR0, (unsigned char)PERM_ATTR1, \
  72. (unsigned char)PERM_ATTR2, (unsigned char)PERM_ATTR3, \
  73. (unsigned char)PERM_ATTR4, (unsigned char)PERM_ATTR5, \
  74. (unsigned char)PERM_ATTR6, (unsigned char)PERM_ATTR7, \
  75. (unsigned char)PERM_ATTR8, (unsigned char)PERM_ATTR9, \
  76. (unsigned char)PERM_ATTR10, (unsigned char)PERM_ATTR11, \
  77. (unsigned char)PERM_ATTR12, (unsigned char)PERM_ATTR13, \
  78. (unsigned char)PERM_ATTR14, (unsigned char)PERM_ATTR15}
  79. typedef enum apusys_apc_err_status (*dapc_cfg_func)(uint32_t slave,
  80. enum apusys_apc_domain_id domain_id,
  81. enum apusys_apc_perm_type perm);
  82. /* Register */
  83. #define DEVAPC_DOM_SIZE (0x40)
  84. #define DEVAPC_REG_SIZE (4)
  85. /* APUSYS APC offsets */
  86. #define APUSYS_DAPC_CON_VIO_MASK (0x80000000)
  87. #define APUSYS_DAPC_CON(base) ((base) + 0x00f00)
  88. /******************************************************************************
  89. * DAPC Common Function
  90. ******************************************************************************/
  91. #define SET_APUSYS_DAPC_V1(dapc, cfg) \
  92. set_apusys_dapc_v1(dapc, ARRAY_SIZE(dapc), cfg)
  93. #define DUMP_APUSYS_DAPC_V1(apc) \
  94. dump_apusys_dapc_v1(#apc, apc##_BASE, \
  95. (apc##_SLAVE_NUM / apc##_SLAVE_NUM_IN_1_DOM), apc##_DOM_NUM)
  96. enum apusys_apc_err_status set_apusys_dapc_v1(const struct apc_dom_16 *dapc,
  97. uint32_t size, dapc_cfg_func cfg);
  98. void dump_apusys_dapc_v1(const char *name, uintptr_t base, uint32_t reg_num, uint32_t dom_num);
  99. /******************************************************************************
  100. * DAPC Permission Policy
  101. ******************************************************************************/
  102. #define SLAVE_FORBID_EXCEPT_D0_SEC_RW(domain) \
  103. APUSYS_APC_AO_ATTR(domain, \
  104. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  105. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  106. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  107. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  108. #define SLAVE_FORBID_EXCEPT_D0_SEC_RW_D5_NO_PROTECT(domain) \
  109. APUSYS_APC_AO_ATTR(domain, \
  110. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  111. FORBIDDEN, NO_PROTECTION, FORBIDDEN, FORBIDDEN, \
  112. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  113. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  114. #define SLAVE_FORBID_EXCEPT_D5_NO_PROTECT(domain) \
  115. APUSYS_APC_AO_ATTR(domain, \
  116. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  117. FORBIDDEN, NO_PROTECTION, FORBIDDEN, FORBIDDEN, \
  118. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  119. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  120. #define SLAVE_FORBID_EXCEPT_D0_SEC_RW_NS_R_D5_NO_PROTECT(domain) \
  121. APUSYS_APC_AO_ATTR(domain, \
  122. SEC_RW_NS_R, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  123. FORBIDDEN, NO_PROTECTION, FORBIDDEN, FORBIDDEN, \
  124. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  125. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  126. #define SLAVE_FORBID_EXCEPT_D7_NO_PROTECT(domain) \
  127. APUSYS_APC_AO_ATTR(domain, \
  128. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  129. FORBIDDEN, FORBIDDEN, FORBIDDEN, NO_PROTECTION, \
  130. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  131. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  132. #define SLAVE_FORBID_EXCEPT_D5_D7_NO_PROTECT(domain) \
  133. APUSYS_APC_AO_ATTR(domain, \
  134. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  135. FORBIDDEN, NO_PROTECTION, FORBIDDEN, NO_PROTECTION, \
  136. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  137. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  138. #define SLAVE_FORBID_EXCEPT_D0_D5_NO_PROTECT(domain) \
  139. APUSYS_APC_AO_ATTR(domain, \
  140. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  141. FORBIDDEN, NO_PROTECTION, FORBIDDEN, FORBIDDEN, \
  142. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  143. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  144. #define SLAVE_FORBID_EXCEPT_D0_D11_NO_PROTECT_D3_D5_D8_SEC_RW(domain) \
  145. APUSYS_APC_AO_ATTR(domain, \
  146. NO_PROTECTION, FORBIDDEN, FORBIDDEN, SEC_RW_ONLY, \
  147. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  148. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, NO_PROTECTION, \
  149. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  150. #define SLAVE_FORBID_EXCEPT_D0_SEC_RW_NS_R_D3_D5_SEC_RW(domain) \
  151. APUSYS_APC_AO_ATTR(domain, \
  152. SEC_RW_NS_R, FORBIDDEN, FORBIDDEN, SEC_RW_ONLY, \
  153. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  154. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  155. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  156. #define SLAVE_FORBID_EXCEPT_D5_SEC_RW(domain) \
  157. APUSYS_APC_AO_ATTR(domain, \
  158. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  159. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  160. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  161. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  162. #define SLAVE_FORBID_EXCEPT_D0_SEC_RW_NS_R_D5_SEC_RW(domain) \
  163. APUSYS_APC_AO_ATTR(domain, \
  164. SEC_RW_NS_R, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  165. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  166. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  167. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  168. #define SLAVE_FORBID_EXCEPT_D0_NO_PROTECT_D3_D5_SEC_RW(domain) \
  169. APUSYS_APC_AO_ATTR(domain, \
  170. NO_PROTECTION, FORBIDDEN, FORBIDDEN, SEC_RW_ONLY, \
  171. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  172. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  173. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  174. #define SLAVE_FORBID_EXCEPT_D3_D5_SEC_RW_D0_D4_D11_NO_PROTECT(domain) \
  175. APUSYS_APC_AO_ATTR(domain, \
  176. NO_PROTECTION, FORBIDDEN, FORBIDDEN, SEC_RW_ONLY, \
  177. NO_PROTECTION, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  178. FORBIDDEN, FORBIDDEN, FORBIDDEN, NO_PROTECTION, \
  179. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  180. #define SLAVE_FORBID_EXCEPT_D5_SEC_RW_D0_NO_PROTECT(domain) \
  181. APUSYS_APC_AO_ATTR(domain, \
  182. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  183. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  184. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  185. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  186. #define SLAVE_FORBID_EXCEPT_D0_D5_SEC_RW(domain) \
  187. APUSYS_APC_AO_ATTR(domain, \
  188. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  189. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  190. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  191. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  192. #define SLAVE_FORBID_EXCEPT_D0_NO_PROTECT_D5_SEC_RW(domain) \
  193. APUSYS_APC_AO_ATTR(domain, \
  194. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  195. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  196. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  197. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  198. #define SLAVE_FORBID_EXCEPT_D3_D5_SEC_RW_D0_D11_NO_PROTECT(domain) \
  199. APUSYS_APC_AO_ATTR(domain, \
  200. NO_PROTECTION, FORBIDDEN, FORBIDDEN, SEC_RW_ONLY, \
  201. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  202. FORBIDDEN, FORBIDDEN, FORBIDDEN, NO_PROTECTION, \
  203. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  204. #define SLAVE_FORBID_EXCEPT_D0_NO_PROTECT_D5_D8_SEC_RW(domain) \
  205. APUSYS_APC_AO_ATTR(domain, \
  206. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  207. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  208. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  209. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  210. #define SLAVE_FORBID_EXCEPT_D0_D3_D5_SEC_RW(domain) \
  211. APUSYS_APC_AO_ATTR(domain, \
  212. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, SEC_RW_ONLY, \
  213. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  214. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  215. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  216. #define SLAVE_FORBID_EXCEPT_D0_SEC_RW_NS_R_D5_D8_SEC_RW(domain) \
  217. APUSYS_APC_AO_ATTR(domain, \
  218. SEC_RW_NS_R, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  219. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  220. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  221. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  222. #define SLAVE_FORBID_EXCEPT_D5_D8_SEC_RW(domain) \
  223. APUSYS_APC_AO_ATTR(domain, \
  224. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  225. FORBIDDEN, SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, \
  226. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  227. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  228. #define SLAVE_FORBID_EXCEPT_D0_D5_D7_D14_NO_PROTECT(domain) \
  229. APUSYS_APC_AO_ATTR(domain, \
  230. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  231. FORBIDDEN, NO_PROTECTION, FORBIDDEN, NO_PROTECTION, \
  232. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  233. FORBIDDEN, FORBIDDEN, NO_PROTECTION, FORBIDDEN)
  234. #endif /* APUSYS_DAPC_V1_H */