bl31_plat_setup.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2020, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /* System Includes */
  7. #include <assert.h>
  8. /* Project Includes */
  9. #include <common/bl_common.h>
  10. #include <common/debug.h>
  11. #include <common/desc_image_load.h>
  12. #include <drivers/generic_delay_timer.h>
  13. #include <drivers/ti/uart/uart_16550.h>
  14. #include <lib/coreboot.h>
  15. /* Platform Includes */
  16. #include <devapc/devapc.h>
  17. #include <emi_mpu/emi_mpu.h>
  18. #include <gpio/mtgpio.h>
  19. #include <mt_gic_v3.h>
  20. #include <mt_spm.h>
  21. #include <mt_timer.h>
  22. #include <mtk_dcm.h>
  23. #include <plat_params.h>
  24. #include <plat_private.h>
  25. static entry_point_info_t bl32_ep_info;
  26. static entry_point_info_t bl33_ep_info;
  27. /*******************************************************************************
  28. * Return a pointer to the 'entry_point_info' structure of the next image for
  29. * the security state specified. BL33 corresponds to the non-secure image type
  30. * while BL32 corresponds to the secure image type. A NULL pointer is returned
  31. * if the image does not exist.
  32. ******************************************************************************/
  33. entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
  34. {
  35. entry_point_info_t *next_image_info;
  36. next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info;
  37. assert(next_image_info->h.type == PARAM_EP);
  38. /* None of the images on this platform can have 0x0 as the entrypoint */
  39. if (next_image_info->pc) {
  40. return next_image_info;
  41. } else {
  42. return NULL;
  43. }
  44. }
  45. /*******************************************************************************
  46. * Perform any BL31 early platform setup. Here is an opportunity to copy
  47. * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they
  48. * are lost (potentially). This needs to be done before the MMU is initialized
  49. * so that the memory layout can be used while creating page tables.
  50. * BL2 has flushed this information to memory, so we are guaranteed to pick up
  51. * good data.
  52. ******************************************************************************/
  53. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  54. u_register_t arg2, u_register_t arg3)
  55. {
  56. static console_t console;
  57. params_early_setup(arg1);
  58. #if COREBOOT
  59. if (coreboot_serial.type) {
  60. console_16550_register(coreboot_serial.baseaddr,
  61. coreboot_serial.input_hertz,
  62. coreboot_serial.baud,
  63. &console);
  64. }
  65. #else
  66. console_16550_register(UART0_BASE, UART_CLOCK, UART_BAUDRATE, &console);
  67. #endif
  68. NOTICE("MT8192 bl31_setup\n");
  69. bl31_params_parse_helper(arg0, &bl32_ep_info, &bl33_ep_info);
  70. }
  71. /*******************************************************************************
  72. * Perform any BL31 platform setup code
  73. ******************************************************************************/
  74. void bl31_platform_setup(void)
  75. {
  76. /* Set dcm on */
  77. if (!dcm_set_default()) {
  78. ERROR("Failed to set default dcm on!!\n");
  79. }
  80. /* MPU Init */
  81. emi_mpu_init();
  82. /* DAPC Init */
  83. devapc_init();
  84. /* Initialize the GIC driver, CPU and distributor interfaces */
  85. mt_gic_driver_init();
  86. mt_gic_init();
  87. mt_gpio_init();
  88. mt_systimer_init();
  89. generic_delay_timer_init();
  90. spm_boot_init();
  91. }
  92. /*******************************************************************************
  93. * Perform the very early platform specific architectural setup here. At the
  94. * moment this is only intializes the mmu in a quick and dirty way.
  95. ******************************************************************************/
  96. void bl31_plat_arch_setup(void)
  97. {
  98. plat_configure_mmu_el3(BL31_START,
  99. BL31_END - BL31_START,
  100. BL_CODE_BASE,
  101. BL_CODE_END);
  102. }