]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiServicesLib/PeiServicesLib.c
Fix up the comment for several functions and make sure the IN and OUT modifier of...
[mirror_edk2.git] / MdePkg / Library / PeiServicesLib / PeiServicesLib.c
1 /** @file
2 Implementation for PEI Services Library.
3
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>
5 All rights reserved. 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
19 #include <Library/PeiServicesLib.h>
20 #include <Library/PeiServicesTablePointerLib.h>
21
22 /**
23 This service enables a given PEIM to register an interface into the PEI Foundation.
24
25 @param PpiList A pointer to the list of interfaces that the caller shall install.
26
27 @retval EFI_SUCCESS The interface was successfully installed.
28 @retval EFI_INVALID_PARAMETER The PpiList pointer is NULL.
29 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
30 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
31 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
32
33 **/
34 EFI_STATUS
35 EFIAPI
36 PeiServicesInstallPpi (
37 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList
38 )
39 {
40 CONST EFI_PEI_SERVICES **PeiServices;
41
42 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
43 return (*PeiServices)->InstallPpi (PeiServices, PpiList);
44 }
45
46 /**
47 This service enables PEIMs to replace an entry in the PPI database with an alternate entry.
48
49 @param OldPpi Pointer to the old PEI PPI Descriptors.
50 @param NewPpi Pointer to the new PEI PPI Descriptors.
51
52 @retval EFI_SUCCESS The interface was successfully installed.
53 @retval EFI_INVALID_PARAMETER The OldPpi or NewPpi is NULL.
54 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
55 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
56 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
57 @retval EFI_NOT_FOUND The PPI for which the reinstallation was requested has not been
58 installed.
59
60 **/
61 EFI_STATUS
62 EFIAPI
63 PeiServicesReInstallPpi (
64 IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi,
65 IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi
66 )
67 {
68 CONST EFI_PEI_SERVICES **PeiServices;
69
70 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
71 return (*PeiServices)->ReInstallPpi (PeiServices, OldPpi, NewPpi);
72 }
73
74 /**
75 This service enables PEIMs to discover a given instance of an interface.
76
77 @param Guid A pointer to the GUID whose corresponding interface needs to be
78 found.
79 @param Instance The N-th instance of the interface that is required.
80 @param PpiDescriptor A pointer to instance of the EFI_PEI_PPI_DESCRIPTOR.
81 @param Ppi A pointer to the instance of the interface.
82
83 @retval EFI_SUCCESS The interface was successfully returned.
84 @retval EFI_NOT_FOUND The PPI descriptor is not found in the database.
85
86 **/
87 EFI_STATUS
88 EFIAPI
89 PeiServicesLocatePpi (
90 IN CONST EFI_GUID *Guid,
91 IN UINTN Instance,
92 IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
93 IN OUT VOID **Ppi
94 )
95 {
96 CONST EFI_PEI_SERVICES **PeiServices;
97
98 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
99 return (*PeiServices)->LocatePpi (PeiServices, Guid, Instance, PpiDescriptor, Ppi);
100 }
101
102 /**
103 This service enables PEIMs to register a given service to be invoked when another service is
104 installed or reinstalled.
105
106 @param NotifyList A pointer to the list of notification interfaces that the caller
107 shall install.
108
109 @retval EFI_SUCCESS The interface was successfully installed.
110 @retval EFI_INVALID_PARAMETER The NotifyList pointer is NULL.
111 @retval EFI_INVALID_PARAMETER Any of the PEI notify descriptors in the list do not have the
112 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES bit set in the Flags field.
113 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
114
115 **/
116 EFI_STATUS
117 EFIAPI
118 PeiServicesNotifyPpi (
119 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList
120 )
121 {
122 CONST EFI_PEI_SERVICES **PeiServices;
123
124 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
125 return (*PeiServices)->NotifyPpi (PeiServices, NotifyList);
126 }
127
128 /**
129 This service enables PEIMs to ascertain the present value of the boot mode.
130
131 @param BootMode A pointer to contain the value of the boot mode.
132
133 @retval EFI_SUCCESS The boot mode was returned successfully.
134 @retval EFI_INVALID_PARAMETER BootMode is NULL.
135
136 **/
137 EFI_STATUS
138 EFIAPI
139 PeiServicesGetBootMode (
140 IN OUT EFI_BOOT_MODE *BootMode
141 )
142 {
143 CONST EFI_PEI_SERVICES **PeiServices;
144
145 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
146 return (*PeiServices)->GetBootMode (PeiServices, BootMode);
147 }
148
149 /**
150 This service enables PEIMs to update the boot mode variable.
151
152 @param BootMode The value of the boot mode to set.
153
154 @retval EFI_SUCCESS The value was successfully updated
155
156 **/
157 EFI_STATUS
158 EFIAPI
159 PeiServicesSetBootMode (
160 IN EFI_BOOT_MODE BootMode
161 )
162 {
163 CONST EFI_PEI_SERVICES **PeiServices;
164
165 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
166 return (*PeiServices)->SetBootMode (PeiServices, BootMode);
167 }
168
169 /**
170 This service enables a PEIM to ascertain the address of the list of HOBs in memory.
171
172 @param HobList A pointer to the list of HOBs that the PEI Foundation will initialize.
173
174 @retval EFI_SUCCESS The list was successfully returned.
175 @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
176
177 **/
178 EFI_STATUS
179 EFIAPI
180 PeiServicesGetHobList (
181 IN OUT VOID **HobList
182 )
183 {
184 CONST EFI_PEI_SERVICES **PeiServices;
185
186 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
187 return (*PeiServices)->GetHobList (PeiServices, HobList);
188 }
189
190 /**
191 This service enables PEIMs to create various types of HOBs.
192
193 @param Type The type of HOB to be installed.
194 @param Length The length of the HOB to be added.
195 @param Hob The address of a pointer that will contain the HOB header.
196
197 @retval EFI_SUCCESS The HOB was successfully created.
198 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
199
200 **/
201 EFI_STATUS
202 EFIAPI
203 PeiServicesCreateHob (
204 IN UINT16 Type,
205 IN UINT16 Length,
206 IN OUT VOID **Hob
207 )
208 {
209 CONST EFI_PEI_SERVICES **PeiServices;
210
211 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
212 return (*PeiServices)->CreateHob (PeiServices, Type, Length, Hob);
213 }
214
215 /**
216 This service enables PEIMs to discover additional firmware volumes.
217
218 @param Instance This instance of the firmware volume to find. The value 0 is the
219 Boot Firmware Volume (BFV).
220 @param FwVolHeader Pointer to the firmware volume header of the volume to return.
221
222 @retval EFI_SUCCESS The volume was found.
223 @retval EFI_NOT_FOUND The volume was not found.
224 @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
225
226 **/
227 EFI_STATUS
228 EFIAPI
229 PeiServicesFfsFindNextVolume (
230 IN UINTN Instance,
231 IN OUT EFI_PEI_FV_HANDLE *VolumeHandle
232 )
233 {
234 CONST EFI_PEI_SERVICES **PeiServices;
235
236 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
237 return (*PeiServices)->FfsFindNextVolume (PeiServices, Instance, VolumeHandle);
238 }
239
240 /**
241 This service enables PEIMs to discover additional firmware files.
242
243 @param SearchType A filter to find files only of this type.
244 @param FwVolHeader Pointer to the firmware volume header of the volume to search.
245 This parameter must point to a valid FFS volume.
246 @param FileHeader Pointer to the current file from which to begin searching.
247
248 @retval EFI_SUCCESS The file was found.
249 @retval EFI_NOT_FOUND The file was not found.
250 @retval EFI_NOT_FOUND The header checksum was not zero.
251
252 **/
253 EFI_STATUS
254 EFIAPI
255 PeiServicesFfsFindNextFile (
256 IN EFI_FV_FILETYPE SearchType,
257 IN EFI_PEI_FV_HANDLE VolumeHandle,
258 IN OUT EFI_PEI_FILE_HANDLE *FileHandle
259 )
260 {
261 CONST EFI_PEI_SERVICES **PeiServices;
262
263 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
264 return (*PeiServices)->FfsFindNextFile (PeiServices, SearchType, VolumeHandle, FileHandle);
265 }
266
267 /**
268 This service enables PEIMs to discover sections of a given type within a valid FFS file.
269
270 @param SearchType The value of the section type to find.
271 @param FfsFileHeader A pointer to the file header that contains the set of sections to
272 be searched.
273 @param SectionData A pointer to the discovered section, if successful.
274
275 @retval EFI_SUCCESS The section was found.
276 @retval EFI_NOT_FOUND The section was not found.
277
278 **/
279 EFI_STATUS
280 EFIAPI
281 PeiServicesFfsFindSectionData (
282 IN EFI_SECTION_TYPE SectionType,
283 IN EFI_PEI_FILE_HANDLE FfsFileHeader,
284 OUT VOID **SectionData
285 )
286 {
287 CONST EFI_PEI_SERVICES **PeiServices;
288
289 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
290 return (*PeiServices)->FfsFindSectionData (PeiServices, SectionType, FfsFileHeader, SectionData);
291 }
292
293 /**
294 This service enables PEIMs to register the permanent memory configuration
295 that has been initialized with the PEI Foundation.
296
297 @param MemoryBegin The value of a region of installed memory.
298 @param MemoryLength The corresponding length of a region of installed memory.
299
300 @retval EFI_SUCCESS The region was successfully installed in a HOB.
301 @retval EFI_INVALID_PARAMETER MemoryBegin and MemoryLength are illegal for this system.
302 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
303
304 **/
305 EFI_STATUS
306 EFIAPI
307 PeiServicesInstallPeiMemory (
308 IN EFI_PHYSICAL_ADDRESS MemoryBegin,
309 IN UINT64 MemoryLength
310 )
311 {
312 CONST EFI_PEI_SERVICES **PeiServices;
313
314 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
315 return (*PeiServices)->InstallPeiMemory (PeiServices, MemoryBegin, MemoryLength);
316 }
317
318 /**
319 This service enables PEIMs to allocate memory after the permanent memory has been installed by a
320 PEIM.
321
322 @param MemoryType Type of memory to allocate.
323 @param Pages Number of pages to allocate.
324 @param Memory Pointer of memory allocated.
325
326 @retval EFI_SUCCESS The memory range was successfully allocated.
327 @retval EFI_INVALID_PARAMETER Type is not equal to AllocateAnyPages.
328 @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available.
329 @retval EFI_OUT_OF_RESOURCES The pages could not be allocated.
330
331 **/
332 EFI_STATUS
333 EFIAPI
334 PeiServicesAllocatePages (
335 IN EFI_MEMORY_TYPE MemoryType,
336 IN UINTN Pages,
337 OUT EFI_PHYSICAL_ADDRESS *Memory
338 )
339 {
340 CONST EFI_PEI_SERVICES **PeiServices;
341
342 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
343 return (*PeiServices)->AllocatePages (PeiServices, MemoryType, Pages, Memory);
344 }
345
346 /**
347 This service allocates memory from the Hand-Off Block (HOB) heap.
348
349 @param Size The number of bytes to allocate from the pool.
350 @param Buffer If the call succeeds, a pointer to a pointer to the allocate
351 buffer; undefined otherwise.
352
353 @retval EFI_SUCCESS The allocation was successful
354 @retval EFI_OUT_OF_RESOURCES There is not enough heap to allocate the requested size.
355
356 **/
357 EFI_STATUS
358 EFIAPI
359 PeiServicesAllocatePool (
360 IN UINTN Size,
361 OUT VOID **Buffer
362 )
363 {
364 CONST EFI_PEI_SERVICES **PeiServices;
365
366 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
367 return (*PeiServices)->AllocatePool (PeiServices, Size, Buffer);
368 }
369
370 /**
371 Resets the entire platform.
372
373 @param VOID
374
375 @retval EFI_SUCCESS The function completed successfully.
376 @retval EFI_NOT_AVAILABLE_YET The service has not been installed yet.
377
378 **/
379 EFI_STATUS
380 EFIAPI
381 PeiServicesResetSystem (
382 VOID
383 )
384 {
385 CONST EFI_PEI_SERVICES **PeiServices;
386
387 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
388 return (*PeiServices)->ResetSystem (PeiServices);
389 }
390
391 /**
392 This service is a wrapper for the PEI Service RegisterForShadow(), except the pointer to the PEI Services
393 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
394 Specification for details.
395
396 @param FileHandle PEIM's file handle. Must be the currently
397 executing PEIM.
398
399 @retval EFI_SUCCESS The PEIM was successfully registered for
400 shadowing.
401
402 @retval EFI_ALREADY_STARTED The PEIM was previously
403 registered for shadowing.
404
405 @retval EFI_NOT_FOUND The FileHandle does not refer to a
406 valid file handle.
407 **/
408 EFI_STATUS
409 EFIAPI
410 PeiServicesRegisterForShadow (
411 IN EFI_PEI_FILE_HANDLE FileHandle
412 )
413 {
414 EFI_PEI_SERVICES **PeiServices;
415
416 PeiServices = GetPeiServicesTablePointer ();
417 return (*PeiServices)->RegisterForShadow (FileHandle);
418 }
419
420 /**
421 This service is a wrapper for the PEI Service FfsGetFileInfo(), except the pointer to the PEI Services
422 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
423 Specification for details.
424
425 @param FileHandle Handle of the file.
426
427 @param FileInfo Upon exit, points to the file's
428 information.
429
430 @retval EFI_SUCCESS File information returned.
431
432 @retval EFI_INVALID_PARAMETER If FileHandle does not
433 represent a valid file.
434
435 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
436
437 **/
438 EFI_STATUS
439 EFIAPI
440 PeiServicesFfsGetFileInfo (
441 IN CONST EFI_PEI_FILE_HANDLE FileHandle,
442 OUT EFI_FV_FILE_INFO *FileInfo
443 )
444 {
445 EFI_PEI_SERVICES **PeiServices;
446
447 PeiServices = GetPeiServicesTablePointer ();
448 return (*PeiServices)->FfsGetFileInfo (FileHandle, FileInfo);
449 }
450
451
452 /**
453 This service is a wrapper for the PEI Service FfsFindByName(), except the pointer to the PEI Services
454 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
455 Specification for details.
456
457 @param FileName A pointer to the name of the file to
458 find within the firmware volume.
459
460 @param VolumeHandle The firmware volume to search FileHandle
461 Upon exit, points to the found file's
462 handle or NULL if it could not be found.
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 return (*GetPeiServicesTablePointer())->FfsFindFileByName (FileName, VolumeHandle, FileHandle);
481 }
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 return (*GetPeiServicesTablePointer())->FfsGetVolumeInfo (VolumeHandle, VolumeInfo);
510 }
511