]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | /*++\r |
2 | \r | |
2c7e5c2f HT |
3 | Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r |
4 | This program and the accompanying materials \r | |
3eb9473e | 5 | are licensed and made available under the terms and conditions of the BSD License \r |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | \r | |
13 | Module Name:\r | |
14 | \r | |
15 | PeiServicesLib.c\r | |
16 | \r | |
17 | Abstract: \r | |
18 | \r | |
19 | PEI Services Lib\r | |
20 | \r | |
21 | --*/\r | |
22 | \r | |
23 | #include "EdkIIGluePeim.h"\r | |
24 | \r | |
25 | /**\r | |
26 | This service enables a given PEIM to register an interface into the PEI Foundation. \r | |
27 | \r | |
28 | @param PpiList A pointer to the list of interfaces that the caller shall install.\r | |
29 | \r | |
30 | @retval EFI_SUCCESS The interface was successfully installed.\r | |
31 | @retval EFI_INVALID_PARAMETER The PpiList pointer is NULL.\r | |
32 | @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the\r | |
33 | EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.\r | |
34 | @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.\r | |
35 | \r | |
36 | **/\r | |
37 | EFI_STATUS\r | |
38 | EFIAPI\r | |
39 | PeiServicesInstallPpi (\r | |
40 | IN EFI_PEI_PPI_DESCRIPTOR *PpiList\r | |
41 | )\r | |
42 | {\r | |
43 | EFI_PEI_SERVICES **PeiServices;\r | |
44 | \r | |
45 | PeiServices = GetPeiServicesTablePointer ();\r | |
46 | return (*PeiServices)->InstallPpi (PeiServices, PpiList);\r | |
47 | }\r | |
48 | \r | |
49 | /**\r | |
50 | This service enables PEIMs to replace an entry in the PPI database with an alternate entry.\r | |
51 | \r | |
52 | @param OldPpi Pointer to the old PEI PPI Descriptors.\r | |
53 | @param NewPpi Pointer to the new PEI PPI Descriptors.\r | |
54 | \r | |
55 | @retval EFI_SUCCESS The interface was successfully installed.\r | |
56 | @retval EFI_INVALID_PARAMETER The OldPpi or NewPpi is NULL.\r | |
57 | @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the\r | |
58 | EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.\r | |
59 | @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.\r | |
60 | @retval EFI_NOT_FOUND The PPI for which the reinstallation was requested has not been\r | |
61 | installed.\r | |
62 | \r | |
63 | **/\r | |
64 | EFI_STATUS\r | |
65 | EFIAPI\r | |
66 | PeiServicesReInstallPpi (\r | |
67 | IN EFI_PEI_PPI_DESCRIPTOR *OldPpi,\r | |
68 | IN EFI_PEI_PPI_DESCRIPTOR *NewPpi\r | |
69 | )\r | |
70 | {\r | |
71 | EFI_PEI_SERVICES **PeiServices;\r | |
72 | \r | |
73 | PeiServices = GetPeiServicesTablePointer ();\r | |
74 | return (*PeiServices)->ReInstallPpi (PeiServices, OldPpi, NewPpi);\r | |
75 | }\r | |
76 | \r | |
77 | /**\r | |
78 | This service enables PEIMs to discover a given instance of an interface.\r | |
79 | \r | |
80 | @param Guid A pointer to the GUID whose corresponding interface needs to be\r | |
81 | found.\r | |
82 | @param Instance The N-th instance of the interface that is required.\r | |
83 | @param PpiDescriptor A pointer to instance of the EFI_PEI_PPI_DESCRIPTOR.\r | |
84 | @param Ppi A pointer to the instance of the interface.\r | |
85 | \r | |
86 | @retval EFI_SUCCESS The interface was successfully returned.\r | |
87 | @retval EFI_NOT_FOUND The PPI descriptor is not found in the database.\r | |
88 | \r | |
89 | **/\r | |
90 | EFI_STATUS\r | |
91 | EFIAPI\r | |
92 | PeiServicesLocatePpi (\r | |
93 | IN EFI_GUID *Guid,\r | |
94 | IN UINTN Instance,\r | |
95 | IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,\r | |
96 | IN OUT VOID **Ppi\r | |
97 | )\r | |
98 | {\r | |
99 | EFI_PEI_SERVICES **PeiServices;\r | |
100 | \r | |
101 | PeiServices = GetPeiServicesTablePointer ();\r | |
102 | return (*PeiServices)->LocatePpi (PeiServices, Guid, Instance, PpiDescriptor, Ppi);\r | |
103 | }\r | |
104 | \r | |
105 | /**\r | |
106 | This service enables PEIMs to register a given service to be invoked when another service is\r | |
107 | installed or reinstalled.\r | |
108 | \r | |
109 | @param NotifyList A pointer to the list of notification interfaces that the caller\r | |
110 | shall install.\r | |
111 | \r | |
112 | @retval EFI_SUCCESS The interface was successfully installed.\r | |
113 | @retval EFI_INVALID_PARAMETER The NotifyList pointer is NULL.\r | |
114 | @retval EFI_INVALID_PARAMETER Any of the PEI notify descriptors in the list do not have the\r | |
115 | EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES bit set in the Flags field.\r | |
116 | @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.\r | |
117 | \r | |
118 | **/\r | |
119 | EFI_STATUS\r | |
120 | EFIAPI\r | |
121 | PeiServicesNotifyPpi (\r | |
122 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList\r | |
123 | )\r | |
124 | {\r | |
125 | EFI_PEI_SERVICES **PeiServices;\r | |
126 | \r | |
127 | PeiServices = GetPeiServicesTablePointer ();\r | |
128 | return (*PeiServices)->NotifyPpi (PeiServices, NotifyList);\r | |
129 | }\r | |
130 | \r | |
131 | /**\r | |
132 | This service enables PEIMs to ascertain the present value of the boot mode. \r | |
133 | \r | |
134 | @param BootMode A pointer to contain the value of the boot mode.\r | |
135 | \r | |
136 | @retval EFI_SUCCESS The boot mode was returned successfully.\r | |
137 | @retval EFI_INVALID_PARAMETER BootMode is NULL.\r | |
138 | \r | |
139 | **/\r | |
140 | EFI_STATUS\r | |
141 | EFIAPI\r | |
142 | PeiServicesGetBootMode (\r | |
143 | IN OUT EFI_BOOT_MODE *BootMode\r | |
144 | )\r | |
145 | {\r | |
146 | EFI_PEI_SERVICES **PeiServices;\r | |
147 | \r | |
148 | PeiServices = GetPeiServicesTablePointer ();\r | |
149 | return (*PeiServices)->GetBootMode (PeiServices, BootMode);\r | |
150 | }\r | |
151 | \r | |
152 | /**\r | |
153 | This service enables PEIMs to update the boot mode variable. \r | |
154 | \r | |
155 | @param BootMode The value of the boot mode to set.\r | |
156 | \r | |
157 | @retval EFI_SUCCESS The value was successfully updated\r | |
158 | \r | |
159 | **/\r | |
160 | EFI_STATUS\r | |
161 | EFIAPI\r | |
162 | PeiServicesSetBootMode (\r | |
163 | IN EFI_BOOT_MODE BootMode\r | |
164 | )\r | |
165 | {\r | |
166 | EFI_PEI_SERVICES **PeiServices;\r | |
167 | \r | |
168 | PeiServices = GetPeiServicesTablePointer ();\r | |
169 | return (*PeiServices)->SetBootMode (PeiServices, BootMode);\r | |
170 | }\r | |
171 | \r | |
172 | /**\r | |
173 | This service enables a PEIM to ascertain the address of the list of HOBs in memory.\r | |
174 | \r | |
175 | @param HobList A pointer to the list of HOBs that the PEI Foundation will initialize.\r | |
176 | \r | |
177 | @retval EFI_SUCCESS The list was successfully returned.\r | |
178 | @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.\r | |
179 | \r | |
180 | **/\r | |
181 | EFI_STATUS\r | |
182 | EFIAPI\r | |
183 | PeiServicesGetHobList (\r | |
184 | IN OUT VOID **HobList\r | |
185 | )\r | |
186 | {\r | |
187 | EFI_PEI_SERVICES **PeiServices;\r | |
188 | \r | |
189 | PeiServices = GetPeiServicesTablePointer ();\r | |
190 | return (*PeiServices)->GetHobList (PeiServices, HobList);\r | |
191 | }\r | |
192 | \r | |
193 | /**\r | |
194 | This service enables PEIMs to create various types of HOBs.\r | |
195 | \r | |
196 | @param Type The type of HOB to be installed.\r | |
197 | @param Length The length of the HOB to be added.\r | |
198 | @param Hob The address of a pointer that will contain the HOB header.\r | |
199 | \r | |
200 | @retval EFI_SUCCESS The HOB was successfully created.\r | |
201 | @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.\r | |
202 | \r | |
203 | **/\r | |
204 | EFI_STATUS\r | |
205 | EFIAPI\r | |
206 | PeiServicesCreateHob (\r | |
207 | IN UINT16 Type,\r | |
208 | IN UINT16 Length,\r | |
209 | IN OUT VOID **Hob\r | |
210 | )\r | |
211 | {\r | |
212 | EFI_PEI_SERVICES **PeiServices;\r | |
213 | \r | |
214 | PeiServices = GetPeiServicesTablePointer ();\r | |
215 | return (*PeiServices)->CreateHob (PeiServices, Type, Length, Hob);\r | |
216 | }\r | |
217 | \r | |
218 | #if (PI_SPECIFICATION_VERSION < 0x00010000)\r | |
219 | /**\r | |
220 | This service enables PEIMs to discover additional firmware volumes.\r | |
221 | \r | |
222 | @param Instance This instance of the firmware volume to find. The value 0 is the\r | |
223 | Boot Firmware Volume (BFV).\r | |
224 | @param FwVolHeader Pointer to the firmware volume header of the volume to return.\r | |
225 | \r | |
226 | @retval EFI_SUCCESS The volume was found.\r | |
227 | @retval EFI_NOT_FOUND The volume was not found.\r | |
228 | @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.\r | |
229 | \r | |
230 | **/\r | |
231 | EFI_STATUS\r | |
232 | EFIAPI\r | |
233 | PeiServicesFfsFindNextVolume (\r | |
234 | IN UINTN Instance,\r | |
235 | IN OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader\r | |
236 | )\r | |
237 | {\r | |
238 | EFI_PEI_SERVICES **PeiServices;\r | |
239 | \r | |
240 | PeiServices = GetPeiServicesTablePointer ();\r | |
241 | return (*PeiServices)->FfsFindNextVolume (PeiServices, Instance, FwVolHeader);\r | |
242 | }\r | |
243 | \r | |
244 | /**\r | |
245 | This service enables PEIMs to discover additional firmware files.\r | |
246 | \r | |
247 | @param SearchType A filter to find files only of this type.\r | |
248 | @param FwVolHeader Pointer to the firmware volume header of the volume to search.\r | |
249 | This parameter must point to a valid FFS volume.\r | |
250 | @param FileHeader Pointer to the current file from which to begin searching.\r | |
251 | \r | |
252 | @retval EFI_SUCCESS The file was found.\r | |
253 | @retval EFI_NOT_FOUND The file was not found.\r | |
254 | @retval EFI_NOT_FOUND The header checksum was not zero.\r | |
255 | \r | |
256 | **/\r | |
257 | EFI_STATUS\r | |
258 | EFIAPI\r | |
259 | PeiServicesFfsFindNextFile (\r | |
260 | IN EFI_FV_FILETYPE SearchType,\r | |
261 | IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,\r | |
262 | IN OUT EFI_FFS_FILE_HEADER **FileHeader\r | |
263 | )\r | |
264 | {\r | |
265 | EFI_PEI_SERVICES **PeiServices;\r | |
266 | \r | |
267 | PeiServices = GetPeiServicesTablePointer ();\r | |
268 | return (*PeiServices)->FfsFindNextFile (PeiServices, SearchType, FwVolHeader, FileHeader);\r | |
269 | }\r | |
270 | \r | |
271 | /**\r | |
272 | This service enables PEIMs to discover sections of a given type within a valid FFS file.\r | |
273 | \r | |
274 | @param SearchType The value of the section type to find.\r | |
275 | @param FfsFileHeader A pointer to the file header that contains the set of sections to\r | |
276 | be searched.\r | |
277 | @param SectionData A pointer to the discovered section, if successful.\r | |
278 | \r | |
279 | @retval EFI_SUCCESS The section was found.\r | |
280 | @retval EFI_NOT_FOUND The section was not found.\r | |
281 | \r | |
282 | **/\r | |
283 | EFI_STATUS\r | |
284 | EFIAPI\r | |
285 | PeiServicesFfsFindSectionData (\r | |
286 | IN EFI_SECTION_TYPE SectionType,\r | |
287 | IN EFI_FFS_FILE_HEADER *FfsFileHeader,\r | |
288 | IN OUT VOID **SectionData\r | |
289 | )\r | |
290 | {\r | |
291 | EFI_PEI_SERVICES **PeiServices;\r | |
292 | \r | |
293 | PeiServices = GetPeiServicesTablePointer ();\r | |
294 | return (*PeiServices)->FfsFindSectionData (PeiServices, SectionType, FfsFileHeader, SectionData);\r | |
295 | }\r | |
296 | \r | |
297 | #endif\r | |
298 | \r | |
299 | /**\r | |
300 | This service enables PEIMs to register the permanent memory configuration\r | |
301 | that has been initialized with the PEI Foundation.\r | |
302 | \r | |
303 | @param MemoryBegin The value of a region of installed memory.\r | |
304 | @param MemoryLength The corresponding length of a region of installed memory.\r | |
305 | \r | |
306 | @retval EFI_SUCCESS The region was successfully installed in a HOB.\r | |
307 | @retval EFI_INVALID_PARAMETER MemoryBegin and MemoryLength are illegal for this system.\r | |
308 | @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.\r | |
309 | \r | |
310 | **/\r | |
311 | EFI_STATUS\r | |
312 | EFIAPI\r | |
313 | PeiServicesInstallPeiMemory (\r | |
314 | IN EFI_PHYSICAL_ADDRESS MemoryBegin,\r | |
315 | IN UINT64 MemoryLength\r | |
316 | )\r | |
317 | {\r | |
318 | EFI_PEI_SERVICES **PeiServices;\r | |
319 | \r | |
320 | PeiServices = GetPeiServicesTablePointer ();\r | |
321 | return (*PeiServices)->InstallPeiMemory (PeiServices, MemoryBegin, MemoryLength);\r | |
322 | }\r | |
323 | \r | |
324 | /**\r | |
325 | This service enables PEIMs to allocate memory after the permanent memory has been installed by a\r | |
326 | PEIM.\r | |
327 | \r | |
328 | @param MemoryType Type of memory to allocate.\r | |
329 | @param Pages Number of pages to allocate.\r | |
330 | @param Memory Pointer of memory allocated.\r | |
331 | \r | |
332 | @retval EFI_SUCCESS The memory range was successfully allocated.\r | |
333 | @retval EFI_INVALID_PARAMETER Type is not equal to AllocateAnyPages.\r | |
334 | @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available.\r | |
335 | @retval EFI_OUT_OF_RESOURCES The pages could not be allocated.\r | |
336 | \r | |
337 | **/\r | |
338 | EFI_STATUS\r | |
339 | EFIAPI\r | |
340 | PeiServicesAllocatePages (\r | |
341 | IN EFI_MEMORY_TYPE MemoryType,\r | |
342 | IN UINTN Pages,\r | |
343 | IN OUT EFI_PHYSICAL_ADDRESS *Memory\r | |
344 | )\r | |
345 | {\r | |
346 | EFI_PEI_SERVICES **PeiServices;\r | |
347 | \r | |
348 | PeiServices = GetPeiServicesTablePointer ();\r | |
349 | return ((*PeiServices)->AllocatePages) (PeiServices, MemoryType, Pages, Memory);\r | |
350 | }\r | |
351 | \r | |
352 | /**\r | |
353 | This service allocates memory from the Hand-Off Block (HOB) heap.\r | |
354 | \r | |
355 | @param Size The number of bytes to allocate from the pool.\r | |
356 | @param Buffer If the call succeeds, a pointer to a pointer to the allocate\r | |
357 | buffer; undefined otherwise.\r | |
358 | \r | |
359 | @retval EFI_SUCCESS The allocation was successful\r | |
360 | @retval EFI_OUT_OF_RESOURCES There is not enough heap to allocate the requested size.\r | |
361 | \r | |
362 | **/\r | |
363 | EFI_STATUS\r | |
364 | EFIAPI\r | |
365 | PeiServicesAllocatePool (\r | |
366 | IN UINTN Size,\r | |
367 | OUT VOID **Buffer\r | |
368 | )\r | |
369 | {\r | |
370 | EFI_PEI_SERVICES **PeiServices;\r | |
371 | \r | |
372 | PeiServices = GetPeiServicesTablePointer ();\r | |
373 | return ((*PeiServices)->AllocatePool) (PeiServices, Size, Buffer);\r | |
374 | }\r | |
375 | \r | |
376 | /**\r | |
377 | This service resets the entire platform, including all processors and devices, and reboots the\r | |
378 | system. \r | |
379 | \r | |
380 | @retval EFI_NOT_AVAILABLE_YET The service has not been installed yet.\r | |
381 | \r | |
382 | **/\r | |
383 | EFI_STATUS\r | |
384 | EFIAPI\r | |
385 | PeiServicesResetSystem (\r | |
386 | VOID\r | |
387 | )\r | |
388 | {\r | |
389 | EFI_PEI_SERVICES **PeiServices;\r | |
390 | \r | |
391 | PeiServices = GetPeiServicesTablePointer ();\r | |
392 | return (*PeiServices)->PeiResetSystem (PeiServices);\r | |
393 | }\r | |
64cd21af LG |
394 | /**\r |
395 | PCI read-modify-write operations.\r | |
396 | \r | |
397 | PIWG's PI specification replaces Inte's EFI Specification 1.10.\r | |
398 | EFI_PEI_PCI_CFG_PPI defined in Inte's EFI Specification 1.10 is replaced by\r | |
399 | EFI_PEI_PCI_CFG2_PPI in PI 1.0. "Modify" function in these two PPI are not \r | |
400 | compatibile with each other.\r | |
401 | \r | |
402 | For Framework code that make the following call:\r | |
403 | PciCfg->Modify (\r | |
404 | PeiServices,\r | |
405 | PciCfg,\r | |
406 | Width,\r | |
407 | Address,\r | |
408 | SetBits,\r | |
409 | ClearBits\r | |
410 | );\r | |
411 | it will be updated to the following code which call this library API:\r | |
412 | PeiLibPciCfgModify (\r | |
413 | PeiServices,\r | |
414 | PciCfg,\r | |
415 | Width,\r | |
416 | Address,\r | |
417 | SetBits,\r | |
418 | ClearBits\r | |
419 | );\r | |
420 | \r | |
421 | @param PeiServices An indirect pointer to the PEI Services Table\r | |
422 | published by the PEI Foundation.\r | |
423 | @param PciCfg A pointer to the this pointer of EFI_PEI_PCI_CFG_PPI. \r | |
424 | This parameter is unused as a place holder to make\r | |
425 | the parameter list identical to PEI_PCI_CFG_PPI_RW.\r | |
426 | @param Width The width of the access. Enumerated in bytes. Type\r | |
427 | EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().\r | |
428 | @param Address The physical address of the access.\r | |
429 | @param SetBits Points to value to bitwise-OR with the read configuration value.\r | |
430 | The size of the value is determined by Width.\r | |
431 | @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.\r | |
432 | The size of the value is determined by Width.\r | |
433 | \r | |
434 | @retval EFI_SUCCESS The function completed successfully.\r | |
435 | @retval EFI_DEVICE_ERROR There was a problem with the transaction.\r | |
436 | **/\r | |
437 | EFI_STATUS\r | |
438 | EFIAPI \r | |
439 | PeiLibPciCfgModify (\r | |
440 | IN EFI_PEI_SERVICES **PeiServices,\r | |
441 | IN PEI_PCI_CFG_PPI *PciCfg,\r | |
442 | IN PEI_PCI_CFG_PPI_WIDTH Width,\r | |
443 | IN UINT64 Address,\r | |
444 | IN UINTN SetBits,\r | |
445 | IN UINTN ClearBits\r | |
446 | )\r | |
447 | {\r | |
448 | EFI_STATUS Status;\r | |
449 | EFI_PEI_PCI_CFG2_PPI *PciCfg2;\r | |
450 | \r | |
451 | Status = (*PeiServices)->LocatePpi (\r | |
452 | PeiServices,\r | |
453 | &gPeiPciCfg2PpiGuid,\r | |
454 | 0,\r | |
455 | NULL,\r | |
456 | (VOID **) &PciCfg2\r | |
457 | );\r | |
458 | ASSERT_EFI_ERROR (Status);\r | |
459 | \r | |
460 | Status = PciCfg2->Modify (\r | |
461 | (CONST EFI_PEI_SERVICES **) PeiServices,\r | |
462 | PciCfg2,\r | |
463 | (EFI_PEI_PCI_CFG_PPI_WIDTH) Width,\r | |
464 | Address,\r | |
465 | &SetBits,\r | |
466 | &ClearBits\r | |
467 | );\r | |
468 | \r | |
469 | return Status;\r | |
470 | }\r |