17be391d1SDavid Vincze /*
27be391d1SDavid Vincze * Copyright (c) 2017-2024, ARM Limited and Contributors. All rights reserved.
37be391d1SDavid Vincze *
47be391d1SDavid Vincze * SPDX-License-Identifier: BSD-3-Clause
57be391d1SDavid Vincze */
67be391d1SDavid Vincze
77be391d1SDavid Vincze #include <arm_acle.h>
87be391d1SDavid Vincze #include <assert.h>
97be391d1SDavid Vincze #include <stdbool.h>
107be391d1SDavid Vincze #include <stdint.h>
117be391d1SDavid Vincze #include <string.h>
127be391d1SDavid Vincze
137be391d1SDavid Vincze #include <lib/mmio.h>
14*8f0235fbSLeo Yan #include <lib/psa/rse_platform_api.h>
157be391d1SDavid Vincze #include <lib/smccc.h>
167be391d1SDavid Vincze #include <lib/utils_def.h>
177be391d1SDavid Vincze #include <plat/common/platform.h>
187be391d1SDavid Vincze #include <platform_def.h>
197be391d1SDavid Vincze #include <services/trng_svc.h>
207be391d1SDavid Vincze #include <smccc_helpers.h>
217be391d1SDavid Vincze
227be391d1SDavid Vincze DEFINE_SVC_UUID2(_plat_trng_uuid,
237be391d1SDavid Vincze 0x23523c58, 0x7448, 0x4083, 0x9d, 0x16,
247be391d1SDavid Vincze 0xe3, 0xfa, 0xb9, 0xf1, 0x73, 0xbc
257be391d1SDavid Vincze );
267be391d1SDavid Vincze uuid_t plat_trng_uuid;
277be391d1SDavid Vincze
plat_get_entropy(uint64_t * out)287be391d1SDavid Vincze bool plat_get_entropy(uint64_t *out)
297be391d1SDavid Vincze {
30*8f0235fbSLeo Yan #if CRYPTO_SUPPORT
31*8f0235fbSLeo Yan psa_status_t status;
32*8f0235fbSLeo Yan
33*8f0235fbSLeo Yan status = rse_platform_get_entropy((uint8_t *)out, sizeof(*out));
34*8f0235fbSLeo Yan if (status != PSA_SUCCESS) {
35*8f0235fbSLeo Yan printf("Failed for entropy read, psa_status=%d\n", status);
36*8f0235fbSLeo Yan return false;
37*8f0235fbSLeo Yan }
38*8f0235fbSLeo Yan #else
39*8f0235fbSLeo Yan /* Dummy value */
407be391d1SDavid Vincze *out = 0xABBAEDDAACDCDEAD;
41*8f0235fbSLeo Yan #endif
427be391d1SDavid Vincze
437be391d1SDavid Vincze return true;
447be391d1SDavid Vincze }
457be391d1SDavid Vincze
plat_entropy_setup(void)467be391d1SDavid Vincze void plat_entropy_setup(void)
477be391d1SDavid Vincze {
48*8f0235fbSLeo Yan uint64_t entropy;
497be391d1SDavid Vincze
507be391d1SDavid Vincze plat_trng_uuid = _plat_trng_uuid;
517be391d1SDavid Vincze
527be391d1SDavid Vincze /* Initialise the entropy source and trigger RNG generation */
53*8f0235fbSLeo Yan if (!plat_get_entropy(&entropy)) {
54*8f0235fbSLeo Yan ERROR("Failed to setup entropy\n");
55*8f0235fbSLeo Yan panic();
56*8f0235fbSLeo Yan }
577be391d1SDavid Vincze }
58