4 Step #1 - When a FV protocol is added to the system every driver in the FV
5 is added to the mDiscoveredList. The Before, and After Depex are
6 pre-processed as drivers are added to the mDiscoveredList. If an Apriori
7 file exists in the FV those drivers are addeded to the
8 mScheduledQueue. The mFvHandleList is used to make sure a
9 FV is only processed once.
11 Step #2 - Dispatch. Remove driver from the mScheduledQueue and load and
12 start it. After mScheduledQueue is drained check the
13 mDiscoveredList to see if any item has a Depex that is ready to
14 be placed on the mScheduledQueue.
16 Step #3 - Adding to the mScheduledQueue requires that you process Before
17 and After dependencies. This is done recursively as the call to add
18 to the mScheduledQueue checks for Before and recursively adds
19 all Befores. It then addes the item that was passed in and then
20 processess the After dependecies by recursively calling the routine.
23 The rules for the dispatcher are similar to the DXE dispatcher.
25 The rules for DXE dispatcher are in chapter 10 of the DXE CIS. Figure 10-3
26 is the state diagram for the DXE dispatcher
28 Depex - Dependency Expresion.
30 Copyright (c) 2014, Hewlett-Packard Development Company, L.P.
31 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
32 Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
34 SPDX-License-Identifier: BSD-2-Clause-Patent
38 #include "StandaloneMmCore.h"
41 // MM Dispatcher Data structures
43 #define KNOWN_HANDLE_SIGNATURE SIGNATURE_32('k','n','o','w')
47 LIST_ENTRY Link
; // mFvHandleList
52 // Function Prototypes
56 MmCoreFfsFindMmDriver (
57 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
61 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
62 must add any driver with a before dependency on InsertedDriverEntry first.
63 You do this by recursively calling this routine. After all the Befores are
64 processed you can add InsertedDriverEntry to the mScheduledQueue.
65 Then you can add any driver with an After dependency on InsertedDriverEntry
66 by recursively calling this routine.
68 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
72 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
73 IN EFI_MM_DRIVER_ENTRY
*InsertedDriverEntry
77 // The Driver List contains one copy of every driver that has been discovered.
78 // Items are never removed from the driver list. List of EFI_MM_DRIVER_ENTRY
80 LIST_ENTRY mDiscoveredList
= INITIALIZE_LIST_HEAD_VARIABLE (mDiscoveredList
);
83 // Queue of drivers that are ready to dispatch. This queue is a subset of the
84 // mDiscoveredList.list of EFI_MM_DRIVER_ENTRY.
86 LIST_ENTRY mScheduledQueue
= INITIALIZE_LIST_HEAD_VARIABLE (mScheduledQueue
);
89 // List of handles who's Fv's have been parsed and added to the mFwDriverList.
91 LIST_ENTRY mFvHandleList
= INITIALIZE_LIST_HEAD_VARIABLE (mFvHandleList
);
94 // Flag for the MM Dispacher. TRUE if dispatcher is execuing.
96 BOOLEAN gDispatcherRunning
= FALSE
;
99 // Flag for the MM Dispacher. TRUE if there is one or more MM drivers ready to be dispatched
101 BOOLEAN gRequestDispatch
= FALSE
;
104 // The global variable is defined for Loading modules at fixed address feature to track the MM code
105 // memory range usage. It is a bit mapped array in which every bit indicates the correspoding
106 // memory page available or not.
108 GLOBAL_REMOVE_IF_UNREFERENCED UINT64
*mMmCodeMemoryRangeUsageBitMap
=NULL
;
111 To check memory usage bit map array to figure out if the memory range in which the image will be loaded
112 is available or not. If memory range is avaliable, the function will mark the correponding bits to 1
113 which indicates the memory range is used. The function is only invoked when load modules at fixed address
116 @param ImageBase The base addres the image will be loaded at.
117 @param ImageSize The size of the image
119 @retval EFI_SUCCESS The memory range the image will be loaded in is available
120 @retval EFI_NOT_FOUND The memory range the image will be loaded in is not available
123 CheckAndMarkFixLoadingMemoryUsageBitMap (
124 IN EFI_PHYSICAL_ADDRESS ImageBase
,
128 UINT32 MmCodePageNumber
;
130 EFI_PHYSICAL_ADDRESS MmCodeBase
;
131 UINTN BaseOffsetPageNumber
;
132 UINTN TopOffsetPageNumber
;
136 // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressMmCodePageNumber
138 MmCodePageNumber
= 0;
139 MmCodeSize
= EFI_PAGES_TO_SIZE (MmCodePageNumber
);
140 MmCodeBase
= gLoadModuleAtFixAddressMmramBase
;
143 // If the memory usage bit map is not initialized, do it. Every bit in the array
144 // indicate the status of the corresponding memory page, available or not
146 if (mMmCodeMemoryRangeUsageBitMap
== NULL
) {
147 mMmCodeMemoryRangeUsageBitMap
= AllocateZeroPool (((MmCodePageNumber
/ 64) + 1) * sizeof (UINT64
));
151 // If the Dxe code memory range is not allocated or the bit map array allocation failed, return EFI_NOT_FOUND
153 if (mMmCodeMemoryRangeUsageBitMap
== NULL
) {
154 return EFI_NOT_FOUND
;
158 // see if the memory range for loading the image is in the MM code range.
160 if (MmCodeBase
+ MmCodeSize
< ImageBase
+ ImageSize
|| MmCodeBase
> ImageBase
) {
161 return EFI_NOT_FOUND
;
165 // Test if the memory is avalaible or not.
167 BaseOffsetPageNumber
= (UINTN
)EFI_SIZE_TO_PAGES ((UINT32
)(ImageBase
- MmCodeBase
));
168 TopOffsetPageNumber
= (UINTN
)EFI_SIZE_TO_PAGES ((UINT32
)(ImageBase
+ ImageSize
- MmCodeBase
));
169 for (Index
= BaseOffsetPageNumber
; Index
< TopOffsetPageNumber
; Index
++) {
170 if ((mMmCodeMemoryRangeUsageBitMap
[Index
/ 64] & LShiftU64 (1, (Index
% 64))) != 0) {
172 // This page is already used.
174 return EFI_NOT_FOUND
;
179 // Being here means the memory range is available. So mark the bits for the memory range
181 for (Index
= BaseOffsetPageNumber
; Index
< TopOffsetPageNumber
; Index
++) {
182 mMmCodeMemoryRangeUsageBitMap
[Index
/ 64] |= LShiftU64 (1, (Index
% 64));
188 Get the fixed loading address from image header assigned by build tool. This function only be called
189 when Loading module at Fixed address feature enabled.
191 @param ImageContext Pointer to the image context structure that describes the PE/COFF
192 image that needs to be examined by this function.
193 @retval EFI_SUCCESS An fixed loading address is assigned to this image by build tools .
194 @retval EFI_NOT_FOUND The image has no assigned fixed loadding address.
198 GetPeCoffImageFixLoadingAssignedAddress(
199 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
202 UINTN SectionHeaderOffset
;
204 EFI_IMAGE_SECTION_HEADER SectionHeader
;
205 EFI_IMAGE_OPTIONAL_HEADER_UNION
*ImgHdr
;
206 EFI_PHYSICAL_ADDRESS FixLoadingAddress
;
209 UINT16 NumberOfSections
;
210 UINT64 ValueInSectionHeader
;
212 FixLoadingAddress
= 0;
213 Status
= EFI_NOT_FOUND
;
216 // Get PeHeader pointer
218 ImgHdr
= (EFI_IMAGE_OPTIONAL_HEADER_UNION
*)((CHAR8
* )ImageContext
->Handle
+ ImageContext
->PeCoffHeaderOffset
);
219 SectionHeaderOffset
= ImageContext
->PeCoffHeaderOffset
+ sizeof (UINT32
) + sizeof (EFI_IMAGE_FILE_HEADER
) +
220 ImgHdr
->Pe32
.FileHeader
.SizeOfOptionalHeader
;
221 NumberOfSections
= ImgHdr
->Pe32
.FileHeader
.NumberOfSections
;
224 // Get base address from the first section header that doesn't point to code section.
226 for (Index
= 0; Index
< NumberOfSections
; Index
++) {
228 // Read section header from file
230 Size
= sizeof (EFI_IMAGE_SECTION_HEADER
);
231 Status
= ImageContext
->ImageRead (
232 ImageContext
->Handle
,
237 if (EFI_ERROR (Status
)) {
241 Status
= EFI_NOT_FOUND
;
243 if ((SectionHeader
.Characteristics
& EFI_IMAGE_SCN_CNT_CODE
) == 0) {
245 // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields
246 // in the first section header that doesn't point to code section in image header. So there
247 // is an assumption that when the feature is enabled, if a module with a loading address
248 // assigned by tools, the PointerToRelocations & PointerToLineNumbers fields should not be
249 // Zero, or else, these 2 fields should be set to Zero
251 ValueInSectionHeader
= ReadUnaligned64 ((UINT64
*)&SectionHeader
.PointerToRelocations
);
252 if (ValueInSectionHeader
!= 0) {
254 // Found first section header that doesn't point to code section in which build tool saves the
255 // offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
257 FixLoadingAddress
= (EFI_PHYSICAL_ADDRESS
)(gLoadModuleAtFixAddressMmramBase
+ (INT64
)ValueInSectionHeader
);
259 // Check if the memory range is available.
261 Status
= CheckAndMarkFixLoadingMemoryUsageBitMap (FixLoadingAddress
, (UINTN
)(ImageContext
->ImageSize
+ ImageContext
->SectionAlignment
));
262 if (!EFI_ERROR(Status
)) {
264 // The assigned address is valid. Return the specified loading address
266 ImageContext
->ImageAddress
= FixLoadingAddress
;
271 SectionHeaderOffset
+= sizeof (EFI_IMAGE_SECTION_HEADER
);
273 DEBUG ((DEBUG_INFO
|DEBUG_LOAD
, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r\n",
274 FixLoadingAddress
, Status
));
278 Loads an EFI image into SMRAM.
280 @param DriverEntry EFI_MM_DRIVER_ENTRY instance
288 IN OUT EFI_MM_DRIVER_ENTRY
*DriverEntry
293 EFI_PHYSICAL_ADDRESS DstBuffer
;
294 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
296 DEBUG ((DEBUG_INFO
, "MmLoadImage - %g\n", &DriverEntry
->FileName
));
298 Status
= EFI_SUCCESS
;
301 // Initialize ImageContext
303 ImageContext
.Handle
= DriverEntry
->Pe32Data
;
304 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
307 // Get information about the image being loaded
309 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
310 if (EFI_ERROR (Status
)) {
314 PageCount
= (UINTN
)EFI_SIZE_TO_PAGES ((UINTN
)ImageContext
.ImageSize
+ ImageContext
.SectionAlignment
);
315 DstBuffer
= (UINTN
)(-1);
317 Status
= MmAllocatePages (
319 EfiRuntimeServicesCode
,
323 if (EFI_ERROR (Status
)) {
327 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)DstBuffer
;
330 // Align buffer on section boundry
332 ImageContext
.ImageAddress
+= ImageContext
.SectionAlignment
- 1;
333 ImageContext
.ImageAddress
&= ~((EFI_PHYSICAL_ADDRESS
)(ImageContext
.SectionAlignment
- 1));
336 // Load the image to our new buffer
338 Status
= PeCoffLoaderLoadImage (&ImageContext
);
339 if (EFI_ERROR (Status
)) {
340 MmFreePages (DstBuffer
, PageCount
);
345 // Relocate the image in our new buffer
347 Status
= PeCoffLoaderRelocateImage (&ImageContext
);
348 if (EFI_ERROR (Status
)) {
349 MmFreePages (DstBuffer
, PageCount
);
354 // Flush the instruction cache so the image data are written before we execute it
356 InvalidateInstructionCacheRange ((VOID
*)(UINTN
) ImageContext
.ImageAddress
, (UINTN
) ImageContext
.ImageSize
);
359 // Save Image EntryPoint in DriverEntry
361 DriverEntry
->ImageEntryPoint
= ImageContext
.EntryPoint
;
362 DriverEntry
->ImageBuffer
= DstBuffer
;
363 DriverEntry
->NumberOfPage
= PageCount
;
365 if (mEfiSystemTable
!= NULL
) {
366 Status
= mEfiSystemTable
->BootServices
->AllocatePool (
368 sizeof (EFI_LOADED_IMAGE_PROTOCOL
),
369 (VOID
**)&DriverEntry
->LoadedImage
371 if (EFI_ERROR (Status
)) {
372 MmFreePages (DstBuffer
, PageCount
);
376 ZeroMem (DriverEntry
->LoadedImage
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
));
378 // Fill in the remaining fields of the Loaded Image Protocol instance.
379 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
381 DriverEntry
->LoadedImage
->Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
382 DriverEntry
->LoadedImage
->ParentHandle
= NULL
;
383 DriverEntry
->LoadedImage
->SystemTable
= mEfiSystemTable
;
384 DriverEntry
->LoadedImage
->DeviceHandle
= NULL
;
385 DriverEntry
->LoadedImage
->FilePath
= NULL
;
387 DriverEntry
->LoadedImage
->ImageBase
= (VOID
*)(UINTN
)DriverEntry
->ImageBuffer
;
388 DriverEntry
->LoadedImage
->ImageSize
= ImageContext
.ImageSize
;
389 DriverEntry
->LoadedImage
->ImageCodeType
= EfiRuntimeServicesCode
;
390 DriverEntry
->LoadedImage
->ImageDataType
= EfiRuntimeServicesData
;
393 // Create a new image handle in the UEFI handle database for the MM Driver
395 DriverEntry
->ImageHandle
= NULL
;
396 Status
= mEfiSystemTable
->BootServices
->InstallMultipleProtocolInterfaces (
397 &DriverEntry
->ImageHandle
,
398 &gEfiLoadedImageProtocolGuid
,
399 DriverEntry
->LoadedImage
,
405 // Print the load address and the PDB file name if it is available
411 CHAR8 EfiFileName
[256];
413 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
,
414 "Loading MM driver at 0x%11p EntryPoint=0x%11p ",
415 (VOID
*)(UINTN
) ImageContext
.ImageAddress
,
416 FUNCTION_ENTRY_POINT (ImageContext
.EntryPoint
)));
419 // Print Module Name by Pdb file path.
420 // Windows and Unix style file path are all trimmed correctly.
422 if (ImageContext
.PdbPointer
!= NULL
) {
424 for (Index
= 0; ImageContext
.PdbPointer
[Index
] != 0; Index
++) {
425 if ((ImageContext
.PdbPointer
[Index
] == '\\') || (ImageContext
.PdbPointer
[Index
] == '/')) {
426 StartIndex
= Index
+ 1;
431 // Copy the PDB file name to our temporary string, and replace .pdb with .efi
432 // The PDB file name is limited in the range of 0~255.
433 // If the length is bigger than 255, trim the redudant characters to avoid overflow in array boundary.
435 for (Index
= 0; Index
< sizeof (EfiFileName
) - 4; Index
++) {
436 EfiFileName
[Index
] = ImageContext
.PdbPointer
[Index
+ StartIndex
];
437 if (EfiFileName
[Index
] == 0) {
438 EfiFileName
[Index
] = '.';
440 if (EfiFileName
[Index
] == '.') {
441 EfiFileName
[Index
+ 1] = 'e';
442 EfiFileName
[Index
+ 2] = 'f';
443 EfiFileName
[Index
+ 3] = 'i';
444 EfiFileName
[Index
+ 4] = 0;
449 if (Index
== sizeof (EfiFileName
) - 4) {
450 EfiFileName
[Index
] = 0;
452 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "%a", EfiFileName
));
454 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "\n"));
462 Preprocess dependency expression and update DriverEntry to reflect the
463 state of Before and After dependencies. If DriverEntry->Before
464 or DriverEntry->After is set it will never be cleared.
466 @param DriverEntry DriverEntry element to update .
468 @retval EFI_SUCCESS It always works.
473 IN EFI_MM_DRIVER_ENTRY
*DriverEntry
478 Iterator
= DriverEntry
->Depex
;
479 DriverEntry
->Dependent
= TRUE
;
481 if (*Iterator
== EFI_DEP_BEFORE
) {
482 DriverEntry
->Before
= TRUE
;
483 } else if (*Iterator
== EFI_DEP_AFTER
) {
484 DriverEntry
->After
= TRUE
;
487 if (DriverEntry
->Before
|| DriverEntry
->After
) {
488 CopyMem (&DriverEntry
->BeforeAfterGuid
, Iterator
+ 1, sizeof (EFI_GUID
));
495 Read Depex and pre-process the Depex for Before and After. If Section Extraction
496 protocol returns an error via ReadSection defer the reading of the Depex.
498 @param DriverEntry Driver to work on.
500 @retval EFI_SUCCESS Depex read and preprossesed
501 @retval EFI_PROTOCOL_ERROR The section extraction protocol returned an error
502 and Depex reading needs to be retried.
503 @retval Error DEPEX not found.
507 MmGetDepexSectionAndPreProccess (
508 IN EFI_MM_DRIVER_ENTRY
*DriverEntry
516 if (DriverEntry
->Depex
== NULL
) {
517 Status
= EFI_NOT_FOUND
;
519 Status
= EFI_SUCCESS
;
521 if (EFI_ERROR (Status
)) {
522 if (Status
== EFI_PROTOCOL_ERROR
) {
524 // The section extraction protocol failed so set protocol error flag
526 DriverEntry
->DepexProtocolError
= TRUE
;
529 // If no Depex assume depend on all architectural protocols
531 DriverEntry
->Depex
= NULL
;
532 DriverEntry
->Dependent
= TRUE
;
533 DriverEntry
->DepexProtocolError
= FALSE
;
537 // Set Before and After state information based on Depex
538 // Driver will be put in Dependent state
540 MmPreProcessDepex (DriverEntry
);
541 DriverEntry
->DepexProtocolError
= FALSE
;
548 This is the main Dispatcher for MM and it exits when there are no more
549 drivers to run. Drain the mScheduledQueue and load and start a PE
550 image for each driver. Search the mDiscoveredList to see if any driver can
551 be placed on the mScheduledQueue. If no drivers are placed on the
552 mScheduledQueue exit the function.
554 @retval EFI_SUCCESS All of the MM Drivers that could be dispatched
555 have been run and the MM Entry Point has been
557 @retval EFI_NOT_READY The MM Driver that registered the MM Entry Point
559 @retval EFI_NOT_FOUND There are no MM Drivers available to be dispatched.
560 @retval EFI_ALREADY_STARTED The MM Dispatcher is already running
570 EFI_MM_DRIVER_ENTRY
*DriverEntry
;
573 DEBUG ((DEBUG_INFO
, "MmDispatcher\n"));
575 if (!gRequestDispatch
) {
576 DEBUG ((DEBUG_INFO
, " !gRequestDispatch\n"));
577 return EFI_NOT_FOUND
;
580 if (gDispatcherRunning
) {
581 DEBUG ((DEBUG_INFO
, " gDispatcherRunning\n"));
583 // If the dispatcher is running don't let it be restarted.
585 return EFI_ALREADY_STARTED
;
588 gDispatcherRunning
= TRUE
;
592 // Drain the Scheduled Queue
594 DEBUG ((DEBUG_INFO
, " Drain the Scheduled Queue\n"));
595 while (!IsListEmpty (&mScheduledQueue
)) {
597 mScheduledQueue
.ForwardLink
,
600 EFI_MM_DRIVER_ENTRY_SIGNATURE
602 DEBUG ((DEBUG_INFO
, " DriverEntry (Scheduled) - %g\n", &DriverEntry
->FileName
));
605 // Load the MM Driver image into memory. If the Driver was transitioned from
606 // Untrused to Scheduled it would have already been loaded so we may need to
607 // skip the LoadImage
609 if (DriverEntry
->ImageHandle
== NULL
) {
610 Status
= MmLoadImage (DriverEntry
);
613 // Update the driver state to reflect that it's been loaded
615 if (EFI_ERROR (Status
)) {
617 // The MM Driver could not be loaded, and do not attempt to load or start it again.
618 // Take driver from Scheduled to Initialized.
620 DriverEntry
->Initialized
= TRUE
;
621 DriverEntry
->Scheduled
= FALSE
;
622 RemoveEntryList (&DriverEntry
->ScheduledLink
);
625 // If it's an error don't try the StartImage
631 DriverEntry
->Scheduled
= FALSE
;
632 DriverEntry
->Initialized
= TRUE
;
633 RemoveEntryList (&DriverEntry
->ScheduledLink
);
636 // For each MM driver, pass NULL as ImageHandle
638 if (mEfiSystemTable
== NULL
) {
639 DEBUG ((DEBUG_INFO
, "StartImage - 0x%x (Standalone Mode)\n", DriverEntry
->ImageEntryPoint
));
640 Status
= ((MM_IMAGE_ENTRY_POINT
)(UINTN
)DriverEntry
->ImageEntryPoint
) (DriverEntry
->ImageHandle
, &gMmCoreMmst
);
642 DEBUG ((DEBUG_INFO
, "StartImage - 0x%x (Tradition Mode)\n", DriverEntry
->ImageEntryPoint
));
643 Status
= ((EFI_IMAGE_ENTRY_POINT
)(UINTN
)DriverEntry
->ImageEntryPoint
) (
644 DriverEntry
->ImageHandle
,
648 if (EFI_ERROR(Status
)) {
649 DEBUG ((DEBUG_INFO
, "StartImage Status - %r\n", Status
));
650 MmFreePages(DriverEntry
->ImageBuffer
, DriverEntry
->NumberOfPage
);
655 // Search DriverList for items to place on Scheduled Queue
657 DEBUG ((DEBUG_INFO
, " Search DriverList for items to place on Scheduled Queue\n"));
659 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
660 DriverEntry
= CR (Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
661 DEBUG ((DEBUG_INFO
, " DriverEntry (Discovered) - %g\n", &DriverEntry
->FileName
));
663 if (DriverEntry
->DepexProtocolError
) {
665 // If Section Extraction Protocol did not let the Depex be read before retry the read
667 Status
= MmGetDepexSectionAndPreProccess (DriverEntry
);
670 if (DriverEntry
->Dependent
) {
671 if (MmIsSchedulable (DriverEntry
)) {
672 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
677 } while (ReadyToRun
);
680 // If there is no more MM driver to dispatch, stop the dispatch request
682 DEBUG ((DEBUG_INFO
, " no more MM driver to dispatch, stop the dispatch request\n"));
683 gRequestDispatch
= FALSE
;
684 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
685 DriverEntry
= CR (Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
686 DEBUG ((DEBUG_INFO
, " DriverEntry (Discovered) - %g\n", &DriverEntry
->FileName
));
688 if (!DriverEntry
->Initialized
) {
690 // We have MM driver pending to dispatch
692 gRequestDispatch
= TRUE
;
697 gDispatcherRunning
= FALSE
;
703 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
704 must add any driver with a before dependency on InsertedDriverEntry first.
705 You do this by recursively calling this routine. After all the Befores are
706 processed you can add InsertedDriverEntry to the mScheduledQueue.
707 Then you can add any driver with an After dependency on InsertedDriverEntry
708 by recursively calling this routine.
710 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
714 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
715 IN EFI_MM_DRIVER_ENTRY
*InsertedDriverEntry
719 EFI_MM_DRIVER_ENTRY
*DriverEntry
;
722 // Process Before Dependency
724 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
725 DriverEntry
= CR(Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
726 if (DriverEntry
->Before
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
727 DEBUG ((DEBUG_DISPATCH
, "Evaluate MM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
728 DEBUG ((DEBUG_DISPATCH
, " BEFORE FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
729 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
731 // Recursively process BEFORE
733 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
734 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
736 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
742 // Convert driver from Dependent to Scheduled state
745 InsertedDriverEntry
->Dependent
= FALSE
;
746 InsertedDriverEntry
->Scheduled
= TRUE
;
747 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
751 // Process After Dependency
753 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
754 DriverEntry
= CR(Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
755 if (DriverEntry
->After
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
756 DEBUG ((DEBUG_DISPATCH
, "Evaluate MM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
757 DEBUG ((DEBUG_DISPATCH
, " AFTER FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
758 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
760 // Recursively process AFTER
762 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
763 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
765 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
772 Return TRUE if the Fv has been processed, FALSE if not.
774 @param FvHandle The handle of a FV that's being tested
776 @retval TRUE Fv protocol on FvHandle has been processed
777 @retval FALSE Fv protocol on FvHandle has not yet been
783 IN EFI_HANDLE FvHandle
787 KNOWN_HANDLE
*KnownHandle
;
789 for (Link
= mFvHandleList
.ForwardLink
; Link
!= &mFvHandleList
; Link
= Link
->ForwardLink
) {
790 KnownHandle
= CR (Link
, KNOWN_HANDLE
, Link
, KNOWN_HANDLE_SIGNATURE
);
791 if (KnownHandle
->Handle
== FvHandle
) {
799 Remember that Fv protocol on FvHandle has had it's drivers placed on the
800 mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are
801 never removed/freed from the mFvHandleList.
803 @param FvHandle The handle of a FV that has been processed
807 FvIsBeingProcesssed (
808 IN EFI_HANDLE FvHandle
811 KNOWN_HANDLE
*KnownHandle
;
813 DEBUG ((DEBUG_INFO
, "FvIsBeingProcesssed - 0x%08x\n", FvHandle
));
815 KnownHandle
= AllocatePool (sizeof (KNOWN_HANDLE
));
816 ASSERT (KnownHandle
!= NULL
);
818 KnownHandle
->Signature
= KNOWN_HANDLE_SIGNATURE
;
819 KnownHandle
->Handle
= FvHandle
;
820 InsertTailList (&mFvHandleList
, &KnownHandle
->Link
);
824 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
825 and initilize any state variables. Read the Depex from the FV and store it
826 in DriverEntry. Pre-process the Depex to set the Before and After state.
827 The Discovered list is never free'ed and contains booleans that represent the
828 other possible MM driver states.
830 @param Fv Fv protocol, needed to read Depex info out of
832 @param FvHandle Handle for Fv, needed in the
833 EFI_MM_DRIVER_ENTRY so that the PE image can be
834 read out of the FV at a later time.
835 @param DriverName Name of driver to add to mDiscoveredList.
837 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
838 @retval EFI_ALREADY_STARTED The driver has already been started. Only one
839 DriverName may be active in the system at any one
845 IN EFI_HANDLE FvHandle
,
847 IN UINTN Pe32DataSize
,
850 IN EFI_GUID
*DriverName
853 EFI_MM_DRIVER_ENTRY
*DriverEntry
;
855 DEBUG ((DEBUG_INFO
, "MmAddToDriverList - %g (0x%08x)\n", DriverName
, Pe32Data
));
858 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
861 DriverEntry
= AllocateZeroPool (sizeof (EFI_MM_DRIVER_ENTRY
));
862 ASSERT (DriverEntry
!= NULL
);
864 DriverEntry
->Signature
= EFI_MM_DRIVER_ENTRY_SIGNATURE
;
865 CopyGuid (&DriverEntry
->FileName
, DriverName
);
866 DriverEntry
->FvHandle
= FvHandle
;
867 DriverEntry
->Pe32Data
= Pe32Data
;
868 DriverEntry
->Pe32DataSize
= Pe32DataSize
;
869 DriverEntry
->Depex
= Depex
;
870 DriverEntry
->DepexSize
= DepexSize
;
872 MmGetDepexSectionAndPreProccess (DriverEntry
);
874 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
875 gRequestDispatch
= TRUE
;
881 Traverse the discovered list for any drivers that were discovered but not loaded
882 because the dependency experessions evaluated to false.
886 MmDisplayDiscoveredNotDispatched (
891 EFI_MM_DRIVER_ENTRY
*DriverEntry
;
893 for (Link
= mDiscoveredList
.ForwardLink
;Link
!=&mDiscoveredList
; Link
= Link
->ForwardLink
) {
894 DriverEntry
= CR (Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
895 if (DriverEntry
->Dependent
) {
896 DEBUG ((DEBUG_LOAD
, "MM Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));