ArmAlgo.c 1.3 KB

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