2 EFI PEI Core PPI services
4 Copyright (c) 2006 - 2010, 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 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.
50 @param FixupPositive TRUE if new Hob list is above the old Hob list.
56 IN PEI_CORE_INSTANCE
*PrivateData
,
57 IN UINTN OldCheckingBottom
,
58 IN UINTN OldCheckingTop
,
60 IN BOOLEAN FixupPositive
64 PEI_PPI_LIST_POINTERS
*PpiPointer
;
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
< OldCheckingTop
) &&
72 ((UINTN
)PpiPointer
->Raw
>= OldCheckingBottom
)) {
74 // Convert the pointer to the PEIM descriptor from the old HOB heap
75 // to the relocated HOB heap.
78 PpiPointer
->Raw
= (VOID
*) ((UINTN
)PpiPointer
->Raw
+ Fixup
);
80 PpiPointer
->Raw
= (VOID
*) ((UINTN
)PpiPointer
->Raw
- Fixup
);
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
< OldCheckingTop
) &&
89 ((UINTN
)PpiPointer
->Ppi
->Guid
>= OldCheckingBottom
)) {
91 // Convert the pointer to the GUID in the PPI or NOTIFY descriptor
92 // from the old HOB heap to the relocated HOB heap.
95 PpiPointer
->Ppi
->Guid
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Guid
+ Fixup
);
97 PpiPointer
->Ppi
->Guid
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Guid
- Fixup
);
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
< OldCheckingTop
&&
107 (UINTN
)PpiPointer
->Ppi
->Ppi
>= OldCheckingBottom
) {
109 // Convert the pointer to the PPI interface structure in the PPI descriptor
110 // from the old HOB heap to the relocated HOB heap.
113 PpiPointer
->Ppi
->Ppi
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Ppi
+ Fixup
);
115 PpiPointer
->Ppi
->Ppi
= (VOID
*) ((UINTN
)PpiPointer
->Ppi
->Ppi
- Fixup
);
125 This function installs an interface in the PEI PPI database by GUID.
126 The purpose of the service is to publish an interface that other parties
127 can use to call additional PEIMs.
129 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
130 @param PpiList Pointer to a list of PEI PPI Descriptors.
132 @retval EFI_SUCCESS if all PPIs in PpiList are successfully installed.
133 @retval EFI_INVALID_PARAMETER if PpiList is NULL pointer
134 if any PPI in PpiList is not valid
135 @retval EFI_OUT_OF_RESOURCES if there is no more memory resource to install PPI
141 IN CONST EFI_PEI_SERVICES
**PeiServices
,
142 IN CONST EFI_PEI_PPI_DESCRIPTOR
*PpiList
145 PEI_CORE_INSTANCE
*PrivateData
;
147 INTN LastCallbackInstall
;
150 if (PpiList
== NULL
) {
151 return EFI_INVALID_PARAMETER
;
154 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
156 Index
= PrivateData
->PpiData
.PpiListEnd
;
157 LastCallbackInstall
= Index
;
160 // This is loop installs all PPI descriptors in the PpiList. It is terminated
161 // by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last
162 // EFI_PEI_PPI_DESCRIPTOR in the list.
167 // Since PpiData is used for NotifyList and PpiList, max resource
168 // is reached if the Install reaches the NotifyList
169 // PcdPeiCoreMaxPpiSupported can be set to a larger value in DSC to satisfy more PPI requirement.
171 if (Index
== PrivateData
->PpiData
.NotifyListEnd
+ 1) {
172 return EFI_OUT_OF_RESOURCES
;
175 // Check if it is a valid PPI.
176 // If not, rollback list to exclude all in this list.
177 // Try to indicate which item failed.
179 if ((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_PPI
) == 0) {
180 PrivateData
->PpiData
.PpiListEnd
= LastCallbackInstall
;
181 DEBUG((EFI_D_ERROR
, "ERROR -> InstallPpi: %g %p\n", PpiList
->Guid
, PpiList
->Ppi
));
182 return EFI_INVALID_PARAMETER
;
185 DEBUG((EFI_D_INFO
, "Install PPI: %g\n", PpiList
->Guid
));
186 PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
= (EFI_PEI_PPI_DESCRIPTOR
*) PpiList
;
187 PrivateData
->PpiData
.PpiListEnd
++;
190 // Continue until the end of the PPI List.
192 if ((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) ==
193 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) {
201 // Dispatch any callback level notifies for newly installed PPIs.
205 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
207 PrivateData
->PpiData
.PpiListEnd
,
208 PrivateData
->PpiData
.DispatchListEnd
,
209 PrivateData
->PpiData
.NotifyListEnd
218 This function reinstalls an interface in the PEI PPI database by GUID.
219 The purpose of the service is to publish an interface that other parties can
220 use to replace an interface of the same name in the protocol database with a
223 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
224 @param OldPpi Pointer to the old PEI PPI Descriptors.
225 @param NewPpi Pointer to the new PEI PPI Descriptors.
227 @retval EFI_SUCCESS if the operation was successful
228 @retval EFI_INVALID_PARAMETER if OldPpi or NewPpi is NULL
229 @retval EFI_INVALID_PARAMETER if NewPpi is not valid
230 @retval EFI_NOT_FOUND if the PPI was not in the database
236 IN CONST EFI_PEI_SERVICES
**PeiServices
,
237 IN CONST EFI_PEI_PPI_DESCRIPTOR
*OldPpi
,
238 IN CONST EFI_PEI_PPI_DESCRIPTOR
*NewPpi
241 PEI_CORE_INSTANCE
*PrivateData
;
245 if ((OldPpi
== NULL
) || (NewPpi
== NULL
)) {
246 return EFI_INVALID_PARAMETER
;
249 if ((NewPpi
->Flags
& EFI_PEI_PPI_DESCRIPTOR_PPI
) == 0) {
250 return EFI_INVALID_PARAMETER
;
253 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
256 // Find the old PPI instance in the database. If we can not find it,
257 // return the EFI_NOT_FOUND error.
259 for (Index
= 0; Index
< PrivateData
->PpiData
.PpiListEnd
; Index
++) {
260 if (OldPpi
== PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
) {
264 if (Index
== PrivateData
->PpiData
.PpiListEnd
) {
265 return EFI_NOT_FOUND
;
269 // Remove the old PPI from the database, add the new one.
271 DEBUG((EFI_D_INFO
, "Reinstall PPI: %g\n", NewPpi
->Guid
));
272 ASSERT (Index
< (INTN
)(FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
)));
273 PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
= (EFI_PEI_PPI_DESCRIPTOR
*) NewPpi
;
276 // Dispatch any callback level notifies for the newly installed PPI.
280 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
283 PrivateData
->PpiData
.DispatchListEnd
,
284 PrivateData
->PpiData
.NotifyListEnd
293 Locate a given named PPI.
296 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
297 @param Guid Pointer to GUID of the PPI.
298 @param Instance Instance Number to discover.
299 @param PpiDescriptor Pointer to reference the found descriptor. If not NULL,
300 returns a pointer to the descriptor (includes flags, etc)
301 @param Ppi Pointer to reference the found PPI
303 @retval EFI_SUCCESS if the PPI is in the database
304 @retval EFI_NOT_FOUND if the PPI is not in the database
310 IN CONST EFI_PEI_SERVICES
**PeiServices
,
311 IN CONST EFI_GUID
*Guid
,
313 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
317 PEI_CORE_INSTANCE
*PrivateData
;
320 EFI_PEI_PPI_DESCRIPTOR
*TempPtr
;
323 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
326 // Search the data base for the matching instance of the GUIDed PPI.
328 for (Index
= 0; Index
< PrivateData
->PpiData
.PpiListEnd
; Index
++) {
329 TempPtr
= PrivateData
->PpiData
.PpiListPtrs
[Index
].Ppi
;
330 CheckGuid
= TempPtr
->Guid
;
333 // Don't use CompareGuid function here for performance reasons.
334 // Instead we compare the GUID as INT32 at a time and branch
335 // on the first failed comparison.
337 if ((((INT32
*)Guid
)[0] == ((INT32
*)CheckGuid
)[0]) &&
338 (((INT32
*)Guid
)[1] == ((INT32
*)CheckGuid
)[1]) &&
339 (((INT32
*)Guid
)[2] == ((INT32
*)CheckGuid
)[2]) &&
340 (((INT32
*)Guid
)[3] == ((INT32
*)CheckGuid
)[3])) {
343 if (PpiDescriptor
!= NULL
) {
344 *PpiDescriptor
= TempPtr
;
358 return EFI_NOT_FOUND
;
363 This function installs a notification service to be called back when a given
364 interface is installed or reinstalled. The purpose of the service is to publish
365 an interface that other parties can use to call additional PPIs that may materialize later.
367 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
368 @param NotifyList Pointer to list of Descriptors to notify upon.
370 @retval EFI_SUCCESS if successful
371 @retval EFI_OUT_OF_RESOURCES if no space in the database
372 @retval EFI_INVALID_PARAMETER if not a good decriptor
378 IN CONST EFI_PEI_SERVICES
**PeiServices
,
379 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyList
382 PEI_CORE_INSTANCE
*PrivateData
;
385 INTN LastCallbackNotify
;
386 EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyPtr
;
387 UINTN NotifyDispatchCount
;
390 NotifyDispatchCount
= 0;
392 if (NotifyList
== NULL
) {
393 return EFI_INVALID_PARAMETER
;
396 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
398 Index
= PrivateData
->PpiData
.NotifyListEnd
;
399 LastCallbackNotify
= Index
;
402 // This is loop installs all Notify descriptors in the NotifyList. It is
403 // terminated by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last
404 // EFI_PEI_NOTIFY_DESCRIPTOR in the list.
409 // Since PpiData is used for NotifyList and InstallList, max resource
410 // is reached if the Install reaches the PpiList
411 // PcdPeiCoreMaxPpiSupported can be set to a larger value in DSC to satisfy more Notify PPIs requirement.
413 if (Index
== PrivateData
->PpiData
.PpiListEnd
- 1) {
414 return EFI_OUT_OF_RESOURCES
;
418 // If some of the PPI data is invalid restore original Notify PPI database value
420 if ((NotifyList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES
) == 0) {
421 PrivateData
->PpiData
.NotifyListEnd
= LastCallbackNotify
;
422 DEBUG((EFI_D_ERROR
, "ERROR -> InstallNotify: %g %p\n", NotifyList
->Guid
, NotifyList
->Notify
));
423 return EFI_INVALID_PARAMETER
;
426 if ((NotifyList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
) != 0) {
427 NotifyDispatchCount
++;
430 PrivateData
->PpiData
.PpiListPtrs
[Index
].Notify
= (EFI_PEI_NOTIFY_DESCRIPTOR
*) NotifyList
;
432 PrivateData
->PpiData
.NotifyListEnd
--;
433 DEBUG((EFI_D_INFO
, "Register PPI Notify: %g\n", NotifyList
->Guid
));
434 if ((NotifyList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) ==
435 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) {
439 // Go the next descriptor. Remember the NotifyList moves down.
446 // If there is Dispatch Notify PPI installed put them on the bottom
448 if (NotifyDispatchCount
> 0) {
449 for (NotifyIndex
= LastCallbackNotify
; NotifyIndex
> PrivateData
->PpiData
.NotifyListEnd
; NotifyIndex
--) {
450 if ((PrivateData
->PpiData
.PpiListPtrs
[NotifyIndex
].Notify
->Flags
& EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
) != 0) {
451 NotifyPtr
= PrivateData
->PpiData
.PpiListPtrs
[NotifyIndex
].Notify
;
453 for (Index
= NotifyIndex
; Index
< PrivateData
->PpiData
.DispatchListEnd
; Index
++){
454 PrivateData
->PpiData
.PpiListPtrs
[Index
].Notify
= PrivateData
->PpiData
.PpiListPtrs
[Index
+ 1].Notify
;
456 PrivateData
->PpiData
.PpiListPtrs
[Index
].Notify
= NotifyPtr
;
457 PrivateData
->PpiData
.DispatchListEnd
--;
461 LastCallbackNotify
-= NotifyDispatchCount
;
465 // Dispatch any callback level notifies for all previously installed PPIs.
469 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
471 PrivateData
->PpiData
.PpiListEnd
,
473 PrivateData
->PpiData
.NotifyListEnd
482 Process the Notify List at dispatch level.
484 @param PrivateData PeiCore's private data structure.
489 IN PEI_CORE_INSTANCE
*PrivateData
496 // Check if the PEIM that was just dispatched resulted in any
497 // Notifies getting installed. If so, go process any dispatch
498 // level Notifies that match the previouly installed PPIs.
499 // Use "while" instead of "if" since DispatchNotify can modify
500 // DispatchListEnd (with NotifyPpi) so we have to iterate until the same.
502 while (PrivateData
->PpiData
.LastDispatchedNotify
!= PrivateData
->PpiData
.DispatchListEnd
) {
503 TempValue
= PrivateData
->PpiData
.DispatchListEnd
;
506 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
,
508 PrivateData
->PpiData
.LastDispatchedInstall
,
509 PrivateData
->PpiData
.LastDispatchedNotify
,
510 PrivateData
->PpiData
.DispatchListEnd
512 PrivateData
->PpiData
.LastDispatchedNotify
= TempValue
;
517 // Check if the PEIM that was just dispatched resulted in any
518 // PPIs getting installed. If so, go process any dispatch
519 // level Notifies that match the installed PPIs.
520 // Use "while" instead of "if" since DispatchNotify can modify
521 // PpiListEnd (with InstallPpi) so we have to iterate until the same.
523 while (PrivateData
->PpiData
.LastDispatchedInstall
!= PrivateData
->PpiData
.PpiListEnd
) {
524 TempValue
= PrivateData
->PpiData
.PpiListEnd
;
527 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH
,
528 PrivateData
->PpiData
.LastDispatchedInstall
,
529 PrivateData
->PpiData
.PpiListEnd
,
530 FixedPcdGet32 (PcdPeiCoreMaxPpiSupported
)-1,
531 PrivateData
->PpiData
.DispatchListEnd
533 PrivateData
->PpiData
.LastDispatchedInstall
= TempValue
;
536 if (PrivateData
->PpiData
.LastDispatchedNotify
== PrivateData
->PpiData
.DispatchListEnd
) {
545 Dispatch notifications.
547 @param PrivateData PeiCore's private data structure
548 @param NotifyType Type of notify to fire.
549 @param InstallStartIndex Install Beginning index.
550 @param InstallStopIndex Install Ending index.
551 @param NotifyStartIndex Notify Beginning index.
552 @param NotifyStopIndex Notify Ending index.
557 IN PEI_CORE_INSTANCE
*PrivateData
,
559 IN INTN InstallStartIndex
,
560 IN INTN InstallStopIndex
,
561 IN INTN NotifyStartIndex
,
562 IN INTN NotifyStopIndex
567 EFI_GUID
*SearchGuid
;
569 EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
;
572 // Remember that Installs moves up and Notifies moves down.
574 for (Index1
= NotifyStartIndex
; Index1
> NotifyStopIndex
; Index1
--) {
575 NotifyDescriptor
= PrivateData
->PpiData
.PpiListPtrs
[Index1
].Notify
;
577 CheckGuid
= NotifyDescriptor
->Guid
;
579 for (Index2
= InstallStartIndex
; Index2
< InstallStopIndex
; Index2
++) {
580 SearchGuid
= PrivateData
->PpiData
.PpiListPtrs
[Index2
].Ppi
->Guid
;
582 // Don't use CompareGuid function here for performance reasons.
583 // Instead we compare the GUID as INT32 at a time and branch
584 // on the first failed comparison.
586 if ((((INT32
*)SearchGuid
)[0] == ((INT32
*)CheckGuid
)[0]) &&
587 (((INT32
*)SearchGuid
)[1] == ((INT32
*)CheckGuid
)[1]) &&
588 (((INT32
*)SearchGuid
)[2] == ((INT32
*)CheckGuid
)[2]) &&
589 (((INT32
*)SearchGuid
)[3] == ((INT32
*)CheckGuid
)[3])) {
590 DEBUG ((EFI_D_INFO
, "Notify: PPI Guid: %g, Peim notify entry point: %p\n",
592 NotifyDescriptor
->Notify
594 NotifyDescriptor
->Notify (
595 (EFI_PEI_SERVICES
**) GetPeiServicesTablePointer (),
597 (PrivateData
->PpiData
.PpiListPtrs
[Index2
].Ppi
)->Ppi