apusys_dapc_v1.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Copyright (c) 2023, 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 = 0x1,
  15. };
  16. enum apusys_apc_perm_type {
  17. NO_PROTECTION = 0,
  18. SEC_RW_ONLY = 1,
  19. SEC_RW_NS_R = 2,
  20. FORBIDDEN = 3,
  21. PERM_NUM = 4,
  22. };
  23. enum apusys_apc_domain_id {
  24. DOMAIN_0 = 0,
  25. DOMAIN_1 = 1,
  26. DOMAIN_2 = 2,
  27. DOMAIN_3 = 3,
  28. DOMAIN_4 = 4,
  29. DOMAIN_5 = 5,
  30. DOMAIN_6 = 6,
  31. DOMAIN_7 = 7,
  32. DOMAIN_8 = 8,
  33. DOMAIN_9 = 9,
  34. DOMAIN_10 = 10,
  35. DOMAIN_11 = 11,
  36. DOMAIN_12 = 12,
  37. DOMAIN_13 = 13,
  38. DOMAIN_14 = 14,
  39. DOMAIN_15 = 15,
  40. };
  41. struct apc_dom_16 {
  42. unsigned char d0_permission;
  43. unsigned char d1_permission;
  44. unsigned char d2_permission;
  45. unsigned char d3_permission;
  46. unsigned char d4_permission;
  47. unsigned char d5_permission;
  48. unsigned char d6_permission;
  49. unsigned char d7_permission;
  50. unsigned char d8_permission;
  51. unsigned char d9_permission;
  52. unsigned char d10_permission;
  53. unsigned char d11_permission;
  54. unsigned char d12_permission;
  55. unsigned char d13_permission;
  56. unsigned char d14_permission;
  57. unsigned char d15_permission;
  58. };
  59. #define APUSYS_APC_AO_ATTR(DEV_NAME, \
  60. PERM_ATTR0, PERM_ATTR1, PERM_ATTR2, PERM_ATTR3, \
  61. PERM_ATTR4, PERM_ATTR5, PERM_ATTR6, PERM_ATTR7, \
  62. PERM_ATTR8, PERM_ATTR9, PERM_ATTR10, PERM_ATTR11, \
  63. PERM_ATTR12, PERM_ATTR13, PERM_ATTR14, PERM_ATTR15) \
  64. {(unsigned char)PERM_ATTR0, (unsigned char)PERM_ATTR1, \
  65. (unsigned char)PERM_ATTR2, (unsigned char)PERM_ATTR3, \
  66. (unsigned char)PERM_ATTR4, (unsigned char)PERM_ATTR5, \
  67. (unsigned char)PERM_ATTR6, (unsigned char)PERM_ATTR7, \
  68. (unsigned char)PERM_ATTR8, (unsigned char)PERM_ATTR9, \
  69. (unsigned char)PERM_ATTR10, (unsigned char)PERM_ATTR11, \
  70. (unsigned char)PERM_ATTR12, (unsigned char)PERM_ATTR13, \
  71. (unsigned char)PERM_ATTR14, (unsigned char)PERM_ATTR15}
  72. typedef enum apusys_apc_err_status (*dapc_cfg_func)(uint32_t slave,
  73. enum apusys_apc_domain_id domain_id,
  74. enum apusys_apc_perm_type perm);
  75. /* Register */
  76. #define DEVAPC_DOM_SIZE (0x40)
  77. #define DEVAPC_REG_SIZE (4)
  78. /* APUSYS APC offsets */
  79. #define APUSYS_DAPC_CON_VIO_MASK (0x80000000)
  80. #define APUSYS_DAPC_CON(base) ((base) + 0x00f00)
  81. /******************************************************************************
  82. * DAPC Common Function
  83. ******************************************************************************/
  84. #define SET_APUSYS_DAPC_V1(dapc, cfg) \
  85. set_apusys_dapc_v1(dapc, ARRAY_SIZE(dapc), cfg)
  86. #define DUMP_APUSYS_DAPC_V1(apc) \
  87. dump_apusys_dapc_v1(#apc, apc##_BASE, \
  88. (apc##_SLAVE_NUM / apc##_SLAVE_NUM_IN_1_DOM), apc##_DOM_NUM)
  89. enum apusys_apc_err_status set_apusys_dapc_v1(const struct apc_dom_16 *dapc,
  90. uint32_t size, dapc_cfg_func cfg);
  91. void dump_apusys_dapc_v1(const char *name, uintptr_t base, uint32_t reg_num, uint32_t dom_num);
  92. /******************************************************************************
  93. * DAPC Permission Policy
  94. ******************************************************************************/
  95. #define SLAVE_FORBID_EXCEPT_D0_SEC_RW(domain) \
  96. APUSYS_APC_AO_ATTR(domain, \
  97. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  98. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  99. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  100. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  101. #define SLAVE_FORBID_EXCEPT_D0_SEC_RW_D5_NO_PROTECT(domain) \
  102. APUSYS_APC_AO_ATTR(domain, \
  103. SEC_RW_ONLY, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  104. FORBIDDEN, NO_PROTECTION, FORBIDDEN, FORBIDDEN, \
  105. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  106. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  107. #define SLAVE_FORBID_EXCEPT_D5_NO_PROTECT(domain) \
  108. APUSYS_APC_AO_ATTR(domain, \
  109. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  110. FORBIDDEN, NO_PROTECTION, FORBIDDEN, FORBIDDEN, \
  111. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  112. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  113. #define SLAVE_FORBID_EXCEPT_D0_SEC_RW_NS_R_D5_NO_PROTECT(domain) \
  114. APUSYS_APC_AO_ATTR(domain, \
  115. SEC_RW_NS_R, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  116. FORBIDDEN, NO_PROTECTION, FORBIDDEN, FORBIDDEN, \
  117. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  118. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  119. #define SLAVE_FORBID_EXCEPT_D7_NO_PROTECT(domain) \
  120. APUSYS_APC_AO_ATTR(domain, \
  121. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  122. FORBIDDEN, FORBIDDEN, FORBIDDEN, NO_PROTECTION, \
  123. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  124. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  125. #define SLAVE_FORBID_EXCEPT_D5_D7_NO_PROTECT(domain) \
  126. APUSYS_APC_AO_ATTR(domain, \
  127. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  128. FORBIDDEN, NO_PROTECTION, FORBIDDEN, NO_PROTECTION, \
  129. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  130. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  131. #define SLAVE_FORBID_EXCEPT_D0_D5_NO_PROTECT(domain) \
  132. APUSYS_APC_AO_ATTR(domain, \
  133. NO_PROTECTION, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  134. FORBIDDEN, NO_PROTECTION, FORBIDDEN, FORBIDDEN, \
  135. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN, \
  136. FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN)
  137. #endif /* APUSYS_DAPC_V1_H */