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