uniphier_bl2_setup.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <errno.h>
  7. #include <platform_def.h>
  8. #include <common/bl_common.h>
  9. #include <common/debug.h>
  10. #include <common/desc_image_load.h>
  11. #include <common/image_decompress.h>
  12. #include <drivers/io/io_storage.h>
  13. #include <lib/xlat_tables/xlat_tables_v2.h>
  14. #include <plat/common/platform.h>
  15. #ifdef UNIPHIER_DECOMPRESS_GZIP
  16. #include <tf_gunzip.h>
  17. #endif
  18. #include "uniphier.h"
  19. #define UNIPHIER_IMAGE_BUF_OFFSET 0x03800000UL
  20. #define UNIPHIER_IMAGE_BUF_SIZE 0x00800000UL
  21. static uintptr_t uniphier_mem_base = UNIPHIER_MEM_BASE;
  22. static unsigned int uniphier_soc = UNIPHIER_SOC_UNKNOWN;
  23. static int uniphier_bl2_kick_scp;
  24. void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
  25. u_register_t x2, u_register_t x3)
  26. {
  27. uniphier_soc = uniphier_get_soc_id();
  28. if (uniphier_soc == UNIPHIER_SOC_UNKNOWN)
  29. plat_error_handler(-ENOTSUP);
  30. uniphier_console_setup(uniphier_soc);
  31. }
  32. void bl2_el3_plat_arch_setup(void)
  33. {
  34. int skip_scp = 0;
  35. int ret;
  36. uniphier_mmap_setup(uniphier_soc);
  37. /* add relocation offset (run-time-address - link-address) */
  38. uniphier_mem_base += BL_CODE_BASE - BL2_BASE;
  39. ret = uniphier_io_setup(uniphier_soc, uniphier_mem_base);
  40. if (ret) {
  41. ERROR("failed to setup io devices\n");
  42. plat_error_handler(ret);
  43. }
  44. switch (uniphier_get_boot_master(uniphier_soc)) {
  45. case UNIPHIER_BOOT_MASTER_THIS:
  46. INFO("Booting from this SoC\n");
  47. skip_scp = 1;
  48. break;
  49. case UNIPHIER_BOOT_MASTER_SCP:
  50. INFO("Booting from on-chip SCP\n");
  51. if (uniphier_scp_is_running()) {
  52. INFO("SCP is already running. SCP_BL2 load will be skipped.\n");
  53. skip_scp = 1;
  54. }
  55. /*
  56. * SCP must be kicked every time even if it is already running
  57. * because it polls this event after the reboot of the backend.
  58. */
  59. uniphier_bl2_kick_scp = 1;
  60. break;
  61. case UNIPHIER_BOOT_MASTER_EXT:
  62. INFO("Booting from external SCP\n");
  63. skip_scp = 1;
  64. break;
  65. default:
  66. plat_error_handler(-ENOTSUP);
  67. break;
  68. }
  69. if (skip_scp) {
  70. struct image_info *image_info;
  71. image_info = uniphier_get_image_info(SCP_BL2_IMAGE_ID);
  72. image_info->h.attr |= IMAGE_ATTRIB_SKIP_LOADING;
  73. }
  74. }
  75. void bl2_platform_setup(void)
  76. {
  77. }
  78. void plat_flush_next_bl_params(void)
  79. {
  80. flush_bl_params_desc();
  81. }
  82. bl_load_info_t *plat_get_bl_image_load_info(void)
  83. {
  84. return get_bl_load_info_from_mem_params_desc();
  85. }
  86. bl_params_t *plat_get_next_bl_params(void)
  87. {
  88. return get_next_bl_params_from_mem_params_desc();
  89. }
  90. void bl2_plat_preload_setup(void)
  91. {
  92. #ifdef UNIPHIER_DECOMPRESS_GZIP
  93. uintptr_t buf_base = uniphier_mem_base + UNIPHIER_IMAGE_BUF_OFFSET;
  94. int ret;
  95. ret = mmap_add_dynamic_region(buf_base, buf_base,
  96. UNIPHIER_IMAGE_BUF_SIZE,
  97. MT_MEMORY | MT_RW | MT_NS);
  98. if (ret)
  99. plat_error_handler(ret);
  100. image_decompress_init(buf_base, UNIPHIER_IMAGE_BUF_SIZE, gunzip);
  101. #endif
  102. uniphier_init_image_descs(uniphier_mem_base);
  103. }
  104. int bl2_plat_handle_pre_image_load(unsigned int image_id)
  105. {
  106. struct image_info *image_info;
  107. int ret;
  108. image_info = uniphier_get_image_info(image_id);
  109. ret = mmap_add_dynamic_region(image_info->image_base,
  110. image_info->image_base,
  111. image_info->image_max_size,
  112. MT_MEMORY | MT_RW | MT_NS);
  113. if (ret)
  114. return ret;
  115. #ifdef UNIPHIER_DECOMPRESS_GZIP
  116. image_decompress_prepare(image_info);
  117. #endif
  118. return 0;
  119. }
  120. int bl2_plat_handle_post_image_load(unsigned int image_id)
  121. {
  122. struct image_info *image_info = uniphier_get_image_info(image_id);
  123. #ifdef UNIPHIER_DECOMPRESS_GZIP
  124. int ret;
  125. if (!(image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) {
  126. ret = image_decompress(uniphier_get_image_info(image_id));
  127. if (ret)
  128. return ret;
  129. }
  130. #endif
  131. if (image_id == SCP_BL2_IMAGE_ID && uniphier_bl2_kick_scp)
  132. uniphier_scp_start(image_info->image_base);
  133. return 0;
  134. }