Jimmy Brisson | c4f3eee | 2020-06-23 15:25:05 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
Zelalem | 331ed68 | 2021-03-11 19:46:31 -0600 | [diff] [blame] | 37 | #ifdef __aarch64__ |
Jimmy Brisson | c4f3eee | 2020-06-23 15:25:05 -0500 | [diff] [blame] | 38 | #define SMC_TRNG_RND 0xc4000053 |
Zelalem | 331ed68 | 2021-03-11 19:46:31 -0600 | [diff] [blame] | 39 | #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 Chidanand | afcf466 | 2022-10-21 20:49:53 +0100 | [diff] [blame] | 45 | #endif /* __aarch64__ */ |
Jimmy Brisson | c4f3eee | 2020-06-23 15:25:05 -0500 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Number of TRNG calls defined in the TRNG specification. |
| 49 | */ |
Jayanth Dodderi Chidanand | afcf466 | 2022-10-21 20:49:53 +0100 | [diff] [blame] | 50 | #define TRNG_NUM_CALLS (4U) |
Jimmy Brisson | c4f3eee | 2020-06-23 15:25:05 -0500 | [diff] [blame] | 51 | |
| 52 | #ifndef __ASSEMBLY__ |
| 53 | typedef struct { |
| 54 | uint32_t id; |
| 55 | bool mandatory; |
| 56 | const char *str; |
| 57 | } trng_function_t; |
| 58 | |
| 59 | extern const trng_function_t trng_functions[TRNG_NUM_CALLS]; |
| 60 | int32_t tftf_trng_version(void); |
| 61 | bool tftf_trng_feature_implemented(uint32_t id); |
| 62 | smc_ret_values tftf_trng_uuid(void); |
| 63 | smc_ret_values tftf_trng_rnd(uint32_t nbits); |
| 64 | #endif /* __ASSEMBLY__ */ |
| 65 | |
| 66 | |
| 67 | /******************************************************************************* |
| 68 | * TRNG version |
| 69 | ******************************************************************************/ |
Jayanth Dodderi Chidanand | afcf466 | 2022-10-21 20:49:53 +0100 | [diff] [blame] | 70 | #define TRNG_MAJOR_VER_SHIFT (16) |
| 71 | #define TRNG_VERSION(major, minor) ((major << TRNG_MAJOR_VER_SHIFT)| minor) |
Jimmy Brisson | c4f3eee | 2020-06-23 15:25:05 -0500 | [diff] [blame] | 72 | |
| 73 | /******************************************************************************* |
| 74 | * TRNG error codes |
| 75 | ******************************************************************************/ |
Jayanth Dodderi Chidanand | afcf466 | 2022-10-21 20:49:53 +0100 | [diff] [blame] | 76 | #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 Brisson | c4f3eee | 2020-06-23 15:25:05 -0500 | [diff] [blame] | 81 | |
| 82 | #endif /* __TRNG_H__ */ |