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