TianoCore EDK2 master
Loading...
Searching...
No Matches
SecBist.c
Go to the documentation of this file.
1
9#include "SecMain.h"
10
11EFI_SEC_PLATFORM_INFORMATION_PPI mSecPlatformInformation = {
13};
14
15EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformation = {
16 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
17 &gEfiSecPlatformInformationPpiGuid,
18 &mSecPlatformInformation
19};
20
21EFI_SEC_PLATFORM_INFORMATION2_PPI mSecPlatformInformation2 = {
23};
24
25EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformation2 = {
26 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
27 &gEfiSecPlatformInformation2PpiGuid,
28 &mSecPlatformInformation2
29};
30
43 IN OUT UINT64 *StructureSize,
44 IN OUT VOID *StructureBuffer
45 )
46{
47 EFI_HOB_GUID_TYPE *GuidHob;
48 VOID *DataInHob;
49 UINTN DataSize;
50
51 GuidHob = GetFirstGuidHob (&gEfiCallerIdGuid);
52 if (GuidHob == NULL) {
53 *StructureSize = 0;
54 return EFI_SUCCESS;
55 }
56
57 DataInHob = GET_GUID_HOB_DATA (GuidHob);
58 DataSize = GET_GUID_HOB_DATA_SIZE (GuidHob);
59
60 //
61 // return the information from BistHob
62 //
63 if ((*StructureSize) < (UINT64)DataSize) {
64 *StructureSize = (UINT64)DataSize;
65 return EFI_BUFFER_TOO_SMALL;
66 }
67
68 *StructureSize = (UINT64)DataSize;
69 CopyMem (StructureBuffer, DataInHob, DataSize);
70 return EFI_SUCCESS;
71}
72
85EFIAPI
87 IN CONST EFI_PEI_SERVICES **PeiServices,
88 IN OUT UINT64 *StructureSize,
89 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord
90 )
91{
92 return GetBistFromHob (StructureSize, PlatformInformationRecord);
93}
94
108EFIAPI
110 IN CONST EFI_PEI_SERVICES **PeiServices,
111 IN OUT UINT64 *StructureSize,
112 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2
113 )
114{
115 return GetBistFromHob (StructureSize, PlatformInformationRecord2);
116}
117
136 IN CONST EFI_PEI_SERVICES **PeiServices,
137 IN CONST EFI_GUID *Guid,
138 OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
139 OUT VOID **BistInformationData,
140 OUT UINT64 *BistInformationSize OPTIONAL
141 )
142{
143 EFI_STATUS Status;
144 EFI_SEC_PLATFORM_INFORMATION2_PPI *SecPlatformInformation2Ppi;
146 UINT64 InformationSize;
147
148 Status = PeiServicesLocatePpi (
149 Guid, // GUID
150 0, // INSTANCE
151 PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
152 (VOID **)&SecPlatformInformation2Ppi // PPI
153 );
154 if (Status == EFI_NOT_FOUND) {
155 return EFI_NOT_FOUND;
156 }
157
158 if (Status == EFI_SUCCESS) {
159 //
160 // Get the size of the sec platform information2(BSP/APs' BIST data)
161 //
162 InformationSize = 0;
164 Status = SecPlatformInformation2Ppi->PlatformInformation2 (
165 PeiServices,
166 &InformationSize,
168 );
169 if (Status == EFI_BUFFER_TOO_SMALL) {
170 Status = PeiServicesAllocatePool (
171 (UINTN)InformationSize,
173 );
174 if (Status == EFI_SUCCESS) {
175 //
176 // Retrieve BIST data
177 //
178 Status = SecPlatformInformation2Ppi->PlatformInformation2 (
179 PeiServices,
180 &InformationSize,
182 );
183 if (Status == EFI_SUCCESS) {
184 *BistInformationData = SecPlatformInformation2;
185 if (BistInformationSize != NULL) {
186 *BistInformationSize = InformationSize;
187 }
188
189 return EFI_SUCCESS;
190 }
191 }
192 }
193 }
194
195 return EFI_DEVICE_ERROR;
196}
197
202VOID
204 VOID
205 )
206{
207 EFI_STATUS Status;
208 CONST EFI_PEI_SERVICES **PeiServices;
209 UINT64 BistInformationSize;
210 VOID *BistInformationData;
211 EFI_PEI_PPI_DESCRIPTOR *SecInformationDescriptor;
212
213 PeiServices = GetPeiServicesTablePointer ();
214 Status = GetBistInfoFromPpi (
215 PeiServices,
216 &gEfiSecPlatformInformation2PpiGuid,
217 &SecInformationDescriptor,
218 &BistInformationData,
219 &BistInformationSize
220 );
221 if (Status == EFI_SUCCESS) {
223 &gEfiCallerIdGuid,
224 BistInformationData,
225 (UINTN)BistInformationSize
226 );
227 //
228 // The old SecPlatformInformation2 data is on temporary memory.
229 // After memory discovered, we should never get it from temporary memory,
230 // or the data will be crashed. So, we reinstall SecPlatformInformation2 PPI here.
231 //
232 Status = PeiServicesReInstallPpi (
233 SecInformationDescriptor,
234 &mPeiSecPlatformInformation2
235 );
236 }
237
238 if (Status == EFI_NOT_FOUND) {
239 Status = GetBistInfoFromPpi (
240 PeiServices,
241 &gEfiSecPlatformInformationPpiGuid,
242 &SecInformationDescriptor,
243 &BistInformationData,
244 &BistInformationSize
245 );
246 if (Status == EFI_SUCCESS) {
248 &gEfiCallerIdGuid,
249 BistInformationData,
250 (UINTN)BistInformationSize
251 );
252 //
253 // The old SecPlatformInformation data is on temporary memory.
254 // After memory discovered, we should never get it from temporary memory,
255 // or the data will be crashed. So, we reinstall SecPlatformInformation PPI here.
256 //
257 Status = PeiServicesReInstallPpi (
258 SecInformationDescriptor,
259 &mPeiSecPlatformInformation
260 );
261 } else if (Status == EFI_NOT_FOUND) {
262 return;
263 }
264 }
265
266 ASSERT_EFI_ERROR (Status);
267}
UINT64 UINTN
CONST EFI_PEI_SERVICES **EFIAPI GetPeiServicesTablePointer(VOID)
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI BuildGuidDataHob(IN CONST EFI_GUID *Guid, IN VOID *Data, IN UINTN DataLength)
Definition: HobLib.c:375
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS EFIAPI SecPlatformInformation2(IN CONST EFI_PEI_SERVICES **PeiServices, IN OUT UINT64 *StructureSize, OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2)
Definition: CpuBist.c:35
EFI_STATUS EFIAPI PeiServicesAllocatePool(IN UINTN Size, OUT VOID **Buffer)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI PeiServicesReInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi, IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
VOID RepublishSecPlatformInformationPpi(VOID)
Definition: SecBist.c:203
EFI_STATUS EFIAPI SecPlatformInformationBist(IN CONST EFI_PEI_SERVICES **PeiServices, IN OUT UINT64 *StructureSize, OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord)
Definition: SecBist.c:86
EFI_STATUS EFIAPI SecPlatformInformation2Bist(IN CONST EFI_PEI_SERVICES **PeiServices, IN OUT UINT64 *StructureSize, OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2)
Definition: SecBist.c:109
EFI_STATUS GetBistFromHob(IN OUT UINT64 *StructureSize, IN OUT VOID *StructureBuffer)
Definition: SecBist.c:42
EFI_STATUS GetBistInfoFromPpi(IN CONST EFI_PEI_SERVICES **PeiServices, IN CONST EFI_GUID *Guid, OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, OUT VOID **BistInformationData, OUT UINT64 *BistInformationSize OPTIONAL)
Definition: SecBist.c:135
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213