Tamas Ban | a426089 | 2023-06-07 13:35:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2024, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stdint.h> |
| 8 | |
Tamas Ban | 0fbe862 | 2023-06-12 11:33:47 +0200 | [diff] [blame] | 9 | #include <common/debug.h> |
Tamas Ban | ae33fa9 | 2023-06-07 14:18:46 +0200 | [diff] [blame^] | 10 | #include <drivers/arm/css/sds.h> |
Tamas Ban | a426089 | 2023-06-07 13:35:04 +0200 | [diff] [blame] | 11 | #include <drivers/arm/rss_comms.h> |
Tamas Ban | ae33fa9 | 2023-06-07 14:18:46 +0200 | [diff] [blame^] | 12 | #include <drivers/delay_timer.h> |
| 13 | #include <drivers/generic_delay_timer.h> |
Tamas Ban | a426089 | 2023-06-07 13:35:04 +0200 | [diff] [blame] | 14 | #include <drivers/measured_boot/metadata.h> |
| 15 | #include <drivers/measured_boot/rss/dice_prot_env.h> |
| 16 | #include <plat/arm/common/plat_arm.h> |
| 17 | #include <plat/common/platform.h> |
| 18 | #include <platform_def.h> |
| 19 | #include <tools_share/zero_oid.h> |
| 20 | |
| 21 | struct dpe_metadata tc_dpe_metadata[] = { |
| 22 | { |
| 23 | .id = FW_CONFIG_ID, |
| 24 | .signer_id_size = SIGNER_ID_MIN_SIZE, |
| 25 | .sw_type = MBOOT_FW_CONFIG_STRING, |
| 26 | .allow_new_context_to_derive = false, |
| 27 | .retain_parent_context = true, |
| 28 | .create_certificate = false, |
| 29 | .pk_oid = ZERO_OID }, |
| 30 | { |
| 31 | .id = TB_FW_CONFIG_ID, |
| 32 | .signer_id_size = SIGNER_ID_MIN_SIZE, |
| 33 | .sw_type = MBOOT_TB_FW_CONFIG_STRING, |
| 34 | .allow_new_context_to_derive = false, |
| 35 | .retain_parent_context = true, |
| 36 | .create_certificate = false, |
| 37 | .pk_oid = ZERO_OID }, |
| 38 | { |
| 39 | .id = BL2_IMAGE_ID, |
| 40 | .signer_id_size = SIGNER_ID_MIN_SIZE, |
| 41 | .sw_type = MBOOT_BL2_IMAGE_STRING, |
| 42 | .allow_new_context_to_derive = true, |
| 43 | .retain_parent_context = false, |
| 44 | .create_certificate = false, |
| 45 | .pk_oid = ZERO_OID }, |
| 46 | { |
| 47 | .id = DPE_INVALID_ID } |
| 48 | }; |
| 49 | |
Tamas Ban | ae33fa9 | 2023-06-07 14:18:46 +0200 | [diff] [blame^] | 50 | /* Effective timeout of 10000 ms */ |
| 51 | #define RSS_DPE_BOOT_10US_RETRIES 1000000 |
| 52 | #define TC2_SDS_DPE_CTX_HANDLE_STRUCT_ID 0x0000000A |
| 53 | |
Tamas Ban | 0fbe862 | 2023-06-12 11:33:47 +0200 | [diff] [blame] | 54 | /* Context handle is meant to be used by BL2. Sharing it via TB_FW_CONFIG */ |
| 55 | static int new_ctx_handle; |
| 56 | |
| 57 | void plat_dpe_share_context_handle(int *ctx_handle) |
| 58 | { |
| 59 | new_ctx_handle = *ctx_handle; |
| 60 | } |
Tamas Ban | a426089 | 2023-06-07 13:35:04 +0200 | [diff] [blame] | 61 | |
Tamas Ban | ae33fa9 | 2023-06-07 14:18:46 +0200 | [diff] [blame^] | 62 | void plat_dpe_get_context_handle(int *ctx_handle) |
| 63 | { |
| 64 | int retry = RSS_DPE_BOOT_10US_RETRIES; |
| 65 | int ret; |
| 66 | |
| 67 | /* Initialize System level generic or SP804 timer */ |
| 68 | generic_delay_timer_init(); |
| 69 | |
| 70 | /* Check the initialization of the Shared Data Storage area between RSS |
| 71 | * and AP. Since AP_BL1 is executed first then a bit later the RSS |
| 72 | * runtime, which initialize this area, therefore AP needs to check it |
| 73 | * in a loop until it gets written by RSS Secure Runtime. |
| 74 | */ |
| 75 | VERBOSE("Waiting for DPE service initialization in RSS Secure Runtime\n"); |
| 76 | while (retry > 0) { |
| 77 | ret = sds_init(SDS_RSS_AP_REGION_ID); |
| 78 | if (ret != SDS_OK) { |
| 79 | udelay(10); |
| 80 | retry--; |
| 81 | } else { |
| 82 | break; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if (retry == 0) { |
| 87 | ERROR("DPE init timeout\n"); |
| 88 | plat_panic_handler(); |
| 89 | } else { |
| 90 | VERBOSE("DPE init succeeded in %dms.\n", |
| 91 | (RSS_DPE_BOOT_10US_RETRIES - retry) / 100); |
| 92 | } |
| 93 | |
| 94 | /* TODO: call this in a loop to avoid reading unfinished data */ |
| 95 | ret = sds_struct_read(SDS_RSS_AP_REGION_ID, |
| 96 | TC2_SDS_DPE_CTX_HANDLE_STRUCT_ID, |
| 97 | 0, |
| 98 | ctx_handle, |
| 99 | sizeof(*ctx_handle), |
| 100 | SDS_ACCESS_MODE_NON_CACHED); |
| 101 | if (ret != SDS_OK) { |
| 102 | ERROR("Unable to get DPE context handle from SDS area\n"); |
| 103 | plat_panic_handler(); |
| 104 | } |
| 105 | |
| 106 | VERBOSE("Received DPE context handle: 0x%x\n", *ctx_handle); |
| 107 | } |
| 108 | |
Tamas Ban | a426089 | 2023-06-07 13:35:04 +0200 | [diff] [blame] | 109 | void bl1_plat_mboot_init(void) |
| 110 | { |
| 111 | /* Initialize the communication channel between AP and RSS */ |
| 112 | (void)rss_comms_init(PLAT_RSS_AP_SND_MHU_BASE, |
| 113 | PLAT_RSS_AP_RCV_MHU_BASE); |
| 114 | |
| 115 | dpe_init(tc_dpe_metadata); |
| 116 | } |
| 117 | |
| 118 | void bl1_plat_mboot_finish(void) |
| 119 | { |
Tamas Ban | 0fbe862 | 2023-06-12 11:33:47 +0200 | [diff] [blame] | 120 | int rc; |
| 121 | |
| 122 | VERBOSE("Share DPE context handle with BL2: 0x%x\n", new_ctx_handle); |
| 123 | rc = arm_set_tb_fw_info(&new_ctx_handle); |
| 124 | if (rc != 0) { |
| 125 | ERROR("Unable to set DPE context handle in TB_FW_CONFIG\n"); |
| 126 | /* |
| 127 | * It is a fatal error because on TC platform, BL2 software |
| 128 | * assumes that a valid DPE context_handle is passed through |
| 129 | * the DTB object by BL1. |
| 130 | */ |
| 131 | plat_panic_handler(); |
| 132 | } |
Tamas Ban | a426089 | 2023-06-07 13:35:04 +0200 | [diff] [blame] | 133 | } |