2 EFI PEI Core PPI services
4 Copyright (c) 2006, Intel Corporation
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
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.
19 Initialize PPI services.
21 @param PrivateData Pointer to the PEI Core data.
22 @param OldCoreData Pointer to old PEI Core data.
23 NULL if being run in non-permament memory mode.
27 InitializePpiServices (
28 IN PEI_CORE_INSTANCE
*PrivateData
,
29 IN PEI_CORE_INSTANCE
*OldCoreData
32 if (OldCoreData
== NULL
) {
33 PrivateData
->PpiData
.NotifyListEnd
= FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
)-1;
34 PrivateData
->PpiData
.DispatchListEnd
= FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
)-1;
35 PrivateData
->PpiData
.LastDispatchedNotify
= FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
)-1;
41 Migrate the Hob list from the CAR stack to PEI installed memory.
43 @param PrivateData Pointer to PeiCore's private data structure.
44 @param OldCheckingBottom Bottom of temporary memory range. All Ppi in this range
45 will be fixup for PpiData and PpiDescriptor pointer.
46 @param OldCheckingTop Top of temporary memory range. All Ppi in this range
47 will be fixup for PpiData and PpiDescriptor.
48 @param Fixup The address difference between
49 the new Hob list and old Hob list.
54 IN PEI_CORE_INSTANCE
*PrivateData
,
55 IN UINTN OldCheckingBottom
,
56 IN UINTN OldCheckingTop
,
61 PEI_PPI_LIST_POINTERS
*PpiPointer
;
63 for (Index
= 0; Index
< FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
); Index
++) {
64 if (Index
< PrivateData
->PpiData
.PpiListEnd
||
65 Index
> PrivateData
->PpiData
.NotifyListEnd
) {
66 PpiPointer
= &PrivateData
->PpiData
.PpiListPtrs
[Index
];
68 if (((UINTN
)PpiPointer
->Raw
< OldCheckingTop
) &&
69 ((UINTN
)PpiPointer
->Raw
>= OldCheckingBottom
)) {
71 // Convert the pointer to the PEIM descriptor from the old HOB heap
72 // to the relocated HOB heap.
74 PpiPointer
->Raw
= (VOID
*) ((UINTN
)PpiPointer
->Raw
+ Fixup
);
77 // Only when the PEIM descriptor is in the old HOB should it be necessary
78 // to try to convert the pointers in the PEIM descriptor
81 if (((UINTN
)PpiPointer
->Ppi
->Guid
< OldCheckingTop
) &&
82 ((UINTN
)PpiPointer
->Ppi
->Guid
>= OldCheckingBottom
)) {
84 // Convert the pointer to the GUID in the PPI or NOTIFY descriptor
85 // from the old HOB heap to the relocated HOB heap.
87 PpiPointer
->Ppi
->Guid
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Guid
+ Fixup
);
91 // Assume that no code is located in the temporary memory, so the pointer to
92 // the notification function in the NOTIFY descriptor needs not be converted.
94 if (Index
< PrivateData
->PpiData
.PpiListEnd
&&
95 (UINTN
)PpiPointer
->Ppi
->Ppi
< OldCheckingTop
&&
96 (UINTN
)PpiPointer
->Ppi
->Ppi
>= OldCheckingBottom
) {
98 // Convert the pointer to the PPI interface structure in the PPI descriptor
99 // from the old HOB heap to the relocated HOB heap.
101 PpiPointer
->Ppi
->Ppi
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Ppi
+ Fixup
);
110 This function installs an interface in the PEI PPI database by GUID.
111 The purpose of the service is to publish an interface that other parties
112 can use to call additional PEIMs.
114 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
115 @param PpiList Pointer to a list of PEI PPI Descriptors.
117 @retval EFI_SUCCESS if all PPIs in PpiList are successfully installed.
118 @retval EFI_INVALID_PARAMETER if PpiList is NULL pointer
119 if any PPI in PpiList is not valid
120 @retval EFI_OUT_OF_RESOURCES if there is no more memory resource to install PPI
126 IN CONST EFI_PEI_SERVICES
**PeiServices
,
127 IN CONST EFI_PEI_PPI_DESCRIPTOR
*PpiList
130 PEI_CORE_INSTANCE
*PrivateData
;
132 INTN LastCallbackInstall
;
135 if (PpiList
== NULL
) {
136 return EFI_INVALID_PARAMETER
;
139 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
141 Index
= PrivateData
->PpiData
.PpiListEnd
;
142 LastCallbackInstall
= Index
;
145 // This is loop installs all PPI descriptors in the PpiList. It is terminated
146 // by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last
147 // EFI_PEI_PPI_DESCRIPTOR in the list.
152 // Since PpiData is used for NotifyList and PpiList, max resource
153 // is reached if the Install reaches the NotifyList
155 if (Index
== PrivateData
->PpiData
.NotifyListEnd
+ 1) {
156 return EFI_OUT_OF_RESOURCES
;
159 // Check if it is a valid PPI.
160 // If not, rollback list to exclude all in this list.
161 // Try to indicate which item failed.
163 if ((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_PPI
) == 0) {
164 PrivateData
->PpiData
.PpiListEnd
= LastCallbackInstall
;
165 DEBUG((EFI_D_ERROR
, "ERROR -> InstallPpi: %g %p\n", PpiList
->Guid
, PpiList
->Ppi
));
166 return EFI_INVALID_PARAMETER
;
169 DEBUG((EFI_D_INFO
, "Install PPI: %g\n", PpiList
->Guid
));
170 ASSERT (Index
< FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
));
171 PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
= (EFI_PEI_PPI_DESCRIPTOR
*) PpiList
;
172 PrivateData
->PpiData
.PpiListEnd
++;
175 // Continue until the end of the PPI List.
177 if ((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) ==
178 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) {
186 // Dispatch any callback level notifies for newly installed PPIs.
190 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
192 PrivateData
->PpiData
.PpiListEnd
,
193 PrivateData
->PpiData
.DispatchListEnd
,
194 PrivateData
->PpiData
.NotifyListEnd
203 This function reinstalls an interface in the PEI PPI database by GUID.
204 The purpose of the service is to publish an interface that other parties can
205 use to replace an interface of the same name in the protocol database with a
208 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
209 @param OldPpi Pointer to the old PEI PPI Descriptors.
210 @param NewPpi Pointer to the new PEI PPI Descriptors.
212 @retval EFI_SUCCESS if the operation was successful
213 @retval EFI_INVALID_PARAMETER if OldPpi or NewPpi is NULL
214 @retval EFI_INVALID_PARAMETER if NewPpi is not valid
215 @retval EFI_NOT_FOUND if the PPI was not in the database
221 IN CONST EFI_PEI_SERVICES
**PeiServices
,
222 IN CONST EFI_PEI_PPI_DESCRIPTOR
*OldPpi
,
223 IN CONST EFI_PEI_PPI_DESCRIPTOR
*NewPpi
226 PEI_CORE_INSTANCE
*PrivateData
;
230 if ((OldPpi
== NULL
) || (NewPpi
== NULL
)) {
231 return EFI_INVALID_PARAMETER
;
234 if ((NewPpi
->Flags
& EFI_PEI_PPI_DESCRIPTOR_PPI
) == 0) {
235 return EFI_INVALID_PARAMETER
;
238 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
241 // Find the old PPI instance in the database. If we can not find it,
242 // return the EFI_NOT_FOUND error.
244 for (Index
= 0; Index
< PrivateData
->PpiData
.PpiListEnd
; Index
++) {
245 if (OldPpi
== PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
) {
249 if (Index
== PrivateData
->PpiData
.PpiListEnd
) {
250 return EFI_NOT_FOUND
;
254 // Remove the old PPI from the database, add the new one.
256 DEBUG((EFI_D_INFO
, "Reinstall PPI: %g\n", NewPpi
->Guid
));
257 PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
= (EFI_PEI_PPI_DESCRIPTOR
*) NewPpi
;
260 // Dispatch any callback level notifies for the newly installed PPI.
264 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
267 PrivateData
->PpiData
.DispatchListEnd
,
268 PrivateData
->PpiData
.NotifyListEnd
277 Locate a given named PPI.
280 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
281 @param Guid Pointer to GUID of the PPI.
282 @param Instance Instance Number to discover.
283 @param PpiDescriptor Pointer to reference the found descriptor. If not NULL,
284 returns a pointer to the descriptor (includes flags, etc)
285 @param Ppi Pointer to reference the found PPI
287 @retval EFI_SUCCESS if the PPI is in the database
288 @retval EFI_NOT_FOUND if the PPI is not in the database
294 IN CONST EFI_PEI_SERVICES
**PeiServices
,
295 IN CONST EFI_GUID
*Guid
,
297 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
301 PEI_CORE_INSTANCE
*PrivateData
;
304 EFI_PEI_PPI_DESCRIPTOR
*TempPtr
;
307 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
310 // Search the data base for the matching instance of the GUIDed PPI.
312 for (Index
= 0; Index
< PrivateData
->PpiData
.PpiListEnd
; Index
++) {
313 TempPtr
= PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
;
314 CheckGuid
= TempPtr
->Guid
;
317 // Don't use CompareGuid function here for performance reasons.
318 // Instead we compare the GUID as INT32 at a time and branch
319 // on the first failed comparison.
321 if ((((INT32
*)Guid
)[0] == ((INT32
*)CheckGuid
)[0]) &&
322 (((INT32
*)Guid
)[1] == ((INT32
*)CheckGuid
)[1]) &&
323 (((INT32
*)Guid
)[2] == ((INT32
*)CheckGuid
)[2]) &&
324 (((INT32
*)Guid
)[3] == ((INT32
*)CheckGuid
)[3])) {
327 if (PpiDescriptor
!= NULL
) {
328 *PpiDescriptor
= TempPtr
;
342 return EFI_NOT_FOUND
;
347 This function installs a notification service to be called back when a given
348 interface is installed or reinstalled. The purpose of the service is to publish
349 an interface that other parties can use to call additional PPIs that may materialize later.
351 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
352 @param NotifyList Pointer to list of Descriptors to notify upon.
354 @retval EFI_SUCCESS if successful
355 @retval EFI_OUT_OF_RESOURCES if no space in the database
356 @retval EFI_INVALID_PARAMETER if not a good decriptor
362 IN CONST EFI_PEI_SERVICES
**PeiServices
,
363 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyList
366 PEI_CORE_INSTANCE
*PrivateData
;
369 INTN LastCallbackNotify
;
370 EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyPtr
;
371 UINTN NotifyDispatchCount
;
374 NotifyDispatchCount
= 0;
376 if (NotifyList
== NULL
) {
377 return EFI_INVALID_PARAMETER
;
380 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
382 Index
= PrivateData
->PpiData
.NotifyListEnd
;
383 LastCallbackNotify
= Index
;
386 // This is loop installs all Notify descriptors in the NotifyList. It is
387 // terminated by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last
388 // EFI_PEI_NOTIFY_DESCRIPTOR in the list.
393 // Since PpiData is used for NotifyList and InstallList, max resource
394 // is reached if the Install reaches the PpiList
396 if (Index
== PrivateData
->PpiData
.PpiListEnd
- 1) {
397 return EFI_OUT_OF_RESOURCES
;
401 // If some of the PPI data is invalid restore original Notify PPI database value
403 if ((NotifyList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES
) == 0) {
404 PrivateData
->PpiData
.NotifyListEnd
= LastCallbackNotify
;
405 DEBUG((EFI_D_ERROR
, "ERROR -> InstallNotify: %g %p\n", NotifyList
->Guid
, NotifyList
->Notify
));
406 return EFI_INVALID_PARAMETER
;
409 if ((NotifyList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
) != 0) {
410 NotifyDispatchCount
++;
413 PrivateData
->PpiData
.PpiListPtrs
[Index
].Notify
= (EFI_PEI_NOTIFY_DESCRIPTOR
*) NotifyList
;
415 PrivateData
->PpiData
.NotifyListEnd
--;
416 DEBUG((EFI_D_INFO
, "Register PPI Notify: %g\n", NotifyList
->Guid
));
417 if ((NotifyList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) ==
418 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) {
422 // Go the next descriptor. Remember the NotifyList moves down.
429 // If there is Dispatch Notify PPI installed put them on the bottom
431 if (NotifyDispatchCount
> 0) {
432 for (NotifyIndex
= LastCallbackNotify
; NotifyIndex
> PrivateData
->PpiData
.NotifyListEnd
; NotifyIndex
--) {
433 if ((PrivateData
->PpiData
.PpiListPtrs
[NotifyIndex
].Notify
->Flags
& EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
) != 0) {
434 NotifyPtr
= PrivateData
->PpiData
.PpiListPtrs
[NotifyIndex
].Notify
;
436 for (Index
= NotifyIndex
; Index
< PrivateData
->PpiData
.DispatchListEnd
; Index
++){
437 PrivateData
->PpiData
.PpiListPtrs
[Index
].Notify
= PrivateData
->PpiData
.PpiListPtrs
[Index
+ 1].Notify
;
439 PrivateData
->PpiData
.PpiListPtrs
[Index
].Notify
= NotifyPtr
;
440 PrivateData
->PpiData
.DispatchListEnd
--;
444 LastCallbackNotify
-= NotifyDispatchCount
;
448 // Dispatch any callback level notifies for all previously installed PPIs.
452 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
454 PrivateData
->PpiData
.PpiListEnd
,
456 PrivateData
->PpiData
.NotifyListEnd
465 Process the Notify List at dispatch level.
467 @param PrivateData PeiCore's private data structure.
472 IN PEI_CORE_INSTANCE
*PrivateData
479 // Check if the PEIM that was just dispatched resulted in any
480 // Notifies getting installed. If so, go process any dispatch
481 // level Notifies that match the previouly installed PPIs.
482 // Use "while" instead of "if" since DispatchNotify can modify
483 // DispatchListEnd (with NotifyPpi) so we have to iterate until the same.
485 while (PrivateData
->PpiData
.LastDispatchedNotify
!= PrivateData
->PpiData
.DispatchListEnd
) {
486 TempValue
= PrivateData
->PpiData
.DispatchListEnd
;
489 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
,
491 PrivateData
->PpiData
.LastDispatchedInstall
,
492 PrivateData
->PpiData
.LastDispatchedNotify
,
493 PrivateData
->PpiData
.DispatchListEnd
495 PrivateData
->PpiData
.LastDispatchedNotify
= TempValue
;
500 // Check if the PEIM that was just dispatched resulted in any
501 // PPIs getting installed. If so, go process any dispatch
502 // level Notifies that match the installed PPIs.
503 // Use "while" instead of "if" since DispatchNotify can modify
504 // PpiListEnd (with InstallPpi) so we have to iterate until the same.
506 while (PrivateData
->PpiData
.LastDispatchedInstall
!= PrivateData
->PpiData
.PpiListEnd
) {
507 TempValue
= PrivateData
->PpiData
.PpiListEnd
;
510 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
,
511 PrivateData
->PpiData
.LastDispatchedInstall
,
512 PrivateData
->PpiData
.PpiListEnd
,
513 FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
)-1,
514 PrivateData
->PpiData
.DispatchListEnd
516 PrivateData
->PpiData
.LastDispatchedInstall
= TempValue
;
519 if (PrivateData
->PpiData
.LastDispatchedNotify
== PrivateData
->PpiData
.DispatchListEnd
) {
528 Dispatch notifications.
530 @param PrivateData PeiCore's private data structure
531 @param NotifyType Type of notify to fire.
532 @param InstallStartIndex Install Beginning index.
533 @param InstallStopIndex Install Ending index.
534 @param NotifyStartIndex Notify Beginning index.
535 @param NotifyStopIndex Notify Ending index.
540 IN PEI_CORE_INSTANCE
*PrivateData
,
542 IN INTN InstallStartIndex
,
543 IN INTN InstallStopIndex
,
544 IN INTN NotifyStartIndex
,
545 IN INTN NotifyStopIndex
550 EFI_GUID
*SearchGuid
;
552 EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
;
555 // Remember that Installs moves up and Notifies moves down.
557 for (Index1
= NotifyStartIndex
; Index1
> NotifyStopIndex
; Index1
--) {
558 NotifyDescriptor
= PrivateData
->PpiData
.PpiListPtrs
[Index1
].Notify
;
560 CheckGuid
= NotifyDescriptor
->Guid
;
562 for (Index2
= InstallStartIndex
; Index2
< InstallStopIndex
; Index2
++) {
563 SearchGuid
= PrivateData
->PpiData
.PpiListPtrs
[Index2
].Ppi
->Guid
;
565 // Don't use CompareGuid function here for performance reasons.
566 // Instead we compare the GUID as INT32 at a time and branch
567 // on the first failed comparison.
569 if ((((INT32
*)SearchGuid
)[0] == ((INT32
*)CheckGuid
)[0]) &&
570 (((INT32
*)SearchGuid
)[1] == ((INT32
*)CheckGuid
)[1]) &&
571 (((INT32
*)SearchGuid
)[2] == ((INT32
*)CheckGuid
)[2]) &&
572 (((INT32
*)SearchGuid
)[3] == ((INT32
*)CheckGuid
)[3])) {
573 DEBUG ((EFI_D_INFO
, "Notify: PPI Guid: %g, Peim notify entry point: %p\n",
575 NotifyDescriptor
->Notify
577 NotifyDescriptor
->Notify (
578 (EFI_PEI_SERVICES
**) GetPeiServicesTablePointer (),
580 (PrivateData
->PpiData
.PpiListPtrs
[Index2
].Ppi
)->Ppi