soc.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <platform_def.h>
  7. #include <arch_helpers.h>
  8. #include <common/debug.h>
  9. #include <drivers/console.h>
  10. #include <drivers/delay_timer.h>
  11. #include <lib/mmio.h>
  12. #include <ddr_parameter.h>
  13. #include <plat_private.h>
  14. #include <rk3328_def.h>
  15. #include <soc.h>
  16. /* Table of regions to map using the MMU. */
  17. const mmap_region_t plat_rk_mmap[] = {
  18. MAP_REGION_FLAT(UART0_BASE, UART0_SIZE,
  19. MT_DEVICE | MT_RW | MT_SECURE),
  20. MAP_REGION_FLAT(UART1_BASE, UART1_SIZE,
  21. MT_DEVICE | MT_RW | MT_SECURE),
  22. MAP_REGION_FLAT(UART2_BASE, UART2_SIZE,
  23. MT_DEVICE | MT_RW | MT_SECURE),
  24. MAP_REGION_FLAT(PMU_BASE, PMU_SIZE,
  25. MT_DEVICE | MT_RW | MT_SECURE),
  26. MAP_REGION_FLAT(SGRF_BASE, SGRF_SIZE,
  27. MT_DEVICE | MT_RW | MT_SECURE),
  28. MAP_REGION_FLAT(GPIO0_BASE, GPIO0_SIZE,
  29. MT_DEVICE | MT_RW | MT_SECURE),
  30. MAP_REGION_FLAT(GPIO1_BASE, GPIO1_SIZE,
  31. MT_DEVICE | MT_RW | MT_SECURE),
  32. MAP_REGION_FLAT(GPIO2_BASE, GPIO2_SIZE,
  33. MT_DEVICE | MT_RW | MT_SECURE),
  34. MAP_REGION_FLAT(GPIO3_BASE, GPIO3_SIZE,
  35. MT_DEVICE | MT_RW | MT_SECURE),
  36. MAP_REGION_FLAT(CRU_BASE, CRU_SIZE,
  37. MT_DEVICE | MT_RW | MT_SECURE),
  38. MAP_REGION_FLAT(GRF_BASE, GRF_SIZE,
  39. MT_DEVICE | MT_RW | MT_SECURE),
  40. MAP_REGION_FLAT(FIREWALL_DDR_BASE, FIREWALL_DDR_SIZE,
  41. MT_DEVICE | MT_RW | MT_SECURE),
  42. MAP_REGION_FLAT(FIREWALL_CFG_BASE, FIREWALL_CFG_SIZE,
  43. MT_DEVICE | MT_RW | MT_SECURE),
  44. MAP_REGION_FLAT(STIME_BASE, STIME_SIZE,
  45. MT_DEVICE | MT_RW | MT_SECURE),
  46. MAP_REGION_FLAT(GIC400_BASE, GIC400_SIZE,
  47. MT_DEVICE | MT_RW | MT_SECURE),
  48. MAP_REGION_FLAT(PMUSRAM_BASE, PMUSRAM_SIZE,
  49. MT_MEMORY | MT_RW | MT_SECURE),
  50. MAP_REGION_FLAT(SHARE_MEM_BASE, SHARE_MEM_SIZE,
  51. MT_DEVICE | MT_RW | MT_SECURE),
  52. MAP_REGION_FLAT(DDR_GRF_BASE, DDR_GRF_SIZE,
  53. MT_DEVICE | MT_RW | MT_SECURE),
  54. MAP_REGION_FLAT(DDR_UPCTL_BASE, DDR_UPCTL_SIZE,
  55. MT_DEVICE | MT_RW | MT_SECURE),
  56. MAP_REGION_FLAT(PWM_BASE, PWM_SIZE,
  57. MT_DEVICE | MT_RW | MT_SECURE),
  58. MAP_REGION_FLAT(DDR_PARAM_BASE, DDR_PARAM_SIZE,
  59. MT_DEVICE | MT_RW | MT_SECURE),
  60. MAP_REGION_FLAT(EFUSE8_BASE, EFUSE8_SIZE,
  61. MT_DEVICE | MT_RW | MT_SECURE),
  62. MAP_REGION_FLAT(EFUSE32_BASE, EFUSE32_SIZE,
  63. MT_DEVICE | MT_RW | MT_SECURE),
  64. MAP_REGION_FLAT(DDR_PHY_BASE, DDR_PHY_SIZE,
  65. MT_DEVICE | MT_RW | MT_SECURE),
  66. MAP_REGION_FLAT(SERVER_MSCH_BASE, SERVER_MSCH_SIZE,
  67. MT_DEVICE | MT_RW | MT_SECURE),
  68. MAP_REGION_FLAT(DDR_MONITOR_BASE, DDR_MONITOR_SIZE,
  69. MT_DEVICE | MT_RW | MT_SECURE),
  70. MAP_REGION_FLAT(VOP_BASE, VOP_SIZE,
  71. MT_DEVICE | MT_RW | MT_SECURE),
  72. { 0 }
  73. };
  74. /* The RockChip power domain tree descriptor */
  75. const unsigned char rockchip_power_domain_tree_desc[] = {
  76. /* No of root nodes */
  77. PLATFORM_SYSTEM_COUNT,
  78. /* No of children for the root node */
  79. PLATFORM_CLUSTER_COUNT,
  80. /* No of children for the first cluster node */
  81. PLATFORM_CLUSTER0_CORE_COUNT,
  82. };
  83. void secure_timer_init(void)
  84. {
  85. mmio_write_32(STIMER_CHN_BASE(1) + TIMER_LOADE_COUNT0, 0xffffffff);
  86. mmio_write_32(STIMER_CHN_BASE(1) + TIMER_LOADE_COUNT1, 0xffffffff);
  87. /* auto reload & enable the timer */
  88. mmio_write_32(STIMER_CHN_BASE(1) + TIMER_CONTROL_REG, TIMER_EN);
  89. }
  90. void sgrf_init(void)
  91. {
  92. #ifdef PLAT_RK_SECURE_DDR_MINILOADER
  93. uint32_t i, val;
  94. struct param_ddr_usage usg;
  95. /* general secure regions */
  96. usg = ddr_region_usage_parse(DDR_PARAM_BASE,
  97. PLAT_MAX_DDR_CAPACITY_MB);
  98. for (i = 0; i < usg.s_nr; i++) {
  99. /* enable secure */
  100. val = mmio_read_32(FIREWALL_DDR_BASE +
  101. FIREWALL_DDR_FW_DDR_CON_REG);
  102. val |= BIT(7 - i);
  103. mmio_write_32(FIREWALL_DDR_BASE +
  104. FIREWALL_DDR_FW_DDR_CON_REG, val);
  105. /* map top and base */
  106. mmio_write_32(FIREWALL_DDR_BASE +
  107. FIREWALL_DDR_FW_DDR_RGN(7 - i),
  108. RG_MAP_SECURE(usg.s_top[i], usg.s_base[i]));
  109. }
  110. #endif
  111. /* set ddr rgn0_top and rga0_top as 0 */
  112. mmio_write_32(FIREWALL_DDR_BASE + FIREWALL_DDR_FW_DDR_RGN(0), 0x0);
  113. /* set all slave ip into no-secure, except stimer */
  114. mmio_write_32(FIREWALL_CFG_BASE + FIREWALL_CFG_FW_SYS_CON(0),
  115. SGRF_SLV_S_ALL_NS);
  116. mmio_write_32(FIREWALL_CFG_BASE + FIREWALL_CFG_FW_SYS_CON(1),
  117. SGRF_SLV_S_ALL_NS);
  118. mmio_write_32(FIREWALL_CFG_BASE + FIREWALL_CFG_FW_SYS_CON(2),
  119. SGRF_SLV_S_ALL_NS | STIMER_S);
  120. mmio_write_32(FIREWALL_CFG_BASE + FIREWALL_CFG_FW_SYS_CON(3),
  121. SGRF_SLV_S_ALL_NS);
  122. /* set all master ip into no-secure */
  123. mmio_write_32(SGRF_BASE + SGRF_SOC_CON(2), 0xf0000000);
  124. mmio_write_32(SGRF_BASE + SGRF_SOC_CON(3), SGRF_MST_S_ALL_NS);
  125. mmio_write_32(SGRF_BASE + SGRF_SOC_CON(4), SGRF_MST_S_ALL_NS);
  126. /* set DMAC into no-secure */
  127. mmio_write_32(SGRF_BASE + SGRF_DMAC_CON(3), DMA_IRQ_BOOT_NS);
  128. mmio_write_32(SGRF_BASE + SGRF_DMAC_CON(4), DMA_PERI_CH_NS_15_0);
  129. mmio_write_32(SGRF_BASE + SGRF_DMAC_CON(5), DMA_PERI_CH_NS_19_16);
  130. mmio_write_32(SGRF_BASE + SGRF_DMAC_CON(5), DMA_MANAGER_BOOT_NS);
  131. /* soft reset dma before use */
  132. mmio_write_32(CRU_BASE + CRU_SOFTRSTS_CON(3), DMA_SOFTRST_REQ);
  133. udelay(5);
  134. mmio_write_32(CRU_BASE + CRU_SOFTRSTS_CON(3), DMA_SOFTRST_RLS);
  135. }
  136. void plat_rockchip_soc_init(void)
  137. {
  138. secure_timer_init();
  139. sgrf_init();
  140. NOTICE("BL31:Rockchip release version: v%d.%d\n",
  141. MAJOR_VERSION, MINOR_VERSION);
  142. }