xref: /rk3399_ARM-atf/plat/arm/board/tc/tc_trng.c (revision b62673c645752a78f649282cfa293e8da09e3bef)
1 /*
2  * Copyright (c) 2017-2024, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arm_acle.h>
8 #include <assert.h>
9 #include <stdbool.h>
10 #include <stdint.h>
11 #include <string.h>
12 
13 #include <lib/mmio.h>
14 #include <lib/psa/rse_platform_api.h>
15 #include <lib/smccc.h>
16 #include <lib/utils_def.h>
17 #include <plat/common/platform.h>
18 #include <platform_def.h>
19 #include <services/trng_svc.h>
20 #include <smccc_helpers.h>
21 
22 DEFINE_SVC_UUID2(_plat_trng_uuid,
23 	0x23523c58, 0x7448, 0x4083, 0x9d, 0x16,
24 	0xe3, 0xfa, 0xb9, 0xf1, 0x73, 0xbc
25 );
26 uuid_t plat_trng_uuid;
27 
28 bool plat_get_entropy(uint64_t *out)
29 {
30 #if CRYPTO_SUPPORT
31 	psa_status_t status;
32 
33 	status = rse_platform_get_entropy((uint8_t *)out, sizeof(*out));
34 	if (status != PSA_SUCCESS) {
35 		printf("Failed for entropy read, psa_status=%d\n", status);
36 		return false;
37 	}
38 #else
39 	/* Dummy value */
40 	*out = 0xABBAEDDAACDCDEAD;
41 #endif
42 
43 	return true;
44 }
45 
46 void plat_entropy_setup(void)
47 {
48 	uint64_t entropy;
49 
50 	plat_trng_uuid = _plat_trng_uuid;
51 
52 	/* Initialise the entropy source and trigger RNG generation */
53 	if (!plat_get_entropy(&entropy)) {
54 		ERROR("Failed to setup entropy\n");
55 		panic();
56 	}
57 }
58