1 /* 2 * Copyright (c) 2014-2017, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <arch_helpers.h> 8 #include <assert.h> 9 #include <css_def.h> 10 #include <debug.h> 11 #include <delay_timer.h> 12 #include <platform.h> 13 #include <stdint.h> 14 #include "../sds/sds.h" 15 16 int css_scp_boot_image_xfer(void *image, unsigned int image_size) 17 { 18 int ret; 19 unsigned int image_offset, image_flags; 20 21 ret = sds_init(); 22 if (ret != SDS_OK) { 23 ERROR("SCP SDS initialization failed\n"); 24 panic(); 25 } 26 27 VERBOSE("Writing SCP image metadata\n"); 28 image_offset = (uintptr_t) image - ARM_TRUSTED_SRAM_BASE; 29 ret = sds_struct_write(SDS_SCP_IMG_STRUCT_ID, SDS_SCP_IMG_ADDR_OFFSET, 30 &image_offset, SDS_SCP_IMG_ADDR_SIZE, 31 SDS_ACCESS_MODE_NON_CACHED); 32 if (ret != SDS_OK) 33 goto sds_fail; 34 35 ret = sds_struct_write(SDS_SCP_IMG_STRUCT_ID, SDS_SCP_IMG_SIZE_OFFSET, 36 &image_size, SDS_SCP_IMG_SIZE_SIZE, 37 SDS_ACCESS_MODE_NON_CACHED); 38 if (ret != SDS_OK) 39 goto sds_fail; 40 41 VERBOSE("Marking SCP image metadata as valid\n"); 42 image_flags = SDS_SCP_IMG_VALID_FLAG_BIT; 43 ret = sds_struct_write(SDS_SCP_IMG_STRUCT_ID, SDS_SCP_IMG_FLAG_OFFSET, 44 &image_flags, SDS_SCP_IMG_FLAG_SIZE, 45 SDS_ACCESS_MODE_NON_CACHED); 46 if (ret != SDS_OK) 47 goto sds_fail; 48 49 return 0; 50 sds_fail: 51 ERROR("SCP SDS write to SCP IMG struct failed\n"); 52 panic(); 53 } 54 55 /* 56 * API to wait for SCP to signal till it's ready after booting the transferred 57 * image. 58 */ 59 int css_scp_boot_ready(void) 60 { 61 uint32_t scp_feature_availability_flags; 62 int ret, retry = CSS_SCP_READY_10US_RETRIES; 63 64 65 VERBOSE("Waiting for SCP RAM to complete its initialization process\n"); 66 67 /* Wait for the SCP RAM Firmware to complete its initialization process */ 68 while (retry > 0) { 69 ret = sds_struct_read(SDS_FEATURE_AVAIL_STRUCT_ID, 0, 70 &scp_feature_availability_flags, 71 SDS_FEATURE_AVAIL_SIZE, 72 SDS_ACCESS_MODE_NON_CACHED); 73 if (ret == SDS_ERR_STRUCT_NOT_FINALIZED) 74 continue; 75 76 if (ret != SDS_OK) { 77 ERROR(" sds_struct_read failed\n"); 78 panic(); 79 } 80 81 if (scp_feature_availability_flags & 82 SDS_FEATURE_AVAIL_SCP_RAM_READY_BIT) 83 return 0; 84 85 udelay(10); 86 retry--; 87 } 88 89 ERROR("Timeout of %d ms expired waiting for SCP RAM Ready flag\n", 90 CSS_SCP_READY_10US_RETRIES/100); 91 92 plat_panic_handler(); 93 } 94