bl31_plat_setup.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 2017-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <inttypes.h>
  9. #include <stddef.h>
  10. #include <stdint.h>
  11. #include <string.h>
  12. #include <platform_def.h>
  13. #include <arch.h>
  14. #include <arch_helpers.h>
  15. #include <bl31/bl31.h>
  16. #include <common/bl_common.h>
  17. #include <common/debug.h>
  18. #include <cortex_a53.h>
  19. #include <drivers/arm/pl011.h>
  20. #include <drivers/generic_delay_timer.h>
  21. #include <lib/mmio.h>
  22. #include <plat/common/platform.h>
  23. #include "hi3798cv200.h"
  24. #include "plat_private.h"
  25. #define TZPC_SEC_ATTR_CTRL_VALUE (0x9DB98D45)
  26. static entry_point_info_t bl32_image_ep_info;
  27. static entry_point_info_t bl33_image_ep_info;
  28. static console_t console;
  29. static void hisi_tzpc_sec_init(void)
  30. {
  31. mmio_write_32(HISI_TZPC_SEC_ATTR_CTRL, TZPC_SEC_ATTR_CTRL_VALUE);
  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. assert(sec_state_is_valid(type));
  37. next_image_info = (type == NON_SECURE)
  38. ? &bl33_image_ep_info : &bl32_image_ep_info;
  39. /*
  40. * None of the images on the ARM development platforms can have 0x0
  41. * as the entrypoint
  42. */
  43. if (next_image_info->pc)
  44. return next_image_info;
  45. else
  46. return NULL;
  47. }
  48. /*******************************************************************************
  49. * Perform any BL31 early platform setup common to ARM standard platforms.
  50. * Here is an opportunity to copy parameters passed by the calling EL (S-EL1
  51. * in BL2 & EL3 in BL1) before they are lost (potentially). This needs to be
  52. * done before the MMU is initialized so that the memory layout can be used
  53. * while creating page tables. BL2 has flushed this information to memory, so
  54. * we are guaranteed to pick up good data.
  55. ******************************************************************************/
  56. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  57. u_register_t arg2, u_register_t arg3)
  58. {
  59. void *from_bl2;
  60. from_bl2 = (void *) arg0;
  61. console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ,
  62. PL011_BAUDRATE, &console);
  63. /* Init console for crash report */
  64. plat_crash_console_init();
  65. /*
  66. * Check params passed from BL2 should not be NULL,
  67. */
  68. bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
  69. assert(params_from_bl2 != NULL);
  70. assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
  71. assert(params_from_bl2->h.version >= VERSION_2);
  72. bl_params_node_t *bl_params = params_from_bl2->head;
  73. /*
  74. * Copy BL33 and BL32 (if present), entry point information.
  75. * They are stored in Secure RAM, in BL2's address space.
  76. */
  77. while (bl_params) {
  78. if (bl_params->image_id == BL32_IMAGE_ID)
  79. bl32_image_ep_info = *bl_params->ep_info;
  80. if (bl_params->image_id == BL33_IMAGE_ID)
  81. bl33_image_ep_info = *bl_params->ep_info;
  82. bl_params = bl_params->next_params_info;
  83. }
  84. if (bl33_image_ep_info.pc == 0)
  85. panic();
  86. }
  87. void bl31_platform_setup(void)
  88. {
  89. /* Init arch timer */
  90. generic_delay_timer_init();
  91. /* Init GIC distributor and CPU interface */
  92. poplar_gic_driver_init();
  93. poplar_gic_init();
  94. /* Init security properties of IP blocks */
  95. hisi_tzpc_sec_init();
  96. }
  97. void bl31_plat_arch_setup(void)
  98. {
  99. plat_configure_mmu_el3(BL31_BASE,
  100. (BL31_LIMIT - BL31_BASE),
  101. BL_CODE_BASE,
  102. BL_CODE_END,
  103. BL_COHERENT_RAM_BASE,
  104. BL_COHERENT_RAM_END);
  105. INFO("Boot BL33 from 0x%lx for %" PRIu64 " Bytes\n",
  106. bl33_image_ep_info.pc, bl33_image_ep_info.args.arg2);
  107. }