]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Pei/Ppi/Ppi.c
MdeModulePkg PeiCore: Remove the using of PcdPeiCoreMaxPpiSupported
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Ppi / Ppi.c
1 /** @file
2 EFI PEI Core PPI services
3
4 Copyright (c) 2006 - 2018, 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
9
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.
12
13 **/
14
15 #include "PeiMain.h"
16
17 /**
18
19 Migrate Pointer from the temporary memory to PEI installed memory.
20
21 @param Pointer Pointer to the Pointer needs to be converted.
22 @param TempBottom Base of old temporary memory
23 @param TempTop Top of old temporary memory
24 @param Offset Offset of new memory to old temporary memory.
25 @param OffsetPositive Positive flag of Offset value.
26
27 **/
28 VOID
29 ConvertPointer (
30 IN OUT VOID **Pointer,
31 IN UINTN TempBottom,
32 IN UINTN TempTop,
33 IN UINTN Offset,
34 IN BOOLEAN OffsetPositive
35 )
36 {
37 if (((UINTN) *Pointer < TempTop) &&
38 ((UINTN) *Pointer >= TempBottom)) {
39 if (OffsetPositive) {
40 *Pointer = (VOID *) ((UINTN) *Pointer + Offset);
41 } else {
42 *Pointer = (VOID *) ((UINTN) *Pointer - Offset);
43 }
44 }
45 }
46
47 /**
48
49 Migrate Pointer in ranges of the temporary memory to PEI installed memory.
50
51 @param SecCoreData Points to a data structure containing SEC to PEI handoff data, such as the size
52 and location of temporary RAM, the stack location and the BFV location.
53 @param PrivateData Pointer to PeiCore's private data structure.
54 @param Pointer Pointer to the Pointer needs to be converted.
55
56 **/
57 VOID
58 ConvertPointerInRanges (
59 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
60 IN PEI_CORE_INSTANCE *PrivateData,
61 IN OUT VOID **Pointer
62 )
63 {
64 UINT8 IndexHole;
65
66 if (PrivateData->MemoryPages.Size != 0) {
67 //
68 // Convert PPI pointer in old memory pages
69 // It needs to be done before Convert PPI pointer in old Heap
70 //
71 ConvertPointer (
72 Pointer,
73 (UINTN)PrivateData->MemoryPages.Base,
74 (UINTN)PrivateData->MemoryPages.Base + PrivateData->MemoryPages.Size,
75 PrivateData->MemoryPages.Offset,
76 PrivateData->MemoryPages.OffsetPositive
77 );
78 }
79
80 //
81 // Convert PPI pointer in old Heap
82 //
83 ConvertPointer (
84 Pointer,
85 (UINTN)SecCoreData->PeiTemporaryRamBase,
86 (UINTN)SecCoreData->PeiTemporaryRamBase + SecCoreData->PeiTemporaryRamSize,
87 PrivateData->HeapOffset,
88 PrivateData->HeapOffsetPositive
89 );
90
91 //
92 // Convert PPI pointer in old Stack
93 //
94 ConvertPointer (
95 Pointer,
96 (UINTN)SecCoreData->StackBase,
97 (UINTN)SecCoreData->StackBase + SecCoreData->StackSize,
98 PrivateData->StackOffset,
99 PrivateData->StackOffsetPositive
100 );
101
102 //
103 // Convert PPI pointer in old TempRam Hole
104 //
105 for (IndexHole = 0; IndexHole < HOLE_MAX_NUMBER; IndexHole ++) {
106 if (PrivateData->HoleData[IndexHole].Size == 0) {
107 continue;
108 }
109
110 ConvertPointer (
111 Pointer,
112 (UINTN)PrivateData->HoleData[IndexHole].Base,
113 (UINTN)PrivateData->HoleData[IndexHole].Base + PrivateData->HoleData[IndexHole].Size,
114 PrivateData->HoleData[IndexHole].Offset,
115 PrivateData->HoleData[IndexHole].OffsetPositive
116 );
117 }
118 }
119
120 /**
121
122 Migrate Single PPI Pointer from the temporary memory to PEI installed memory.
123
124 @param SecCoreData Points to a data structure containing SEC to PEI handoff data, such as the size
125 and location of temporary RAM, the stack location and the BFV location.
126 @param PrivateData Pointer to PeiCore's private data structure.
127 @param PpiPointer Pointer to Ppi
128
129 **/
130 VOID
131 ConvertSinglePpiPointer (
132 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
133 IN PEI_CORE_INSTANCE *PrivateData,
134 IN PEI_PPI_LIST_POINTERS *PpiPointer
135 )
136 {
137 //
138 // 1. Convert the pointer to the PPI descriptor from the old TempRam
139 // to the relocated physical memory.
140 // It (for the pointer to the PPI descriptor) needs to be done before 2 (for
141 // the pointer to the GUID) and 3 (for the pointer to the PPI interface structure).
142 //
143 ConvertPointerInRanges (SecCoreData, PrivateData, &PpiPointer->Raw);
144 //
145 // 2. Convert the pointer to the GUID in the PPI or NOTIFY descriptor
146 // from the old TempRam to the relocated physical memory.
147 //
148 ConvertPointerInRanges (SecCoreData, PrivateData, (VOID **) &PpiPointer->Ppi->Guid);
149 //
150 // 3. Convert the pointer to the PPI interface structure in the PPI descriptor
151 // from the old TempRam to the relocated physical memory.
152 //
153 ConvertPointerInRanges (SecCoreData, PrivateData, (VOID **) &PpiPointer->Ppi->Ppi);
154 }
155
156 /**
157
158 Migrate PPI Pointers from the temporary memory to PEI installed memory.
159
160 @param SecCoreData Points to a data structure containing SEC to PEI handoff data, such as the size
161 and location of temporary RAM, the stack location and the BFV location.
162 @param PrivateData Pointer to PeiCore's private data structure.
163
164 **/
165 VOID
166 ConvertPpiPointers (
167 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
168 IN PEI_CORE_INSTANCE *PrivateData
169 )
170 {
171 UINT8 Index;
172
173 //
174 // Convert normal PPIs.
175 //
176 for (Index = 0; Index < PrivateData->PpiData.PpiList.CurrentCount; Index++) {
177 ConvertSinglePpiPointer (
178 SecCoreData,
179 PrivateData,
180 &PrivateData->PpiData.PpiList.PpiPtrs[Index]
181 );
182 }
183
184 //
185 // Convert Callback Notification PPIs.
186 //
187 for (Index = 0; Index < PrivateData->PpiData.CallbackNotifyList.CurrentCount; Index++) {
188 ConvertSinglePpiPointer (
189 SecCoreData,
190 PrivateData,
191 &PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index]
192 );
193 }
194
195 //
196 // Convert Dispatch Notification PPIs.
197 //
198 for (Index = 0; Index < PrivateData->PpiData.DispatchNotifyList.CurrentCount; Index++) {
199 ConvertSinglePpiPointer (
200 SecCoreData,
201 PrivateData,
202 &PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index]
203 );
204 }
205 }
206
207 /**
208
209 This function installs an interface in the PEI PPI database by GUID.
210 The purpose of the service is to publish an interface that other parties
211 can use to call additional PEIMs.
212
213 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
214 @param PpiList Pointer to a list of PEI PPI Descriptors.
215 @param Single TRUE if only single entry in the PpiList.
216 FALSE if the PpiList is ended with an entry which has the
217 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST flag set in its Flags field.
218
219 @retval EFI_SUCCESS if all PPIs in PpiList are successfully installed.
220 @retval EFI_INVALID_PARAMETER if PpiList is NULL pointer
221 if any PPI in PpiList is not valid
222 @retval EFI_OUT_OF_RESOURCES if there is no more memory resource to install PPI
223
224 **/
225 EFI_STATUS
226 InternalPeiInstallPpi (
227 IN CONST EFI_PEI_SERVICES **PeiServices,
228 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
229 IN BOOLEAN Single
230 )
231 {
232 PEI_CORE_INSTANCE *PrivateData;
233 PEI_PPI_LIST *PpiListPointer;
234 UINTN Index;
235 UINTN LastCount;
236 VOID *TempPtr;
237
238 if (PpiList == NULL) {
239 return EFI_INVALID_PARAMETER;
240 }
241
242 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
243
244 PpiListPointer = &PrivateData->PpiData.PpiList;
245 Index = PpiListPointer->CurrentCount;
246 LastCount = Index;
247
248 //
249 // This is loop installs all PPI descriptors in the PpiList. It is terminated
250 // by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last
251 // EFI_PEI_PPI_DESCRIPTOR in the list.
252 //
253
254 for (;;) {
255 //
256 // Check if it is a valid PPI.
257 // If not, rollback list to exclude all in this list.
258 // Try to indicate which item failed.
259 //
260 if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_PPI) == 0) {
261 PpiListPointer->CurrentCount = LastCount;
262 DEBUG((EFI_D_ERROR, "ERROR -> InstallPpi: %g %p\n", PpiList->Guid, PpiList->Ppi));
263 return EFI_INVALID_PARAMETER;
264 }
265
266 if (Index >= PpiListPointer->MaxCount) {
267 //
268 // Run out of room, grow the buffer.
269 //
270 TempPtr = AllocateZeroPool (
271 sizeof (PEI_PPI_LIST_POINTERS) * (PpiListPointer->MaxCount + PPI_GROWTH_STEP)
272 );
273 ASSERT (TempPtr != NULL);
274 CopyMem (
275 TempPtr,
276 PpiListPointer->PpiPtrs,
277 sizeof (PEI_PPI_LIST_POINTERS) * PpiListPointer->MaxCount
278 );
279 PpiListPointer->PpiPtrs = TempPtr;
280 PpiListPointer->MaxCount = PpiListPointer->MaxCount + PPI_GROWTH_STEP;
281 }
282
283 DEBUG((EFI_D_INFO, "Install PPI: %g\n", PpiList->Guid));
284 PpiListPointer->PpiPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR *) PpiList;
285 Index++;
286 PpiListPointer->CurrentCount++;
287
288 if (Single) {
289 //
290 // Only single entry in the PpiList.
291 //
292 break;
293 } else if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==
294 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {
295 //
296 // Continue until the end of the PPI List.
297 //
298 break;
299 }
300 //
301 // Go to the next descriptor.
302 //
303 PpiList++;
304 }
305
306 //
307 // Process any callback level notifies for newly installed PPIs.
308 //
309 ProcessNotify (
310 PrivateData,
311 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
312 LastCount,
313 PpiListPointer->CurrentCount,
314 0,
315 PrivateData->PpiData.CallbackNotifyList.CurrentCount
316 );
317
318 return EFI_SUCCESS;
319 }
320
321 /**
322
323 This function installs an interface in the PEI PPI database by GUID.
324 The purpose of the service is to publish an interface that other parties
325 can use to call additional PEIMs.
326
327 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
328 @param PpiList Pointer to a list of PEI PPI Descriptors.
329
330 @retval EFI_SUCCESS if all PPIs in PpiList are successfully installed.
331 @retval EFI_INVALID_PARAMETER if PpiList is NULL pointer
332 if any PPI in PpiList is not valid
333 @retval EFI_OUT_OF_RESOURCES if there is no more memory resource to install PPI
334
335 **/
336 EFI_STATUS
337 EFIAPI
338 PeiInstallPpi (
339 IN CONST EFI_PEI_SERVICES **PeiServices,
340 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList
341 )
342 {
343 return InternalPeiInstallPpi (PeiServices, PpiList, FALSE);
344 }
345
346 /**
347
348 This function reinstalls an interface in the PEI PPI database by GUID.
349 The purpose of the service is to publish an interface that other parties can
350 use to replace an interface of the same name in the protocol database with a
351 different interface.
352
353 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
354 @param OldPpi Pointer to the old PEI PPI Descriptors.
355 @param NewPpi Pointer to the new PEI PPI Descriptors.
356
357 @retval EFI_SUCCESS if the operation was successful
358 @retval EFI_INVALID_PARAMETER if OldPpi or NewPpi is NULL
359 @retval EFI_INVALID_PARAMETER if NewPpi is not valid
360 @retval EFI_NOT_FOUND if the PPI was not in the database
361
362 **/
363 EFI_STATUS
364 EFIAPI
365 PeiReInstallPpi (
366 IN CONST EFI_PEI_SERVICES **PeiServices,
367 IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi,
368 IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi
369 )
370 {
371 PEI_CORE_INSTANCE *PrivateData;
372 UINTN Index;
373
374
375 if ((OldPpi == NULL) || (NewPpi == NULL)) {
376 return EFI_INVALID_PARAMETER;
377 }
378
379 if ((NewPpi->Flags & EFI_PEI_PPI_DESCRIPTOR_PPI) == 0) {
380 return EFI_INVALID_PARAMETER;
381 }
382
383 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
384
385 //
386 // Find the old PPI instance in the database. If we can not find it,
387 // return the EFI_NOT_FOUND error.
388 //
389 for (Index = 0; Index < PrivateData->PpiData.PpiList.CurrentCount; Index++) {
390 if (OldPpi == PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi) {
391 break;
392 }
393 }
394 if (Index == PrivateData->PpiData.PpiList.CurrentCount) {
395 return EFI_NOT_FOUND;
396 }
397
398 //
399 // Replace the old PPI with the new one.
400 //
401 DEBUG((EFI_D_INFO, "Reinstall PPI: %g\n", NewPpi->Guid));
402 PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR *) NewPpi;
403
404 //
405 // Process any callback level notifies for the newly installed PPI.
406 //
407 ProcessNotify (
408 PrivateData,
409 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
410 Index,
411 Index+1,
412 0,
413 PrivateData->PpiData.CallbackNotifyList.CurrentCount
414 );
415
416 return EFI_SUCCESS;
417 }
418
419 /**
420
421 Locate a given named PPI.
422
423
424 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
425 @param Guid Pointer to GUID of the PPI.
426 @param Instance Instance Number to discover.
427 @param PpiDescriptor Pointer to reference the found descriptor. If not NULL,
428 returns a pointer to the descriptor (includes flags, etc)
429 @param Ppi Pointer to reference the found PPI
430
431 @retval EFI_SUCCESS if the PPI is in the database
432 @retval EFI_NOT_FOUND if the PPI is not in the database
433
434 **/
435 EFI_STATUS
436 EFIAPI
437 PeiLocatePpi (
438 IN CONST EFI_PEI_SERVICES **PeiServices,
439 IN CONST EFI_GUID *Guid,
440 IN UINTN Instance,
441 IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
442 IN OUT VOID **Ppi
443 )
444 {
445 PEI_CORE_INSTANCE *PrivateData;
446 UINTN Index;
447 EFI_GUID *CheckGuid;
448 EFI_PEI_PPI_DESCRIPTOR *TempPtr;
449
450
451 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
452
453 //
454 // Search the data base for the matching instance of the GUIDed PPI.
455 //
456 for (Index = 0; Index < PrivateData->PpiData.PpiList.CurrentCount; Index++) {
457 TempPtr = PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi;
458 CheckGuid = TempPtr->Guid;
459
460 //
461 // Don't use CompareGuid function here for performance reasons.
462 // Instead we compare the GUID as INT32 at a time and branch
463 // on the first failed comparison.
464 //
465 if ((((INT32 *)Guid)[0] == ((INT32 *)CheckGuid)[0]) &&
466 (((INT32 *)Guid)[1] == ((INT32 *)CheckGuid)[1]) &&
467 (((INT32 *)Guid)[2] == ((INT32 *)CheckGuid)[2]) &&
468 (((INT32 *)Guid)[3] == ((INT32 *)CheckGuid)[3])) {
469 if (Instance == 0) {
470
471 if (PpiDescriptor != NULL) {
472 *PpiDescriptor = TempPtr;
473 }
474
475 if (Ppi != NULL) {
476 *Ppi = TempPtr->Ppi;
477 }
478
479
480 return EFI_SUCCESS;
481 }
482 Instance--;
483 }
484 }
485
486 return EFI_NOT_FOUND;
487 }
488
489 /**
490
491 This function installs a notification service to be called back when a given
492 interface is installed or reinstalled. The purpose of the service is to publish
493 an interface that other parties can use to call additional PPIs that may materialize later.
494
495 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
496 @param NotifyList Pointer to list of Descriptors to notify upon.
497 @param Single TRUE if only single entry in the NotifyList.
498 FALSE if the NotifyList is ended with an entry which has the
499 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST flag set in its Flags field.
500
501 @retval EFI_SUCCESS if successful
502 @retval EFI_OUT_OF_RESOURCES if no space in the database
503 @retval EFI_INVALID_PARAMETER if not a good descriptor
504
505 **/
506 EFI_STATUS
507 InternalPeiNotifyPpi (
508 IN CONST EFI_PEI_SERVICES **PeiServices,
509 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList,
510 IN BOOLEAN Single
511 )
512 {
513 PEI_CORE_INSTANCE *PrivateData;
514 PEI_CALLBACK_NOTIFY_LIST *CallbackNotifyListPointer;
515 UINTN CallbackNotifyIndex;
516 UINTN LastCallbackNotifyCount;
517 PEI_DISPATCH_NOTIFY_LIST *DispatchNotifyListPointer;
518 UINTN DispatchNotifyIndex;
519 UINTN LastDispatchNotifyCount;
520 VOID *TempPtr;
521
522 if (NotifyList == NULL) {
523 return EFI_INVALID_PARAMETER;
524 }
525
526 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
527
528 CallbackNotifyListPointer = &PrivateData->PpiData.CallbackNotifyList;
529 CallbackNotifyIndex = CallbackNotifyListPointer->CurrentCount;
530 LastCallbackNotifyCount = CallbackNotifyIndex;
531
532 DispatchNotifyListPointer = &PrivateData->PpiData.DispatchNotifyList;
533 DispatchNotifyIndex = DispatchNotifyListPointer->CurrentCount;
534 LastDispatchNotifyCount = DispatchNotifyIndex;
535
536 //
537 // This is loop installs all Notify descriptors in the NotifyList. It is
538 // terminated by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last
539 // EFI_PEI_NOTIFY_DESCRIPTOR in the list.
540 //
541
542 for (;;) {
543 //
544 // If some of the PPI data is invalid restore original Notify PPI database value
545 //
546 if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES) == 0) {
547 CallbackNotifyListPointer->CurrentCount = LastCallbackNotifyCount;
548 DispatchNotifyListPointer->CurrentCount = LastDispatchNotifyCount;
549 DEBUG((DEBUG_ERROR, "ERROR -> NotifyPpi: %g %p\n", NotifyList->Guid, NotifyList->Notify));
550 return EFI_INVALID_PARAMETER;
551 }
552
553 if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK) != 0) {
554 if (CallbackNotifyIndex >= CallbackNotifyListPointer->MaxCount) {
555 //
556 // Run out of room, grow the buffer.
557 //
558 TempPtr = AllocateZeroPool (
559 sizeof (PEI_PPI_LIST_POINTERS) * (CallbackNotifyListPointer->MaxCount + CALLBACK_NOTIFY_GROWTH_STEP)
560 );
561 ASSERT (TempPtr != NULL);
562 CopyMem (
563 TempPtr,
564 CallbackNotifyListPointer->NotifyPtrs,
565 sizeof (PEI_PPI_LIST_POINTERS) * CallbackNotifyListPointer->MaxCount
566 );
567 CallbackNotifyListPointer->NotifyPtrs = TempPtr;
568 CallbackNotifyListPointer->MaxCount = CallbackNotifyListPointer->MaxCount + CALLBACK_NOTIFY_GROWTH_STEP;
569 }
570 CallbackNotifyListPointer->NotifyPtrs[CallbackNotifyIndex].Notify = (EFI_PEI_NOTIFY_DESCRIPTOR *) NotifyList;
571 CallbackNotifyIndex++;
572 CallbackNotifyListPointer->CurrentCount++;
573 } else {
574 if (DispatchNotifyIndex >= DispatchNotifyListPointer->MaxCount) {
575 //
576 // Run out of room, grow the buffer.
577 //
578 TempPtr = AllocateZeroPool (
579 sizeof (PEI_PPI_LIST_POINTERS) * (DispatchNotifyListPointer->MaxCount + DISPATCH_NOTIFY_GROWTH_STEP)
580 );
581 ASSERT (TempPtr != NULL);
582 CopyMem (
583 TempPtr,
584 DispatchNotifyListPointer->NotifyPtrs,
585 sizeof (PEI_PPI_LIST_POINTERS) * DispatchNotifyListPointer->MaxCount
586 );
587 DispatchNotifyListPointer->NotifyPtrs = TempPtr;
588 DispatchNotifyListPointer->MaxCount = DispatchNotifyListPointer->MaxCount + DISPATCH_NOTIFY_GROWTH_STEP;
589 }
590 DispatchNotifyListPointer->NotifyPtrs[DispatchNotifyIndex].Notify = (EFI_PEI_NOTIFY_DESCRIPTOR *) NotifyList;
591 DispatchNotifyIndex++;
592 DispatchNotifyListPointer->CurrentCount++;
593 }
594
595 DEBUG((EFI_D_INFO, "Register PPI Notify: %g\n", NotifyList->Guid));
596
597 if (Single) {
598 //
599 // Only single entry in the NotifyList.
600 //
601 break;
602 } else if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==
603 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {
604 //
605 // Continue until the end of the Notify List.
606 //
607 break;
608 }
609 //
610 // Go to the next descriptor.
611 //
612 NotifyList++;
613 }
614
615 //
616 // Process any callback level notifies for all previously installed PPIs.
617 //
618 ProcessNotify (
619 PrivateData,
620 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
621 0,
622 PrivateData->PpiData.PpiList.CurrentCount,
623 LastCallbackNotifyCount,
624 CallbackNotifyListPointer->CurrentCount
625 );
626
627 return EFI_SUCCESS;
628 }
629
630 /**
631
632 This function installs a notification service to be called back when a given
633 interface is installed or reinstalled. The purpose of the service is to publish
634 an interface that other parties can use to call additional PPIs that may materialize later.
635
636 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
637 @param NotifyList Pointer to list of Descriptors to notify upon.
638
639 @retval EFI_SUCCESS if successful
640 @retval EFI_OUT_OF_RESOURCES if no space in the database
641 @retval EFI_INVALID_PARAMETER if not a good descriptor
642
643 **/
644 EFI_STATUS
645 EFIAPI
646 PeiNotifyPpi (
647 IN CONST EFI_PEI_SERVICES **PeiServices,
648 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList
649 )
650 {
651 return InternalPeiNotifyPpi (PeiServices, NotifyList, FALSE);
652 }
653
654 /**
655
656 Process the Notify List at dispatch level.
657
658 @param PrivateData PeiCore's private data structure.
659
660 **/
661 VOID
662 ProcessDispatchNotifyList (
663 IN PEI_CORE_INSTANCE *PrivateData
664 )
665 {
666 UINTN TempValue;
667
668 while (TRUE) {
669 //
670 // Check if the PEIM that was just dispatched resulted in any
671 // Notifies getting installed. If so, go process any dispatch
672 // level Notifies that match the previouly installed PPIs.
673 // Use "while" instead of "if" since ProcessNotify can modify
674 // DispatchNotifyList.CurrentCount (with NotifyPpi) so we have
675 // to iterate until the same.
676 //
677 while (PrivateData->PpiData.DispatchNotifyList.LastDispatchedCount != PrivateData->PpiData.DispatchNotifyList.CurrentCount) {
678 TempValue = PrivateData->PpiData.DispatchNotifyList.CurrentCount;
679 ProcessNotify (
680 PrivateData,
681 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH,
682 0,
683 PrivateData->PpiData.PpiList.LastDispatchedCount,
684 PrivateData->PpiData.DispatchNotifyList.LastDispatchedCount,
685 PrivateData->PpiData.DispatchNotifyList.CurrentCount
686 );
687 PrivateData->PpiData.DispatchNotifyList.LastDispatchedCount = TempValue;
688 }
689
690 //
691 // Check if the PEIM that was just dispatched resulted in any
692 // PPIs getting installed. If so, go process any dispatch
693 // level Notifies that match the installed PPIs.
694 // Use "while" instead of "if" since ProcessNotify can modify
695 // PpiList.CurrentCount (with InstallPpi) so we have to iterate
696 // until the same.
697 //
698 while (PrivateData->PpiData.PpiList.LastDispatchedCount != PrivateData->PpiData.PpiList.CurrentCount) {
699 TempValue = PrivateData->PpiData.PpiList.CurrentCount;
700 ProcessNotify (
701 PrivateData,
702 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH,
703 PrivateData->PpiData.PpiList.LastDispatchedCount,
704 PrivateData->PpiData.PpiList.CurrentCount,
705 0,
706 PrivateData->PpiData.DispatchNotifyList.LastDispatchedCount
707 );
708 PrivateData->PpiData.PpiList.LastDispatchedCount = TempValue;
709 }
710
711 if (PrivateData->PpiData.DispatchNotifyList.LastDispatchedCount == PrivateData->PpiData.DispatchNotifyList.CurrentCount) {
712 break;
713 }
714 }
715 return;
716 }
717
718 /**
719
720 Process notifications.
721
722 @param PrivateData PeiCore's private data structure
723 @param NotifyType Type of notify to fire.
724 @param InstallStartIndex Install Beginning index.
725 @param InstallStopIndex Install Ending index.
726 @param NotifyStartIndex Notify Beginning index.
727 @param NotifyStopIndex Notify Ending index.
728
729 **/
730 VOID
731 ProcessNotify (
732 IN PEI_CORE_INSTANCE *PrivateData,
733 IN UINTN NotifyType,
734 IN INTN InstallStartIndex,
735 IN INTN InstallStopIndex,
736 IN INTN NotifyStartIndex,
737 IN INTN NotifyStopIndex
738 )
739 {
740 INTN Index1;
741 INTN Index2;
742 EFI_GUID *SearchGuid;
743 EFI_GUID *CheckGuid;
744 EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor;
745
746 for (Index1 = NotifyStartIndex; Index1 < NotifyStopIndex; Index1++) {
747 if (NotifyType == EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK) {
748 NotifyDescriptor = PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index1].Notify;
749 } else {
750 NotifyDescriptor = PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index1].Notify;
751 }
752
753 CheckGuid = NotifyDescriptor->Guid;
754
755 for (Index2 = InstallStartIndex; Index2 < InstallStopIndex; Index2++) {
756 SearchGuid = PrivateData->PpiData.PpiList.PpiPtrs[Index2].Ppi->Guid;
757 //
758 // Don't use CompareGuid function here for performance reasons.
759 // Instead we compare the GUID as INT32 at a time and branch
760 // on the first failed comparison.
761 //
762 if ((((INT32 *)SearchGuid)[0] == ((INT32 *)CheckGuid)[0]) &&
763 (((INT32 *)SearchGuid)[1] == ((INT32 *)CheckGuid)[1]) &&
764 (((INT32 *)SearchGuid)[2] == ((INT32 *)CheckGuid)[2]) &&
765 (((INT32 *)SearchGuid)[3] == ((INT32 *)CheckGuid)[3])) {
766 DEBUG ((EFI_D_INFO, "Notify: PPI Guid: %g, Peim notify entry point: %p\n",
767 SearchGuid,
768 NotifyDescriptor->Notify
769 ));
770 NotifyDescriptor->Notify (
771 (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
772 NotifyDescriptor,
773 (PrivateData->PpiData.PpiList.PpiPtrs[Index2].Ppi)->Ppi
774 );
775 }
776 }
777 }
778 }
779
780 /**
781 Process PpiList from SEC phase.
782
783 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
784 @param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core.
785 These PPI's will be installed and/or immediately signaled if they are notification type.
786
787 **/
788 VOID
789 ProcessPpiListFromSec (
790 IN CONST EFI_PEI_SERVICES **PeiServices,
791 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList
792 )
793 {
794 EFI_STATUS Status;
795 EFI_SEC_HOB_DATA_PPI *SecHobDataPpi;
796 EFI_HOB_GENERIC_HEADER *SecHobList;
797
798 for (;;) {
799 if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES) != 0) {
800 //
801 // It is a notification PPI.
802 //
803 Status = InternalPeiNotifyPpi (PeiServices, (CONST EFI_PEI_NOTIFY_DESCRIPTOR *) PpiList, TRUE);
804 ASSERT_EFI_ERROR (Status);
805 } else {
806 //
807 // It is a normal PPI.
808 //
809 Status = InternalPeiInstallPpi (PeiServices, PpiList, TRUE);
810 ASSERT_EFI_ERROR (Status);
811 }
812
813 if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {
814 //
815 // Continue until the end of the PPI List.
816 //
817 break;
818 }
819
820 PpiList++;
821 }
822
823 //
824 // If the EFI_SEC_HOB_DATA_PPI is in the list of PPIs passed to the PEI entry point,
825 // the PEI Foundation will call the GetHobs() member function and install all HOBs
826 // returned into the HOB list. It does this after installing all PPIs passed from SEC
827 // into the PPI database and before dispatching any PEIMs.
828 //
829 Status = PeiLocatePpi (PeiServices, &gEfiSecHobDataPpiGuid, 0, NULL, (VOID **) &SecHobDataPpi);
830 if (!EFI_ERROR (Status)) {
831 Status = SecHobDataPpi->GetHobs (SecHobDataPpi, &SecHobList);
832 if (!EFI_ERROR (Status)) {
833 Status = PeiInstallSecHobData (PeiServices, SecHobList);
834 ASSERT_EFI_ERROR (Status);
835 }
836 }
837 }
838