1b4315306SDan Handley /* 2*ed567207SHarrison Mutai * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved. 3b4315306SDan Handley * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 5b4315306SDan Handley */ 6b4315306SDan Handley 74c117f6cSSandrine Bailleux #include <string.h> 809d40e0eSAntonio Nino Diaz 909d40e0eSAntonio Nino Diaz #include <common/bl_common.h> 1009d40e0eSAntonio Nino Diaz #include <common/debug.h> 112d4135e0SAntonio Nino Diaz #include <drivers/arm/css/css_scp.h> 1209d40e0eSAntonio Nino Diaz #include <lib/mmio.h> 1309d40e0eSAntonio Nino Diaz #include <lib/utils.h> 14bd9344f6SAntonio Nino Diaz #include <plat/arm/common/plat_arm.h> 15234bc7f8SAntonio Nino Diaz #include <platform_def.h> 1609d40e0eSAntonio Nino Diaz 17b4315306SDan Handley /* Weak definition may be overridden in specific CSS based platform */ 18a8aa7fecSYatharth Kochar #pragma weak plat_arm_bl2_handle_scp_bl2 19b4315306SDan Handley 20b4315306SDan Handley /******************************************************************************* 21f59821d5SJuan Castillo * Transfer SCP_BL2 from Trusted RAM using the SCP Download protocol. 22b4315306SDan Handley * Return 0 on success, -1 otherwise. 23b4315306SDan Handley ******************************************************************************/ 24a8aa7fecSYatharth Kochar int plat_arm_bl2_handle_scp_bl2(image_info_t *scp_bl2_image_info) 25b4315306SDan Handley { 26b4315306SDan Handley int ret; 27b4315306SDan Handley 28f59821d5SJuan Castillo INFO("BL2: Initiating SCP_BL2 transfer to SCP\n"); 29e234ba03SSandrine Bailleux 3074d44a49SSoby Mathew ret = css_scp_boot_image_xfer((void *)scp_bl2_image_info->image_base, 31f59821d5SJuan Castillo scp_bl2_image_info->image_size); 32b4315306SDan Handley 33b4315306SDan Handley if (ret == 0) 3474d44a49SSoby Mathew ret = css_scp_boot_ready(); 3574d44a49SSoby Mathew 3674d44a49SSoby Mathew if (ret == 0) 37f59821d5SJuan Castillo INFO("BL2: SCP_BL2 transferred to SCP\n"); 38b4315306SDan Handley else 39f59821d5SJuan Castillo ERROR("BL2: SCP_BL2 transfer failure\n"); 40b4315306SDan Handley 41b4315306SDan Handley return ret; 42b4315306SDan Handley } 434c117f6cSSandrine Bailleux 4418e279ebSSoby Mathew #if !CSS_USE_SCMI_SDS_DRIVER 45a9f9b608SSoby Mathew # if defined(EL3_PAYLOAD_BASE) || JUNO_AARCH32_EL3_RUNTIME 4618e279ebSSoby Mathew 474c117f6cSSandrine Bailleux /* 484c117f6cSSandrine Bailleux * We need to override some of the platform functions when booting an EL3 49a9f9b608SSoby Mathew * payload or SP_MIN on Juno AArch32. This needs to be done only for 50a9f9b608SSoby Mathew * SCPI/BOM SCP systems as in case of SDS, the structures remain in memory and 51a9f9b608SSoby Mathew * don't need to be overwritten. 524c117f6cSSandrine Bailleux */ 534c117f6cSSandrine Bailleux 544c117f6cSSandrine Bailleux static unsigned int scp_boot_config; 554c117f6cSSandrine Bailleux 560c306cc0SSoby Mathew void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1, 570c306cc0SSoby Mathew u_register_t arg2, u_register_t arg3) 584c117f6cSSandrine Bailleux { 590c306cc0SSoby Mathew arm_bl2_early_platform_setup((uintptr_t)arg0, (meminfo_t *)arg1); 604c117f6cSSandrine Bailleux 61f59821d5SJuan Castillo /* Save SCP Boot config before it gets overwritten by SCP_BL2 loading */ 624c117f6cSSandrine Bailleux scp_boot_config = mmio_read_32(SCP_BOOT_CFG_ADDR); 634c117f6cSSandrine Bailleux VERBOSE("BL2: Saved SCP Boot config = 0x%x\n", scp_boot_config); 644c117f6cSSandrine Bailleux } 654c117f6cSSandrine Bailleux 664c117f6cSSandrine Bailleux void bl2_platform_setup(void) 674c117f6cSSandrine Bailleux { 684c117f6cSSandrine Bailleux arm_bl2_platform_setup(); 694c117f6cSSandrine Bailleux 704c117f6cSSandrine Bailleux /* 714c117f6cSSandrine Bailleux * Before releasing the AP cores out of reset, the SCP writes some data 724c117f6cSSandrine Bailleux * at the beginning of the Trusted SRAM. It is is overwritten before 734c117f6cSSandrine Bailleux * reaching this function. We need to restore this data, as if the 744c117f6cSSandrine Bailleux * target had just come out of reset. This implies: 75a1f5a9e5SRoberto Vargas * - zeroing the first 128 bytes of Trusted SRAM using zeromem instead 76a1f5a9e5SRoberto Vargas * of zero_normalmem since this is device memory. 774c117f6cSSandrine Bailleux * - restoring the SCP boot configuration. 784c117f6cSSandrine Bailleux */ 794c117f6cSSandrine Bailleux VERBOSE("BL2: Restoring SCP reset data in Trusted SRAM\n"); 80a1f5a9e5SRoberto Vargas zeromem((void *) ARM_SHARED_RAM_BASE, 128); 814c117f6cSSandrine Bailleux mmio_write_32(SCP_BOOT_CFG_ADDR, scp_boot_config); 824c117f6cSSandrine Bailleux } 8318e279ebSSoby Mathew 844c117f6cSSandrine Bailleux # endif /* EL3_PAYLOAD_BASE */ 8518e279ebSSoby Mathew 8618e279ebSSoby Mathew #endif /* CSS_USE_SCMI_SDS_DRIVER */ 87*ed567207SHarrison Mutai 88*ed567207SHarrison Mutai int bl2_plat_handle_post_image_load(unsigned int image_id) 89*ed567207SHarrison Mutai { 90*ed567207SHarrison Mutai return arm_bl2_plat_handle_post_image_load(image_id); 91*ed567207SHarrison Mutai } 92