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 This program and the accompanying materials are licensed and made available
33 under the terms and conditions of the BSD License which accompanies this
34 distribution. The full text of the license may be found at
35 http://opensource.org/licenses/bsd-license.php
37 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
38 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
42 #include "PiSmmCore.h"
45 // SMM Dispatcher Data structures
47 #define KNOWN_HANDLE_SIGNATURE SIGNATURE_32('k','n','o','w')
50 LIST_ENTRY Link
; // mFvHandleList
55 // Function Prototypes
59 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
60 must add any driver with a before dependency on InsertedDriverEntry first.
61 You do this by recursively calling this routine. After all the Befores are
62 processed you can add InsertedDriverEntry to the mScheduledQueue.
63 Then you can add any driver with an After dependency on InsertedDriverEntry
64 by recursively calling this routine.
66 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
70 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
71 IN EFI_SMM_DRIVER_ENTRY
*InsertedDriverEntry
75 // The Driver List contains one copy of every driver that has been discovered.
76 // Items are never removed from the driver list. List of EFI_SMM_DRIVER_ENTRY
78 LIST_ENTRY mDiscoveredList
= INITIALIZE_LIST_HEAD_VARIABLE (mDiscoveredList
);
81 // Queue of drivers that are ready to dispatch. This queue is a subset of the
82 // mDiscoveredList.list of EFI_SMM_DRIVER_ENTRY.
84 LIST_ENTRY mScheduledQueue
= INITIALIZE_LIST_HEAD_VARIABLE (mScheduledQueue
);
87 // List of handles who's Fv's have been parsed and added to the mFwDriverList.
89 LIST_ENTRY mFvHandleList
= INITIALIZE_LIST_HEAD_VARIABLE (mFvHandleList
);
92 // Flag for the SMM Dispacher. TRUE if dispatcher is execuing.
94 BOOLEAN gDispatcherRunning
= FALSE
;
97 // Flag for the SMM Dispacher. TRUE if there is one or more SMM drivers ready to be dispatched
99 BOOLEAN gRequestDispatch
= FALSE
;
102 // List of file types supported by dispatcher
104 EFI_FV_FILETYPE mSmmFileTypes
[] = {
106 EFI_FV_FILETYPE_COMBINED_SMM_DXE
,
107 EFI_FV_FILETYPE_SMM_CORE
,
109 // Note: DXE core will process the FV image file, so skip it in SMM core
110 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
115 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH File
;
116 EFI_DEVICE_PATH_PROTOCOL End
;
117 } FV_FILEPATH_DEVICE_PATH
;
119 FV_FILEPATH_DEVICE_PATH mFvDevicePath
;
122 // DXE Architecture Protocols
124 EFI_SECURITY_ARCH_PROTOCOL
*mSecurity
= NULL
;
125 EFI_SECURITY2_ARCH_PROTOCOL
*mSecurity2
= NULL
;
128 // The global variable is defined for Loading modules at fixed address feature to track the SMM code
129 // memory range usage. It is a bit mapped array in which every bit indicates the correspoding
130 // memory page available or not.
132 GLOBAL_REMOVE_IF_UNREFERENCED UINT64
*mSmmCodeMemoryRangeUsageBitMap
=NULL
;
135 To check memory usage bit map array to figure out if the memory range in which the image will be loaded is available or not. If
136 memory range is avaliable, the function will mark the correponding bits to 1 which indicates the memory range is used.
137 The function is only invoked when load modules at fixed address feature is enabled.
139 @param ImageBase The base addres the image will be loaded at.
140 @param ImageSize The size of the image
142 @retval EFI_SUCCESS The memory range the image will be loaded in is available
143 @retval EFI_NOT_FOUND The memory range the image will be loaded in is not available
146 CheckAndMarkFixLoadingMemoryUsageBitMap (
147 IN EFI_PHYSICAL_ADDRESS ImageBase
,
151 UINT32 SmmCodePageNumber
;
153 EFI_PHYSICAL_ADDRESS SmmCodeBase
;
154 UINTN BaseOffsetPageNumber
;
155 UINTN TopOffsetPageNumber
;
158 // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
160 SmmCodePageNumber
= PcdGet32(PcdLoadFixAddressSmmCodePageNumber
);
161 SmmCodeSize
= EFI_PAGES_TO_SIZE (SmmCodePageNumber
);
162 SmmCodeBase
= gLoadModuleAtFixAddressSmramBase
;
165 // If the memory usage bit map is not initialized, do it. Every bit in the array
166 // indicate the status of the corresponding memory page, available or not
168 if (mSmmCodeMemoryRangeUsageBitMap
== NULL
) {
169 mSmmCodeMemoryRangeUsageBitMap
= AllocateZeroPool(((SmmCodePageNumber
/ 64) + 1)*sizeof(UINT64
));
172 // If the Dxe code memory range is not allocated or the bit map array allocation failed, return EFI_NOT_FOUND
174 if (mSmmCodeMemoryRangeUsageBitMap
== NULL
) {
175 return EFI_NOT_FOUND
;
178 // see if the memory range for loading the image is in the SMM code range.
180 if (SmmCodeBase
+ SmmCodeSize
< ImageBase
+ ImageSize
|| SmmCodeBase
> ImageBase
) {
181 return EFI_NOT_FOUND
;
184 // Test if the memory is avalaible or not.
186 BaseOffsetPageNumber
= (UINTN
)EFI_SIZE_TO_PAGES((UINT32
)(ImageBase
- SmmCodeBase
));
187 TopOffsetPageNumber
= (UINTN
)EFI_SIZE_TO_PAGES((UINT32
)(ImageBase
+ ImageSize
- SmmCodeBase
));
188 for (Index
= BaseOffsetPageNumber
; Index
< TopOffsetPageNumber
; Index
++) {
189 if ((mSmmCodeMemoryRangeUsageBitMap
[Index
/ 64] & LShiftU64(1, (Index
% 64))) != 0) {
191 // This page is already used.
193 return EFI_NOT_FOUND
;
198 // Being here means the memory range is available. So mark the bits for the memory range
200 for (Index
= BaseOffsetPageNumber
; Index
< TopOffsetPageNumber
; Index
++) {
201 mSmmCodeMemoryRangeUsageBitMap
[Index
/ 64] |= LShiftU64(1, (Index
% 64));
206 Get the fixed loadding address from image header assigned by build tool. This function only be called
207 when Loading module at Fixed address feature enabled.
209 @param ImageContext Pointer to the image context structure that describes the PE/COFF
210 image that needs to be examined by this function.
211 @retval EFI_SUCCESS An fixed loading address is assigned to this image by build tools .
212 @retval EFI_NOT_FOUND The image has no assigned fixed loadding address.
216 GetPeCoffImageFixLoadingAssignedAddress(
217 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
220 UINTN SectionHeaderOffset
;
222 EFI_IMAGE_SECTION_HEADER SectionHeader
;
223 EFI_IMAGE_OPTIONAL_HEADER_UNION
*ImgHdr
;
224 EFI_PHYSICAL_ADDRESS FixLoaddingAddress
;
227 UINT16 NumberOfSections
;
228 UINT64 ValueInSectionHeader
;
230 FixLoaddingAddress
= 0;
231 Status
= EFI_NOT_FOUND
;
234 // Get PeHeader pointer
236 ImgHdr
= (EFI_IMAGE_OPTIONAL_HEADER_UNION
*)((CHAR8
* )ImageContext
->Handle
+ ImageContext
->PeCoffHeaderOffset
);
237 SectionHeaderOffset
= (UINTN
)(
238 ImageContext
->PeCoffHeaderOffset
+
240 sizeof (EFI_IMAGE_FILE_HEADER
) +
241 ImgHdr
->Pe32
.FileHeader
.SizeOfOptionalHeader
243 NumberOfSections
= ImgHdr
->Pe32
.FileHeader
.NumberOfSections
;
246 // Get base address from the first section header that doesn't point to code section.
248 for (Index
= 0; Index
< NumberOfSections
; Index
++) {
250 // Read section header from file
252 Size
= sizeof (EFI_IMAGE_SECTION_HEADER
);
253 Status
= ImageContext
->ImageRead (
254 ImageContext
->Handle
,
259 if (EFI_ERROR (Status
)) {
263 Status
= EFI_NOT_FOUND
;
265 if ((SectionHeader
.Characteristics
& EFI_IMAGE_SCN_CNT_CODE
) == 0) {
267 // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields in the first section header
268 // that doesn't point to code section in image header.So there is an assumption that when the feature is enabled,
269 // if a module with a loading address assigned by tools, the PointerToRelocations & PointerToLineNumbers fields
270 // should not be Zero, or else, these 2 fileds should be set to Zero
272 ValueInSectionHeader
= ReadUnaligned64((UINT64
*)&SectionHeader
.PointerToRelocations
);
273 if (ValueInSectionHeader
!= 0) {
275 // Found first section header that doesn't point to code section in which uild tool saves the
276 // offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
278 FixLoaddingAddress
= (EFI_PHYSICAL_ADDRESS
)(gLoadModuleAtFixAddressSmramBase
+ (INT64
)ValueInSectionHeader
);
280 // Check if the memory range is avaliable.
282 Status
= CheckAndMarkFixLoadingMemoryUsageBitMap (FixLoaddingAddress
, (UINTN
)(ImageContext
->ImageSize
+ ImageContext
->SectionAlignment
));
283 if (!EFI_ERROR(Status
)) {
285 // The assigned address is valid. Return the specified loadding address
287 ImageContext
->ImageAddress
= FixLoaddingAddress
;
292 SectionHeaderOffset
+= sizeof (EFI_IMAGE_SECTION_HEADER
);
294 DEBUG ((EFI_D_INFO
|EFI_D_LOAD
, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r\n", FixLoaddingAddress
, Status
));
298 Loads an EFI image into SMRAM.
300 @param DriverEntry EFI_SMM_DRIVER_ENTRY instance
308 IN OUT EFI_SMM_DRIVER_ENTRY
*DriverEntry
311 UINT32 AuthenticationStatus
;
318 EFI_STATUS SecurityStatus
;
319 EFI_HANDLE DeviceHandle
;
320 EFI_PHYSICAL_ADDRESS DstBuffer
;
321 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
322 EFI_DEVICE_PATH_PROTOCOL
*OriginalFilePath
;
323 EFI_DEVICE_PATH_PROTOCOL
*HandleFilePath
;
324 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
325 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
330 Tick
= GetPerformanceCounter ();
335 Fv
= DriverEntry
->Fv
;
336 NameGuid
= &DriverEntry
->FileName
;
337 FilePath
= DriverEntry
->FvFileDevicePath
;
339 OriginalFilePath
= FilePath
;
340 HandleFilePath
= FilePath
;
342 SecurityStatus
= EFI_SUCCESS
;
343 Status
= EFI_SUCCESS
;
344 AuthenticationStatus
= 0;
347 // Try to get the image device handle by checking the match protocol.
349 Status
= gBS
->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid
, &HandleFilePath
, &DeviceHandle
);
350 if (EFI_ERROR(Status
)) {
355 // If the Security2 and Security Architectural Protocol has not been located yet, then attempt to locate it
357 if (mSecurity2
== NULL
) {
358 gBS
->LocateProtocol (&gEfiSecurity2ArchProtocolGuid
, NULL
, (VOID
**)&mSecurity2
);
360 if (mSecurity
== NULL
) {
361 gBS
->LocateProtocol (&gEfiSecurityArchProtocolGuid
, NULL
, (VOID
**)&mSecurity
);
364 // When Security2 is installed, Security Architectural Protocol must be published.
366 ASSERT (mSecurity2
== NULL
|| mSecurity
!= NULL
);
369 // Pull out just the file portion of the DevicePath for the LoadedImage FilePath
371 FilePath
= OriginalFilePath
;
372 Status
= gBS
->HandleProtocol (DeviceHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&HandleFilePath
);
373 if (!EFI_ERROR (Status
)) {
374 FilePathSize
= GetDevicePathSize (HandleFilePath
) - sizeof(EFI_DEVICE_PATH_PROTOCOL
);
375 FilePath
= (EFI_DEVICE_PATH_PROTOCOL
*) (((UINT8
*)FilePath
) + FilePathSize
);
379 // Try reading PE32 section firstly
381 Status
= Fv
->ReadSection (
388 &AuthenticationStatus
391 if (EFI_ERROR (Status
)) {
393 // Try reading TE section secondly
397 Status
= Fv
->ReadSection (
404 &AuthenticationStatus
408 if (EFI_ERROR (Status
)) {
409 if (Buffer
!= NULL
) {
410 gBS
->FreePool (Buffer
);
416 // Verify File Authentication through the Security2 Architectural Protocol
418 if (mSecurity2
!= NULL
) {
419 SecurityStatus
= mSecurity2
->FileAuthentication (
429 // Verify the Authentication Status through the Security Architectural Protocol
430 // Only on images that have been read using Firmware Volume protocol.
431 // All SMM images are from FV protocol.
433 if (!EFI_ERROR (SecurityStatus
) && (mSecurity
!= NULL
)) {
434 SecurityStatus
= mSecurity
->FileAuthenticationState (
436 AuthenticationStatus
,
441 if (EFI_ERROR (SecurityStatus
) && SecurityStatus
!= EFI_SECURITY_VIOLATION
) {
442 Status
= SecurityStatus
;
447 // Initialize ImageContext
449 ImageContext
.Handle
= Buffer
;
450 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
453 // Get information about the image being loaded
455 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
456 if (EFI_ERROR (Status
)) {
457 if (Buffer
!= NULL
) {
458 gBS
->FreePool (Buffer
);
463 // if Loading module at Fixed Address feature is enabled, then cut out a memory range started from TESG BASE
464 // to hold the Smm driver code
466 if (PcdGet64(PcdLoadModuleAtFixAddressEnable
) != 0) {
468 // Get the fixed loading address assigned by Build tool
470 Status
= GetPeCoffImageFixLoadingAssignedAddress (&ImageContext
);
471 if (!EFI_ERROR (Status
)) {
473 // Since the memory range to load Smm core alreay been cut out, so no need to allocate and free this range
474 // following statements is to bypass SmmFreePages
477 DstBuffer
= (UINTN
)gLoadModuleAtFixAddressSmramBase
;
479 DEBUG ((EFI_D_INFO
|EFI_D_LOAD
, "LOADING MODULE FIXED ERROR: Failed to load module at fixed address. \n"));
481 // allocate the memory to load the SMM driver
483 PageCount
= (UINTN
)EFI_SIZE_TO_PAGES((UINTN
)ImageContext
.ImageSize
+ ImageContext
.SectionAlignment
);
484 DstBuffer
= (UINTN
)(-1);
486 Status
= SmmAllocatePages (
488 EfiRuntimeServicesCode
,
492 if (EFI_ERROR (Status
)) {
493 if (Buffer
!= NULL
) {
494 gBS
->FreePool (Buffer
);
498 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)DstBuffer
;
501 PageCount
= (UINTN
)EFI_SIZE_TO_PAGES((UINTN
)ImageContext
.ImageSize
+ ImageContext
.SectionAlignment
);
502 DstBuffer
= (UINTN
)(-1);
504 Status
= SmmAllocatePages (
506 EfiRuntimeServicesCode
,
510 if (EFI_ERROR (Status
)) {
511 if (Buffer
!= NULL
) {
512 gBS
->FreePool (Buffer
);
517 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)DstBuffer
;
520 // Align buffer on section boundry
522 ImageContext
.ImageAddress
+= ImageContext
.SectionAlignment
- 1;
523 ImageContext
.ImageAddress
&= ~((EFI_PHYSICAL_ADDRESS
)(ImageContext
.SectionAlignment
- 1));
526 // Load the image to our new buffer
528 Status
= PeCoffLoaderLoadImage (&ImageContext
);
529 if (EFI_ERROR (Status
)) {
530 if (Buffer
!= NULL
) {
531 gBS
->FreePool (Buffer
);
533 SmmFreePages (DstBuffer
, PageCount
);
538 // Relocate the image in our new buffer
540 Status
= PeCoffLoaderRelocateImage (&ImageContext
);
541 if (EFI_ERROR (Status
)) {
542 if (Buffer
!= NULL
) {
543 gBS
->FreePool (Buffer
);
545 SmmFreePages (DstBuffer
, PageCount
);
550 // Flush the instruction cache so the image data are written before we execute it
552 InvalidateInstructionCacheRange ((VOID
*)(UINTN
) ImageContext
.ImageAddress
, (UINTN
) ImageContext
.ImageSize
);
555 // Save Image EntryPoint in DriverEntry
557 DriverEntry
->ImageEntryPoint
= ImageContext
.EntryPoint
;
558 DriverEntry
->ImageBuffer
= DstBuffer
;
559 DriverEntry
->NumberOfPage
= PageCount
;
562 // Allocate a Loaded Image Protocol in EfiBootServicesData
564 Status
= gBS
->AllocatePool (EfiBootServicesData
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
), (VOID
**)&DriverEntry
->LoadedImage
);
565 if (EFI_ERROR (Status
)) {
566 if (Buffer
!= NULL
) {
567 gBS
->FreePool (Buffer
);
569 SmmFreePages (DstBuffer
, PageCount
);
573 ZeroMem (DriverEntry
->LoadedImage
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
));
575 // Fill in the remaining fields of the Loaded Image Protocol instance.
576 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
578 DriverEntry
->LoadedImage
->Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
579 DriverEntry
->LoadedImage
->ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
580 DriverEntry
->LoadedImage
->SystemTable
= gST
;
581 DriverEntry
->LoadedImage
->DeviceHandle
= DeviceHandle
;
584 // Make an EfiBootServicesData buffer copy of FilePath
586 Status
= gBS
->AllocatePool (EfiBootServicesData
, GetDevicePathSize (FilePath
), (VOID
**)&DriverEntry
->LoadedImage
->FilePath
);
587 if (EFI_ERROR (Status
)) {
588 if (Buffer
!= NULL
) {
589 gBS
->FreePool (Buffer
);
591 SmmFreePages (DstBuffer
, PageCount
);
594 CopyMem (DriverEntry
->LoadedImage
->FilePath
, FilePath
, GetDevicePathSize (FilePath
));
596 DriverEntry
->LoadedImage
->ImageBase
= (VOID
*)(UINTN
)DriverEntry
->ImageBuffer
;
597 DriverEntry
->LoadedImage
->ImageSize
= ImageContext
.ImageSize
;
598 DriverEntry
->LoadedImage
->ImageCodeType
= EfiRuntimeServicesCode
;
599 DriverEntry
->LoadedImage
->ImageDataType
= EfiRuntimeServicesData
;
602 // Create a new image handle in the UEFI handle database for the SMM Driver
604 DriverEntry
->ImageHandle
= NULL
;
605 Status
= gBS
->InstallMultipleProtocolInterfaces (
606 &DriverEntry
->ImageHandle
,
607 &gEfiLoadedImageProtocolGuid
, DriverEntry
->LoadedImage
,
611 PERF_START (DriverEntry
->ImageHandle
, "LoadImage:", NULL
, Tick
);
612 PERF_END (DriverEntry
->ImageHandle
, "LoadImage:", NULL
, 0);
615 // Print the load address and the PDB file name if it is available
622 CHAR8 EfiFileName
[256];
625 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
,
626 "Loading SMM driver at 0x%11p EntryPoint=0x%11p ",
627 (VOID
*)(UINTN
) ImageContext
.ImageAddress
,
628 FUNCTION_ENTRY_POINT (ImageContext
.EntryPoint
)));
632 // Print Module Name by Pdb file path.
633 // Windows and Unix style file path are all trimmed correctly.
635 if (ImageContext
.PdbPointer
!= NULL
) {
637 for (Index
= 0; ImageContext
.PdbPointer
[Index
] != 0; Index
++) {
638 if ((ImageContext
.PdbPointer
[Index
] == '\\') || (ImageContext
.PdbPointer
[Index
] == '/')) {
639 StartIndex
= Index
+ 1;
643 // Copy the PDB file name to our temporary string, and replace .pdb with .efi
644 // The PDB file name is limited in the range of 0~255.
645 // If the length is bigger than 255, trim the redudant characters to avoid overflow in array boundary.
647 for (Index
= 0; Index
< sizeof (EfiFileName
) - 4; Index
++) {
648 EfiFileName
[Index
] = ImageContext
.PdbPointer
[Index
+ StartIndex
];
649 if (EfiFileName
[Index
] == 0) {
650 EfiFileName
[Index
] = '.';
652 if (EfiFileName
[Index
] == '.') {
653 EfiFileName
[Index
+ 1] = 'e';
654 EfiFileName
[Index
+ 2] = 'f';
655 EfiFileName
[Index
+ 3] = 'i';
656 EfiFileName
[Index
+ 4] = 0;
661 if (Index
== sizeof (EfiFileName
) - 4) {
662 EfiFileName
[Index
] = 0;
664 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "%a", EfiFileName
)); // &Image->ImageContext.PdbPointer[StartIndex]));
666 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "\n"));
671 // Free buffer allocated by Fv->ReadSection.
673 // The UEFI Boot Services FreePool() function must be used because Fv->ReadSection
674 // used the UEFI Boot Services AllocatePool() function
676 Status
= gBS
->FreePool(Buffer
);
677 if (!EFI_ERROR (Status
) && EFI_ERROR (SecurityStatus
)) {
678 Status
= SecurityStatus
;
684 Preprocess dependency expression and update DriverEntry to reflect the
685 state of Before and After dependencies. If DriverEntry->Before
686 or DriverEntry->After is set it will never be cleared.
688 @param DriverEntry DriverEntry element to update .
690 @retval EFI_SUCCESS It always works.
695 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
700 Iterator
= DriverEntry
->Depex
;
701 DriverEntry
->Dependent
= TRUE
;
703 if (*Iterator
== EFI_DEP_BEFORE
) {
704 DriverEntry
->Before
= TRUE
;
705 } else if (*Iterator
== EFI_DEP_AFTER
) {
706 DriverEntry
->After
= TRUE
;
709 if (DriverEntry
->Before
|| DriverEntry
->After
) {
710 CopyMem (&DriverEntry
->BeforeAfterGuid
, Iterator
+ 1, sizeof (EFI_GUID
));
717 Read Depex and pre-process the Depex for Before and After. If Section Extraction
718 protocol returns an error via ReadSection defer the reading of the Depex.
720 @param DriverEntry Driver to work on.
722 @retval EFI_SUCCESS Depex read and preprossesed
723 @retval EFI_PROTOCOL_ERROR The section extraction protocol returned an error
724 and Depex reading needs to be retried.
725 @retval Error DEPEX not found.
729 SmmGetDepexSectionAndPreProccess (
730 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
734 EFI_SECTION_TYPE SectionType
;
735 UINT32 AuthenticationStatus
;
736 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
738 Fv
= DriverEntry
->Fv
;
741 // Grab Depex info, it will never be free'ed.
742 // (Note: DriverEntry->Depex is in DXE memory)
744 SectionType
= EFI_SECTION_SMM_DEPEX
;
745 Status
= Fv
->ReadSection (
747 &DriverEntry
->FileName
,
751 (UINTN
*)&DriverEntry
->DepexSize
,
752 &AuthenticationStatus
754 if (EFI_ERROR (Status
)) {
755 if (Status
== EFI_PROTOCOL_ERROR
) {
757 // The section extraction protocol failed so set protocol error flag
759 DriverEntry
->DepexProtocolError
= TRUE
;
762 // If no Depex assume depend on all architectural protocols
764 DriverEntry
->Depex
= NULL
;
765 DriverEntry
->Dependent
= TRUE
;
766 DriverEntry
->DepexProtocolError
= FALSE
;
770 // Set Before and After state information based on Depex
771 // Driver will be put in Dependent state
773 SmmPreProcessDepex (DriverEntry
);
774 DriverEntry
->DepexProtocolError
= FALSE
;
781 This is the main Dispatcher for SMM and it exits when there are no more
782 drivers to run. Drain the mScheduledQueue and load and start a PE
783 image for each driver. Search the mDiscoveredList to see if any driver can
784 be placed on the mScheduledQueue. If no drivers are placed on the
785 mScheduledQueue exit the function.
787 @retval EFI_SUCCESS All of the SMM Drivers that could be dispatched
788 have been run and the SMM Entry Point has been
790 @retval EFI_NOT_READY The SMM Driver that registered the SMM Entry Point
792 @retval EFI_NOT_FOUND There are no SMM Drivers available to be dispatched.
793 @retval EFI_ALREADY_STARTED The SMM Dispatcher is already running
803 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
805 BOOLEAN PreviousSmmEntryPointRegistered
;
807 if (!gRequestDispatch
) {
808 return EFI_NOT_FOUND
;
811 if (gDispatcherRunning
) {
813 // If the dispatcher is running don't let it be restarted.
815 return EFI_ALREADY_STARTED
;
818 gDispatcherRunning
= TRUE
;
822 // Drain the Scheduled Queue
824 while (!IsListEmpty (&mScheduledQueue
)) {
826 mScheduledQueue
.ForwardLink
,
827 EFI_SMM_DRIVER_ENTRY
,
829 EFI_SMM_DRIVER_ENTRY_SIGNATURE
833 // Load the SMM Driver image into memory. If the Driver was transitioned from
834 // Untrused to Scheduled it would have already been loaded so we may need to
835 // skip the LoadImage
837 if (DriverEntry
->ImageHandle
== NULL
) {
838 Status
= SmmLoadImage (DriverEntry
);
841 // Update the driver state to reflect that it's been loaded
843 if (EFI_ERROR (Status
)) {
845 // The SMM Driver could not be loaded, and do not attempt to load or start it again.
846 // Take driver from Scheduled to Initialized.
848 DriverEntry
->Initialized
= TRUE
;
849 DriverEntry
->Scheduled
= FALSE
;
850 RemoveEntryList (&DriverEntry
->ScheduledLink
);
853 // If it's an error don't try the StartImage
859 DriverEntry
->Scheduled
= FALSE
;
860 DriverEntry
->Initialized
= TRUE
;
861 RemoveEntryList (&DriverEntry
->ScheduledLink
);
863 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
865 EFI_SOFTWARE_SMM_DRIVER
| EFI_SW_PC_INIT_BEGIN
,
866 &DriverEntry
->ImageHandle
,
867 sizeof (DriverEntry
->ImageHandle
)
871 // Cache state of SmmEntryPointRegistered before calling entry point
873 PreviousSmmEntryPointRegistered
= gSmmCorePrivate
->SmmEntryPointRegistered
;
876 // For each SMM driver, pass NULL as ImageHandle
878 RegisterSmramProfileImage (DriverEntry
, TRUE
);
879 PERF_START (DriverEntry
->ImageHandle
, "StartImage:", NULL
, 0);
880 Status
= ((EFI_IMAGE_ENTRY_POINT
)(UINTN
)DriverEntry
->ImageEntryPoint
)(DriverEntry
->ImageHandle
, gST
);
881 PERF_END (DriverEntry
->ImageHandle
, "StartImage:", NULL
, 0);
882 if (EFI_ERROR(Status
)){
883 UnregisterSmramProfileImage (DriverEntry
, TRUE
);
884 SmmFreePages(DriverEntry
->ImageBuffer
, DriverEntry
->NumberOfPage
);
886 // Uninstall LoadedImage
888 Status
= gBS
->UninstallProtocolInterface (
889 DriverEntry
->ImageHandle
,
890 &gEfiLoadedImageProtocolGuid
,
891 DriverEntry
->LoadedImage
893 if (!EFI_ERROR (Status
)) {
894 if (DriverEntry
->LoadedImage
->FilePath
!= NULL
) {
895 gBS
->FreePool (DriverEntry
->LoadedImage
->FilePath
);
897 gBS
->FreePool (DriverEntry
->LoadedImage
);
901 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
903 EFI_SOFTWARE_SMM_DRIVER
| EFI_SW_PC_INIT_END
,
904 &DriverEntry
->ImageHandle
,
905 sizeof (DriverEntry
->ImageHandle
)
908 if (!PreviousSmmEntryPointRegistered
&& gSmmCorePrivate
->SmmEntryPointRegistered
) {
910 // Return immediately if the SMM Entry Point was registered by the SMM
911 // Driver that was just dispatched. The SMM IPL will reinvoke the SMM
912 // Core Dispatcher. This is required so SMM Mode may be enabled as soon
913 // as all the dependent SMM Drivers for SMM Mode have been dispatched.
914 // Once the SMM Entry Point has been registered, then SMM Mode will be
917 gRequestDispatch
= TRUE
;
918 gDispatcherRunning
= FALSE
;
919 return EFI_NOT_READY
;
924 // Search DriverList for items to place on Scheduled Queue
927 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
928 DriverEntry
= CR (Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
930 if (DriverEntry
->DepexProtocolError
){
932 // If Section Extraction Protocol did not let the Depex be read before retry the read
934 Status
= SmmGetDepexSectionAndPreProccess (DriverEntry
);
937 if (DriverEntry
->Dependent
) {
938 if (SmmIsSchedulable (DriverEntry
)) {
939 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
944 } while (ReadyToRun
);
947 // If there is no more SMM driver to dispatch, stop the dispatch request
949 gRequestDispatch
= FALSE
;
950 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
951 DriverEntry
= CR (Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
953 if (!DriverEntry
->Initialized
){
955 // We have SMM driver pending to dispatch
957 gRequestDispatch
= TRUE
;
962 gDispatcherRunning
= FALSE
;
968 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
969 must add any driver with a before dependency on InsertedDriverEntry first.
970 You do this by recursively calling this routine. After all the Befores are
971 processed you can add InsertedDriverEntry to the mScheduledQueue.
972 Then you can add any driver with an After dependency on InsertedDriverEntry
973 by recursively calling this routine.
975 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
979 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
980 IN EFI_SMM_DRIVER_ENTRY
*InsertedDriverEntry
984 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
987 // Process Before Dependency
989 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
990 DriverEntry
= CR(Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
991 if (DriverEntry
->Before
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
992 DEBUG ((DEBUG_DISPATCH
, "Evaluate SMM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
993 DEBUG ((DEBUG_DISPATCH
, " BEFORE FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
994 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
996 // Recursively process BEFORE
998 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
999 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
1001 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
1007 // Convert driver from Dependent to Scheduled state
1010 InsertedDriverEntry
->Dependent
= FALSE
;
1011 InsertedDriverEntry
->Scheduled
= TRUE
;
1012 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
1016 // Process After Dependency
1018 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1019 DriverEntry
= CR(Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
1020 if (DriverEntry
->After
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
1021 DEBUG ((DEBUG_DISPATCH
, "Evaluate SMM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
1022 DEBUG ((DEBUG_DISPATCH
, " AFTER FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
1023 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
1025 // Recursively process AFTER
1027 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
1028 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
1030 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
1037 Return TRUE if the Fv has been processed, FALSE if not.
1039 @param FvHandle The handle of a FV that's being tested
1041 @retval TRUE Fv protocol on FvHandle has been processed
1042 @retval FALSE Fv protocol on FvHandle has not yet been
1047 FvHasBeenProcessed (
1048 IN EFI_HANDLE FvHandle
1052 KNOWN_HANDLE
*KnownHandle
;
1054 for (Link
= mFvHandleList
.ForwardLink
; Link
!= &mFvHandleList
; Link
= Link
->ForwardLink
) {
1055 KnownHandle
= CR(Link
, KNOWN_HANDLE
, Link
, KNOWN_HANDLE_SIGNATURE
);
1056 if (KnownHandle
->Handle
== FvHandle
) {
1064 Remember that Fv protocol on FvHandle has had it's drivers placed on the
1065 mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are
1066 never removed/freed from the mFvHandleList.
1068 @param FvHandle The handle of a FV that has been processed
1072 FvIsBeingProcesssed (
1073 IN EFI_HANDLE FvHandle
1076 KNOWN_HANDLE
*KnownHandle
;
1078 KnownHandle
= AllocatePool (sizeof (KNOWN_HANDLE
));
1079 ASSERT (KnownHandle
!= NULL
);
1081 KnownHandle
->Signature
= KNOWN_HANDLE_SIGNATURE
;
1082 KnownHandle
->Handle
= FvHandle
;
1083 InsertTailList (&mFvHandleList
, &KnownHandle
->Link
);
1087 Convert FvHandle and DriverName into an EFI device path
1089 @param Fv Fv protocol, needed to read Depex info out of
1091 @param FvHandle Handle for Fv, needed in the
1092 EFI_SMM_DRIVER_ENTRY so that the PE image can be
1093 read out of the FV at a later time.
1094 @param DriverName Name of driver to add to mDiscoveredList.
1096 @return Pointer to device path constructed from FvHandle and DriverName
1099 EFI_DEVICE_PATH_PROTOCOL
*
1101 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
1102 IN EFI_HANDLE FvHandle
,
1103 IN EFI_GUID
*DriverName
1107 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
1108 EFI_DEVICE_PATH_PROTOCOL
*FileNameDevicePath
;
1111 // Remember the device path of the FV
1113 Status
= gBS
->HandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
1114 if (EFI_ERROR (Status
)) {
1115 FileNameDevicePath
= NULL
;
1118 // Build a device path to the file in the FV to pass into gBS->LoadImage
1120 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, DriverName
);
1121 SetDevicePathEndNode (&mFvDevicePath
.End
);
1124 // Note: FileNameDevicePath is in DXE memory
1126 FileNameDevicePath
= AppendDevicePath (
1128 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
1131 return FileNameDevicePath
;
1135 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
1136 and initilize any state variables. Read the Depex from the FV and store it
1137 in DriverEntry. Pre-process the Depex to set the Before and After state.
1138 The Discovered list is never free'ed and contains booleans that represent the
1139 other possible SMM driver states.
1141 @param Fv Fv protocol, needed to read Depex info out of
1143 @param FvHandle Handle for Fv, needed in the
1144 EFI_SMM_DRIVER_ENTRY so that the PE image can be
1145 read out of the FV at a later time.
1146 @param DriverName Name of driver to add to mDiscoveredList.
1148 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
1149 @retval EFI_ALREADY_STARTED The driver has already been started. Only one
1150 DriverName may be active in the system at any one
1155 SmmAddToDriverList (
1156 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
1157 IN EFI_HANDLE FvHandle
,
1158 IN EFI_GUID
*DriverName
1161 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
1164 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
1167 DriverEntry
= AllocateZeroPool (sizeof (EFI_SMM_DRIVER_ENTRY
));
1168 ASSERT (DriverEntry
!= NULL
);
1170 DriverEntry
->Signature
= EFI_SMM_DRIVER_ENTRY_SIGNATURE
;
1171 CopyGuid (&DriverEntry
->FileName
, DriverName
);
1172 DriverEntry
->FvHandle
= FvHandle
;
1173 DriverEntry
->Fv
= Fv
;
1174 DriverEntry
->FvFileDevicePath
= SmmFvToDevicePath (Fv
, FvHandle
, DriverName
);
1176 SmmGetDepexSectionAndPreProccess (DriverEntry
);
1178 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
1179 gRequestDispatch
= TRUE
;
1185 This function is the main entry point for an SMM handler dispatch
1186 or communicate-based callback.
1188 Event notification that is fired every time a FV dispatch protocol is added.
1189 More than one protocol may have been added when this event is fired, so you
1190 must loop on SmmLocateHandle () to see how many protocols were added and
1191 do the following to each FV:
1192 If the Fv has already been processed, skip it. If the Fv has not been
1193 processed then mark it as being processed, as we are about to process it.
1194 Read the Fv and add any driver in the Fv to the mDiscoveredList.The
1195 mDiscoveredList is never free'ed and contains variables that define
1196 the other states the SMM driver transitions to..
1197 While you are at it read the A Priori file into memory.
1198 Place drivers in the A Priori list onto the mScheduledQueue.
1200 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
1201 @param Context Points to an optional handler context which was specified when the handler was registered.
1202 @param CommBuffer A pointer to a collection of data in memory that will
1203 be conveyed from a non-SMM environment into an SMM environment.
1204 @param CommBufferSize The size of the CommBuffer.
1211 SmmDriverDispatchHandler (
1212 IN EFI_HANDLE DispatchHandle
,
1213 IN CONST VOID
*Context
, OPTIONAL
1214 IN OUT VOID
*CommBuffer
, OPTIONAL
1215 IN OUT UINTN
*CommBufferSize OPTIONAL
1220 EFI_HANDLE
*HandleBuffer
;
1221 EFI_STATUS GetNextFileStatus
;
1222 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
1223 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
1224 EFI_HANDLE FvHandle
;
1227 EFI_FV_FILETYPE Type
;
1228 EFI_FV_FILE_ATTRIBUTES Attributes
;
1230 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
1231 EFI_GUID
*AprioriFile
;
1232 UINTN AprioriEntryCount
;
1237 UINT32 AuthenticationStatus
;
1240 HandleBuffer
= NULL
;
1241 Status
= gBS
->LocateHandleBuffer (
1243 &gEfiFirmwareVolume2ProtocolGuid
,
1248 if (EFI_ERROR (Status
)) {
1249 return EFI_NOT_FOUND
;
1252 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
1253 FvHandle
= HandleBuffer
[HandleIndex
];
1255 if (FvHasBeenProcessed (FvHandle
)) {
1257 // This Fv has already been processed so lets skip it!
1263 // Since we are about to process this Fv mark it as processed.
1265 FvIsBeingProcesssed (FvHandle
);
1267 Status
= gBS
->HandleProtocol (FvHandle
, &gEfiFirmwareVolume2ProtocolGuid
, (VOID
**)&Fv
);
1268 if (EFI_ERROR (Status
)) {
1270 // FvHandle must have a Firmware Volume2 Protocol thus we should never get here.
1276 Status
= gBS
->HandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
1277 if (EFI_ERROR (Status
)) {
1279 // The Firmware volume doesn't have device path, can't be dispatched.
1285 // Discover Drivers in FV and add them to the Discovered Driver List.
1286 // Process EFI_FV_FILETYPE_SMM type and then EFI_FV_FILETYPE_COMBINED_SMM_DXE
1287 // EFI_FV_FILETYPE_SMM_CORE is processed to produce a Loaded Image protocol for the core
1289 for (SmmTypeIndex
= 0; SmmTypeIndex
< sizeof (mSmmFileTypes
)/sizeof (EFI_FV_FILETYPE
); SmmTypeIndex
++) {
1291 // Initialize the search key
1295 Type
= mSmmFileTypes
[SmmTypeIndex
];
1296 GetNextFileStatus
= Fv
->GetNextFile (
1304 if (!EFI_ERROR (GetNextFileStatus
)) {
1305 if (Type
== EFI_FV_FILETYPE_SMM_CORE
) {
1307 // If this is the SMM core fill in it's DevicePath & DeviceHandle
1309 if (mSmmCoreLoadedImage
->FilePath
== NULL
) {
1311 // Maybe one special FV contains only one SMM_CORE module, so its device path must
1312 // be initialized completely.
1314 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, &NameGuid
);
1315 SetDevicePathEndNode (&mFvDevicePath
.End
);
1318 // Make an EfiBootServicesData buffer copy of FilePath
1320 Status
= gBS
->AllocatePool (
1321 EfiBootServicesData
,
1322 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
),
1323 (VOID
**)&mSmmCoreLoadedImage
->FilePath
1325 ASSERT_EFI_ERROR (Status
);
1326 CopyMem (mSmmCoreLoadedImage
->FilePath
, &mFvDevicePath
, GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
));
1328 mSmmCoreLoadedImage
->DeviceHandle
= FvHandle
;
1331 SmmAddToDriverList (Fv
, FvHandle
, &NameGuid
);
1334 } while (!EFI_ERROR (GetNextFileStatus
));
1338 // Read the array of GUIDs from the Apriori file if it is present in the firmware volume
1339 // (Note: AprioriFile is in DXE memory)
1342 Status
= Fv
->ReadSection (
1347 (VOID
**)&AprioriFile
,
1349 &AuthenticationStatus
1351 if (!EFI_ERROR (Status
)) {
1352 AprioriEntryCount
= SizeOfBuffer
/ sizeof (EFI_GUID
);
1354 AprioriEntryCount
= 0;
1358 // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes
1359 // drivers not in the current FV and these must be skipped since the a priori list
1360 // is only valid for the FV that it resided in.
1363 for (AprioriIndex
= 0; AprioriIndex
< AprioriEntryCount
; AprioriIndex
++) {
1364 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1365 DriverEntry
= CR(Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
1366 if (CompareGuid (&DriverEntry
->FileName
, &AprioriFile
[AprioriIndex
]) &&
1367 (FvHandle
== DriverEntry
->FvHandle
)) {
1368 DriverEntry
->Dependent
= FALSE
;
1369 DriverEntry
->Scheduled
= TRUE
;
1370 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
1371 DEBUG ((DEBUG_DISPATCH
, "Evaluate SMM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
1372 DEBUG ((DEBUG_DISPATCH
, " RESULT = TRUE (Apriori)\n"));
1379 // Free data allocated by Fv->ReadSection ()
1381 // The UEFI Boot Services FreePool() function must be used because Fv->ReadSection
1382 // used the UEFI Boot Services AllocatePool() function
1384 gBS
->FreePool (AprioriFile
);
1388 // Execute the SMM Dispatcher on any newly discovered FVs and previously
1389 // discovered SMM drivers that have been discovered but not dispatched.
1391 Status
= SmmDispatcher ();
1394 // Check to see if CommBuffer and CommBufferSize are valid
1396 if (CommBuffer
!= NULL
&& CommBufferSize
!= NULL
) {
1397 if (*CommBufferSize
> 0) {
1398 if (Status
== EFI_NOT_READY
) {
1400 // If a the SMM Core Entry Point was just registered, then set flag to
1401 // request the SMM Dispatcher to be restarted.
1403 *(UINT8
*)CommBuffer
= COMM_BUFFER_SMM_DISPATCH_RESTART
;
1404 } else if (!EFI_ERROR (Status
)) {
1406 // Set the flag to show that the SMM Dispatcher executed without errors
1408 *(UINT8
*)CommBuffer
= COMM_BUFFER_SMM_DISPATCH_SUCCESS
;
1411 // Set the flag to show that the SMM Dispatcher encountered an error
1413 *(UINT8
*)CommBuffer
= COMM_BUFFER_SMM_DISPATCH_ERROR
;
1422 Traverse the discovered list for any drivers that were discovered but not loaded
1423 because the dependency experessions evaluated to false.
1427 SmmDisplayDiscoveredNotDispatched (
1432 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
1434 for (Link
= mDiscoveredList
.ForwardLink
;Link
!=&mDiscoveredList
; Link
= Link
->ForwardLink
) {
1435 DriverEntry
= CR(Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
1436 if (DriverEntry
->Dependent
) {
1437 DEBUG ((DEBUG_LOAD
, "SMM Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));