]> git.proxmox.com Git - mirror_edk2.git/blob - InOsEmuPkg/Library/SecPeiServicesLib/PeiServicesLib.c
Added generic EFIABI SEC to InOsEmuPkg. Add library to abstract FV cracking and remov...
[mirror_edk2.git] / InOsEmuPkg / Library / SecPeiServicesLib / PeiServicesLib.c
1 /** @file
2 Implementation for PEI Services Library.
3
4 Copyright (c) 2006 - 2010, 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
16 #include <PiPei.h>
17
18 #include <Library/PeiServicesLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/PpiListLib.h>
22
23
24
25 EFI_STATUS
26 SecFfsFindNextFile (
27 IN EFI_FV_FILETYPE SearchType,
28 IN EFI_PEI_FV_HANDLE VolumeHandle,
29 IN OUT EFI_PEI_FILE_HANDLE *FileHandle
30 );
31
32 EFI_STATUS
33 SecFfsFindSectionData (
34 IN EFI_SECTION_TYPE SectionType,
35 IN EFI_PEI_FILE_HANDLE FileHandle,
36 OUT VOID **SectionData
37 );
38
39
40 /**
41 This service enables a given PEIM to register an interface into the PEI Foundation.
42
43 @param PpiList A pointer to the list of interfaces that the caller shall install.
44
45 @retval EFI_SUCCESS The interface was successfully installed.
46 @retval EFI_INVALID_PARAMETER The PpiList pointer is NULL.
47 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
48 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
49 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
50
51 **/
52 EFI_STATUS
53 EFIAPI
54 PeiServicesInstallPpi (
55 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList
56 )
57 {
58 ASSERT (FALSE);
59 return EFI_OUT_OF_RESOURCES;
60 }
61
62 /**
63 This service enables PEIMs to replace an entry in the PPI database with an alternate entry.
64
65 @param OldPpi The pointer to the old PEI PPI Descriptors.
66 @param NewPpi The pointer to the new PEI PPI Descriptors.
67
68 @retval EFI_SUCCESS The interface was successfully installed.
69 @retval EFI_INVALID_PARAMETER The OldPpi or NewPpi is NULL.
70 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
71 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
72 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
73 @retval EFI_NOT_FOUND The PPI for which the reinstallation was requested has not been
74 installed.
75
76 **/
77 EFI_STATUS
78 EFIAPI
79 PeiServicesReInstallPpi (
80 IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi,
81 IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi
82 )
83 {
84 ASSERT (FALSE);
85 return EFI_OUT_OF_RESOURCES;
86 }
87
88 /**
89 This service enables PEIMs to discover a given instance of an interface.
90
91 So this is, well a hack, so we can reuse the same libraries as the PEI Core
92 for XIP modules....
93
94 @param Guid A pointer to the GUID whose corresponding interface needs to be
95 found.
96 @param Instance The N-th instance of the interface that is required.
97 @param PpiDescriptor A pointer to instance of the EFI_PEI_PPI_DESCRIPTOR.
98 @param Ppi A pointer to the instance of the interface.
99
100 @retval EFI_SUCCESS The interface was successfully returned.
101 @retval EFI_NOT_FOUND The PPI descriptor is not found in the database.
102
103 **/
104 EFI_STATUS
105 EFIAPI
106 PeiServicesLocatePpi (
107 IN CONST EFI_GUID *Guid,
108 IN UINTN Instance,
109 IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
110 IN OUT VOID **Ppi
111 )
112 {
113 EFI_PEI_PPI_DESCRIPTOR *PpiList;
114
115 if (Instance != 0) {
116 return EFI_NOT_FOUND;
117 }
118
119
120 for (PpiList = (EFI_PEI_PPI_DESCRIPTOR *)gPpiList; ; PpiList++) {
121 if (CompareGuid (PpiList->Guid, Guid)) {
122 if (PpiDescriptor != NULL) {
123 *PpiDescriptor = PpiList;
124 }
125 if (Ppi != NULL) {
126 *Ppi = PpiList->Ppi;
127 }
128 return EFI_SUCCESS;
129 }
130
131 if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {
132 break;
133 }
134 }
135
136
137 return EFI_NOT_FOUND;
138 }
139
140 /**
141 This service enables PEIMs to register a given service to be invoked when another service is
142 installed or reinstalled.
143
144 @param NotifyList A pointer to the list of notification interfaces
145 that the caller shall install.
146
147 @retval EFI_SUCCESS The interface was successfully installed.
148 @retval EFI_INVALID_PARAMETER The NotifyList pointer is NULL.
149 @retval EFI_INVALID_PARAMETER Any of the PEI notify descriptors in the list do
150 not have the EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES
151 bit set in the Flags field.
152 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
153
154 **/
155 EFI_STATUS
156 EFIAPI
157 PeiServicesNotifyPpi (
158 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList
159 )
160 {
161 ASSERT (FALSE);
162 return EFI_OUT_OF_RESOURCES;
163 }
164
165 /**
166 This service enables PEIMs to ascertain the present value of the boot mode.
167
168 @param BootMode A pointer to contain the value of the boot mode.
169
170 @retval EFI_SUCCESS The boot mode was returned successfully.
171 @retval EFI_INVALID_PARAMETER BootMode is NULL.
172
173 **/
174 EFI_STATUS
175 EFIAPI
176 PeiServicesGetBootMode (
177 OUT EFI_BOOT_MODE *BootMode
178 )
179 {
180 ASSERT (FALSE);
181 return EFI_OUT_OF_RESOURCES;
182 }
183
184 /**
185 This service enables PEIMs to update the boot mode variable.
186
187 @param BootMode The value of the boot mode to set.
188
189 @retval EFI_SUCCESS The value was successfully updated
190
191 **/
192 EFI_STATUS
193 EFIAPI
194 PeiServicesSetBootMode (
195 IN EFI_BOOT_MODE BootMode
196 )
197 {
198 ASSERT (FALSE);
199 return EFI_OUT_OF_RESOURCES;
200 }
201
202 /**
203 This service enables a PEIM to ascertain the address of the list of HOBs in memory.
204
205 @param HobList A pointer to the list of HOBs that the PEI Foundation
206 will initialize.
207
208 @retval EFI_SUCCESS The list was successfully returned.
209 @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
210
211 **/
212 EFI_STATUS
213 EFIAPI
214 PeiServicesGetHobList (
215 OUT VOID **HobList
216 )
217 {
218 ASSERT (FALSE);
219 return EFI_OUT_OF_RESOURCES;
220 }
221
222 /**
223 This service enables PEIMs to create various types of HOBs.
224
225 @param Type The type of HOB to be installed.
226 @param Length The length of the HOB to be added.
227 @param Hob The address of a pointer that will contain the
228 HOB header.
229
230 @retval EFI_SUCCESS The HOB was successfully created.
231 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
232
233 **/
234 EFI_STATUS
235 EFIAPI
236 PeiServicesCreateHob (
237 IN UINT16 Type,
238 IN UINT16 Length,
239 OUT VOID **Hob
240 )
241 {
242 ASSERT (FALSE);
243 return EFI_OUT_OF_RESOURCES;
244 }
245
246 /**
247 This service enables PEIMs to discover additional firmware volumes.
248
249 @param Instance This instance of the firmware volume to find. The
250 value 0 is the Boot Firmware Volume (BFV).
251 @param VolumeHandle Handle of the firmware volume header of the volume
252 to return.
253
254 @retval EFI_SUCCESS The volume was found.
255 @retval EFI_NOT_FOUND The volume was not found.
256 @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
257
258 **/
259 EFI_STATUS
260 EFIAPI
261 PeiServicesFfsFindNextVolume (
262 IN UINTN Instance,
263 IN OUT EFI_PEI_FV_HANDLE *VolumeHandle
264 )
265 {
266 ASSERT (FALSE);
267 return EFI_OUT_OF_RESOURCES;
268 }
269
270 /**
271 This service enables PEIMs to discover additional firmware files.
272
273 @param SearchType A filter to find files only of this type.
274 @param VolumeHandle The pointer to the firmware volume header of the
275 volume to search. This parameter must point to a
276 valid FFS volume.
277 @param FileHandle Handle of the current file from which to begin searching.
278
279 @retval EFI_SUCCESS The file was found.
280 @retval EFI_NOT_FOUND The file was not found.
281 @retval EFI_NOT_FOUND The header checksum was not zero.
282
283 **/
284 EFI_STATUS
285 EFIAPI
286 PeiServicesFfsFindNextFile (
287 IN EFI_FV_FILETYPE SearchType,
288 IN EFI_PEI_FV_HANDLE VolumeHandle,
289 IN OUT EFI_PEI_FILE_HANDLE *FileHandle
290 )
291 {
292 return SecFfsFindNextFile (SearchType, VolumeHandle, FileHandle);
293 }
294
295 /**
296 This service enables PEIMs to discover sections of a given type within a valid FFS file.
297
298 @param SectionType The value of the section type to find.
299 @param FileHandle A pointer to the file header that contains the set
300 of sections to be searched.
301 @param SectionData A pointer to the discovered section, if successful.
302
303 @retval EFI_SUCCESS The section was found.
304 @retval EFI_NOT_FOUND The section was not found.
305
306 **/
307 EFI_STATUS
308 EFIAPI
309 PeiServicesFfsFindSectionData (
310 IN EFI_SECTION_TYPE SectionType,
311 IN EFI_PEI_FILE_HANDLE FileHandle,
312 OUT VOID **SectionData
313 )
314 {
315 return SecFfsFindSectionData (SectionType, FileHandle, SectionData);
316 }
317
318 /**
319 This service enables PEIMs to register the permanent memory configuration
320 that has been initialized with the PEI Foundation.
321
322 @param MemoryBegin The value of a region of installed memory.
323 @param MemoryLength The corresponding length of a region of installed memory.
324
325 @retval EFI_SUCCESS The region was successfully installed in a HOB.
326 @retval EFI_INVALID_PARAMETER MemoryBegin and MemoryLength are illegal for this system.
327 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
328
329 **/
330 EFI_STATUS
331 EFIAPI
332 PeiServicesInstallPeiMemory (
333 IN EFI_PHYSICAL_ADDRESS MemoryBegin,
334 IN UINT64 MemoryLength
335 )
336 {
337 ASSERT (FALSE);
338 return EFI_OUT_OF_RESOURCES;
339 }
340
341 /**
342 This service enables PEIMs to allocate memory after the permanent memory has been
343 installed by a PEIM.
344
345 @param MemoryType Type of memory to allocate.
346 @param Pages The number of pages to allocate.
347 @param Memory Pointer of memory allocated.
348
349 @retval EFI_SUCCESS The memory range was successfully allocated.
350 @retval EFI_INVALID_PARAMETER Type is not equal to AllocateAnyPages.
351 @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available.
352 @retval EFI_OUT_OF_RESOURCES The pages could not be allocated.
353
354 **/
355 EFI_STATUS
356 EFIAPI
357 PeiServicesAllocatePages (
358 IN EFI_MEMORY_TYPE MemoryType,
359 IN UINTN Pages,
360 OUT EFI_PHYSICAL_ADDRESS *Memory
361 )
362 {
363 ASSERT (FALSE);
364 return EFI_OUT_OF_RESOURCES;
365 }
366
367 /**
368 This service allocates memory from the Hand-Off Block (HOB) heap.
369
370 @param Size The number of bytes to allocate from the pool.
371 @param Buffer If the call succeeds, a pointer to a pointer to
372 the allocate buffer; otherwise, undefined.
373
374 @retval EFI_SUCCESS The allocation was successful
375 @retval EFI_OUT_OF_RESOURCES There is not enough heap to allocate the requested size.
376
377 **/
378 EFI_STATUS
379 EFIAPI
380 PeiServicesAllocatePool (
381 IN UINTN Size,
382 OUT VOID **Buffer
383 )
384 {
385 ASSERT (FALSE);
386 return EFI_OUT_OF_RESOURCES;
387 }
388
389 /**
390 Resets the entire platform.
391
392 @retval EFI_SUCCESS The function completed successfully.
393 @retval EFI_NOT_AVAILABLE_YET The service has not been installed yet.
394
395 **/
396 EFI_STATUS
397 EFIAPI
398 PeiServicesResetSystem (
399 VOID
400 )
401 {
402 ASSERT (FALSE);
403 return EFI_OUT_OF_RESOURCES;
404 }
405
406 /**
407 This service is a wrapper for the PEI Service RegisterForShadow(), except the
408 pointer to the PEI Services Table has been removed. See the Platform
409 Initialization Pre-EFI Initialization Core Interface Specification for details.
410
411 @param FileHandle PEIM's file handle. Must be the currently
412 executing PEIM.
413
414 @retval EFI_SUCCESS The PEIM was successfully registered for
415 shadowing.
416
417 @retval EFI_ALREADY_STARTED The PEIM was previously
418 registered for shadowing.
419
420 @retval EFI_NOT_FOUND The FileHandle does not refer to a
421 valid file handle.
422 **/
423 EFI_STATUS
424 EFIAPI
425 PeiServicesRegisterForShadow (
426 IN EFI_PEI_FILE_HANDLE FileHandle
427 )
428 {
429 ASSERT (FALSE);
430 return EFI_OUT_OF_RESOURCES;
431 }
432
433 /**
434 This service is a wrapper for the PEI Service FfsGetFileInfo(), except the pointer to the PEI Services
435 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
436 Specification for details.
437
438 @param FileHandle The handle of the file.
439
440 @param FileInfo Upon exit, points to the file's
441 information.
442
443 @retval EFI_SUCCESS File information returned.
444
445 @retval EFI_INVALID_PARAMETER If FileHandle does not
446 represent a valid file.
447
448 @retval EFI_INVALID_PARAMETER FileInfo is NULL.
449
450 **/
451 EFI_STATUS
452 EFIAPI
453 PeiServicesFfsGetFileInfo (
454 IN CONST EFI_PEI_FILE_HANDLE FileHandle,
455 OUT EFI_FV_FILE_INFO *FileInfo
456 )
457 {
458 ASSERT (FALSE);
459 return EFI_OUT_OF_RESOURCES;
460 }
461
462
463 /**
464 This service is a wrapper for the PEI Service FfsFindByName(), except the pointer to the PEI Services
465 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
466 Specification for details.
467
468 @param FileName A pointer to the name of the file to
469 find within the firmware volume.
470
471 @param VolumeHandle The firmware volume to search FileHandle
472 Upon exit, points to the found file's
473 handle or NULL if it could not be found.
474 @param FileHandle The pointer to found file handle
475
476 @retval EFI_SUCCESS File was found.
477
478 @retval EFI_NOT_FOUND File was not found.
479
480 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or
481 FileName was NULL.
482
483 **/
484 EFI_STATUS
485 EFIAPI
486 PeiServicesFfsFindFileByName (
487 IN CONST EFI_GUID *FileName,
488 IN CONST EFI_PEI_FV_HANDLE VolumeHandle,
489 OUT EFI_PEI_FILE_HANDLE *FileHandle
490 )
491 {
492 ASSERT (FALSE);
493 return EFI_OUT_OF_RESOURCES;
494 }
495
496
497 /**
498 This service is a wrapper for the PEI Service FfsGetVolumeInfo(), except the pointer to the PEI Services
499 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
500 Specification for details.
501
502 @param VolumeHandle Handle of the volume.
503
504 @param VolumeInfo Upon exit, points to the volume's
505 information.
506
507 @retval EFI_SUCCESS File information returned.
508
509 @retval EFI_INVALID_PARAMETER If FileHandle does not
510 represent a valid file.
511
512 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
513
514 **/
515 EFI_STATUS
516 EFIAPI
517 PeiServicesFfsGetVolumeInfo (
518 IN EFI_PEI_FV_HANDLE VolumeHandle,
519 OUT EFI_FV_INFO *VolumeInfo
520 )
521 {
522 ASSERT (FALSE);
523 return EFI_OUT_OF_RESOURCES;
524 }
525
526 /**
527 Install a EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance so the PEI Core will be notified about a new firmware volume.
528
529 This function allocates, initializes, and installs a new EFI_PEI_FIRMWARE_VOLUME_INFO_PPI using
530 the parameters passed in to initialize the fields of the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance.
531 If the resources can not be allocated for EFI_PEI_FIRMWARE_VOLUME_INFO_PPI, then ASSERT().
532 If the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI can not be installed, then ASSERT().
533
534
535 @param FvFormat Unique identifier of the format of the memory-mapped
536 firmware volume. This parameter is optional and
537 may be NULL. If NULL is specified, the
538 EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed.
539 @param FvInfo Points to a buffer which allows the
540 EFI_PEI_FIRMWARE_VOLUME_PPI to process the volume.
541 The format of this buffer is specific to the FvFormat.
542 For memory-mapped firmware volumes, this typically
543 points to the first byte of the firmware volume.
544 @param FvInfoSize The size, in bytes, of FvInfo. For memory-mapped
545 firmware volumes, this is typically the size of
546 the firmware volume.
547 @param ParentFvName If the new firmware volume originated from a file
548 in a different firmware volume, then this parameter
549 specifies the GUID name of the originating firmware
550 volume. Otherwise, this parameter must be NULL.
551 @param ParentFileName If the new firmware volume originated from a file
552 in a different firmware volume, then this parameter
553 specifies the GUID file name of the originating
554 firmware file. Otherwise, this parameter must be NULL.
555 **/
556 VOID
557 EFIAPI
558 PeiServicesInstallFvInfoPpi (
559 IN CONST EFI_GUID *FvFormat, OPTIONAL
560 IN CONST VOID *FvInfo,
561 IN UINT32 FvInfoSize,
562 IN CONST EFI_GUID *ParentFvName, OPTIONAL
563 IN CONST EFI_GUID *ParentFileName OPTIONAL
564 )
565 {
566 ASSERT (FALSE);
567 return;
568 }
569