]>
Commit | Line | Data |
---|---|---|
162ed594 | 1 | /** @file\r |
797a9d67 | 2 | DXE Dispatcher.\r |
28a00297 | 3 | \r |
4 | Step #1 - When a FV protocol is added to the system every driver in the FV\r | |
022c6d45 | 5 | is added to the mDiscoveredList. The SOR, Before, and After Depex are\r |
6 | pre-processed as drivers are added to the mDiscoveredList. If an Apriori\r | |
7 | file exists in the FV those drivers are addeded to the\r | |
8 | mScheduledQueue. The mFvHandleList is used to make sure a\r | |
28a00297 | 9 | FV is only processed once.\r |
10 | \r | |
11 | Step #2 - Dispatch. Remove driver from the mScheduledQueue and load and\r | |
022c6d45 | 12 | start it. After mScheduledQueue is drained check the\r |
13 | mDiscoveredList to see if any item has a Depex that is ready to\r | |
28a00297 | 14 | be placed on the mScheduledQueue.\r |
15 | \r | |
022c6d45 | 16 | Step #3 - Adding to the mScheduledQueue requires that you process Before\r |
28a00297 | 17 | and After dependencies. This is done recursively as the call to add\r |
022c6d45 | 18 | to the mScheduledQueue checks for Before and recursively adds\r |
19 | all Befores. It then addes the item that was passed in and then\r | |
28a00297 | 20 | processess the After dependecies by recursively calling the routine.\r |
21 | \r | |
22 | Dispatcher Rules:\r | |
022c6d45 | 23 | The rules for the dispatcher are in chapter 10 of the DXE CIS. Figure 10-3\r |
28a00297 | 24 | is the state diagram for the DXE dispatcher\r |
25 | \r | |
26 | Depex - Dependency Expresion.\r | |
27 | SOR - Schedule On Request - Don't schedule if this bit is set.\r | |
28 | \r | |
23c98c94 | 29 | Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r |
30 | All rights reserved. This program and the accompanying materials\r | |
31 | are licensed and made available under the terms and conditions of the BSD License\r | |
32 | which accompanies this distribution. The full text of the license may be found at\r | |
33 | http://opensource.org/licenses/bsd-license.php\r | |
34 | \r | |
35 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
36 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
797a9d67 | 37 | \r |
38 | **/\r | |
28a00297 | 39 | \r |
40 | #include <DxeMain.h>\r | |
41 | \r | |
42 | //\r | |
43 | // The Driver List contains one copy of every driver that has been discovered.\r | |
44 | // Items are never removed from the driver list. List of EFI_CORE_DRIVER_ENTRY\r | |
45 | //\r | |
022c6d45 | 46 | LIST_ENTRY mDiscoveredList = INITIALIZE_LIST_HEAD_VARIABLE (mDiscoveredList);\r |
28a00297 | 47 | \r |
48 | //\r | |
49 | // Queue of drivers that are ready to dispatch. This queue is a subset of the\r | |
50 | // mDiscoveredList.list of EFI_CORE_DRIVER_ENTRY.\r | |
51 | //\r | |
52 | LIST_ENTRY mScheduledQueue = INITIALIZE_LIST_HEAD_VARIABLE (mScheduledQueue);\r | |
53 | \r | |
54 | //\r | |
55 | // List of handles who's Fv's have been parsed and added to the mFwDriverList.\r | |
56 | //\r | |
57 | LIST_ENTRY mFvHandleList = INITIALIZE_LIST_HEAD_VARIABLE (mFvHandleList); // list of KNOWN_HANDLE\r | |
58 | \r | |
59 | //\r | |
60 | // Lock for mDiscoveredList, mScheduledQueue, gDispatcherRunning.\r | |
61 | //\r | |
62 | EFI_LOCK mDispatcherLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL);\r | |
63 | \r | |
64 | \r | |
65 | //\r | |
66 | // Flag for the DXE Dispacher. TRUE if dispatcher is execuing.\r | |
67 | //\r | |
68 | BOOLEAN gDispatcherRunning = FALSE;\r | |
69 | \r | |
70 | //\r | |
71 | // Module globals to manage the FwVol registration notification event\r | |
72 | //\r | |
73 | EFI_EVENT mFwVolEvent;\r | |
74 | VOID *mFwVolEventRegistration;\r | |
75 | \r | |
76 | //\r | |
77 | // List of file types supported by dispatcher\r | |
78 | //\r | |
022c6d45 | 79 | EFI_FV_FILETYPE mDxeFileTypes[] = {\r |
80 | EFI_FV_FILETYPE_DRIVER,\r | |
81 | EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER,\r | |
28a00297 | 82 | EFI_FV_FILETYPE_DXE_CORE,\r |
83 | EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE\r | |
84 | };\r | |
85 | \r | |
86 | typedef struct {\r | |
87 | MEDIA_FW_VOL_FILEPATH_DEVICE_PATH File;\r | |
88 | EFI_DEVICE_PATH_PROTOCOL End;\r | |
89 | } FV_FILEPATH_DEVICE_PATH;\r | |
90 | \r | |
91 | FV_FILEPATH_DEVICE_PATH mFvDevicePath;\r | |
92 | \r | |
93 | \r | |
94 | //\r | |
95 | // Function Prototypes\r | |
96 | //\r | |
162ed594 | 97 | /**\r |
98 | Insert InsertedDriverEntry onto the mScheduledQueue. To do this you\r | |
99 | must add any driver with a before dependency on InsertedDriverEntry first.\r | |
100 | You do this by recursively calling this routine. After all the Befores are\r | |
101 | processed you can add InsertedDriverEntry to the mScheduledQueue.\r | |
102 | Then you can add any driver with an After dependency on InsertedDriverEntry\r | |
103 | by recursively calling this routine.\r | |
104 | \r | |
105 | @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue\r | |
106 | \r | |
107 | **/\r | |
28a00297 | 108 | VOID\r |
109 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (\r | |
110 | IN EFI_CORE_DRIVER_ENTRY *InsertedDriverEntry\r | |
111 | );\r | |
022c6d45 | 112 | \r |
162ed594 | 113 | /**\r |
114 | Event notification that is fired every time a FV dispatch protocol is added.\r | |
115 | More than one protocol may have been added when this event is fired, so you\r | |
116 | must loop on CoreLocateHandle () to see how many protocols were added and\r | |
117 | do the following to each FV:\r | |
118 | If the Fv has already been processed, skip it. If the Fv has not been\r | |
119 | processed then mark it as being processed, as we are about to process it.\r | |
120 | Read the Fv and add any driver in the Fv to the mDiscoveredList.The\r | |
121 | mDiscoveredList is never free'ed and contains variables that define\r | |
122 | the other states the DXE driver transitions to..\r | |
123 | While you are at it read the A Priori file into memory.\r | |
124 | Place drivers in the A Priori list onto the mScheduledQueue.\r | |
125 | \r | |
022c6d45 | 126 | @param Event The Event that is being processed, not used.\r |
162ed594 | 127 | @param Context Event Context, not used.\r |
128 | \r | |
129 | **/\r | |
28a00297 | 130 | VOID\r |
131 | EFIAPI\r | |
132 | CoreFwVolEventProtocolNotify (\r | |
133 | IN EFI_EVENT Event,\r | |
134 | IN VOID *Context\r | |
135 | );\r | |
136 | \r | |
162ed594 | 137 | /**\r |
022c6d45 | 138 | Convert FvHandle and DriverName into an EFI device path\r |
162ed594 | 139 | \r |
022c6d45 | 140 | @param Fv Fv protocol, needed to read Depex info out of\r |
141 | FLASH.\r | |
142 | @param FvHandle Handle for Fv, needed in the\r | |
143 | EFI_CORE_DRIVER_ENTRY so that the PE image can be\r | |
144 | read out of the FV at a later time.\r | |
145 | @param DriverName Name of driver to add to mDiscoveredList.\r | |
162ed594 | 146 | \r |
147 | @return Pointer to device path constructed from FvHandle and DriverName\r | |
148 | \r | |
149 | **/\r | |
28a00297 | 150 | EFI_DEVICE_PATH_PROTOCOL *\r |
151 | CoreFvToDevicePath (\r | |
0c2b5da8 | 152 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r |
28a00297 | 153 | IN EFI_HANDLE FvHandle,\r |
154 | IN EFI_GUID *DriverName\r | |
155 | );\r | |
156 | \r | |
162ed594 | 157 | /**\r |
158 | Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,\r | |
159 | and initilize any state variables. Read the Depex from the FV and store it\r | |
160 | in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.\r | |
161 | The Discovered list is never free'ed and contains booleans that represent the\r | |
162 | other possible DXE driver states.\r | |
163 | \r | |
022c6d45 | 164 | @param Fv Fv protocol, needed to read Depex info out of\r |
165 | FLASH.\r | |
166 | @param FvHandle Handle for Fv, needed in the\r | |
167 | EFI_CORE_DRIVER_ENTRY so that the PE image can be\r | |
168 | read out of the FV at a later time.\r | |
169 | @param DriverName Name of driver to add to mDiscoveredList.\r | |
162ed594 | 170 | \r |
022c6d45 | 171 | @retval EFI_SUCCESS If driver was added to the mDiscoveredList.\r |
172 | @retval EFI_ALREADY_STARTED The driver has already been started. Only one\r | |
173 | DriverName may be active in the system at any one\r | |
162ed594 | 174 | time.\r |
175 | \r | |
176 | **/\r | |
28a00297 | 177 | EFI_STATUS\r |
178 | CoreAddToDriverList (\r | |
23c98c94 | 179 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r |
180 | IN EFI_HANDLE FvHandle,\r | |
181 | IN EFI_GUID *DriverName\r | |
28a00297 | 182 | );\r |
183 | \r | |
162ed594 | 184 | /**\r |
185 | Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.\r | |
186 | \r | |
022c6d45 | 187 | @param Fv The FIRMWARE_VOLUME protocol installed on the FV.\r |
188 | @param FvHandle The handle which FVB protocol installed on.\r | |
189 | @param DriverName The driver guid specified.\r | |
162ed594 | 190 | \r |
022c6d45 | 191 | @retval EFI_OUT_OF_RESOURCES No enough memory or other resource.\r |
192 | @retval EFI_VOLUME_CORRUPTED Corrupted volume.\r | |
162ed594 | 193 | @retval EFI_SUCCESS Function successfully returned.\r |
194 | \r | |
195 | **/\r | |
022c6d45 | 196 | EFI_STATUS\r |
28a00297 | 197 | CoreProcessFvImageFile (\r |
0c2b5da8 | 198 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r |
28a00297 | 199 | IN EFI_HANDLE FvHandle,\r |
200 | IN EFI_GUID *DriverName\r | |
201 | );\r | |
202 | \r | |
162ed594 | 203 | \r |
204 | /**\r | |
205 | Enter critical section by gaining lock on mDispatcherLock.\r | |
206 | \r | |
207 | **/\r | |
28a00297 | 208 | VOID\r |
209 | CoreAcquireDispatcherLock (\r | |
210 | VOID\r | |
211 | )\r | |
28a00297 | 212 | {\r |
213 | CoreAcquireLock (&mDispatcherLock);\r | |
214 | }\r | |
215 | \r | |
162ed594 | 216 | \r |
217 | /**\r | |
218 | Exit critical section by releasing lock on mDispatcherLock.\r | |
219 | \r | |
220 | **/\r | |
28a00297 | 221 | VOID\r |
222 | CoreReleaseDispatcherLock (\r | |
223 | VOID\r | |
224 | )\r | |
28a00297 | 225 | {\r |
226 | CoreReleaseLock (&mDispatcherLock);\r | |
227 | }\r | |
228 | \r | |
28a00297 | 229 | \r |
162ed594 | 230 | /**\r |
28a00297 | 231 | Read Depex and pre-process the Depex for Before and After. If Section Extraction\r |
232 | protocol returns an error via ReadSection defer the reading of the Depex.\r | |
233 | \r | |
022c6d45 | 234 | @param DriverEntry Driver to work on.\r |
28a00297 | 235 | \r |
022c6d45 | 236 | @retval EFI_SUCCESS Depex read and preprossesed\r |
237 | @retval EFI_PROTOCOL_ERROR The section extraction protocol returned an error\r | |
238 | and Depex reading needs to be retried.\r | |
162ed594 | 239 | @retval Error DEPEX not found.\r |
28a00297 | 240 | \r |
162ed594 | 241 | **/\r |
162ed594 | 242 | EFI_STATUS\r |
243 | CoreGetDepexSectionAndPreProccess (\r | |
244 | IN EFI_CORE_DRIVER_ENTRY *DriverEntry\r | |
245 | )\r | |
28a00297 | 246 | {\r |
247 | EFI_STATUS Status;\r | |
248 | EFI_SECTION_TYPE SectionType;\r | |
249 | UINT32 AuthenticationStatus;\r | |
0c2b5da8 | 250 | EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r |
28a00297 | 251 | \r |
022c6d45 | 252 | \r |
28a00297 | 253 | Fv = DriverEntry->Fv;\r |
254 | \r | |
255 | //\r | |
256 | // Grab Depex info, it will never be free'ed.\r | |
257 | //\r | |
258 | SectionType = EFI_SECTION_DXE_DEPEX;\r | |
259 | Status = Fv->ReadSection (\r | |
022c6d45 | 260 | DriverEntry->Fv,\r |
28a00297 | 261 | &DriverEntry->FileName,\r |
022c6d45 | 262 | SectionType,\r |
263 | 0,\r | |
264 | &DriverEntry->Depex,\r | |
28a00297 | 265 | (UINTN *)&DriverEntry->DepexSize,\r |
266 | &AuthenticationStatus\r | |
267 | );\r | |
268 | if (EFI_ERROR (Status)) {\r | |
269 | if (Status == EFI_PROTOCOL_ERROR) {\r | |
270 | //\r | |
271 | // The section extraction protocol failed so set protocol error flag\r | |
272 | //\r | |
273 | DriverEntry->DepexProtocolError = TRUE;\r | |
274 | } else {\r | |
275 | //\r | |
8a7d75b0 | 276 | // If no Depex assume UEFI 2.0 driver model\r |
28a00297 | 277 | //\r |
278 | DriverEntry->Depex = NULL;\r | |
279 | DriverEntry->Dependent = TRUE;\r | |
280 | DriverEntry->DepexProtocolError = FALSE;\r | |
281 | }\r | |
282 | } else {\r | |
283 | //\r | |
284 | // Set Before, After, and Unrequested state information based on Depex\r | |
285 | // Driver will be put in Dependent or Unrequested state\r | |
286 | //\r | |
287 | CorePreProcessDepex (DriverEntry);\r | |
288 | DriverEntry->DepexProtocolError = FALSE;\r | |
022c6d45 | 289 | }\r |
28a00297 | 290 | \r |
291 | return Status;\r | |
292 | }\r | |
293 | \r | |
162ed594 | 294 | \r |
295 | /**\r | |
296 | Check every driver and locate a matching one. If the driver is found, the Unrequested\r | |
297 | state flag is cleared.\r | |
298 | \r | |
022c6d45 | 299 | @param FirmwareVolumeHandle The handle of the Firmware Volume that contains\r |
300 | the firmware file specified by DriverName.\r | |
301 | @param DriverName The Driver name to put in the Dependent state.\r | |
162ed594 | 302 | \r |
022c6d45 | 303 | @retval EFI_SUCCESS The DriverName was found and it's SOR bit was\r |
304 | cleared\r | |
305 | @retval EFI_NOT_FOUND The DriverName does not exist or it's SOR bit was\r | |
306 | not set.\r | |
162ed594 | 307 | \r |
308 | **/\r | |
28a00297 | 309 | EFI_STATUS\r |
310 | EFIAPI\r | |
311 | CoreSchedule (\r | |
312 | IN EFI_HANDLE FirmwareVolumeHandle,\r | |
313 | IN EFI_GUID *DriverName\r | |
314 | )\r | |
28a00297 | 315 | {\r |
316 | LIST_ENTRY *Link;\r | |
317 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
318 | \r | |
319 | //\r | |
320 | // Check every driver\r | |
321 | //\r | |
322 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
323 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
324 | if (DriverEntry->FvHandle == FirmwareVolumeHandle &&\r | |
022c6d45 | 325 | DriverEntry->Unrequested &&\r |
28a00297 | 326 | CompareGuid (DriverName, &DriverEntry->FileName)) {\r |
327 | //\r | |
328 | // Move the driver from the Unrequested to the Dependent state\r | |
329 | //\r | |
330 | CoreAcquireDispatcherLock ();\r | |
331 | DriverEntry->Unrequested = FALSE;\r | |
332 | DriverEntry->Dependent = TRUE;\r | |
333 | CoreReleaseDispatcherLock ();\r | |
022c6d45 | 334 | \r |
28a00297 | 335 | return EFI_SUCCESS;\r |
336 | }\r | |
337 | }\r | |
022c6d45 | 338 | return EFI_NOT_FOUND;\r |
28a00297 | 339 | }\r |
340 | \r | |
341 | \r | |
162ed594 | 342 | \r |
343 | /**\r | |
e94a9ff7 | 344 | Convert a driver from the Untrused back to the Scheduled state.\r |
162ed594 | 345 | \r |
022c6d45 | 346 | @param FirmwareVolumeHandle The handle of the Firmware Volume that contains\r |
347 | the firmware file specified by DriverName.\r | |
348 | @param DriverName The Driver name to put in the Scheduled state\r | |
162ed594 | 349 | \r |
022c6d45 | 350 | @retval EFI_SUCCESS The file was found in the untrusted state, and it\r |
351 | was promoted to the trusted state.\r | |
352 | @retval EFI_NOT_FOUND The file was not found in the untrusted state.\r | |
162ed594 | 353 | \r |
354 | **/\r | |
28a00297 | 355 | EFI_STATUS\r |
356 | EFIAPI\r | |
357 | CoreTrust (\r | |
358 | IN EFI_HANDLE FirmwareVolumeHandle,\r | |
359 | IN EFI_GUID *DriverName\r | |
360 | )\r | |
28a00297 | 361 | {\r |
362 | LIST_ENTRY *Link;\r | |
363 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
364 | \r | |
365 | //\r | |
366 | // Check every driver\r | |
367 | //\r | |
368 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
369 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
370 | if (DriverEntry->FvHandle == FirmwareVolumeHandle &&\r | |
022c6d45 | 371 | DriverEntry->Untrusted &&\r |
28a00297 | 372 | CompareGuid (DriverName, &DriverEntry->FileName)) {\r |
373 | //\r | |
374 | // Transition driver from Untrusted to Scheduled state.\r | |
375 | //\r | |
376 | CoreAcquireDispatcherLock ();\r | |
377 | DriverEntry->Untrusted = FALSE;\r | |
378 | DriverEntry->Scheduled = TRUE;\r | |
379 | InsertTailList (&mScheduledQueue, &DriverEntry->ScheduledLink);\r | |
380 | CoreReleaseDispatcherLock ();\r | |
022c6d45 | 381 | \r |
28a00297 | 382 | return EFI_SUCCESS;\r |
383 | }\r | |
384 | }\r | |
022c6d45 | 385 | return EFI_NOT_FOUND;\r |
28a00297 | 386 | }\r |
387 | \r | |
388 | \r | |
28a00297 | 389 | \r |
162ed594 | 390 | /**\r |
391 | This is the main Dispatcher for DXE and it exits when there are no more\r | |
28a00297 | 392 | drivers to run. Drain the mScheduledQueue and load and start a PE\r |
162ed594 | 393 | image for each driver. Search the mDiscoveredList to see if any driver can\r |
28a00297 | 394 | be placed on the mScheduledQueue. If no drivers are placed on the\r |
395 | mScheduledQueue exit the function. On exit it is assumed the Bds()\r | |
162ed594 | 396 | will be called, and when the Bds() exits the Dispatcher will be called\r |
28a00297 | 397 | again.\r |
398 | \r | |
022c6d45 | 399 | @retval EFI_ALREADY_STARTED The DXE Dispatcher is already running\r |
400 | @retval EFI_NOT_FOUND No DXE Drivers were dispatched\r | |
401 | @retval EFI_SUCCESS One or more DXE Drivers were dispatched\r | |
28a00297 | 402 | \r |
162ed594 | 403 | **/\r |
162ed594 | 404 | EFI_STATUS\r |
405 | EFIAPI\r | |
406 | CoreDispatcher (\r | |
407 | VOID\r | |
408 | )\r | |
28a00297 | 409 | {\r |
410 | EFI_STATUS Status;\r | |
411 | EFI_STATUS ReturnStatus;\r | |
412 | LIST_ENTRY *Link;\r | |
413 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
414 | BOOLEAN ReadyToRun;\r | |
415 | \r | |
416 | if (gDispatcherRunning) {\r | |
417 | //\r | |
418 | // If the dispatcher is running don't let it be restarted.\r | |
419 | //\r | |
420 | return EFI_ALREADY_STARTED;\r | |
421 | }\r | |
422 | \r | |
423 | gDispatcherRunning = TRUE;\r | |
424 | \r | |
425 | \r | |
426 | ReturnStatus = EFI_NOT_FOUND;\r | |
427 | do {\r | |
428 | //\r | |
429 | // Drain the Scheduled Queue\r | |
430 | //\r | |
431 | while (!IsListEmpty (&mScheduledQueue)) {\r | |
432 | DriverEntry = CR (\r | |
433 | mScheduledQueue.ForwardLink,\r | |
434 | EFI_CORE_DRIVER_ENTRY,\r | |
435 | ScheduledLink,\r | |
436 | EFI_CORE_DRIVER_ENTRY_SIGNATURE\r | |
437 | );\r | |
438 | \r | |
439 | //\r | |
440 | // Load the DXE Driver image into memory. If the Driver was transitioned from\r | |
441 | // Untrused to Scheduled it would have already been loaded so we may need to\r | |
442 | // skip the LoadImage\r | |
443 | //\r | |
444 | if (DriverEntry->ImageHandle == NULL) {\r | |
445 | Status = CoreLoadImage (\r | |
022c6d45 | 446 | FALSE,\r |
447 | gDxeCoreImageHandle,\r | |
28a00297 | 448 | DriverEntry->FvFileDevicePath,\r |
022c6d45 | 449 | NULL,\r |
450 | 0,\r | |
28a00297 | 451 | &DriverEntry->ImageHandle\r |
452 | );\r | |
453 | \r | |
454 | //\r | |
455 | // Update the driver state to reflect that it's been loaded\r | |
456 | //\r | |
457 | if (EFI_ERROR (Status)) {\r | |
458 | CoreAcquireDispatcherLock ();\r | |
459 | \r | |
460 | if (Status == EFI_SECURITY_VIOLATION) {\r | |
461 | //\r | |
462 | // Take driver from Scheduled to Untrused state\r | |
463 | //\r | |
464 | DriverEntry->Untrusted = TRUE;\r | |
465 | } else {\r | |
466 | //\r | |
467 | // The DXE Driver could not be loaded, and do not attempt to load or start it again.\r | |
022c6d45 | 468 | // Take driver from Scheduled to Initialized.\r |
28a00297 | 469 | //\r |
470 | // This case include the Never Trusted state if EFI_ACCESS_DENIED is returned\r | |
471 | //\r | |
472 | DriverEntry->Initialized = TRUE;\r | |
473 | }\r | |
474 | \r | |
475 | DriverEntry->Scheduled = FALSE;\r | |
476 | RemoveEntryList (&DriverEntry->ScheduledLink);\r | |
022c6d45 | 477 | \r |
28a00297 | 478 | CoreReleaseDispatcherLock ();\r |
022c6d45 | 479 | \r |
28a00297 | 480 | //\r |
481 | // If it's an error don't try the StartImage\r | |
482 | //\r | |
483 | continue;\r | |
484 | }\r | |
485 | }\r | |
486 | \r | |
487 | CoreAcquireDispatcherLock ();\r | |
488 | \r | |
489 | DriverEntry->Scheduled = FALSE;\r | |
490 | DriverEntry->Initialized = TRUE;\r | |
491 | RemoveEntryList (&DriverEntry->ScheduledLink);\r | |
022c6d45 | 492 | \r |
28a00297 | 493 | CoreReleaseDispatcherLock ();\r |
494 | \r | |
797a9d67 | 495 | CoreReportProgressCodeSpecific (\r |
022c6d45 | 496 | FixedPcdGet32(PcdStatusCodeValueDxeDriverBegin),\r |
797a9d67 | 497 | DriverEntry->ImageHandle\r |
498 | );\r | |
28a00297 | 499 | Status = CoreStartImage (DriverEntry->ImageHandle, NULL, NULL);\r |
797a9d67 | 500 | CoreReportProgressCodeSpecific (\r |
022c6d45 | 501 | FixedPcdGet32(PcdStatusCodeValueDxeDriverEnd),\r |
797a9d67 | 502 | DriverEntry->ImageHandle\r |
503 | );\r | |
28a00297 | 504 | \r |
505 | ReturnStatus = EFI_SUCCESS;\r | |
506 | }\r | |
507 | \r | |
508 | //\r | |
509 | // Search DriverList for items to place on Scheduled Queue\r | |
510 | //\r | |
511 | ReadyToRun = FALSE;\r | |
512 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
513 | DriverEntry = CR (Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
514 | \r | |
515 | if (DriverEntry->DepexProtocolError){\r | |
516 | //\r | |
517 | // If Section Extraction Protocol did not let the Depex be read before retry the read\r | |
518 | //\r | |
519 | Status = CoreGetDepexSectionAndPreProccess (DriverEntry);\r | |
022c6d45 | 520 | }\r |
28a00297 | 521 | \r |
522 | if (DriverEntry->Dependent) {\r | |
523 | if (CoreIsSchedulable (DriverEntry)) {\r | |
022c6d45 | 524 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry);\r |
28a00297 | 525 | ReadyToRun = TRUE;\r |
022c6d45 | 526 | }\r |
28a00297 | 527 | }\r |
528 | }\r | |
529 | } while (ReadyToRun);\r | |
530 | \r | |
531 | gDispatcherRunning = FALSE;\r | |
532 | \r | |
533 | return ReturnStatus;\r | |
534 | }\r | |
535 | \r | |
28a00297 | 536 | \r |
162ed594 | 537 | /**\r |
538 | Insert InsertedDriverEntry onto the mScheduledQueue. To do this you\r | |
28a00297 | 539 | must add any driver with a before dependency on InsertedDriverEntry first.\r |
540 | You do this by recursively calling this routine. After all the Befores are\r | |
162ed594 | 541 | processed you can add InsertedDriverEntry to the mScheduledQueue.\r |
542 | Then you can add any driver with an After dependency on InsertedDriverEntry\r | |
28a00297 | 543 | by recursively calling this routine.\r |
544 | \r | |
162ed594 | 545 | @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue\r |
28a00297 | 546 | \r |
162ed594 | 547 | **/\r |
162ed594 | 548 | VOID\r |
549 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (\r | |
550 | IN EFI_CORE_DRIVER_ENTRY *InsertedDriverEntry\r | |
551 | )\r | |
28a00297 | 552 | {\r |
553 | LIST_ENTRY *Link;\r | |
554 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
555 | \r | |
556 | //\r | |
557 | // Process Before Dependency\r | |
558 | //\r | |
559 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
560 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
561 | if (DriverEntry->Before && DriverEntry->Dependent) {\r | |
562 | if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) {\r | |
563 | //\r | |
564 | // Recursively process BEFORE\r | |
565 | //\r | |
566 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry);\r | |
567 | }\r | |
568 | }\r | |
569 | }\r | |
570 | \r | |
571 | //\r | |
572 | // Convert driver from Dependent to Scheduled state\r | |
573 | //\r | |
574 | CoreAcquireDispatcherLock ();\r | |
575 | \r | |
576 | InsertedDriverEntry->Dependent = FALSE;\r | |
577 | InsertedDriverEntry->Scheduled = TRUE;\r | |
578 | InsertTailList (&mScheduledQueue, &InsertedDriverEntry->ScheduledLink);\r | |
022c6d45 | 579 | \r |
28a00297 | 580 | CoreReleaseDispatcherLock ();\r |
581 | \r | |
582 | //\r | |
583 | // Process After Dependency\r | |
584 | //\r | |
585 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
586 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
587 | if (DriverEntry->After && DriverEntry->Dependent) {\r | |
588 | if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) {\r | |
589 | //\r | |
590 | // Recursively process AFTER\r | |
591 | //\r | |
592 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry);\r | |
593 | }\r | |
594 | }\r | |
595 | }\r | |
596 | }\r | |
597 | \r | |
28a00297 | 598 | \r |
162ed594 | 599 | /**\r |
28a00297 | 600 | Return TRUE if the Fv has been processed, FALSE if not.\r |
601 | \r | |
022c6d45 | 602 | @param FvHandle The handle of a FV that's being tested\r |
28a00297 | 603 | \r |
022c6d45 | 604 | @retval TRUE Fv protocol on FvHandle has been processed\r |
e94a9ff7 | 605 | @retval FALSE Fv protocol on FvHandle has not yet been processed\r |
28a00297 | 606 | \r |
162ed594 | 607 | **/\r |
162ed594 | 608 | BOOLEAN\r |
609 | FvHasBeenProcessed (\r | |
610 | IN EFI_HANDLE FvHandle\r | |
611 | )\r | |
28a00297 | 612 | {\r |
613 | LIST_ENTRY *Link;\r | |
614 | KNOWN_HANDLE *KnownHandle;\r | |
615 | \r | |
616 | for (Link = mFvHandleList.ForwardLink; Link != &mFvHandleList; Link = Link->ForwardLink) {\r | |
617 | KnownHandle = CR(Link, KNOWN_HANDLE, Link, KNOWN_HANDLE_SIGNATURE);\r | |
618 | if (KnownHandle->Handle == FvHandle) {\r | |
619 | return TRUE;\r | |
620 | }\r | |
621 | }\r | |
622 | return FALSE;\r | |
623 | }\r | |
624 | \r | |
28a00297 | 625 | \r |
162ed594 | 626 | /**\r |
28a00297 | 627 | Remember that Fv protocol on FvHandle has had it's drivers placed on the\r |
628 | mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are\r | |
629 | never removed/freed from the mFvHandleList.\r | |
630 | \r | |
162ed594 | 631 | @param FvHandle The handle of a FV that has been processed\r |
28a00297 | 632 | \r |
162ed594 | 633 | **/\r |
162ed594 | 634 | VOID\r |
635 | FvIsBeingProcesssed (\r | |
636 | IN EFI_HANDLE FvHandle\r | |
637 | )\r | |
28a00297 | 638 | {\r |
639 | KNOWN_HANDLE *KnownHandle;\r | |
640 | \r | |
641 | KnownHandle = CoreAllocateBootServicesPool (sizeof (KNOWN_HANDLE));\r | |
642 | ASSERT (KnownHandle != NULL);\r | |
643 | \r | |
644 | KnownHandle->Signature = KNOWN_HANDLE_SIGNATURE;\r | |
645 | KnownHandle->Handle = FvHandle;\r | |
646 | InsertTailList (&mFvHandleList, &KnownHandle->Link);\r | |
647 | }\r | |
648 | \r | |
649 | \r | |
650 | \r | |
162ed594 | 651 | \r |
652 | /**\r | |
653 | Convert FvHandle and DriverName into an EFI device path\r | |
654 | \r | |
022c6d45 | 655 | @param Fv Fv protocol, needed to read Depex info out of\r |
656 | FLASH.\r | |
657 | @param FvHandle Handle for Fv, needed in the\r | |
658 | EFI_CORE_DRIVER_ENTRY so that the PE image can be\r | |
659 | read out of the FV at a later time.\r | |
660 | @param DriverName Name of driver to add to mDiscoveredList.\r | |
162ed594 | 661 | \r |
662 | @return Pointer to device path constructed from FvHandle and DriverName\r | |
663 | \r | |
664 | **/\r | |
28a00297 | 665 | EFI_DEVICE_PATH_PROTOCOL *\r |
666 | CoreFvToDevicePath (\r | |
0c2b5da8 | 667 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r |
28a00297 | 668 | IN EFI_HANDLE FvHandle,\r |
669 | IN EFI_GUID *DriverName\r | |
670 | )\r | |
28a00297 | 671 | {\r |
672 | EFI_STATUS Status;\r | |
673 | EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;\r | |
674 | EFI_DEVICE_PATH_PROTOCOL *FileNameDevicePath;\r | |
675 | \r | |
676 | //\r | |
677 | // Remember the device path of the FV\r | |
678 | //\r | |
679 | Status = CoreHandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath);\r | |
680 | if (EFI_ERROR (Status)) {\r | |
681 | FileNameDevicePath = NULL;\r | |
682 | } else {\r | |
683 | //\r | |
684 | // Build a device path to the file in the FV to pass into gBS->LoadImage\r | |
685 | //\r | |
686 | EfiInitializeFwVolDevicepathNode (&mFvDevicePath.File, DriverName);\r | |
687 | mFvDevicePath.End.Type = EFI_END_ENTIRE_DEVICE_PATH;\r | |
688 | mFvDevicePath.End.SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;\r | |
689 | SetDevicePathNodeLength (&mFvDevicePath.End, sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
690 | \r | |
691 | FileNameDevicePath = CoreAppendDevicePath (\r | |
022c6d45 | 692 | FvDevicePath,\r |
28a00297 | 693 | (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath\r |
694 | );\r | |
695 | }\r | |
696 | \r | |
697 | return FileNameDevicePath;\r | |
698 | }\r | |
699 | \r | |
700 | \r | |
701 | \r | |
162ed594 | 702 | /**\r |
703 | Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,\r | |
28a00297 | 704 | and initilize any state variables. Read the Depex from the FV and store it\r |
705 | in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.\r | |
706 | The Discovered list is never free'ed and contains booleans that represent the\r | |
707 | other possible DXE driver states.\r | |
708 | \r | |
022c6d45 | 709 | @param Fv Fv protocol, needed to read Depex info out of\r |
710 | FLASH.\r | |
711 | @param FvHandle Handle for Fv, needed in the\r | |
712 | EFI_CORE_DRIVER_ENTRY so that the PE image can be\r | |
713 | read out of the FV at a later time.\r | |
714 | @param DriverName Name of driver to add to mDiscoveredList.\r | |
28a00297 | 715 | \r |
022c6d45 | 716 | @retval EFI_SUCCESS If driver was added to the mDiscoveredList.\r |
717 | @retval EFI_ALREADY_STARTED The driver has already been started. Only one\r | |
718 | DriverName may be active in the system at any one\r | |
162ed594 | 719 | time.\r |
28a00297 | 720 | \r |
162ed594 | 721 | **/\r |
722 | EFI_STATUS\r | |
723 | CoreAddToDriverList (\r | |
724 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r | |
725 | IN EFI_HANDLE FvHandle,\r | |
726 | IN EFI_GUID *DriverName\r | |
727 | )\r | |
28a00297 | 728 | {\r |
729 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
730 | \r | |
022c6d45 | 731 | \r |
28a00297 | 732 | //\r |
022c6d45 | 733 | // Create the Driver Entry for the list. ZeroPool initializes lots of variables to\r |
28a00297 | 734 | // NULL or FALSE.\r |
735 | //\r | |
736 | DriverEntry = CoreAllocateZeroBootServicesPool (sizeof (EFI_CORE_DRIVER_ENTRY));\r | |
737 | ASSERT (DriverEntry != NULL);\r | |
738 | \r | |
739 | DriverEntry->Signature = EFI_CORE_DRIVER_ENTRY_SIGNATURE;\r | |
e94a9ff7 | 740 | CopyGuid (&DriverEntry->FileName, DriverName);\r |
28a00297 | 741 | DriverEntry->FvHandle = FvHandle;\r |
742 | DriverEntry->Fv = Fv;\r | |
743 | DriverEntry->FvFileDevicePath = CoreFvToDevicePath (Fv, FvHandle, DriverName);\r | |
744 | \r | |
745 | CoreGetDepexSectionAndPreProccess (DriverEntry);\r | |
022c6d45 | 746 | \r |
28a00297 | 747 | CoreAcquireDispatcherLock ();\r |
022c6d45 | 748 | \r |
28a00297 | 749 | InsertTailList (&mDiscoveredList, &DriverEntry->Link);\r |
750 | \r | |
751 | CoreReleaseDispatcherLock ();\r | |
752 | \r | |
753 | return EFI_SUCCESS;\r | |
754 | }\r | |
755 | \r | |
bbc0f1bb | 756 | \r |
162ed594 | 757 | /**\r |
bbc0f1bb | 758 | Check if a FV Image type file (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) is\r |
759 | described by a EFI_HOB_FIRMWARE_VOLUME2 Hob.\r | |
760 | \r | |
022c6d45 | 761 | @param FvHandle The handle which FVB protocol installed on.\r |
762 | @param DriverName The driver guid specified.\r | |
bbc0f1bb | 763 | \r |
022c6d45 | 764 | @retval TRUE This file is found in a EFI_HOB_FIRMWARE_VOLUME2\r |
765 | Hob.\r | |
162ed594 | 766 | @retval FALSE Not found.\r |
bbc0f1bb | 767 | \r |
162ed594 | 768 | **/\r |
162ed594 | 769 | BOOLEAN\r |
770 | FvFoundInHobFv2 (\r | |
771 | IN EFI_HANDLE FvHandle,\r | |
772 | IN CONST EFI_GUID *DriverName\r | |
773 | )\r | |
bbc0f1bb | 774 | {\r |
775 | EFI_PEI_HOB_POINTERS HobFv2;\r | |
022c6d45 | 776 | \r |
bbc0f1bb | 777 | HobFv2.Raw = GetHobList ();\r |
022c6d45 | 778 | \r |
bbc0f1bb | 779 | while ((HobFv2.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobFv2.Raw)) != NULL) {\r |
780 | if (CompareGuid (DriverName, &HobFv2.FirmwareVolume2->FileName)) {\r | |
b0d803fe | 781 | return TRUE;\r |
bbc0f1bb | 782 | }\r |
783 | HobFv2.Raw = GET_NEXT_HOB (HobFv2);\r | |
784 | }\r | |
785 | \r | |
786 | return FALSE;\r | |
787 | }\r | |
28a00297 | 788 | \r |
789 | \r | |
162ed594 | 790 | \r |
791 | /**\r | |
792 | Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.\r | |
793 | \r | |
022c6d45 | 794 | @param Fv The FIRMWARE_VOLUME protocol installed on the FV.\r |
795 | @param FvHandle The handle which FVB protocol installed on.\r | |
796 | @param DriverName The driver guid specified.\r | |
162ed594 | 797 | \r |
022c6d45 | 798 | @retval EFI_OUT_OF_RESOURCES No enough memory or other resource.\r |
799 | @retval EFI_VOLUME_CORRUPTED Corrupted volume.\r | |
162ed594 | 800 | @retval EFI_SUCCESS Function successfully returned.\r |
801 | \r | |
802 | **/\r | |
022c6d45 | 803 | EFI_STATUS\r |
28a00297 | 804 | CoreProcessFvImageFile (\r |
0c2b5da8 | 805 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r |
28a00297 | 806 | IN EFI_HANDLE FvHandle,\r |
807 | IN EFI_GUID *DriverName\r | |
808 | )\r | |
28a00297 | 809 | {\r |
810 | EFI_STATUS Status;\r | |
811 | EFI_SECTION_TYPE SectionType;\r | |
812 | UINT32 AuthenticationStatus;\r | |
813 | VOID *Buffer;\r | |
38837959 | 814 | VOID *AlignedBuffer;\r |
28a00297 | 815 | UINTN BufferSize;\r |
38837959 | 816 | EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r |
022c6d45 | 817 | UINT32 FvAlignment;\r |
28a00297 | 818 | \r |
819 | //\r | |
820 | // Read the first (and only the first) firmware volume section\r | |
821 | //\r | |
e94a9ff7 | 822 | SectionType = EFI_SECTION_FIRMWARE_VOLUME_IMAGE;\r |
823 | FvHeader = NULL;\r | |
824 | FvAlignment = 0;\r | |
825 | Buffer = NULL;\r | |
826 | BufferSize = 0;\r | |
38837959 | 827 | AlignedBuffer = NULL;\r |
28a00297 | 828 | Status = Fv->ReadSection (\r |
022c6d45 | 829 | Fv,\r |
830 | DriverName,\r | |
831 | SectionType,\r | |
832 | 0,\r | |
833 | &Buffer,\r | |
e94a9ff7 | 834 | &BufferSize,\r |
835 | &AuthenticationStatus\r | |
836 | );\r | |
28a00297 | 837 | if (!EFI_ERROR (Status)) {\r |
838 | //\r | |
38837959 | 839 | // FvImage should be at its required alignment.\r |
28a00297 | 840 | //\r |
38837959 LG |
841 | FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Buffer;\r |
842 | FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r | |
843 | //\r | |
844 | // FvAlignment must be more than 8 bytes required by FvHeader structure.\r | |
022c6d45 | 845 | //\r |
38837959 LG |
846 | if (FvAlignment < 8) {\r |
847 | FvAlignment = 8;\r | |
848 | }\r | |
e94a9ff7 | 849 | //\r |
850 | // Allocate the aligned buffer for the FvImage.\r | |
851 | //\r | |
b2c5e194 | 852 | AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment);\r |
38837959 LG |
853 | if (AlignedBuffer == NULL) {\r |
854 | Status = EFI_OUT_OF_RESOURCES;\r | |
855 | } else {\r | |
856 | //\r | |
857 | // Move FvImage into the aligned buffer and release the original buffer.\r | |
858 | //\r | |
859 | CopyMem (AlignedBuffer, Buffer, BufferSize);\r | |
860 | CoreFreePool (Buffer);\r | |
861 | Buffer = NULL;\r | |
862 | //\r | |
863 | // Produce a FVB protocol for the file\r | |
864 | //\r | |
865 | Status = ProduceFVBProtocolOnBuffer (\r | |
866 | (EFI_PHYSICAL_ADDRESS) (UINTN) AlignedBuffer,\r | |
867 | (UINT64)BufferSize,\r | |
868 | FvHandle,\r | |
869 | NULL\r | |
870 | );\r | |
871 | }\r | |
28a00297 | 872 | }\r |
873 | \r | |
022c6d45 | 874 | if (EFI_ERROR (Status)) {\r |
38837959 LG |
875 | //\r |
876 | // ReadSection or Produce FVB failed, Free data buffer\r | |
877 | //\r | |
878 | if (Buffer != NULL) {\r | |
022c6d45 | 879 | CoreFreePool (Buffer);\r |
38837959 | 880 | }\r |
022c6d45 | 881 | \r |
38837959 | 882 | if (AlignedBuffer != NULL) {\r |
b2c5e194 | 883 | FreeAlignedPages (AlignedBuffer, EFI_SIZE_TO_PAGES (BufferSize));\r |
38837959 | 884 | }\r |
28a00297 | 885 | }\r |
886 | \r | |
887 | return Status;\r | |
888 | }\r | |
889 | \r | |
28a00297 | 890 | \r |
162ed594 | 891 | /**\r |
892 | Event notification that is fired every time a FV dispatch protocol is added.\r | |
28a00297 | 893 | More than one protocol may have been added when this event is fired, so you\r |
894 | must loop on CoreLocateHandle () to see how many protocols were added and\r | |
895 | do the following to each FV:\r | |
162ed594 | 896 | If the Fv has already been processed, skip it. If the Fv has not been\r |
28a00297 | 897 | processed then mark it as being processed, as we are about to process it.\r |
162ed594 | 898 | Read the Fv and add any driver in the Fv to the mDiscoveredList.The\r |
28a00297 | 899 | mDiscoveredList is never free'ed and contains variables that define\r |
162ed594 | 900 | the other states the DXE driver transitions to..\r |
28a00297 | 901 | While you are at it read the A Priori file into memory.\r |
902 | Place drivers in the A Priori list onto the mScheduledQueue.\r | |
903 | \r | |
022c6d45 | 904 | @param Event The Event that is being processed, not used.\r |
162ed594 | 905 | @param Context Event Context, not used.\r |
28a00297 | 906 | \r |
162ed594 | 907 | **/\r |
162ed594 | 908 | VOID\r |
909 | EFIAPI\r | |
910 | CoreFwVolEventProtocolNotify (\r | |
911 | IN EFI_EVENT Event,\r | |
912 | IN VOID *Context\r | |
913 | )\r | |
28a00297 | 914 | {\r |
915 | EFI_STATUS Status;\r | |
916 | EFI_STATUS GetNextFileStatus;\r | |
917 | EFI_STATUS SecurityStatus;\r | |
0c2b5da8 | 918 | EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r |
28a00297 | 919 | EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;\r |
920 | EFI_HANDLE FvHandle;\r | |
921 | UINTN BufferSize;\r | |
922 | EFI_GUID NameGuid;\r | |
923 | UINTN Key;\r | |
924 | EFI_FV_FILETYPE Type;\r | |
925 | EFI_FV_FILE_ATTRIBUTES Attributes;\r | |
926 | UINTN Size;\r | |
927 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
928 | EFI_GUID *AprioriFile;\r | |
929 | UINTN AprioriEntryCount;\r | |
930 | UINTN Index;\r | |
931 | LIST_ENTRY *Link;\r | |
932 | UINT32 AuthenticationStatus;\r | |
933 | UINTN SizeOfBuffer;\r | |
934 | \r | |
935 | \r | |
936 | while (TRUE) {\r | |
937 | BufferSize = sizeof (EFI_HANDLE);\r | |
938 | Status = CoreLocateHandle (\r | |
e94a9ff7 | 939 | ByRegisterNotify,\r |
940 | NULL,\r | |
941 | mFwVolEventRegistration,\r | |
942 | &BufferSize,\r | |
943 | &FvHandle\r | |
944 | );\r | |
28a00297 | 945 | if (EFI_ERROR (Status)) {\r |
946 | //\r | |
947 | // If no more notification events exit\r | |
948 | //\r | |
949 | return;\r | |
950 | }\r | |
951 | \r | |
952 | if (FvHasBeenProcessed (FvHandle)) {\r | |
953 | //\r | |
954 | // This Fv has already been processed so lets skip it!\r | |
955 | //\r | |
956 | continue;\r | |
957 | }\r | |
958 | \r | |
959 | Status = CoreHandleProtocol (FvHandle, &gEfiFirmwareVolumeDispatchProtocolGuid, (VOID **)&Fv);\r | |
960 | if (EFI_ERROR (Status)) {\r | |
961 | //\r | |
962 | // If no dispatch protocol then skip, but do not marked as being processed as it\r | |
963 | // may show up later.\r | |
964 | //\r | |
965 | continue;\r | |
966 | }\r | |
967 | \r | |
968 | //\r | |
969 | // Since we are about to process this Fv mark it as processed.\r | |
970 | //\r | |
971 | FvIsBeingProcesssed (FvHandle);\r | |
972 | \r | |
0c2b5da8 | 973 | Status = CoreHandleProtocol (FvHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Fv);\r |
28a00297 | 974 | if (EFI_ERROR (Status)) {\r |
975 | //\r | |
976 | // The Handle has a FirmwareVolumeDispatch protocol and should also contiain\r | |
977 | // a FirmwareVolume protocol thus we should never get here.\r | |
978 | //\r | |
979 | ASSERT (FALSE);\r | |
980 | continue;\r | |
981 | }\r | |
022c6d45 | 982 | \r |
28a00297 | 983 | Status = CoreHandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath);\r |
984 | if (EFI_ERROR (Status)) {\r | |
985 | //\r | |
986 | // The Firmware volume doesn't have device path, can't be dispatched.\r | |
987 | //\r | |
988 | continue;\r | |
989 | }\r | |
022c6d45 | 990 | \r |
28a00297 | 991 | //\r |
022c6d45 | 992 | // Evaluate the authentication status of the Firmware Volume through\r |
28a00297 | 993 | // Security Architectural Protocol\r |
994 | //\r | |
995 | if (gSecurity != NULL) {\r | |
996 | SecurityStatus = gSecurity->FileAuthenticationState (\r | |
022c6d45 | 997 | gSecurity,\r |
998 | 0,\r | |
28a00297 | 999 | FvDevicePath\r |
1000 | );\r | |
1001 | if (SecurityStatus != EFI_SUCCESS) {\r | |
1002 | //\r | |
1003 | // Security check failed. The firmware volume should not be used for any purpose.\r | |
1004 | //\r | |
1005 | continue;\r | |
1006 | }\r | |
022c6d45 | 1007 | }\r |
1008 | \r | |
28a00297 | 1009 | //\r |
022c6d45 | 1010 | // Discover Drivers in FV and add them to the Discovered Driver List.\r |
1011 | // Process EFI_FV_FILETYPE_DRIVER type and then EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER\r | |
28a00297 | 1012 | // EFI_FV_FILETYPE_DXE_CORE is processed to produce a Loaded Image protocol for the core\r |
1013 | // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE is processed to create a Fvb\r | |
1014 | //\r | |
e94a9ff7 | 1015 | for (Index = 0; Index < sizeof (mDxeFileTypes) / sizeof (EFI_FV_FILETYPE); Index++) {\r |
28a00297 | 1016 | //\r |
1017 | // Initialize the search key\r | |
1018 | //\r | |
1019 | Key = 0;\r | |
1020 | do {\r | |
1021 | Type = mDxeFileTypes[Index];\r | |
1022 | GetNextFileStatus = Fv->GetNextFile (\r | |
022c6d45 | 1023 | Fv,\r |
28a00297 | 1024 | &Key,\r |
022c6d45 | 1025 | &Type,\r |
1026 | &NameGuid,\r | |
1027 | &Attributes,\r | |
28a00297 | 1028 | &Size\r |
1029 | );\r | |
1030 | if (!EFI_ERROR (GetNextFileStatus)) {\r | |
1031 | if (Type == EFI_FV_FILETYPE_DXE_CORE) {\r | |
1032 | //\r | |
1033 | // If this is the DXE core fill in it's DevicePath & DeviceHandle\r | |
1034 | //\r | |
1035 | if (gDxeCoreLoadedImage->FilePath == NULL) {\r | |
1036 | if (CompareGuid (&NameGuid, gDxeCoreFileName)) {\r | |
1037 | //\r | |
1038 | // Maybe One specail Fv cantains only one DXE_CORE module, so its device path must\r | |
1039 | // be initialized completely.\r | |
1040 | //\r | |
1041 | EfiInitializeFwVolDevicepathNode (&mFvDevicePath.File, &NameGuid);\r | |
1042 | mFvDevicePath.End.Type = EFI_END_ENTIRE_DEVICE_PATH;\r | |
1043 | mFvDevicePath.End.SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;\r | |
1044 | SetDevicePathNodeLength (&mFvDevicePath.End, sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
1045 | \r | |
1046 | gDxeCoreLoadedImage->FilePath = CoreDuplicateDevicePath (\r | |
1047 | (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath\r | |
1048 | );\r | |
1049 | gDxeCoreLoadedImage->DeviceHandle = FvHandle;\r | |
1050 | }\r | |
1051 | }\r | |
1052 | } else if (Type == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r | |
bbc0f1bb | 1053 | //\r |
022c6d45 | 1054 | // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r |
bbc0f1bb | 1055 | // been extracted.\r |
1056 | //\r | |
1057 | if (FvFoundInHobFv2 (FvHandle, &NameGuid)) {\r | |
1058 | continue;\r | |
1059 | }\r | |
28a00297 | 1060 | //\r |
1061 | // Found a firmware volume image. Produce a firmware volume block\r | |
022c6d45 | 1062 | // protocol for it so it gets dispatched from. This is usually a\r |
28a00297 | 1063 | // capsule.\r |
1064 | //\r | |
1065 | CoreProcessFvImageFile (Fv, FvHandle, &NameGuid);\r | |
1066 | } else {\r | |
1067 | //\r | |
1068 | // Transition driver from Undiscovered to Discovered state\r | |
1069 | //\r | |
1070 | CoreAddToDriverList (Fv, FvHandle, &NameGuid);\r | |
1071 | }\r | |
1072 | }\r | |
1073 | } while (!EFI_ERROR (GetNextFileStatus));\r | |
1074 | }\r | |
022c6d45 | 1075 | \r |
28a00297 | 1076 | //\r |
1077 | // Read the array of GUIDs from the Apriori file if it is present in the firmware volume\r | |
1078 | //\r | |
1079 | AprioriFile = NULL;\r | |
1080 | Status = Fv->ReadSection (\r | |
1081 | Fv,\r | |
1082 | &gAprioriGuid,\r | |
1083 | EFI_SECTION_RAW,\r | |
1084 | 0,\r | |
1085 | (VOID **)&AprioriFile,\r | |
1086 | &SizeOfBuffer,\r | |
1087 | &AuthenticationStatus\r | |
1088 | );\r | |
1089 | if (!EFI_ERROR (Status)) {\r | |
1090 | AprioriEntryCount = SizeOfBuffer / sizeof (EFI_GUID);\r | |
1091 | } else {\r | |
1092 | AprioriEntryCount = 0;\r | |
1093 | }\r | |
1094 | \r | |
1095 | //\r | |
1096 | // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes\r | |
1097 | // drivers not in the current FV and these must be skipped since the a priori list\r | |
1098 | // is only valid for the FV that it resided in.\r | |
1099 | //\r | |
1100 | CoreAcquireDispatcherLock ();\r | |
022c6d45 | 1101 | \r |
28a00297 | 1102 | for (Index = 0; Index < AprioriEntryCount; Index++) {\r |
1103 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
1104 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
1105 | if (CompareGuid (&DriverEntry->FileName, &AprioriFile[Index]) &&\r | |
1106 | (FvHandle == DriverEntry->FvHandle)) {\r | |
1107 | DriverEntry->Dependent = FALSE;\r | |
1108 | DriverEntry->Scheduled = TRUE;\r | |
1109 | InsertTailList (&mScheduledQueue, &DriverEntry->ScheduledLink);\r | |
1110 | break;\r | |
1111 | }\r | |
1112 | }\r | |
1113 | }\r | |
1114 | \r | |
1115 | CoreReleaseDispatcherLock ();\r | |
1116 | \r | |
1117 | //\r | |
022c6d45 | 1118 | // Free data allocated by Fv->ReadSection ()\r |
28a00297 | 1119 | //\r |
022c6d45 | 1120 | CoreFreePool (AprioriFile);\r |
28a00297 | 1121 | }\r |
1122 | }\r | |
1123 | \r | |
1124 | \r | |
28a00297 | 1125 | \r |
162ed594 | 1126 | /**\r |
28a00297 | 1127 | Initialize the dispatcher. Initialize the notification function that runs when\r |
e94a9ff7 | 1128 | an FV2 protocol is added to the system.\r |
28a00297 | 1129 | \r |
162ed594 | 1130 | **/\r |
1131 | VOID\r | |
1132 | CoreInitializeDispatcher (\r | |
1133 | VOID\r | |
1134 | )\r | |
28a00297 | 1135 | {\r |
1136 | mFwVolEvent = CoreCreateProtocolNotifyEvent (\r | |
022c6d45 | 1137 | &gEfiFirmwareVolume2ProtocolGuid,\r |
28a00297 | 1138 | TPL_CALLBACK,\r |
1139 | CoreFwVolEventProtocolNotify,\r | |
1140 | NULL,\r | |
1141 | &mFwVolEventRegistration,\r | |
1142 | TRUE\r | |
1143 | );\r | |
1144 | }\r | |
1145 | \r | |
1146 | //\r | |
1147 | // Function only used in debug builds\r | |
1148 | //\r | |
162ed594 | 1149 | \r |
1150 | /**\r | |
1151 | Traverse the discovered list for any drivers that were discovered but not loaded\r | |
1152 | because the dependency experessions evaluated to false.\r | |
1153 | \r | |
1154 | **/\r | |
28a00297 | 1155 | VOID\r |
1156 | CoreDisplayDiscoveredNotDispatched (\r | |
1157 | VOID\r | |
1158 | )\r | |
28a00297 | 1159 | {\r |
1160 | LIST_ENTRY *Link;\r | |
1161 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
1162 | \r | |
1163 | for (Link = mDiscoveredList.ForwardLink;Link !=&mDiscoveredList; Link = Link->ForwardLink) {\r | |
1164 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
1165 | if (DriverEntry->Dependent) {\r | |
162ed594 | 1166 | DEBUG ((DEBUG_LOAD, "Driver %g was discovered but not loaded!!\n", &DriverEntry->FileName));\r |
28a00297 | 1167 | }\r |
1168 | }\r | |
1169 | }\r |