TianoCore EDK2 master
Loading...
Searching...
No Matches
SecMigrationPei.c
Go to the documentation of this file.
1
9#include <Base.h>
10
11#include <Library/BaseLib.h>
13#include <Library/DebugLib.h>
14#include <Library/HobLib.h>
18
19#include "SecMigrationPei.h"
20
21STATIC REPUBLISH_SEC_PPI_PPI mEdkiiRepublishSecPpiPpi = {
23};
24
25GLOBAL_REMOVE_IF_UNREFERENCED EFI_SEC_PLATFORM_INFORMATION_PPI mSecPlatformInformationPostMemoryPpi = {
27};
28
29GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_TEMPORARY_RAM_DONE_PPI mSecTemporaryRamDonePostMemoryPpi = {
31};
32
33GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPostMemoryPpi = {
35};
36
39};
40
41STATIC EFI_PEI_PPI_DESCRIPTOR mEdkiiRepublishSecPpiDescriptor = {
42 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
43 &gRepublishSecPpiPpiGuid,
44 &mEdkiiRepublishSecPpiPpi
45};
46
47GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecPlatformInformationPostMemoryDescriptor = {
48 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
49 &gEfiSecPlatformInformationPpiGuid,
50 &mSecPlatformInformationPostMemoryPpi
51};
52
53GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecTemporaryRamDonePostMemoryDescriptor = {
54 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
55 &gEfiTemporaryRamDonePpiGuid,
56 &mSecTemporaryRamDonePostMemoryPpi
57};
58
59GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecTemporaryRamSupportPostMemoryDescriptor = {
60 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
61 &gEfiTemporaryRamSupportPpiGuid,
62 &mSecTemporaryRamSupportPostMemoryPpi
63};
64
65GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mSecPerformancePpiDescriptor = {
66 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
67 &gPeiSecPerformancePpiGuid,
68 &mSecPerformancePpi
69};
70
81EFIAPI
83 VOID
84 )
85{
86 //
87 // Temporary RAM Done is already done in post-memory
88 // install a stub function that is located in permanent memory
89 //
90 return EFI_SUCCESS;
91}
92
110EFIAPI
112 IN CONST EFI_PEI_SERVICES **PeiServices,
113 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
114 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
115 IN UINTN CopySize
116 )
117{
118 //
119 // Temporary RAM Support is already done in post-memory
120 // install a stub function that is located in permanent memory
121 //
122 return EFI_SUCCESS;
123}
124
144EFIAPI
146 IN CONST EFI_PEI_SERVICES **PeiServices,
148 OUT FIRMWARE_SEC_PERFORMANCE *Performance
149 )
150{
151 SEC_PLATFORM_INFORMATION_CONTEXT_HOB *SecPlatformInformationContexHob;
152
153 if ((This == NULL) || (Performance == NULL)) {
154 return EFI_INVALID_PARAMETER;
155 }
156
157 SecPlatformInformationContexHob = GetFirstGuidHob (&gEfiCallerIdGuid);
158 if (SecPlatformInformationContexHob == NULL) {
159 return EFI_NOT_FOUND;
160 }
161
162 Performance->ResetEnd = SecPlatformInformationContexHob->FirmwareSecPerformance.ResetEnd;
163
164 return EFI_SUCCESS;
165}
166
182EFIAPI
184 IN CONST EFI_PEI_SERVICES **PeiServices,
185 IN OUT UINT64 *StructureSize,
186 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord
187 )
188{
189 SEC_PLATFORM_INFORMATION_CONTEXT_HOB *SecPlatformInformationContexHob;
190
191 if (StructureSize == NULL) {
192 return EFI_INVALID_PARAMETER;
193 }
194
195 SecPlatformInformationContexHob = GetFirstGuidHob (&gEfiCallerIdGuid);
196 if (SecPlatformInformationContexHob == NULL) {
197 return EFI_NOT_FOUND;
198 }
199
200 if (*StructureSize < SecPlatformInformationContexHob->Context.StructureSize) {
201 *StructureSize = SecPlatformInformationContexHob->Context.StructureSize;
202 return EFI_BUFFER_TOO_SMALL;
203 }
204
205 if (PlatformInformationRecord == NULL) {
206 return EFI_INVALID_PARAMETER;
207 }
208
209 *StructureSize = SecPlatformInformationContexHob->Context.StructureSize;
210 CopyMem (
211 (VOID *)PlatformInformationRecord,
212 (VOID *)SecPlatformInformationContexHob->Context.PlatformInformationRecord,
213 (UINTN)SecPlatformInformationContexHob->Context.StructureSize
214 );
215
216 return EFI_SUCCESS;
217}
218
230EFIAPI
232 VOID
233 )
234{
235 EFI_STATUS Status;
236 EFI_PEI_PPI_DESCRIPTOR *PeiPpiDescriptor;
237 VOID *PeiPpi;
238 SEC_PLATFORM_INFORMATION_CONTEXT_HOB *SecPlatformInformationContextHob;
239 EFI_SEC_PLATFORM_INFORMATION_RECORD *SecPlatformInformationPtr;
240 UINT64 SecStructureSize;
241
242 SecPlatformInformationPtr = NULL;
243 SecStructureSize = 0;
244
245 Status = PeiServicesLocatePpi (
246 &gEfiTemporaryRamDonePpiGuid,
247 0,
248 &PeiPpiDescriptor,
249 (VOID **)&PeiPpi
250 );
251 if (!EFI_ERROR (Status)) {
252 Status = PeiServicesReInstallPpi (
253 PeiPpiDescriptor,
254 &mSecTemporaryRamDonePostMemoryDescriptor
255 );
256 ASSERT_EFI_ERROR (Status);
257 }
258
259 Status = PeiServicesLocatePpi (
260 &gEfiTemporaryRamSupportPpiGuid,
261 0,
262 &PeiPpiDescriptor,
263 (VOID **)&PeiPpi
264 );
265 if (!EFI_ERROR (Status)) {
266 Status = PeiServicesReInstallPpi (
267 PeiPpiDescriptor,
268 &mSecTemporaryRamSupportPostMemoryDescriptor
269 );
270 ASSERT_EFI_ERROR (Status);
271 }
272
273 Status = PeiServicesCreateHob (
274 EFI_HOB_TYPE_GUID_EXTENSION,
276 (VOID **)&SecPlatformInformationContextHob
277 );
278 ASSERT_EFI_ERROR (Status);
279 if (EFI_ERROR (Status)) {
280 DEBUG ((DEBUG_ERROR, "SecPlatformInformation Context HOB could not be created.\n"));
281 return Status;
282 }
283
284 SecPlatformInformationContextHob->Header.Name = gEfiCallerIdGuid;
285 SecPlatformInformationContextHob->Revision = 1;
286
287 Status = PeiServicesLocatePpi (
288 &gPeiSecPerformancePpiGuid,
289 0,
290 &PeiPpiDescriptor,
291 (VOID **)&PeiPpi
292 );
293 if (!EFI_ERROR (Status)) {
294 Status = ((PEI_SEC_PERFORMANCE_PPI *)PeiPpi)->GetPerformance (
296 (PEI_SEC_PERFORMANCE_PPI *)PeiPpi,
297 &SecPlatformInformationContextHob->FirmwareSecPerformance
298 );
299 ASSERT_EFI_ERROR (Status);
300 if (!EFI_ERROR (Status)) {
301 Status = PeiServicesReInstallPpi (
302 PeiPpiDescriptor,
303 &mSecPerformancePpiDescriptor
304 );
305 ASSERT_EFI_ERROR (Status);
306 }
307 }
308
309 Status = PeiServicesLocatePpi (
310 &gEfiSecPlatformInformationPpiGuid,
311 0,
312 &PeiPpiDescriptor,
313 (VOID **)&PeiPpi
314 );
315 if (!EFI_ERROR (Status)) {
316 Status = ((EFI_SEC_PLATFORM_INFORMATION_PPI *)PeiPpi)->PlatformInformation (
318 &SecStructureSize,
319 SecPlatformInformationPtr
320 );
321 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
322 if (Status != EFI_BUFFER_TOO_SMALL) {
323 return EFI_NOT_FOUND;
324 }
325
326 ZeroMem ((VOID *)&(SecPlatformInformationContextHob->Context), sizeof (SEC_PLATFORM_INFORMATION_CONTEXT));
327 SecPlatformInformationContextHob->Context.PlatformInformationRecord = AllocatePool ((UINTN)SecStructureSize);
328 ASSERT (SecPlatformInformationContextHob->Context.PlatformInformationRecord != NULL);
329 if (SecPlatformInformationContextHob->Context.PlatformInformationRecord == NULL) {
330 return EFI_OUT_OF_RESOURCES;
331 }
332
333 SecPlatformInformationContextHob->Context.StructureSize = SecStructureSize;
334
335 Status = ((EFI_SEC_PLATFORM_INFORMATION_PPI *)PeiPpi)->PlatformInformation (
337 &(SecPlatformInformationContextHob->Context.StructureSize),
338 SecPlatformInformationContextHob->Context.PlatformInformationRecord
339 );
340 ASSERT_EFI_ERROR (Status);
341 if (!EFI_ERROR (Status)) {
342 Status = PeiServicesReInstallPpi (
343 PeiPpiDescriptor,
344 &mSecPlatformInformationPostMemoryDescriptor
345 );
346 ASSERT_EFI_ERROR (Status);
347 }
348 }
349
350 return EFI_SUCCESS;
351}
352
369EFIAPI
371 IN EFI_PEI_FILE_HANDLE FileHandle,
372 IN CONST EFI_PEI_SERVICES **PeiServices
373 )
374{
375 EFI_STATUS Status;
376
377 Status = EFI_ABORTED;
378
379 if (PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes)) {
380 Status = PeiServicesInstallPpi (&mEdkiiRepublishSecPpiDescriptor);
381 ASSERT_EFI_ERROR (Status);
382 }
383
384 return Status;
385}
UINT64 UINTN
CONST EFI_PEI_SERVICES **EFIAPI GetPeiServicesTablePointer(VOID)
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI PeiServicesCreateHob(IN UINT16 Type, IN UINT16 Length, OUT VOID **Hob)
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 PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
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 STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define GLOBAL_REMOVE_IF_UNREFERENCED
Definition: Base.h:48
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI SecMigrationPeiInitialize(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS EFIAPI SecPlatformInformationPostMemory(IN CONST EFI_PEI_SERVICES **PeiServices, IN OUT UINT64 *StructureSize, OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord)
EFI_STATUS EFIAPI SecTemporaryRamDonePostMemory(VOID)
EFI_STATUS EFIAPI GetPerformancePostMemory(IN CONST EFI_PEI_SERVICES **PeiServices, IN PEI_SEC_PERFORMANCE_PPI *This, OUT FIRMWARE_SEC_PERFORMANCE *Performance)
EFI_STATUS EFIAPI SecTemporaryRamSupportPostMemory(IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, IN UINTN CopySize)
EFI_STATUS EFIAPI RepublishSecPpis(VOID)
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_GUID Name
Definition: PiHob.h:347
UINT64 ResetEnd
Timer value logged at the beginning of firmware image execution, in unit of nanosecond.