X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FCore%2FPiSmmCore%2FPiSmmCore.c;h=9e4390e15a1cbe69d44d57b0221ed8faaa297ac4;hb=e06179889586c37101e2900e7f52be9f0da12cda;hp=496638a17ed1bca43b955199b6662c8901ad069d;hpb=3b657538dc4e83cc304b4036dc5d63969a0c10db;p=mirror_edk2.git diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c index 496638a17e..9e4390e15a 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c @@ -1,7 +1,7 @@ /** @file SMM Core Main Entry Point - Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -87,6 +87,10 @@ SMM_CORE_SMI_HANDLERS mSmmCoreSmiHandlers[] = { UINTN mFullSmramRangeCount; EFI_SMRAM_DESCRIPTOR *mFullSmramRanges; +EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry; + +EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage; + /** Place holder function until all the SMM System Table Service are available. @@ -254,7 +258,7 @@ SmmReadyToBootHandler ( or if gEfiEventReadyToBootGuid is signalled. This function unregisters the Software SMIs that are nor required after SMRAM is locked and installs the SMM Ready To Lock Protocol so SMM Drivers are informed that SMRAM is about - to be locked. It also verifies the the SMM CPU I/O 2 Protocol has been installed + to be locked. It also verifies the SMM CPU I/O 2 Protocol has been installed and NULLs gBS and gST because they can not longer be used after SMRAM is locked. @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister(). @@ -428,13 +432,19 @@ SmmEntryPoint ( EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader; BOOLEAN InLegacyBoot; BOOLEAN IsOverlapped; + VOID *CommunicationBuffer; + UINTN BufferSize; PERF_START (NULL, "SMM", NULL, 0) ; // - // Update SMST using the context + // Update SMST with contents of the SmmEntryContext structure // - CopyMem (&gSmmCoreSmst.SmmStartupThisAp, SmmEntryContext, sizeof (EFI_SMM_ENTRY_CONTEXT)); + gSmmCoreSmst.SmmStartupThisAp = SmmEntryContext->SmmStartupThisAp; + gSmmCoreSmst.CurrentlyExecutingCpu = SmmEntryContext->CurrentlyExecutingCpu; + gSmmCoreSmst.NumberOfCpus = SmmEntryContext->NumberOfCpus; + gSmmCoreSmst.CpuSaveStateSize = SmmEntryContext->CpuSaveStateSize; + gSmmCoreSmst.CpuSaveState = SmmEntryContext->CpuSaveState; // // Call platform hook before Smm Dispatch @@ -455,17 +465,19 @@ SmmEntryPoint ( // Check to see if this is a Synchronous SMI sent through the SMM Communication // Protocol or an Asynchronous SMI // - if (gSmmCorePrivate->CommunicationBuffer != NULL) { + CommunicationBuffer = gSmmCorePrivate->CommunicationBuffer; + BufferSize = gSmmCorePrivate->BufferSize; + if (CommunicationBuffer != NULL) { // // Synchronous SMI for SMM Core or request from Communicate protocol // IsOverlapped = InternalIsBufferOverlapped ( - (UINT8 *) gSmmCorePrivate->CommunicationBuffer, - gSmmCorePrivate->BufferSize, + (UINT8 *) CommunicationBuffer, + BufferSize, (UINT8 *) gSmmCorePrivate, sizeof (*gSmmCorePrivate) ); - if (!SmmIsBufferOutsideSmmValid ((UINTN)gSmmCorePrivate->CommunicationBuffer, gSmmCorePrivate->BufferSize) || IsOverlapped) { + if (!SmmIsBufferOutsideSmmValid ((UINTN)CommunicationBuffer, BufferSize) || IsOverlapped) { // // If CommunicationBuffer is not in valid address scope, // or there is overlap between gSmmCorePrivate and CommunicationBuffer, @@ -474,19 +486,19 @@ SmmEntryPoint ( gSmmCorePrivate->CommunicationBuffer = NULL; gSmmCorePrivate->ReturnStatus = EFI_INVALID_PARAMETER; } else { - CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)gSmmCorePrivate->CommunicationBuffer; - gSmmCorePrivate->BufferSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data); + CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommunicationBuffer; + BufferSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data); Status = SmiManage ( &CommunicateHeader->HeaderGuid, NULL, CommunicateHeader->Data, - &gSmmCorePrivate->BufferSize + &BufferSize ); // // Update CommunicationBuffer, BufferSize and ReturnStatus // Communicate service finished, reset the pointer to CommBuffer to NULL // - gSmmCorePrivate->BufferSize += OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data); + gSmmCorePrivate->BufferSize = BufferSize + OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data); gSmmCorePrivate->CommunicationBuffer = NULL; gSmmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND; } @@ -516,6 +528,87 @@ SmmEntryPoint ( PERF_END (NULL, "SMM", NULL, 0) ; } +/** + Install LoadedImage protocol for SMM Core. +**/ +VOID +SmmCoreInstallLoadedImage ( + VOID + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + + // + // Allocate a Loaded Image Protocol in EfiBootServicesData + // + Status = gBS->AllocatePool (EfiBootServicesData, sizeof(EFI_LOADED_IMAGE_PROTOCOL), (VOID **)&mSmmCoreLoadedImage); + ASSERT_EFI_ERROR (Status); + + ZeroMem (mSmmCoreLoadedImage, sizeof (EFI_LOADED_IMAGE_PROTOCOL)); + // + // Fill in the remaining fields of the Loaded Image Protocol instance. + // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed. + // + mSmmCoreLoadedImage->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION; + mSmmCoreLoadedImage->ParentHandle = gSmmCorePrivate->SmmIplImageHandle; + mSmmCoreLoadedImage->SystemTable = gST; + + mSmmCoreLoadedImage->ImageBase = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase; + mSmmCoreLoadedImage->ImageSize = gSmmCorePrivate->PiSmmCoreImageSize; + mSmmCoreLoadedImage->ImageCodeType = EfiRuntimeServicesCode; + mSmmCoreLoadedImage->ImageDataType = EfiRuntimeServicesData; + + // + // Create a new image handle in the UEFI handle database for the SMM Driver + // + Handle = NULL; + Status = gBS->InstallMultipleProtocolInterfaces ( + &Handle, + &gEfiLoadedImageProtocolGuid, mSmmCoreLoadedImage, + NULL + ); + ASSERT_EFI_ERROR (Status); + + // + // Allocate a Loaded Image Protocol in SMM + // + Status = SmmAllocatePool (EfiRuntimeServicesData, sizeof(EFI_SMM_DRIVER_ENTRY), (VOID **)&mSmmCoreDriverEntry); + ASSERT_EFI_ERROR(Status); + + ZeroMem (mSmmCoreDriverEntry, sizeof(EFI_SMM_DRIVER_ENTRY)); + // + // Fill in the remaining fields of the Loaded Image Protocol instance. + // + mSmmCoreDriverEntry->Signature = EFI_SMM_DRIVER_ENTRY_SIGNATURE; + mSmmCoreDriverEntry->SmmLoadedImage.Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION; + mSmmCoreDriverEntry->SmmLoadedImage.ParentHandle = gSmmCorePrivate->SmmIplImageHandle; + mSmmCoreDriverEntry->SmmLoadedImage.SystemTable = gST; + + mSmmCoreDriverEntry->SmmLoadedImage.ImageBase = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase; + mSmmCoreDriverEntry->SmmLoadedImage.ImageSize = gSmmCorePrivate->PiSmmCoreImageSize; + mSmmCoreDriverEntry->SmmLoadedImage.ImageCodeType = EfiRuntimeServicesCode; + mSmmCoreDriverEntry->SmmLoadedImage.ImageDataType = EfiRuntimeServicesData; + + mSmmCoreDriverEntry->ImageEntryPoint = gSmmCorePrivate->PiSmmCoreEntryPoint; + mSmmCoreDriverEntry->ImageBuffer = gSmmCorePrivate->PiSmmCoreImageBase; + mSmmCoreDriverEntry->NumberOfPage = EFI_SIZE_TO_PAGES((UINTN)gSmmCorePrivate->PiSmmCoreImageSize); + + // + // Create a new image handle in the SMM handle database for the SMM Driver + // + mSmmCoreDriverEntry->SmmImageHandle = NULL; + Status = SmmInstallProtocolInterface ( + &mSmmCoreDriverEntry->SmmImageHandle, + &gEfiLoadedImageProtocolGuid, + EFI_NATIVE_INTERFACE, + &mSmmCoreDriverEntry->SmmLoadedImage + ); + ASSERT_EFI_ERROR(Status); + + return ; +} + /** The Entry Point for SMM Core @@ -581,6 +674,13 @@ SmmMain ( } RegisterSmramProfileHandler (); + SmramProfileInstallProtocol (); + + SmmCoreInstallLoadedImage (); + + SmmCoreInitializeMemoryAttributesTable (); + + SmmCoreInitializeSmiHandlerProfile (); return EFI_SUCCESS; }