Jimmy Brisson | 26c5b5c | 2020-06-22 14:18:42 -0500 | [diff] [blame] | 1 | /* |
Jayanth Dodderi Chidanand | 7c7faff | 2022-10-11 17:16:07 +0100 | [diff] [blame] | 2 | * Copyright (c) 2021-2022, ARM Limited. All rights reserved. |
Jimmy Brisson | 26c5b5c | 2020-06-22 14:18:42 -0500 | [diff] [blame] | 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) |
Jayanth Dodderi Chidanand | 7c7faff | 2022-10-11 17:16:07 +0100 | [diff] [blame] | 20 | #define ARM_TRNG_RND64 U(0xC4000053) |
Jimmy Brisson | 26c5b5c | 2020-06-22 14:18:42 -0500 | [diff] [blame] | 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 | |
Jayanth Dodderi Chidanand | 7c7faff | 2022-10-11 17:16:07 +0100 | [diff] [blame] | 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 */ |
Jimmy Brisson | 26c5b5c | 2020-06-22 14:18:42 -0500 | [diff] [blame] | 38 | void trng_setup(void); |
Jayanth Dodderi Chidanand | 7c7faff | 2022-10-11 17:16:07 +0100 | [diff] [blame] | 39 | |
| 40 | /* Public API to verify function id is part of TRNG */ |
Jimmy Brisson | 26c5b5c | 2020-06-22 14:18:42 -0500 | [diff] [blame] | 41 | bool is_trng_fid(uint32_t smc_fid); |
Jimmy Brisson | 26c5b5c | 2020-06-22 14:18:42 -0500 | [diff] [blame] | 42 | |
Jayanth Dodderi Chidanand | 7c7faff | 2022-10-11 17:16:07 +0100 | [diff] [blame] | 43 | /* Handler to be called to handle TRNG smc calls */ |
Jimmy Brisson | 26c5b5c | 2020-06-22 14:18:42 -0500 | [diff] [blame] | 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 */ |