xref: /rk3399_ARM-atf/lib/psa/rse_platform.c (revision a1f10d80560f5c7f14852c5af03440385131c679)
1 /*
2  * Copyright (c) 2023-2025, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include <psa/client.h>
9 #include <psa_manifest/sid.h>
10 #if CRYPTO_SUPPORT
11 #include <rse_crypto_defs.h>
12 #endif
13 #include <rse_platform_api.h>
14 
15 psa_status_t
rse_platform_nv_counter_increment(uint32_t counter_id)16 rse_platform_nv_counter_increment(uint32_t counter_id)
17 {
18 	struct psa_invec in_vec[1];
19 
20 	in_vec[0].base = &counter_id;
21 	in_vec[0].len = sizeof(counter_id);
22 
23 	return psa_call(RSE_PLATFORM_SERVICE_HANDLE,
24 			RSE_PLATFORM_API_ID_NV_INCREMENT,
25 			in_vec, 1, NULL, 0);
26 }
27 
28 psa_status_t
rse_platform_nv_counter_read(uint32_t counter_id,uint32_t size,uint8_t * val)29 rse_platform_nv_counter_read(uint32_t counter_id,
30 		uint32_t size, uint8_t *val)
31 {
32 	struct psa_invec in_vec[1];
33 	struct psa_outvec out_vec[1];
34 
35 	in_vec[0].base = &counter_id;
36 	in_vec[0].len = sizeof(counter_id);
37 
38 	out_vec[0].base = val;
39 	out_vec[0].len = size;
40 
41 	return psa_call(RSE_PLATFORM_SERVICE_HANDLE,
42 			RSE_PLATFORM_API_ID_NV_READ,
43 			in_vec, 1, out_vec, 1);
44 }
45 
46 #if CRYPTO_SUPPORT
47 psa_status_t
rse_platform_get_entropy(uint8_t * data,size_t data_size)48 rse_platform_get_entropy(uint8_t *data, size_t data_size)
49 {
50 	psa_status_t status;
51 
52 	struct rse_crypto_pack_iovec iov = {
53 		.function_id = RSE_CRYPTO_GENERATE_RANDOM_SID,
54 	};
55 
56 	psa_invec in_vec[] = {
57 		{.base = &iov, .len = sizeof(struct rse_crypto_pack_iovec)},
58 	};
59 	psa_outvec out_vec[] = {
60 		{.base = data, .len = data_size}
61 	};
62 
63 	status = psa_call(RSE_CRYPTO_HANDLE, PSA_IPC_CALL,
64 			  in_vec, IOVEC_LEN(in_vec),
65 			  out_vec, IOVEC_LEN(out_vec));
66 
67 	return status;
68 }
69 #endif
70