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