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
);
135 This function installs an interface in the PEI PPI database by GUID.
136 The purpose of the service is to publish an interface that other parties
137 can use to call additional PEIMs.
139 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
140 @param PpiList Pointer to a list of PEI PPI Descriptors.
142 @retval EFI_SUCCESS if all PPIs in PpiList are successfully installed.
143 @retval EFI_INVALID_PARAMETER if PpiList is NULL pointer
144 if any PPI in PpiList is not valid
145 @retval EFI_OUT_OF_RESOURCES if there is no more memory resource to install PPI
151 IN CONST EFI_PEI_SERVICES
**PeiServices
,
152 IN CONST EFI_PEI_PPI_DESCRIPTOR
*PpiList
155 PEI_CORE_INSTANCE
*PrivateData
;
157 INTN LastCallbackInstall
;
160 if (PpiList
== NULL
) {
161 return EFI_INVALID_PARAMETER
;
164 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
166 Index
= PrivateData
->PpiData
.PpiListEnd
;
167 LastCallbackInstall
= Index
;
170 // This is loop installs all PPI descriptors in the PpiList. It is terminated
171 // by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last
172 // EFI_PEI_PPI_DESCRIPTOR in the list.
177 // Since PpiData is used for NotifyList and PpiList, max resource
178 // is reached if the Install reaches the NotifyList
179 // PcdPeiCoreMaxPpiSupported can be set to a larger value in DSC to satisfy more PPI requirement.
181 if (Index
== PrivateData
->PpiData
.NotifyListEnd
+ 1) {
182 return EFI_OUT_OF_RESOURCES
;
185 // Check if it is a valid PPI.
186 // If not, rollback list to exclude all in this list.
187 // Try to indicate which item failed.
189 if ((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_PPI
) == 0) {
190 PrivateData
->PpiData
.PpiListEnd
= LastCallbackInstall
;
191 DEBUG((EFI_D_ERROR
, "ERROR -> InstallPpi: %g %p\n", PpiList
->Guid
, PpiList
->Ppi
));
192 return EFI_INVALID_PARAMETER
;
195 DEBUG((EFI_D_INFO
, "Install PPI: %g\n", PpiList
->Guid
));
196 PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
= (EFI_PEI_PPI_DESCRIPTOR
*) PpiList
;
197 PrivateData
->PpiData
.PpiListEnd
++;
200 // Continue until the end of the PPI List.
202 if ((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) ==
203 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) {
211 // Dispatch any callback level notifies for newly installed PPIs.
215 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
217 PrivateData
->PpiData
.PpiListEnd
,
218 PrivateData
->PpiData
.DispatchListEnd
,
219 PrivateData
->PpiData
.NotifyListEnd
228 This function reinstalls an interface in the PEI PPI database by GUID.
229 The purpose of the service is to publish an interface that other parties can
230 use to replace an interface of the same name in the protocol database with a
233 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
234 @param OldPpi Pointer to the old PEI PPI Descriptors.
235 @param NewPpi Pointer to the new PEI PPI Descriptors.
237 @retval EFI_SUCCESS if the operation was successful
238 @retval EFI_INVALID_PARAMETER if OldPpi or NewPpi is NULL
239 @retval EFI_INVALID_PARAMETER if NewPpi is not valid
240 @retval EFI_NOT_FOUND if the PPI was not in the database
246 IN CONST EFI_PEI_SERVICES
**PeiServices
,
247 IN CONST EFI_PEI_PPI_DESCRIPTOR
*OldPpi
,
248 IN CONST EFI_PEI_PPI_DESCRIPTOR
*NewPpi
251 PEI_CORE_INSTANCE
*PrivateData
;
255 if ((OldPpi
== NULL
) || (NewPpi
== NULL
)) {
256 return EFI_INVALID_PARAMETER
;
259 if ((NewPpi
->Flags
& EFI_PEI_PPI_DESCRIPTOR_PPI
) == 0) {
260 return EFI_INVALID_PARAMETER
;
263 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
266 // Find the old PPI instance in the database. If we can not find it,
267 // return the EFI_NOT_FOUND error.
269 for (Index
= 0; Index
< PrivateData
->PpiData
.PpiListEnd
; Index
++) {
270 if (OldPpi
== PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
) {
274 if (Index
== PrivateData
->PpiData
.PpiListEnd
) {
275 return EFI_NOT_FOUND
;
279 // Remove the old PPI from the database, add the new one.
281 DEBUG((EFI_D_INFO
, "Reinstall PPI: %g\n", NewPpi
->Guid
));
282 ASSERT (Index
< (INTN
)(FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
)));
283 PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
= (EFI_PEI_PPI_DESCRIPTOR
*) NewPpi
;
286 // Dispatch any callback level notifies for the newly installed PPI.
290 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
293 PrivateData
->PpiData
.DispatchListEnd
,
294 PrivateData
->PpiData
.NotifyListEnd
303 Locate a given named PPI.
306 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
307 @param Guid Pointer to GUID of the PPI.
308 @param Instance Instance Number to discover.
309 @param PpiDescriptor Pointer to reference the found descriptor. If not NULL,
310 returns a pointer to the descriptor (includes flags, etc)
311 @param Ppi Pointer to reference the found PPI
313 @retval EFI_SUCCESS if the PPI is in the database
314 @retval EFI_NOT_FOUND if the PPI is not in the database
320 IN CONST EFI_PEI_SERVICES
**PeiServices
,
321 IN CONST EFI_GUID
*Guid
,
323 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
327 PEI_CORE_INSTANCE
*PrivateData
;
330 EFI_PEI_PPI_DESCRIPTOR
*TempPtr
;
333 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
336 // Search the data base for the matching instance of the GUIDed PPI.
338 for (Index
= 0; Index
< PrivateData
->PpiData
.PpiListEnd
; Index
++) {
339 TempPtr
= PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
;
340 CheckGuid
= TempPtr
->Guid
;
343 // Don't use CompareGuid function here for performance reasons.
344 // Instead we compare the GUID as INT32 at a time and branch
345 // on the first failed comparison.
347 if ((((INT32
*)Guid
)[0] == ((INT32
*)CheckGuid
)[0]) &&
348 (((INT32
*)Guid
)[1] == ((INT32
*)CheckGuid
)[1]) &&
349 (((INT32
*)Guid
)[2] == ((INT32
*)CheckGuid
)[2]) &&
350 (((INT32
*)Guid
)[3] == ((INT32
*)CheckGuid
)[3])) {
353 if (PpiDescriptor
!= NULL
) {
354 *PpiDescriptor
= TempPtr
;
368 return EFI_NOT_FOUND
;
373 This function installs a notification service to be called back when a given
374 interface is installed or reinstalled. The purpose of the service is to publish
375 an interface that other parties can use to call additional PPIs that may materialize later.
377 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
378 @param NotifyList Pointer to list of Descriptors to notify upon.
380 @retval EFI_SUCCESS if successful
381 @retval EFI_OUT_OF_RESOURCES if no space in the database
382 @retval EFI_INVALID_PARAMETER if not a good decriptor
388 IN CONST EFI_PEI_SERVICES
**PeiServices
,
389 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyList
392 PEI_CORE_INSTANCE
*PrivateData
;
395 INTN LastCallbackNotify
;
396 EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyPtr
;
397 UINTN NotifyDispatchCount
;
400 NotifyDispatchCount
= 0;
402 if (NotifyList
== NULL
) {
403 return EFI_INVALID_PARAMETER
;
406 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
408 Index
= PrivateData
->PpiData
.NotifyListEnd
;
409 LastCallbackNotify
= Index
;
412 // This is loop installs all Notify descriptors in the NotifyList. It is
413 // terminated by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last
414 // EFI_PEI_NOTIFY_DESCRIPTOR in the list.
419 // Since PpiData is used for NotifyList and InstallList, max resource
420 // is reached if the Install reaches the PpiList
421 // PcdPeiCoreMaxPpiSupported can be set to a larger value in DSC to satisfy more Notify PPIs requirement.
423 if (Index
== PrivateData
->PpiData
.PpiListEnd
- 1) {
424 return EFI_OUT_OF_RESOURCES
;
428 // If some of the PPI data is invalid restore original Notify PPI database value
430 if ((NotifyList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES
) == 0) {
431 PrivateData
->PpiData
.NotifyListEnd
= LastCallbackNotify
;
432 DEBUG((EFI_D_ERROR
, "ERROR -> InstallNotify: %g %p\n", NotifyList
->Guid
, NotifyList
->Notify
));
433 return EFI_INVALID_PARAMETER
;
436 if ((NotifyList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
) != 0) {
437 NotifyDispatchCount
++;
440 PrivateData
->PpiData
.PpiListPtrs
[Index
].Notify
= (EFI_PEI_NOTIFY_DESCRIPTOR
*) NotifyList
;
442 PrivateData
->PpiData
.NotifyListEnd
--;
443 DEBUG((EFI_D_INFO
, "Register PPI Notify: %g\n", NotifyList
->Guid
));
444 if ((NotifyList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) ==
445 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) {
449 // Go the next descriptor. Remember the NotifyList moves down.
456 // If there is Dispatch Notify PPI installed put them on the bottom
458 if (NotifyDispatchCount
> 0) {
459 for (NotifyIndex
= LastCallbackNotify
; NotifyIndex
> PrivateData
->PpiData
.NotifyListEnd
; NotifyIndex
--) {
460 if ((PrivateData
->PpiData
.PpiListPtrs
[NotifyIndex
].Notify
->Flags
& EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
) != 0) {
461 NotifyPtr
= PrivateData
->PpiData
.PpiListPtrs
[NotifyIndex
].Notify
;
463 for (Index
= NotifyIndex
; Index
< PrivateData
->PpiData
.DispatchListEnd
; Index
++){
464 PrivateData
->PpiData
.PpiListPtrs
[Index
].Notify
= PrivateData
->PpiData
.PpiListPtrs
[Index
+ 1].Notify
;
466 PrivateData
->PpiData
.PpiListPtrs
[Index
].Notify
= NotifyPtr
;
467 PrivateData
->PpiData
.DispatchListEnd
--;
471 LastCallbackNotify
-= NotifyDispatchCount
;
475 // Dispatch any callback level notifies for all previously installed PPIs.
479 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
481 PrivateData
->PpiData
.PpiListEnd
,
483 PrivateData
->PpiData
.NotifyListEnd
492 Process the Notify List at dispatch level.
494 @param PrivateData PeiCore's private data structure.
499 IN PEI_CORE_INSTANCE
*PrivateData
506 // Check if the PEIM that was just dispatched resulted in any
507 // Notifies getting installed. If so, go process any dispatch
508 // level Notifies that match the previouly installed PPIs.
509 // Use "while" instead of "if" since DispatchNotify can modify
510 // DispatchListEnd (with NotifyPpi) so we have to iterate until the same.
512 while (PrivateData
->PpiData
.LastDispatchedNotify
!= PrivateData
->PpiData
.DispatchListEnd
) {
513 TempValue
= PrivateData
->PpiData
.DispatchListEnd
;
516 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
,
518 PrivateData
->PpiData
.LastDispatchedInstall
,
519 PrivateData
->PpiData
.LastDispatchedNotify
,
520 PrivateData
->PpiData
.DispatchListEnd
522 PrivateData
->PpiData
.LastDispatchedNotify
= TempValue
;
527 // Check if the PEIM that was just dispatched resulted in any
528 // PPIs getting installed. If so, go process any dispatch
529 // level Notifies that match the installed PPIs.
530 // Use "while" instead of "if" since DispatchNotify can modify
531 // PpiListEnd (with InstallPpi) so we have to iterate until the same.
533 while (PrivateData
->PpiData
.LastDispatchedInstall
!= PrivateData
->PpiData
.PpiListEnd
) {
534 TempValue
= PrivateData
->PpiData
.PpiListEnd
;
537 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
,
538 PrivateData
->PpiData
.LastDispatchedInstall
,
539 PrivateData
->PpiData
.PpiListEnd
,
540 FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
)-1,
541 PrivateData
->PpiData
.DispatchListEnd
543 PrivateData
->PpiData
.LastDispatchedInstall
= TempValue
;
546 if (PrivateData
->PpiData
.LastDispatchedNotify
== PrivateData
->PpiData
.DispatchListEnd
) {
555 Dispatch notifications.
557 @param PrivateData PeiCore's private data structure
558 @param NotifyType Type of notify to fire.
559 @param InstallStartIndex Install Beginning index.
560 @param InstallStopIndex Install Ending index.
561 @param NotifyStartIndex Notify Beginning index.
562 @param NotifyStopIndex Notify Ending index.
567 IN PEI_CORE_INSTANCE
*PrivateData
,
569 IN INTN InstallStartIndex
,
570 IN INTN InstallStopIndex
,
571 IN INTN NotifyStartIndex
,
572 IN INTN NotifyStopIndex
577 EFI_GUID
*SearchGuid
;
579 EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
;
582 // Remember that Installs moves up and Notifies moves down.
584 for (Index1
= NotifyStartIndex
; Index1
> NotifyStopIndex
; Index1
--) {
585 NotifyDescriptor
= PrivateData
->PpiData
.PpiListPtrs
[Index1
].Notify
;
587 CheckGuid
= NotifyDescriptor
->Guid
;
589 for (Index2
= InstallStartIndex
; Index2
< InstallStopIndex
; Index2
++) {
590 SearchGuid
= PrivateData
->PpiData
.PpiListPtrs
[Index2
].Ppi
->Guid
;
592 // Don't use CompareGuid function here for performance reasons.
593 // Instead we compare the GUID as INT32 at a time and branch
594 // on the first failed comparison.
596 if ((((INT32
*)SearchGuid
)[0] == ((INT32
*)CheckGuid
)[0]) &&
597 (((INT32
*)SearchGuid
)[1] == ((INT32
*)CheckGuid
)[1]) &&
598 (((INT32
*)SearchGuid
)[2] == ((INT32
*)CheckGuid
)[2]) &&
599 (((INT32
*)SearchGuid
)[3] == ((INT32
*)CheckGuid
)[3])) {
600 DEBUG ((EFI_D_INFO
, "Notify: PPI Guid: %g, Peim notify entry point: %p\n",
602 NotifyDescriptor
->Notify
604 NotifyDescriptor
->Notify (
605 (EFI_PEI_SERVICES
**) GetPeiServicesTablePointer (),
607 (PrivateData
->PpiData
.PpiListPtrs
[Index2
].Ppi
)->Ppi