]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/Ppi/Ppi.c
Source level security checked
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Ppi / Ppi.c
CommitLineData
615c6dd0 1/** @file\r
b1f6a7c6 2 EFI PEI Core PPI services\r
3 \r
58dcdada 4Copyright (c) 2006, Intel Corporation\r
5All rights reserved. This 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
192f6d4c 12\r
b1f6a7c6 13**/\r
192f6d4c 14\r
0d516397 15#include "PeiMain.h"\r
192f6d4c 16\r
b1f6a7c6 17/**\r
192f6d4c 18\r
b1f6a7c6 19 Initialize PPI services.\r
192f6d4c 20\r
b1f6a7c6 21 @param PrivateData Pointer to the PEI Core data.\r
22 @param OldCoreData Pointer to old PEI Core data. \r
23 NULL if being run in non-permament memory mode.\r
192f6d4c 24\r
b1f6a7c6 25**/\r
192f6d4c 26VOID\r
27InitializePpiServices (\r
b0d803fe 28 IN PEI_CORE_INSTANCE *PrivateData,\r
192f6d4c 29 IN PEI_CORE_INSTANCE *OldCoreData\r
30 )\r
192f6d4c 31{\r
192f6d4c 32 if (OldCoreData == NULL) {\r
eaf539d0
LG
33 PrivateData->PpiData.NotifyListEnd = FixedPcdGet32 (PcdPeiCoreMaxPpiSupported)-1;\r
34 PrivateData->PpiData.DispatchListEnd = FixedPcdGet32 (PcdPeiCoreMaxPpiSupported)-1;\r
35 PrivateData->PpiData.LastDispatchedNotify = FixedPcdGet32 (PcdPeiCoreMaxPpiSupported)-1;\r
192f6d4c 36 }\r
192f6d4c 37}\r
38\r
b1f6a7c6 39/**\r
40\r
41 Migrate the Hob list from the CAR stack to PEI installed memory.\r
42\r
0f65cdaa 43 @param PrivateData Pointer to PeiCore's private data structure.\r
731bd38e 44 @param OldCheckingBottom Bottom of temporary memory range. All Ppi in this range\r
45 will be fixup for PpiData and PpiDescriptor pointer.\r
46 @param OldCheckingTop Top of temporary memory range. All Ppi in this range\r
47 will be fixup for PpiData and PpiDescriptor.\r
5c5a0601 48 @param Fixup The address difference between\r
49 the new Hob list and old Hob list.\r
b1f6a7c6 50\r
51**/\r
192f6d4c 52VOID\r
53ConvertPpiPointers (\r
40f26b8f 54 IN PEI_CORE_INSTANCE *PrivateData,\r
55 IN UINTN OldCheckingBottom,\r
56 IN UINTN OldCheckingTop,\r
57 IN INTN Fixup\r
192f6d4c 58 )\r
192f6d4c 59{\r
192f6d4c 60 UINT8 Index;\r
61 PEI_PPI_LIST_POINTERS *PpiPointer;\r
192f6d4c 62\r
eaf539d0 63 for (Index = 0; Index < FixedPcdGet32 (PcdPeiCoreMaxPpiSupported); Index++) {\r
192f6d4c 64 if (Index < PrivateData->PpiData.PpiListEnd ||\r
65 Index > PrivateData->PpiData.NotifyListEnd) {\r
66 PpiPointer = &PrivateData->PpiData.PpiListPtrs[Index];\r
58dcdada 67\r
68 if (((UINTN)PpiPointer->Raw < OldCheckingTop) &&\r
69 ((UINTN)PpiPointer->Raw >= OldCheckingBottom)) {\r
192f6d4c 70 //\r
71 // Convert the pointer to the PEIM descriptor from the old HOB heap\r
72 // to the relocated HOB heap.\r
73 //\r
74 PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw + Fixup);\r
75\r
76 //\r
77 // Only when the PEIM descriptor is in the old HOB should it be necessary\r
78 // to try to convert the pointers in the PEIM descriptor\r
79 //\r
58dcdada 80\r
81 if (((UINTN)PpiPointer->Ppi->Guid < OldCheckingTop) &&\r
82 ((UINTN)PpiPointer->Ppi->Guid >= OldCheckingBottom)) {\r
192f6d4c 83 //\r
84 // Convert the pointer to the GUID in the PPI or NOTIFY descriptor\r
85 // from the old HOB heap to the relocated HOB heap.\r
86 //\r
87 PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid + Fixup);\r
88 }\r
89\r
90 //\r
91 // Assume that no code is located in the temporary memory, so the pointer to\r
92 // the notification function in the NOTIFY descriptor needs not be converted.\r
93 //\r
94 if (Index < PrivateData->PpiData.PpiListEnd &&\r
58dcdada 95 (UINTN)PpiPointer->Ppi->Ppi < OldCheckingTop &&\r
96 (UINTN)PpiPointer->Ppi->Ppi >= OldCheckingBottom) {\r
192f6d4c 97 //\r
98 // Convert the pointer to the PPI interface structure in the PPI descriptor\r
99 // from the old HOB heap to the relocated HOB heap.\r
100 //\r
58dcdada 101 PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi+ Fixup);\r
192f6d4c 102 }\r
103 }\r
104 }\r
105 }\r
106}\r
107\r
b1f6a7c6 108/**\r
192f6d4c 109\r
0f65cdaa 110 This function installs an interface in the PEI PPI database by GUID. \r
111 The purpose of the service is to publish an interface that other parties\r
112 can use to call additional PEIMs.\r
192f6d4c 113\r
0f65cdaa 114 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
115 @param PpiList Pointer to a list of PEI PPI Descriptors.\r
b1f6a7c6 116\r
0f65cdaa 117 @retval EFI_SUCCESS if all PPIs in PpiList are successfully installed.\r
118 @retval EFI_INVALID_PARAMETER if PpiList is NULL pointer\r
731bd38e 119 if any PPI in PpiList is not valid\r
0f65cdaa 120 @retval EFI_OUT_OF_RESOURCES if there is no more memory resource to install PPI\r
b1f6a7c6 121\r
122**/\r
192f6d4c 123EFI_STATUS\r
124EFIAPI\r
125PeiInstallPpi (\r
0c2b5da8 126 IN CONST EFI_PEI_SERVICES **PeiServices,\r
127 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList\r
192f6d4c 128 )\r
192f6d4c 129{\r
130 PEI_CORE_INSTANCE *PrivateData;\r
131 INTN Index;\r
132 INTN LastCallbackInstall;\r
133\r
134\r
135 if (PpiList == NULL) {\r
136 return EFI_INVALID_PARAMETER;\r
137 }\r
138\r
139 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);\r
140\r
141 Index = PrivateData->PpiData.PpiListEnd;\r
142 LastCallbackInstall = Index;\r
143\r
144 //\r
145 // This is loop installs all PPI descriptors in the PpiList. It is terminated\r
146 // by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last\r
147 // EFI_PEI_PPI_DESCRIPTOR in the list.\r
148 //\r
58dcdada 149\r
192f6d4c 150 for (;;) {\r
151 //\r
731bd38e 152 // Since PpiData is used for NotifyList and PpiList, max resource\r
192f6d4c 153 // is reached if the Install reaches the NotifyList\r
154 //\r
155 if (Index == PrivateData->PpiData.NotifyListEnd + 1) {\r
156 return EFI_OUT_OF_RESOURCES;\r
157 }\r
158 //\r
58dcdada 159 // Check if it is a valid PPI.\r
192f6d4c 160 // If not, rollback list to exclude all in this list.\r
161 // Try to indicate which item failed.\r
162 //\r
163 if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_PPI) == 0) {\r
164 PrivateData->PpiData.PpiListEnd = LastCallbackInstall;\r
0e549d5b 165 DEBUG((EFI_D_ERROR, "ERROR -> InstallPpi: %g %p\n", PpiList->Guid, PpiList->Ppi));\r
192f6d4c 166 return EFI_INVALID_PARAMETER;\r
167 }\r
168\r
58dcdada 169 DEBUG((EFI_D_INFO, "Install PPI: %g\n", PpiList->Guid));\r
170 PrivateData->PpiData.PpiListPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR*) PpiList;\r
192f6d4c 171 PrivateData->PpiData.PpiListEnd++;\r
58dcdada 172\r
192f6d4c 173 //\r
174 // Continue until the end of the PPI List.\r
175 //\r
58dcdada 176 if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==\r
192f6d4c 177 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {\r
178 break;\r
179 }\r
180 PpiList++;\r
181 Index++;\r
182 }\r
183\r
184 //\r
185 // Dispatch any callback level notifies for newly installed PPIs.\r
186 //\r
187 DispatchNotify (\r
b0d803fe 188 PrivateData,\r
192f6d4c 189 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r
190 LastCallbackInstall,\r
191 PrivateData->PpiData.PpiListEnd,\r
58dcdada 192 PrivateData->PpiData.DispatchListEnd,\r
192f6d4c 193 PrivateData->PpiData.NotifyListEnd\r
194 );\r
195\r
196\r
197 return EFI_SUCCESS;\r
198}\r
199\r
b1f6a7c6 200/**\r
201\r
0f65cdaa 202 This function reinstalls an interface in the PEI PPI database by GUID. \r
203 The purpose of the service is to publish an interface that other parties can \r
204 use to replace an interface of the same name in the protocol database with a \r
205 different interface.\r
b1f6a7c6 206\r
0f65cdaa 207 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
208 @param OldPpi Pointer to the old PEI PPI Descriptors.\r
209 @param NewPpi Pointer to the new PEI PPI Descriptors.\r
192f6d4c 210\r
0f65cdaa 211 @retval EFI_SUCCESS if the operation was successful\r
212 @retval EFI_INVALID_PARAMETER if OldPpi or NewPpi is NULL\r
213 @retval EFI_INVALID_PARAMETER if NewPpi is not valid\r
214 @retval EFI_NOT_FOUND if the PPI was not in the database\r
b1f6a7c6 215\r
216**/\r
192f6d4c 217EFI_STATUS\r
218EFIAPI\r
219PeiReInstallPpi (\r
0c2b5da8 220 IN CONST EFI_PEI_SERVICES **PeiServices,\r
221 IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi,\r
222 IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi\r
192f6d4c 223 )\r
192f6d4c 224{\r
225 PEI_CORE_INSTANCE *PrivateData;\r
226 INTN Index;\r
227\r
228\r
229 if ((OldPpi == NULL) || (NewPpi == NULL)) {\r
230 return EFI_INVALID_PARAMETER;\r
231 }\r
232\r
233 if ((NewPpi->Flags & EFI_PEI_PPI_DESCRIPTOR_PPI) == 0) {\r
234 return EFI_INVALID_PARAMETER;\r
235 }\r
236\r
237 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);\r
238\r
239 //\r
240 // Find the old PPI instance in the database. If we can not find it,\r
241 // return the EFI_NOT_FOUND error.\r
242 //\r
243 for (Index = 0; Index < PrivateData->PpiData.PpiListEnd; Index++) {\r
244 if (OldPpi == PrivateData->PpiData.PpiListPtrs[Index].Ppi) {\r
245 break;\r
246 }\r
247 }\r
248 if (Index == PrivateData->PpiData.PpiListEnd) {\r
249 return EFI_NOT_FOUND;\r
250 }\r
251\r
252 //\r
253 // Remove the old PPI from the database, add the new one.\r
58dcdada 254 //\r
192f6d4c 255 DEBUG((EFI_D_INFO, "Reinstall PPI: %g\n", NewPpi->Guid));\r
2fead09f 256 ASSERT (Index < FixedPcdGet32 (PcdPeiCoreMaxPpiSupported));\r
0c2b5da8 257 PrivateData->PpiData.PpiListPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR *) NewPpi;\r
192f6d4c 258\r
259 //\r
260 // Dispatch any callback level notifies for the newly installed PPI.\r
261 //\r
262 DispatchNotify (\r
b0d803fe 263 PrivateData,\r
192f6d4c 264 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r
265 Index,\r
266 Index+1,\r
58dcdada 267 PrivateData->PpiData.DispatchListEnd,\r
192f6d4c 268 PrivateData->PpiData.NotifyListEnd\r
269 );\r
270\r
271\r
272 return EFI_SUCCESS;\r
273}\r
274\r
b1f6a7c6 275/**\r
276\r
277 Locate a given named PPI.\r
278\r
192f6d4c 279\r
0f65cdaa 280 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
281 @param Guid Pointer to GUID of the PPI.\r
282 @param Instance Instance Number to discover.\r
283 @param PpiDescriptor Pointer to reference the found descriptor. If not NULL,\r
284 returns a pointer to the descriptor (includes flags, etc)\r
285 @param Ppi Pointer to reference the found PPI\r
b1f6a7c6 286\r
287 @retval EFI_SUCCESS if the PPI is in the database\r
288 @retval EFI_NOT_FOUND if the PPI is not in the database\r
289\r
290**/\r
192f6d4c 291EFI_STATUS\r
292EFIAPI\r
293PeiLocatePpi (\r
0c2b5da8 294 IN CONST EFI_PEI_SERVICES **PeiServices,\r
295 IN CONST EFI_GUID *Guid,\r
0f65cdaa 296 IN UINTN Instance,\r
297 IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,\r
298 IN OUT VOID **Ppi\r
192f6d4c 299 )\r
192f6d4c 300{\r
301 PEI_CORE_INSTANCE *PrivateData;\r
302 INTN Index;\r
303 EFI_GUID *CheckGuid;\r
304 EFI_PEI_PPI_DESCRIPTOR *TempPtr;\r
305\r
58dcdada 306\r
192f6d4c 307 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);\r
308\r
309 //\r
310 // Search the data base for the matching instance of the GUIDed PPI.\r
311 //\r
312 for (Index = 0; Index < PrivateData->PpiData.PpiListEnd; Index++) {\r
313 TempPtr = PrivateData->PpiData.PpiListPtrs[Index].Ppi;\r
314 CheckGuid = TempPtr->Guid;\r
315\r
316 //\r
317 // Don't use CompareGuid function here for performance reasons.\r
318 // Instead we compare the GUID as INT32 at a time and branch\r
319 // on the first failed comparison.\r
320 //\r
321 if ((((INT32 *)Guid)[0] == ((INT32 *)CheckGuid)[0]) &&\r
322 (((INT32 *)Guid)[1] == ((INT32 *)CheckGuid)[1]) &&\r
323 (((INT32 *)Guid)[2] == ((INT32 *)CheckGuid)[2]) &&\r
324 (((INT32 *)Guid)[3] == ((INT32 *)CheckGuid)[3])) {\r
325 if (Instance == 0) {\r
326\r
327 if (PpiDescriptor != NULL) {\r
328 *PpiDescriptor = TempPtr;\r
329 }\r
330\r
331 if (Ppi != NULL) {\r
332 *Ppi = TempPtr->Ppi;\r
333 }\r
334\r
335\r
336 return EFI_SUCCESS;\r
337 }\r
338 Instance--;\r
339 }\r
340 }\r
341\r
342 return EFI_NOT_FOUND;\r
343}\r
344\r
b1f6a7c6 345/**\r
192f6d4c 346\r
0f65cdaa 347 This function installs a notification service to be called back when a given \r
348 interface is installed or reinstalled. The purpose of the service is to publish \r
349 an interface that other parties can use to call additional PPIs that may materialize later.\r
b1f6a7c6 350\r
0f65cdaa 351 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
352 @param NotifyList Pointer to list of Descriptors to notify upon.\r
b1f6a7c6 353\r
354 @retval EFI_SUCCESS if successful\r
355 @retval EFI_OUT_OF_RESOURCES if no space in the database\r
356 @retval EFI_INVALID_PARAMETER if not a good decriptor\r
357\r
358**/\r
192f6d4c 359EFI_STATUS\r
360EFIAPI\r
361PeiNotifyPpi (\r
0c2b5da8 362 IN CONST EFI_PEI_SERVICES **PeiServices,\r
363 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList\r
192f6d4c 364 )\r
192f6d4c 365{\r
366 PEI_CORE_INSTANCE *PrivateData;\r
367 INTN Index;\r
368 INTN NotifyIndex;\r
369 INTN LastCallbackNotify;\r
370 EFI_PEI_NOTIFY_DESCRIPTOR *NotifyPtr;\r
371 UINTN NotifyDispatchCount;\r
372\r
373\r
374 NotifyDispatchCount = 0;\r
375\r
376 if (NotifyList == NULL) {\r
377 return EFI_INVALID_PARAMETER;\r
378 }\r
379\r
380 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);\r
381\r
382 Index = PrivateData->PpiData.NotifyListEnd;\r
383 LastCallbackNotify = Index;\r
384\r
385 //\r
386 // This is loop installs all Notify descriptors in the NotifyList. It is\r
387 // terminated by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last\r
388 // EFI_PEI_NOTIFY_DESCRIPTOR in the list.\r
389 //\r
390\r
391 for (;;) {\r
392 //\r
393 // Since PpiData is used for NotifyList and InstallList, max resource\r
394 // is reached if the Install reaches the PpiList\r
395 //\r
396 if (Index == PrivateData->PpiData.PpiListEnd - 1) {\r
397 return EFI_OUT_OF_RESOURCES;\r
398 }\r
58dcdada 399\r
192f6d4c 400 //\r
401 // If some of the PPI data is invalid restore original Notify PPI database value\r
402 //\r
403 if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES) == 0) {\r
404 PrivateData->PpiData.NotifyListEnd = LastCallbackNotify;\r
0e549d5b 405 DEBUG((EFI_D_ERROR, "ERROR -> InstallNotify: %g %p\n", NotifyList->Guid, NotifyList->Notify));\r
192f6d4c 406 return EFI_INVALID_PARAMETER;\r
407 }\r
58dcdada 408\r
192f6d4c 409 if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH) != 0) {\r
58dcdada 410 NotifyDispatchCount ++;\r
411 }\r
412\r
413 PrivateData->PpiData.PpiListPtrs[Index].Notify = (EFI_PEI_NOTIFY_DESCRIPTOR *) NotifyList;\r
414\r
192f6d4c 415 PrivateData->PpiData.NotifyListEnd--;\r
416 DEBUG((EFI_D_INFO, "Register PPI Notify: %g\n", NotifyList->Guid));\r
417 if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==\r
418 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {\r
419 break;\r
420 }\r
421 //\r
422 // Go the next descriptor. Remember the NotifyList moves down.\r
423 //\r
424 NotifyList++;\r
425 Index--;\r
426 }\r
58dcdada 427\r
192f6d4c 428 //\r
58dcdada 429 // If there is Dispatch Notify PPI installed put them on the bottom\r
192f6d4c 430 //\r
431 if (NotifyDispatchCount > 0) {\r
58dcdada 432 for (NotifyIndex = LastCallbackNotify; NotifyIndex > PrivateData->PpiData.NotifyListEnd; NotifyIndex--) {\r
192f6d4c 433 if ((PrivateData->PpiData.PpiListPtrs[NotifyIndex].Notify->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH) != 0) {\r
434 NotifyPtr = PrivateData->PpiData.PpiListPtrs[NotifyIndex].Notify;\r
58dcdada 435\r
192f6d4c 436 for (Index = NotifyIndex; Index < PrivateData->PpiData.DispatchListEnd; Index++){\r
437 PrivateData->PpiData.PpiListPtrs[Index].Notify = PrivateData->PpiData.PpiListPtrs[Index + 1].Notify;\r
438 }\r
439 PrivateData->PpiData.PpiListPtrs[Index].Notify = NotifyPtr;\r
58dcdada 440 PrivateData->PpiData.DispatchListEnd--;\r
192f6d4c 441 }\r
442 }\r
58dcdada 443\r
444 LastCallbackNotify -= NotifyDispatchCount;\r
192f6d4c 445 }\r
58dcdada 446\r
192f6d4c 447 //\r
448 // Dispatch any callback level notifies for all previously installed PPIs.\r
449 //\r
450 DispatchNotify (\r
b0d803fe 451 PrivateData,\r
192f6d4c 452 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r
453 0,\r
454 PrivateData->PpiData.PpiListEnd,\r
455 LastCallbackNotify,\r
456 PrivateData->PpiData.NotifyListEnd\r
457 );\r
58dcdada 458\r
192f6d4c 459 return EFI_SUCCESS;\r
460}\r
461\r
462\r
b1f6a7c6 463/**\r
192f6d4c 464\r
465 Process the Notify List at dispatch level.\r
466\r
b1f6a7c6 467 @param PrivateData PeiCore's private data structure.\r
192f6d4c 468\r
b1f6a7c6 469**/\r
470VOID\r
471ProcessNotifyList (\r
472 IN PEI_CORE_INSTANCE *PrivateData\r
473 )\r
192f6d4c 474{\r
192f6d4c 475 INTN TempValue;\r
58dcdada 476\r
192f6d4c 477 while (TRUE) {\r
478 //\r
479 // Check if the PEIM that was just dispatched resulted in any\r
480 // Notifies getting installed. If so, go process any dispatch\r
481 // level Notifies that match the previouly installed PPIs.\r
58dcdada 482 // Use "while" instead of "if" since DispatchNotify can modify\r
192f6d4c 483 // DispatchListEnd (with NotifyPpi) so we have to iterate until the same.\r
484 //\r
485 while (PrivateData->PpiData.LastDispatchedNotify != PrivateData->PpiData.DispatchListEnd) {\r
486 TempValue = PrivateData->PpiData.DispatchListEnd;\r
487 DispatchNotify (\r
b0d803fe 488 PrivateData,\r
192f6d4c 489 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH,\r
490 0,\r
491 PrivateData->PpiData.LastDispatchedInstall,\r
492 PrivateData->PpiData.LastDispatchedNotify,\r
493 PrivateData->PpiData.DispatchListEnd\r
494 );\r
495 PrivateData->PpiData.LastDispatchedNotify = TempValue;\r
496 }\r
58dcdada 497\r
498\r
192f6d4c 499 //\r
500 // Check if the PEIM that was just dispatched resulted in any\r
501 // PPIs getting installed. If so, go process any dispatch\r
502 // level Notifies that match the installed PPIs.\r
58dcdada 503 // Use "while" instead of "if" since DispatchNotify can modify\r
192f6d4c 504 // PpiListEnd (with InstallPpi) so we have to iterate until the same.\r
505 //\r
506 while (PrivateData->PpiData.LastDispatchedInstall != PrivateData->PpiData.PpiListEnd) {\r
507 TempValue = PrivateData->PpiData.PpiListEnd;\r
508 DispatchNotify (\r
b0d803fe 509 PrivateData,\r
192f6d4c 510 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH,\r
511 PrivateData->PpiData.LastDispatchedInstall,\r
512 PrivateData->PpiData.PpiListEnd,\r
eaf539d0 513 FixedPcdGet32 (PcdPeiCoreMaxPpiSupported)-1,\r
192f6d4c 514 PrivateData->PpiData.DispatchListEnd\r
515 );\r
516 PrivateData->PpiData.LastDispatchedInstall = TempValue;\r
517 }\r
58dcdada 518\r
192f6d4c 519 if (PrivateData->PpiData.LastDispatchedNotify == PrivateData->PpiData.DispatchListEnd) {\r
520 break;\r
521 }\r
58dcdada 522 }\r
192f6d4c 523 return;\r
524}\r
525\r
b1f6a7c6 526/**\r
527\r
528 Dispatch notifications.\r
529\r
530 @param PrivateData PeiCore's private data structure\r
531 @param NotifyType Type of notify to fire.\r
532 @param InstallStartIndex Install Beginning index.\r
533 @param InstallStopIndex Install Ending index.\r
534 @param NotifyStartIndex Notify Beginning index.\r
535 @param NotifyStopIndex Notify Ending index.\r
536\r
537**/\r
192f6d4c 538VOID\r
539DispatchNotify (\r
b0d803fe 540 IN PEI_CORE_INSTANCE *PrivateData,\r
192f6d4c 541 IN UINTN NotifyType,\r
542 IN INTN InstallStartIndex,\r
543 IN INTN InstallStopIndex,\r
544 IN INTN NotifyStartIndex,\r
545 IN INTN NotifyStopIndex\r
546 )\r
192f6d4c 547{\r
192f6d4c 548 INTN Index1;\r
549 INTN Index2;\r
550 EFI_GUID *SearchGuid;\r
551 EFI_GUID *CheckGuid;\r
552 EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor;\r
553\r
192f6d4c 554 //\r
555 // Remember that Installs moves up and Notifies moves down.\r
556 //\r
557 for (Index1 = NotifyStartIndex; Index1 > NotifyStopIndex; Index1--) {\r
558 NotifyDescriptor = PrivateData->PpiData.PpiListPtrs[Index1].Notify;\r
559\r
560 CheckGuid = NotifyDescriptor->Guid;\r
561\r
562 for (Index2 = InstallStartIndex; Index2 < InstallStopIndex; Index2++) {\r
563 SearchGuid = PrivateData->PpiData.PpiListPtrs[Index2].Ppi->Guid;\r
564 //\r
565 // Don't use CompareGuid function here for performance reasons.\r
566 // Instead we compare the GUID as INT32 at a time and branch\r
567 // on the first failed comparison.\r
568 //\r
569 if ((((INT32 *)SearchGuid)[0] == ((INT32 *)CheckGuid)[0]) &&\r
570 (((INT32 *)SearchGuid)[1] == ((INT32 *)CheckGuid)[1]) &&\r
571 (((INT32 *)SearchGuid)[2] == ((INT32 *)CheckGuid)[2]) &&\r
572 (((INT32 *)SearchGuid)[3] == ((INT32 *)CheckGuid)[3])) {\r
0e549d5b 573 DEBUG ((EFI_D_INFO, "Notify: PPI Guid: %g, Peim notify entry point: %p\n",\r
58dcdada 574 SearchGuid,\r
192f6d4c 575 NotifyDescriptor->Notify\r
576 ));\r
577 NotifyDescriptor->Notify (\r
284c8400 578 (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),\r
192f6d4c 579 NotifyDescriptor,\r
580 (PrivateData->PpiData.PpiListPtrs[Index2].Ppi)->Ppi\r
581 );\r
582 }\r
583 }\r
584 }\r
192f6d4c 585}\r
586\r