]>
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 | |
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 | |
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 | |
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 | |
db405d1b | 79 | STATIC EFI_FV_FILETYPE mDxeFileTypes[] = { \r |
28a00297 | 80 | EFI_FV_FILETYPE_DRIVER, \r |
81 | EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER, \r | |
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 | |
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 | |
126 | @param Event The Event that is being processed, not used. \r | |
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 |
138 | Convert FvHandle and DriverName into an EFI device path\r | |
139 | \r | |
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 | |
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 | |
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 | |
170 | \r | |
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 | |
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 | |
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 | |
190 | \r | |
191 | @retval EFI_OUT_OF_RESOURCES No enough memory or other resource. \r | |
192 | @retval EFI_VOLUME_CORRUPTED Corrupted volume. \r | |
193 | @retval EFI_SUCCESS Function successfully returned.\r | |
194 | \r | |
195 | **/\r | |
28a00297 | 196 | EFI_STATUS \r |
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 | |
162ed594 | 234 | @param DriverEntry Driver to work on. \r |
28a00297 | 235 | \r |
162ed594 | 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 | |
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 |
252 | \r | |
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 | |
260 | DriverEntry->Fv, \r | |
261 | &DriverEntry->FileName,\r | |
262 | SectionType, \r | |
263 | 0, \r | |
264 | &DriverEntry->Depex, \r | |
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 | |
289 | } \r | |
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 | |
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 | |
302 | \r | |
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 | |
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 | |
325 | DriverEntry->Unrequested && \r | |
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 | |
334 | \r | |
335 | return EFI_SUCCESS;\r | |
336 | }\r | |
337 | }\r | |
338 | return EFI_NOT_FOUND; \r | |
339 | }\r | |
340 | \r | |
341 | \r | |
162ed594 | 342 | \r |
343 | /**\r | |
344 | Convert a driver from the Untrused back to the Scheduled state\r | |
345 | \r | |
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 | |
349 | \r | |
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 | |
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 | |
371 | DriverEntry->Untrusted && \r | |
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 | |
381 | \r | |
382 | return EFI_SUCCESS;\r | |
383 | }\r | |
384 | }\r | |
385 | return EFI_NOT_FOUND; \r | |
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 | |
28a00297 | 399 | NONE\r |
400 | \r | |
162ed594 | 401 | @retval EFI_ALREADY_STARTED The DXE Dispatcher is already running \r |
402 | @retval EFI_NOT_FOUND No DXE Drivers were dispatched \r | |
403 | @retval EFI_SUCCESS One or more DXE Drivers were dispatched \r | |
28a00297 | 404 | \r |
162ed594 | 405 | **/\r |
162ed594 | 406 | EFI_STATUS\r |
407 | EFIAPI\r | |
408 | CoreDispatcher (\r | |
409 | VOID\r | |
410 | )\r | |
28a00297 | 411 | {\r |
412 | EFI_STATUS Status;\r | |
413 | EFI_STATUS ReturnStatus;\r | |
414 | LIST_ENTRY *Link;\r | |
415 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
416 | BOOLEAN ReadyToRun;\r | |
417 | \r | |
418 | if (gDispatcherRunning) {\r | |
419 | //\r | |
420 | // If the dispatcher is running don't let it be restarted.\r | |
421 | //\r | |
422 | return EFI_ALREADY_STARTED;\r | |
423 | }\r | |
424 | \r | |
425 | gDispatcherRunning = TRUE;\r | |
426 | \r | |
427 | \r | |
428 | ReturnStatus = EFI_NOT_FOUND;\r | |
429 | do {\r | |
430 | //\r | |
431 | // Drain the Scheduled Queue\r | |
432 | //\r | |
433 | while (!IsListEmpty (&mScheduledQueue)) {\r | |
434 | DriverEntry = CR (\r | |
435 | mScheduledQueue.ForwardLink,\r | |
436 | EFI_CORE_DRIVER_ENTRY,\r | |
437 | ScheduledLink,\r | |
438 | EFI_CORE_DRIVER_ENTRY_SIGNATURE\r | |
439 | );\r | |
440 | \r | |
441 | //\r | |
442 | // Load the DXE Driver image into memory. If the Driver was transitioned from\r | |
443 | // Untrused to Scheduled it would have already been loaded so we may need to\r | |
444 | // skip the LoadImage\r | |
445 | //\r | |
446 | if (DriverEntry->ImageHandle == NULL) {\r | |
447 | Status = CoreLoadImage (\r | |
448 | FALSE, \r | |
449 | gDxeCoreImageHandle, \r | |
450 | DriverEntry->FvFileDevicePath,\r | |
451 | NULL, \r | |
452 | 0, \r | |
453 | &DriverEntry->ImageHandle\r | |
454 | );\r | |
455 | \r | |
456 | //\r | |
457 | // Update the driver state to reflect that it's been loaded\r | |
458 | //\r | |
459 | if (EFI_ERROR (Status)) {\r | |
460 | CoreAcquireDispatcherLock ();\r | |
461 | \r | |
462 | if (Status == EFI_SECURITY_VIOLATION) {\r | |
463 | //\r | |
464 | // Take driver from Scheduled to Untrused state\r | |
465 | //\r | |
466 | DriverEntry->Untrusted = TRUE;\r | |
467 | } else {\r | |
468 | //\r | |
469 | // The DXE Driver could not be loaded, and do not attempt to load or start it again.\r | |
470 | // Take driver from Scheduled to Initialized. \r | |
471 | //\r | |
472 | // This case include the Never Trusted state if EFI_ACCESS_DENIED is returned\r | |
473 | //\r | |
474 | DriverEntry->Initialized = TRUE;\r | |
475 | }\r | |
476 | \r | |
477 | DriverEntry->Scheduled = FALSE;\r | |
478 | RemoveEntryList (&DriverEntry->ScheduledLink);\r | |
479 | \r | |
480 | CoreReleaseDispatcherLock ();\r | |
481 | \r | |
482 | //\r | |
483 | // If it's an error don't try the StartImage\r | |
484 | //\r | |
485 | continue;\r | |
486 | }\r | |
487 | }\r | |
488 | \r | |
489 | CoreAcquireDispatcherLock ();\r | |
490 | \r | |
491 | DriverEntry->Scheduled = FALSE;\r | |
492 | DriverEntry->Initialized = TRUE;\r | |
493 | RemoveEntryList (&DriverEntry->ScheduledLink);\r | |
494 | \r | |
495 | CoreReleaseDispatcherLock ();\r | |
496 | \r | |
797a9d67 | 497 | CoreReportProgressCodeSpecific (\r |
498 | FixedPcdGet32(PcdStatusCodeValueDxeDriverBegin), \r | |
499 | DriverEntry->ImageHandle\r | |
500 | );\r | |
28a00297 | 501 | Status = CoreStartImage (DriverEntry->ImageHandle, NULL, NULL);\r |
797a9d67 | 502 | CoreReportProgressCodeSpecific (\r |
503 | FixedPcdGet32(PcdStatusCodeValueDxeDriverEnd), \r | |
504 | DriverEntry->ImageHandle\r | |
505 | );\r | |
28a00297 | 506 | \r |
507 | ReturnStatus = EFI_SUCCESS;\r | |
508 | }\r | |
509 | \r | |
510 | //\r | |
511 | // Search DriverList for items to place on Scheduled Queue\r | |
512 | //\r | |
513 | ReadyToRun = FALSE;\r | |
514 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
515 | DriverEntry = CR (Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
516 | \r | |
517 | if (DriverEntry->DepexProtocolError){\r | |
518 | //\r | |
519 | // If Section Extraction Protocol did not let the Depex be read before retry the read\r | |
520 | //\r | |
521 | Status = CoreGetDepexSectionAndPreProccess (DriverEntry);\r | |
522 | } \r | |
523 | \r | |
524 | if (DriverEntry->Dependent) {\r | |
525 | if (CoreIsSchedulable (DriverEntry)) {\r | |
526 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry); \r | |
527 | ReadyToRun = TRUE;\r | |
528 | } \r | |
529 | }\r | |
530 | }\r | |
531 | } while (ReadyToRun);\r | |
532 | \r | |
533 | gDispatcherRunning = FALSE;\r | |
534 | \r | |
535 | return ReturnStatus;\r | |
536 | }\r | |
537 | \r | |
28a00297 | 538 | \r |
162ed594 | 539 | /**\r |
540 | Insert InsertedDriverEntry onto the mScheduledQueue. To do this you\r | |
28a00297 | 541 | must add any driver with a before dependency on InsertedDriverEntry first.\r |
542 | You do this by recursively calling this routine. After all the Befores are\r | |
162ed594 | 543 | processed you can add InsertedDriverEntry to the mScheduledQueue.\r |
544 | Then you can add any driver with an After dependency on InsertedDriverEntry\r | |
28a00297 | 545 | by recursively calling this routine.\r |
546 | \r | |
162ed594 | 547 | @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue\r |
28a00297 | 548 | \r |
162ed594 | 549 | **/\r |
162ed594 | 550 | VOID\r |
551 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (\r | |
552 | IN EFI_CORE_DRIVER_ENTRY *InsertedDriverEntry\r | |
553 | )\r | |
28a00297 | 554 | {\r |
555 | LIST_ENTRY *Link;\r | |
556 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
557 | \r | |
558 | //\r | |
559 | // Process Before Dependency\r | |
560 | //\r | |
561 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
562 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
563 | if (DriverEntry->Before && DriverEntry->Dependent) {\r | |
564 | if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) {\r | |
565 | //\r | |
566 | // Recursively process BEFORE\r | |
567 | //\r | |
568 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry);\r | |
569 | }\r | |
570 | }\r | |
571 | }\r | |
572 | \r | |
573 | //\r | |
574 | // Convert driver from Dependent to Scheduled state\r | |
575 | //\r | |
576 | CoreAcquireDispatcherLock ();\r | |
577 | \r | |
578 | InsertedDriverEntry->Dependent = FALSE;\r | |
579 | InsertedDriverEntry->Scheduled = TRUE;\r | |
580 | InsertTailList (&mScheduledQueue, &InsertedDriverEntry->ScheduledLink);\r | |
581 | \r | |
582 | CoreReleaseDispatcherLock ();\r | |
583 | \r | |
584 | //\r | |
585 | // Process After Dependency\r | |
586 | //\r | |
587 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
588 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
589 | if (DriverEntry->After && DriverEntry->Dependent) {\r | |
590 | if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) {\r | |
591 | //\r | |
592 | // Recursively process AFTER\r | |
593 | //\r | |
594 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry);\r | |
595 | }\r | |
596 | }\r | |
597 | }\r | |
598 | }\r | |
599 | \r | |
28a00297 | 600 | \r |
162ed594 | 601 | /**\r |
28a00297 | 602 | Return TRUE if the Fv has been processed, FALSE if not.\r |
603 | \r | |
162ed594 | 604 | @param FvHandle The handle of a FV that's being tested \r |
28a00297 | 605 | \r |
162ed594 | 606 | @retval TRUE Fv protocol on FvHandle has been processed \r |
607 | @retval FALSE Fv protocol on FvHandle has not yet been \r | |
608 | processed\r | |
28a00297 | 609 | \r |
162ed594 | 610 | **/\r |
162ed594 | 611 | BOOLEAN\r |
612 | FvHasBeenProcessed (\r | |
613 | IN EFI_HANDLE FvHandle\r | |
614 | )\r | |
28a00297 | 615 | {\r |
616 | LIST_ENTRY *Link;\r | |
617 | KNOWN_HANDLE *KnownHandle;\r | |
618 | \r | |
619 | for (Link = mFvHandleList.ForwardLink; Link != &mFvHandleList; Link = Link->ForwardLink) {\r | |
620 | KnownHandle = CR(Link, KNOWN_HANDLE, Link, KNOWN_HANDLE_SIGNATURE);\r | |
621 | if (KnownHandle->Handle == FvHandle) {\r | |
622 | return TRUE;\r | |
623 | }\r | |
624 | }\r | |
625 | return FALSE;\r | |
626 | }\r | |
627 | \r | |
28a00297 | 628 | \r |
162ed594 | 629 | /**\r |
28a00297 | 630 | Remember that Fv protocol on FvHandle has had it's drivers placed on the\r |
631 | mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are\r | |
632 | never removed/freed from the mFvHandleList.\r | |
633 | \r | |
162ed594 | 634 | @param FvHandle The handle of a FV that has been processed\r |
28a00297 | 635 | \r |
162ed594 | 636 | **/\r |
162ed594 | 637 | VOID\r |
638 | FvIsBeingProcesssed (\r | |
639 | IN EFI_HANDLE FvHandle\r | |
640 | )\r | |
28a00297 | 641 | {\r |
642 | KNOWN_HANDLE *KnownHandle;\r | |
643 | \r | |
644 | KnownHandle = CoreAllocateBootServicesPool (sizeof (KNOWN_HANDLE));\r | |
645 | ASSERT (KnownHandle != NULL);\r | |
646 | \r | |
647 | KnownHandle->Signature = KNOWN_HANDLE_SIGNATURE;\r | |
648 | KnownHandle->Handle = FvHandle;\r | |
649 | InsertTailList (&mFvHandleList, &KnownHandle->Link);\r | |
650 | }\r | |
651 | \r | |
652 | \r | |
653 | \r | |
162ed594 | 654 | \r |
655 | /**\r | |
656 | Convert FvHandle and DriverName into an EFI device path\r | |
657 | \r | |
658 | @param Fv Fv protocol, needed to read Depex info out of \r | |
659 | FLASH. \r | |
660 | @param FvHandle Handle for Fv, needed in the \r | |
661 | EFI_CORE_DRIVER_ENTRY so that the PE image can be \r | |
662 | read out of the FV at a later time. \r | |
663 | @param DriverName Name of driver to add to mDiscoveredList. \r | |
664 | \r | |
665 | @return Pointer to device path constructed from FvHandle and DriverName\r | |
666 | \r | |
667 | **/\r | |
28a00297 | 668 | EFI_DEVICE_PATH_PROTOCOL *\r |
669 | CoreFvToDevicePath (\r | |
0c2b5da8 | 670 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r |
28a00297 | 671 | IN EFI_HANDLE FvHandle,\r |
672 | IN EFI_GUID *DriverName\r | |
673 | )\r | |
28a00297 | 674 | {\r |
675 | EFI_STATUS Status;\r | |
676 | EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;\r | |
677 | EFI_DEVICE_PATH_PROTOCOL *FileNameDevicePath;\r | |
678 | \r | |
679 | //\r | |
680 | // Remember the device path of the FV\r | |
681 | //\r | |
682 | Status = CoreHandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath);\r | |
683 | if (EFI_ERROR (Status)) {\r | |
684 | FileNameDevicePath = NULL;\r | |
685 | } else {\r | |
686 | //\r | |
687 | // Build a device path to the file in the FV to pass into gBS->LoadImage\r | |
688 | //\r | |
689 | EfiInitializeFwVolDevicepathNode (&mFvDevicePath.File, DriverName);\r | |
690 | mFvDevicePath.End.Type = EFI_END_ENTIRE_DEVICE_PATH;\r | |
691 | mFvDevicePath.End.SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;\r | |
692 | SetDevicePathNodeLength (&mFvDevicePath.End, sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
693 | \r | |
694 | FileNameDevicePath = CoreAppendDevicePath (\r | |
695 | FvDevicePath, \r | |
696 | (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath\r | |
697 | );\r | |
698 | }\r | |
699 | \r | |
700 | return FileNameDevicePath;\r | |
701 | }\r | |
702 | \r | |
703 | \r | |
704 | \r | |
28a00297 | 705 | \r |
162ed594 | 706 | /**\r |
707 | Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,\r | |
28a00297 | 708 | and initilize any state variables. Read the Depex from the FV and store it\r |
709 | in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.\r | |
710 | The Discovered list is never free'ed and contains booleans that represent the\r | |
711 | other possible DXE driver states.\r | |
712 | \r | |
162ed594 | 713 | @param Fv Fv protocol, needed to read Depex info out of \r |
714 | FLASH. \r | |
715 | @param FvHandle Handle for Fv, needed in the \r | |
716 | EFI_CORE_DRIVER_ENTRY so that the PE image can be \r | |
717 | read out of the FV at a later time. \r | |
718 | @param DriverName Name of driver to add to mDiscoveredList. \r | |
28a00297 | 719 | \r |
162ed594 | 720 | @retval EFI_SUCCESS If driver was added to the mDiscoveredList. \r |
721 | @retval EFI_ALREADY_STARTED The driver has already been started. Only one \r | |
722 | DriverName may be active in the system at any one \r | |
723 | time.\r | |
28a00297 | 724 | \r |
162ed594 | 725 | **/\r |
726 | EFI_STATUS\r | |
727 | CoreAddToDriverList (\r | |
728 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r | |
729 | IN EFI_HANDLE FvHandle,\r | |
730 | IN EFI_GUID *DriverName\r | |
731 | )\r | |
28a00297 | 732 | {\r |
733 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
734 | \r | |
735 | \r | |
736 | //\r | |
737 | // Create the Driver Entry for the list. ZeroPool initializes lots of variables to \r | |
738 | // NULL or FALSE.\r | |
739 | //\r | |
740 | DriverEntry = CoreAllocateZeroBootServicesPool (sizeof (EFI_CORE_DRIVER_ENTRY));\r | |
741 | ASSERT (DriverEntry != NULL);\r | |
742 | \r | |
743 | DriverEntry->Signature = EFI_CORE_DRIVER_ENTRY_SIGNATURE;\r | |
744 | CopyMem (&DriverEntry->FileName, DriverName, sizeof (EFI_GUID));\r | |
745 | DriverEntry->FvHandle = FvHandle;\r | |
746 | DriverEntry->Fv = Fv;\r | |
747 | DriverEntry->FvFileDevicePath = CoreFvToDevicePath (Fv, FvHandle, DriverName);\r | |
748 | \r | |
749 | CoreGetDepexSectionAndPreProccess (DriverEntry);\r | |
750 | \r | |
751 | CoreAcquireDispatcherLock ();\r | |
752 | \r | |
753 | InsertTailList (&mDiscoveredList, &DriverEntry->Link);\r | |
754 | \r | |
755 | CoreReleaseDispatcherLock ();\r | |
756 | \r | |
757 | return EFI_SUCCESS;\r | |
758 | }\r | |
759 | \r | |
bbc0f1bb | 760 | \r |
162ed594 | 761 | /**\r |
bbc0f1bb | 762 | Check if a FV Image type file (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) is\r |
763 | described by a EFI_HOB_FIRMWARE_VOLUME2 Hob.\r | |
764 | \r | |
162ed594 | 765 | @param FvHandle The handle which FVB protocol installed on. \r |
766 | @param DriverName The driver guid specified. \r | |
bbc0f1bb | 767 | \r |
162ed594 | 768 | @retval TRUE This file is found in a EFI_HOB_FIRMWARE_VOLUME2 \r |
769 | Hob. \r | |
770 | @retval FALSE Not found.\r | |
bbc0f1bb | 771 | \r |
162ed594 | 772 | **/\r |
162ed594 | 773 | BOOLEAN\r |
774 | FvFoundInHobFv2 (\r | |
775 | IN EFI_HANDLE FvHandle,\r | |
776 | IN CONST EFI_GUID *DriverName\r | |
777 | )\r | |
bbc0f1bb | 778 | {\r |
779 | EFI_PEI_HOB_POINTERS HobFv2;\r | |
bbc0f1bb | 780 | \r |
781 | HobFv2.Raw = GetHobList ();\r | |
782 | \r | |
783 | while ((HobFv2.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobFv2.Raw)) != NULL) {\r | |
784 | if (CompareGuid (DriverName, &HobFv2.FirmwareVolume2->FileName)) {\r | |
b0d803fe | 785 | return TRUE;\r |
bbc0f1bb | 786 | }\r |
787 | HobFv2.Raw = GET_NEXT_HOB (HobFv2);\r | |
788 | }\r | |
789 | \r | |
790 | return FALSE;\r | |
791 | }\r | |
28a00297 | 792 | \r |
793 | \r | |
162ed594 | 794 | \r |
795 | /**\r | |
796 | Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.\r | |
797 | \r | |
798 | @param Fv The FIRMWARE_VOLUME protocol installed on the FV. \r | |
799 | @param FvHandle The handle which FVB protocol installed on. \r | |
800 | @param DriverName The driver guid specified. \r | |
801 | \r | |
802 | @retval EFI_OUT_OF_RESOURCES No enough memory or other resource. \r | |
803 | @retval EFI_VOLUME_CORRUPTED Corrupted volume. \r | |
804 | @retval EFI_SUCCESS Function successfully returned.\r | |
805 | \r | |
806 | **/\r | |
28a00297 | 807 | EFI_STATUS \r |
808 | CoreProcessFvImageFile (\r | |
0c2b5da8 | 809 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r |
28a00297 | 810 | IN EFI_HANDLE FvHandle,\r |
811 | IN EFI_GUID *DriverName\r | |
812 | )\r | |
28a00297 | 813 | {\r |
814 | EFI_STATUS Status;\r | |
815 | EFI_SECTION_TYPE SectionType;\r | |
816 | UINT32 AuthenticationStatus;\r | |
817 | VOID *Buffer;\r | |
38837959 | 818 | VOID *AlignedBuffer;\r |
28a00297 | 819 | UINTN BufferSize;\r |
38837959 LG |
820 | EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r |
821 | UINT32 FvAlignment; \r | |
28a00297 | 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 | |
38837959 LG |
827 | FvHeader = NULL;\r |
828 | FvAlignment = 0;\r | |
28a00297 | 829 | Buffer = NULL;\r |
830 | BufferSize = 0;\r | |
38837959 | 831 | AlignedBuffer = NULL;\r |
28a00297 | 832 | Status = Fv->ReadSection (\r |
833 | Fv, \r | |
834 | DriverName, \r | |
835 | SectionType, \r | |
836 | 0, \r | |
837 | &Buffer, \r | |
838 | &BufferSize,\r | |
839 | &AuthenticationStatus\r | |
840 | );\r | |
841 | if (!EFI_ERROR (Status)) {\r | |
842 | //\r | |
38837959 | 843 | // FvImage should be at its required alignment.\r |
28a00297 | 844 | //\r |
38837959 LG |
845 | FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Buffer;\r |
846 | FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r | |
847 | //\r | |
848 | // FvAlignment must be more than 8 bytes required by FvHeader structure.\r | |
849 | // \r | |
850 | if (FvAlignment < 8) {\r | |
851 | FvAlignment = 8;\r | |
852 | }\r | |
b2c5e194 | 853 | AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment);\r |
38837959 LG |
854 | if (AlignedBuffer == NULL) {\r |
855 | Status = EFI_OUT_OF_RESOURCES;\r | |
856 | } else {\r | |
857 | //\r | |
858 | // Move FvImage into the aligned buffer and release the original buffer.\r | |
859 | //\r | |
860 | CopyMem (AlignedBuffer, Buffer, BufferSize);\r | |
861 | CoreFreePool (Buffer);\r | |
862 | Buffer = NULL;\r | |
863 | //\r | |
864 | // Produce a FVB protocol for the file\r | |
865 | //\r | |
866 | Status = ProduceFVBProtocolOnBuffer (\r | |
867 | (EFI_PHYSICAL_ADDRESS) (UINTN) AlignedBuffer,\r | |
868 | (UINT64)BufferSize,\r | |
869 | FvHandle,\r | |
870 | NULL\r | |
871 | );\r | |
872 | }\r | |
28a00297 | 873 | }\r |
874 | \r | |
38837959 LG |
875 | if (EFI_ERROR (Status)) { \r |
876 | //\r | |
877 | // ReadSection or Produce FVB failed, Free data buffer\r | |
878 | //\r | |
879 | if (Buffer != NULL) {\r | |
880 | CoreFreePool (Buffer); \r | |
881 | }\r | |
882 | \r | |
883 | if (AlignedBuffer != NULL) {\r | |
b2c5e194 | 884 | FreeAlignedPages (AlignedBuffer, EFI_SIZE_TO_PAGES (BufferSize));\r |
38837959 | 885 | }\r |
28a00297 | 886 | }\r |
887 | \r | |
888 | return Status;\r | |
889 | }\r | |
890 | \r | |
28a00297 | 891 | \r |
162ed594 | 892 | /**\r |
893 | Event notification that is fired every time a FV dispatch protocol is added.\r | |
28a00297 | 894 | More than one protocol may have been added when this event is fired, so you\r |
895 | must loop on CoreLocateHandle () to see how many protocols were added and\r | |
896 | do the following to each FV:\r | |
162ed594 | 897 | If the Fv has already been processed, skip it. If the Fv has not been\r |
28a00297 | 898 | processed then mark it as being processed, as we are about to process it.\r |
162ed594 | 899 | Read the Fv and add any driver in the Fv to the mDiscoveredList.The\r |
28a00297 | 900 | mDiscoveredList is never free'ed and contains variables that define\r |
162ed594 | 901 | the other states the DXE driver transitions to..\r |
28a00297 | 902 | While you are at it read the A Priori file into memory.\r |
903 | Place drivers in the A Priori list onto the mScheduledQueue.\r | |
904 | \r | |
162ed594 | 905 | @param Event The Event that is being processed, not used. \r |
906 | @param Context Event Context, not used.\r | |
28a00297 | 907 | \r |
162ed594 | 908 | **/\r |
162ed594 | 909 | VOID\r |
910 | EFIAPI\r | |
911 | CoreFwVolEventProtocolNotify (\r | |
912 | IN EFI_EVENT Event,\r | |
913 | IN VOID *Context\r | |
914 | )\r | |
28a00297 | 915 | {\r |
916 | EFI_STATUS Status;\r | |
917 | EFI_STATUS GetNextFileStatus;\r | |
918 | EFI_STATUS SecurityStatus;\r | |
0c2b5da8 | 919 | EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r |
28a00297 | 920 | EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;\r |
921 | EFI_HANDLE FvHandle;\r | |
922 | UINTN BufferSize;\r | |
923 | EFI_GUID NameGuid;\r | |
924 | UINTN Key;\r | |
925 | EFI_FV_FILETYPE Type;\r | |
926 | EFI_FV_FILE_ATTRIBUTES Attributes;\r | |
927 | UINTN Size;\r | |
928 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
929 | EFI_GUID *AprioriFile;\r | |
930 | UINTN AprioriEntryCount;\r | |
931 | UINTN Index;\r | |
932 | LIST_ENTRY *Link;\r | |
933 | UINT32 AuthenticationStatus;\r | |
934 | UINTN SizeOfBuffer;\r | |
935 | \r | |
936 | \r | |
937 | while (TRUE) {\r | |
938 | BufferSize = sizeof (EFI_HANDLE);\r | |
939 | Status = CoreLocateHandle (\r | |
940 | ByRegisterNotify,\r | |
941 | NULL,\r | |
942 | mFwVolEventRegistration,\r | |
943 | &BufferSize,\r | |
944 | &FvHandle\r | |
945 | );\r | |
946 | if (EFI_ERROR (Status)) {\r | |
947 | //\r | |
948 | // If no more notification events exit\r | |
949 | //\r | |
950 | return;\r | |
951 | }\r | |
952 | \r | |
953 | if (FvHasBeenProcessed (FvHandle)) {\r | |
954 | //\r | |
955 | // This Fv has already been processed so lets skip it!\r | |
956 | //\r | |
957 | continue;\r | |
958 | }\r | |
959 | \r | |
960 | Status = CoreHandleProtocol (FvHandle, &gEfiFirmwareVolumeDispatchProtocolGuid, (VOID **)&Fv);\r | |
961 | if (EFI_ERROR (Status)) {\r | |
962 | //\r | |
963 | // If no dispatch protocol then skip, but do not marked as being processed as it\r | |
964 | // may show up later.\r | |
965 | //\r | |
966 | continue;\r | |
967 | }\r | |
968 | \r | |
969 | //\r | |
970 | // Since we are about to process this Fv mark it as processed.\r | |
971 | //\r | |
972 | FvIsBeingProcesssed (FvHandle);\r | |
973 | \r | |
974 | \r | |
0c2b5da8 | 975 | Status = CoreHandleProtocol (FvHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Fv);\r |
28a00297 | 976 | if (EFI_ERROR (Status)) {\r |
977 | //\r | |
978 | // The Handle has a FirmwareVolumeDispatch protocol and should also contiain\r | |
979 | // a FirmwareVolume protocol thus we should never get here.\r | |
980 | //\r | |
981 | ASSERT (FALSE);\r | |
982 | continue;\r | |
983 | }\r | |
984 | \r | |
985 | Status = CoreHandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath);\r | |
986 | if (EFI_ERROR (Status)) {\r | |
987 | //\r | |
988 | // The Firmware volume doesn't have device path, can't be dispatched.\r | |
989 | //\r | |
990 | continue;\r | |
991 | }\r | |
992 | \r | |
993 | //\r | |
994 | // Evaluate the authentication status of the Firmware Volume through \r | |
995 | // Security Architectural Protocol\r | |
996 | //\r | |
997 | if (gSecurity != NULL) {\r | |
998 | SecurityStatus = gSecurity->FileAuthenticationState (\r | |
999 | gSecurity, \r | |
1000 | 0, \r | |
1001 | FvDevicePath\r | |
1002 | );\r | |
1003 | if (SecurityStatus != EFI_SUCCESS) {\r | |
1004 | //\r | |
1005 | // Security check failed. The firmware volume should not be used for any purpose.\r | |
1006 | //\r | |
1007 | continue;\r | |
1008 | }\r | |
1009 | } \r | |
1010 | \r | |
1011 | //\r | |
1012 | // Discover Drivers in FV and add them to the Discovered Driver List. \r | |
1013 | // Process EFI_FV_FILETYPE_DRIVER type and then EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER \r | |
1014 | // EFI_FV_FILETYPE_DXE_CORE is processed to produce a Loaded Image protocol for the core\r | |
1015 | // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE is processed to create a Fvb\r | |
1016 | //\r | |
1017 | for (Index = 0; Index < sizeof (mDxeFileTypes)/sizeof (EFI_FV_FILETYPE); Index++) {\r | |
1018 | //\r | |
1019 | // Initialize the search key\r | |
1020 | //\r | |
1021 | Key = 0;\r | |
1022 | do {\r | |
1023 | Type = mDxeFileTypes[Index];\r | |
1024 | GetNextFileStatus = Fv->GetNextFile (\r | |
1025 | Fv, \r | |
1026 | &Key,\r | |
1027 | &Type, \r | |
1028 | &NameGuid, \r | |
1029 | &Attributes, \r | |
1030 | &Size\r | |
1031 | );\r | |
1032 | if (!EFI_ERROR (GetNextFileStatus)) {\r | |
1033 | if (Type == EFI_FV_FILETYPE_DXE_CORE) {\r | |
1034 | //\r | |
1035 | // If this is the DXE core fill in it's DevicePath & DeviceHandle\r | |
1036 | //\r | |
1037 | if (gDxeCoreLoadedImage->FilePath == NULL) {\r | |
1038 | if (CompareGuid (&NameGuid, gDxeCoreFileName)) {\r | |
1039 | //\r | |
1040 | // Maybe One specail Fv cantains only one DXE_CORE module, so its device path must\r | |
1041 | // be initialized completely.\r | |
1042 | //\r | |
1043 | EfiInitializeFwVolDevicepathNode (&mFvDevicePath.File, &NameGuid);\r | |
1044 | mFvDevicePath.End.Type = EFI_END_ENTIRE_DEVICE_PATH;\r | |
1045 | mFvDevicePath.End.SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;\r | |
1046 | SetDevicePathNodeLength (&mFvDevicePath.End, sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
1047 | \r | |
1048 | gDxeCoreLoadedImage->FilePath = CoreDuplicateDevicePath (\r | |
1049 | (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath\r | |
1050 | );\r | |
1051 | gDxeCoreLoadedImage->DeviceHandle = FvHandle;\r | |
1052 | }\r | |
1053 | }\r | |
1054 | } else if (Type == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r | |
bbc0f1bb | 1055 | //\r |
1056 | // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already \r | |
1057 | // been extracted.\r | |
1058 | //\r | |
1059 | if (FvFoundInHobFv2 (FvHandle, &NameGuid)) {\r | |
1060 | continue;\r | |
1061 | }\r | |
28a00297 | 1062 | //\r |
1063 | // Found a firmware volume image. Produce a firmware volume block\r | |
1064 | // protocol for it so it gets dispatched from. This is usually a \r | |
1065 | // capsule.\r | |
1066 | //\r | |
1067 | CoreProcessFvImageFile (Fv, FvHandle, &NameGuid);\r | |
1068 | } else {\r | |
1069 | //\r | |
1070 | // Transition driver from Undiscovered to Discovered state\r | |
1071 | //\r | |
1072 | CoreAddToDriverList (Fv, FvHandle, &NameGuid);\r | |
1073 | }\r | |
1074 | }\r | |
1075 | } while (!EFI_ERROR (GetNextFileStatus));\r | |
1076 | }\r | |
1077 | \r | |
1078 | //\r | |
1079 | // Read the array of GUIDs from the Apriori file if it is present in the firmware volume\r | |
1080 | //\r | |
1081 | AprioriFile = NULL;\r | |
1082 | Status = Fv->ReadSection (\r | |
1083 | Fv,\r | |
1084 | &gAprioriGuid,\r | |
1085 | EFI_SECTION_RAW,\r | |
1086 | 0,\r | |
1087 | (VOID **)&AprioriFile,\r | |
1088 | &SizeOfBuffer,\r | |
1089 | &AuthenticationStatus\r | |
1090 | );\r | |
1091 | if (!EFI_ERROR (Status)) {\r | |
1092 | AprioriEntryCount = SizeOfBuffer / sizeof (EFI_GUID);\r | |
1093 | } else {\r | |
1094 | AprioriEntryCount = 0;\r | |
1095 | }\r | |
1096 | \r | |
1097 | //\r | |
1098 | // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes\r | |
1099 | // drivers not in the current FV and these must be skipped since the a priori list\r | |
1100 | // is only valid for the FV that it resided in.\r | |
1101 | //\r | |
1102 | CoreAcquireDispatcherLock ();\r | |
1103 | \r | |
1104 | for (Index = 0; Index < AprioriEntryCount; Index++) {\r | |
1105 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
1106 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
1107 | if (CompareGuid (&DriverEntry->FileName, &AprioriFile[Index]) &&\r | |
1108 | (FvHandle == DriverEntry->FvHandle)) {\r | |
1109 | DriverEntry->Dependent = FALSE;\r | |
1110 | DriverEntry->Scheduled = TRUE;\r | |
1111 | InsertTailList (&mScheduledQueue, &DriverEntry->ScheduledLink);\r | |
1112 | break;\r | |
1113 | }\r | |
1114 | }\r | |
1115 | }\r | |
1116 | \r | |
1117 | CoreReleaseDispatcherLock ();\r | |
1118 | \r | |
1119 | //\r | |
1120 | // Free data allocated by Fv->ReadSection () \r | |
1121 | //\r | |
1122 | CoreFreePool (AprioriFile); \r | |
1123 | }\r | |
1124 | }\r | |
1125 | \r | |
1126 | \r | |
28a00297 | 1127 | \r |
162ed594 | 1128 | /**\r |
28a00297 | 1129 | Initialize the dispatcher. Initialize the notification function that runs when\r |
1130 | a FV protocol is added to the system.\r | |
1131 | \r | |
162ed594 | 1132 | **/\r |
1133 | VOID\r | |
1134 | CoreInitializeDispatcher (\r | |
1135 | VOID\r | |
1136 | )\r | |
28a00297 | 1137 | {\r |
1138 | mFwVolEvent = CoreCreateProtocolNotifyEvent (\r | |
0c2b5da8 | 1139 | &gEfiFirmwareVolume2ProtocolGuid, \r |
28a00297 | 1140 | TPL_CALLBACK,\r |
1141 | CoreFwVolEventProtocolNotify,\r | |
1142 | NULL,\r | |
1143 | &mFwVolEventRegistration,\r | |
1144 | TRUE\r | |
1145 | );\r | |
1146 | }\r | |
1147 | \r | |
1148 | //\r | |
1149 | // Function only used in debug builds\r | |
1150 | //\r | |
162ed594 | 1151 | \r |
1152 | /**\r | |
1153 | Traverse the discovered list for any drivers that were discovered but not loaded\r | |
1154 | because the dependency experessions evaluated to false.\r | |
1155 | \r | |
1156 | **/\r | |
28a00297 | 1157 | VOID\r |
1158 | CoreDisplayDiscoveredNotDispatched (\r | |
1159 | VOID\r | |
1160 | )\r | |
28a00297 | 1161 | {\r |
1162 | LIST_ENTRY *Link;\r | |
1163 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
1164 | \r | |
1165 | for (Link = mDiscoveredList.ForwardLink;Link !=&mDiscoveredList; Link = Link->ForwardLink) {\r | |
1166 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
1167 | if (DriverEntry->Dependent) {\r | |
162ed594 | 1168 | DEBUG ((DEBUG_LOAD, "Driver %g was discovered but not loaded!!\n", &DriverEntry->FileName));\r |
28a00297 | 1169 | }\r |
1170 | }\r | |
1171 | }\r |