blob: dc60fb6a0bf51ca8e547b938404fff1a30c33bf5 [file] [log] [blame]
Tamas Bana4260892023-06-07 13:35:04 +02001/*
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 Ban0fbe8622023-06-12 11:33:47 +02009#include <common/debug.h>
Tamas Banae33fa92023-06-07 14:18:46 +020010#include <drivers/arm/css/sds.h>
Tamas Bana4260892023-06-07 13:35:04 +020011#include <drivers/arm/rss_comms.h>
Tamas Banae33fa92023-06-07 14:18:46 +020012#include <drivers/delay_timer.h>
13#include <drivers/generic_delay_timer.h>
Tamas Bana4260892023-06-07 13:35:04 +020014#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
Tamas Bana5d3ca82024-01-30 12:56:38 +010021#include "tc_dpe_cert.h"
22
Tamas Bana4260892023-06-07 13:35:04 +020023struct dpe_metadata tc_dpe_metadata[] = {
24 {
25 .id = FW_CONFIG_ID,
Tamas Bana5d3ca82024-01-30 12:56:38 +010026 .cert_id = DPE_AP_FW_CERT_ID,
Tamas Bana4260892023-06-07 13:35:04 +020027 .signer_id_size = SIGNER_ID_MIN_SIZE,
28 .sw_type = MBOOT_FW_CONFIG_STRING,
29 .allow_new_context_to_derive = false,
30 .retain_parent_context = true,
31 .create_certificate = false,
32 .pk_oid = ZERO_OID },
33 {
34 .id = TB_FW_CONFIG_ID,
Tamas Bana5d3ca82024-01-30 12:56:38 +010035 .cert_id = DPE_AP_FW_CERT_ID,
Tamas Bana4260892023-06-07 13:35:04 +020036 .signer_id_size = SIGNER_ID_MIN_SIZE,
37 .sw_type = MBOOT_TB_FW_CONFIG_STRING,
38 .allow_new_context_to_derive = false,
39 .retain_parent_context = true,
40 .create_certificate = false,
41 .pk_oid = ZERO_OID },
42 {
43 .id = BL2_IMAGE_ID,
Tamas Bana5d3ca82024-01-30 12:56:38 +010044 .cert_id = DPE_AP_FW_CERT_ID,
Tamas Bana4260892023-06-07 13:35:04 +020045 .signer_id_size = SIGNER_ID_MIN_SIZE,
46 .sw_type = MBOOT_BL2_IMAGE_STRING,
47 .allow_new_context_to_derive = true,
48 .retain_parent_context = false,
49 .create_certificate = false,
50 .pk_oid = ZERO_OID },
51 {
52 .id = DPE_INVALID_ID }
53};
54
Tamas Banae33fa92023-06-07 14:18:46 +020055/* Effective timeout of 10000 ms */
56#define RSS_DPE_BOOT_10US_RETRIES 1000000
57#define TC2_SDS_DPE_CTX_HANDLE_STRUCT_ID 0x0000000A
58
Tamas Ban0fbe8622023-06-12 11:33:47 +020059/* Context handle is meant to be used by BL2. Sharing it via TB_FW_CONFIG */
60static int new_ctx_handle;
61
62void plat_dpe_share_context_handle(int *ctx_handle)
63{
64 new_ctx_handle = *ctx_handle;
65}
Tamas Bana4260892023-06-07 13:35:04 +020066
Tamas Banae33fa92023-06-07 14:18:46 +020067void plat_dpe_get_context_handle(int *ctx_handle)
68{
69 int retry = RSS_DPE_BOOT_10US_RETRIES;
70 int ret;
71
72 /* Initialize System level generic or SP804 timer */
73 generic_delay_timer_init();
74
75 /* Check the initialization of the Shared Data Storage area between RSS
76 * and AP. Since AP_BL1 is executed first then a bit later the RSS
77 * runtime, which initialize this area, therefore AP needs to check it
78 * in a loop until it gets written by RSS Secure Runtime.
79 */
80 VERBOSE("Waiting for DPE service initialization in RSS Secure Runtime\n");
81 while (retry > 0) {
82 ret = sds_init(SDS_RSS_AP_REGION_ID);
83 if (ret != SDS_OK) {
84 udelay(10);
85 retry--;
86 } else {
87 break;
88 }
89 }
90
91 if (retry == 0) {
92 ERROR("DPE init timeout\n");
93 plat_panic_handler();
94 } else {
95 VERBOSE("DPE init succeeded in %dms.\n",
96 (RSS_DPE_BOOT_10US_RETRIES - retry) / 100);
97 }
98
99 /* TODO: call this in a loop to avoid reading unfinished data */
100 ret = sds_struct_read(SDS_RSS_AP_REGION_ID,
101 TC2_SDS_DPE_CTX_HANDLE_STRUCT_ID,
102 0,
103 ctx_handle,
104 sizeof(*ctx_handle),
105 SDS_ACCESS_MODE_NON_CACHED);
106 if (ret != SDS_OK) {
107 ERROR("Unable to get DPE context handle from SDS area\n");
108 plat_panic_handler();
109 }
110
111 VERBOSE("Received DPE context handle: 0x%x\n", *ctx_handle);
112}
113
Tamas Bana4260892023-06-07 13:35:04 +0200114void bl1_plat_mboot_init(void)
115{
116 /* Initialize the communication channel between AP and RSS */
117 (void)rss_comms_init(PLAT_RSS_AP_SND_MHU_BASE,
118 PLAT_RSS_AP_RCV_MHU_BASE);
119
120 dpe_init(tc_dpe_metadata);
121}
122
123void bl1_plat_mboot_finish(void)
124{
Tamas Ban0fbe8622023-06-12 11:33:47 +0200125 int rc;
126
127 VERBOSE("Share DPE context handle with BL2: 0x%x\n", new_ctx_handle);
128 rc = arm_set_tb_fw_info(&new_ctx_handle);
129 if (rc != 0) {
130 ERROR("Unable to set DPE context handle in TB_FW_CONFIG\n");
131 /*
132 * It is a fatal error because on TC platform, BL2 software
133 * assumes that a valid DPE context_handle is passed through
134 * the DTB object by BL1.
135 */
136 plat_panic_handler();
137 }
Tamas Bana4260892023-06-07 13:35:04 +0200138}