1 /** @file
2 Sample to provide SecPlatformInformation function.
3
4 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <PiPei.h>
16
17 #include <Ppi/SecPlatformInformation.h>
18 #include <Ppi/TopOfTemporaryRam.h>
19
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/DebugLib.h>
22
23 /**
24 This interface conveys state information out of the Security (SEC) phase into PEI.
25
26 @param[in] PeiServices Pointer to the PEI Services Table.
27 @param[in,out] StructureSize Pointer to the variable describing size of the input buffer.
28 @param[out] PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.
29
30 @retval EFI_SUCCESS The data was successfully returned.
31 @retval EFI_BUFFER_TOO_SMALL The buffer was too small.
32
33 **/
34 EFI_STATUS
35 EFIAPI
SecPlatformInformation(IN CONST EFI_PEI_SERVICES ** PeiServices,IN OUT UINT64 * StructureSize,OUT EFI_SEC_PLATFORM_INFORMATION_RECORD * PlatformInformationRecord)36 SecPlatformInformation (
37 IN CONST EFI_PEI_SERVICES **PeiServices,
38 IN OUT UINT64 *StructureSize,
39 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord
40 )
41 {
42 UINT32 *Bist;
43 UINT32 Size;
44 UINT32 Count;
45 UINT32 TopOfTemporaryRam;
46 VOID *TopOfTemporaryRamPpi;
47 EFI_STATUS Status;
48
49 DEBUG ((DEBUG_INFO, "SecPlatformInformation\n"));
50
51 Status = (*PeiServices)->LocatePpi (
52 PeiServices,
53 &gTopOfTemporaryRamPpiGuid,
54 0,
55 NULL,
56 (VOID **) &TopOfTemporaryRamPpi
57 );
58 if (EFI_ERROR (Status)) {
59 return EFI_NOT_FOUND;
60 }
61
62 //
63 // The entries of BIST information, together with the number of them,
64 // reside in the bottom of stack, left untouched by normal stack operation.
65 // This routine copies the BIST information to the buffer pointed by
66 // PlatformInformationRecord for output.
67 //
68 TopOfTemporaryRam = (UINT32)(UINTN)TopOfTemporaryRamPpi - sizeof (UINT32);
69 TopOfTemporaryRam -= sizeof(UINT32) * 2;
70 Count = *((UINT32 *)(UINTN) (TopOfTemporaryRam - sizeof (UINT32)));
71 Size = Count * sizeof (IA32_HANDOFF_STATUS);
72
73 if ((*StructureSize) < (UINT64) Size) {
74 *StructureSize = Size;
75 return EFI_BUFFER_TOO_SMALL;
76 }
77
78 *StructureSize = Size;
79 Bist = (UINT32 *) (TopOfTemporaryRam - sizeof (UINT32) - Size);
80
81 CopyMem (PlatformInformationRecord, Bist, Size);
82
83 return EFI_SUCCESS;
84 }
85