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));
191 Get the fixed loading address from image header assigned by build tool. This function only be called
192 when Loading module at Fixed address feature enabled.
194 @param ImageContext Pointer to the image context structure that describes the PE/COFF
195 image that needs to be examined by this function.
196 @retval EFI_SUCCESS An fixed loading address is assigned to this image by build tools .
197 @retval EFI_NOT_FOUND The image has no assigned fixed loadding address.
201 GetPeCoffImageFixLoadingAssignedAddress (
202 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
205 UINTN SectionHeaderOffset
;
207 EFI_IMAGE_SECTION_HEADER SectionHeader
;
208 EFI_IMAGE_OPTIONAL_HEADER_UNION
*ImgHdr
;
209 EFI_PHYSICAL_ADDRESS FixLoadingAddress
;
212 UINT16 NumberOfSections
;
213 UINT64 ValueInSectionHeader
;
215 FixLoadingAddress
= 0;
216 Status
= EFI_NOT_FOUND
;
219 // Get PeHeader pointer
221 ImgHdr
= (EFI_IMAGE_OPTIONAL_HEADER_UNION
*)((CHAR8
*)ImageContext
->Handle
+ ImageContext
->PeCoffHeaderOffset
);
222 SectionHeaderOffset
= ImageContext
->PeCoffHeaderOffset
+ sizeof (UINT32
) + sizeof (EFI_IMAGE_FILE_HEADER
) +
223 ImgHdr
->Pe32
.FileHeader
.SizeOfOptionalHeader
;
224 NumberOfSections
= ImgHdr
->Pe32
.FileHeader
.NumberOfSections
;
227 // Get base address from the first section header that doesn't point to code section.
229 for (Index
= 0; Index
< NumberOfSections
; Index
++) {
231 // Read section header from file
233 Size
= sizeof (EFI_IMAGE_SECTION_HEADER
);
234 Status
= ImageContext
->ImageRead (
235 ImageContext
->Handle
,
240 if (EFI_ERROR (Status
)) {
244 Status
= EFI_NOT_FOUND
;
246 if ((SectionHeader
.Characteristics
& EFI_IMAGE_SCN_CNT_CODE
) == 0) {
248 // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields
249 // in the first section header that doesn't point to code section in image header. So there
250 // is an assumption that when the feature is enabled, if a module with a loading address
251 // assigned by tools, the PointerToRelocations & PointerToLineNumbers fields should not be
252 // Zero, or else, these 2 fields should be set to Zero
254 ValueInSectionHeader
= ReadUnaligned64 ((UINT64
*)&SectionHeader
.PointerToRelocations
);
255 if (ValueInSectionHeader
!= 0) {
257 // Found first section header that doesn't point to code section in which build tool saves the
258 // offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
260 FixLoadingAddress
= (EFI_PHYSICAL_ADDRESS
)(gLoadModuleAtFixAddressMmramBase
+ (INT64
)ValueInSectionHeader
);
262 // Check if the memory range is available.
264 Status
= CheckAndMarkFixLoadingMemoryUsageBitMap (FixLoadingAddress
, (UINTN
)(ImageContext
->ImageSize
+ ImageContext
->SectionAlignment
));
265 if (!EFI_ERROR (Status
)) {
267 // The assigned address is valid. Return the specified loading address
269 ImageContext
->ImageAddress
= FixLoadingAddress
;
276 SectionHeaderOffset
+= sizeof (EFI_IMAGE_SECTION_HEADER
);
280 DEBUG_INFO
|DEBUG_LOAD
,
281 "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r\n",
289 Loads an EFI image into SMRAM.
291 @param DriverEntry EFI_MM_DRIVER_ENTRY instance
299 IN OUT EFI_MM_DRIVER_ENTRY
*DriverEntry
304 EFI_PHYSICAL_ADDRESS DstBuffer
;
305 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
307 DEBUG ((DEBUG_INFO
, "MmLoadImage - %g\n", &DriverEntry
->FileName
));
309 Status
= EFI_SUCCESS
;
312 // Initialize ImageContext
314 ImageContext
.Handle
= DriverEntry
->Pe32Data
;
315 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
318 // Get information about the image being loaded
320 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
321 if (EFI_ERROR (Status
)) {
325 PageCount
= (UINTN
)EFI_SIZE_TO_PAGES ((UINTN
)ImageContext
.ImageSize
+ ImageContext
.SectionAlignment
);
326 DstBuffer
= (UINTN
)(-1);
328 Status
= MmAllocatePages (
330 EfiRuntimeServicesCode
,
334 if (EFI_ERROR (Status
)) {
338 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)DstBuffer
;
341 // Align buffer on section boundary
343 ImageContext
.ImageAddress
+= ImageContext
.SectionAlignment
- 1;
344 ImageContext
.ImageAddress
&= ~((EFI_PHYSICAL_ADDRESS
)(ImageContext
.SectionAlignment
- 1));
347 // Load the image to our new buffer
349 Status
= PeCoffLoaderLoadImage (&ImageContext
);
350 if (EFI_ERROR (Status
)) {
351 MmFreePages (DstBuffer
, PageCount
);
356 // Relocate the image in our new buffer
358 Status
= PeCoffLoaderRelocateImage (&ImageContext
);
359 if (EFI_ERROR (Status
)) {
360 MmFreePages (DstBuffer
, PageCount
);
365 // Flush the instruction cache so the image data are written before we execute it
367 InvalidateInstructionCacheRange ((VOID
*)(UINTN
)ImageContext
.ImageAddress
, (UINTN
)ImageContext
.ImageSize
);
370 // Save Image EntryPoint in DriverEntry
372 DriverEntry
->ImageEntryPoint
= ImageContext
.EntryPoint
;
373 DriverEntry
->ImageBuffer
= DstBuffer
;
374 DriverEntry
->NumberOfPage
= PageCount
;
376 if (mEfiSystemTable
!= NULL
) {
377 Status
= mEfiSystemTable
->BootServices
->AllocatePool (
379 sizeof (EFI_LOADED_IMAGE_PROTOCOL
),
380 (VOID
**)&DriverEntry
->LoadedImage
382 if (EFI_ERROR (Status
)) {
383 MmFreePages (DstBuffer
, PageCount
);
387 ZeroMem (DriverEntry
->LoadedImage
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
));
389 // Fill in the remaining fields of the Loaded Image Protocol instance.
390 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
392 DriverEntry
->LoadedImage
->Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
393 DriverEntry
->LoadedImage
->ParentHandle
= NULL
;
394 DriverEntry
->LoadedImage
->SystemTable
= mEfiSystemTable
;
395 DriverEntry
->LoadedImage
->DeviceHandle
= NULL
;
396 DriverEntry
->LoadedImage
->FilePath
= NULL
;
398 DriverEntry
->LoadedImage
->ImageBase
= (VOID
*)(UINTN
)DriverEntry
->ImageBuffer
;
399 DriverEntry
->LoadedImage
->ImageSize
= ImageContext
.ImageSize
;
400 DriverEntry
->LoadedImage
->ImageCodeType
= EfiRuntimeServicesCode
;
401 DriverEntry
->LoadedImage
->ImageDataType
= EfiRuntimeServicesData
;
404 // Create a new image handle in the UEFI handle database for the MM Driver
406 DriverEntry
->ImageHandle
= NULL
;
407 Status
= mEfiSystemTable
->BootServices
->InstallMultipleProtocolInterfaces (
408 &DriverEntry
->ImageHandle
,
409 &gEfiLoadedImageProtocolGuid
,
410 DriverEntry
->LoadedImage
,
416 // Print the load address and the PDB file name if it is available
422 CHAR8 EfiFileName
[256];
425 DEBUG_INFO
| DEBUG_LOAD
,
426 "Loading MM driver at 0x%11p EntryPoint=0x%11p ",
427 (VOID
*)(UINTN
)ImageContext
.ImageAddress
,
428 FUNCTION_ENTRY_POINT (ImageContext
.EntryPoint
)
432 // Print Module Name by Pdb file path.
433 // Windows and Unix style file path are all trimmed correctly.
435 if (ImageContext
.PdbPointer
!= NULL
) {
437 for (Index
= 0; ImageContext
.PdbPointer
[Index
] != 0; Index
++) {
438 if ((ImageContext
.PdbPointer
[Index
] == '\\') || (ImageContext
.PdbPointer
[Index
] == '/')) {
439 StartIndex
= Index
+ 1;
444 // Copy the PDB file name to our temporary string, and replace .pdb with .efi
445 // The PDB file name is limited in the range of 0~255.
446 // If the length is bigger than 255, trim the redundant characters to avoid overflow in array boundary.
448 for (Index
= 0; Index
< sizeof (EfiFileName
) - 4; Index
++) {
449 EfiFileName
[Index
] = ImageContext
.PdbPointer
[Index
+ StartIndex
];
450 if (EfiFileName
[Index
] == 0) {
451 EfiFileName
[Index
] = '.';
454 if (EfiFileName
[Index
] == '.') {
455 EfiFileName
[Index
+ 1] = 'e';
456 EfiFileName
[Index
+ 2] = 'f';
457 EfiFileName
[Index
+ 3] = 'i';
458 EfiFileName
[Index
+ 4] = 0;
463 if (Index
== sizeof (EfiFileName
) - 4) {
464 EfiFileName
[Index
] = 0;
467 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "%a", EfiFileName
));
470 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "\n"));
478 Preprocess dependency expression and update DriverEntry to reflect the
479 state of Before and After dependencies. If DriverEntry->Before
480 or DriverEntry->After is set it will never be cleared.
482 @param DriverEntry DriverEntry element to update .
484 @retval EFI_SUCCESS It always works.
489 IN EFI_MM_DRIVER_ENTRY
*DriverEntry
494 Iterator
= DriverEntry
->Depex
;
495 DriverEntry
->Dependent
= TRUE
;
497 if (*Iterator
== EFI_DEP_BEFORE
) {
498 DriverEntry
->Before
= TRUE
;
499 } else if (*Iterator
== EFI_DEP_AFTER
) {
500 DriverEntry
->After
= TRUE
;
503 if (DriverEntry
->Before
|| DriverEntry
->After
) {
504 CopyMem (&DriverEntry
->BeforeAfterGuid
, Iterator
+ 1, sizeof (EFI_GUID
));
511 Read Depex and pre-process the Depex for Before and After. If Section Extraction
512 protocol returns an error via ReadSection defer the reading of the Depex.
514 @param DriverEntry Driver to work on.
516 @retval EFI_SUCCESS Depex read and preprossesed
517 @retval EFI_PROTOCOL_ERROR The section extraction protocol returned an error
518 and Depex reading needs to be retried.
519 @retval Error DEPEX not found.
523 MmGetDepexSectionAndPreProccess (
524 IN EFI_MM_DRIVER_ENTRY
*DriverEntry
532 if (DriverEntry
->Depex
== NULL
) {
533 Status
= EFI_NOT_FOUND
;
535 Status
= EFI_SUCCESS
;
538 if (EFI_ERROR (Status
)) {
539 if (Status
== EFI_PROTOCOL_ERROR
) {
541 // The section extraction protocol failed so set protocol error flag
543 DriverEntry
->DepexProtocolError
= TRUE
;
546 // If no Depex assume depend on all architectural protocols
548 DriverEntry
->Depex
= NULL
;
549 DriverEntry
->Dependent
= TRUE
;
550 DriverEntry
->DepexProtocolError
= FALSE
;
554 // Set Before and After state information based on Depex
555 // Driver will be put in Dependent state
557 MmPreProcessDepex (DriverEntry
);
558 DriverEntry
->DepexProtocolError
= FALSE
;
565 This is the main Dispatcher for MM and it exits when there are no more
566 drivers to run. Drain the mScheduledQueue and load and start a PE
567 image for each driver. Search the mDiscoveredList to see if any driver can
568 be placed on the mScheduledQueue. If no drivers are placed on the
569 mScheduledQueue exit the function.
571 @retval EFI_SUCCESS All of the MM Drivers that could be dispatched
572 have been run and the MM Entry Point has been
574 @retval EFI_NOT_READY The MM Driver that registered the MM Entry Point
576 @retval EFI_NOT_FOUND There are no MM Drivers available to be dispatched.
577 @retval EFI_ALREADY_STARTED The MM Dispatcher is already running
587 EFI_MM_DRIVER_ENTRY
*DriverEntry
;
590 DEBUG ((DEBUG_INFO
, "MmDispatcher\n"));
592 if (!gRequestDispatch
) {
593 DEBUG ((DEBUG_INFO
, " !gRequestDispatch\n"));
594 return EFI_NOT_FOUND
;
597 if (gDispatcherRunning
) {
598 DEBUG ((DEBUG_INFO
, " gDispatcherRunning\n"));
600 // If the dispatcher is running don't let it be restarted.
602 return EFI_ALREADY_STARTED
;
605 gDispatcherRunning
= TRUE
;
609 // Drain the Scheduled Queue
611 DEBUG ((DEBUG_INFO
, " Drain the Scheduled Queue\n"));
612 while (!IsListEmpty (&mScheduledQueue
)) {
614 mScheduledQueue
.ForwardLink
,
617 EFI_MM_DRIVER_ENTRY_SIGNATURE
619 DEBUG ((DEBUG_INFO
, " DriverEntry (Scheduled) - %g\n", &DriverEntry
->FileName
));
622 // Load the MM Driver image into memory. If the Driver was transitioned from
623 // Untrusted to Scheduled it would have already been loaded so we may need to
624 // skip the LoadImage
626 if (DriverEntry
->ImageHandle
== NULL
) {
627 Status
= MmLoadImage (DriverEntry
);
630 // Update the driver state to reflect that it's been loaded
632 if (EFI_ERROR (Status
)) {
634 // The MM Driver could not be loaded, and do not attempt to load or start it again.
635 // Take driver from Scheduled to Initialized.
637 DriverEntry
->Initialized
= TRUE
;
638 DriverEntry
->Scheduled
= FALSE
;
639 RemoveEntryList (&DriverEntry
->ScheduledLink
);
642 // If it's an error don't try the StartImage
648 DriverEntry
->Scheduled
= FALSE
;
649 DriverEntry
->Initialized
= TRUE
;
650 RemoveEntryList (&DriverEntry
->ScheduledLink
);
653 // For each MM driver, pass NULL as ImageHandle
655 if (mEfiSystemTable
== NULL
) {
656 DEBUG ((DEBUG_INFO
, "StartImage - 0x%x (Standalone Mode)\n", DriverEntry
->ImageEntryPoint
));
657 Status
= ((MM_IMAGE_ENTRY_POINT
)(UINTN
)DriverEntry
->ImageEntryPoint
)(DriverEntry
->ImageHandle
, &gMmCoreMmst
);
659 DEBUG ((DEBUG_INFO
, "StartImage - 0x%x (Tradition Mode)\n", DriverEntry
->ImageEntryPoint
));
660 Status
= ((EFI_IMAGE_ENTRY_POINT
)(UINTN
)DriverEntry
->ImageEntryPoint
)(
661 DriverEntry
->ImageHandle
,
666 if (EFI_ERROR (Status
)) {
667 DEBUG ((DEBUG_INFO
, "StartImage Status - %r\n", Status
));
668 MmFreePages (DriverEntry
->ImageBuffer
, DriverEntry
->NumberOfPage
);
673 // Search DriverList for items to place on Scheduled Queue
675 DEBUG ((DEBUG_INFO
, " Search DriverList for items to place on Scheduled Queue\n"));
677 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
678 DriverEntry
= CR (Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
679 DEBUG ((DEBUG_INFO
, " DriverEntry (Discovered) - %g\n", &DriverEntry
->FileName
));
681 if (DriverEntry
->DepexProtocolError
) {
683 // If Section Extraction Protocol did not let the Depex be read before retry the read
685 Status
= MmGetDepexSectionAndPreProccess (DriverEntry
);
688 if (DriverEntry
->Dependent
) {
689 if (MmIsSchedulable (DriverEntry
)) {
690 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
695 } while (ReadyToRun
);
698 // If there is no more MM driver to dispatch, stop the dispatch request
700 DEBUG ((DEBUG_INFO
, " no more MM driver to dispatch, stop the dispatch request\n"));
701 gRequestDispatch
= FALSE
;
702 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
703 DriverEntry
= CR (Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
704 DEBUG ((DEBUG_INFO
, " DriverEntry (Discovered) - %g\n", &DriverEntry
->FileName
));
706 if (!DriverEntry
->Initialized
) {
708 // We have MM driver pending to dispatch
710 gRequestDispatch
= TRUE
;
715 gDispatcherRunning
= FALSE
;
721 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
722 must add any driver with a before dependency on InsertedDriverEntry first.
723 You do this by recursively calling this routine. After all the Before Depexes
724 are processed you can add InsertedDriverEntry to the mScheduledQueue.
725 Then you can add any driver with an After dependency on InsertedDriverEntry
726 by recursively calling this routine.
728 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
732 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
733 IN EFI_MM_DRIVER_ENTRY
*InsertedDriverEntry
737 EFI_MM_DRIVER_ENTRY
*DriverEntry
;
740 // Process Before Dependency
742 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
743 DriverEntry
= CR (Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
744 if (DriverEntry
->Before
&& DriverEntry
->Dependent
&& (DriverEntry
!= InsertedDriverEntry
)) {
745 DEBUG ((DEBUG_DISPATCH
, "Evaluate MM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
746 DEBUG ((DEBUG_DISPATCH
, " BEFORE FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
747 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
749 // Recursively process BEFORE
751 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
752 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
754 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
760 // Convert driver from Dependent to Scheduled state
763 InsertedDriverEntry
->Dependent
= FALSE
;
764 InsertedDriverEntry
->Scheduled
= TRUE
;
765 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
768 // Process After Dependency
770 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
771 DriverEntry
= CR (Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
772 if (DriverEntry
->After
&& DriverEntry
->Dependent
&& (DriverEntry
!= InsertedDriverEntry
)) {
773 DEBUG ((DEBUG_DISPATCH
, "Evaluate MM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
774 DEBUG ((DEBUG_DISPATCH
, " AFTER FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
775 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
777 // Recursively process AFTER
779 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
780 MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
782 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
789 Return TRUE if the firmware volume has been processed, FALSE if not.
791 @param FwVolHeader The header of the firmware volume that's being
794 @retval TRUE The firmware volume denoted by FwVolHeader has
796 @retval FALSE The firmware volume denoted by FwVolHeader has
797 not yet been processed
802 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
806 KNOWN_FWVOL
*KnownFwVol
;
808 for (Link
= mFwVolList
.ForwardLink
;
810 Link
= Link
->ForwardLink
)
812 KnownFwVol
= CR (Link
, KNOWN_FWVOL
, Link
, KNOWN_FWVOL_SIGNATURE
);
813 if (KnownFwVol
->FwVolHeader
== FwVolHeader
) {
822 Remember that the firmware volume denoted by FwVolHeader has had its drivers
823 placed on mDiscoveredList. This function adds entries to mFwVolList. Items
824 are never removed/freed from mFwVolList.
826 @param FwVolHeader The header of the firmware volume that's being
832 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
835 KNOWN_FWVOL
*KnownFwVol
;
837 DEBUG ((DEBUG_INFO
, "FvIsBeingProcessed - 0x%08x\n", FwVolHeader
));
839 KnownFwVol
= AllocatePool (sizeof (KNOWN_FWVOL
));
840 ASSERT (KnownFwVol
!= NULL
);
842 KnownFwVol
->Signature
= KNOWN_FWVOL_SIGNATURE
;
843 KnownFwVol
->FwVolHeader
= FwVolHeader
;
844 InsertTailList (&mFwVolList
, &KnownFwVol
->Link
);
848 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
849 and initialise any state variables. Read the Depex from the FV and store it
850 in DriverEntry. Pre-process the Depex to set the Before and After state.
851 The Discovered list is never freed and contains booleans that represent the
852 other possible MM driver states.
854 @param [in] FwVolHeader Pointer to the formware volume header.
855 @param [in] Pe32Data Pointer to the PE data.
856 @param [in] Pe32DataSize Size of the PE data.
857 @param [in] Depex Pointer to the Depex info.
858 @param [in] DepexSize Size of the Depex info.
859 @param [in] DriverName Name of driver to add to mDiscoveredList.
861 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
865 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
867 IN UINTN Pe32DataSize
,
870 IN EFI_GUID
*DriverName
873 EFI_MM_DRIVER_ENTRY
*DriverEntry
;
875 DEBUG ((DEBUG_INFO
, "MmAddToDriverList - %g (0x%08x)\n", DriverName
, Pe32Data
));
878 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
881 DriverEntry
= AllocateZeroPool (sizeof (EFI_MM_DRIVER_ENTRY
));
882 ASSERT (DriverEntry
!= NULL
);
884 DriverEntry
->Signature
= EFI_MM_DRIVER_ENTRY_SIGNATURE
;
885 CopyGuid (&DriverEntry
->FileName
, DriverName
);
886 DriverEntry
->FwVolHeader
= FwVolHeader
;
887 DriverEntry
->Pe32Data
= Pe32Data
;
888 DriverEntry
->Pe32DataSize
= Pe32DataSize
;
889 DriverEntry
->Depex
= Depex
;
890 DriverEntry
->DepexSize
= DepexSize
;
892 MmGetDepexSectionAndPreProccess (DriverEntry
);
894 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
895 gRequestDispatch
= TRUE
;
901 Traverse the discovered list for any drivers that were discovered but not loaded
902 because the dependency expressions evaluated to false.
906 MmDisplayDiscoveredNotDispatched (
911 EFI_MM_DRIVER_ENTRY
*DriverEntry
;
913 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
914 DriverEntry
= CR (Link
, EFI_MM_DRIVER_ENTRY
, Link
, EFI_MM_DRIVER_ENTRY_SIGNATURE
);
915 if (DriverEntry
->Dependent
) {
916 DEBUG ((DEBUG_LOAD
, "MM Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));