apn806_setup.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * Copyright (C) 2018 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. * https://spdx.org/licenses
  6. */
  7. /* AP806 Marvell SoC driver */
  8. #include <common/debug.h>
  9. #include <drivers/marvell/ccu.h>
  10. #include <drivers/marvell/cache_llc.h>
  11. #include <drivers/marvell/io_win.h>
  12. #include <drivers/marvell/mci.h>
  13. #include <drivers/marvell/mochi/ap_setup.h>
  14. #include <lib/mmio.h>
  15. #include <a8k_plat_def.h>
  16. #define SMMU_sACR (MVEBU_SMMU_BASE + 0x10)
  17. #define SMMU_sACR_PG_64K (1 << 16)
  18. #define CCU_GSPMU_CR (MVEBU_CCU_BASE(MVEBU_AP0) + \
  19. 0x3F0)
  20. #define GSPMU_CPU_CONTROL (0x1 << 0)
  21. #define CCU_HTC_CR (MVEBU_CCU_BASE(MVEBU_AP0) + \
  22. 0x200)
  23. #define CCU_SET_POC_OFFSET 5
  24. #define DSS_CR0 (MVEBU_RFU_BASE + 0x100)
  25. #define DVM_48BIT_VA_ENABLE (1 << 21)
  26. /* Secure MoChi incoming access */
  27. #define SEC_MOCHI_IN_ACC_REG (MVEBU_RFU_BASE + 0x4738)
  28. #define SEC_MOCHI_IN_ACC_IHB0_EN (1)
  29. #define SEC_MOCHI_IN_ACC_IHB1_EN (1 << 3)
  30. #define SEC_MOCHI_IN_ACC_IHB2_EN (1 << 6)
  31. #define SEC_MOCHI_IN_ACC_PIDI_EN (1 << 9)
  32. #define SEC_IN_ACCESS_ENA_ALL_MASTERS (SEC_MOCHI_IN_ACC_IHB0_EN | \
  33. SEC_MOCHI_IN_ACC_IHB1_EN | \
  34. SEC_MOCHI_IN_ACC_IHB2_EN | \
  35. SEC_MOCHI_IN_ACC_PIDI_EN)
  36. #define MOCHI_IN_ACC_LEVEL_FORCE_NONSEC (0)
  37. #define MOCHI_IN_ACC_LEVEL_FORCE_SEC (1)
  38. #define MOCHI_IN_ACC_LEVEL_LEAVE_ORIG (2)
  39. #define MOCHI_IN_ACC_LEVEL_MASK_ALL (3)
  40. #define SEC_MOCHI_IN_ACC_IHB0_LEVEL(l) ((l) << 1)
  41. #define SEC_MOCHI_IN_ACC_IHB1_LEVEL(l) ((l) << 4)
  42. #define SEC_MOCHI_IN_ACC_PIDI_LEVEL(l) ((l) << 10)
  43. /* SYSRST_OUTn Config definitions */
  44. #define MVEBU_SYSRST_OUT_CONFIG_REG (MVEBU_MISC_SOC_BASE + 0x4)
  45. #define WD_MASK_SYS_RST_OUT (1 << 2)
  46. /* Generic Timer System Controller */
  47. #define MVEBU_MSS_GTCR_REG (MVEBU_REGS_BASE + 0x581000)
  48. #define MVEBU_MSS_GTCR_ENABLE_BIT 0x1
  49. /*
  50. * AXI Configuration.
  51. */
  52. /* Used for Units of AP-806 (e.g. SDIO and etc) */
  53. #define MVEBU_AXI_ATTR_BASE (MVEBU_REGS_BASE + 0x6F4580)
  54. #define MVEBU_AXI_ATTR_REG(index) (MVEBU_AXI_ATTR_BASE + \
  55. 0x4 * index)
  56. #define XOR_STREAM_ID_REG(ch) (MVEBU_REGS_BASE + 0x410010 + (ch) * 0x20000)
  57. #define XOR_STREAM_ID_MASK 0xFFFF
  58. #define SDIO_STREAM_ID_REG (MVEBU_RFU_BASE + 0x4600)
  59. #define SDIO_STREAM_ID_MASK 0xFF
  60. /* Do not use the default Stream ID 0 */
  61. #define A806_STREAM_ID_BASE (0x1)
  62. static uintptr_t stream_id_reg[] = {
  63. XOR_STREAM_ID_REG(0),
  64. XOR_STREAM_ID_REG(1),
  65. XOR_STREAM_ID_REG(2),
  66. XOR_STREAM_ID_REG(3),
  67. SDIO_STREAM_ID_REG,
  68. 0
  69. };
  70. enum axi_attr {
  71. AXI_SDIO_ATTR = 0,
  72. AXI_DFX_ATTR,
  73. AXI_MAX_ATTR,
  74. };
  75. static void apn_sec_masters_access_en(uint32_t enable)
  76. {
  77. /* Open/Close incoming access for all masters.
  78. * The access is disabled in trusted boot mode
  79. * Could only be done in EL3
  80. */
  81. if (enable != 0) {
  82. mmio_clrsetbits_32(SEC_MOCHI_IN_ACC_REG, 0x0U, /* no clear */
  83. SEC_IN_ACCESS_ENA_ALL_MASTERS);
  84. #if LLC_SRAM
  85. /* Do not change access security level
  86. * for PIDI masters
  87. */
  88. mmio_clrsetbits_32(SEC_MOCHI_IN_ACC_REG,
  89. SEC_MOCHI_IN_ACC_PIDI_LEVEL(
  90. MOCHI_IN_ACC_LEVEL_MASK_ALL),
  91. SEC_MOCHI_IN_ACC_PIDI_LEVEL(
  92. MOCHI_IN_ACC_LEVEL_LEAVE_ORIG));
  93. #endif
  94. } else {
  95. mmio_clrsetbits_32(SEC_MOCHI_IN_ACC_REG,
  96. SEC_IN_ACCESS_ENA_ALL_MASTERS,
  97. 0x0U /* no set */);
  98. #if LLC_SRAM
  99. /* Return PIDI access level to the default */
  100. mmio_clrsetbits_32(SEC_MOCHI_IN_ACC_REG,
  101. SEC_MOCHI_IN_ACC_PIDI_LEVEL(
  102. MOCHI_IN_ACC_LEVEL_MASK_ALL),
  103. SEC_MOCHI_IN_ACC_PIDI_LEVEL(
  104. MOCHI_IN_ACC_LEVEL_FORCE_NONSEC));
  105. #endif
  106. }
  107. }
  108. static void setup_smmu(void)
  109. {
  110. uint32_t reg;
  111. /* Set the SMMU page size to 64 KB */
  112. reg = mmio_read_32(SMMU_sACR);
  113. reg |= SMMU_sACR_PG_64K;
  114. mmio_write_32(SMMU_sACR, reg);
  115. }
  116. static void init_aurora2(void)
  117. {
  118. uint32_t reg;
  119. /* Enable GSPMU control by CPU */
  120. reg = mmio_read_32(CCU_GSPMU_CR);
  121. reg |= GSPMU_CPU_CONTROL;
  122. mmio_write_32(CCU_GSPMU_CR, reg);
  123. #if LLC_ENABLE
  124. /* Enable LLC for AP806 in exclusive mode */
  125. llc_enable(0, 1);
  126. /* Set point of coherency to DDR.
  127. * This is required by units which have
  128. * SW cache coherency
  129. */
  130. reg = mmio_read_32(CCU_HTC_CR);
  131. reg |= (0x1 << CCU_SET_POC_OFFSET);
  132. mmio_write_32(CCU_HTC_CR, reg);
  133. #endif /* LLC_ENABLE */
  134. errata_wa_init();
  135. }
  136. /* MCIx indirect access register are based by default at 0xf4000000/0xf6000000
  137. * to avoid conflict of internal registers of units connected via MCIx, which
  138. * can be based on the same address (i.e CP1 base is also 0xf4000000),
  139. * the following routines remaps the MCIx indirect bases to another domain
  140. */
  141. static void mci_remap_indirect_access_base(void)
  142. {
  143. uint32_t mci;
  144. for (mci = 0; mci < MCI_MAX_UNIT_ID; mci++)
  145. mmio_write_32(MCIX4_REG_START_ADDRESS_REG(mci),
  146. MVEBU_MCI_REG_BASE_REMAP(mci) >>
  147. MCI_REMAP_OFF_SHIFT);
  148. }
  149. /* Set a unique stream id for all DMA capable devices */
  150. static void ap806_stream_id_init(void)
  151. {
  152. int i;
  153. for (i = 0; stream_id_reg[i] != 0; i++) {
  154. uint32_t mask = stream_id_reg[i] == SDIO_STREAM_ID_REG ?
  155. SDIO_STREAM_ID_MASK : XOR_STREAM_ID_MASK;
  156. mmio_clrsetbits_32(stream_id_reg[i], mask,
  157. i + A806_STREAM_ID_BASE);
  158. }
  159. }
  160. static void apn806_axi_attr_init(void)
  161. {
  162. uint32_t index, data;
  163. /* Initialize AXI attributes for APN806 */
  164. /* Go over the AXI attributes and set Ax-Cache and Ax-Domain */
  165. for (index = 0; index < AXI_MAX_ATTR; index++) {
  166. switch (index) {
  167. /* DFX works with no coherent only -
  168. * there's no option to configure the Ax-Cache and Ax-Domain
  169. */
  170. case AXI_DFX_ATTR:
  171. continue;
  172. default:
  173. /* Set Ax-Cache as cacheable, no allocate, modifiable,
  174. * bufferable
  175. * The values are different because Read & Write
  176. * definition is different in Ax-Cache
  177. */
  178. data = mmio_read_32(MVEBU_AXI_ATTR_REG(index));
  179. data &= ~MVEBU_AXI_ATTR_ARCACHE_MASK;
  180. data |= (CACHE_ATTR_WRITE_ALLOC |
  181. CACHE_ATTR_CACHEABLE |
  182. CACHE_ATTR_BUFFERABLE) <<
  183. MVEBU_AXI_ATTR_ARCACHE_OFFSET;
  184. data &= ~MVEBU_AXI_ATTR_AWCACHE_MASK;
  185. data |= (CACHE_ATTR_READ_ALLOC |
  186. CACHE_ATTR_CACHEABLE |
  187. CACHE_ATTR_BUFFERABLE) <<
  188. MVEBU_AXI_ATTR_AWCACHE_OFFSET;
  189. /* Set Ax-Domain as Outer domain */
  190. data &= ~MVEBU_AXI_ATTR_ARDOMAIN_MASK;
  191. data |= DOMAIN_OUTER_SHAREABLE <<
  192. MVEBU_AXI_ATTR_ARDOMAIN_OFFSET;
  193. data &= ~MVEBU_AXI_ATTR_AWDOMAIN_MASK;
  194. data |= DOMAIN_OUTER_SHAREABLE <<
  195. MVEBU_AXI_ATTR_AWDOMAIN_OFFSET;
  196. mmio_write_32(MVEBU_AXI_ATTR_REG(index), data);
  197. }
  198. }
  199. }
  200. static void dss_setup(void)
  201. {
  202. /* Enable 48-bit VA */
  203. mmio_setbits_32(DSS_CR0, DVM_48BIT_VA_ENABLE);
  204. }
  205. void misc_soc_configurations(void)
  206. {
  207. uint32_t reg;
  208. /* Un-mask Watchdog reset from influencing the SYSRST_OUTn.
  209. * Otherwise, upon WD timeout, the WD reset signal won't trigger reset
  210. */
  211. reg = mmio_read_32(MVEBU_SYSRST_OUT_CONFIG_REG);
  212. reg &= ~(WD_MASK_SYS_RST_OUT);
  213. mmio_write_32(MVEBU_SYSRST_OUT_CONFIG_REG, reg);
  214. }
  215. void ap_init(void)
  216. {
  217. /* Setup Aurora2. */
  218. init_aurora2();
  219. /* configure MCI mapping */
  220. mci_remap_indirect_access_base();
  221. /* configure IO_WIN windows */
  222. init_io_win(MVEBU_AP0);
  223. /* configure CCU windows */
  224. init_ccu(MVEBU_AP0);
  225. /* configure DSS */
  226. dss_setup();
  227. /* Set the stream IDs for DMA masters */
  228. ap806_stream_id_init();
  229. /* configure the SMMU */
  230. setup_smmu();
  231. /* Open APN incoming access for all masters */
  232. apn_sec_masters_access_en(1);
  233. /* configure axi for APN*/
  234. apn806_axi_attr_init();
  235. /* misc configuration of the SoC */
  236. misc_soc_configurations();
  237. }
  238. void ap_ble_init(void)
  239. {
  240. }
  241. int ap_get_count(void)
  242. {
  243. return 1;
  244. }
  245. void update_cp110_default_win(int cp_id)
  246. {
  247. }