blob: 793a90fbce96eeef7ddcc97d723505bba88e091f [file] [log] [blame]
David Vincze7be391d2024-01-04 18:37:12 +01001/*
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 Yan8f0235f2025-01-31 10:20:28 +000014#include <lib/psa/rse_platform_api.h>
David Vincze7be391d2024-01-04 18:37:12 +010015#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
22DEFINE_SVC_UUID2(_plat_trng_uuid,
23 0x23523c58, 0x7448, 0x4083, 0x9d, 0x16,
24 0xe3, 0xfa, 0xb9, 0xf1, 0x73, 0xbc
25);
26uuid_t plat_trng_uuid;
27
David Vincze7be391d2024-01-04 18:37:12 +010028bool plat_get_entropy(uint64_t *out)
29{
Leo Yan8f0235f2025-01-31 10:20:28 +000030#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 Vincze7be391d2024-01-04 18:37:12 +010040 *out = 0xABBAEDDAACDCDEAD;
Leo Yan8f0235f2025-01-31 10:20:28 +000041#endif
David Vincze7be391d2024-01-04 18:37:12 +010042
43 return true;
44}
45
46void plat_entropy_setup(void)
47{
Leo Yan8f0235f2025-01-31 10:20:28 +000048 uint64_t entropy;
David Vincze7be391d2024-01-04 18:37:12 +010049
50 plat_trng_uuid = _plat_trng_uuid;
51
52 /* Initialise the entropy source and trigger RNG generation */
Leo Yan8f0235f2025-01-31 10:20:28 +000053 if (!plat_get_entropy(&entropy)) {
54 ERROR("Failed to setup entropy\n");
55 panic();
56 }
David Vincze7be391d2024-01-04 18:37:12 +010057}