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