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 | #include <arch_helpers.h> |
| 8 | #include <debug.h> |
| 9 | #include <drivers/arm/arm_gic.h> |
| 10 | #include <irq.h> |
| 11 | #include <platform.h> |
| 12 | #include <trng.h> |
| 13 | #include <sgi.h> |
| 14 | #include <tftf.h> |
| 15 | #include <tftf_lib.h> |
| 16 | |
| 17 | const trng_function_t trng_functions[TRNG_NUM_CALLS] = { |
| 18 | DEFINE_TRNG_FUNC(TRNG_VERSION, true), |
| 19 | DEFINE_TRNG_FUNC(TRNG_FEATURES, true), |
| 20 | DEFINE_TRNG_FUNC(TRNG_UUID, true), |
| 21 | DEFINE_TRNG_FUNC(TRNG_RND, true), |
| 22 | }; |
| 23 | |
| 24 | int32_t tftf_trng_version(void) |
| 25 | { |
| 26 | smc_args args = { SMC_TRNG_VERSION }; |
| 27 | smc_ret_values ret_vals; |
| 28 | |
| 29 | ret_vals = tftf_smc(&args); |
| 30 | return ret_vals.ret0; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | bool tftf_trng_feature_implemented(uint32_t id) |
| 35 | { |
| 36 | smc_args args = { |
| 37 | SMC_TRNG_FEATURES, |
| 38 | id, |
| 39 | }; |
| 40 | smc_ret_values ret_vals; |
| 41 | |
| 42 | ret_vals = tftf_smc(&args); |
| 43 | return ret_vals.ret0 == TRNG_E_SUCCESS; |
| 44 | } |
| 45 | |
| 46 | smc_ret_values tftf_trng_uuid(void) |
| 47 | { |
| 48 | smc_args args = { SMC_TRNG_UUID }; |
| 49 | |
| 50 | return tftf_smc(&args); |
| 51 | } |
| 52 | |
| 53 | smc_ret_values tftf_trng_rnd(uint32_t nbits) |
| 54 | { |
| 55 | smc_args args = { |
| 56 | SMC_TRNG_RND, |
| 57 | nbits, |
| 58 | }; |
| 59 | |
| 60 | return tftf_smc(&args); |
| 61 | } |