]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/RandomNumberGenerator/RngDxe/Arm/ArmAlgo.c
SecurityPkg/RngDxe: Add Arm support of RngDxe
[mirror_edk2.git] / SecurityPkg / RandomNumberGenerator / RngDxe / Arm / ArmAlgo.c
1 /** @file
2 Arm specific code.
3
4 Copyright (c) 2022, Arm Limited. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 **/
7
8 #include <Library/BaseLib.h>
9 #include <Library/BaseMemoryLib.h>
10 #include <Library/DebugLib.h>
11 #include <Library/MemoryAllocationLib.h>
12 #include <Library/ArmTrngLib.h>
13
14 #include "RngDxeInternals.h"
15
16 // Maximum number of Rng algorithms.
17 #define RNG_AVAILABLE_ALGO_MAX 1
18
19 /** Allocate and initialize mAvailableAlgoArray with the available
20 Rng algorithms. Also update mAvailableAlgoArrayCount.
21
22 @retval EFI_SUCCESS The function completed successfully.
23 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.
24 **/
25 EFI_STATUS
26 EFIAPI
27 GetAvailableAlgorithms (
28 VOID
29 )
30 {
31 UINT16 MajorRevision;
32 UINT16 MinorRevision;
33
34 // Rng algorithms 2 times, one for the allocation, one to populate.
35 mAvailableAlgoArray = AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX);
36 if (mAvailableAlgoArray == NULL) {
37 return EFI_OUT_OF_RESOURCES;
38 }
39
40 // Raw algorithm (Trng)
41 if (!EFI_ERROR (GetArmTrngVersion (&MajorRevision, &MinorRevision))) {
42 CopyMem (
43 &mAvailableAlgoArray[mAvailableAlgoArrayCount],
44 &gEfiRngAlgorithmRaw,
45 sizeof (EFI_RNG_ALGORITHM)
46 );
47 mAvailableAlgoArrayCount++;
48 }
49
50 return EFI_SUCCESS;
51 }