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