]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/PeiServicesLib/PeiServicesLib.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / PeiServicesLib / PeiServicesLib.c
1 /*++
2
3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 Module Name:
14
15 PeiServicesLib.c
16
17 Abstract:
18
19 PEI Services Lib
20
21 --*/
22
23 #include "EdkIIGluePeim.h"
24
25 /**
26 This service enables a given PEIM to register an interface into the PEI Foundation.
27
28 @param PpiList A pointer to the list of interfaces that the caller shall install.
29
30 @retval EFI_SUCCESS The interface was successfully installed.
31 @retval EFI_INVALID_PARAMETER The PpiList pointer is NULL.
32 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
33 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
34 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
35
36 **/
37 EFI_STATUS
38 EFIAPI
39 PeiServicesInstallPpi (
40 IN EFI_PEI_PPI_DESCRIPTOR *PpiList
41 )
42 {
43 EFI_PEI_SERVICES **PeiServices;
44
45 PeiServices = GetPeiServicesTablePointer ();
46 return (*PeiServices)->InstallPpi (PeiServices, PpiList);
47 }
48
49 /**
50 This service enables PEIMs to replace an entry in the PPI database with an alternate entry.
51
52 @param OldPpi Pointer to the old PEI PPI Descriptors.
53 @param NewPpi Pointer to the new PEI PPI Descriptors.
54
55 @retval EFI_SUCCESS The interface was successfully installed.
56 @retval EFI_INVALID_PARAMETER The OldPpi or NewPpi is NULL.
57 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
58 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
59 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
60 @retval EFI_NOT_FOUND The PPI for which the reinstallation was requested has not been
61 installed.
62
63 **/
64 EFI_STATUS
65 EFIAPI
66 PeiServicesReInstallPpi (
67 IN EFI_PEI_PPI_DESCRIPTOR *OldPpi,
68 IN EFI_PEI_PPI_DESCRIPTOR *NewPpi
69 )
70 {
71 EFI_PEI_SERVICES **PeiServices;
72
73 PeiServices = GetPeiServicesTablePointer ();
74 return (*PeiServices)->ReInstallPpi (PeiServices, OldPpi, NewPpi);
75 }
76
77 /**
78 This service enables PEIMs to discover a given instance of an interface.
79
80 @param Guid A pointer to the GUID whose corresponding interface needs to be
81 found.
82 @param Instance The N-th instance of the interface that is required.
83 @param PpiDescriptor A pointer to instance of the EFI_PEI_PPI_DESCRIPTOR.
84 @param Ppi A pointer to the instance of the interface.
85
86 @retval EFI_SUCCESS The interface was successfully returned.
87 @retval EFI_NOT_FOUND The PPI descriptor is not found in the database.
88
89 **/
90 EFI_STATUS
91 EFIAPI
92 PeiServicesLocatePpi (
93 IN EFI_GUID *Guid,
94 IN UINTN Instance,
95 IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
96 IN OUT VOID **Ppi
97 )
98 {
99 EFI_PEI_SERVICES **PeiServices;
100
101 PeiServices = GetPeiServicesTablePointer ();
102 return (*PeiServices)->LocatePpi (PeiServices, Guid, Instance, PpiDescriptor, Ppi);
103 }
104
105 /**
106 This service enables PEIMs to register a given service to be invoked when another service is
107 installed or reinstalled.
108
109 @param NotifyList A pointer to the list of notification interfaces that the caller
110 shall install.
111
112 @retval EFI_SUCCESS The interface was successfully installed.
113 @retval EFI_INVALID_PARAMETER The NotifyList pointer is NULL.
114 @retval EFI_INVALID_PARAMETER Any of the PEI notify descriptors in the list do not have the
115 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES bit set in the Flags field.
116 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
117
118 **/
119 EFI_STATUS
120 EFIAPI
121 PeiServicesNotifyPpi (
122 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList
123 )
124 {
125 EFI_PEI_SERVICES **PeiServices;
126
127 PeiServices = GetPeiServicesTablePointer ();
128 return (*PeiServices)->NotifyPpi (PeiServices, NotifyList);
129 }
130
131 /**
132 This service enables PEIMs to ascertain the present value of the boot mode.
133
134 @param BootMode A pointer to contain the value of the boot mode.
135
136 @retval EFI_SUCCESS The boot mode was returned successfully.
137 @retval EFI_INVALID_PARAMETER BootMode is NULL.
138
139 **/
140 EFI_STATUS
141 EFIAPI
142 PeiServicesGetBootMode (
143 IN OUT EFI_BOOT_MODE *BootMode
144 )
145 {
146 EFI_PEI_SERVICES **PeiServices;
147
148 PeiServices = GetPeiServicesTablePointer ();
149 return (*PeiServices)->GetBootMode (PeiServices, BootMode);
150 }
151
152 /**
153 This service enables PEIMs to update the boot mode variable.
154
155 @param BootMode The value of the boot mode to set.
156
157 @retval EFI_SUCCESS The value was successfully updated
158
159 **/
160 EFI_STATUS
161 EFIAPI
162 PeiServicesSetBootMode (
163 IN EFI_BOOT_MODE BootMode
164 )
165 {
166 EFI_PEI_SERVICES **PeiServices;
167
168 PeiServices = GetPeiServicesTablePointer ();
169 return (*PeiServices)->SetBootMode (PeiServices, BootMode);
170 }
171
172 /**
173 This service enables a PEIM to ascertain the address of the list of HOBs in memory.
174
175 @param HobList A pointer to the list of HOBs that the PEI Foundation will initialize.
176
177 @retval EFI_SUCCESS The list was successfully returned.
178 @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
179
180 **/
181 EFI_STATUS
182 EFIAPI
183 PeiServicesGetHobList (
184 IN OUT VOID **HobList
185 )
186 {
187 EFI_PEI_SERVICES **PeiServices;
188
189 PeiServices = GetPeiServicesTablePointer ();
190 return (*PeiServices)->GetHobList (PeiServices, HobList);
191 }
192
193 /**
194 This service enables PEIMs to create various types of HOBs.
195
196 @param Type The type of HOB to be installed.
197 @param Length The length of the HOB to be added.
198 @param Hob The address of a pointer that will contain the HOB header.
199
200 @retval EFI_SUCCESS The HOB was successfully created.
201 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
202
203 **/
204 EFI_STATUS
205 EFIAPI
206 PeiServicesCreateHob (
207 IN UINT16 Type,
208 IN UINT16 Length,
209 IN OUT VOID **Hob
210 )
211 {
212 EFI_PEI_SERVICES **PeiServices;
213
214 PeiServices = GetPeiServicesTablePointer ();
215 return (*PeiServices)->CreateHob (PeiServices, Type, Length, Hob);
216 }
217
218 #if (PI_SPECIFICATION_VERSION < 0x00010000)
219 /**
220 This service enables PEIMs to discover additional firmware volumes.
221
222 @param Instance This instance of the firmware volume to find. The value 0 is the
223 Boot Firmware Volume (BFV).
224 @param FwVolHeader Pointer to the firmware volume header of the volume to return.
225
226 @retval EFI_SUCCESS The volume was found.
227 @retval EFI_NOT_FOUND The volume was not found.
228 @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
229
230 **/
231 EFI_STATUS
232 EFIAPI
233 PeiServicesFfsFindNextVolume (
234 IN UINTN Instance,
235 IN OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader
236 )
237 {
238 EFI_PEI_SERVICES **PeiServices;
239
240 PeiServices = GetPeiServicesTablePointer ();
241 return (*PeiServices)->FfsFindNextVolume (PeiServices, Instance, FwVolHeader);
242 }
243
244 /**
245 This service enables PEIMs to discover additional firmware files.
246
247 @param SearchType A filter to find files only of this type.
248 @param FwVolHeader Pointer to the firmware volume header of the volume to search.
249 This parameter must point to a valid FFS volume.
250 @param FileHeader Pointer to the current file from which to begin searching.
251
252 @retval EFI_SUCCESS The file was found.
253 @retval EFI_NOT_FOUND The file was not found.
254 @retval EFI_NOT_FOUND The header checksum was not zero.
255
256 **/
257 EFI_STATUS
258 EFIAPI
259 PeiServicesFfsFindNextFile (
260 IN EFI_FV_FILETYPE SearchType,
261 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
262 IN OUT EFI_FFS_FILE_HEADER **FileHeader
263 )
264 {
265 EFI_PEI_SERVICES **PeiServices;
266
267 PeiServices = GetPeiServicesTablePointer ();
268 return (*PeiServices)->FfsFindNextFile (PeiServices, SearchType, FwVolHeader, FileHeader);
269 }
270
271 /**
272 This service enables PEIMs to discover sections of a given type within a valid FFS file.
273
274 @param SearchType The value of the section type to find.
275 @param FfsFileHeader A pointer to the file header that contains the set of sections to
276 be searched.
277 @param SectionData A pointer to the discovered section, if successful.
278
279 @retval EFI_SUCCESS The section was found.
280 @retval EFI_NOT_FOUND The section was not found.
281
282 **/
283 EFI_STATUS
284 EFIAPI
285 PeiServicesFfsFindSectionData (
286 IN EFI_SECTION_TYPE SectionType,
287 IN EFI_FFS_FILE_HEADER *FfsFileHeader,
288 IN OUT VOID **SectionData
289 )
290 {
291 EFI_PEI_SERVICES **PeiServices;
292
293 PeiServices = GetPeiServicesTablePointer ();
294 return (*PeiServices)->FfsFindSectionData (PeiServices, SectionType, FfsFileHeader, SectionData);
295 }
296
297 #endif
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)->PeiResetSystem (PeiServices);
393 }