blob: 41600b485f2c03911694f5c7887f71dd25a84870 [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
Zelalem331ed682021-03-11 19:46:31 -060037#ifdef __aarch64__
Jimmy Brissonc4f3eee2020-06-23 15:25:05 -050038#define SMC_TRNG_RND 0xc4000053
Zelalem331ed682021-03-11 19:46:31 -060039#define TRNG_MAX_BITS U(192)
40#define TRNG_ENTROPY_MASK U(0xFFFFFFFFFFFFFFFF)
41#else
42#define SMC_TRNG_RND 0x84000053
43#define TRNG_MAX_BITS U(96)
44#define TRNG_ENTROPY_MASK U(0xFFFFFFFF)
Jayanth Dodderi Chidanandafcf4662022-10-21 20:49:53 +010045#endif /* __aarch64__ */
Jimmy Brissonc4f3eee2020-06-23 15:25:05 -050046
47/*
48 * Number of TRNG calls defined in the TRNG specification.
49 */
Jayanth Dodderi Chidanandafcf4662022-10-21 20:49:53 +010050#define TRNG_NUM_CALLS (4U)
Jimmy Brissonc4f3eee2020-06-23 15:25:05 -050051
52#ifndef __ASSEMBLY__
53typedef struct {
54 uint32_t id;
55 bool mandatory;
56 const char *str;
57} trng_function_t;
58
59extern const trng_function_t trng_functions[TRNG_NUM_CALLS];
60int32_t tftf_trng_version(void);
61bool tftf_trng_feature_implemented(uint32_t id);
62smc_ret_values tftf_trng_uuid(void);
63smc_ret_values tftf_trng_rnd(uint32_t nbits);
64#endif /* __ASSEMBLY__ */
65
66
67/*******************************************************************************
68 * TRNG version
69 ******************************************************************************/
Jayanth Dodderi Chidanandafcf4662022-10-21 20:49:53 +010070#define TRNG_MAJOR_VER_SHIFT (16)
71#define TRNG_VERSION(major, minor) ((major << TRNG_MAJOR_VER_SHIFT)| minor)
Jimmy Brissonc4f3eee2020-06-23 15:25:05 -050072
73/*******************************************************************************
74 * TRNG error codes
75 ******************************************************************************/
Jayanth Dodderi Chidanandafcf4662022-10-21 20:49:53 +010076#define TRNG_E_SUCCESS (0)
77#define TRNG_E_NOT_SUPPORTED (-1)
78#define TRNG_E_INVALID_PARAMS (-2)
79#define TRNG_E_NO_ENTROPY (-3)
80#define TRNG_E_NOT_IMPLEMENTED (-4)
Jimmy Brissonc4f3eee2020-06-23 15:25:05 -050081
82#endif /* __TRNG_H__ */