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