brcm_bl2_setup.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (c) 2019-2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <string.h>
  8. #include <arch_helpers.h>
  9. #include <common/bl_common.h>
  10. #include <common/debug.h>
  11. #include <common/desc_image_load.h>
  12. #include <drivers/arm/sp804_delay_timer.h>
  13. #include <lib/mmio.h>
  14. #include <bcm_console.h>
  15. #include <platform_def.h>
  16. #include <plat/brcm/common/plat_brcm.h>
  17. /* Data structure which holds the extents of the trusted SRAM for BL2 */
  18. static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
  19. /* Weak definitions may be overridden in specific BRCM platform */
  20. #pragma weak plat_bcm_bl2_platform_setup
  21. #pragma weak plat_bcm_bl2_plat_arch_setup
  22. #pragma weak plat_bcm_security_setup
  23. #pragma weak plat_bcm_bl2_plat_handle_scp_bl2
  24. #pragma weak plat_bcm_bl2_early_platform_setup
  25. void plat_bcm_bl2_early_platform_setup(void)
  26. {
  27. }
  28. void plat_bcm_bl2_platform_setup(void)
  29. {
  30. }
  31. void plat_bcm_bl2_plat_arch_setup(void)
  32. {
  33. }
  34. void plat_bcm_security_setup(void)
  35. {
  36. }
  37. void bcm_bl2_early_platform_setup(uintptr_t tb_fw_config,
  38. meminfo_t *mem_layout)
  39. {
  40. /* Initialize the console to provide early debug support */
  41. bcm_console_boot_init();
  42. /* Setup the BL2 memory layout */
  43. bl2_tzram_layout = *mem_layout;
  44. /* Initialise the IO layer and register platform IO devices */
  45. plat_brcm_io_setup();
  46. /* Log HW reset event */
  47. INFO("RESET: 0x%x\n",
  48. mmio_read_32(CRMU_RESET_EVENT_LOG));
  49. }
  50. void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  51. u_register_t arg2, u_register_t arg3)
  52. {
  53. /* SoC specific setup */
  54. plat_bcm_bl2_early_platform_setup();
  55. /* Initialize delay timer driver using SP804 dual timer 0 */
  56. sp804_timer_init(SP804_TIMER0_BASE,
  57. SP804_TIMER0_CLKMULT, SP804_TIMER0_CLKDIV);
  58. /* BRCM platforms generic setup */
  59. bcm_bl2_early_platform_setup((uintptr_t)arg0, (meminfo_t *)arg1);
  60. }
  61. /*
  62. * Perform Broadcom platform setup.
  63. */
  64. void bcm_bl2_platform_setup(void)
  65. {
  66. /* Initialize the secure environment */
  67. plat_bcm_security_setup();
  68. }
  69. void bl2_platform_setup(void)
  70. {
  71. bcm_bl2_platform_setup();
  72. plat_bcm_bl2_platform_setup();
  73. }
  74. /*******************************************************************************
  75. * Perform the very early platform specific architectural setup here. At the
  76. * moment this is only initializes the mmu in a quick and dirty way.
  77. ******************************************************************************/
  78. void bcm_bl2_plat_arch_setup(void)
  79. {
  80. #ifndef MMU_DISABLED
  81. if (!(read_sctlr_el1() & SCTLR_M_BIT)) {
  82. const mmap_region_t bl_regions[] = {
  83. MAP_REGION_FLAT(bl2_tzram_layout.total_base,
  84. bl2_tzram_layout.total_size,
  85. MT_MEMORY | MT_RW | MT_SECURE),
  86. MAP_REGION_FLAT(BL_CODE_BASE,
  87. BL_CODE_END - BL_CODE_BASE,
  88. MT_CODE | MT_SECURE),
  89. MAP_REGION_FLAT(BL_RO_DATA_BASE,
  90. BL_RO_DATA_END - BL_RO_DATA_BASE,
  91. MT_RO_DATA | MT_SECURE),
  92. #if USE_COHERENT_MEM
  93. MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
  94. BL_COHERENT_RAM_END -
  95. BL_COHERENT_RAM_BASE,
  96. MT_DEVICE | MT_RW | MT_SECURE),
  97. #endif
  98. {0}
  99. };
  100. setup_page_tables(bl_regions, plat_brcm_get_mmap());
  101. enable_mmu_el1(0);
  102. }
  103. #endif
  104. }
  105. void bl2_plat_arch_setup(void)
  106. {
  107. #ifdef ENA_MMU_BEFORE_DDR_INIT
  108. /*
  109. * Once MMU is enabled before DDR, MEMORY TESTS
  110. * get affected as read/write transaction might occures from
  111. * caches. So For running memory test, one should not set this
  112. * flag.
  113. */
  114. bcm_bl2_plat_arch_setup();
  115. plat_bcm_bl2_plat_arch_setup();
  116. #else
  117. plat_bcm_bl2_plat_arch_setup();
  118. bcm_bl2_plat_arch_setup();
  119. #endif
  120. }
  121. int bcm_bl2_handle_post_image_load(unsigned int image_id)
  122. {
  123. int err = 0;
  124. bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
  125. assert(bl_mem_params);
  126. switch (image_id) {
  127. case BL32_IMAGE_ID:
  128. bl_mem_params->ep_info.spsr = brcm_get_spsr_for_bl32_entry();
  129. break;
  130. case BL33_IMAGE_ID:
  131. /* BL33 expects to receive the primary CPU MPID (through r0) */
  132. bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
  133. bl_mem_params->ep_info.spsr = brcm_get_spsr_for_bl33_entry();
  134. break;
  135. #ifdef SCP_BL2_BASE
  136. case SCP_BL2_IMAGE_ID:
  137. /* The subsequent handling of SCP_BL2 is platform specific */
  138. err = bcm_bl2_handle_scp_bl2(&bl_mem_params->image_info);
  139. if (err)
  140. WARN("Failure in platform-specific handling of SCP_BL2 image.\n");
  141. break;
  142. #endif
  143. default:
  144. /* Do nothing in default case */
  145. break;
  146. }
  147. return err;
  148. }
  149. /*******************************************************************************
  150. * This function can be used by the platforms to update/use image
  151. * information for given `image_id`.
  152. ******************************************************************************/
  153. int bcm_bl2_plat_handle_post_image_load(unsigned int image_id)
  154. {
  155. return bcm_bl2_handle_post_image_load(image_id);
  156. }
  157. int bl2_plat_handle_post_image_load(unsigned int image_id)
  158. {
  159. return bcm_bl2_plat_handle_post_image_load(image_id);
  160. }
  161. #ifdef SCP_BL2_BASE
  162. int plat_bcm_bl2_plat_handle_scp_bl2(image_info_t *scp_bl2_image_info)
  163. {
  164. return 0;
  165. }
  166. int bcm_bl2_handle_scp_bl2(image_info_t *scp_bl2_image_info)
  167. {
  168. return plat_bcm_bl2_plat_handle_scp_bl2(scp_bl2_image_info);
  169. }
  170. #endif