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 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 corresponding
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 available, the function will mark the corresponding 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 address 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
= EFI_SIZE_TO_PAGES((UINT32
)(ImageBase
- SmmCodeBase
));
187 TopOffsetPageNumber
= 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 loading 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 loading 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 FixLoadingAddress
;
227 UINT16 NumberOfSections
;
228 UINT64 ValueInSectionHeader
;
230 FixLoadingAddress
= 0;
231 Status
= EFI_NOT_FOUND
;
234 // Get PeHeader pointer
236 ImgHdr
= (EFI_IMAGE_OPTIONAL_HEADER_UNION
*)((CHAR8
* )ImageContext
->Handle
+ ImageContext
->PeCoffHeaderOffset
);
237 SectionHeaderOffset
= ImageContext
->PeCoffHeaderOffset
+
239 sizeof (EFI_IMAGE_FILE_HEADER
) +
240 ImgHdr
->Pe32
.FileHeader
.SizeOfOptionalHeader
;
241 NumberOfSections
= ImgHdr
->Pe32
.FileHeader
.NumberOfSections
;
244 // Get base address from the first section header that doesn't point to code section.
246 for (Index
= 0; Index
< NumberOfSections
; Index
++) {
248 // Read section header from file
250 Size
= sizeof (EFI_IMAGE_SECTION_HEADER
);
251 Status
= ImageContext
->ImageRead (
252 ImageContext
->Handle
,
257 if (EFI_ERROR (Status
)) {
261 Status
= EFI_NOT_FOUND
;
263 if ((SectionHeader
.Characteristics
& EFI_IMAGE_SCN_CNT_CODE
) == 0) {
265 // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields in the first section header
266 // that doesn't point to code section in image header.So there is an assumption that when the feature is enabled,
267 // if a module with a loading address assigned by tools, the PointerToRelocations & PointerToLineNumbers fields
268 // should not be Zero, or else, these 2 fields should be set to Zero
270 ValueInSectionHeader
= ReadUnaligned64((UINT64
*)&SectionHeader
.PointerToRelocations
);
271 if (ValueInSectionHeader
!= 0) {
273 // Found first section header that doesn't point to code section in which build tool saves the
274 // offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
276 FixLoadingAddress
= (EFI_PHYSICAL_ADDRESS
)(gLoadModuleAtFixAddressSmramBase
+ (INT64
)ValueInSectionHeader
);
278 // Check if the memory range is available.
280 Status
= CheckAndMarkFixLoadingMemoryUsageBitMap (FixLoadingAddress
, (UINTN
)(ImageContext
->ImageSize
+ ImageContext
->SectionAlignment
));
281 if (!EFI_ERROR(Status
)) {
283 // The assigned address is valid. Return the specified loading address
285 ImageContext
->ImageAddress
= FixLoadingAddress
;
290 SectionHeaderOffset
+= sizeof (EFI_IMAGE_SECTION_HEADER
);
292 DEBUG ((EFI_D_INFO
|EFI_D_LOAD
, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r\n", FixLoadingAddress
, Status
));
296 Loads an EFI image into SMRAM.
298 @param DriverEntry EFI_SMM_DRIVER_ENTRY instance
306 IN OUT EFI_SMM_DRIVER_ENTRY
*DriverEntry
309 UINT32 AuthenticationStatus
;
316 EFI_STATUS SecurityStatus
;
317 EFI_HANDLE DeviceHandle
;
318 EFI_PHYSICAL_ADDRESS DstBuffer
;
319 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
320 EFI_DEVICE_PATH_PROTOCOL
*OriginalFilePath
;
321 EFI_DEVICE_PATH_PROTOCOL
*HandleFilePath
;
322 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
323 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
325 PERF_LOAD_IMAGE_BEGIN (DriverEntry
->ImageHandle
);
329 Fv
= DriverEntry
->Fv
;
330 NameGuid
= &DriverEntry
->FileName
;
331 FilePath
= DriverEntry
->FvFileDevicePath
;
333 OriginalFilePath
= FilePath
;
334 HandleFilePath
= FilePath
;
336 SecurityStatus
= EFI_SUCCESS
;
337 Status
= EFI_SUCCESS
;
338 AuthenticationStatus
= 0;
341 // Try to get the image device handle by checking the match protocol.
343 Status
= gBS
->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid
, &HandleFilePath
, &DeviceHandle
);
344 if (EFI_ERROR(Status
)) {
349 // If the Security2 and Security Architectural Protocol has not been located yet, then attempt to locate it
351 if (mSecurity2
== NULL
) {
352 gBS
->LocateProtocol (&gEfiSecurity2ArchProtocolGuid
, NULL
, (VOID
**)&mSecurity2
);
354 if (mSecurity
== NULL
) {
355 gBS
->LocateProtocol (&gEfiSecurityArchProtocolGuid
, NULL
, (VOID
**)&mSecurity
);
358 // When Security2 is installed, Security Architectural Protocol must be published.
360 ASSERT (mSecurity2
== NULL
|| mSecurity
!= NULL
);
363 // Pull out just the file portion of the DevicePath for the LoadedImage FilePath
365 FilePath
= OriginalFilePath
;
366 Status
= gBS
->HandleProtocol (DeviceHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&HandleFilePath
);
367 if (!EFI_ERROR (Status
)) {
368 FilePathSize
= GetDevicePathSize (HandleFilePath
) - sizeof(EFI_DEVICE_PATH_PROTOCOL
);
369 FilePath
= (EFI_DEVICE_PATH_PROTOCOL
*) (((UINT8
*)FilePath
) + FilePathSize
);
373 // Try reading PE32 section firstly
375 Status
= Fv
->ReadSection (
382 &AuthenticationStatus
385 if (EFI_ERROR (Status
)) {
387 // Try reading TE section secondly
391 Status
= Fv
->ReadSection (
398 &AuthenticationStatus
402 if (EFI_ERROR (Status
)) {
403 if (Buffer
!= NULL
) {
404 gBS
->FreePool (Buffer
);
410 // Verify File Authentication through the Security2 Architectural Protocol
412 if (mSecurity2
!= NULL
) {
413 SecurityStatus
= mSecurity2
->FileAuthentication (
423 // Verify the Authentication Status through the Security Architectural Protocol
424 // Only on images that have been read using Firmware Volume protocol.
425 // All SMM images are from FV protocol.
427 if (!EFI_ERROR (SecurityStatus
) && (mSecurity
!= NULL
)) {
428 SecurityStatus
= mSecurity
->FileAuthenticationState (
430 AuthenticationStatus
,
435 if (EFI_ERROR (SecurityStatus
) && SecurityStatus
!= EFI_SECURITY_VIOLATION
) {
436 Status
= SecurityStatus
;
441 // Initialize ImageContext
443 ImageContext
.Handle
= Buffer
;
444 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
447 // Get information about the image being loaded
449 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
450 if (EFI_ERROR (Status
)) {
451 if (Buffer
!= NULL
) {
452 gBS
->FreePool (Buffer
);
457 // if Loading module at Fixed Address feature is enabled, then cut out a memory range started from TESG BASE
458 // to hold the Smm driver code
460 if (PcdGet64(PcdLoadModuleAtFixAddressEnable
) != 0) {
462 // Get the fixed loading address assigned by Build tool
464 Status
= GetPeCoffImageFixLoadingAssignedAddress (&ImageContext
);
465 if (!EFI_ERROR (Status
)) {
467 // Since the memory range to load Smm core alreay been cut out, so no need to allocate and free this range
468 // following statements is to bypass SmmFreePages
471 DstBuffer
= (UINTN
)gLoadModuleAtFixAddressSmramBase
;
473 DEBUG ((EFI_D_INFO
|EFI_D_LOAD
, "LOADING MODULE FIXED ERROR: Failed to load module at fixed address. \n"));
475 // allocate the memory to load the SMM driver
477 PageCount
= (UINTN
)EFI_SIZE_TO_PAGES((UINTN
)ImageContext
.ImageSize
+ ImageContext
.SectionAlignment
);
478 DstBuffer
= (UINTN
)(-1);
480 Status
= SmmAllocatePages (
482 EfiRuntimeServicesCode
,
486 if (EFI_ERROR (Status
)) {
487 if (Buffer
!= NULL
) {
488 gBS
->FreePool (Buffer
);
492 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)DstBuffer
;
495 PageCount
= (UINTN
)EFI_SIZE_TO_PAGES((UINTN
)ImageContext
.ImageSize
+ ImageContext
.SectionAlignment
);
496 DstBuffer
= (UINTN
)(-1);
498 Status
= SmmAllocatePages (
500 EfiRuntimeServicesCode
,
504 if (EFI_ERROR (Status
)) {
505 if (Buffer
!= NULL
) {
506 gBS
->FreePool (Buffer
);
511 ImageContext
.ImageAddress
= (EFI_PHYSICAL_ADDRESS
)DstBuffer
;
514 // Align buffer on section boundary
516 ImageContext
.ImageAddress
+= ImageContext
.SectionAlignment
- 1;
517 ImageContext
.ImageAddress
&= ~((EFI_PHYSICAL_ADDRESS
)ImageContext
.SectionAlignment
- 1);
520 // Load the image to our new buffer
522 Status
= PeCoffLoaderLoadImage (&ImageContext
);
523 if (EFI_ERROR (Status
)) {
524 if (Buffer
!= NULL
) {
525 gBS
->FreePool (Buffer
);
527 SmmFreePages (DstBuffer
, PageCount
);
532 // Relocate the image in our new buffer
534 Status
= PeCoffLoaderRelocateImage (&ImageContext
);
535 if (EFI_ERROR (Status
)) {
536 if (Buffer
!= NULL
) {
537 gBS
->FreePool (Buffer
);
539 SmmFreePages (DstBuffer
, PageCount
);
544 // Flush the instruction cache so the image data are written before we execute it
546 InvalidateInstructionCacheRange ((VOID
*)(UINTN
) ImageContext
.ImageAddress
, (UINTN
) ImageContext
.ImageSize
);
549 // Save Image EntryPoint in DriverEntry
551 DriverEntry
->ImageEntryPoint
= ImageContext
.EntryPoint
;
552 DriverEntry
->ImageBuffer
= DstBuffer
;
553 DriverEntry
->NumberOfPage
= PageCount
;
556 // Allocate a Loaded Image Protocol in EfiBootServicesData
558 Status
= gBS
->AllocatePool (EfiBootServicesData
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
), (VOID
**)&DriverEntry
->LoadedImage
);
559 if (EFI_ERROR (Status
)) {
560 if (Buffer
!= NULL
) {
561 gBS
->FreePool (Buffer
);
563 SmmFreePages (DstBuffer
, PageCount
);
567 ZeroMem (DriverEntry
->LoadedImage
, sizeof (EFI_LOADED_IMAGE_PROTOCOL
));
569 // Fill in the remaining fields of the Loaded Image Protocol instance.
570 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
572 DriverEntry
->LoadedImage
->Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
573 DriverEntry
->LoadedImage
->ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
574 DriverEntry
->LoadedImage
->SystemTable
= gST
;
575 DriverEntry
->LoadedImage
->DeviceHandle
= DeviceHandle
;
577 DriverEntry
->SmmLoadedImage
.Revision
= EFI_LOADED_IMAGE_PROTOCOL_REVISION
;
578 DriverEntry
->SmmLoadedImage
.ParentHandle
= gSmmCorePrivate
->SmmIplImageHandle
;
579 DriverEntry
->SmmLoadedImage
.SystemTable
= gST
;
580 DriverEntry
->SmmLoadedImage
.DeviceHandle
= DeviceHandle
;
583 // Make an EfiBootServicesData buffer copy of FilePath
585 Status
= gBS
->AllocatePool (EfiBootServicesData
, GetDevicePathSize (FilePath
), (VOID
**)&DriverEntry
->LoadedImage
->FilePath
);
586 if (EFI_ERROR (Status
)) {
587 if (Buffer
!= NULL
) {
588 gBS
->FreePool (Buffer
);
590 SmmFreePages (DstBuffer
, PageCount
);
593 CopyMem (DriverEntry
->LoadedImage
->FilePath
, FilePath
, GetDevicePathSize (FilePath
));
595 DriverEntry
->LoadedImage
->ImageBase
= (VOID
*)(UINTN
) ImageContext
.ImageAddress
;
596 DriverEntry
->LoadedImage
->ImageSize
= ImageContext
.ImageSize
;
597 DriverEntry
->LoadedImage
->ImageCodeType
= EfiRuntimeServicesCode
;
598 DriverEntry
->LoadedImage
->ImageDataType
= EfiRuntimeServicesData
;
601 // Make a buffer copy of FilePath
603 Status
= SmmAllocatePool (EfiRuntimeServicesData
, GetDevicePathSize(FilePath
), (VOID
**)&DriverEntry
->SmmLoadedImage
.FilePath
);
604 if (EFI_ERROR (Status
)) {
605 if (Buffer
!= NULL
) {
606 gBS
->FreePool (Buffer
);
608 gBS
->FreePool (DriverEntry
->LoadedImage
->FilePath
);
609 SmmFreePages (DstBuffer
, PageCount
);
612 CopyMem (DriverEntry
->SmmLoadedImage
.FilePath
, FilePath
, GetDevicePathSize(FilePath
));
614 DriverEntry
->SmmLoadedImage
.ImageBase
= (VOID
*)(UINTN
) ImageContext
.ImageAddress
;
615 DriverEntry
->SmmLoadedImage
.ImageSize
= ImageContext
.ImageSize
;
616 DriverEntry
->SmmLoadedImage
.ImageCodeType
= EfiRuntimeServicesCode
;
617 DriverEntry
->SmmLoadedImage
.ImageDataType
= EfiRuntimeServicesData
;
620 // Create a new image handle in the UEFI handle database for the SMM Driver
622 DriverEntry
->ImageHandle
= NULL
;
623 Status
= gBS
->InstallMultipleProtocolInterfaces (
624 &DriverEntry
->ImageHandle
,
625 &gEfiLoadedImageProtocolGuid
, DriverEntry
->LoadedImage
,
630 // Create a new image handle in the SMM handle database for the SMM Driver
632 DriverEntry
->SmmImageHandle
= NULL
;
633 Status
= SmmInstallProtocolInterface (
634 &DriverEntry
->SmmImageHandle
,
635 &gEfiLoadedImageProtocolGuid
,
636 EFI_NATIVE_INTERFACE
,
637 &DriverEntry
->SmmLoadedImage
640 PERF_LOAD_IMAGE_END (DriverEntry
->ImageHandle
);
643 // Print the load address and the PDB file name if it is available
650 CHAR8 EfiFileName
[256];
653 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
,
654 "Loading SMM driver at 0x%11p EntryPoint=0x%11p ",
655 (VOID
*)(UINTN
) ImageContext
.ImageAddress
,
656 FUNCTION_ENTRY_POINT (ImageContext
.EntryPoint
)));
660 // Print Module Name by Pdb file path.
661 // Windows and Unix style file path are all trimmed correctly.
663 if (ImageContext
.PdbPointer
!= NULL
) {
665 for (Index
= 0; ImageContext
.PdbPointer
[Index
] != 0; Index
++) {
666 if ((ImageContext
.PdbPointer
[Index
] == '\\') || (ImageContext
.PdbPointer
[Index
] == '/')) {
667 StartIndex
= Index
+ 1;
671 // Copy the PDB file name to our temporary string, and replace .pdb with .efi
672 // The PDB file name is limited in the range of 0~255.
673 // If the length is bigger than 255, trim the redudant characters to avoid overflow in array boundary.
675 for (Index
= 0; Index
< sizeof (EfiFileName
) - 4; Index
++) {
676 EfiFileName
[Index
] = ImageContext
.PdbPointer
[Index
+ StartIndex
];
677 if (EfiFileName
[Index
] == 0) {
678 EfiFileName
[Index
] = '.';
680 if (EfiFileName
[Index
] == '.') {
681 EfiFileName
[Index
+ 1] = 'e';
682 EfiFileName
[Index
+ 2] = 'f';
683 EfiFileName
[Index
+ 3] = 'i';
684 EfiFileName
[Index
+ 4] = 0;
689 if (Index
== sizeof (EfiFileName
) - 4) {
690 EfiFileName
[Index
] = 0;
692 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "%a", EfiFileName
)); // &Image->ImageContext.PdbPointer[StartIndex]));
694 DEBUG ((DEBUG_INFO
| DEBUG_LOAD
, "\n"));
699 // Free buffer allocated by Fv->ReadSection.
701 // The UEFI Boot Services FreePool() function must be used because Fv->ReadSection
702 // used the UEFI Boot Services AllocatePool() function
704 Status
= gBS
->FreePool(Buffer
);
705 if (!EFI_ERROR (Status
) && EFI_ERROR (SecurityStatus
)) {
706 Status
= SecurityStatus
;
712 Preprocess dependency expression and update DriverEntry to reflect the
713 state of Before and After dependencies. If DriverEntry->Before
714 or DriverEntry->After is set it will never be cleared.
716 @param DriverEntry DriverEntry element to update .
718 @retval EFI_SUCCESS It always works.
723 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
728 Iterator
= DriverEntry
->Depex
;
729 DriverEntry
->Dependent
= TRUE
;
731 if (*Iterator
== EFI_DEP_BEFORE
) {
732 DriverEntry
->Before
= TRUE
;
733 } else if (*Iterator
== EFI_DEP_AFTER
) {
734 DriverEntry
->After
= TRUE
;
737 if (DriverEntry
->Before
|| DriverEntry
->After
) {
738 CopyMem (&DriverEntry
->BeforeAfterGuid
, Iterator
+ 1, sizeof (EFI_GUID
));
745 Read Depex and pre-process the Depex for Before and After. If Section Extraction
746 protocol returns an error via ReadSection defer the reading of the Depex.
748 @param DriverEntry Driver to work on.
750 @retval EFI_SUCCESS Depex read and preprossesed
751 @retval EFI_PROTOCOL_ERROR The section extraction protocol returned an error
752 and Depex reading needs to be retried.
753 @retval Error DEPEX not found.
757 SmmGetDepexSectionAndPreProccess (
758 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
762 EFI_SECTION_TYPE SectionType
;
763 UINT32 AuthenticationStatus
;
764 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
766 Fv
= DriverEntry
->Fv
;
769 // Grab Depex info, it will never be free'ed.
770 // (Note: DriverEntry->Depex is in DXE memory)
772 SectionType
= EFI_SECTION_SMM_DEPEX
;
773 Status
= Fv
->ReadSection (
775 &DriverEntry
->FileName
,
779 (UINTN
*)&DriverEntry
->DepexSize
,
780 &AuthenticationStatus
782 if (EFI_ERROR (Status
)) {
783 if (Status
== EFI_PROTOCOL_ERROR
) {
785 // The section extraction protocol failed so set protocol error flag
787 DriverEntry
->DepexProtocolError
= TRUE
;
790 // If no Depex assume depend on all architectural protocols
792 DriverEntry
->Depex
= NULL
;
793 DriverEntry
->Dependent
= TRUE
;
794 DriverEntry
->DepexProtocolError
= FALSE
;
798 // Set Before and After state information based on Depex
799 // Driver will be put in Dependent state
801 SmmPreProcessDepex (DriverEntry
);
802 DriverEntry
->DepexProtocolError
= FALSE
;
809 This is the main Dispatcher for SMM and it exits when there are no more
810 drivers to run. Drain the mScheduledQueue and load and start a PE
811 image for each driver. Search the mDiscoveredList to see if any driver can
812 be placed on the mScheduledQueue. If no drivers are placed on the
813 mScheduledQueue exit the function.
815 @retval EFI_SUCCESS All of the SMM Drivers that could be dispatched
816 have been run and the SMM Entry Point has been
818 @retval EFI_NOT_READY The SMM Driver that registered the SMM Entry Point
820 @retval EFI_NOT_FOUND There are no SMM Drivers available to be dispatched.
821 @retval EFI_ALREADY_STARTED The SMM Dispatcher is already running
831 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
833 BOOLEAN PreviousSmmEntryPointRegistered
;
835 if (!gRequestDispatch
) {
836 return EFI_NOT_FOUND
;
839 if (gDispatcherRunning
) {
841 // If the dispatcher is running don't let it be restarted.
843 return EFI_ALREADY_STARTED
;
846 gDispatcherRunning
= TRUE
;
850 // Drain the Scheduled Queue
852 while (!IsListEmpty (&mScheduledQueue
)) {
854 mScheduledQueue
.ForwardLink
,
855 EFI_SMM_DRIVER_ENTRY
,
857 EFI_SMM_DRIVER_ENTRY_SIGNATURE
861 // Load the SMM Driver image into memory. If the Driver was transitioned from
862 // Untrused to Scheduled it would have already been loaded so we may need to
863 // skip the LoadImage
865 if (DriverEntry
->ImageHandle
== NULL
) {
866 Status
= SmmLoadImage (DriverEntry
);
869 // Update the driver state to reflect that it's been loaded
871 if (EFI_ERROR (Status
)) {
873 // The SMM Driver could not be loaded, and do not attempt to load or start it again.
874 // Take driver from Scheduled to Initialized.
876 DriverEntry
->Initialized
= TRUE
;
877 DriverEntry
->Scheduled
= FALSE
;
878 RemoveEntryList (&DriverEntry
->ScheduledLink
);
881 // If it's an error don't try the StartImage
887 DriverEntry
->Scheduled
= FALSE
;
888 DriverEntry
->Initialized
= TRUE
;
889 RemoveEntryList (&DriverEntry
->ScheduledLink
);
891 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
893 EFI_SOFTWARE_SMM_DRIVER
| EFI_SW_PC_INIT_BEGIN
,
894 &DriverEntry
->ImageHandle
,
895 sizeof (DriverEntry
->ImageHandle
)
899 // Cache state of SmmEntryPointRegistered before calling entry point
901 PreviousSmmEntryPointRegistered
= gSmmCorePrivate
->SmmEntryPointRegistered
;
904 // For each SMM driver, pass NULL as ImageHandle
906 RegisterSmramProfileImage (DriverEntry
, TRUE
);
907 PERF_START_IMAGE_BEGIN (DriverEntry
->ImageHandle
);
908 Status
= ((EFI_IMAGE_ENTRY_POINT
)(UINTN
)DriverEntry
->ImageEntryPoint
)(DriverEntry
->ImageHandle
, gST
);
909 PERF_START_IMAGE_END (DriverEntry
->ImageHandle
);
910 if (EFI_ERROR(Status
)){
911 UnregisterSmramProfileImage (DriverEntry
, TRUE
);
912 SmmFreePages(DriverEntry
->ImageBuffer
, DriverEntry
->NumberOfPage
);
914 // Uninstall LoadedImage
916 Status
= gBS
->UninstallProtocolInterface (
917 DriverEntry
->ImageHandle
,
918 &gEfiLoadedImageProtocolGuid
,
919 DriverEntry
->LoadedImage
921 if (!EFI_ERROR (Status
)) {
922 if (DriverEntry
->LoadedImage
->FilePath
!= NULL
) {
923 gBS
->FreePool (DriverEntry
->LoadedImage
->FilePath
);
925 gBS
->FreePool (DriverEntry
->LoadedImage
);
927 Status
= SmmUninstallProtocolInterface (
928 DriverEntry
->SmmImageHandle
,
929 &gEfiLoadedImageProtocolGuid
,
930 &DriverEntry
->SmmLoadedImage
932 if (!EFI_ERROR(Status
)) {
933 if (DriverEntry
->SmmLoadedImage
.FilePath
!= NULL
) {
934 SmmFreePool (DriverEntry
->SmmLoadedImage
.FilePath
);
939 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
941 EFI_SOFTWARE_SMM_DRIVER
| EFI_SW_PC_INIT_END
,
942 &DriverEntry
->ImageHandle
,
943 sizeof (DriverEntry
->ImageHandle
)
946 if (!PreviousSmmEntryPointRegistered
&& gSmmCorePrivate
->SmmEntryPointRegistered
) {
948 // Return immediately if the SMM Entry Point was registered by the SMM
949 // Driver that was just dispatched. The SMM IPL will reinvoke the SMM
950 // Core Dispatcher. This is required so SMM Mode may be enabled as soon
951 // as all the dependent SMM Drivers for SMM Mode have been dispatched.
952 // Once the SMM Entry Point has been registered, then SMM Mode will be
955 gRequestDispatch
= TRUE
;
956 gDispatcherRunning
= FALSE
;
957 return EFI_NOT_READY
;
962 // Search DriverList for items to place on Scheduled Queue
965 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
966 DriverEntry
= CR (Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
968 if (DriverEntry
->DepexProtocolError
){
970 // If Section Extraction Protocol did not let the Depex be read before retry the read
972 Status
= SmmGetDepexSectionAndPreProccess (DriverEntry
);
975 if (DriverEntry
->Dependent
) {
976 if (SmmIsSchedulable (DriverEntry
)) {
977 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
982 } while (ReadyToRun
);
985 // If there is no more SMM driver to dispatch, stop the dispatch request
987 gRequestDispatch
= FALSE
;
988 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
989 DriverEntry
= CR (Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
991 if (!DriverEntry
->Initialized
){
993 // We have SMM driver pending to dispatch
995 gRequestDispatch
= TRUE
;
1000 gDispatcherRunning
= FALSE
;
1006 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
1007 must add any driver with a before dependency on InsertedDriverEntry first.
1008 You do this by recursively calling this routine. After all the Befores are
1009 processed you can add InsertedDriverEntry to the mScheduledQueue.
1010 Then you can add any driver with an After dependency on InsertedDriverEntry
1011 by recursively calling this routine.
1013 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
1017 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
1018 IN EFI_SMM_DRIVER_ENTRY
*InsertedDriverEntry
1022 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
1025 // Process Before Dependency
1027 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1028 DriverEntry
= CR(Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
1029 if (DriverEntry
->Before
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
1030 DEBUG ((DEBUG_DISPATCH
, "Evaluate SMM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
1031 DEBUG ((DEBUG_DISPATCH
, " BEFORE FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
1032 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
1034 // Recursively process BEFORE
1036 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
1037 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
1039 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
1045 // Convert driver from Dependent to Scheduled state
1048 InsertedDriverEntry
->Dependent
= FALSE
;
1049 InsertedDriverEntry
->Scheduled
= TRUE
;
1050 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
1054 // Process After Dependency
1056 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1057 DriverEntry
= CR(Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
1058 if (DriverEntry
->After
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
1059 DEBUG ((DEBUG_DISPATCH
, "Evaluate SMM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
1060 DEBUG ((DEBUG_DISPATCH
, " AFTER FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
1061 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
1063 // Recursively process AFTER
1065 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
1066 SmmInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
1068 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
1075 Return TRUE if the Fv has been processed, FALSE if not.
1077 @param FvHandle The handle of a FV that's being tested
1079 @retval TRUE Fv protocol on FvHandle has been processed
1080 @retval FALSE Fv protocol on FvHandle has not yet been
1085 FvHasBeenProcessed (
1086 IN EFI_HANDLE FvHandle
1090 KNOWN_HANDLE
*KnownHandle
;
1092 for (Link
= mFvHandleList
.ForwardLink
; Link
!= &mFvHandleList
; Link
= Link
->ForwardLink
) {
1093 KnownHandle
= CR(Link
, KNOWN_HANDLE
, Link
, KNOWN_HANDLE_SIGNATURE
);
1094 if (KnownHandle
->Handle
== FvHandle
) {
1102 Remember that Fv protocol on FvHandle has had it's drivers placed on the
1103 mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are
1104 never removed/freed from the mFvHandleList.
1106 @param FvHandle The handle of a FV that has been processed
1110 FvIsBeingProcesssed (
1111 IN EFI_HANDLE FvHandle
1114 KNOWN_HANDLE
*KnownHandle
;
1116 KnownHandle
= AllocatePool (sizeof (KNOWN_HANDLE
));
1117 ASSERT (KnownHandle
!= NULL
);
1119 KnownHandle
->Signature
= KNOWN_HANDLE_SIGNATURE
;
1120 KnownHandle
->Handle
= FvHandle
;
1121 InsertTailList (&mFvHandleList
, &KnownHandle
->Link
);
1125 Convert FvHandle and DriverName into an EFI device path
1127 @param Fv Fv protocol, needed to read Depex info out of
1129 @param FvHandle Handle for Fv, needed in the
1130 EFI_SMM_DRIVER_ENTRY so that the PE image can be
1131 read out of the FV at a later time.
1132 @param DriverName Name of driver to add to mDiscoveredList.
1134 @return Pointer to device path constructed from FvHandle and DriverName
1137 EFI_DEVICE_PATH_PROTOCOL
*
1139 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
1140 IN EFI_HANDLE FvHandle
,
1141 IN EFI_GUID
*DriverName
1145 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
1146 EFI_DEVICE_PATH_PROTOCOL
*FileNameDevicePath
;
1149 // Remember the device path of the FV
1151 Status
= gBS
->HandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
1152 if (EFI_ERROR (Status
)) {
1153 FileNameDevicePath
= NULL
;
1156 // Build a device path to the file in the FV to pass into gBS->LoadImage
1158 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, DriverName
);
1159 SetDevicePathEndNode (&mFvDevicePath
.End
);
1162 // Note: FileNameDevicePath is in DXE memory
1164 FileNameDevicePath
= AppendDevicePath (
1166 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
1169 return FileNameDevicePath
;
1173 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
1174 and initilize any state variables. Read the Depex from the FV and store it
1175 in DriverEntry. Pre-process the Depex to set the Before and After state.
1176 The Discovered list is never free'ed and contains booleans that represent the
1177 other possible SMM driver states.
1179 @param Fv Fv protocol, needed to read Depex info out of
1181 @param FvHandle Handle for Fv, needed in the
1182 EFI_SMM_DRIVER_ENTRY so that the PE image can be
1183 read out of the FV at a later time.
1184 @param DriverName Name of driver to add to mDiscoveredList.
1186 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
1187 @retval EFI_ALREADY_STARTED The driver has already been started. Only one
1188 DriverName may be active in the system at any one
1193 SmmAddToDriverList (
1194 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
1195 IN EFI_HANDLE FvHandle
,
1196 IN EFI_GUID
*DriverName
1199 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
1202 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
1205 DriverEntry
= AllocateZeroPool (sizeof (EFI_SMM_DRIVER_ENTRY
));
1206 ASSERT (DriverEntry
!= NULL
);
1208 DriverEntry
->Signature
= EFI_SMM_DRIVER_ENTRY_SIGNATURE
;
1209 CopyGuid (&DriverEntry
->FileName
, DriverName
);
1210 DriverEntry
->FvHandle
= FvHandle
;
1211 DriverEntry
->Fv
= Fv
;
1212 DriverEntry
->FvFileDevicePath
= SmmFvToDevicePath (Fv
, FvHandle
, DriverName
);
1214 SmmGetDepexSectionAndPreProccess (DriverEntry
);
1216 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
1217 gRequestDispatch
= TRUE
;
1223 This function is the main entry point for an SMM handler dispatch
1224 or communicate-based callback.
1226 Event notification that is fired every time a FV dispatch protocol is added.
1227 More than one protocol may have been added when this event is fired, so you
1228 must loop on SmmLocateHandle () to see how many protocols were added and
1229 do the following to each FV:
1230 If the Fv has already been processed, skip it. If the Fv has not been
1231 processed then mark it as being processed, as we are about to process it.
1232 Read the Fv and add any driver in the Fv to the mDiscoveredList.The
1233 mDiscoveredList is never free'ed and contains variables that define
1234 the other states the SMM driver transitions to..
1235 While you are at it read the A Priori file into memory.
1236 Place drivers in the A Priori list onto the mScheduledQueue.
1238 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
1239 @param Context Points to an optional handler context which was specified when the handler was registered.
1240 @param CommBuffer A pointer to a collection of data in memory that will
1241 be conveyed from a non-SMM environment into an SMM environment.
1242 @param CommBufferSize The size of the CommBuffer.
1249 SmmDriverDispatchHandler (
1250 IN EFI_HANDLE DispatchHandle
,
1251 IN CONST VOID
*Context
, OPTIONAL
1252 IN OUT VOID
*CommBuffer
, OPTIONAL
1253 IN OUT UINTN
*CommBufferSize OPTIONAL
1258 EFI_HANDLE
*HandleBuffer
;
1259 EFI_STATUS GetNextFileStatus
;
1260 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
1261 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
1262 EFI_HANDLE FvHandle
;
1265 EFI_FV_FILETYPE Type
;
1266 EFI_FV_FILE_ATTRIBUTES Attributes
;
1268 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
1269 EFI_GUID
*AprioriFile
;
1270 UINTN AprioriEntryCount
;
1275 UINT32 AuthenticationStatus
;
1278 HandleBuffer
= NULL
;
1279 Status
= gBS
->LocateHandleBuffer (
1281 &gEfiFirmwareVolume2ProtocolGuid
,
1286 if (EFI_ERROR (Status
)) {
1287 return EFI_NOT_FOUND
;
1290 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
1291 FvHandle
= HandleBuffer
[HandleIndex
];
1293 if (FvHasBeenProcessed (FvHandle
)) {
1295 // This Fv has already been processed so lets skip it!
1301 // Since we are about to process this Fv mark it as processed.
1303 FvIsBeingProcesssed (FvHandle
);
1305 Status
= gBS
->HandleProtocol (FvHandle
, &gEfiFirmwareVolume2ProtocolGuid
, (VOID
**)&Fv
);
1306 if (EFI_ERROR (Status
)) {
1308 // FvHandle must have a Firmware Volume2 Protocol thus we should never get here.
1314 Status
= gBS
->HandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
1315 if (EFI_ERROR (Status
)) {
1317 // The Firmware volume doesn't have device path, can't be dispatched.
1323 // Discover Drivers in FV and add them to the Discovered Driver List.
1324 // Process EFI_FV_FILETYPE_SMM type and then EFI_FV_FILETYPE_COMBINED_SMM_DXE
1325 // EFI_FV_FILETYPE_SMM_CORE is processed to produce a Loaded Image protocol for the core
1327 for (SmmTypeIndex
= 0; SmmTypeIndex
< sizeof (mSmmFileTypes
)/sizeof (EFI_FV_FILETYPE
); SmmTypeIndex
++) {
1329 // Initialize the search key
1333 Type
= mSmmFileTypes
[SmmTypeIndex
];
1334 GetNextFileStatus
= Fv
->GetNextFile (
1342 if (!EFI_ERROR (GetNextFileStatus
)) {
1343 if (Type
== EFI_FV_FILETYPE_SMM_CORE
) {
1345 // If this is the SMM core fill in it's DevicePath & DeviceHandle
1347 if (mSmmCoreLoadedImage
->FilePath
== NULL
) {
1349 // Maybe one special FV contains only one SMM_CORE module, so its device path must
1350 // be initialized completely.
1352 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, &NameGuid
);
1353 SetDevicePathEndNode (&mFvDevicePath
.End
);
1356 // Make an EfiBootServicesData buffer copy of FilePath
1358 Status
= gBS
->AllocatePool (
1359 EfiBootServicesData
,
1360 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
),
1361 (VOID
**)&mSmmCoreLoadedImage
->FilePath
1363 ASSERT_EFI_ERROR (Status
);
1364 CopyMem (mSmmCoreLoadedImage
->FilePath
, &mFvDevicePath
, GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
));
1366 mSmmCoreLoadedImage
->DeviceHandle
= FvHandle
;
1368 if (mSmmCoreDriverEntry
->SmmLoadedImage
.FilePath
== NULL
) {
1370 // Maybe one special FV contains only one SMM_CORE module, so its device path must
1371 // be initialized completely.
1373 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, &NameGuid
);
1374 SetDevicePathEndNode (&mFvDevicePath
.End
);
1377 // Make a buffer copy FilePath
1379 Status
= SmmAllocatePool (
1380 EfiRuntimeServicesData
,
1381 GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
),
1382 (VOID
**)&mSmmCoreDriverEntry
->SmmLoadedImage
.FilePath
1384 ASSERT_EFI_ERROR (Status
);
1385 CopyMem (mSmmCoreDriverEntry
->SmmLoadedImage
.FilePath
, &mFvDevicePath
, GetDevicePathSize((EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
));
1387 mSmmCoreDriverEntry
->SmmLoadedImage
.DeviceHandle
= FvHandle
;
1390 SmmAddToDriverList (Fv
, FvHandle
, &NameGuid
);
1393 } while (!EFI_ERROR (GetNextFileStatus
));
1397 // Read the array of GUIDs from the Apriori file if it is present in the firmware volume
1398 // (Note: AprioriFile is in DXE memory)
1401 Status
= Fv
->ReadSection (
1406 (VOID
**)&AprioriFile
,
1408 &AuthenticationStatus
1410 if (!EFI_ERROR (Status
)) {
1411 AprioriEntryCount
= SizeOfBuffer
/ sizeof (EFI_GUID
);
1413 AprioriEntryCount
= 0;
1417 // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes
1418 // drivers not in the current FV and these must be skipped since the a priori list
1419 // is only valid for the FV that it resided in.
1422 for (AprioriIndex
= 0; AprioriIndex
< AprioriEntryCount
; AprioriIndex
++) {
1423 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1424 DriverEntry
= CR(Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
1425 if (CompareGuid (&DriverEntry
->FileName
, &AprioriFile
[AprioriIndex
]) &&
1426 (FvHandle
== DriverEntry
->FvHandle
)) {
1427 DriverEntry
->Dependent
= FALSE
;
1428 DriverEntry
->Scheduled
= TRUE
;
1429 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
1430 DEBUG ((DEBUG_DISPATCH
, "Evaluate SMM DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
1431 DEBUG ((DEBUG_DISPATCH
, " RESULT = TRUE (Apriori)\n"));
1438 // Free data allocated by Fv->ReadSection ()
1440 // The UEFI Boot Services FreePool() function must be used because Fv->ReadSection
1441 // used the UEFI Boot Services AllocatePool() function
1443 gBS
->FreePool (AprioriFile
);
1447 // Execute the SMM Dispatcher on any newly discovered FVs and previously
1448 // discovered SMM drivers that have been discovered but not dispatched.
1450 Status
= SmmDispatcher ();
1453 // Check to see if CommBuffer and CommBufferSize are valid
1455 if (CommBuffer
!= NULL
&& CommBufferSize
!= NULL
) {
1456 if (*CommBufferSize
> 0) {
1457 if (Status
== EFI_NOT_READY
) {
1459 // If a the SMM Core Entry Point was just registered, then set flag to
1460 // request the SMM Dispatcher to be restarted.
1462 *(UINT8
*)CommBuffer
= COMM_BUFFER_SMM_DISPATCH_RESTART
;
1463 } else if (!EFI_ERROR (Status
)) {
1465 // Set the flag to show that the SMM Dispatcher executed without errors
1467 *(UINT8
*)CommBuffer
= COMM_BUFFER_SMM_DISPATCH_SUCCESS
;
1470 // Set the flag to show that the SMM Dispatcher encountered an error
1472 *(UINT8
*)CommBuffer
= COMM_BUFFER_SMM_DISPATCH_ERROR
;
1481 Traverse the discovered list for any drivers that were discovered but not loaded
1482 because the dependency experessions evaluated to false.
1486 SmmDisplayDiscoveredNotDispatched (
1491 EFI_SMM_DRIVER_ENTRY
*DriverEntry
;
1493 for (Link
= mDiscoveredList
.ForwardLink
;Link
!=&mDiscoveredList
; Link
= Link
->ForwardLink
) {
1494 DriverEntry
= CR(Link
, EFI_SMM_DRIVER_ENTRY
, Link
, EFI_SMM_DRIVER_ENTRY_SIGNATURE
);
1495 if (DriverEntry
->Dependent
) {
1496 DEBUG ((DEBUG_LOAD
, "SMM Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));