]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/SecCore/SecBist.c
UefiCpuPkg/SecCore: Add SecBist.c
[mirror_edk2.git] / UefiCpuPkg / SecCore / SecBist.c
1 /** @file
2 Get SEC platform information(2) PPI and reinstall it.
3
4 Copyright (c) 2006 - 2016, 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 "SecMain.h"
16
17 /**
18 Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI.
19
20 @param PeiServices The pointer to the PEI Services Table.
21 @param StructureSize The pointer to the variable describing size of the input buffer.
22 @param PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2.
23
24 @retval EFI_SUCCESS The data was successfully returned.
25 @retval EFI_BUFFER_TOO_SMALL The buffer was too small. The current buffer size needed to
26 hold the record is returned in StructureSize.
27
28 **/
29 EFI_STATUS
30 EFIAPI
31 SecPlatformInformation2 (
32 IN CONST EFI_PEI_SERVICES **PeiServices,
33 IN OUT UINT64 *StructureSize,
34 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2
35 )
36 {
37 EFI_HOB_GUID_TYPE *GuidHob;
38 VOID *DataInHob;
39 UINTN DataSize;
40
41 GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformation2PpiGuid);
42 if (GuidHob == NULL) {
43 *StructureSize = 0;
44 return EFI_SUCCESS;
45 }
46
47 DataInHob = GET_GUID_HOB_DATA (GuidHob);
48 DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob);
49
50 //
51 // return the information from BistHob
52 //
53 if ((*StructureSize) < (UINT64) DataSize) {
54 *StructureSize = (UINT64) DataSize;
55 return EFI_BUFFER_TOO_SMALL;
56 }
57
58 *StructureSize = (UINT64) DataSize;
59 CopyMem (PlatformInformationRecord2, DataInHob, DataSize);
60 return EFI_SUCCESS;
61 }
62
63 /**
64 Worker function to get CPUs' BIST by calling SecPlatformInformationPpi
65 or SecPlatformInformation2Ppi.
66
67 @param PeiServices Pointer to PEI Services Table
68 @param Guid PPI Guid
69 @param PpiDescriptor Return a pointer to instance of the
70 EFI_PEI_PPI_DESCRIPTOR
71 @param BistInformationData Pointer to BIST information data
72 @param BistInformationSize Return the size in bytes of BIST information
73
74 @retval EFI_SUCCESS Retrieve of the BIST data successfully
75 @retval EFI_NOT_FOUND No sec platform information(2) ppi export
76 @retval EFI_DEVICE_ERROR Failed to get CPU Information
77
78 **/
79 EFI_STATUS
80 GetBistInfoFromPpi (
81 IN CONST EFI_PEI_SERVICES **PeiServices,
82 IN CONST EFI_GUID *Guid,
83 OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
84 OUT VOID **BistInformationData,
85 OUT UINT64 *BistInformationSize OPTIONAL
86 )
87 {
88 EFI_STATUS Status;
89 EFI_SEC_PLATFORM_INFORMATION2_PPI *SecPlatformInformation2Ppi;
90 EFI_SEC_PLATFORM_INFORMATION_RECORD2 *SecPlatformInformation2;
91 UINT64 InformationSize;
92
93 Status = PeiServicesLocatePpi (
94 Guid, // GUID
95 0, // INSTANCE
96 PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
97 (VOID **)&SecPlatformInformation2Ppi // PPI
98 );
99 if (Status == EFI_NOT_FOUND) {
100 return EFI_NOT_FOUND;
101 }
102
103 if (Status == EFI_SUCCESS) {
104 //
105 // Get the size of the sec platform information2(BSP/APs' BIST data)
106 //
107 InformationSize = 0;
108 SecPlatformInformation2 = NULL;
109 Status = SecPlatformInformation2Ppi->PlatformInformation2 (
110 PeiServices,
111 &InformationSize,
112 SecPlatformInformation2
113 );
114 if (Status == EFI_BUFFER_TOO_SMALL) {
115 Status = PeiServicesAllocatePool (
116 (UINTN) InformationSize,
117 (VOID **) &SecPlatformInformation2
118 );
119 if (Status == EFI_SUCCESS) {
120 //
121 // Retrieve BIST data
122 //
123 Status = SecPlatformInformation2Ppi->PlatformInformation2 (
124 PeiServices,
125 &InformationSize,
126 SecPlatformInformation2
127 );
128 if (Status == EFI_SUCCESS) {
129 *BistInformationData = SecPlatformInformation2;
130 if (BistInformationSize != NULL) {
131 *BistInformationSize = InformationSize;
132 }
133 return EFI_SUCCESS;
134 }
135 }
136 }
137 }
138
139 return EFI_DEVICE_ERROR;
140 }