plat_setup.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <arch_helpers.h>
  8. #include <assert.h>
  9. #include <cortex_a57.h>
  10. #include <common/bl_common.h>
  11. #include <common/debug.h>
  12. #include <common/interrupt_props.h>
  13. #include <drivers/console.h>
  14. #include <lib/xlat_tables/xlat_tables_v2.h>
  15. #include <drivers/arm/gic_common.h>
  16. #include <drivers/arm/gicv2.h>
  17. #include <bl31/interrupt_mgmt.h>
  18. #include <bpmp.h>
  19. #include <flowctrl.h>
  20. #include <memctrl.h>
  21. #include <plat/common/platform.h>
  22. #include <security_engine.h>
  23. #include <tegra_def.h>
  24. #include <tegra_platform.h>
  25. #include <tegra_private.h>
  26. /* sets of MMIO ranges setup */
  27. #define MMIO_RANGE_0_ADDR 0x50000000
  28. #define MMIO_RANGE_1_ADDR 0x60000000
  29. #define MMIO_RANGE_2_ADDR 0x70000000
  30. #define MMIO_RANGE_SIZE 0x200000
  31. /*
  32. * Table of regions to map using the MMU.
  33. */
  34. static const mmap_region_t tegra_mmap[] = {
  35. MAP_REGION_FLAT(TEGRA_IRAM_BASE, 0x40000, /* 256KB */
  36. MT_DEVICE | MT_RW | MT_SECURE),
  37. MAP_REGION_FLAT(MMIO_RANGE_0_ADDR, MMIO_RANGE_SIZE,
  38. MT_DEVICE | MT_RW | MT_SECURE),
  39. MAP_REGION_FLAT(MMIO_RANGE_1_ADDR, MMIO_RANGE_SIZE,
  40. MT_DEVICE | MT_RW | MT_SECURE),
  41. MAP_REGION_FLAT(MMIO_RANGE_2_ADDR, MMIO_RANGE_SIZE,
  42. MT_DEVICE | MT_RW | MT_SECURE),
  43. {0}
  44. };
  45. /*******************************************************************************
  46. * Set up the pagetables as per the platform memory map & initialize the MMU
  47. ******************************************************************************/
  48. const mmap_region_t *plat_get_mmio_map(void)
  49. {
  50. /* Add the map region for security engine SE2 */
  51. if (tegra_chipid_is_t210_b01()) {
  52. mmap_add_region((uint64_t)TEGRA_SE2_BASE,
  53. (uint64_t)TEGRA_SE2_BASE,
  54. (uint64_t)TEGRA_SE2_RANGE_SIZE,
  55. MT_DEVICE | MT_RW | MT_SECURE);
  56. }
  57. /* MMIO space */
  58. return tegra_mmap;
  59. }
  60. /*******************************************************************************
  61. * The Tegra power domain tree has a single system level power domain i.e. a
  62. * single root node. The first entry in the power domain descriptor specifies
  63. * the number of power domains at the highest power level.
  64. *******************************************************************************
  65. */
  66. const unsigned char tegra_power_domain_tree_desc[] = {
  67. /* No of root nodes */
  68. 1,
  69. /* No of clusters */
  70. PLATFORM_CLUSTER_COUNT,
  71. /* No of CPU cores - cluster0 */
  72. PLATFORM_MAX_CPUS_PER_CLUSTER,
  73. /* No of CPU cores - cluster1 */
  74. PLATFORM_MAX_CPUS_PER_CLUSTER
  75. };
  76. /*******************************************************************************
  77. * This function returns the Tegra default topology tree information.
  78. ******************************************************************************/
  79. const unsigned char *plat_get_power_domain_tree_desc(void)
  80. {
  81. return tegra_power_domain_tree_desc;
  82. }
  83. /*******************************************************************************
  84. * Handler to get the System Counter Frequency
  85. ******************************************************************************/
  86. unsigned int plat_get_syscnt_freq2(void)
  87. {
  88. return 19200000;
  89. }
  90. /*******************************************************************************
  91. * Maximum supported UART controllers
  92. ******************************************************************************/
  93. #define TEGRA210_MAX_UART_PORTS 5
  94. /*******************************************************************************
  95. * This variable holds the UART port base addresses
  96. ******************************************************************************/
  97. static uint32_t tegra210_uart_addresses[TEGRA210_MAX_UART_PORTS + 1] = {
  98. 0, /* undefined - treated as an error case */
  99. TEGRA_UARTA_BASE,
  100. TEGRA_UARTB_BASE,
  101. TEGRA_UARTC_BASE,
  102. TEGRA_UARTD_BASE,
  103. TEGRA_UARTE_BASE,
  104. };
  105. /*******************************************************************************
  106. * Enable console corresponding to the console ID
  107. ******************************************************************************/
  108. void plat_enable_console(int32_t id)
  109. {
  110. static console_t uart_console;
  111. uint32_t console_clock;
  112. if ((id > 0) && (id < TEGRA210_MAX_UART_PORTS)) {
  113. /*
  114. * Reference clock used by the FPGAs is a lot slower.
  115. */
  116. if (tegra_platform_is_fpga()) {
  117. console_clock = TEGRA_BOOT_UART_CLK_13_MHZ;
  118. } else {
  119. console_clock = TEGRA_BOOT_UART_CLK_408_MHZ;
  120. }
  121. (void)console_16550_register(tegra210_uart_addresses[id],
  122. console_clock,
  123. TEGRA_CONSOLE_BAUDRATE,
  124. &uart_console);
  125. console_set_scope(&uart_console, CONSOLE_FLAG_BOOT |
  126. CONSOLE_FLAG_RUNTIME | CONSOLE_FLAG_CRASH);
  127. }
  128. }
  129. /*******************************************************************************
  130. * Return pointer to the BL31 params from previous bootloader
  131. ******************************************************************************/
  132. struct tegra_bl31_params *plat_get_bl31_params(void)
  133. {
  134. return NULL;
  135. }
  136. /*******************************************************************************
  137. * Return pointer to the BL31 platform params from previous bootloader
  138. ******************************************************************************/
  139. plat_params_from_bl2_t *plat_get_bl31_plat_params(void)
  140. {
  141. return NULL;
  142. }
  143. /*******************************************************************************
  144. * Handler for early platform setup
  145. ******************************************************************************/
  146. void plat_early_platform_setup(void)
  147. {
  148. const plat_params_from_bl2_t *plat_params = bl31_get_plat_params();
  149. uint64_t val;
  150. /* Verify chip id is t210 */
  151. assert(tegra_chipid_is_t210());
  152. /*
  153. * Do initial security configuration to allow DRAM/device access.
  154. */
  155. tegra_memctrl_tzdram_setup(plat_params->tzdram_base,
  156. (uint32_t)plat_params->tzdram_size);
  157. /* platform parameter passed by the previous bootloader */
  158. if (plat_params->l2_ecc_parity_prot_dis != 1) {
  159. /* Enable ECC Parity Protection for Cortex-A57 CPUs */
  160. val = read_l2ctlr_el1();
  161. val |= (uint64_t)CORTEX_A57_L2_ECC_PARITY_PROTECTION_BIT;
  162. write_l2ctlr_el1(val);
  163. }
  164. /* Initialize security engine driver */
  165. tegra_se_init();
  166. }
  167. /* Secure IRQs for Tegra186 */
  168. static const interrupt_prop_t tegra210_interrupt_props[] = {
  169. INTR_PROP_DESC(TEGRA_SDEI_SGI_PRIVATE, PLAT_SDEI_CRITICAL_PRI,
  170. GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
  171. INTR_PROP_DESC(TEGRA210_TIMER1_IRQ, PLAT_TEGRA_WDT_PRIO,
  172. GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
  173. INTR_PROP_DESC(TEGRA210_WDT_CPU_LEGACY_FIQ, PLAT_TEGRA_WDT_PRIO,
  174. GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
  175. };
  176. /*******************************************************************************
  177. * Handler for late platform setup
  178. ******************************************************************************/
  179. void plat_late_platform_setup(void)
  180. {
  181. const plat_params_from_bl2_t *plat_params = bl31_get_plat_params();
  182. uint64_t sc7entry_end, offset;
  183. int ret;
  184. uint32_t val;
  185. /* memmap TZDRAM area containing the SC7 Entry Firmware */
  186. if (plat_params->sc7entry_fw_base && plat_params->sc7entry_fw_size) {
  187. assert(plat_params->sc7entry_fw_size <= TEGRA_IRAM_A_SIZE);
  188. /*
  189. * Verify that the SC7 entry firmware resides inside the TZDRAM
  190. * aperture, _before_ the BL31 code and the start address is
  191. * exactly 1MB from BL31 base.
  192. */
  193. /* sc7entry-fw must be _before_ BL31 base */
  194. assert(plat_params->tzdram_base > plat_params->sc7entry_fw_base);
  195. sc7entry_end = plat_params->sc7entry_fw_base +
  196. plat_params->sc7entry_fw_size;
  197. assert(sc7entry_end < plat_params->tzdram_base);
  198. /* sc7entry-fw start must be exactly 1MB behind BL31 base */
  199. offset = plat_params->tzdram_base - plat_params->sc7entry_fw_base;
  200. assert(offset == 0x100000);
  201. /* secure TZDRAM area */
  202. tegra_memctrl_tzdram_setup(plat_params->sc7entry_fw_base,
  203. plat_params->tzdram_size + offset);
  204. /* power off BPMP processor until SC7 entry */
  205. tegra_fc_bpmp_off();
  206. /* memmap SC7 entry firmware code */
  207. ret = mmap_add_dynamic_region(plat_params->sc7entry_fw_base,
  208. plat_params->sc7entry_fw_base,
  209. plat_params->sc7entry_fw_size,
  210. MT_SECURE | MT_RO_DATA);
  211. assert(ret == 0);
  212. /* restrict PMC access to secure world */
  213. val = mmio_read_32(TEGRA_MISC_BASE + APB_SLAVE_SECURITY_ENABLE);
  214. val |= PMC_SECURITY_EN_BIT;
  215. mmio_write_32(TEGRA_MISC_BASE + APB_SLAVE_SECURITY_ENABLE, val);
  216. }
  217. if (!tegra_chipid_is_t210_b01()) {
  218. /* restrict PMC access to secure world */
  219. val = mmio_read_32(TEGRA_MISC_BASE + APB_SLAVE_SECURITY_ENABLE);
  220. val |= PMC_SECURITY_EN_BIT;
  221. mmio_write_32(TEGRA_MISC_BASE + APB_SLAVE_SECURITY_ENABLE, val);
  222. }
  223. }
  224. /*******************************************************************************
  225. * Initialize the GIC and SGIs
  226. ******************************************************************************/
  227. void plat_gic_setup(void)
  228. {
  229. tegra_gic_setup(tegra210_interrupt_props, ARRAY_SIZE(tegra210_interrupt_props));
  230. tegra_gic_init();
  231. /* Enable handling for FIQs */
  232. tegra_fiq_handler_setup();
  233. /*
  234. * Enable routing watchdog FIQs from the flow controller to
  235. * the GICD.
  236. */
  237. tegra_fc_enable_fiq_to_ccplex_routing();
  238. }
  239. /*******************************************************************************
  240. * Handler to indicate support for System Suspend
  241. ******************************************************************************/
  242. bool plat_supports_system_suspend(void)
  243. {
  244. const plat_params_from_bl2_t *plat_params = bl31_get_plat_params();
  245. /*
  246. * sc7entry-fw is only supported by Tegra210 SoCs.
  247. */
  248. if (!tegra_chipid_is_t210_b01() && (plat_params->sc7entry_fw_base != 0U)) {
  249. return true;
  250. } else if (tegra_chipid_is_t210_b01()) {
  251. return true;
  252. } else {
  253. return false;
  254. }
  255. }
  256. /*******************************************************************************
  257. * Platform specific runtime setup.
  258. ******************************************************************************/
  259. void plat_runtime_setup(void)
  260. {
  261. /*
  262. * During cold boot, it is observed that the arbitration
  263. * bit is set in the Memory controller leading to false
  264. * error interrupts in the non-secure world. To avoid
  265. * this, clean the interrupt status register before
  266. * booting into the non-secure world
  267. */
  268. tegra_memctrl_clear_pending_interrupts();
  269. /*
  270. * During boot, USB3 and flash media (SDMMC/SATA) devices need
  271. * access to IRAM. Because these clients connect to the MC and
  272. * do not have a direct path to the IRAM, the MC implements AHB
  273. * redirection during boot to allow path to IRAM. In this mode
  274. * accesses to a programmed memory address aperture are directed
  275. * to the AHB bus, allowing access to the IRAM. This mode must be
  276. * disabled before we jump to the non-secure world.
  277. */
  278. tegra_memctrl_disable_ahb_redirection();
  279. }