2 EFI PEI Core PPI services
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 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 temporary memory stack to PEI installed memory.
43 @param SecCoreData Points to a data structure containing SEC to PEI handoff data, such as the size
44 and location of temporary RAM, the stack location and the BFV location.
45 @param PrivateData Pointer to PeiCore's private data structure.
50 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
51 IN PEI_CORE_INSTANCE
*PrivateData
55 PEI_PPI_LIST_POINTERS
*PpiPointer
;
61 OldHeapBottom
= (UINTN
)SecCoreData
->PeiTemporaryRamBase
;
62 OldHeapTop
= (UINTN
)SecCoreData
->PeiTemporaryRamBase
+ SecCoreData
->PeiTemporaryRamSize
;
63 OldStackBottom
= (UINTN
)SecCoreData
->StackBase
;
64 OldStackTop
= (UINTN
)SecCoreData
->StackBase
+ SecCoreData
->StackSize
;
66 for (Index
= 0; Index
< FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
); Index
++) {
67 if (Index
< PrivateData
->PpiData
.PpiListEnd
||
68 Index
> PrivateData
->PpiData
.NotifyListEnd
) {
69 PpiPointer
= &PrivateData
->PpiData
.PpiListPtrs
[Index
];
71 if (((UINTN
)PpiPointer
->Raw
< OldHeapTop
) &&
72 ((UINTN
)PpiPointer
->Raw
>= OldHeapBottom
)) {
74 // Convert the pointer to the PPI descriptor from the old HOB heap
75 // to the relocated HOB heap.
77 if (PrivateData
->HeapOffsetPositive
) {
78 PpiPointer
->Raw
= (VOID
*) ((UINTN
)PpiPointer
->Raw
+ PrivateData
->HeapOffset
);
80 PpiPointer
->Raw
= (VOID
*) ((UINTN
)PpiPointer
->Raw
- PrivateData
->HeapOffset
);
84 // Only when the PEIM descriptor is in the old HOB should it be necessary
85 // to try to convert the pointers in the PEIM descriptor
88 if (((UINTN
)PpiPointer
->Ppi
->Guid
< OldHeapTop
) &&
89 ((UINTN
)PpiPointer
->Ppi
->Guid
>= OldHeapBottom
)) {
91 // Convert the pointer to the GUID in the PPI or NOTIFY descriptor
92 // from the old HOB heap to the relocated HOB heap.
94 if (PrivateData
->HeapOffsetPositive
) {
95 PpiPointer
->Ppi
->Guid
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Guid
+ PrivateData
->HeapOffset
);
97 PpiPointer
->Ppi
->Guid
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Guid
- PrivateData
->HeapOffset
);
102 // Assume that no code is located in the temporary memory, so the pointer to
103 // the notification function in the NOTIFY descriptor needs not be converted.
105 if (Index
< PrivateData
->PpiData
.PpiListEnd
&&
106 (UINTN
)PpiPointer
->Ppi
->Ppi
< OldHeapTop
&&
107 (UINTN
)PpiPointer
->Ppi
->Ppi
>= OldHeapBottom
) {
109 // Convert the pointer to the PPI interface structure in the PPI descriptor
110 // from the old HOB heap to the relocated HOB heap.
112 if (PrivateData
->HeapOffsetPositive
) {
113 PpiPointer
->Ppi
->Ppi
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Ppi
+ PrivateData
->HeapOffset
);
115 PpiPointer
->Ppi
->Ppi
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Ppi
- PrivateData
->HeapOffset
);
118 } else if (((UINTN
)PpiPointer
->Raw
< OldStackTop
) && ((UINTN
)PpiPointer
->Raw
>= OldStackBottom
)) {
120 // Convert the pointer to the PPI descriptor from the temporary stack
121 // to the permanent PEI stack.
123 if (PrivateData
->StackOffsetPositive
) {
124 PpiPointer
->Raw
= (VOID
*) ((UINTN
)PpiPointer
->Raw
+ PrivateData
->StackOffset
);
126 PpiPointer
->Raw
= (VOID
*) ((UINTN
)PpiPointer
->Raw
- PrivateData
->StackOffset
);
130 // Try to convert the pointers in the PEIM descriptor
133 if (((UINTN
)PpiPointer
->Ppi
->Guid
< OldStackTop
) &&
134 ((UINTN
)PpiPointer
->Ppi
->Guid
>= OldStackBottom
)) {
136 // Convert the pointer to the GUID in the PPI or NOTIFY descriptor
137 // from the the temporary stack to the permanent PEI stack.
139 if (PrivateData
->StackOffsetPositive
) {
140 PpiPointer
->Ppi
->Guid
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Guid
+ PrivateData
->StackOffset
);
142 PpiPointer
->Ppi
->Guid
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Guid
- PrivateData
->StackOffset
);
147 // Assume that no code is located in the temporary memory, so the pointer to
148 // the notification function in the NOTIFY descriptor needs not be converted.
150 if (Index
< PrivateData
->PpiData
.PpiListEnd
&&
151 (UINTN
)PpiPointer
->Ppi
->Ppi
< OldStackTop
&&
152 (UINTN
)PpiPointer
->Ppi
->Ppi
>= OldStackBottom
) {
154 // Convert the pointer to the PPI interface structure in the PPI descriptor
155 // from the the temporary stack to the permanent PEI stack.
157 if (PrivateData
->StackOffsetPositive
) {
158 PpiPointer
->Ppi
->Ppi
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Ppi
+ PrivateData
->StackOffset
);
160 PpiPointer
->Ppi
->Ppi
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Ppi
- PrivateData
->StackOffset
);
170 This function installs an interface in the PEI PPI database by GUID.
171 The purpose of the service is to publish an interface that other parties
172 can use to call additional PEIMs.
174 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
175 @param PpiList Pointer to a list of PEI PPI Descriptors.
177 @retval EFI_SUCCESS if all PPIs in PpiList are successfully installed.
178 @retval EFI_INVALID_PARAMETER if PpiList is NULL pointer
179 if any PPI in PpiList is not valid
180 @retval EFI_OUT_OF_RESOURCES if there is no more memory resource to install PPI
186 IN CONST EFI_PEI_SERVICES
**PeiServices
,
187 IN CONST EFI_PEI_PPI_DESCRIPTOR
*PpiList
190 PEI_CORE_INSTANCE
*PrivateData
;
192 INTN LastCallbackInstall
;
195 if (PpiList
== NULL
) {
196 return EFI_INVALID_PARAMETER
;
199 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
201 Index
= PrivateData
->PpiData
.PpiListEnd
;
202 LastCallbackInstall
= Index
;
205 // This is loop installs all PPI descriptors in the PpiList. It is terminated
206 // by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last
207 // EFI_PEI_PPI_DESCRIPTOR in the list.
212 // Since PpiData is used for NotifyList and PpiList, max resource
213 // is reached if the Install reaches the NotifyList
214 // PcdPeiCoreMaxPpiSupported can be set to a larger value in DSC to satisfy more PPI requirement.
216 if (Index
== PrivateData
->PpiData
.NotifyListEnd
+ 1) {
217 return EFI_OUT_OF_RESOURCES
;
220 // Check if it is a valid PPI.
221 // If not, rollback list to exclude all in this list.
222 // Try to indicate which item failed.
224 if ((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_PPI
) == 0) {
225 PrivateData
->PpiData
.PpiListEnd
= LastCallbackInstall
;
226 DEBUG((EFI_D_ERROR
, "ERROR -> InstallPpi: %g %p\n", PpiList
->Guid
, PpiList
->Ppi
));
227 return EFI_INVALID_PARAMETER
;
230 DEBUG((EFI_D_INFO
, "Install PPI: %g\n", PpiList
->Guid
));
231 PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
= (EFI_PEI_PPI_DESCRIPTOR
*) PpiList
;
232 PrivateData
->PpiData
.PpiListEnd
++;
235 // Continue until the end of the PPI List.
237 if ((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) ==
238 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) {
246 // Dispatch any callback level notifies for newly installed PPIs.
250 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
252 PrivateData
->PpiData
.PpiListEnd
,
253 PrivateData
->PpiData
.DispatchListEnd
,
254 PrivateData
->PpiData
.NotifyListEnd
263 This function reinstalls an interface in the PEI PPI database by GUID.
264 The purpose of the service is to publish an interface that other parties can
265 use to replace an interface of the same name in the protocol database with a
268 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
269 @param OldPpi Pointer to the old PEI PPI Descriptors.
270 @param NewPpi Pointer to the new PEI PPI Descriptors.
272 @retval EFI_SUCCESS if the operation was successful
273 @retval EFI_INVALID_PARAMETER if OldPpi or NewPpi is NULL
274 @retval EFI_INVALID_PARAMETER if NewPpi is not valid
275 @retval EFI_NOT_FOUND if the PPI was not in the database
281 IN CONST EFI_PEI_SERVICES
**PeiServices
,
282 IN CONST EFI_PEI_PPI_DESCRIPTOR
*OldPpi
,
283 IN CONST EFI_PEI_PPI_DESCRIPTOR
*NewPpi
286 PEI_CORE_INSTANCE
*PrivateData
;
290 if ((OldPpi
== NULL
) || (NewPpi
== NULL
)) {
291 return EFI_INVALID_PARAMETER
;
294 if ((NewPpi
->Flags
& EFI_PEI_PPI_DESCRIPTOR_PPI
) == 0) {
295 return EFI_INVALID_PARAMETER
;
298 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
301 // Find the old PPI instance in the database. If we can not find it,
302 // return the EFI_NOT_FOUND error.
304 for (Index
= 0; Index
< PrivateData
->PpiData
.PpiListEnd
; Index
++) {
305 if (OldPpi
== PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
) {
309 if (Index
== PrivateData
->PpiData
.PpiListEnd
) {
310 return EFI_NOT_FOUND
;
314 // Remove the old PPI from the database, add the new one.
316 DEBUG((EFI_D_INFO
, "Reinstall PPI: %g\n", NewPpi
->Guid
));
317 ASSERT (Index
< (INTN
)(FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
)));
318 PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
= (EFI_PEI_PPI_DESCRIPTOR
*) NewPpi
;
321 // Dispatch any callback level notifies for the newly installed PPI.
325 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
328 PrivateData
->PpiData
.DispatchListEnd
,
329 PrivateData
->PpiData
.NotifyListEnd
338 Locate a given named PPI.
341 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
342 @param Guid Pointer to GUID of the PPI.
343 @param Instance Instance Number to discover.
344 @param PpiDescriptor Pointer to reference the found descriptor. If not NULL,
345 returns a pointer to the descriptor (includes flags, etc)
346 @param Ppi Pointer to reference the found PPI
348 @retval EFI_SUCCESS if the PPI is in the database
349 @retval EFI_NOT_FOUND if the PPI is not in the database
355 IN CONST EFI_PEI_SERVICES
**PeiServices
,
356 IN CONST EFI_GUID
*Guid
,
358 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
362 PEI_CORE_INSTANCE
*PrivateData
;
365 EFI_PEI_PPI_DESCRIPTOR
*TempPtr
;
368 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
371 // Search the data base for the matching instance of the GUIDed PPI.
373 for (Index
= 0; Index
< PrivateData
->PpiData
.PpiListEnd
; Index
++) {
374 TempPtr
= PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
;
375 CheckGuid
= TempPtr
->Guid
;
378 // Don't use CompareGuid function here for performance reasons.
379 // Instead we compare the GUID as INT32 at a time and branch
380 // on the first failed comparison.
382 if ((((INT32
*)Guid
)[0] == ((INT32
*)CheckGuid
)[0]) &&
383 (((INT32
*)Guid
)[1] == ((INT32
*)CheckGuid
)[1]) &&
384 (((INT32
*)Guid
)[2] == ((INT32
*)CheckGuid
)[2]) &&
385 (((INT32
*)Guid
)[3] == ((INT32
*)CheckGuid
)[3])) {
388 if (PpiDescriptor
!= NULL
) {
389 *PpiDescriptor
= TempPtr
;
403 return EFI_NOT_FOUND
;
408 This function installs a notification service to be called back when a given
409 interface is installed or reinstalled. The purpose of the service is to publish
410 an interface that other parties can use to call additional PPIs that may materialize later.
412 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
413 @param NotifyList Pointer to list of Descriptors to notify upon.
415 @retval EFI_SUCCESS if successful
416 @retval EFI_OUT_OF_RESOURCES if no space in the database
417 @retval EFI_INVALID_PARAMETER if not a good decriptor
423 IN CONST EFI_PEI_SERVICES
**PeiServices
,
424 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyList
427 PEI_CORE_INSTANCE
*PrivateData
;
430 INTN LastCallbackNotify
;
431 EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyPtr
;
432 UINTN NotifyDispatchCount
;
435 NotifyDispatchCount
= 0;
437 if (NotifyList
== NULL
) {
438 return EFI_INVALID_PARAMETER
;
441 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
443 Index
= PrivateData
->PpiData
.NotifyListEnd
;
444 LastCallbackNotify
= Index
;
447 // This is loop installs all Notify descriptors in the NotifyList. It is
448 // terminated by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last
449 // EFI_PEI_NOTIFY_DESCRIPTOR in the list.
454 // Since PpiData is used for NotifyList and InstallList, max resource
455 // is reached if the Install reaches the PpiList
456 // PcdPeiCoreMaxPpiSupported can be set to a larger value in DSC to satisfy more Notify PPIs requirement.
458 if (Index
== PrivateData
->PpiData
.PpiListEnd
- 1) {
459 return EFI_OUT_OF_RESOURCES
;
463 // If some of the PPI data is invalid restore original Notify PPI database value
465 if ((NotifyList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES
) == 0) {
466 PrivateData
->PpiData
.NotifyListEnd
= LastCallbackNotify
;
467 DEBUG((EFI_D_ERROR
, "ERROR -> InstallNotify: %g %p\n", NotifyList
->Guid
, NotifyList
->Notify
));
468 return EFI_INVALID_PARAMETER
;
471 if ((NotifyList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
) != 0) {
472 NotifyDispatchCount
++;
475 PrivateData
->PpiData
.PpiListPtrs
[Index
].Notify
= (EFI_PEI_NOTIFY_DESCRIPTOR
*) NotifyList
;
477 PrivateData
->PpiData
.NotifyListEnd
--;
478 DEBUG((EFI_D_INFO
, "Register PPI Notify: %g\n", NotifyList
->Guid
));
479 if ((NotifyList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) ==
480 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) {
484 // Go the next descriptor. Remember the NotifyList moves down.
491 // If there is Dispatch Notify PPI installed put them on the bottom
493 if (NotifyDispatchCount
> 0) {
494 for (NotifyIndex
= LastCallbackNotify
; NotifyIndex
> PrivateData
->PpiData
.NotifyListEnd
; NotifyIndex
--) {
495 if ((PrivateData
->PpiData
.PpiListPtrs
[NotifyIndex
].Notify
->Flags
& EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
) != 0) {
496 NotifyPtr
= PrivateData
->PpiData
.PpiListPtrs
[NotifyIndex
].Notify
;
498 for (Index
= NotifyIndex
; Index
< PrivateData
->PpiData
.DispatchListEnd
; Index
++){
499 PrivateData
->PpiData
.PpiListPtrs
[Index
].Notify
= PrivateData
->PpiData
.PpiListPtrs
[Index
+ 1].Notify
;
501 PrivateData
->PpiData
.PpiListPtrs
[Index
].Notify
= NotifyPtr
;
502 PrivateData
->PpiData
.DispatchListEnd
--;
506 LastCallbackNotify
-= NotifyDispatchCount
;
510 // Dispatch any callback level notifies for all previously installed PPIs.
514 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
516 PrivateData
->PpiData
.PpiListEnd
,
518 PrivateData
->PpiData
.NotifyListEnd
527 Process the Notify List at dispatch level.
529 @param PrivateData PeiCore's private data structure.
534 IN PEI_CORE_INSTANCE
*PrivateData
541 // Check if the PEIM that was just dispatched resulted in any
542 // Notifies getting installed. If so, go process any dispatch
543 // level Notifies that match the previouly installed PPIs.
544 // Use "while" instead of "if" since DispatchNotify can modify
545 // DispatchListEnd (with NotifyPpi) so we have to iterate until the same.
547 while (PrivateData
->PpiData
.LastDispatchedNotify
!= PrivateData
->PpiData
.DispatchListEnd
) {
548 TempValue
= PrivateData
->PpiData
.DispatchListEnd
;
551 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
,
553 PrivateData
->PpiData
.LastDispatchedInstall
,
554 PrivateData
->PpiData
.LastDispatchedNotify
,
555 PrivateData
->PpiData
.DispatchListEnd
557 PrivateData
->PpiData
.LastDispatchedNotify
= TempValue
;
562 // Check if the PEIM that was just dispatched resulted in any
563 // PPIs getting installed. If so, go process any dispatch
564 // level Notifies that match the installed PPIs.
565 // Use "while" instead of "if" since DispatchNotify can modify
566 // PpiListEnd (with InstallPpi) so we have to iterate until the same.
568 while (PrivateData
->PpiData
.LastDispatchedInstall
!= PrivateData
->PpiData
.PpiListEnd
) {
569 TempValue
= PrivateData
->PpiData
.PpiListEnd
;
572 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
,
573 PrivateData
->PpiData
.LastDispatchedInstall
,
574 PrivateData
->PpiData
.PpiListEnd
,
575 FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
)-1,
576 PrivateData
->PpiData
.DispatchListEnd
578 PrivateData
->PpiData
.LastDispatchedInstall
= TempValue
;
581 if (PrivateData
->PpiData
.LastDispatchedNotify
== PrivateData
->PpiData
.DispatchListEnd
) {
590 Dispatch notifications.
592 @param PrivateData PeiCore's private data structure
593 @param NotifyType Type of notify to fire.
594 @param InstallStartIndex Install Beginning index.
595 @param InstallStopIndex Install Ending index.
596 @param NotifyStartIndex Notify Beginning index.
597 @param NotifyStopIndex Notify Ending index.
602 IN PEI_CORE_INSTANCE
*PrivateData
,
604 IN INTN InstallStartIndex
,
605 IN INTN InstallStopIndex
,
606 IN INTN NotifyStartIndex
,
607 IN INTN NotifyStopIndex
612 EFI_GUID
*SearchGuid
;
614 EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
;
617 // Remember that Installs moves up and Notifies moves down.
619 for (Index1
= NotifyStartIndex
; Index1
> NotifyStopIndex
; Index1
--) {
620 NotifyDescriptor
= PrivateData
->PpiData
.PpiListPtrs
[Index1
].Notify
;
622 CheckGuid
= NotifyDescriptor
->Guid
;
624 for (Index2
= InstallStartIndex
; Index2
< InstallStopIndex
; Index2
++) {
625 SearchGuid
= PrivateData
->PpiData
.PpiListPtrs
[Index2
].Ppi
->Guid
;
627 // Don't use CompareGuid function here for performance reasons.
628 // Instead we compare the GUID as INT32 at a time and branch
629 // on the first failed comparison.
631 if ((((INT32
*)SearchGuid
)[0] == ((INT32
*)CheckGuid
)[0]) &&
632 (((INT32
*)SearchGuid
)[1] == ((INT32
*)CheckGuid
)[1]) &&
633 (((INT32
*)SearchGuid
)[2] == ((INT32
*)CheckGuid
)[2]) &&
634 (((INT32
*)SearchGuid
)[3] == ((INT32
*)CheckGuid
)[3])) {
635 DEBUG ((EFI_D_INFO
, "Notify: PPI Guid: %g, Peim notify entry point: %p\n",
637 NotifyDescriptor
->Notify
639 NotifyDescriptor
->Notify (
640 (EFI_PEI_SERVICES
**) GetPeiServicesTablePointer (),
642 (PrivateData
->PpiData
.PpiListPtrs
[Index2
].Ppi
)->Ppi