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 added to the
8 mScheduledQueue. The mFwVolList 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 Depexes and recursively
19 adds all Before Depexes. It then adds the item that was passed in
20 and then processess the After dependencies by recursively calling
24 The rules for the dispatcher are similar to the DXE dispatcher.
26 The rules for DXE dispatcher are in chapter 10 of the DXE CIS. Figure 10-3
27 is the state diagram for the DXE dispatcher
29 Depex - Dependency Expresion.
31 Copyright (c) 2014, Hewlett-Packard Development Company, L.P.
32 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
33 Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.<BR>
35 SPDX-License-Identifier: BSD-2-Clause-Patent
39 #include "StandaloneMmCore.h"
42 // MM Dispatcher Data structures
44 #define KNOWN_FWVOL_SIGNATURE SIGNATURE_32('k','n','o','w')
48 LIST_ENTRY Link
; // mFwVolList
49 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
53 // Function Prototypes
57 MmCoreFfsFindMmDriver (
58 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
62 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
63 must add any driver with a before dependency on InsertedDriverEntry first.
64 You do this by recursively calling this routine. After all the Before Depexes
65 are processed you can add InsertedDriverEntry to the mScheduledQueue.
66 Then you can add any driver with an After dependency on InsertedDriverEntry
67 by recursively calling this routine.
69 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
73 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
74 IN EFI_MM_DRIVER_ENTRY
*InsertedDriverEntry
78 // The Driver List contains one copy of every driver that has been discovered.
79 // Items are never removed from the driver list. List of EFI_MM_DRIVER_ENTRY
81 LIST_ENTRY mDiscoveredList
= INITIALIZE_LIST_HEAD_VARIABLE (mDiscoveredList
);
84 // Queue of drivers that are ready to dispatch. This queue is a subset of the
85 // mDiscoveredList.list of EFI_MM_DRIVER_ENTRY.
87 LIST_ENTRY mScheduledQueue
= INITIALIZE_LIST_HEAD_VARIABLE (mScheduledQueue
);
90 // List of firmware volume headers whose containing firmware volumes have been
91 // parsed and added to the mFwDriverList.
93 LIST_ENTRY mFwVolList
= INITIALIZE_LIST_HEAD_VARIABLE (mFwVolList
);
96 // Flag for the MM Dispacher. TRUE if dispatcher is executing.
98 BOOLEAN gDispatcherRunning
= FALSE
;
101 // Flag for the MM Dispacher. TRUE if there is one or more MM drivers ready to be dispatched
103 BOOLEAN gRequestDispatch
= FALSE
;
106 // The global variable is defined for Loading modules at fixed address feature to track the MM code
107 // memory range usage. It is a bit mapped array in which every bit indicates the correspoding
108 // memory page available or not.
110 GLOBAL_REMOVE_IF_UNREFERENCED UINT64
*mMmCodeMemoryRangeUsageBitMap
=NULL
;
113 To check memory usage bit map array to figure out if the memory range in which the image will be loaded
114 is available or not. If memory range is avaliable, the function will mark the corresponding bits to 1
115 which indicates the memory range is used. The function is only invoked when load modules at fixed address
118 @param ImageBase The base addres the image will be loaded at.
119 @param ImageSize The size of the image
121 @retval EFI_SUCCESS The memory range the image will be loaded in is available
122 @retval EFI_NOT_FOUND The memory range the image will be loaded in is not available
125 CheckAndMarkFixLoadingMemoryUsageBitMap (
126 IN EFI_PHYSICAL_ADDRESS ImageBase
,
130 UINT32 MmCodePageNumber
;
132 EFI_PHYSICAL_ADDRESS MmCodeBase
;
133 UINTN BaseOffsetPageNumber
;
134 UINTN TopOffsetPageNumber
;
138 // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressMmCodePageNumber
140 MmCodePageNumber
= 0;
141 MmCodeSize
= EFI_PAGES_TO_SIZE (MmCodePageNumber
);
142 MmCodeBase
= gLoadModuleAtFixAddressMmramBase
;
145 // If the memory usage bit map is not initialized, do it. Every bit in the array
146 // indicate the status of the corresponding memory page, available or not
148 if (mMmCodeMemoryRangeUsageBitMap
== NULL
) {
149 mMmCodeMemoryRangeUsageBitMap
= AllocateZeroPool (((MmCodePageNumber
/ 64) + 1) * sizeof (UINT64
));
153 // If the Dxe code memory range is not allocated or the bit map array allocation failed, return EFI_NOT_FOUND
155 if (mMmCodeMemoryRangeUsageBitMap
== NULL
) {
156 return EFI_NOT_FOUND
;
160 // see if the memory range for loading the image is in the MM code range.
162 if (MmCodeBase
+ MmCodeSize
< ImageBase
+ ImageSize
|| MmCodeBase
> ImageBase
) {
163 return EFI_NOT_FOUND
;
167 // Test if the memory is available or not.
169 BaseOffsetPageNumber
= (UINTN
)EFI_SIZE_TO_PAGES ((UINT32
)(ImageBase
- MmCodeBase
));
170 TopOffsetPageNumber
= (UINTN
)EFI_SIZE_TO_PAGES ((UINT32
)(ImageBase
+ ImageSize
- MmCodeBase
));
171 for (Index
= BaseOffsetPageNumber
; Index
< TopOffsetPageNumber
; Index
++) {
172 if ((mMmCodeMemoryRangeUsageBitMap
[Index
/ 64] & LShiftU64 (1, (Index
% 64))) != 0) {
174 // This page is already used.
176 return EFI_NOT_FOUND
;
181 // Being here means the memory range is available. So mark the bits for the memory range
183 for (Index
= BaseOffsetPageNumber
; Index
< TopOffsetPageNumber
; Index
++) {
184 mMmCodeMemoryRangeUsageBitMap
[Index
/ 64] |= LShiftU64 (1, (Index
% 64));
190 Get the fixed loading address from image header assigned by build tool. This function only be called
191 when Loading module at Fixed address feature enabled.
193 @param ImageContext Pointer to the image context structure that describes the PE/COFF
194 image that needs to be examined by this function.
195 @retval EFI_SUCCESS An fixed loading address is assigned to this image by build tools .
196 @retval EFI_NOT_FOUND The image has no assigned fixed loadding address.
200 GetPeCoffImageFixLoadingAssignedAddress(
201 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
204 UINTN SectionHeaderOffset
;
206 EFI_IMAGE_SECTION_HEADER SectionHeader
;
207 EFI_IMAGE_OPTIONAL_HEADER_UNION
*ImgHdr
;
208 EFI_PHYSICAL_ADDRESS FixLoadingAddress
;
211 UINT16 NumberOfSections
;
212 UINT64 ValueInSectionHeader
;
214 FixLoadingAddress
= 0;
215 Status
= EFI_NOT_FOUND
;
218 // Get PeHeader pointer
220 ImgHdr
= (EFI_IMAGE_OPTIONAL_HEADER_UNION
*)((CHAR8
* )ImageContext
->Handle
+ ImageContext
->PeCoffHeaderOffset
);
221 SectionHeaderOffset
= ImageContext
->PeCoffHeaderOffset
+ sizeof (UINT32
) + sizeof (EFI_IMAGE_FILE_HEADER
) +
222 ImgHdr
->Pe32
.FileHeader
.SizeOfOptionalHeader
;
223 NumberOfSections
= ImgHdr
->Pe32
.FileHeader
.NumberOfSections
;
226 // Get base address from the first section header that doesn't point to code section.
228 for (Index
= 0; Index
< NumberOfSections
; Index
++) {
230 // Read section header from file
232 Size
= sizeof (EFI_IMAGE_SECTION_HEADER
);
233 Status
= ImageContext
->ImageRead (
234 ImageContext
->Handle
,
239 if (EFI_ERROR (Status
)) {
243 Status
= EFI_NOT_FOUND
;
245 if ((SectionHeader
.Characteristics
& EFI_IMAGE_SCN_CNT_CODE
) == 0) {
247 // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields
248 // in the first section header that doesn't point to code section in image header. So there
249 // is an assumption that when the feature is enabled, if a module with a loading address
250 // assigned by tools, the PointerToRelocations & PointerToLineNumbers fields should not be
251 // Zero, or else, these 2 fields should be set to Zero
253 ValueInSectionHeader
= ReadUnaligned64 ((UINT64
*)&SectionHeader
.PointerToRelocations
);
254 if (ValueInSectionHeader
!= 0) {
256 // Found first section header that doesn't point to code section in which build tool saves the
257 // offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
259 FixLoadingAddress
= (EFI_PHYSICAL_ADDRESS
)(gLoadModuleAtFixAddressMmramBase
+ (INT64
)ValueInSectionHeader
);
261 // Check if the memory range is available.
263 Status
= CheckAndMarkFixLoadingMemoryUsageBitMap (FixLoadingAddress
, (UINTN
)(ImageContext
->ImageSize
+ ImageContext
->SectionAlignment
));
264 if (!EFI_ERROR(Status
)) {
266 // The assigned address is valid. Return the specified loading address
268 ImageContext
->ImageAddress
= FixLoadingAddress
;
273 SectionHeaderOffset
+= sizeof (EFI_IMAGE_SECTION_HEADER
);
275 DEBUG ((DEBUG_INFO
|DEBUG_LOAD
, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r\n",
276 FixLoadingAddress
, Status
));
280 Loads an EFI image into SMRAM.
282 @param DriverEntry EFI_MM_DRIVER_ENTRY instance
290 IN OUT EFI_MM_DRIVER_ENTRY
*DriverEntry
295 EFI_PHYSICAL_ADDRESS DstBuffer
;
296 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
298 DEBUG ((DEBUG_INFO
, "MmLoadImage - %g\n", &DriverEntry
->FileName
));
300 Status
= EFI_SUCCESS
;
303 // Initialize ImageContext
305 ImageContext
.Handle
= DriverEntry
->Pe32Data
;
306 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
309 // Get information about the image being loaded
311 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
312 if (EFI_ERROR (Status
)) {
316 PageCount
= (UINTN
)EFI_SIZE_TO_PAGES ((UINTN
)ImageContext
.ImageSize
+ ImageContext
.SectionAlignment
);
317 DstBuffer
= (UINTN
)(-1);
319 Status
= MmAllocatePages (
321 EfiRuntimeServicesCode
,
325 if (EFI_ERROR (Status
)) {
329 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)DstBuffer
;
332 // Align buffer on section boundary
334 ImageContext
.ImageAddress
+= ImageContext
.SectionAlignment
- 1;
335 ImageContext
.ImageAddress
&= ~((EFI_PHYSICAL_ADDRESS
)(ImageContext
.SectionAlignment
- 1));
338 // Load the image to our new buffer
340 Status
= PeCoffLoaderLoadImage (&ImageContext
);
341 if (EFI_ERROR (Status
)) {
342 MmFreePages (DstBuffer
, PageCount
);
347 // Relocate the image in our new buffer
349 Status
= PeCoffLoaderRelocateImage (&ImageContext
);
350 if (EFI_ERROR (Status
)) {
351 MmFreePages (DstBuffer
, PageCount
);
356 // Flush the instruction cache so the image data are written before we execute it
358 InvalidateInstructionCacheRange ((VOID
*)(UINTN
) ImageContext
.ImageAddress
, (UINTN
) ImageContext
.ImageSize
);
361 // Save Image EntryPoint in DriverEntry
363 DriverEntry
->ImageEntryPoint
= ImageContext
.EntryPoint
;
364 DriverEntry
->ImageBuffer
= DstBuffer
;
365 DriverEntry
->NumberOfPage
= PageCount
;
367 if (mEfiSystemTable
!= NULL
) {
368 Status
= mEfiSystemTable
->BootServices
->AllocatePool (
370 sizeof (EFI_LOADED_IMAGE_PROTOCOL
),
371 (VOID
**)&DriverEntry
->LoadedImage
373 if (EFI_ERROR (Status
)) {
374 MmFreePages (DstBuffer
, PageCount
);
378 ZeroMem (DriverEntry
->LoadedImage
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
));
380 // Fill in the remaining fields of the Loaded Image Protocol instance.
381 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
383 DriverEntry
->LoadedImage
->Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
384 DriverEntry
->LoadedImage
->ParentHandle
= NULL
;
385 DriverEntry
->LoadedImage
->SystemTable
= mEfiSystemTable
;
386 DriverEntry
->LoadedImage
->DeviceHandle
= NULL
;
387 DriverEntry
->LoadedImage
->FilePath
= NULL
;
389 DriverEntry
->LoadedImage
->ImageBase
= (VOID
*)(UINTN
)DriverEntry
->ImageBuffer
;
390 DriverEntry
->LoadedImage
->ImageSize
= ImageContext
.ImageSize
;
391 DriverEntry
->LoadedImage
->ImageCodeType
= EfiRuntimeServicesCode
;
392 DriverEntry
->LoadedImage
->ImageDataType
= EfiRuntimeServicesData
;
395 // Create a new image handle in the UEFI handle database for the MM Driver
397 DriverEntry
->ImageHandle
= NULL
;
398 Status
= mEfiSystemTable
->BootServices
->InstallMultipleProtocolInterfaces (
399 &DriverEntry
->ImageHandle
,
400 &gEfiLoadedImageProtocolGuid
,
401 DriverEntry
->LoadedImage
,
407 // Print the load address and the PDB file name if it is available
413 CHAR8 EfiFileName
[256];
415 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
,
416 "Loading MM driver at 0x%11p EntryPoint=0x%11p ",
417 (VOID
*)(UINTN
) ImageContext
.ImageAddress
,
418 FUNCTION_ENTRY_POINT (ImageContext
.EntryPoint
)));
421 // Print Module Name by Pdb file path.
422 // Windows and Unix style file path are all trimmed correctly.
424 if (ImageContext
.PdbPointer
!= NULL
) {
426 for (Index
= 0; ImageContext
.PdbPointer
[Index
] != 0; Index
++) {
427 if ((ImageContext
.PdbPointer
[Index
] == '\\') || (ImageContext
.PdbPointer
[Index
] == '/')) {
428 StartIndex
= Index
+ 1;
433 // Copy the PDB file name to our temporary string, and replace .pdb with .efi
434 // The PDB file name is limited in the range of 0~255.
435 // If the length is bigger than 255, trim the redundant characters to avoid overflow in array boundary.
437 for (Index
= 0; Index
< sizeof (EfiFileName
) - 4; Index
++) {
438 EfiFileName
[Index
] = ImageContext
.PdbPointer
[Index
+ StartIndex
];
439 if (EfiFileName
[Index
] == 0) {
440 EfiFileName
[Index
] = '.';
442 if (EfiFileName
[Index
] == '.') {
443 EfiFileName
[Index
+ 1] = 'e';
444 EfiFileName
[Index
+ 2] = 'f';
445 EfiFileName
[Index
+ 3] = 'i';
446 EfiFileName
[Index
+ 4] = 0;
451 if (Index
== sizeof (EfiFileName
) - 4) {
452 EfiFileName
[Index
] = 0;
454 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "%a", EfiFileName
));
456 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "\n"));
464 Preprocess dependency expression and update DriverEntry to reflect the
465 state of Before and After dependencies. If DriverEntry->Before
466 or DriverEntry->After is set it will never be cleared.
468 @param DriverEntry DriverEntry element to update .
470 @retval EFI_SUCCESS It always works.
475 IN EFI_MM_DRIVER_ENTRY
*DriverEntry
480 Iterator
= DriverEntry
->Depex
;
481 DriverEntry
->Dependent
= TRUE
;
483 if (*Iterator
== EFI_DEP_BEFORE
) {
484 DriverEntry
->Before
= TRUE
;
485 } else if (*Iterator
== EFI_DEP_AFTER
) {
486 DriverEntry
->After
= TRUE
;
489 if (DriverEntry
->Before
|| DriverEntry
->After
) {
490 CopyMem (&DriverEntry
->BeforeAfterGuid
, Iterator
+ 1, sizeof (EFI_GUID
));
497 Read Depex and pre-process the Depex for Before and After. If Section Extraction
498 protocol returns an error via ReadSection defer the reading of the Depex.
500 @param DriverEntry Driver to work on.
502 @retval EFI_SUCCESS Depex read and preprossesed
503 @retval EFI_PROTOCOL_ERROR The section extraction protocol returned an error
504 and Depex reading needs to be retried.
505 @retval Error DEPEX not found.
509 MmGetDepexSectionAndPreProccess (
510 IN EFI_MM_DRIVER_ENTRY
*DriverEntry
518 if (DriverEntry
->Depex
== NULL
) {
519 Status
= EFI_NOT_FOUND
;
521 Status
= EFI_SUCCESS
;
523 if (EFI_ERROR (Status
)) {
524 if (Status
== EFI_PROTOCOL_ERROR
) {
526 // The section extraction protocol failed so set protocol error flag
528 DriverEntry
->DepexProtocolError
= TRUE
;
531 // If no Depex assume depend on all architectural protocols
533 DriverEntry
->Depex
= NULL
;
534 DriverEntry
->Dependent
= TRUE
;
535 DriverEntry
->DepexProtocolError
= FALSE
;
539 // Set Before and After state information based on Depex
540 // Driver will be put in Dependent state
542 MmPreProcessDepex (DriverEntry
);
543 DriverEntry
->DepexProtocolError
= FALSE
;
550 This is the main Dispatcher for MM and it exits when there are no more
551 drivers to run. Drain the mScheduledQueue and load and start a PE
552 image for each driver. Search the mDiscoveredList to see if any driver can
553 be placed on the mScheduledQueue. If no drivers are placed on the
554 mScheduledQueue exit the function.
556 @retval EFI_SUCCESS All of the MM Drivers that could be dispatched
557 have been run and the MM Entry Point has been
559 @retval EFI_NOT_READY The MM Driver that registered the MM Entry Point
561 @retval EFI_NOT_FOUND There are no MM Drivers available to be dispatched.
562 @retval EFI_ALREADY_STARTED The MM Dispatcher is already running
572 EFI_MM_DRIVER_ENTRY
*DriverEntry
;
575 DEBUG ((DEBUG_INFO
, "MmDispatcher\n"));
577 if (!gRequestDispatch
) {
578 DEBUG ((DEBUG_INFO
, " !gRequestDispatch\n"));
579 return EFI_NOT_FOUND
;
582 if (gDispatcherRunning
) {
583 DEBUG ((DEBUG_INFO
, " gDispatcherRunning\n"));
585 // If the dispatcher is running don't let it be restarted.
587 return EFI_ALREADY_STARTED
;
590 gDispatcherRunning
= TRUE
;
594 // Drain the Scheduled Queue
596 DEBUG ((DEBUG_INFO
, " Drain the Scheduled Queue\n"));
597 while (!IsListEmpty (&mScheduledQueue
)) {
599 mScheduledQueue
.ForwardLink
,
602 EFI_MM_DRIVER_ENTRY_SIGNATURE
604 DEBUG ((DEBUG_INFO
, " DriverEntry (Scheduled) - %g\n", &DriverEntry
->FileName
));
607 // Load the MM Driver image into memory. If the Driver was transitioned from
608 // Untrusted to Scheduled it would have already been loaded so we may need to
609 // skip the LoadImage
611 if (DriverEntry
->ImageHandle
== NULL
) {
612 Status
= MmLoadImage (DriverEntry
);
615 // Update the driver state to reflect that it's been loaded
617 if (EFI_ERROR (Status
)) {
619 // The MM Driver could not be loaded, and do not attempt to load or start it again.
620 // Take driver from Scheduled to Initialized.
622 DriverEntry
->Initialized
= TRUE
;
623 DriverEntry
->Scheduled
= FALSE
;
624 RemoveEntryList (&DriverEntry
->ScheduledLink
);
627 // If it's an error don't try the StartImage
633 DriverEntry
->Scheduled
= FALSE
;
634 DriverEntry
->Initialized
= TRUE
;
635 RemoveEntryList (&DriverEntry
->ScheduledLink
);
638 // For each MM driver, pass NULL as ImageHandle
640 if (mEfiSystemTable
== NULL
) {
641 DEBUG ((DEBUG_INFO
, "StartImage - 0x%x (Standalone Mode)\n", DriverEntry
->ImageEntryPoint
));
642 Status
= ((MM_IMAGE_ENTRY_POINT
)(UINTN
)DriverEntry
->ImageEntryPoint
) (DriverEntry
->ImageHandle
, &gMmCoreMmst
);
644 DEBUG ((DEBUG_INFO
, "StartImage - 0x%x (Tradition Mode)\n", DriverEntry
->ImageEntryPoint
));
645 Status
= ((EFI_IMAGE_ENTRY_POINT
)(UINTN
)DriverEntry
->ImageEntryPoint
) (
646 DriverEntry
->ImageHandle
,
650 if (EFI_ERROR(Status
)) {
651 DEBUG ((DEBUG_INFO
, "StartImage Status - %r\n", Status
));
652 MmFreePages(DriverEntry
->ImageBuffer
, DriverEntry
->NumberOfPage
);
657 // Search DriverList for items to place on Scheduled Queue
659 DEBUG ((DEBUG_INFO
, " Search DriverList for items to place on Scheduled Queue\n"));
661 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
662 DriverEntry
= CR (Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
663 DEBUG ((DEBUG_INFO
, " DriverEntry (Discovered) - %g\n", &DriverEntry
->FileName
));
665 if (DriverEntry
->DepexProtocolError
) {
667 // If Section Extraction Protocol did not let the Depex be read before retry the read
669 Status
= MmGetDepexSectionAndPreProccess (DriverEntry
);
672 if (DriverEntry
->Dependent
) {
673 if (MmIsSchedulable (DriverEntry
)) {
674 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
679 } while (ReadyToRun
);
682 // If there is no more MM driver to dispatch, stop the dispatch request
684 DEBUG ((DEBUG_INFO
, " no more MM driver to dispatch, stop the dispatch request\n"));
685 gRequestDispatch
= FALSE
;
686 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
687 DriverEntry
= CR (Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
688 DEBUG ((DEBUG_INFO
, " DriverEntry (Discovered) - %g\n", &DriverEntry
->FileName
));
690 if (!DriverEntry
->Initialized
) {
692 // We have MM driver pending to dispatch
694 gRequestDispatch
= TRUE
;
699 gDispatcherRunning
= FALSE
;
705 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
706 must add any driver with a before dependency on InsertedDriverEntry first.
707 You do this by recursively calling this routine. After all the Before Depexes
708 are processed you can add InsertedDriverEntry to the mScheduledQueue.
709 Then you can add any driver with an After dependency on InsertedDriverEntry
710 by recursively calling this routine.
712 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
716 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
717 IN EFI_MM_DRIVER_ENTRY
*InsertedDriverEntry
721 EFI_MM_DRIVER_ENTRY
*DriverEntry
;
724 // Process Before Dependency
726 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
727 DriverEntry
= CR(Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
728 if (DriverEntry
->Before
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
729 DEBUG ((DEBUG_DISPATCH
, "Evaluate MM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
730 DEBUG ((DEBUG_DISPATCH
, " BEFORE FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
731 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
733 // Recursively process BEFORE
735 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
736 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
738 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
744 // Convert driver from Dependent to Scheduled state
747 InsertedDriverEntry
->Dependent
= FALSE
;
748 InsertedDriverEntry
->Scheduled
= TRUE
;
749 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
753 // Process After Dependency
755 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
756 DriverEntry
= CR(Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
757 if (DriverEntry
->After
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
758 DEBUG ((DEBUG_DISPATCH
, "Evaluate MM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
759 DEBUG ((DEBUG_DISPATCH
, " AFTER FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
760 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
762 // Recursively process AFTER
764 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
765 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
767 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
774 Return TRUE if the firmware volume has been processed, FALSE if not.
776 @param FwVolHeader The header of the firmware volume that's being
779 @retval TRUE The firmware volume denoted by FwVolHeader has
781 @retval FALSE The firmware volume denoted by FwVolHeader has
782 not yet been processed
787 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
791 KNOWN_FWVOL
*KnownFwVol
;
793 for (Link
= mFwVolList
.ForwardLink
;
795 Link
= Link
->ForwardLink
) {
796 KnownFwVol
= CR (Link
, KNOWN_FWVOL
, Link
, KNOWN_FWVOL_SIGNATURE
);
797 if (KnownFwVol
->FwVolHeader
== FwVolHeader
) {
805 Remember that the firmware volume denoted by FwVolHeader has had its drivers
806 placed on mDiscoveredList. This function adds entries to mFwVolList. Items
807 are never removed/freed from mFwVolList.
809 @param FwVolHeader The header of the firmware volume that's being
815 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
818 KNOWN_FWVOL
*KnownFwVol
;
820 DEBUG ((DEBUG_INFO
, "FvIsBeingProcessed - 0x%08x\n", FwVolHeader
));
822 KnownFwVol
= AllocatePool (sizeof (KNOWN_FWVOL
));
823 ASSERT (KnownFwVol
!= NULL
);
825 KnownFwVol
->Signature
= KNOWN_FWVOL_SIGNATURE
;
826 KnownFwVol
->FwVolHeader
= FwVolHeader
;
827 InsertTailList (&mFwVolList
, &KnownFwVol
->Link
);
831 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
832 and initialise any state variables. Read the Depex from the FV and store it
833 in DriverEntry. Pre-process the Depex to set the Before and After state.
834 The Discovered list is never freed and contains booleans that represent the
835 other possible MM driver states.
837 @param [in] FwVolHeader Pointer to the formware volume header.
838 @param [in] Pe32Data Pointer to the PE data.
839 @param [in] Pe32DataSize Size of the PE data.
840 @param [in] Depex Pointer to the Depex info.
841 @param [in] DepexSize Size of the Depex info.
842 @param [in] DriverName Name of driver to add to mDiscoveredList.
844 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
848 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
850 IN UINTN Pe32DataSize
,
853 IN EFI_GUID
*DriverName
856 EFI_MM_DRIVER_ENTRY
*DriverEntry
;
858 DEBUG ((DEBUG_INFO
, "MmAddToDriverList - %g (0x%08x)\n", DriverName
, Pe32Data
));
861 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
864 DriverEntry
= AllocateZeroPool (sizeof (EFI_MM_DRIVER_ENTRY
));
865 ASSERT (DriverEntry
!= NULL
);
867 DriverEntry
->Signature
= EFI_MM_DRIVER_ENTRY_SIGNATURE
;
868 CopyGuid (&DriverEntry
->FileName
, DriverName
);
869 DriverEntry
->FwVolHeader
= FwVolHeader
;
870 DriverEntry
->Pe32Data
= Pe32Data
;
871 DriverEntry
->Pe32DataSize
= Pe32DataSize
;
872 DriverEntry
->Depex
= Depex
;
873 DriverEntry
->DepexSize
= DepexSize
;
875 MmGetDepexSectionAndPreProccess (DriverEntry
);
877 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
878 gRequestDispatch
= TRUE
;
884 Traverse the discovered list for any drivers that were discovered but not loaded
885 because the dependency expressions evaluated to false.
889 MmDisplayDiscoveredNotDispatched (
894 EFI_MM_DRIVER_ENTRY
*DriverEntry
;
896 for (Link
= mDiscoveredList
.ForwardLink
;Link
!=&mDiscoveredList
; Link
= Link
->ForwardLink
) {
897 DriverEntry
= CR (Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
898 if (DriverEntry
->Dependent
) {
899 DEBUG ((DEBUG_LOAD
, "MM Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));