TianoCore EDK2 master
Loading...
Searching...
No Matches
UnitTestPeiServicesTablePointerLibPpi.c
Go to the documentation of this file.
1
10
31 IN CONST EFI_PEI_SERVICES **PeiServices,
33 IN BOOLEAN Single
34 )
35{
36 PEI_CORE_INSTANCE *PrivateData;
37 PEI_PPI_LIST *PpiListPointer;
38 UINTN Index;
39 UINTN LastCount;
40
41 if (PpiList == NULL) {
42 return EFI_INVALID_PARAMETER;
43 }
44
45 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
46
47 PpiListPointer = &PrivateData->PpiData.PpiList;
48 Index = PpiListPointer->CurrentCount;
49 LastCount = Index;
50
51 //
52 // This is loop installs all PPI descriptors in the PpiList. It is terminated
53 // by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last
54 // EFI_PEI_PPI_DESCRIPTOR in the list.
55 //
56
57 for ( ; ;) {
58 //
59 // Check if it is a valid PPI.
60 // If not, rollback list to exclude all in this list.
61 // Try to indicate which item failed.
62 //
63 if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_PPI) == 0) {
64 PpiListPointer->CurrentCount = LastCount;
65 DEBUG ((DEBUG_ERROR, "ERROR -> InstallPpi: %g %p\n", PpiList->Guid, PpiList->Ppi));
66 return EFI_INVALID_PARAMETER;
67 }
68
69 if (Index >= PpiListPointer->MaxCount) {
70 //
71 // Run out of room, assert.
72 //
73 ASSERT (Index < PpiListPointer->MaxCount);
74 }
75
76 DEBUG ((DEBUG_INFO, "Install PPI: %g\n", PpiList->Guid));
77 PpiListPointer->PpiPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR *)PpiList;
78 Index++;
79 PpiListPointer->CurrentCount++;
80
81 if (Single) {
82 //
83 // Only single entry in the PpiList.
84 //
85 break;
86 } else if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==
87 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST)
88 {
89 //
90 // Continue until the end of the PPI List.
91 //
92 break;
93 }
94
95 //
96 // Go to the next descriptor.
97 //
98 PpiList++;
99 }
100
101 //
102 // Process any callback level notifies for newly installed PPIs.
103 //
105 PrivateData,
106 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
107 LastCount,
108 PpiListPointer->CurrentCount,
109 0,
110 PrivateData->PpiData.CallbackNotifyList.CurrentCount
111 );
112
113 return EFI_SUCCESS;
114}
115
132EFIAPI
134 IN CONST EFI_PEI_SERVICES **PeiServices,
136 )
137{
138 return InternalPeiInstallPpi (PeiServices, PpiList, FALSE);
139}
140
159EFIAPI
161 IN CONST EFI_PEI_SERVICES **PeiServices,
164 )
165{
166 PEI_CORE_INSTANCE *PrivateData;
167 UINTN Index;
168
169 if ((OldPpi == NULL) || (NewPpi == NULL)) {
170 return EFI_INVALID_PARAMETER;
171 }
172
173 if ((NewPpi->Flags & EFI_PEI_PPI_DESCRIPTOR_PPI) == 0) {
174 return EFI_INVALID_PARAMETER;
175 }
176
177 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
178
179 //
180 // Find the old PPI instance in the database. If we can not find it,
181 // return the EFI_NOT_FOUND error.
182 //
183 for (Index = 0; Index < PrivateData->PpiData.PpiList.CurrentCount; Index++) {
184 if (OldPpi == PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi) {
185 break;
186 }
187 }
188
189 if (Index == PrivateData->PpiData.PpiList.CurrentCount) {
190 return EFI_NOT_FOUND;
191 }
192
193 //
194 // Replace the old PPI with the new one.
195 //
196 DEBUG ((DEBUG_INFO, "Reinstall PPI: %g\n", NewPpi->Guid));
197 PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR *)NewPpi;
198
199 //
200 // Process any callback level notifies for the newly installed PPI.
201 //
203 PrivateData,
204 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
205 Index,
206 Index+1,
207 0,
208 PrivateData->PpiData.CallbackNotifyList.CurrentCount
209 );
210
211 return EFI_SUCCESS;
212}
213
231EFIAPI
233 IN CONST EFI_PEI_SERVICES **PeiServices,
234 IN CONST EFI_GUID *Guid,
235 IN UINTN Instance,
236 IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
237 IN OUT VOID **Ppi
238 )
239{
240 PEI_CORE_INSTANCE *PrivateData;
241 UINTN Index;
242 EFI_GUID *CheckGuid;
243 EFI_PEI_PPI_DESCRIPTOR *TempPtr;
244
245 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
246
247 //
248 // Search the data base for the matching instance of the GUIDed PPI.
249 //
250 for (Index = 0; Index < PrivateData->PpiData.PpiList.CurrentCount; Index++) {
251 TempPtr = PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi;
252 CheckGuid = TempPtr->Guid;
253
254 //
255 // Don't use CompareGuid function here for performance reasons.
256 // Instead we compare the GUID as INT32 at a time and branch
257 // on the first failed comparison.
258 //
259 if ((((INT32 *)Guid)[0] == ((INT32 *)CheckGuid)[0]) &&
260 (((INT32 *)Guid)[1] == ((INT32 *)CheckGuid)[1]) &&
261 (((INT32 *)Guid)[2] == ((INT32 *)CheckGuid)[2]) &&
262 (((INT32 *)Guid)[3] == ((INT32 *)CheckGuid)[3]))
263 {
264 if (Instance == 0) {
265 if (PpiDescriptor != NULL) {
266 *PpiDescriptor = TempPtr;
267 }
268
269 if (Ppi != NULL) {
270 *Ppi = TempPtr->Ppi;
271 }
272
273 return EFI_SUCCESS;
274 }
275
276 Instance--;
277 }
278 }
279
280 return EFI_NOT_FOUND;
281}
282
302 IN CONST EFI_PEI_SERVICES **PeiServices,
304 IN BOOLEAN Single
305 )
306{
307 PEI_CORE_INSTANCE *PrivateData;
308 PEI_CALLBACK_NOTIFY_LIST *CallbackNotifyListPointer;
309 UINTN CallbackNotifyIndex;
310 UINTN LastCallbackNotifyCount;
311 PEI_DISPATCH_NOTIFY_LIST *DispatchNotifyListPointer;
312 UINTN DispatchNotifyIndex;
313 UINTN LastDispatchNotifyCount;
314
315 if (NotifyList == NULL) {
316 return EFI_INVALID_PARAMETER;
317 }
318
319 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
320
321 CallbackNotifyListPointer = &PrivateData->PpiData.CallbackNotifyList;
322 CallbackNotifyIndex = CallbackNotifyListPointer->CurrentCount;
323 LastCallbackNotifyCount = CallbackNotifyIndex;
324
325 DispatchNotifyListPointer = &PrivateData->PpiData.DispatchNotifyList;
326 DispatchNotifyIndex = DispatchNotifyListPointer->CurrentCount;
327 LastDispatchNotifyCount = DispatchNotifyIndex;
328
329 //
330 // This is loop installs all Notify descriptors in the NotifyList. It is
331 // terminated by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last
332 // EFI_PEI_NOTIFY_DESCRIPTOR in the list.
333 //
334
335 for ( ; ;) {
336 //
337 // If some of the PPI data is invalid restore original Notify PPI database value
338 //
339 if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES) == 0) {
340 CallbackNotifyListPointer->CurrentCount = LastCallbackNotifyCount;
341 DispatchNotifyListPointer->CurrentCount = LastDispatchNotifyCount;
342 DEBUG ((DEBUG_ERROR, "ERROR -> NotifyPpi: %g %p\n", NotifyList->Guid, NotifyList->Notify));
343 return EFI_INVALID_PARAMETER;
344 }
345
346 if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK) != 0) {
347 if (CallbackNotifyIndex >= CallbackNotifyListPointer->MaxCount) {
348 //
349 // Run out of room, assert.
350 //
351 ASSERT (CallbackNotifyIndex < CallbackNotifyListPointer->MaxCount);
352 }
353
354 CallbackNotifyListPointer->NotifyPtrs[CallbackNotifyIndex].Notify = (EFI_PEI_NOTIFY_DESCRIPTOR *)NotifyList;
355 CallbackNotifyIndex++;
356 CallbackNotifyListPointer->CurrentCount++;
357 } else {
358 ASSERT ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK) != 0);
359 }
360
361 DEBUG ((DEBUG_INFO, "Register PPI Notify: %g\n", NotifyList->Guid));
362
363 if (Single) {
364 //
365 // Only single entry in the NotifyList.
366 //
367 break;
368 } else if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==
369 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST)
370 {
371 //
372 // Continue until the end of the Notify List.
373 //
374 break;
375 }
376
377 //
378 // Go to the next descriptor.
379 //
380 NotifyList++;
381 }
382
383 //
384 // Process any callback level notifies for all previously installed PPIs.
385 //
387 PrivateData,
388 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,
389 0,
390 PrivateData->PpiData.PpiList.CurrentCount,
391 LastCallbackNotifyCount,
392 CallbackNotifyListPointer->CurrentCount
393 );
394
395 return EFI_SUCCESS;
396}
397
413EFIAPI
415 IN CONST EFI_PEI_SERVICES **PeiServices,
417 )
418{
419 return InternalPeiNotifyPpi (PeiServices, NotifyList, FALSE);
420}
421
434VOID
436 IN PEI_CORE_INSTANCE *PrivateData,
437 IN UINTN NotifyType,
438 IN INTN InstallStartIndex,
439 IN INTN InstallStopIndex,
440 IN INTN NotifyStartIndex,
441 IN INTN NotifyStopIndex
442 )
443{
444 INTN Index1;
445 INTN Index2;
446 EFI_GUID *SearchGuid;
447 EFI_GUID *CheckGuid;
448 EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor;
449
450 for (Index1 = NotifyStartIndex; Index1 < NotifyStopIndex; Index1++) {
451 if (NotifyType == EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK) {
452 NotifyDescriptor = PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index1].Notify;
453 } else {
454 NotifyDescriptor = PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index1].Notify;
455 }
456
457 CheckGuid = NotifyDescriptor->Guid;
458
459 for (Index2 = InstallStartIndex; Index2 < InstallStopIndex; Index2++) {
460 SearchGuid = PrivateData->PpiData.PpiList.PpiPtrs[Index2].Ppi->Guid;
461 //
462 // Don't use CompareGuid function here for performance reasons.
463 // Instead we compare the GUID as INT32 at a time and branch
464 // on the first failed comparison.
465 //
466 if ((((INT32 *)SearchGuid)[0] == ((INT32 *)CheckGuid)[0]) &&
467 (((INT32 *)SearchGuid)[1] == ((INT32 *)CheckGuid)[1]) &&
468 (((INT32 *)SearchGuid)[2] == ((INT32 *)CheckGuid)[2]) &&
469 (((INT32 *)SearchGuid)[3] == ((INT32 *)CheckGuid)[3]))
470 {
471 DEBUG ((
472 DEBUG_INFO,
473 "Notify: PPI Guid: %g, Peim notify entry point: %p\n",
474 SearchGuid,
475 NotifyDescriptor->Notify
476 ));
477 NotifyDescriptor->Notify (
479 NotifyDescriptor,
480 (PrivateData->PpiData.PpiList.PpiPtrs[Index2].Ppi)->Ppi
481 );
482 }
483 }
484 }
485}
UINT64 UINTN
INT64 INTN
CONST EFI_PEI_SERVICES **EFIAPI GetPeiServicesTablePointer(VOID)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PEI_CORE_INSTANCE_FROM_PS_THIS(a)
Definition: PeiMain.h:343
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS InternalPeiNotifyPpi(IN CONST EFI_PEI_SERVICES **PeiServices, IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList, IN BOOLEAN Single)
VOID ProcessNotify(IN PEI_CORE_INSTANCE *PrivateData, IN UINTN NotifyType, IN INTN InstallStartIndex, IN INTN InstallStopIndex, IN INTN NotifyStartIndex, IN INTN NotifyStopIndex)
EFI_STATUS EFIAPI UnitTestInstallPpi(IN CONST EFI_PEI_SERVICES **PeiServices, IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
EFI_STATUS EFIAPI UnitTestNotifyPpi(IN CONST EFI_PEI_SERVICES **PeiServices, IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList)
EFI_STATUS EFIAPI UnitTestLocatePpi(IN CONST EFI_PEI_SERVICES **PeiServices, IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI UnitTestReInstallPpi(IN CONST EFI_PEI_SERVICES **PeiServices, IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi, IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi)
EFI_STATUS InternalPeiInstallPpi(IN CONST EFI_PEI_SERVICES **PeiServices, IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList, IN BOOLEAN Single)
EFI_PEIM_NOTIFY_ENTRY_POINT Notify
Definition: PiPeiCis.h:122
Definition: Base.h:213
PEI_PPI_LIST_POINTERS * NotifyPtrs
Definition: PeiMain.h:93
PEI_CALLBACK_NOTIFY_LIST CallbackNotifyList
Definition: PeiMain.h:118
PEI_DISPATCH_NOTIFY_LIST DispatchNotifyList
Definition: PeiMain.h:122
PEI_PPI_LIST PpiList
Definition: PeiMain.h:114
PEI_PPI_LIST_POINTERS * PpiPtrs
Definition: PeiMain.h:84