David Vincze | 7be391d | 2024-01-04 18:37:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2024, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arm_acle.h> |
| 8 | #include <assert.h> |
| 9 | #include <stdbool.h> |
| 10 | #include <stdint.h> |
| 11 | #include <string.h> |
| 12 | |
| 13 | #include <lib/mmio.h> |
Leo Yan | 8f0235f | 2025-01-31 10:20:28 +0000 | [diff] [blame] | 14 | #include <lib/psa/rse_platform_api.h> |
David Vincze | 7be391d | 2024-01-04 18:37:12 +0100 | [diff] [blame] | 15 | #include <lib/smccc.h> |
| 16 | #include <lib/utils_def.h> |
| 17 | #include <plat/common/platform.h> |
| 18 | #include <platform_def.h> |
| 19 | #include <services/trng_svc.h> |
| 20 | #include <smccc_helpers.h> |
| 21 | |
| 22 | DEFINE_SVC_UUID2(_plat_trng_uuid, |
| 23 | 0x23523c58, 0x7448, 0x4083, 0x9d, 0x16, |
| 24 | 0xe3, 0xfa, 0xb9, 0xf1, 0x73, 0xbc |
| 25 | ); |
| 26 | uuid_t plat_trng_uuid; |
| 27 | |
David Vincze | 7be391d | 2024-01-04 18:37:12 +0100 | [diff] [blame] | 28 | bool plat_get_entropy(uint64_t *out) |
| 29 | { |
Leo Yan | 8f0235f | 2025-01-31 10:20:28 +0000 | [diff] [blame] | 30 | #if CRYPTO_SUPPORT |
| 31 | psa_status_t status; |
| 32 | |
| 33 | status = rse_platform_get_entropy((uint8_t *)out, sizeof(*out)); |
| 34 | if (status != PSA_SUCCESS) { |
| 35 | printf("Failed for entropy read, psa_status=%d\n", status); |
| 36 | return false; |
| 37 | } |
| 38 | #else |
| 39 | /* Dummy value */ |
David Vincze | 7be391d | 2024-01-04 18:37:12 +0100 | [diff] [blame] | 40 | *out = 0xABBAEDDAACDCDEAD; |
Leo Yan | 8f0235f | 2025-01-31 10:20:28 +0000 | [diff] [blame] | 41 | #endif |
David Vincze | 7be391d | 2024-01-04 18:37:12 +0100 | [diff] [blame] | 42 | |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | void plat_entropy_setup(void) |
| 47 | { |
Leo Yan | 8f0235f | 2025-01-31 10:20:28 +0000 | [diff] [blame] | 48 | uint64_t entropy; |
David Vincze | 7be391d | 2024-01-04 18:37:12 +0100 | [diff] [blame] | 49 | |
| 50 | plat_trng_uuid = _plat_trng_uuid; |
| 51 | |
| 52 | /* Initialise the entropy source and trigger RNG generation */ |
Leo Yan | 8f0235f | 2025-01-31 10:20:28 +0000 | [diff] [blame] | 53 | if (!plat_get_entropy(&entropy)) { |
| 54 | ERROR("Failed to setup entropy\n"); |
| 55 | panic(); |
| 56 | } |
David Vincze | 7be391d | 2024-01-04 18:37:12 +0100 | [diff] [blame] | 57 | } |