apusys_ammu.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Copyright (c) 2024, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef APUSYS_AMMU_H
  7. #define APUSYS_AMMU_H
  8. #include <platform_def.h>
  9. /* CMU */
  10. #define APUMMU_CMU_TOP_BASE (APU_CMU_TOP)
  11. #define APUMMU_CMU_TOP_TOPOLOGY (APUMMU_CMU_TOP_BASE + 0x04)
  12. #define APUMMU_VSID_ENABLE_OFFSET (0x50)
  13. #define APUMMU_VSID_VALID_OFFSET (0xb0)
  14. #define VSID_OFFSET(vsid_idx) (((vsid_idx) >> 5) * 0x4)
  15. #define APUMMU_VSID_ENABLE_BASE(vsid_idx) \
  16. (APUMMU_CMU_TOP_BASE + VSID_OFFSET(vsid_idx) + APUMMU_VSID_ENABLE_OFFSET)
  17. #define APUMMU_VSID_VALID_BASE(vsid_idx) \
  18. (APUMMU_CMU_TOP_BASE + VSID_OFFSET(vsid_idx) + APUMMU_VSID_VALID_OFFSET)
  19. /* VSID SRAM */
  20. #define APUMMU_VSID_BASE (APUMMU_CMU_TOP_BASE + 0x1000)
  21. #define APUMMU_VSID_DESC_BASE (APUMMU_VSID_BASE + 0x400)
  22. #define APUMMU_VSID_SRAM_SZIE (0x5C00)
  23. #define APUMMU_VSID_TBL_SZIE (0xF4)
  24. #define APUMMU_VSID(vsid_idx) (APUMMU_VSID_BASE + (vsid_idx) * 4)
  25. #define APUMMU_VSID_DESC(vsid_idx) \
  26. (APUMMU_VSID_DESC_BASE + (vsid_idx) * APUMMU_VSID_TBL_SZIE)
  27. /* TCU RCX */
  28. #define APU_VCORE_CONFIG_BASE (APU_RCX_VCORE_CONFIG)
  29. #define APUMMU_RCX_EXTM_TCU_BASE (APU_RCX_EXTM_TCU)
  30. #define APUMMU_RCX_UPRV_TCU_BASE (APU_RCX_UPRV_TCU)
  31. #define APUMMU_SSID_SID_WIDTH_CTRL (0xCC0)
  32. #define CSR_SMMU_AXMMUSID_WIDTH BIT(7)
  33. #define APUMMU_1M_SIZE (0x100000)
  34. #define SMMU_NORMAL_0_1G_SID (0x8)
  35. #define SMMU_NORMAL_1_4G_SID (0x9)
  36. #define SMMU_NORMAL_4_16G_SID (0xA)
  37. enum apummu_page_size {
  38. APUMMU_PAGE_LEN_128KB = 0,
  39. APUMMU_PAGE_LEN_256KB,
  40. APUMMU_PAGE_LEN_512KB,
  41. APUMMU_PAGE_LEN_1MB,
  42. APUMMU_PAGE_LEN_128MB,
  43. APUMMU_PAGE_LEN_256MB,
  44. APUMMU_PAGE_LEN_512MB,
  45. APUMMU_PAGE_LEN_4GB,
  46. };
  47. #define APUMMU_VSID_SEGMENT_BASE(vsid_idx, seg_idx, seg_offset) \
  48. (APUMMU_VSID_DESC(vsid_idx) + (seg_idx) * 0xC + (seg_offset) * 0x04 + 0x4)
  49. #define APUMMU_VSID_SEGMENT_ENABLE(vsid_idx) (APUMMU_VSID_DESC(vsid_idx))
  50. #define APUMMU_VSID_SRAM_TOTAL (APUMMU_VSID_SRAM_SZIE / APUMMU_VSID_TBL_SZIE)
  51. #define APUMMU_RSV_VSID_DESC_IDX_END (APUMMU_VSID_SRAM_TOTAL - 1)
  52. #define APUMMU_UPRV_RSV_DESC_IDX (APUMMU_RSV_VSID_DESC_IDX_END) /* 53 */
  53. #define APUMMU_LOGGER_RSV_DESC_IDX (APUMMU_RSV_VSID_DESC_IDX_END - 1)
  54. #define APUMMU_APMCU_RSV_DESC_IDX (APUMMU_RSV_VSID_DESC_IDX_END - 2)
  55. #define APUMMU_GPU_RSV_DESC_IDX (APUMMU_RSV_VSID_DESC_IDX_END - 3)
  56. #define APUMMU_SEG_OFFSET_0 (0)
  57. #define APUMMU_SEG_OFFSET_1 (1)
  58. #define APUMMU_SEG_OFFSET_2 (2)
  59. #define APUMMU_VSID_EN_MASK (0x1f)
  60. #define APUMMU_HW_THREAD_MAX (7)
  61. #define APUMMU_SEG_MAX (9)
  62. #define APUMMU_ADDR_SHIFT (12)
  63. #define VSID_THREAD_SZ (0x4)
  64. #define VSID_CORID_MASK (0x7f)
  65. #define VSID_CORID_OFF (11)
  66. #define VSID_IDX_MASK (0xff)
  67. #define VSID_IDX_OFF (3)
  68. #define VSID_VALID_MASK (0x1)
  69. #define VSID_COR_VALID_OFF (1)
  70. #define VSID_VALID_OFF (0)
  71. #define APUMMU_VSID_ACTIVE (32)
  72. #define APUMMU_VSID_RSV (4)
  73. #define APUMMU_VSID_UNUSED (12)
  74. #define APUMMU_VSID_USE_MAX (APUMMU_VSID_ACTIVE + APUMMU_VSID_RSV)
  75. #if ((APUMMU_VSID_RSV + APUMMU_VSID_ACTIVE + APUMMU_VSID_UNUSED + 1) > APUMMU_VSID_SRAM_TOTAL)
  76. #error APUMMU VSID Overflow
  77. #endif
  78. #define APUMMU_RSV_VSID_IDX_END (254)
  79. #define APUMMU_RSV_VSID_IDX_START (APUMMU_RSV_VSID_IDX_END - APUMMU_VSID_RSV + 1)
  80. #if ((APUMMU_RSV_VSID_IDX_END - APUMMU_RSV_VSID_IDX_START) > APUMMU_VSID_RSV)
  81. #error APUMMU VSID RSV Overflow
  82. #endif
  83. /* Reserve */
  84. #define APUMMU_UPRV_RSV_VSID (APUMMU_RSV_VSID_IDX_END)
  85. #define APUMMU_LOGGER_RSV_VSID (APUMMU_RSV_VSID_IDX_END - 1)
  86. #define APUMMU_APMCU_RSV_VSID (APUMMU_RSV_VSID_IDX_END - 2)
  87. #define APUMMU_GPU_RSV_VSID (APUMMU_RSV_VSID_IDX_END - 3)
  88. /* VSID bit mask */
  89. #define APUMMU_VSID_MAX_MASK_WORD ((APUMMU_VSID_USE_MAX + 32 - 1) / 32)
  90. /* VSID fields */
  91. #define READ_VSID_FIELD(vids, sg, offset, shift, mask) \
  92. ((mmio_read_32(APUMMU_VSID_SEGMENT_BASE(vsid, seg, offset)) >> sift) & mask)
  93. #define READ_VSID_FIELD_OFFESET0(vids, sg, shift, mask) \
  94. READ_VSID_FIELD(vids, sg, 0, shift, mask)
  95. #define READ_VSID_FIELD_OFFESET1(vids, sg, shift, mask) \
  96. READ_VSID_FIELD(vids, sg, 1, shift, mask)
  97. #define READ_VSID_FIELD_OFFESET2(vids, sg, shift, mask) \
  98. READ_VSID_FIELD(vids, sg, 2, shift, mask)
  99. /* Get segment offset 0 data - 0x00 */
  100. #define APUMMU_SEGMENT_GET_INPUT(vsid, seg) \
  101. READ_VSID_FIELD_OFFESET0(vsid, seg, 10, 0x3FFFFF)
  102. #define APUMMU_SEGMENT_GET_OFFSET0_RSRV(vsid, seg) \
  103. READ_VSID_FIELD_OFFESET0(vsid, seg, 6, 0xF)
  104. #define APUMMU_SEGMENT_GET_PAGELEN(vsid, seg) \
  105. READ_VSID_FIELD_OFFESET0(vsid, seg, 0, 0x7)
  106. #define APUMMU_SEGMENT_GET_PAGESEL(vsid, seg) \
  107. READ_VSID_FIELD_OFFESET0(vsid, seg, 3, 0x7)
  108. /* Get segment offset 1 data - 0x04 */
  109. #define APUMMU_SEGMENT_GET_IOMMU_EN(vsid, seg) \
  110. READ_VSID_FIELD_OFFESET1(vsid, seg, 1, 0x1)
  111. #define APUMMU_SEGMENT_GET_OFFSET1_RSRV0(vsid, seg) \
  112. READ_VSID_FIELD_OFFESET1(vsid, seg, 2, 0xFF)
  113. #define APUMMU_SEGMENT_GET_OFFSET1_RSRV1(vsid, seg) \
  114. READ_VSID_FIELD_OFFESET1(vsid, seg, 0, 0x1)
  115. #define APUMMU_SEGMENT_GET_OUTPUT(vsid, seg) \
  116. READ_VSID_FIELD_OFFESET1(vsid, seg, 10, 0x3FFFFF)
  117. /* Get segment offset 2 data - 0x08 */
  118. #define APUMMU_SEGMENT_GET_ACP_EN(vsid, seg) \
  119. READ_VSID_FIELD_OFFESET2(vsid, seg, 12, 0x1)
  120. #define APUMMU_SEGMENT_GET_AR_CACHE_ALLOC(vsid, seg) \
  121. READ_VSID_FIELD_OFFESET2(vsid, seg, 4, 0x1)
  122. #define APUMMU_SEGMENT_GET_AR_EXCLU(vsid, seg) \
  123. READ_VSID_FIELD_OFFESET2(vsid, seg, 9, 0x1)
  124. #define APUMMU_SEGMENT_GET_AR_SEPCU(vsid, seg) \
  125. READ_VSID_FIELD_OFFESET2(vsid, seg, 8, 0x1)
  126. #define APUMMU_SEGMENT_GET_AR_SLB_EN(vsid, seg) \
  127. READ_VSID_FIELD_OFFESET2(vsid, seg, 2, 0x1)
  128. #define APUMMU_SEGMENT_GET_AR_SLC_EN(vsid, seg) \
  129. READ_VSID_FIELD_OFFESET2(vsid, seg, 3, 0x1)
  130. #define APUMMU_SEGMENT_GET_AW_CACHE_ALLOC(vsid, seg) \
  131. READ_VSID_FIELD_OFFESET2(vsid, seg, 7, 0x1)
  132. #define APUMMU_SEGMENT_GET_AW_CLR(vsid, seg) \
  133. READ_VSID_FIELD_OFFESET2(vsid, seg, 11, 0x1)
  134. #define APUMMU_SEGMENT_GET_AW_INVALID(vsid, seg) \
  135. READ_VSID_FIELD_OFFESET2(vsid, seg, 10, 0x1)
  136. #define APUMMU_SEGMENT_GET_AW_SLB_EN(vsid, seg) \
  137. READ_VSID_FIELD_OFFESET2(vsid, seg, 5, 0x1)
  138. #define APUMMU_SEGMENT_GET_AW_SLC_EN(vsid, seg) \
  139. READ_VSID_FIELD_OFFESET2(vsid, seg, 6, 0x1)
  140. #define APUMMU_SEGMENT_GET_DOMAIN(vsid, seg) \
  141. READ_VSID_FIELD_OFFESET2(vsid, seg, 13, 0xF)
  142. #define APUMMU_SEGMENT_GET_NS(vsid, seg) \
  143. READ_VSID_FIELD_OFFESET2(vsid, seg, 0, 0x1)
  144. /* Build segment data */
  145. /* Build segment offset 0 (0x00) data */
  146. #define APUMMU_VSID_SEGMENT_00_INPUT(input_adr) (((input_adr) & 0x3fffff) << 10)
  147. #define APUMMU_VSID_SEGMENT_00_PAGESEL(page_sel) (((page_sel) & 0x7) << 3)
  148. #define APUMMU_VSID_SEGMENT_00_PAGELEN(page_len) (((page_len) & 0x7) << 0)
  149. #define APUMMU_VSID_SEGMENT_00_RESV(resv) (((resv) & 0xf) << 6)
  150. #define APUMMU_BUILD_SEGMENT_OFFSET0(input_adr, resv, page_sel, page_len) \
  151. (APUMMU_VSID_SEGMENT_00_INPUT(input_adr) | \
  152. APUMMU_VSID_SEGMENT_00_RESV(resv) | \
  153. APUMMU_VSID_SEGMENT_00_PAGESEL(page_sel) | \
  154. APUMMU_VSID_SEGMENT_00_PAGELEN(page_len))
  155. /* Build segment offset 1 (0x04) data */
  156. #define APUMMU_VSID_SEGMENT_04_IOMMU_EN(iommu_en) (((iommu_en) & 0x1) << 1)
  157. #define APUMMU_VSID_SEGMENT_04_OUTPUT(output_adr) (((output_adr) & 0x3fffff) << 10)
  158. #define APUMMU_VSID_SEGMENT_04_RESV0(resv0) (((resv0) & 0xff) << 2)
  159. #define APUMMU_VSID_SEGMENT_04_RESV1(resv1) (((resv1) & 0x1) << 0)
  160. #define APUMMU_BUILD_SEGMENT_OFFSET1(output_adr, resv0, iommu_en, resv1) \
  161. (APUMMU_VSID_SEGMENT_04_OUTPUT(output_adr) | \
  162. APUMMU_VSID_SEGMENT_04_RESV0(resv0) | \
  163. APUMMU_VSID_SEGMENT_04_IOMMU_EN(iommu_en) | \
  164. APUMMU_VSID_SEGMENT_04_RESV1(resv1))
  165. /* Build segment offset 2 (0x08) data */
  166. #define APUMMU_VSID_SEGMENT_08_DOMAIN_MASK (0xf)
  167. #define APUMMU_VSID_SEGMENT_08_DOMAIN_SHIFT (13)
  168. #define APUMMU_VSID_SEGMENT_08_RESV_MASK (0x7fff)
  169. #define APUMMU_VSID_SEGMENT_08_RESV_SHIFT (17)
  170. #define APUMMU_VSID_SEGMENT_08_DOMAIN(domain) \
  171. (((domain) & APUMMU_VSID_SEGMENT_08_DOMAIN_MASK) << APUMMU_VSID_SEGMENT_08_DOMAIN_SHIFT)
  172. #define APUMMU_VSID_SEGMENT_08_RESV(resv) \
  173. (((resv) & APUMMU_VSID_SEGMENT_08_RESV_MASK) << APUMMU_VSID_SEGMENT_08_RESV_SHIFT)
  174. #define APUMMU_VSID_SEGMENT_08_ACP_EN(acp_en) (((acp_en) & 0x1) << 12)
  175. #define APUMMU_VSID_SEGMENT_08_AR_EXCLU(ar_exclu) (((ar_exclu) & 0x1) << 9)
  176. #define APUMMU_VSID_SEGMENT_08_AR_SEPCU(ar_sepcu) (((ar_sepcu) & 0x1) << 8)
  177. #define APUMMU_VSID_SEGMENT_08_AR_SLB_EN(ar_slb_en) (((ar_slb_en) & 0x1) << 2)
  178. #define APUMMU_VSID_SEGMENT_08_AR_SLC_EN(ar_slc_en) (((ar_slc_en) & 0x1) << 3)
  179. #define APUMMU_VSID_SEGMENT_08_AW_CLR(aw_clr) (((aw_clr) & 0x1) << 11)
  180. #define APUMMU_VSID_SEGMENT_08_AW_INVALID(aw_invalid) (((aw_invalid) & 0x1) << 10)
  181. #define APUMMU_VSID_SEGMENT_08_AW_SLB_EN(aw_slb_en) (((aw_slb_en) & 0x1) << 5)
  182. #define APUMMU_VSID_SEGMENT_08_AW_SLC_EN(aw_slc_en) (((aw_slc_en) & 0x1) << 6)
  183. #define APUMMU_VSID_SEGMENT_08_NS(ns) (((ns) & 0x1) << 0)
  184. #define APUMMU_VSID_SEGMENT_08_RO(ro) (((ro) & 0x1) << 1)
  185. #define APUMMU_VSID_SEGMENT_08_AR_CACHE_ALLOCATE(ar_cache_allocate) \
  186. (((ar_cache_allocate) & 0x1) << 4)
  187. #define APUMMU_VSID_SEGMENT_08_AW_CACHE_ALLOCATE(aw_cache_allocate) \
  188. (((aw_cache_allocate) & 0x1) << 7)
  189. #define APUMMU_BUILD_SEGMENT_OFFSET2(resv, domain, acp_en, aw_clr, \
  190. aw_invalid, ar_exclu, ar_sepcu, \
  191. aw_cache_allocate, aw_slc_en, aw_slb_en, ar_cache_allocate, \
  192. ar_slc_en, ar_slb_en, ro, ns) \
  193. ((APUMMU_VSID_SEGMENT_08_RESV(resv)) |\
  194. (APUMMU_VSID_SEGMENT_08_DOMAIN(domain)) |\
  195. (APUMMU_VSID_SEGMENT_08_ACP_EN(acp_en)) |\
  196. (APUMMU_VSID_SEGMENT_08_AW_CLR(aw_clr)) |\
  197. (APUMMU_VSID_SEGMENT_08_AW_INVALID(aw_invalid)) |\
  198. (APUMMU_VSID_SEGMENT_08_AR_EXCLU(ar_exclu)) |\
  199. (APUMMU_VSID_SEGMENT_08_AR_SEPCU(ar_sepcu)) |\
  200. (APUMMU_VSID_SEGMENT_08_AW_CACHE_ALLOCATE(aw_cache_allocate)) |\
  201. (APUMMU_VSID_SEGMENT_08_AW_SLC_EN(aw_slc_en)) |\
  202. (APUMMU_VSID_SEGMENT_08_AW_SLB_EN(aw_slb_en)) |\
  203. (APUMMU_VSID_SEGMENT_08_AR_CACHE_ALLOCATE(ar_cache_allocate)) |\
  204. (APUMMU_VSID_SEGMENT_08_AR_SLC_EN(ar_slc_en)) |\
  205. (APUMMU_VSID_SEGMENT_08_AR_SLB_EN(ar_slb_en)) |\
  206. (APUMMU_VSID_SEGMENT_08_RO(ro)) | (APUMMU_VSID_SEGMENT_08_NS(ns)))
  207. /* Build segment offset 3 (0x0c) data */
  208. #define APUMMU_VSID_SEGMENT_0C_RESV(rsv) (((rsv) & 0x7fffffff) << 0)
  209. #define APUMMU_VSID_SEGMENT_0C_SEG_VALID(seg_valid) (((seg_valid) & 0x1U) << 31)
  210. #define APUMMU_BUILD_SEGMENT_OFFSET3(seg_valid, rsv) \
  211. ((uint32_t)APUMMU_VSID_SEGMENT_0C_SEG_VALID(seg_valid) | \
  212. APUMMU_VSID_SEGMENT_0C_RESV(rsv))
  213. #define APUMMU_INT_D2T_TBL0_OFS (0x40)
  214. #define APUSYS_TCM (0x4d100000)
  215. enum {
  216. APUMMU_THD_ID_APMCU_NORMAL = 0,
  217. APUMMU_THD_ID_TEE,
  218. };
  219. int rv_boot(uint32_t uP_seg_output, uint8_t uP_hw_thread,
  220. enum apummu_page_size logger_page_size, uint32_t XPU_seg_output,
  221. enum apummu_page_size XPU_page_size);
  222. #endif