1 /*
2  * Copyright (c) 2021-2022, ARM Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef TRNG_SVC_H
8 #define TRNG_SVC_H
9 
10 #include <stdbool.h>
11 #include <stdint.h>
12 
13 #include <lib/smccc.h>
14 
15 /* SMC function IDs for TRNG queries */
16 #define ARM_TRNG_VERSION	U(0x84000050)
17 #define ARM_TRNG_FEATURES	U(0x84000051)
18 #define ARM_TRNG_GET_UUID	U(0x84000052)
19 #define ARM_TRNG_RND32		U(0x84000053)
20 #define ARM_TRNG_RND64		U(0xC4000053)
21 
22 /* TRNG version numbers */
23 #define TRNG_VERSION_MAJOR	(0x1)
24 #define TRNG_VERSION_MINOR	(0x0)
25 
26 /* TRNG Error Numbers */
27 #define TRNG_E_SUCCESS		(0)
28 #define TRNG_E_NOT_SUPPORTED	(-1)
29 #define TRNG_E_INVALID_PARAMS	(-2)
30 #define TRNG_E_NO_ENTROPY	(-3)
31 #define TRNG_E_NOT_IMPLEMENTED	(-4)
32 
33 /* TRNG Entropy Bit Numbers */
34 #define TRNG_RND32_ENTROPY_MAXBITS	(96U)
35 #define TRNG_RND64_ENTROPY_MAXBITS	(192U)
36 
37 /* Public API to perform the initial TRNG entropy setup */
38 void trng_setup(void);
39 
40 /* Public API to verify function id is part of TRNG */
41 bool is_trng_fid(uint32_t smc_fid);
42 
43 /* Handler to be called to handle TRNG smc calls */
44 uintptr_t trng_smc_handler(
45 	uint32_t smc_fid,
46 	u_register_t x1,
47 	u_register_t x2,
48 	u_register_t x3,
49 	u_register_t x4,
50 	void *cookie,
51 	void *handle,
52 	u_register_t flags
53 );
54 
55 #endif /* TRNG_SVC_H */
56