marvell_bl2_setup.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Copyright (C) 2018 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. * https://spdx.org/licenses
  6. */
  7. #include <assert.h>
  8. #include <string.h>
  9. #include <platform_def.h>
  10. #include <arch_helpers.h>
  11. #include <common/bl_common.h>
  12. #include <common/debug.h>
  13. #include <common/desc_image_load.h>
  14. #include <drivers/console.h>
  15. #include <lib/utils.h>
  16. #ifdef SPD_opteed
  17. #include <optee_utils.h>
  18. #endif
  19. #include <marvell_def.h>
  20. #include <plat_marvell.h>
  21. /* Data structure which holds the extents of the trusted SRAM for BL2 */
  22. static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
  23. /* Weak definitions may be overridden in specific MARVELL standard platform */
  24. #pragma weak bl2_early_platform_setup2
  25. #pragma weak bl2_platform_setup
  26. #pragma weak bl2_plat_arch_setup
  27. #pragma weak bl2_plat_sec_mem_layout
  28. meminfo_t *bl2_plat_sec_mem_layout(void)
  29. {
  30. return &bl2_tzram_layout;
  31. }
  32. /*****************************************************************************
  33. * BL1 has passed the extents of the trusted SRAM that should be visible to BL2
  34. * in x0. This memory layout is sitting at the base of the free trusted SRAM.
  35. * Copy it to a safe location before its reclaimed by later BL2 functionality.
  36. *****************************************************************************
  37. */
  38. void marvell_bl2_early_platform_setup(meminfo_t *mem_layout)
  39. {
  40. /* Initialize the console to provide early debug support */
  41. marvell_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_marvell_io_setup();
  46. }
  47. void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  48. u_register_t arg2, u_register_t arg3)
  49. {
  50. struct meminfo *mem_layout = (struct meminfo *)arg1;
  51. marvell_bl2_early_platform_setup(mem_layout);
  52. }
  53. void bl2_platform_setup(void)
  54. {
  55. /* Nothing to do */
  56. }
  57. /*****************************************************************************
  58. * Perform the very early platform specific architectural setup here. At the
  59. * moment this is only initializes the mmu in a quick and dirty way.
  60. *****************************************************************************
  61. */
  62. void marvell_bl2_plat_arch_setup(void)
  63. {
  64. marvell_setup_page_tables(bl2_tzram_layout.total_base,
  65. bl2_tzram_layout.total_size,
  66. BL_CODE_BASE,
  67. BL_CODE_END,
  68. BL_RO_DATA_BASE,
  69. BL_RO_DATA_END
  70. #if USE_COHERENT_MEM
  71. , BL_COHERENT_RAM_BASE,
  72. BL_COHERENT_RAM_END
  73. #endif
  74. );
  75. enable_mmu_el1(0);
  76. }
  77. void bl2_plat_arch_setup(void)
  78. {
  79. marvell_bl2_plat_arch_setup();
  80. }
  81. int marvell_bl2_handle_post_image_load(unsigned int image_id)
  82. {
  83. int err = 0;
  84. bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
  85. #ifdef SPD_opteed
  86. bl_mem_params_node_t *pager_mem_params = NULL;
  87. bl_mem_params_node_t *paged_mem_params = NULL;
  88. #endif /* SPD_opteed */
  89. assert(bl_mem_params);
  90. switch (image_id) {
  91. case BL32_IMAGE_ID:
  92. #ifdef SPD_opteed
  93. pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID);
  94. assert(pager_mem_params);
  95. paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID);
  96. assert(paged_mem_params);
  97. err = parse_optee_header(&bl_mem_params->ep_info,
  98. &pager_mem_params->image_info,
  99. &paged_mem_params->image_info);
  100. if (err != 0)
  101. WARN("OPTEE header parse error.\n");
  102. #endif /* SPD_opteed */
  103. bl_mem_params->ep_info.spsr = marvell_get_spsr_for_bl32_entry();
  104. break;
  105. case BL33_IMAGE_ID:
  106. /* BL33 expects to receive the primary CPU MPID (through r0) */
  107. bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
  108. bl_mem_params->ep_info.spsr = marvell_get_spsr_for_bl33_entry();
  109. break;
  110. #ifdef SCP_BL2_BASE
  111. case SCP_BL2_IMAGE_ID:
  112. /* The subsequent handling of SCP_BL2 is platform specific */
  113. err = bl2_plat_handle_scp_bl2(&bl_mem_params->image_info);
  114. if (err) {
  115. WARN("Failure in platform-specific handling of SCP_BL2 image.\n");
  116. }
  117. break;
  118. #endif
  119. default:
  120. /* Do nothing in default case */
  121. break;
  122. }
  123. return err;
  124. }
  125. /*******************************************************************************
  126. * This function can be used by the platforms to update/use image
  127. * information for given `image_id`.
  128. ******************************************************************************/
  129. int bl2_plat_handle_post_image_load(unsigned int image_id)
  130. {
  131. return marvell_bl2_handle_post_image_load(image_id);
  132. }