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