blob: 561e97b2e4f2fdd63e3c1436ee94f21b20925db9 [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
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>
Roberto Vargasdaaae6c2018-02-12 12:36:17 +000014#include "css_scp.h"
Soby Mathew1ced6b82017-06-12 12:37:10 +010015#include "../sds/sds.h"
16
17int css_scp_boot_image_xfer(void *image, unsigned int image_size)
18{
19 int ret;
20 unsigned int image_offset, image_flags;
21
22 ret = sds_init();
23 if (ret != SDS_OK) {
24 ERROR("SCP SDS initialization failed\n");
25 panic();
26 }
27
28 VERBOSE("Writing SCP image metadata\n");
29 image_offset = (uintptr_t) image - ARM_TRUSTED_SRAM_BASE;
30 ret = sds_struct_write(SDS_SCP_IMG_STRUCT_ID, SDS_SCP_IMG_ADDR_OFFSET,
31 &image_offset, SDS_SCP_IMG_ADDR_SIZE,
32 SDS_ACCESS_MODE_NON_CACHED);
33 if (ret != SDS_OK)
34 goto sds_fail;
35
36 ret = sds_struct_write(SDS_SCP_IMG_STRUCT_ID, SDS_SCP_IMG_SIZE_OFFSET,
37 &image_size, SDS_SCP_IMG_SIZE_SIZE,
38 SDS_ACCESS_MODE_NON_CACHED);
39 if (ret != SDS_OK)
40 goto sds_fail;
41
42 VERBOSE("Marking SCP image metadata as valid\n");
43 image_flags = SDS_SCP_IMG_VALID_FLAG_BIT;
44 ret = sds_struct_write(SDS_SCP_IMG_STRUCT_ID, SDS_SCP_IMG_FLAG_OFFSET,
45 &image_flags, SDS_SCP_IMG_FLAG_SIZE,
46 SDS_ACCESS_MODE_NON_CACHED);
47 if (ret != SDS_OK)
48 goto sds_fail;
49
50 return 0;
51sds_fail:
52 ERROR("SCP SDS write to SCP IMG struct failed\n");
53 panic();
54}
55
56/*
57 * API to wait for SCP to signal till it's ready after booting the transferred
58 * image.
59 */
60int css_scp_boot_ready(void)
61{
62 uint32_t scp_feature_availability_flags;
63 int ret, retry = CSS_SCP_READY_10US_RETRIES;
64
65
66 VERBOSE("Waiting for SCP RAM to complete its initialization process\n");
67
68 /* Wait for the SCP RAM Firmware to complete its initialization process */
69 while (retry > 0) {
70 ret = sds_struct_read(SDS_FEATURE_AVAIL_STRUCT_ID, 0,
71 &scp_feature_availability_flags,
72 SDS_FEATURE_AVAIL_SIZE,
73 SDS_ACCESS_MODE_NON_CACHED);
74 if (ret == SDS_ERR_STRUCT_NOT_FINALIZED)
75 continue;
76
77 if (ret != SDS_OK) {
78 ERROR(" sds_struct_read failed\n");
79 panic();
80 }
81
82 if (scp_feature_availability_flags &
83 SDS_FEATURE_AVAIL_SCP_RAM_READY_BIT)
84 return 0;
85
86 udelay(10);
87 retry--;
88 }
89
90 ERROR("Timeout of %d ms expired waiting for SCP RAM Ready flag\n",
91 CSS_SCP_READY_10US_RETRIES/100);
92
93 plat_panic_handler();
94}