blob: 010362468f1669679a316c4a678ccbdf8fba076b [file] [log] [blame]
Jimmy Brissonc4f3eee2020-06-23 15:25:05 -05001/*
2 * Copyright (c) 2021, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/*
8 * Definitions related to the True Random Number Generator (TRNG)
9 * as per the SMC Calling Convention.
10 *
11 * TRNG calls are a subset of the Standard Service Calls.
12 */
13
14#ifndef __TRNG_H__
15#define __TRNG_H__
16
17#ifndef __ASSEMBLY__
18#include <platform_def.h>
19#include <stdbool.h>
20#include <stdint.h>
21#include <tftf_lib.h>
22#endif
23
24/*******************************************************************************
25 * Macro to create the array entry for trng_functions[]
26 ******************************************************************************/
27#define DEFINE_TRNG_FUNC(_func_id, _mandatory) \
28 { SMC_##_func_id, _mandatory, "SMC_" # _func_id }
29
30/*******************************************************************************
31 * Defines for runtime services function ids
32 ******************************************************************************/
33#define SMC_TRNG_VERSION 0x84000050
34#define SMC_TRNG_FEATURES 0x84000051
35#define SMC_TRNG_UUID 0x84000052
36
37#ifndef __aarch64__
38#define SMC_TRNG_RND 0x84000053
39#else
40#define SMC_TRNG_RND 0xc4000053
41#endif
42
43/*
44 * Number of TRNG calls defined in the TRNG specification.
45 */
46#define TRNG_NUM_CALLS 5
47
48#ifndef __ASSEMBLY__
49typedef struct {
50 uint32_t id;
51 bool mandatory;
52 const char *str;
53} trng_function_t;
54
55extern const trng_function_t trng_functions[TRNG_NUM_CALLS];
56int32_t tftf_trng_version(void);
57bool tftf_trng_feature_implemented(uint32_t id);
58smc_ret_values tftf_trng_uuid(void);
59smc_ret_values tftf_trng_rnd(uint32_t nbits);
60#endif /* __ASSEMBLY__ */
61
62
63/*******************************************************************************
64 * TRNG version
65 ******************************************************************************/
66#define TRNG_MAJOR_VER_SHIFT (16)
67#define TRNG_VERSION(major, minor) ((major << TRNG_MAJOR_VER_SHIFT) \
68 | minor)
69
70/*******************************************************************************
71 * TRNG error codes
72 ******************************************************************************/
73#define TRNG_E_SUCCESS (0)
74#define TRNG_E_NOT_SUPPORTED (-1)
75#define TRNG_E_INVALID_PARAMS (-2)
76#define TRNG_E_NO_ENTOPY (-3)
77#define TRNG_E_NOT_IMPLEMENTED (-4)
78
79#endif /* __TRNG_H__ */