Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 1 | /* |
Tamas Ban | 896c734 | 2023-05-08 13:38:27 +0200 | [diff] [blame] | 2 | * Copyright (c) 2014-2024, Arm Limited and Contributors. All rights reserved. |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 7 | #include <assert.h> |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 8 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
| 10 | #include <arch_helpers.h> |
| 11 | #include <common/debug.h> |
Antonio Nino Diaz | 326f56b | 2019-01-23 18:55:03 +0000 | [diff] [blame] | 12 | #include <drivers/arm/css/css_scp.h> |
Antonio Nino Diaz | 09d5876 | 2019-01-23 19:06:55 +0000 | [diff] [blame] | 13 | #include <drivers/arm/css/sds.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 14 | #include <drivers/delay_timer.h> |
| 15 | #include <plat/common/platform.h> |
Antonio Nino Diaz | a320ecd | 2019-01-15 14:19:50 +0000 | [diff] [blame] | 16 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 17 | |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 18 | int css_scp_boot_image_xfer(void *image, unsigned int image_size) |
| 19 | { |
| 20 | int ret; |
| 21 | unsigned int image_offset, image_flags; |
| 22 | |
Tamas Ban | 896c734 | 2023-05-08 13:38:27 +0200 | [diff] [blame] | 23 | ret = sds_init(SDS_SCP_AP_REGION_ID); |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 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; |
Tamas Ban | 896c734 | 2023-05-08 13:38:27 +0200 | [diff] [blame] | 31 | ret = sds_struct_write(SDS_SCP_AP_REGION_ID, |
| 32 | SDS_SCP_IMG_STRUCT_ID, SDS_SCP_IMG_ADDR_OFFSET, |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 33 | &image_offset, SDS_SCP_IMG_ADDR_SIZE, |
| 34 | SDS_ACCESS_MODE_NON_CACHED); |
| 35 | if (ret != SDS_OK) |
| 36 | goto sds_fail; |
| 37 | |
Tamas Ban | 896c734 | 2023-05-08 13:38:27 +0200 | [diff] [blame] | 38 | ret = sds_struct_write(SDS_SCP_AP_REGION_ID, |
| 39 | SDS_SCP_IMG_STRUCT_ID, SDS_SCP_IMG_SIZE_OFFSET, |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 40 | &image_size, SDS_SCP_IMG_SIZE_SIZE, |
| 41 | SDS_ACCESS_MODE_NON_CACHED); |
| 42 | if (ret != SDS_OK) |
| 43 | goto sds_fail; |
| 44 | |
| 45 | VERBOSE("Marking SCP image metadata as valid\n"); |
| 46 | image_flags = SDS_SCP_IMG_VALID_FLAG_BIT; |
Tamas Ban | 896c734 | 2023-05-08 13:38:27 +0200 | [diff] [blame] | 47 | ret = sds_struct_write(SDS_SCP_AP_REGION_ID, |
| 48 | SDS_SCP_IMG_STRUCT_ID, SDS_SCP_IMG_FLAG_OFFSET, |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 49 | &image_flags, SDS_SCP_IMG_FLAG_SIZE, |
| 50 | SDS_ACCESS_MODE_NON_CACHED); |
| 51 | if (ret != SDS_OK) |
| 52 | goto sds_fail; |
| 53 | |
| 54 | return 0; |
| 55 | sds_fail: |
| 56 | ERROR("SCP SDS write to SCP IMG struct failed\n"); |
| 57 | panic(); |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * API to wait for SCP to signal till it's ready after booting the transferred |
| 62 | * image. |
| 63 | */ |
| 64 | int css_scp_boot_ready(void) |
| 65 | { |
| 66 | uint32_t scp_feature_availability_flags; |
| 67 | int ret, retry = CSS_SCP_READY_10US_RETRIES; |
| 68 | |
| 69 | |
| 70 | VERBOSE("Waiting for SCP RAM to complete its initialization process\n"); |
| 71 | |
| 72 | /* Wait for the SCP RAM Firmware to complete its initialization process */ |
| 73 | while (retry > 0) { |
Tamas Ban | 896c734 | 2023-05-08 13:38:27 +0200 | [diff] [blame] | 74 | ret = sds_struct_read(SDS_SCP_AP_REGION_ID, |
| 75 | SDS_FEATURE_AVAIL_STRUCT_ID, 0, |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 76 | &scp_feature_availability_flags, |
| 77 | SDS_FEATURE_AVAIL_SIZE, |
| 78 | SDS_ACCESS_MODE_NON_CACHED); |
| 79 | if (ret == SDS_ERR_STRUCT_NOT_FINALIZED) |
| 80 | continue; |
| 81 | |
| 82 | if (ret != SDS_OK) { |
| 83 | ERROR(" sds_struct_read failed\n"); |
| 84 | panic(); |
| 85 | } |
| 86 | |
| 87 | if (scp_feature_availability_flags & |
| 88 | SDS_FEATURE_AVAIL_SCP_RAM_READY_BIT) |
| 89 | return 0; |
| 90 | |
| 91 | udelay(10); |
| 92 | retry--; |
| 93 | } |
| 94 | |
| 95 | ERROR("Timeout of %d ms expired waiting for SCP RAM Ready flag\n", |
| 96 | CSS_SCP_READY_10US_RETRIES/100); |
| 97 | |
| 98 | plat_panic_handler(); |
| 99 | } |