css_bl2_setup.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <string.h>
  7. #include <common/bl_common.h>
  8. #include <common/debug.h>
  9. #include <drivers/arm/css/css_scp.h>
  10. #include <lib/mmio.h>
  11. #include <lib/utils.h>
  12. #include <plat/arm/common/plat_arm.h>
  13. #include <platform_def.h>
  14. /* Weak definition may be overridden in specific CSS based platform */
  15. #pragma weak plat_arm_bl2_handle_scp_bl2
  16. /*******************************************************************************
  17. * Transfer SCP_BL2 from Trusted RAM using the SCP Download protocol.
  18. * Return 0 on success, -1 otherwise.
  19. ******************************************************************************/
  20. int plat_arm_bl2_handle_scp_bl2(image_info_t *scp_bl2_image_info)
  21. {
  22. int ret;
  23. INFO("BL2: Initiating SCP_BL2 transfer to SCP\n");
  24. ret = css_scp_boot_image_xfer((void *)scp_bl2_image_info->image_base,
  25. scp_bl2_image_info->image_size);
  26. if (ret == 0)
  27. ret = css_scp_boot_ready();
  28. if (ret == 0)
  29. INFO("BL2: SCP_BL2 transferred to SCP\n");
  30. else
  31. ERROR("BL2: SCP_BL2 transfer failure\n");
  32. return ret;
  33. }
  34. #if !CSS_USE_SCMI_SDS_DRIVER
  35. # if defined(EL3_PAYLOAD_BASE) || JUNO_AARCH32_EL3_RUNTIME
  36. /*
  37. * We need to override some of the platform functions when booting an EL3
  38. * payload or SP_MIN on Juno AArch32. This needs to be done only for
  39. * SCPI/BOM SCP systems as in case of SDS, the structures remain in memory and
  40. * don't need to be overwritten.
  41. */
  42. static unsigned int scp_boot_config;
  43. void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  44. u_register_t arg2, u_register_t arg3)
  45. {
  46. arm_bl2_early_platform_setup((uintptr_t)arg0, (meminfo_t *)arg1);
  47. /* Save SCP Boot config before it gets overwritten by SCP_BL2 loading */
  48. scp_boot_config = mmio_read_32(SCP_BOOT_CFG_ADDR);
  49. VERBOSE("BL2: Saved SCP Boot config = 0x%x\n", scp_boot_config);
  50. }
  51. void bl2_platform_setup(void)
  52. {
  53. arm_bl2_platform_setup();
  54. /*
  55. * Before releasing the AP cores out of reset, the SCP writes some data
  56. * at the beginning of the Trusted SRAM. It is is overwritten before
  57. * reaching this function. We need to restore this data, as if the
  58. * target had just come out of reset. This implies:
  59. * - zeroing the first 128 bytes of Trusted SRAM using zeromem instead
  60. * of zero_normalmem since this is device memory.
  61. * - restoring the SCP boot configuration.
  62. */
  63. VERBOSE("BL2: Restoring SCP reset data in Trusted SRAM\n");
  64. zeromem((void *) ARM_SHARED_RAM_BASE, 128);
  65. mmio_write_32(SCP_BOOT_CFG_ADDR, scp_boot_config);
  66. }
  67. # endif /* EL3_PAYLOAD_BASE */
  68. #endif /* CSS_USE_SCMI_SDS_DRIVER */
  69. int bl2_plat_handle_post_image_load(unsigned int image_id)
  70. {
  71. return arm_bl2_plat_handle_post_image_load(image_id);
  72. }