]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiServicesLib/PeiServicesLib.c
Merge branch of PI tree to main trunk
[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 IN 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 IN 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 This service resets the entire platform, including all processors and devices, and reboots the
372 system.
373
374 @retval EFI_NOT_AVAILABLE_YET The service has not been installed yet.
375
376 **/
377 EFI_STATUS
378 EFIAPI
379 PeiServicesResetSystem (
380 VOID
381 )
382 {
383 CONST EFI_PEI_SERVICES **PeiServices;
384
385 PeiServices = (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
386 return (*PeiServices)->ResetSystem (PeiServices);
387 }
388
389 EFI_STATUS
390 EFIAPI
391 PeiServicesRegisterForShadow (
392 IN EFI_PEI_FILE_HANDLE FileHandle
393 )
394 {
395 EFI_PEI_SERVICES **PeiServices;
396
397 PeiServices = GetPeiServicesTablePointer ();
398 return (*PeiServices)->RegisterForShadow (FileHandle);
399 }
400
401 EFI_STATUS
402 EFIAPI
403 PeiServicesFfsGetFileInfo (
404 IN CONST EFI_PEI_FILE_HANDLE FileHandle,
405 OUT EFI_FV_FILE_INFO *FileInfo
406 )
407 {
408 EFI_PEI_SERVICES **PeiServices;
409
410 PeiServices = GetPeiServicesTablePointer ();
411 return (*PeiServices)->FfsGetFileInfo (FileHandle, FileInfo);
412 }
413
414
415 EFI_STATUS
416 EFIAPI
417 PeiServicesFfsFindFileByName (
418 IN CONST EFI_GUID *FileName,
419 IN CONST EFI_PEI_FV_HANDLE VolumeHandle,
420 OUT EFI_PEI_FILE_HANDLE *FileHandle
421 )
422 {
423 return (*GetPeiServicesTablePointer())->FfsFindFileByName (FileName, VolumeHandle, FileHandle);
424 }
425
426
427 EFI_STATUS
428 EFIAPI
429 PeiServicesFfsGetVolumeInfo (
430 IN EFI_PEI_FV_HANDLE VolumeHandle,
431 OUT EFI_FV_INFO *VolumeInfo
432 )
433 {
434 return (*GetPeiServicesTablePointer())->FfsGetVolumeInfo (VolumeHandle, VolumeInfo);
435 }
436