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 - 2018, Intel Corporation. All rights reserved.<BR>
32 SPDX-License-Identifier: BSD-2-Clause-Patent
36 #include "PiSmmCore.h"
39 // SMM Dispatcher Data structures
41 #define KNOWN_HANDLE_SIGNATURE SIGNATURE_32('k','n','o','w')
44 LIST_ENTRY Link
; // mFvHandleList
49 // Function Prototypes
53 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
54 must add any driver with a before dependency on InsertedDriverEntry first.
55 You do this by recursively calling this routine. After all the Befores are
56 processed you can add InsertedDriverEntry to the mScheduledQueue.
57 Then you can add any driver with an After dependency on InsertedDriverEntry
58 by recursively calling this routine.
60 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
64 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
65 IN EFI_SMM_DRIVER_ENTRY
*InsertedDriverEntry
69 // The Driver List contains one copy of every driver that has been discovered.
70 // Items are never removed from the driver list. List of EFI_SMM_DRIVER_ENTRY
72 LIST_ENTRY mDiscoveredList
= INITIALIZE_LIST_HEAD_VARIABLE (mDiscoveredList
);
75 // Queue of drivers that are ready to dispatch. This queue is a subset of the
76 // mDiscoveredList.list of EFI_SMM_DRIVER_ENTRY.
78 LIST_ENTRY mScheduledQueue
= INITIALIZE_LIST_HEAD_VARIABLE (mScheduledQueue
);
81 // List of handles who's Fv's have been parsed and added to the mFwDriverList.
83 LIST_ENTRY mFvHandleList
= INITIALIZE_LIST_HEAD_VARIABLE (mFvHandleList
);
86 // Flag for the SMM Dispacher. TRUE if dispatcher is execuing.
88 BOOLEAN gDispatcherRunning
= FALSE
;
91 // Flag for the SMM Dispacher. TRUE if there is one or more SMM drivers ready to be dispatched
93 BOOLEAN gRequestDispatch
= FALSE
;
96 // List of file types supported by dispatcher
98 EFI_FV_FILETYPE mSmmFileTypes
[] = {
100 EFI_FV_FILETYPE_COMBINED_SMM_DXE
,
101 EFI_FV_FILETYPE_SMM_CORE
,
103 // Note: DXE core will process the FV image file, so skip it in SMM core
104 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
109 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH File
;
110 EFI_DEVICE_PATH_PROTOCOL End
;
111 } FV_FILEPATH_DEVICE_PATH
;
113 FV_FILEPATH_DEVICE_PATH mFvDevicePath
;
116 // DXE Architecture Protocols
118 EFI_SECURITY_ARCH_PROTOCOL
*mSecurity
= NULL
;
119 EFI_SECURITY2_ARCH_PROTOCOL
*mSecurity2
= NULL
;
122 // The global variable is defined for Loading modules at fixed address feature to track the SMM code
123 // memory range usage. It is a bit mapped array in which every bit indicates the corresponding
124 // memory page available or not.
126 GLOBAL_REMOVE_IF_UNREFERENCED UINT64
*mSmmCodeMemoryRangeUsageBitMap
=NULL
;
129 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
130 memory range is available, the function will mark the corresponding bits to 1 which indicates the memory range is used.
131 The function is only invoked when load modules at fixed address feature is enabled.
133 @param ImageBase The base address the image will be loaded at.
134 @param ImageSize The size of the image
136 @retval EFI_SUCCESS The memory range the image will be loaded in is available
137 @retval EFI_NOT_FOUND The memory range the image will be loaded in is not available
140 CheckAndMarkFixLoadingMemoryUsageBitMap (
141 IN EFI_PHYSICAL_ADDRESS ImageBase
,
145 UINT32 SmmCodePageNumber
;
147 EFI_PHYSICAL_ADDRESS SmmCodeBase
;
148 UINTN BaseOffsetPageNumber
;
149 UINTN TopOffsetPageNumber
;
152 // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
154 SmmCodePageNumber
= PcdGet32(PcdLoadFixAddressSmmCodePageNumber
);
155 SmmCodeSize
= EFI_PAGES_TO_SIZE (SmmCodePageNumber
);
156 SmmCodeBase
= gLoadModuleAtFixAddressSmramBase
;
159 // If the memory usage bit map is not initialized, do it. Every bit in the array
160 // indicate the status of the corresponding memory page, available or not
162 if (mSmmCodeMemoryRangeUsageBitMap
== NULL
) {
163 mSmmCodeMemoryRangeUsageBitMap
= AllocateZeroPool(((SmmCodePageNumber
/ 64) + 1)*sizeof(UINT64
));
166 // If the Dxe code memory range is not allocated or the bit map array allocation failed, return EFI_NOT_FOUND
168 if (mSmmCodeMemoryRangeUsageBitMap
== NULL
) {
169 return EFI_NOT_FOUND
;
172 // see if the memory range for loading the image is in the SMM code range.
174 if (SmmCodeBase
+ SmmCodeSize
< ImageBase
+ ImageSize
|| SmmCodeBase
> ImageBase
) {
175 return EFI_NOT_FOUND
;
178 // Test if the memory is avalaible or not.
180 BaseOffsetPageNumber
= EFI_SIZE_TO_PAGES((UINT32
)(ImageBase
- SmmCodeBase
));
181 TopOffsetPageNumber
= EFI_SIZE_TO_PAGES((UINT32
)(ImageBase
+ ImageSize
- SmmCodeBase
));
182 for (Index
= BaseOffsetPageNumber
; Index
< TopOffsetPageNumber
; Index
++) {
183 if ((mSmmCodeMemoryRangeUsageBitMap
[Index
/ 64] & LShiftU64(1, (Index
% 64))) != 0) {
185 // This page is already used.
187 return EFI_NOT_FOUND
;
192 // Being here means the memory range is available. So mark the bits for the memory range
194 for (Index
= BaseOffsetPageNumber
; Index
< TopOffsetPageNumber
; Index
++) {
195 mSmmCodeMemoryRangeUsageBitMap
[Index
/ 64] |= LShiftU64(1, (Index
% 64));
200 Get the fixed loading address from image header assigned by build tool. This function only be called
201 when Loading module at Fixed address feature enabled.
203 @param ImageContext Pointer to the image context structure that describes the PE/COFF
204 image that needs to be examined by this function.
205 @retval EFI_SUCCESS An fixed loading address is assigned to this image by build tools .
206 @retval EFI_NOT_FOUND The image has no assigned fixed loading address.
210 GetPeCoffImageFixLoadingAssignedAddress(
211 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
214 UINTN SectionHeaderOffset
;
216 EFI_IMAGE_SECTION_HEADER SectionHeader
;
217 EFI_IMAGE_OPTIONAL_HEADER_UNION
*ImgHdr
;
218 EFI_PHYSICAL_ADDRESS FixLoadingAddress
;
221 UINT16 NumberOfSections
;
222 UINT64 ValueInSectionHeader
;
224 FixLoadingAddress
= 0;
225 Status
= EFI_NOT_FOUND
;
228 // Get PeHeader pointer
230 ImgHdr
= (EFI_IMAGE_OPTIONAL_HEADER_UNION
*)((CHAR8
* )ImageContext
->Handle
+ ImageContext
->PeCoffHeaderOffset
);
231 SectionHeaderOffset
= ImageContext
->PeCoffHeaderOffset
+
233 sizeof (EFI_IMAGE_FILE_HEADER
) +
234 ImgHdr
->Pe32
.FileHeader
.SizeOfOptionalHeader
;
235 NumberOfSections
= ImgHdr
->Pe32
.FileHeader
.NumberOfSections
;
238 // Get base address from the first section header that doesn't point to code section.
240 for (Index
= 0; Index
< NumberOfSections
; Index
++) {
242 // Read section header from file
244 Size
= sizeof (EFI_IMAGE_SECTION_HEADER
);
245 Status
= ImageContext
->ImageRead (
246 ImageContext
->Handle
,
251 if (EFI_ERROR (Status
)) {
255 Status
= EFI_NOT_FOUND
;
257 if ((SectionHeader
.Characteristics
& EFI_IMAGE_SCN_CNT_CODE
) == 0) {
259 // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields in the first section header
260 // that doesn't point to code section in image header.So there is an assumption that when the feature is enabled,
261 // if a module with a loading address assigned by tools, the PointerToRelocations & PointerToLineNumbers fields
262 // should not be Zero, or else, these 2 fields should be set to Zero
264 ValueInSectionHeader
= ReadUnaligned64((UINT64
*)&SectionHeader
.PointerToRelocations
);
265 if (ValueInSectionHeader
!= 0) {
267 // Found first section header that doesn't point to code section in which build tool saves the
268 // offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
270 FixLoadingAddress
= (EFI_PHYSICAL_ADDRESS
)(gLoadModuleAtFixAddressSmramBase
+ (INT64
)ValueInSectionHeader
);
272 // Check if the memory range is available.
274 Status
= CheckAndMarkFixLoadingMemoryUsageBitMap (FixLoadingAddress
, (UINTN
)(ImageContext
->ImageSize
+ ImageContext
->SectionAlignment
));
275 if (!EFI_ERROR(Status
)) {
277 // The assigned address is valid. Return the specified loading address
279 ImageContext
->ImageAddress
= FixLoadingAddress
;
284 SectionHeaderOffset
+= sizeof (EFI_IMAGE_SECTION_HEADER
);
286 DEBUG ((EFI_D_INFO
|EFI_D_LOAD
, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r\n", FixLoadingAddress
, Status
));
290 Loads an EFI image into SMRAM.
292 @param DriverEntry EFI_SMM_DRIVER_ENTRY instance
300 IN OUT EFI_SMM_DRIVER_ENTRY
*DriverEntry
303 UINT32 AuthenticationStatus
;
310 EFI_STATUS SecurityStatus
;
311 EFI_HANDLE DeviceHandle
;
312 EFI_PHYSICAL_ADDRESS DstBuffer
;
313 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
314 EFI_DEVICE_PATH_PROTOCOL
*OriginalFilePath
;
315 EFI_DEVICE_PATH_PROTOCOL
*HandleFilePath
;
316 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
317 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
319 PERF_LOAD_IMAGE_BEGIN (DriverEntry
->ImageHandle
);
323 Fv
= DriverEntry
->Fv
;
324 NameGuid
= &DriverEntry
->FileName
;
325 FilePath
= DriverEntry
->FvFileDevicePath
;
327 OriginalFilePath
= FilePath
;
328 HandleFilePath
= FilePath
;
330 SecurityStatus
= EFI_SUCCESS
;
331 Status
= EFI_SUCCESS
;
332 AuthenticationStatus
= 0;
335 // Try to get the image device handle by checking the match protocol.
337 Status
= gBS
->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid
, &HandleFilePath
, &DeviceHandle
);
338 if (EFI_ERROR(Status
)) {
343 // If the Security2 and Security Architectural Protocol has not been located yet, then attempt to locate it
345 if (mSecurity2
== NULL
) {
346 gBS
->LocateProtocol (&gEfiSecurity2ArchProtocolGuid
, NULL
, (VOID
**)&mSecurity2
);
348 if (mSecurity
== NULL
) {
349 gBS
->LocateProtocol (&gEfiSecurityArchProtocolGuid
, NULL
, (VOID
**)&mSecurity
);
352 // When Security2 is installed, Security Architectural Protocol must be published.
354 ASSERT (mSecurity2
== NULL
|| mSecurity
!= NULL
);
357 // Pull out just the file portion of the DevicePath for the LoadedImage FilePath
359 FilePath
= OriginalFilePath
;
360 Status
= gBS
->HandleProtocol (DeviceHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&HandleFilePath
);
361 if (!EFI_ERROR (Status
)) {
362 FilePathSize
= GetDevicePathSize (HandleFilePath
) - sizeof(EFI_DEVICE_PATH_PROTOCOL
);
363 FilePath
= (EFI_DEVICE_PATH_PROTOCOL
*) (((UINT8
*)FilePath
) + FilePathSize
);
367 // Try reading PE32 section firstly
369 Status
= Fv
->ReadSection (
376 &AuthenticationStatus
379 if (EFI_ERROR (Status
)) {
381 // Try reading TE section secondly
385 Status
= Fv
->ReadSection (
392 &AuthenticationStatus
396 if (EFI_ERROR (Status
)) {
397 if (Buffer
!= NULL
) {
398 gBS
->FreePool (Buffer
);
404 // Verify File Authentication through the Security2 Architectural Protocol
406 if (mSecurity2
!= NULL
) {
407 SecurityStatus
= mSecurity2
->FileAuthentication (
417 // Verify the Authentication Status through the Security Architectural Protocol
418 // Only on images that have been read using Firmware Volume protocol.
419 // All SMM images are from FV protocol.
421 if (!EFI_ERROR (SecurityStatus
) && (mSecurity
!= NULL
)) {
422 SecurityStatus
= mSecurity
->FileAuthenticationState (
424 AuthenticationStatus
,
429 if (EFI_ERROR (SecurityStatus
) && SecurityStatus
!= EFI_SECURITY_VIOLATION
) {
430 Status
= SecurityStatus
;
435 // Initialize ImageContext
437 ImageContext
.Handle
= Buffer
;
438 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
441 // Get information about the image being loaded
443 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
444 if (EFI_ERROR (Status
)) {
445 if (Buffer
!= NULL
) {
446 gBS
->FreePool (Buffer
);
451 // if Loading module at Fixed Address feature is enabled, then cut out a memory range started from TESG BASE
452 // to hold the Smm driver code
454 if (PcdGet64(PcdLoadModuleAtFixAddressEnable
) != 0) {
456 // Get the fixed loading address assigned by Build tool
458 Status
= GetPeCoffImageFixLoadingAssignedAddress (&ImageContext
);
459 if (!EFI_ERROR (Status
)) {
461 // Since the memory range to load Smm core alreay been cut out, so no need to allocate and free this range
462 // following statements is to bypass SmmFreePages
465 DstBuffer
= (UINTN
)gLoadModuleAtFixAddressSmramBase
;
467 DEBUG ((EFI_D_INFO
|EFI_D_LOAD
, "LOADING MODULE FIXED ERROR: Failed to load module at fixed address. \n"));
469 // allocate the memory to load the SMM driver
471 PageCount
= (UINTN
)EFI_SIZE_TO_PAGES((UINTN
)ImageContext
.ImageSize
+ ImageContext
.SectionAlignment
);
472 DstBuffer
= (UINTN
)(-1);
474 Status
= SmmAllocatePages (
476 EfiRuntimeServicesCode
,
480 if (EFI_ERROR (Status
)) {
481 if (Buffer
!= NULL
) {
482 gBS
->FreePool (Buffer
);
486 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)DstBuffer
;
489 PageCount
= (UINTN
)EFI_SIZE_TO_PAGES((UINTN
)ImageContext
.ImageSize
+ ImageContext
.SectionAlignment
);
490 DstBuffer
= (UINTN
)(-1);
492 Status
= SmmAllocatePages (
494 EfiRuntimeServicesCode
,
498 if (EFI_ERROR (Status
)) {
499 if (Buffer
!= NULL
) {
500 gBS
->FreePool (Buffer
);
505 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)DstBuffer
;
508 // Align buffer on section boundary
510 ImageContext
.ImageAddress
+= ImageContext
.SectionAlignment
- 1;
511 ImageContext
.ImageAddress
&= ~((EFI_PHYSICAL_ADDRESS
)ImageContext
.SectionAlignment
- 1);
514 // Load the image to our new buffer
516 Status
= PeCoffLoaderLoadImage (&ImageContext
);
517 if (EFI_ERROR (Status
)) {
518 if (Buffer
!= NULL
) {
519 gBS
->FreePool (Buffer
);
521 SmmFreePages (DstBuffer
, PageCount
);
526 // Relocate the image in our new buffer
528 Status
= PeCoffLoaderRelocateImage (&ImageContext
);
529 if (EFI_ERROR (Status
)) {
530 if (Buffer
!= NULL
) {
531 gBS
->FreePool (Buffer
);
533 SmmFreePages (DstBuffer
, PageCount
);
538 // Flush the instruction cache so the image data are written before we execute it
540 InvalidateInstructionCacheRange ((VOID
*)(UINTN
) ImageContext
.ImageAddress
, (UINTN
) ImageContext
.ImageSize
);
543 // Save Image EntryPoint in DriverEntry
545 DriverEntry
->ImageEntryPoint
= ImageContext
.EntryPoint
;
546 DriverEntry
->ImageBuffer
= DstBuffer
;
547 DriverEntry
->NumberOfPage
= PageCount
;
550 // Allocate a Loaded Image Protocol in EfiBootServicesData
552 Status
= gBS
->AllocatePool (EfiBootServicesData
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
), (VOID
**)&DriverEntry
->LoadedImage
);
553 if (EFI_ERROR (Status
)) {
554 if (Buffer
!= NULL
) {
555 gBS
->FreePool (Buffer
);
557 SmmFreePages (DstBuffer
, PageCount
);
561 ZeroMem (DriverEntry
->LoadedImage
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
));
563 // Fill in the remaining fields of the Loaded Image Protocol instance.
564 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
566 DriverEntry
->LoadedImage
->Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
567 DriverEntry
->LoadedImage
->ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
568 DriverEntry
->LoadedImage
->SystemTable
= gST
;
569 DriverEntry
->LoadedImage
->DeviceHandle
= DeviceHandle
;
571 DriverEntry
->SmmLoadedImage
.Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
572 DriverEntry
->SmmLoadedImage
.ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
573 DriverEntry
->SmmLoadedImage
.SystemTable
= gST
;
574 DriverEntry
->SmmLoadedImage
.DeviceHandle
= DeviceHandle
;
577 // Make an EfiBootServicesData buffer copy of FilePath
579 Status
= gBS
->AllocatePool (EfiBootServicesData
, GetDevicePathSize (FilePath
), (VOID
**)&DriverEntry
->LoadedImage
->FilePath
);
580 if (EFI_ERROR (Status
)) {
581 if (Buffer
!= NULL
) {
582 gBS
->FreePool (Buffer
);
584 SmmFreePages (DstBuffer
, PageCount
);
587 CopyMem (DriverEntry
->LoadedImage
->FilePath
, FilePath
, GetDevicePathSize (FilePath
));
589 DriverEntry
->LoadedImage
->ImageBase
= (VOID
*)(UINTN
) ImageContext
.ImageAddress
;
590 DriverEntry
->LoadedImage
->ImageSize
= ImageContext
.ImageSize
;
591 DriverEntry
->LoadedImage
->ImageCodeType
= EfiRuntimeServicesCode
;
592 DriverEntry
->LoadedImage
->ImageDataType
= EfiRuntimeServicesData
;
595 // Make a buffer copy of FilePath
597 Status
= SmmAllocatePool (EfiRuntimeServicesData
, GetDevicePathSize(FilePath
), (VOID
**)&DriverEntry
->SmmLoadedImage
.FilePath
);
598 if (EFI_ERROR (Status
)) {
599 if (Buffer
!= NULL
) {
600 gBS
->FreePool (Buffer
);
602 gBS
->FreePool (DriverEntry
->LoadedImage
->FilePath
);
603 SmmFreePages (DstBuffer
, PageCount
);
606 CopyMem (DriverEntry
->SmmLoadedImage
.FilePath
, FilePath
, GetDevicePathSize(FilePath
));
608 DriverEntry
->SmmLoadedImage
.ImageBase
= (VOID
*)(UINTN
) ImageContext
.ImageAddress
;
609 DriverEntry
->SmmLoadedImage
.ImageSize
= ImageContext
.ImageSize
;
610 DriverEntry
->SmmLoadedImage
.ImageCodeType
= EfiRuntimeServicesCode
;
611 DriverEntry
->SmmLoadedImage
.ImageDataType
= EfiRuntimeServicesData
;
614 // Create a new image handle in the UEFI handle database for the SMM Driver
616 DriverEntry
->ImageHandle
= NULL
;
617 Status
= gBS
->InstallMultipleProtocolInterfaces (
618 &DriverEntry
->ImageHandle
,
619 &gEfiLoadedImageProtocolGuid
, DriverEntry
->LoadedImage
,
624 // Create a new image handle in the SMM handle database for the SMM Driver
626 DriverEntry
->SmmImageHandle
= NULL
;
627 Status
= SmmInstallProtocolInterface (
628 &DriverEntry
->SmmImageHandle
,
629 &gEfiLoadedImageProtocolGuid
,
630 EFI_NATIVE_INTERFACE
,
631 &DriverEntry
->SmmLoadedImage
634 PERF_LOAD_IMAGE_END (DriverEntry
->ImageHandle
);
637 // Print the load address and the PDB file name if it is available
644 CHAR8 EfiFileName
[256];
647 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
,
648 "Loading SMM driver at 0x%11p EntryPoint=0x%11p ",
649 (VOID
*)(UINTN
) ImageContext
.ImageAddress
,
650 FUNCTION_ENTRY_POINT (ImageContext
.EntryPoint
)));
654 // Print Module Name by Pdb file path.
655 // Windows and Unix style file path are all trimmed correctly.
657 if (ImageContext
.PdbPointer
!= NULL
) {
659 for (Index
= 0; ImageContext
.PdbPointer
[Index
] != 0; Index
++) {
660 if ((ImageContext
.PdbPointer
[Index
] == '\\') || (ImageContext
.PdbPointer
[Index
] == '/')) {
661 StartIndex
= Index
+ 1;
665 // Copy the PDB file name to our temporary string, and replace .pdb with .efi
666 // The PDB file name is limited in the range of 0~255.
667 // If the length is bigger than 255, trim the redudant characters to avoid overflow in array boundary.
669 for (Index
= 0; Index
< sizeof (EfiFileName
) - 4; Index
++) {
670 EfiFileName
[Index
] = ImageContext
.PdbPointer
[Index
+ StartIndex
];
671 if (EfiFileName
[Index
] == 0) {
672 EfiFileName
[Index
] = '.';
674 if (EfiFileName
[Index
] == '.') {
675 EfiFileName
[Index
+ 1] = 'e';
676 EfiFileName
[Index
+ 2] = 'f';
677 EfiFileName
[Index
+ 3] = 'i';
678 EfiFileName
[Index
+ 4] = 0;
683 if (Index
== sizeof (EfiFileName
) - 4) {
684 EfiFileName
[Index
] = 0;
686 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "%a", EfiFileName
)); // &Image->ImageContext.PdbPointer[StartIndex]));
688 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "\n"));
693 // Free buffer allocated by Fv->ReadSection.
695 // The UEFI Boot Services FreePool() function must be used because Fv->ReadSection
696 // used the UEFI Boot Services AllocatePool() function
698 Status
= gBS
->FreePool(Buffer
);
699 if (!EFI_ERROR (Status
) && EFI_ERROR (SecurityStatus
)) {
700 Status
= SecurityStatus
;
706 Preprocess dependency expression and update DriverEntry to reflect the
707 state of Before and After dependencies. If DriverEntry->Before
708 or DriverEntry->After is set it will never be cleared.
710 @param DriverEntry DriverEntry element to update .
712 @retval EFI_SUCCESS It always works.
717 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
722 Iterator
= DriverEntry
->Depex
;
723 DriverEntry
->Dependent
= TRUE
;
725 if (*Iterator
== EFI_DEP_BEFORE
) {
726 DriverEntry
->Before
= TRUE
;
727 } else if (*Iterator
== EFI_DEP_AFTER
) {
728 DriverEntry
->After
= TRUE
;
731 if (DriverEntry
->Before
|| DriverEntry
->After
) {
732 CopyMem (&DriverEntry
->BeforeAfterGuid
, Iterator
+ 1, sizeof (EFI_GUID
));
739 Read Depex and pre-process the Depex for Before and After. If Section Extraction
740 protocol returns an error via ReadSection defer the reading of the Depex.
742 @param DriverEntry Driver to work on.
744 @retval EFI_SUCCESS Depex read and preprossesed
745 @retval EFI_PROTOCOL_ERROR The section extraction protocol returned an error
746 and Depex reading needs to be retried.
747 @retval Error DEPEX not found.
751 SmmGetDepexSectionAndPreProccess (
752 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
756 EFI_SECTION_TYPE SectionType
;
757 UINT32 AuthenticationStatus
;
758 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
760 Fv
= DriverEntry
->Fv
;
763 // Grab Depex info, it will never be free'ed.
764 // (Note: DriverEntry->Depex is in DXE memory)
766 SectionType
= EFI_SECTION_SMM_DEPEX
;
767 Status
= Fv
->ReadSection (
769 &DriverEntry
->FileName
,
773 (UINTN
*)&DriverEntry
->DepexSize
,
774 &AuthenticationStatus
776 if (EFI_ERROR (Status
)) {
777 if (Status
== EFI_PROTOCOL_ERROR
) {
779 // The section extraction protocol failed so set protocol error flag
781 DriverEntry
->DepexProtocolError
= TRUE
;
784 // If no Depex assume depend on all architectural protocols
786 DriverEntry
->Depex
= NULL
;
787 DriverEntry
->Dependent
= TRUE
;
788 DriverEntry
->DepexProtocolError
= FALSE
;
792 // Set Before and After state information based on Depex
793 // Driver will be put in Dependent state
795 SmmPreProcessDepex (DriverEntry
);
796 DriverEntry
->DepexProtocolError
= FALSE
;
803 This is the main Dispatcher for SMM and it exits when there are no more
804 drivers to run. Drain the mScheduledQueue and load and start a PE
805 image for each driver. Search the mDiscoveredList to see if any driver can
806 be placed on the mScheduledQueue. If no drivers are placed on the
807 mScheduledQueue exit the function.
809 @retval EFI_SUCCESS All of the SMM Drivers that could be dispatched
810 have been run and the SMM Entry Point has been
812 @retval EFI_NOT_READY The SMM Driver that registered the SMM Entry Point
814 @retval EFI_NOT_FOUND There are no SMM Drivers available to be dispatched.
815 @retval EFI_ALREADY_STARTED The SMM Dispatcher is already running
825 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
827 BOOLEAN PreviousSmmEntryPointRegistered
;
829 if (!gRequestDispatch
) {
830 return EFI_NOT_FOUND
;
833 if (gDispatcherRunning
) {
835 // If the dispatcher is running don't let it be restarted.
837 return EFI_ALREADY_STARTED
;
840 gDispatcherRunning
= TRUE
;
844 // Drain the Scheduled Queue
846 while (!IsListEmpty (&mScheduledQueue
)) {
848 mScheduledQueue
.ForwardLink
,
849 EFI_SMM_DRIVER_ENTRY
,
851 EFI_SMM_DRIVER_ENTRY_SIGNATURE
855 // Load the SMM Driver image into memory. If the Driver was transitioned from
856 // Untrused to Scheduled it would have already been loaded so we may need to
857 // skip the LoadImage
859 if (DriverEntry
->ImageHandle
== NULL
) {
860 Status
= SmmLoadImage (DriverEntry
);
863 // Update the driver state to reflect that it's been loaded
865 if (EFI_ERROR (Status
)) {
867 // The SMM Driver could not be loaded, and do not attempt to load or start it again.
868 // Take driver from Scheduled to Initialized.
870 DriverEntry
->Initialized
= TRUE
;
871 DriverEntry
->Scheduled
= FALSE
;
872 RemoveEntryList (&DriverEntry
->ScheduledLink
);
875 // If it's an error don't try the StartImage
881 DriverEntry
->Scheduled
= FALSE
;
882 DriverEntry
->Initialized
= TRUE
;
883 RemoveEntryList (&DriverEntry
->ScheduledLink
);
885 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
887 EFI_SOFTWARE_SMM_DRIVER
| EFI_SW_PC_INIT_BEGIN
,
888 &DriverEntry
->ImageHandle
,
889 sizeof (DriverEntry
->ImageHandle
)
893 // Cache state of SmmEntryPointRegistered before calling entry point
895 PreviousSmmEntryPointRegistered
= gSmmCorePrivate
->SmmEntryPointRegistered
;
898 // For each SMM driver, pass NULL as ImageHandle
900 RegisterSmramProfileImage (DriverEntry
, TRUE
);
901 PERF_START_IMAGE_BEGIN (DriverEntry
->ImageHandle
);
902 Status
= ((EFI_IMAGE_ENTRY_POINT
)(UINTN
)DriverEntry
->ImageEntryPoint
)(DriverEntry
->ImageHandle
, gST
);
903 PERF_START_IMAGE_END (DriverEntry
->ImageHandle
);
904 if (EFI_ERROR(Status
)){
905 UnregisterSmramProfileImage (DriverEntry
, TRUE
);
906 SmmFreePages(DriverEntry
->ImageBuffer
, DriverEntry
->NumberOfPage
);
908 // Uninstall LoadedImage
910 Status
= gBS
->UninstallProtocolInterface (
911 DriverEntry
->ImageHandle
,
912 &gEfiLoadedImageProtocolGuid
,
913 DriverEntry
->LoadedImage
915 if (!EFI_ERROR (Status
)) {
916 if (DriverEntry
->LoadedImage
->FilePath
!= NULL
) {
917 gBS
->FreePool (DriverEntry
->LoadedImage
->FilePath
);
919 gBS
->FreePool (DriverEntry
->LoadedImage
);
921 Status
= SmmUninstallProtocolInterface (
922 DriverEntry
->SmmImageHandle
,
923 &gEfiLoadedImageProtocolGuid
,
924 &DriverEntry
->SmmLoadedImage
926 if (!EFI_ERROR(Status
)) {
927 if (DriverEntry
->SmmLoadedImage
.FilePath
!= NULL
) {
928 SmmFreePool (DriverEntry
->SmmLoadedImage
.FilePath
);
933 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
935 EFI_SOFTWARE_SMM_DRIVER
| EFI_SW_PC_INIT_END
,
936 &DriverEntry
->ImageHandle
,
937 sizeof (DriverEntry
->ImageHandle
)
940 if (!PreviousSmmEntryPointRegistered
&& gSmmCorePrivate
->SmmEntryPointRegistered
) {
942 // Return immediately if the SMM Entry Point was registered by the SMM
943 // Driver that was just dispatched. The SMM IPL will reinvoke the SMM
944 // Core Dispatcher. This is required so SMM Mode may be enabled as soon
945 // as all the dependent SMM Drivers for SMM Mode have been dispatched.
946 // Once the SMM Entry Point has been registered, then SMM Mode will be
949 gRequestDispatch
= TRUE
;
950 gDispatcherRunning
= FALSE
;
951 return EFI_NOT_READY
;
956 // Search DriverList for items to place on Scheduled Queue
959 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
960 DriverEntry
= CR (Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
962 if (DriverEntry
->DepexProtocolError
){
964 // If Section Extraction Protocol did not let the Depex be read before retry the read
966 Status
= SmmGetDepexSectionAndPreProccess (DriverEntry
);
969 if (DriverEntry
->Dependent
) {
970 if (SmmIsSchedulable (DriverEntry
)) {
971 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
976 } while (ReadyToRun
);
979 // If there is no more SMM driver to dispatch, stop the dispatch request
981 gRequestDispatch
= FALSE
;
982 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
983 DriverEntry
= CR (Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
985 if (!DriverEntry
->Initialized
){
987 // We have SMM driver pending to dispatch
989 gRequestDispatch
= TRUE
;
994 gDispatcherRunning
= FALSE
;
1000 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
1001 must add any driver with a before dependency on InsertedDriverEntry first.
1002 You do this by recursively calling this routine. After all the Befores are
1003 processed you can add InsertedDriverEntry to the mScheduledQueue.
1004 Then you can add any driver with an After dependency on InsertedDriverEntry
1005 by recursively calling this routine.
1007 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
1011 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
1012 IN EFI_SMM_DRIVER_ENTRY
*InsertedDriverEntry
1016 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
1019 // Process Before Dependency
1021 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1022 DriverEntry
= CR(Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
1023 if (DriverEntry
->Before
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
1024 DEBUG ((DEBUG_DISPATCH
, "Evaluate SMM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
1025 DEBUG ((DEBUG_DISPATCH
, " BEFORE FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
1026 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
1028 // Recursively process BEFORE
1030 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
1031 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
1033 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
1039 // Convert driver from Dependent to Scheduled state
1042 InsertedDriverEntry
->Dependent
= FALSE
;
1043 InsertedDriverEntry
->Scheduled
= TRUE
;
1044 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
1048 // Process After Dependency
1050 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1051 DriverEntry
= CR(Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
1052 if (DriverEntry
->After
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
1053 DEBUG ((DEBUG_DISPATCH
, "Evaluate SMM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
1054 DEBUG ((DEBUG_DISPATCH
, " AFTER FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
1055 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
1057 // Recursively process AFTER
1059 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
1060 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
1062 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
1069 Return TRUE if the Fv has been processed, FALSE if not.
1071 @param FvHandle The handle of a FV that's being tested
1073 @retval TRUE Fv protocol on FvHandle has been processed
1074 @retval FALSE Fv protocol on FvHandle has not yet been
1079 FvHasBeenProcessed (
1080 IN EFI_HANDLE FvHandle
1084 KNOWN_HANDLE
*KnownHandle
;
1086 for (Link
= mFvHandleList
.ForwardLink
; Link
!= &mFvHandleList
; Link
= Link
->ForwardLink
) {
1087 KnownHandle
= CR(Link
, KNOWN_HANDLE
, Link
, KNOWN_HANDLE_SIGNATURE
);
1088 if (KnownHandle
->Handle
== FvHandle
) {
1096 Remember that Fv protocol on FvHandle has had it's drivers placed on the
1097 mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are
1098 never removed/freed from the mFvHandleList.
1100 @param FvHandle The handle of a FV that has been processed
1104 FvIsBeingProcessed (
1105 IN EFI_HANDLE FvHandle
1108 KNOWN_HANDLE
*KnownHandle
;
1110 KnownHandle
= AllocatePool (sizeof (KNOWN_HANDLE
));
1111 ASSERT (KnownHandle
!= NULL
);
1113 KnownHandle
->Signature
= KNOWN_HANDLE_SIGNATURE
;
1114 KnownHandle
->Handle
= FvHandle
;
1115 InsertTailList (&mFvHandleList
, &KnownHandle
->Link
);
1119 Convert FvHandle and DriverName into an EFI device path
1121 @param Fv Fv protocol, needed to read Depex info out of
1123 @param FvHandle Handle for Fv, needed in the
1124 EFI_SMM_DRIVER_ENTRY so that the PE image can be
1125 read out of the FV at a later time.
1126 @param DriverName Name of driver to add to mDiscoveredList.
1128 @return Pointer to device path constructed from FvHandle and DriverName
1131 EFI_DEVICE_PATH_PROTOCOL
*
1133 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
1134 IN EFI_HANDLE FvHandle
,
1135 IN EFI_GUID
*DriverName
1139 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
1140 EFI_DEVICE_PATH_PROTOCOL
*FileNameDevicePath
;
1143 // Remember the device path of the FV
1145 Status
= gBS
->HandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
1146 if (EFI_ERROR (Status
)) {
1147 FileNameDevicePath
= NULL
;
1150 // Build a device path to the file in the FV to pass into gBS->LoadImage
1152 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, DriverName
);
1153 SetDevicePathEndNode (&mFvDevicePath
.End
);
1156 // Note: FileNameDevicePath is in DXE memory
1158 FileNameDevicePath
= AppendDevicePath (
1160 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
1163 return FileNameDevicePath
;
1167 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
1168 and initilize any state variables. Read the Depex from the FV and store it
1169 in DriverEntry. Pre-process the Depex to set the Before and After state.
1170 The Discovered list is never free'ed and contains booleans that represent the
1171 other possible SMM driver states.
1173 @param Fv Fv protocol, needed to read Depex info out of
1175 @param FvHandle Handle for Fv, needed in the
1176 EFI_SMM_DRIVER_ENTRY so that the PE image can be
1177 read out of the FV at a later time.
1178 @param DriverName Name of driver to add to mDiscoveredList.
1180 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
1181 @retval EFI_ALREADY_STARTED The driver has already been started. Only one
1182 DriverName may be active in the system at any one
1187 SmmAddToDriverList (
1188 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
1189 IN EFI_HANDLE FvHandle
,
1190 IN EFI_GUID
*DriverName
1193 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
1196 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
1199 DriverEntry
= AllocateZeroPool (sizeof (EFI_SMM_DRIVER_ENTRY
));
1200 ASSERT (DriverEntry
!= NULL
);
1202 DriverEntry
->Signature
= EFI_SMM_DRIVER_ENTRY_SIGNATURE
;
1203 CopyGuid (&DriverEntry
->FileName
, DriverName
);
1204 DriverEntry
->FvHandle
= FvHandle
;
1205 DriverEntry
->Fv
= Fv
;
1206 DriverEntry
->FvFileDevicePath
= SmmFvToDevicePath (Fv
, FvHandle
, DriverName
);
1208 SmmGetDepexSectionAndPreProccess (DriverEntry
);
1210 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
1211 gRequestDispatch
= TRUE
;
1217 This function is the main entry point for an SMM handler dispatch
1218 or communicate-based callback.
1220 Event notification that is fired every time a FV dispatch protocol is added.
1221 More than one protocol may have been added when this event is fired, so you
1222 must loop on SmmLocateHandle () to see how many protocols were added and
1223 do the following to each FV:
1224 If the Fv has already been processed, skip it. If the Fv has not been
1225 processed then mark it as being processed, as we are about to process it.
1226 Read the Fv and add any driver in the Fv to the mDiscoveredList.The
1227 mDiscoveredList is never free'ed and contains variables that define
1228 the other states the SMM driver transitions to..
1229 While you are at it read the A Priori file into memory.
1230 Place drivers in the A Priori list onto the mScheduledQueue.
1232 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
1233 @param Context Points to an optional handler context which was specified when the handler was registered.
1234 @param CommBuffer A pointer to a collection of data in memory that will
1235 be conveyed from a non-SMM environment into an SMM environment.
1236 @param CommBufferSize The size of the CommBuffer.
1243 SmmDriverDispatchHandler (
1244 IN EFI_HANDLE DispatchHandle
,
1245 IN CONST VOID
*Context
, OPTIONAL
1246 IN OUT VOID
*CommBuffer
, OPTIONAL
1247 IN OUT UINTN
*CommBufferSize OPTIONAL
1252 EFI_HANDLE
*HandleBuffer
;
1253 EFI_STATUS GetNextFileStatus
;
1254 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
1255 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
1256 EFI_HANDLE FvHandle
;
1259 EFI_FV_FILETYPE Type
;
1260 EFI_FV_FILE_ATTRIBUTES Attributes
;
1262 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
1263 EFI_GUID
*AprioriFile
;
1264 UINTN AprioriEntryCount
;
1269 UINT32 AuthenticationStatus
;
1272 HandleBuffer
= NULL
;
1273 Status
= gBS
->LocateHandleBuffer (
1275 &gEfiFirmwareVolume2ProtocolGuid
,
1280 if (EFI_ERROR (Status
)) {
1281 return EFI_NOT_FOUND
;
1284 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
1285 FvHandle
= HandleBuffer
[HandleIndex
];
1287 if (FvHasBeenProcessed (FvHandle
)) {
1289 // This Fv has already been processed so lets skip it!
1295 // Since we are about to process this Fv mark it as processed.
1297 FvIsBeingProcessed (FvHandle
);
1299 Status
= gBS
->HandleProtocol (FvHandle
, &gEfiFirmwareVolume2ProtocolGuid
, (VOID
**)&Fv
);
1300 if (EFI_ERROR (Status
)) {
1302 // FvHandle must have a Firmware Volume2 Protocol thus we should never get here.
1308 Status
= gBS
->HandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
1309 if (EFI_ERROR (Status
)) {
1311 // The Firmware volume doesn't have device path, can't be dispatched.
1317 // Discover Drivers in FV and add them to the Discovered Driver List.
1318 // Process EFI_FV_FILETYPE_SMM type and then EFI_FV_FILETYPE_COMBINED_SMM_DXE
1319 // EFI_FV_FILETYPE_SMM_CORE is processed to produce a Loaded Image protocol for the core
1321 for (SmmTypeIndex
= 0; SmmTypeIndex
< sizeof (mSmmFileTypes
)/sizeof (EFI_FV_FILETYPE
); SmmTypeIndex
++) {
1323 // Initialize the search key
1327 Type
= mSmmFileTypes
[SmmTypeIndex
];
1328 GetNextFileStatus
= Fv
->GetNextFile (
1336 if (!EFI_ERROR (GetNextFileStatus
)) {
1337 if (Type
== EFI_FV_FILETYPE_SMM_CORE
) {
1339 // If this is the SMM core fill in it's DevicePath & DeviceHandle
1341 if (mSmmCoreLoadedImage
->FilePath
== NULL
) {
1343 // Maybe one special FV contains only one SMM_CORE module, so its device path must
1344 // be initialized completely.
1346 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, &NameGuid
);
1347 SetDevicePathEndNode (&mFvDevicePath
.End
);
1350 // Make an EfiBootServicesData buffer copy of FilePath
1352 Status
= gBS
->AllocatePool (
1353 EfiBootServicesData
,
1354 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
),
1355 (VOID
**)&mSmmCoreLoadedImage
->FilePath
1357 ASSERT_EFI_ERROR (Status
);
1358 CopyMem (mSmmCoreLoadedImage
->FilePath
, &mFvDevicePath
, GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
));
1360 mSmmCoreLoadedImage
->DeviceHandle
= FvHandle
;
1362 if (mSmmCoreDriverEntry
->SmmLoadedImage
.FilePath
== NULL
) {
1364 // Maybe one special FV contains only one SMM_CORE module, so its device path must
1365 // be initialized completely.
1367 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, &NameGuid
);
1368 SetDevicePathEndNode (&mFvDevicePath
.End
);
1371 // Make a buffer copy FilePath
1373 Status
= SmmAllocatePool (
1374 EfiRuntimeServicesData
,
1375 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
),
1376 (VOID
**)&mSmmCoreDriverEntry
->SmmLoadedImage
.FilePath
1378 ASSERT_EFI_ERROR (Status
);
1379 CopyMem (mSmmCoreDriverEntry
->SmmLoadedImage
.FilePath
, &mFvDevicePath
, GetDevicePathSize((EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
));
1381 mSmmCoreDriverEntry
->SmmLoadedImage
.DeviceHandle
= FvHandle
;
1384 SmmAddToDriverList (Fv
, FvHandle
, &NameGuid
);
1387 } while (!EFI_ERROR (GetNextFileStatus
));
1391 // Read the array of GUIDs from the Apriori file if it is present in the firmware volume
1392 // (Note: AprioriFile is in DXE memory)
1395 Status
= Fv
->ReadSection (
1400 (VOID
**)&AprioriFile
,
1402 &AuthenticationStatus
1404 if (!EFI_ERROR (Status
)) {
1405 AprioriEntryCount
= SizeOfBuffer
/ sizeof (EFI_GUID
);
1407 AprioriEntryCount
= 0;
1411 // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes
1412 // drivers not in the current FV and these must be skipped since the a priori list
1413 // is only valid for the FV that it resided in.
1416 for (AprioriIndex
= 0; AprioriIndex
< AprioriEntryCount
; AprioriIndex
++) {
1417 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1418 DriverEntry
= CR(Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
1419 if (CompareGuid (&DriverEntry
->FileName
, &AprioriFile
[AprioriIndex
]) &&
1420 (FvHandle
== DriverEntry
->FvHandle
)) {
1421 DriverEntry
->Dependent
= FALSE
;
1422 DriverEntry
->Scheduled
= TRUE
;
1423 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
1424 DEBUG ((DEBUG_DISPATCH
, "Evaluate SMM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
1425 DEBUG ((DEBUG_DISPATCH
, " RESULT = TRUE (Apriori)\n"));
1432 // Free data allocated by Fv->ReadSection ()
1434 // The UEFI Boot Services FreePool() function must be used because Fv->ReadSection
1435 // used the UEFI Boot Services AllocatePool() function
1437 gBS
->FreePool (AprioriFile
);
1441 // Execute the SMM Dispatcher on any newly discovered FVs and previously
1442 // discovered SMM drivers that have been discovered but not dispatched.
1444 Status
= SmmDispatcher ();
1447 // Check to see if CommBuffer and CommBufferSize are valid
1449 if (CommBuffer
!= NULL
&& CommBufferSize
!= NULL
) {
1450 if (*CommBufferSize
> 0) {
1451 if (Status
== EFI_NOT_READY
) {
1453 // If a the SMM Core Entry Point was just registered, then set flag to
1454 // request the SMM Dispatcher to be restarted.
1456 *(UINT8
*)CommBuffer
= COMM_BUFFER_SMM_DISPATCH_RESTART
;
1457 } else if (!EFI_ERROR (Status
)) {
1459 // Set the flag to show that the SMM Dispatcher executed without errors
1461 *(UINT8
*)CommBuffer
= COMM_BUFFER_SMM_DISPATCH_SUCCESS
;
1464 // Set the flag to show that the SMM Dispatcher encountered an error
1466 *(UINT8
*)CommBuffer
= COMM_BUFFER_SMM_DISPATCH_ERROR
;
1475 Traverse the discovered list for any drivers that were discovered but not loaded
1476 because the dependency experessions evaluated to false.
1480 SmmDisplayDiscoveredNotDispatched (
1485 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
1487 for (Link
= mDiscoveredList
.ForwardLink
;Link
!=&mDiscoveredList
; Link
= Link
->ForwardLink
) {
1488 DriverEntry
= CR(Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
1489 if (DriverEntry
->Dependent
) {
1490 DEBUG ((DEBUG_LOAD
, "SMM Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));