]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiServicesLib/PeiServicesLib.c
Update the comments of Acpi.h.
[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 // The package level header files this module uses
17 //
18 #include <PiPei.h>
19 //
20 // The protocols, PPI and GUID defintions for this module
21 //
22 //
23 // The Library classes this module consumes
24 //
25 #include <Library/PeiServicesLib.h>
26 #include <Library/PeiServicesTablePointerLib.h>
27
28 /**
29 This service enables a given PEIM to register an interface into the PEI Foundation.
30
31 @param PpiList A pointer to the list of interfaces that the caller shall install.
32
33 @retval EFI_SUCCESS The interface was successfully installed.
34 @retval EFI_INVALID_PARAMETER The PpiList pointer is NULL.
35 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
36 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
37 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
38
39 **/
40 EFI_STATUS
41 EFIAPI
42 PeiServicesInstallPpi (
43 IN EFI_PEI_PPI_DESCRIPTOR *PpiList
44 )
45 {
46 EFI_PEI_SERVICES **PeiServices;
47
48 PeiServices = GetPeiServicesTablePointer ();
49 return (*PeiServices)->InstallPpi (PeiServices, PpiList);
50 }
51
52 /**
53 This service enables PEIMs to replace an entry in the PPI database with an alternate entry.
54
55 @param OldPpi Pointer to the old PEI PPI Descriptors.
56 @param NewPpi Pointer to the new PEI PPI Descriptors.
57
58 @retval EFI_SUCCESS The interface was successfully installed.
59 @retval EFI_INVALID_PARAMETER The OldPpi or NewPpi is NULL.
60 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
61 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
62 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
63 @retval EFI_NOT_FOUND The PPI for which the reinstallation was requested has not been
64 installed.
65
66 **/
67 EFI_STATUS
68 EFIAPI
69 PeiServicesReInstallPpi (
70 IN EFI_PEI_PPI_DESCRIPTOR *OldPpi,
71 IN EFI_PEI_PPI_DESCRIPTOR *NewPpi
72 )
73 {
74 EFI_PEI_SERVICES **PeiServices;
75
76 PeiServices = GetPeiServicesTablePointer ();
77 return (*PeiServices)->ReInstallPpi (PeiServices, OldPpi, NewPpi);
78 }
79
80 /**
81 This service enables PEIMs to discover a given instance of an interface.
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 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_SERVICES **PeiServices;
103
104 PeiServices = GetPeiServicesTablePointer ();
105 return (*PeiServices)->LocatePpi (PeiServices, Guid, Instance, PpiDescriptor, Ppi);
106 }
107
108 /**
109 This service enables PEIMs to register a given service to be invoked when another service is
110 installed or reinstalled.
111
112 @param NotifyList A pointer to the list of notification interfaces that the caller
113 shall install.
114
115 @retval EFI_SUCCESS The interface was successfully installed.
116 @retval EFI_INVALID_PARAMETER The NotifyList pointer is NULL.
117 @retval EFI_INVALID_PARAMETER Any of the PEI notify descriptors in the list do not have the
118 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES bit set in the Flags field.
119 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
120
121 **/
122 EFI_STATUS
123 EFIAPI
124 PeiServicesNotifyPpi (
125 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList
126 )
127 {
128 EFI_PEI_SERVICES **PeiServices;
129
130 PeiServices = GetPeiServicesTablePointer ();
131 return (*PeiServices)->NotifyPpi (PeiServices, NotifyList);
132 }
133
134 /**
135 This service enables PEIMs to ascertain the present value of the boot mode.
136
137 @param BootMode A pointer to contain the value of the boot mode.
138
139 @retval EFI_SUCCESS The boot mode was returned successfully.
140 @retval EFI_INVALID_PARAMETER BootMode is NULL.
141
142 **/
143 EFI_STATUS
144 EFIAPI
145 PeiServicesGetBootMode (
146 IN OUT EFI_BOOT_MODE *BootMode
147 )
148 {
149 EFI_PEI_SERVICES **PeiServices;
150
151 PeiServices = GetPeiServicesTablePointer ();
152 return (*PeiServices)->GetBootMode (PeiServices, BootMode);
153 }
154
155 /**
156 This service enables PEIMs to update the boot mode variable.
157
158 @param BootMode The value of the boot mode to set.
159
160 @retval EFI_SUCCESS The value was successfully updated
161
162 **/
163 EFI_STATUS
164 EFIAPI
165 PeiServicesSetBootMode (
166 IN EFI_BOOT_MODE BootMode
167 )
168 {
169 EFI_PEI_SERVICES **PeiServices;
170
171 PeiServices = GetPeiServicesTablePointer ();
172 return (*PeiServices)->SetBootMode (PeiServices, BootMode);
173 }
174
175 /**
176 This service enables a PEIM to ascertain the address of the list of HOBs in memory.
177
178 @param HobList A pointer to the list of HOBs that the PEI Foundation will initialize.
179
180 @retval EFI_SUCCESS The list was successfully returned.
181 @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
182
183 **/
184 EFI_STATUS
185 EFIAPI
186 PeiServicesGetHobList (
187 IN OUT VOID **HobList
188 )
189 {
190 EFI_PEI_SERVICES **PeiServices;
191
192 PeiServices = GetPeiServicesTablePointer ();
193 return (*PeiServices)->GetHobList (PeiServices, HobList);
194 }
195
196 /**
197 This service enables PEIMs to create various types of HOBs.
198
199 @param Type The type of HOB to be installed.
200 @param Length The length of the HOB to be added.
201 @param Hob The address of a pointer that will contain the HOB header.
202
203 @retval EFI_SUCCESS The HOB was successfully created.
204 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
205
206 **/
207 EFI_STATUS
208 EFIAPI
209 PeiServicesCreateHob (
210 IN UINT16 Type,
211 IN UINT16 Length,
212 IN OUT VOID **Hob
213 )
214 {
215 EFI_PEI_SERVICES **PeiServices;
216
217 PeiServices = GetPeiServicesTablePointer ();
218 return (*PeiServices)->CreateHob (PeiServices, Type, Length, Hob);
219 }
220
221 /**
222 This service enables PEIMs to discover additional firmware volumes.
223
224 @param Instance This instance of the firmware volume to find. The value 0 is the
225 Boot Firmware Volume (BFV).
226 @param FwVolHeader Pointer to the firmware volume header of the volume to return.
227
228 @retval EFI_SUCCESS The volume was found.
229 @retval EFI_NOT_FOUND The volume was not found.
230 @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
231
232 **/
233 EFI_STATUS
234 EFIAPI
235 PeiServicesFfsFindNextVolume (
236 IN UINTN Instance,
237 IN OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader
238 )
239 {
240 EFI_PEI_SERVICES **PeiServices;
241
242 PeiServices = GetPeiServicesTablePointer ();
243 return (*PeiServices)->FfsFindNextVolume (PeiServices, Instance, FwVolHeader);
244 }
245
246 /**
247 This service enables PEIMs to discover additional firmware files.
248
249 @param SearchType A filter to find files only of this type.
250 @param FwVolHeader Pointer to the firmware volume header of the volume to search.
251 This parameter must point to a valid FFS volume.
252 @param FileHeader Pointer to the current file from which to begin searching.
253
254 @retval EFI_SUCCESS The file was found.
255 @retval EFI_NOT_FOUND The file was not found.
256 @retval EFI_NOT_FOUND The header checksum was not zero.
257
258 **/
259 EFI_STATUS
260 EFIAPI
261 PeiServicesFfsFindNextFile (
262 IN EFI_FV_FILETYPE SearchType,
263 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
264 IN OUT EFI_FFS_FILE_HEADER **FileHeader
265 )
266 {
267 EFI_PEI_SERVICES **PeiServices;
268
269 PeiServices = GetPeiServicesTablePointer ();
270 return (*PeiServices)->FfsFindNextFile (PeiServices, SearchType, FwVolHeader, FileHeader);
271 }
272
273 /**
274 This service enables PEIMs to discover sections of a given type within a valid FFS file.
275
276 @param SearchType The value of the section type to find.
277 @param FfsFileHeader A pointer to the file header that contains the set of sections to
278 be searched.
279 @param SectionData A pointer to the discovered section, if successful.
280
281 @retval EFI_SUCCESS The section was found.
282 @retval EFI_NOT_FOUND The section was not found.
283
284 **/
285 EFI_STATUS
286 EFIAPI
287 PeiServicesFfsFindSectionData (
288 IN EFI_SECTION_TYPE SectionType,
289 IN EFI_FFS_FILE_HEADER *FfsFileHeader,
290 IN OUT VOID **SectionData
291 )
292 {
293 EFI_PEI_SERVICES **PeiServices;
294
295 PeiServices = GetPeiServicesTablePointer ();
296 return (*PeiServices)->FfsFindSectionData (PeiServices, SectionType, FfsFileHeader, SectionData);
297 }
298
299 /**
300 This service enables PEIMs to register the permanent memory configuration
301 that has been initialized with the PEI Foundation.
302
303 @param MemoryBegin The value of a region of installed memory.
304 @param MemoryLength The corresponding length of a region of installed memory.
305
306 @retval EFI_SUCCESS The region was successfully installed in a HOB.
307 @retval EFI_INVALID_PARAMETER MemoryBegin and MemoryLength are illegal for this system.
308 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
309
310 **/
311 EFI_STATUS
312 EFIAPI
313 PeiServicesInstallPeiMemory (
314 IN EFI_PHYSICAL_ADDRESS MemoryBegin,
315 IN UINT64 MemoryLength
316 )
317 {
318 EFI_PEI_SERVICES **PeiServices;
319
320 PeiServices = GetPeiServicesTablePointer ();
321 return (*PeiServices)->InstallPeiMemory (PeiServices, MemoryBegin, MemoryLength);
322 }
323
324 /**
325 This service enables PEIMs to allocate memory after the permanent memory has been installed by a
326 PEIM.
327
328 @param MemoryType Type of memory to allocate.
329 @param Pages Number of pages to allocate.
330 @param Memory Pointer of memory allocated.
331
332 @retval EFI_SUCCESS The memory range was successfully allocated.
333 @retval EFI_INVALID_PARAMETER Type is not equal to AllocateAnyPages.
334 @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available.
335 @retval EFI_OUT_OF_RESOURCES The pages could not be allocated.
336
337 **/
338 EFI_STATUS
339 EFIAPI
340 PeiServicesAllocatePages (
341 IN EFI_MEMORY_TYPE MemoryType,
342 IN UINTN Pages,
343 IN OUT EFI_PHYSICAL_ADDRESS *Memory
344 )
345 {
346 EFI_PEI_SERVICES **PeiServices;
347
348 PeiServices = GetPeiServicesTablePointer ();
349 return (*PeiServices)->AllocatePages (PeiServices, MemoryType, Pages, Memory);
350 }
351
352 /**
353 This service allocates memory from the Hand-Off Block (HOB) heap.
354
355 @param Size The number of bytes to allocate from the pool.
356 @param Buffer If the call succeeds, a pointer to a pointer to the allocate
357 buffer; undefined otherwise.
358
359 @retval EFI_SUCCESS The allocation was successful
360 @retval EFI_OUT_OF_RESOURCES There is not enough heap to allocate the requested size.
361
362 **/
363 EFI_STATUS
364 EFIAPI
365 PeiServicesAllocatePool (
366 IN UINTN Size,
367 OUT VOID **Buffer
368 )
369 {
370 EFI_PEI_SERVICES **PeiServices;
371
372 PeiServices = GetPeiServicesTablePointer ();
373 return (*PeiServices)->AllocatePool (PeiServices, Size, Buffer);
374 }
375
376 /**
377 This service resets the entire platform, including all processors and devices, and reboots the
378 system.
379
380 @retval EFI_NOT_AVAILABLE_YET The service has not been installed yet.
381
382 **/
383 EFI_STATUS
384 EFIAPI
385 PeiServicesResetSystem (
386 VOID
387 )
388 {
389 EFI_PEI_SERVICES **PeiServices;
390
391 PeiServices = GetPeiServicesTablePointer ();
392 return (*PeiServices)->ResetSystem (PeiServices);
393 }