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