SecPlatformInformation.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /** @file
  2. Sample to provide SecPlatformInformation function.
  3. @copyright
  4. Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <PiPei.h>
  8. #include <Ppi/SecPlatformInformation.h>
  9. #include <Ppi/TopOfTemporaryRam.h>
  10. #include <Library/BaseMemoryLib.h>
  11. #include <Library/DebugLib.h>
  12. /**
  13. This interface conveys state information out of the Security (SEC) phase into PEI.
  14. @param[in] PeiServices Pointer to the PEI Services Table.
  15. @param[in,out] StructureSize Pointer to the variable describing size of the input buffer.
  16. @param[out] PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.
  17. @retval EFI_SUCCESS The data was successfully returned.
  18. @retval EFI_BUFFER_TOO_SMALL The buffer was too small.
  19. **/
  20. EFI_STATUS
  21. EFIAPI
  22. SecPlatformInformation (
  23. IN CONST EFI_PEI_SERVICES **PeiServices,
  24. IN OUT UINT64 *StructureSize,
  25. OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord
  26. )
  27. {
  28. UINT32 *Bist;
  29. UINT32 Size;
  30. UINT32 Count;
  31. UINTN TopOfTemporaryRam;
  32. VOID *TopOfTemporaryRamPpi;
  33. EFI_STATUS Status;
  34. DEBUG ((DEBUG_INFO, "SecPlatformInformation\n"));
  35. Status = (*PeiServices)->LocatePpi (
  36. PeiServices,
  37. &gTopOfTemporaryRamPpiGuid,
  38. 0,
  39. NULL,
  40. (VOID **) &TopOfTemporaryRamPpi
  41. );
  42. if (EFI_ERROR (Status)) {
  43. return EFI_NOT_FOUND;
  44. }
  45. //
  46. // The entries of BIST information, together with the number of them,
  47. // reside in the bottom of stack, left untouched by normal stack operation.
  48. // This routine copies the BIST information to the buffer pointed by
  49. // PlatformInformationRecord for output.
  50. //
  51. TopOfTemporaryRam = (UINTN) TopOfTemporaryRamPpi - sizeof (UINT32);
  52. TopOfTemporaryRam -= sizeof (UINT32) * 2;
  53. Count = *((UINT32 *)(TopOfTemporaryRam - sizeof (UINT32)));
  54. Size = Count * sizeof (IA32_HANDOFF_STATUS);
  55. if ((*StructureSize) < (UINT64) Size) {
  56. *StructureSize = Size;
  57. return EFI_BUFFER_TOO_SMALL;
  58. }
  59. *StructureSize = Size;
  60. Bist = (UINT32 *) (TopOfTemporaryRam - sizeof (UINT32) - Size);
  61. CopyMem (PlatformInformationRecord, Bist, Size);
  62. return EFI_SUCCESS;
  63. }