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