bl31_plat_setup.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <common/bl_common.h>
  8. #include <common/debug.h>
  9. #include <common/desc_image_load.h>
  10. #include <drivers/generic_delay_timer.h>
  11. #include <drivers/ti/uart/uart_16550.h>
  12. #include <lib/mmio.h>
  13. #include <plat/arm/common/plat_arm.h>
  14. #include <plat/common/common_def.h>
  15. #include <plat/common/platform.h>
  16. #include <mcucfg.h>
  17. #include <mtcmos.h>
  18. #include <mtk_plat_common.h>
  19. #include <plat_private.h>
  20. #include <spm.h>
  21. static entry_point_info_t bl32_ep_info;
  22. static entry_point_info_t bl33_ep_info;
  23. static void platform_setup_cpu(void)
  24. {
  25. /* turn off all the little core's power except cpu 0 */
  26. mtcmos_little_cpu_off();
  27. /* setup big cores */
  28. mmio_write_32((uintptr_t)&mt8173_mcucfg->mp1_config_res,
  29. MP1_DIS_RGU0_WAIT_PD_CPUS_L1_ACK |
  30. MP1_DIS_RGU1_WAIT_PD_CPUS_L1_ACK |
  31. MP1_DIS_RGU2_WAIT_PD_CPUS_L1_ACK |
  32. MP1_DIS_RGU3_WAIT_PD_CPUS_L1_ACK |
  33. MP1_DIS_RGU_NOCPU_WAIT_PD_CPUS_L1_ACK);
  34. mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_miscdbg, MP1_AINACTS);
  35. mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_clkenm_div,
  36. MP1_SW_CG_GEN);
  37. mmio_clrbits_32((uintptr_t)&mt8173_mcucfg->mp1_rst_ctl,
  38. MP1_L2RSTDISABLE);
  39. /* set big cores arm64 boot mode */
  40. mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp1_cpucfg,
  41. MP1_CPUCFG_64BIT);
  42. /* set LITTLE cores arm64 boot mode */
  43. mmio_setbits_32((uintptr_t)&mt8173_mcucfg->mp0_rv_addr[0].rv_addr_hw,
  44. MP0_CPUCFG_64BIT);
  45. /* enable dcm control */
  46. mmio_setbits_32((uintptr_t)&mt8173_mcucfg->bus_fabric_dcm_ctrl,
  47. ADB400_GRP_DCM_EN | CCI400_GRP_DCM_EN | ADBCLK_GRP_DCM_EN |
  48. EMICLK_GRP_DCM_EN | ACLK_GRP_DCM_EN | L2C_IDLE_DCM_EN |
  49. INFRACLK_PSYS_DYNAMIC_CG_EN);
  50. mmio_setbits_32((uintptr_t)&mt8173_mcucfg->l2c_sram_ctrl,
  51. L2C_SRAM_DCM_EN);
  52. mmio_setbits_32((uintptr_t)&mt8173_mcucfg->cci_clk_ctrl,
  53. MCU_BUS_DCM_EN);
  54. }
  55. static void platform_setup_sram(void)
  56. {
  57. /* protect BL31 memory from non-secure read/write access */
  58. mmio_write_32(SRAMROM_SEC_ADDR, (uint32_t)(BL31_END + 0x3ff) & 0x3fc00);
  59. mmio_write_32(SRAMROM_SEC_CTRL, 0x10000ff9);
  60. }
  61. /*******************************************************************************
  62. * Return a pointer to the 'entry_point_info' structure of the next image for
  63. * the security state specified. BL33 corresponds to the non-secure image type
  64. * while BL32 corresponds to the secure image type. A NULL pointer is returned
  65. * if the image does not exist.
  66. ******************************************************************************/
  67. entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
  68. {
  69. entry_point_info_t *next_image_info;
  70. next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info;
  71. assert(next_image_info->h.type == PARAM_EP);
  72. /* None of the images on this platform can have 0x0 as the entrypoint */
  73. if (next_image_info->pc)
  74. return next_image_info;
  75. else
  76. return NULL;
  77. }
  78. /*******************************************************************************
  79. * Perform any BL3-1 early platform setup. Here is an opportunity to copy
  80. * parameters passed by the calling EL (S-EL1 in BL2 & EL3 in BL1) before they
  81. * are lost (potentially). This needs to be done before the MMU is initialized
  82. * so that the memory layout can be used while creating page tables.
  83. * BL2 has flushed this information to memory, so we are guaranteed to pick up
  84. * good data.
  85. ******************************************************************************/
  86. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  87. u_register_t arg2, u_register_t arg3)
  88. {
  89. static console_t console;
  90. console_16550_register(MT8173_UART0_BASE, MT8173_UART_CLOCK, MT8173_BAUDRATE, &console);
  91. VERBOSE("bl31_setup\n");
  92. bl31_params_parse_helper(arg0, &bl32_ep_info, &bl33_ep_info);
  93. }
  94. /*******************************************************************************
  95. * Perform any BL3-1 platform setup code
  96. ******************************************************************************/
  97. void bl31_platform_setup(void)
  98. {
  99. platform_setup_cpu();
  100. platform_setup_sram();
  101. generic_delay_timer_init();
  102. /* Initialize the gic cpu and distributor interfaces */
  103. plat_arm_gic_driver_init();
  104. plat_arm_gic_init();
  105. /* Initialize spm at boot time */
  106. spm_boot_init();
  107. }
  108. /*******************************************************************************
  109. * Perform the very early platform specific architectural setup here. At the
  110. * moment this is only initializes the mmu in a quick and dirty way.
  111. ******************************************************************************/
  112. void bl31_plat_arch_setup(void)
  113. {
  114. plat_cci_init();
  115. plat_cci_enable();
  116. plat_configure_mmu_el3(BL_CODE_BASE,
  117. BL_COHERENT_RAM_END - BL_CODE_BASE,
  118. BL_CODE_BASE,
  119. BL_CODE_END,
  120. BL_COHERENT_RAM_BASE,
  121. BL_COHERENT_RAM_END);
  122. }