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