11/*
2- * Copyright (c) 2021-2024 , Arm Limited and Contributors. All rights reserved.
2+ * Copyright (c) 2021-2025 , Arm Limited and Contributors. All rights reserved.
33 *
44 * SPDX-License-Identifier: BSD-3-Clause
55 */
1515
1616#include <platform_def.h>
1717
18+ #define RMI_ERROR_REALM 2U
19+ #define RMI_ERROR_NOT_SUPPORTED 6U
20+
21+ #define DIR_BIT_SHIFT 0x8
22+ #define KEYSET_SHIFT 0xC
23+ #define STREAM_ID_MASK 0xFF
24+ #define STREAM_ID_SHIFT 0x0
25+ #define SUBSTREAM_MASK 0x7
26+ #define SUBSTREAM_SHIFT 0x8
27+
28+ #define KEY_SET 0x0
29+ #define DIR_VAL 0x0
30+ #define SUBSTREAM_VAL 0x1
31+ #define STREAM_ID 0x1
32+
33+ #define ENCODE_STREAM_INFO (key , dir , substream , stream_id ) \
34+ (((key & 0x1) << KEYSET_SHIFT) | \
35+ ((dir & 0x1) << DIR_BIT_SHIFT) | \
36+ ((substream && SUBSTREAM_MASK) << SUBSTREAM_SHIFT) | \
37+ ((stream_id && STREAM_ID_MASK) << STREAM_ID_SHIFT))
38+
1839/* Parameters received from the previous image */
1940static unsigned int trp_boot_abi_version ;
2041static uintptr_t trp_shared_region_start ;
@@ -129,7 +150,7 @@ static void trp_asc_mark_realm(unsigned long long x1,
129150{
130151 VERBOSE ("Delegating granule 0x%llx\n" , x1 );
131152 smc_ret -> x [0 ] = trp_smc (set_smc_args (RMM_GTSI_DELEGATE , x1 ,
132- 0UL , 0UL , 0UL , 0UL , 0UL , 0UL ));
153+ 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL ));
133154
134155 if (smc_ret -> x [0 ] != 0ULL ) {
135156 ERROR ("Granule transition from NON-SECURE type to REALM type "
@@ -145,14 +166,70 @@ static void trp_asc_mark_nonsecure(unsigned long long x1,
145166{
146167 VERBOSE ("Undelegating granule 0x%llx\n" , x1 );
147168 smc_ret -> x [0 ] = trp_smc (set_smc_args (RMM_GTSI_UNDELEGATE , x1 ,
148- 0UL , 0UL , 0UL , 0UL , 0UL , 0UL ));
169+ 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL ));
149170
150171 if (smc_ret -> x [0 ] != 0ULL ) {
151172 ERROR ("Granule transition from REALM type to NON-SECURE type "
152173 "failed 0x%llx\n" , smc_ret -> x [0 ]);
153174 }
154175}
155176
177+ /*******************************************************************************
178+ * Test the IDE Key management interface
179+ ******************************************************************************/
180+ static void trp_ide_keymgmt_interface_fn (unsigned long long x1 , unsigned long long x2 ,
181+ struct trp_smc_result * smc_ret )
182+ {
183+ uint64_t ecam_address = 0U , rp_id = 0U , ide_stream_info ;
184+ uint64_t keyqw0 , keyqw1 , keyqw2 , keyqw3 ;
185+ uint64_t ifvqw0 , ifvqw1 ;
186+ int return_value ;
187+
188+ #if RMMD_ENABLE_IDE_KEY_PROG
189+ trp_get_test_rootport (& ecam_address , & rp_id );
190+ #endif /* RMMD_ENABLE_IDE_KEY_PROG */
191+ /*
192+ * Dummy values for testing:
193+ * Key set = 0x0
194+ * Dir = 0x0
195+ * Substream = 0x1
196+ * Stream ID = 0x1
197+ */
198+ ide_stream_info = ENCODE_STREAM_INFO (KEY_SET , DIR_VAL , SUBSTREAM_VAL , STREAM_ID );
199+
200+ /* Dummy key and IV values for testing */
201+ keyqw0 = 0xA1B2C3D4E5F60708 ;
202+ keyqw1 = 0x1122334455667788 ;
203+ keyqw2 = 0xDEADBEEFCAFEBABE ;
204+ keyqw3 = 0x1234567890ABCDEF ;
205+ ifvqw0 = 0xABCDEF0123456789 ;
206+ ifvqw1 = 0x9876543210FEDCBA ;
207+
208+ return_value = trp_smc (set_smc_args (RMM_IDE_KEY_PROG , ecam_address , rp_id ,
209+ ide_stream_info , keyqw0 , keyqw1 , keyqw2 , keyqw3 , ifvqw0 ,
210+ ifvqw1 , 0UL , 0UL ));
211+
212+ INFO ("return value from RMM_IDE_KEY_PROG = %d\n" , return_value );
213+
214+ return_value = trp_smc (set_smc_args (RMM_IDE_KEY_SET_GO , ecam_address , rp_id ,
215+ ide_stream_info , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL ));
216+
217+ INFO ("return value from RMM_IDE_KEY_SET_GO = %d\n" , return_value );
218+
219+ return_value = trp_smc (set_smc_args (RMM_IDE_KEY_SET_STOP , ecam_address , rp_id ,
220+ ide_stream_info , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL ));
221+
222+ INFO ("return value from RMM_IDE_KEY_SET_STOP = %d\n" , return_value );
223+
224+ return_value = trp_smc (set_smc_args (RMM_IDE_KM_PULL_RESPONSE , ecam_address , rp_id ,
225+ 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL , 0UL ));
226+
227+ INFO ("return value from RMM_IDE_KEY_SET_STOP = %d\n" , return_value );
228+
229+ smc_ret -> x [0 ] = RMI_ERROR_NOT_SUPPORTED ;
230+
231+ }
232+
156233/*******************************************************************************
157234 * Main RMI SMC handler function
158235 ******************************************************************************/
@@ -179,6 +256,9 @@ void trp_rmi_handler(unsigned long fid,
179256 case RMI_RMM_GRANULE_UNDELEGATE :
180257 trp_asc_mark_nonsecure (x1 , smc_ret );
181258 break ;
259+ case RMI_RMM_PDEV_CREATE :
260+ trp_ide_keymgmt_interface_fn (x1 , x2 , smc_ret );
261+ break ;
182262 default :
183263 ERROR ("Invalid SMC code to %s, FID %lx\n" , __func__ , fid );
184264 smc_ret -> x [0 ] = SMC_UNK ;
0 commit comments