2010-02-26 00:41:19 +01:00
|
|
|
/** @file
|
|
|
|
SMM Core Main Entry Point
|
|
|
|
|
2017-12-08 11:06:25 +01:00
|
|
|
Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
|
2010-02-26 00:41:19 +01:00
|
|
|
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
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "PiSmmCore.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// Physical pointer to private structure shared between SMM IPL and the SMM Core
|
|
|
|
//
|
|
|
|
SMM_CORE_PRIVATE_DATA *gSmmCorePrivate;
|
|
|
|
|
|
|
|
//
|
|
|
|
// SMM Core global variable for SMM System Table. Only accessed as a physical structure in SMRAM.
|
|
|
|
//
|
|
|
|
EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst = {
|
|
|
|
{
|
|
|
|
SMM_SMST_SIGNATURE,
|
|
|
|
EFI_SMM_SYSTEM_TABLE2_REVISION,
|
|
|
|
sizeof (gSmmCoreSmst.Hdr)
|
|
|
|
},
|
|
|
|
NULL, // SmmFirmwareVendor
|
|
|
|
0, // SmmFirmwareRevision
|
|
|
|
SmmInstallConfigurationTable,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
(EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5, // SmmMemRead
|
|
|
|
(EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5 // SmmMemWrite
|
|
|
|
},
|
|
|
|
{
|
|
|
|
(EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5, // SmmIoRead
|
|
|
|
(EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5 // SmmIoWrite
|
|
|
|
}
|
|
|
|
},
|
|
|
|
SmmAllocatePool,
|
|
|
|
SmmFreePool,
|
|
|
|
SmmAllocatePages,
|
|
|
|
SmmFreePages,
|
|
|
|
NULL, // SmmStartupThisAp
|
|
|
|
0, // CurrentlyExecutingCpu
|
|
|
|
0, // NumberOfCpus
|
|
|
|
NULL, // CpuSaveStateSize
|
|
|
|
NULL, // CpuSaveState
|
|
|
|
0, // NumberOfTableEntries
|
|
|
|
NULL, // SmmConfigurationTable
|
|
|
|
SmmInstallProtocolInterface,
|
|
|
|
SmmUninstallProtocolInterface,
|
|
|
|
SmmHandleProtocol,
|
|
|
|
SmmRegisterProtocolNotify,
|
|
|
|
SmmLocateHandle,
|
|
|
|
SmmLocateProtocol,
|
|
|
|
SmiManage,
|
|
|
|
SmiHandlerRegister,
|
|
|
|
SmiHandlerUnRegister
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Flag to determine if the platform has performed a legacy boot.
|
|
|
|
// If this flag is TRUE, then the runtime code and runtime data associated with the
|
2015-06-18 11:26:41 +02:00
|
|
|
// SMM IPL are converted to free memory, so the SMM Core must guarantee that is
|
2010-02-26 00:41:19 +01:00
|
|
|
// does not touch of the code/data associated with the SMM IPL if this flag is TRUE.
|
|
|
|
//
|
|
|
|
BOOLEAN mInLegacyBoot = FALSE;
|
|
|
|
|
2017-12-08 11:44:40 +01:00
|
|
|
//
|
|
|
|
// Flag to determine if it is during S3 resume.
|
|
|
|
// It will be set in S3 entry callback and cleared at EndOfS3Resume.
|
|
|
|
//
|
|
|
|
BOOLEAN mDuringS3Resume = FALSE;
|
|
|
|
|
2010-02-26 00:41:19 +01:00
|
|
|
//
|
|
|
|
// Table of SMI Handlers that are registered by the SMM Core when it is initialized
|
|
|
|
//
|
|
|
|
SMM_CORE_SMI_HANDLERS mSmmCoreSmiHandlers[] = {
|
2017-10-11 03:29:52 +02:00
|
|
|
{ SmmDriverDispatchHandler, &gEfiEventDxeDispatchGuid, NULL, TRUE },
|
|
|
|
{ SmmReadyToLockHandler, &gEfiDxeSmmReadyToLockProtocolGuid, NULL, TRUE },
|
|
|
|
{ SmmLegacyBootHandler, &gEfiEventLegacyBootGuid, NULL, FALSE },
|
|
|
|
{ SmmExitBootServicesHandler, &gEfiEventExitBootServicesGuid, NULL, FALSE },
|
|
|
|
{ SmmReadyToBootHandler, &gEfiEventReadyToBootGuid, NULL, FALSE },
|
|
|
|
{ SmmEndOfDxeHandler, &gEfiEndOfDxeEventGroupGuid, NULL, TRUE },
|
2017-12-08 11:06:25 +01:00
|
|
|
{ SmmS3SmmInitDoneHandler, &gEdkiiS3SmmInitDoneGuid, NULL, FALSE },
|
2017-12-08 10:36:09 +01:00
|
|
|
{ SmmEndOfS3ResumeHandler, &gEdkiiEndOfS3ResumeGuid, NULL, FALSE },
|
2017-10-11 03:29:52 +02:00
|
|
|
{ NULL, NULL, NULL, FALSE }
|
2010-02-26 00:41:19 +01:00
|
|
|
};
|
|
|
|
|
2014-11-12 04:27:48 +01:00
|
|
|
UINTN mFullSmramRangeCount;
|
|
|
|
EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;
|
|
|
|
|
2016-10-23 17:14:00 +02:00
|
|
|
EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;
|
|
|
|
|
2015-11-25 09:40:49 +01:00
|
|
|
EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;
|
|
|
|
|
2010-02-26 00:41:19 +01:00
|
|
|
/**
|
|
|
|
Place holder function until all the SMM System Table Service are available.
|
|
|
|
|
|
|
|
Note: This function is only used by SMRAM invocation. It is never used by DXE invocation.
|
|
|
|
|
|
|
|
@param Arg1 Undefined
|
|
|
|
@param Arg2 Undefined
|
|
|
|
@param Arg3 Undefined
|
|
|
|
@param Arg4 Undefined
|
|
|
|
@param Arg5 Undefined
|
|
|
|
|
|
|
|
@return EFI_NOT_AVAILABLE_YET
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SmmEfiNotAvailableYetArg5 (
|
|
|
|
UINTN Arg1,
|
|
|
|
UINTN Arg2,
|
|
|
|
UINTN Arg3,
|
|
|
|
UINTN Arg4,
|
|
|
|
UINTN Arg5
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// This function should never be executed. If it does, then the architectural protocols
|
|
|
|
// have not been designed correctly.
|
|
|
|
//
|
|
|
|
return EFI_NOT_AVAILABLE_YET;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Software SMI handler that is called when a Legacy Boot event is signalled. The SMM
|
|
|
|
Core uses this signal to know that a Legacy Boot has been performed and that
|
|
|
|
gSmmCorePrivate that is shared between the UEFI and SMM execution environments can
|
|
|
|
not be accessed from SMM anymore since that structure is considered free memory by
|
2015-06-18 11:26:41 +02:00
|
|
|
a legacy OS. Then the SMM Core also install SMM Legacy Boot protocol to notify SMM
|
|
|
|
driver that system enter legacy boot.
|
2010-02-26 00:41:19 +01:00
|
|
|
|
|
|
|
@param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
|
|
|
|
@param Context Points to an optional handler context which was specified when the handler was registered.
|
|
|
|
@param CommBuffer A pointer to a collection of data in memory that will
|
|
|
|
be conveyed from a non-SMM environment into an SMM environment.
|
|
|
|
@param CommBufferSize The size of the CommBuffer.
|
|
|
|
|
|
|
|
@return Status Code
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SmmLegacyBootHandler (
|
|
|
|
IN EFI_HANDLE DispatchHandle,
|
|
|
|
IN CONST VOID *Context, OPTIONAL
|
|
|
|
IN OUT VOID *CommBuffer, OPTIONAL
|
|
|
|
IN OUT UINTN *CommBufferSize OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
2015-06-18 11:26:41 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE SmmHandle;
|
2017-12-08 11:57:29 +01:00
|
|
|
UINTN Index;
|
2015-06-18 11:26:41 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Install SMM Legacy Boot protocol.
|
|
|
|
//
|
|
|
|
SmmHandle = NULL;
|
|
|
|
Status = SmmInstallProtocolInterface (
|
|
|
|
&SmmHandle,
|
|
|
|
&gEdkiiSmmLegacyBootProtocolGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
2010-02-26 00:41:19 +01:00
|
|
|
mInLegacyBoot = TRUE;
|
2015-06-18 11:26:41 +02:00
|
|
|
|
|
|
|
SmiHandlerUnRegister (DispatchHandle);
|
|
|
|
|
2017-12-08 11:57:29 +01:00
|
|
|
//
|
|
|
|
// It is legacy boot, unregister ExitBootService SMI handler.
|
|
|
|
//
|
|
|
|
for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) {
|
|
|
|
if (CompareGuid (mSmmCoreSmiHandlers[Index].HandlerType, &gEfiEventExitBootServicesGuid)) {
|
|
|
|
SmiHandlerUnRegister (mSmmCoreSmiHandlers[Index].DispatchHandle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-18 11:26:41 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Software SMI handler that is called when an Exit Boot Services event is signalled.
|
|
|
|
Then the SMM Core also install SMM Exit Boot Services protocol to notify SMM driver
|
|
|
|
that system enter exit boot services.
|
|
|
|
|
|
|
|
@param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
|
|
|
|
@param Context Points to an optional handler context which was specified when the handler was registered.
|
|
|
|
@param CommBuffer A pointer to a collection of data in memory that will
|
|
|
|
be conveyed from a non-SMM environment into an SMM environment.
|
|
|
|
@param CommBufferSize The size of the CommBuffer.
|
|
|
|
|
|
|
|
@return Status Code
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SmmExitBootServicesHandler (
|
|
|
|
IN EFI_HANDLE DispatchHandle,
|
|
|
|
IN CONST VOID *Context, OPTIONAL
|
|
|
|
IN OUT VOID *CommBuffer, OPTIONAL
|
|
|
|
IN OUT UINTN *CommBufferSize OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE SmmHandle;
|
2017-12-08 11:57:29 +01:00
|
|
|
UINTN Index;
|
2015-06-18 11:26:41 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Install SMM Exit Boot Services protocol.
|
|
|
|
//
|
|
|
|
SmmHandle = NULL;
|
|
|
|
Status = SmmInstallProtocolInterface (
|
|
|
|
&SmmHandle,
|
|
|
|
&gEdkiiSmmExitBootServicesProtocolGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
SmiHandlerUnRegister (DispatchHandle);
|
|
|
|
|
2017-12-08 11:57:29 +01:00
|
|
|
//
|
|
|
|
// It is UEFI boot, unregister LegacyBoot SMI handler.
|
|
|
|
//
|
|
|
|
for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) {
|
|
|
|
if (CompareGuid (mSmmCoreSmiHandlers[Index].HandlerType, &gEfiEventLegacyBootGuid)) {
|
|
|
|
SmiHandlerUnRegister (mSmmCoreSmiHandlers[Index].DispatchHandle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-18 11:26:41 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2017-12-08 11:44:40 +01:00
|
|
|
/**
|
|
|
|
Main entry point for an SMM handler dispatch or communicate-based callback.
|
|
|
|
|
|
|
|
@param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
|
|
|
|
@param[in] Context Points to an optional handler context which was specified when the
|
|
|
|
handler was registered.
|
|
|
|
@param[in,out] CommBuffer A pointer to a collection of data in memory that will
|
|
|
|
be conveyed from a non-SMM environment into an SMM environment.
|
|
|
|
@param[in,out] CommBufferSize The size of the CommBuffer.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
|
|
|
|
should still be called.
|
|
|
|
@retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should
|
|
|
|
still be called.
|
|
|
|
@retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still
|
|
|
|
be called.
|
|
|
|
@retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SmmS3EntryCallBack (
|
|
|
|
IN EFI_HANDLE DispatchHandle,
|
|
|
|
IN CONST VOID *Context OPTIONAL,
|
|
|
|
IN OUT VOID *CommBuffer OPTIONAL,
|
|
|
|
IN OUT UINTN *CommBufferSize OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
|
|
|
mDuringS3Resume = TRUE;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-06-18 11:26:41 +02:00
|
|
|
/**
|
|
|
|
Software SMI handler that is called when an Ready To Boot event is signalled.
|
|
|
|
Then the SMM Core also install SMM Ready To Boot protocol to notify SMM driver
|
|
|
|
that system enter ready to boot.
|
|
|
|
|
|
|
|
@param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
|
|
|
|
@param Context Points to an optional handler context which was specified when the handler was registered.
|
|
|
|
@param CommBuffer A pointer to a collection of data in memory that will
|
|
|
|
be conveyed from a non-SMM environment into an SMM environment.
|
|
|
|
@param CommBufferSize The size of the CommBuffer.
|
|
|
|
|
|
|
|
@return Status Code
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SmmReadyToBootHandler (
|
|
|
|
IN EFI_HANDLE DispatchHandle,
|
|
|
|
IN CONST VOID *Context, OPTIONAL
|
|
|
|
IN OUT VOID *CommBuffer, OPTIONAL
|
|
|
|
IN OUT UINTN *CommBufferSize OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
2017-12-08 11:44:40 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE SmmHandle;
|
2015-06-18 11:26:41 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Install SMM Ready To Boot protocol.
|
|
|
|
//
|
|
|
|
SmmHandle = NULL;
|
|
|
|
Status = SmmInstallProtocolInterface (
|
|
|
|
&SmmHandle,
|
|
|
|
&gEdkiiSmmReadyToBootProtocolGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
SmiHandlerUnRegister (DispatchHandle);
|
|
|
|
|
2017-12-14 09:20:32 +01:00
|
|
|
return Status;
|
2010-02-26 00:41:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Software SMI handler that is called when the DxeSmmReadyToLock protocol is added
|
|
|
|
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
|
2016-07-08 08:21:04 +02:00
|
|
|
to be locked. It also verifies the SMM CPU I/O 2 Protocol has been installed
|
2010-02-26 00:41:19 +01:00
|
|
|
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().
|
|
|
|
@param Context Points to an optional handler context which was specified when the handler was registered.
|
|
|
|
@param CommBuffer A pointer to a collection of data in memory that will
|
|
|
|
be conveyed from a non-SMM environment into an SMM environment.
|
|
|
|
@param CommBufferSize The size of the CommBuffer.
|
|
|
|
|
|
|
|
@return Status Code
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SmmReadyToLockHandler (
|
|
|
|
IN EFI_HANDLE DispatchHandle,
|
|
|
|
IN CONST VOID *Context, OPTIONAL
|
|
|
|
IN OUT VOID *CommBuffer, OPTIONAL
|
|
|
|
IN OUT UINTN *CommBufferSize OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN Index;
|
|
|
|
EFI_HANDLE SmmHandle;
|
|
|
|
VOID *Interface;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Unregister SMI Handlers that are no required after the SMM driver dispatch is stopped
|
|
|
|
//
|
|
|
|
for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) {
|
|
|
|
if (mSmmCoreSmiHandlers[Index].UnRegister) {
|
|
|
|
SmiHandlerUnRegister (mSmmCoreSmiHandlers[Index].DispatchHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Install SMM Ready to lock protocol
|
|
|
|
//
|
|
|
|
SmmHandle = NULL;
|
|
|
|
Status = SmmInstallProtocolInterface (
|
|
|
|
&SmmHandle,
|
|
|
|
&gEfiSmmReadyToLockProtocolGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Make sure SMM CPU I/O 2 Procol has been installed into the handle database
|
|
|
|
//
|
|
|
|
Status = SmmLocateProtocol (&gEfiSmmCpuIo2ProtocolGuid, NULL, &Interface);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Print a message on a debug build if the SMM CPU I/O 2 Protocol is not installed
|
|
|
|
//
|
|
|
|
DEBUG_CODE_BEGIN ();
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((DEBUG_ERROR, "\nSMM: SmmCpuIo Arch Protocol not present!!\n"));
|
|
|
|
}
|
|
|
|
DEBUG_CODE_END ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Assert if the CPU I/O 2 Protocol is not installed
|
|
|
|
//
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Display any drivers that were not dispatched because dependency expression
|
|
|
|
// evaluated to false if this is a debug build
|
|
|
|
//
|
|
|
|
DEBUG_CODE_BEGIN ();
|
|
|
|
SmmDisplayDiscoveredNotDispatched ();
|
|
|
|
DEBUG_CODE_END ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Not allowed to use gST or gBS after lock
|
|
|
|
//
|
|
|
|
gST = NULL;
|
|
|
|
gBS = NULL;
|
|
|
|
|
2014-11-12 04:27:48 +01:00
|
|
|
SmramProfileReadyToLock ();
|
|
|
|
|
2010-02-26 00:41:19 +01:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2012-12-18 06:07:35 +01:00
|
|
|
/**
|
|
|
|
Software SMI handler that is called when the EndOfDxe event is signalled.
|
|
|
|
This function installs the SMM EndOfDxe Protocol so SMM Drivers are informed that
|
|
|
|
platform code will invoke 3rd part code.
|
|
|
|
|
|
|
|
@param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
|
|
|
|
@param Context Points to an optional handler context which was specified when the handler was registered.
|
|
|
|
@param CommBuffer A pointer to a collection of data in memory that will
|
|
|
|
be conveyed from a non-SMM environment into an SMM environment.
|
|
|
|
@param CommBufferSize The size of the CommBuffer.
|
|
|
|
|
|
|
|
@return Status Code
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SmmEndOfDxeHandler (
|
|
|
|
IN EFI_HANDLE DispatchHandle,
|
|
|
|
IN CONST VOID *Context, OPTIONAL
|
|
|
|
IN OUT VOID *CommBuffer, OPTIONAL
|
|
|
|
IN OUT UINTN *CommBufferSize OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
2017-12-14 09:20:32 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE SmmHandle;
|
|
|
|
EFI_SMM_SX_DISPATCH2_PROTOCOL *SxDispatch;
|
|
|
|
EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext;
|
|
|
|
EFI_HANDLE S3EntryHandle;
|
2012-12-18 06:07:35 +01:00
|
|
|
|
|
|
|
DEBUG ((EFI_D_INFO, "SmmEndOfDxeHandler\n"));
|
2017-12-14 09:20:32 +01:00
|
|
|
|
2012-12-18 06:07:35 +01:00
|
|
|
//
|
|
|
|
// Install SMM EndOfDxe protocol
|
|
|
|
//
|
|
|
|
SmmHandle = NULL;
|
|
|
|
Status = SmmInstallProtocolInterface (
|
|
|
|
&SmmHandle,
|
|
|
|
&gEfiSmmEndOfDxeProtocolGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
NULL
|
|
|
|
);
|
2017-12-14 09:20:32 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Locate SmmSxDispatch2 protocol.
|
|
|
|
//
|
|
|
|
Status = SmmLocateProtocol (
|
|
|
|
&gEfiSmmSxDispatch2ProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
(VOID **)&SxDispatch
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (Status) && (SxDispatch != NULL)) {
|
|
|
|
//
|
|
|
|
// Register a S3 entry callback function to
|
|
|
|
// determine if it will be during S3 resume.
|
|
|
|
//
|
|
|
|
EntryRegisterContext.Type = SxS3;
|
|
|
|
EntryRegisterContext.Phase = SxEntry;
|
|
|
|
Status = SxDispatch->Register (
|
|
|
|
SxDispatch,
|
|
|
|
SmmS3EntryCallBack,
|
|
|
|
&EntryRegisterContext,
|
|
|
|
&S3EntryHandle
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
2012-12-18 06:07:35 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 11:06:25 +01:00
|
|
|
/**
|
|
|
|
Software SMI handler that is called when the S3SmmInitDone signal is triggered.
|
|
|
|
This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are informed that
|
|
|
|
S3 SMM initialization has been done.
|
|
|
|
|
|
|
|
@param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
|
|
|
|
@param Context Points to an optional handler context which was specified when the handler was registered.
|
|
|
|
@param CommBuffer A pointer to a collection of data in memory that will
|
|
|
|
be conveyed from a non-SMM environment into an SMM environment.
|
|
|
|
@param CommBufferSize The size of the CommBuffer.
|
|
|
|
|
|
|
|
@return Status Code
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SmmS3SmmInitDoneHandler (
|
|
|
|
IN EFI_HANDLE DispatchHandle,
|
|
|
|
IN CONST VOID *Context, OPTIONAL
|
|
|
|
IN OUT VOID *CommBuffer, OPTIONAL
|
|
|
|
IN OUT UINTN *CommBufferSize OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE SmmHandle;
|
|
|
|
|
|
|
|
DEBUG ((DEBUG_INFO, "SmmS3SmmInitDoneHandler\n"));
|
|
|
|
|
|
|
|
if (!mDuringS3Resume) {
|
|
|
|
DEBUG ((DEBUG_ERROR, "It is not during S3 resume\n"));
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Install SMM S3SmmInitDone protocol
|
|
|
|
//
|
|
|
|
SmmHandle = NULL;
|
|
|
|
Status = SmmInstallProtocolInterface (
|
|
|
|
&SmmHandle,
|
|
|
|
&gEdkiiS3SmmInitDoneGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Uninstall the protocol here because the comsumer just hook the
|
|
|
|
// installation event.
|
|
|
|
//
|
|
|
|
Status = SmmUninstallProtocolInterface (
|
|
|
|
SmmHandle,
|
|
|
|
&gEdkiiS3SmmInitDoneGuid,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2017-10-11 03:29:52 +02:00
|
|
|
/**
|
2017-12-08 10:36:09 +01:00
|
|
|
Software SMI handler that is called when the EndOfS3Resume signal is triggered.
|
2017-10-11 03:29:52 +02:00
|
|
|
This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that
|
|
|
|
S3 resume has finished.
|
|
|
|
|
|
|
|
@param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
|
|
|
|
@param Context Points to an optional handler context which was specified when the handler was registered.
|
|
|
|
@param CommBuffer A pointer to a collection of data in memory that will
|
|
|
|
be conveyed from a non-SMM environment into an SMM environment.
|
|
|
|
@param CommBufferSize The size of the CommBuffer.
|
|
|
|
|
|
|
|
@return Status Code
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SmmEndOfS3ResumeHandler (
|
|
|
|
IN EFI_HANDLE DispatchHandle,
|
|
|
|
IN CONST VOID *Context, OPTIONAL
|
|
|
|
IN OUT VOID *CommBuffer, OPTIONAL
|
|
|
|
IN OUT UINTN *CommBufferSize OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE SmmHandle;
|
|
|
|
|
2017-12-08 11:44:40 +01:00
|
|
|
DEBUG ((DEBUG_INFO, "SmmEndOfS3ResumeHandler\n"));
|
|
|
|
|
|
|
|
if (!mDuringS3Resume) {
|
|
|
|
DEBUG ((DEBUG_ERROR, "It is not during S3 resume\n"));
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2017-10-11 03:29:52 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Install SMM EndOfS3Resume protocol
|
|
|
|
//
|
|
|
|
SmmHandle = NULL;
|
|
|
|
Status = SmmInstallProtocolInterface (
|
|
|
|
&SmmHandle,
|
2017-12-08 10:36:09 +01:00
|
|
|
&gEdkiiEndOfS3ResumeGuid,
|
2017-10-11 03:29:52 +02:00
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
//
|
2017-12-08 10:36:09 +01:00
|
|
|
// Uninstall the protocol here because the comsumer just hook the
|
2017-10-11 03:29:52 +02:00
|
|
|
// installation event.
|
|
|
|
//
|
|
|
|
Status = SmmUninstallProtocolInterface (
|
|
|
|
SmmHandle,
|
2017-12-08 10:36:09 +01:00
|
|
|
&gEdkiiEndOfS3ResumeGuid,
|
2017-10-11 03:29:52 +02:00
|
|
|
NULL
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2017-12-08 11:44:40 +01:00
|
|
|
mDuringS3Resume = FALSE;
|
2017-10-11 03:29:52 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2015-08-26 03:10:39 +02:00
|
|
|
/**
|
|
|
|
Determine if two buffers overlap in memory.
|
|
|
|
|
|
|
|
@param[in] Buff1 Pointer to first buffer
|
|
|
|
@param[in] Size1 Size of Buff1
|
|
|
|
@param[in] Buff2 Pointer to second buffer
|
|
|
|
@param[in] Size2 Size of Buff2
|
|
|
|
|
|
|
|
@retval TRUE Buffers overlap in memory.
|
|
|
|
@retval FALSE Buffer doesn't overlap.
|
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
InternalIsBufferOverlapped (
|
|
|
|
IN UINT8 *Buff1,
|
|
|
|
IN UINTN Size1,
|
|
|
|
IN UINT8 *Buff2,
|
|
|
|
IN UINTN Size2
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// If buff1's end is less than the start of buff2, then it's ok.
|
|
|
|
// Also, if buff1's start is beyond buff2's end, then it's ok.
|
|
|
|
//
|
|
|
|
if (((Buff1 + Size1) <= Buff2) || (Buff1 >= (Buff2 + Size2))) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-02-26 00:41:19 +01:00
|
|
|
/**
|
|
|
|
The main entry point to SMM Foundation.
|
|
|
|
|
|
|
|
Note: This function is only used by SMRAM invocation. It is never used by DXE invocation.
|
|
|
|
|
|
|
|
@param SmmEntryContext Processor information and functionality
|
|
|
|
needed by SMM Foundation.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
SmmEntryPoint (
|
|
|
|
IN CONST EFI_SMM_ENTRY_CONTEXT *SmmEntryContext
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader;
|
2012-11-02 00:51:22 +01:00
|
|
|
BOOLEAN InLegacyBoot;
|
2015-08-26 03:10:39 +02:00
|
|
|
BOOLEAN IsOverlapped;
|
2016-11-18 03:46:43 +01:00
|
|
|
VOID *CommunicationBuffer;
|
|
|
|
UINTN BufferSize;
|
2010-02-26 00:41:19 +01:00
|
|
|
|
2011-08-16 04:58:20 +02:00
|
|
|
PERF_START (NULL, "SMM", NULL, 0) ;
|
|
|
|
|
2010-02-26 00:41:19 +01:00
|
|
|
//
|
2015-11-03 03:06:57 +01:00
|
|
|
// Update SMST with contents of the SmmEntryContext structure
|
2010-02-26 00:41:19 +01:00
|
|
|
//
|
2015-11-03 03:06:57 +01:00
|
|
|
gSmmCoreSmst.SmmStartupThisAp = SmmEntryContext->SmmStartupThisAp;
|
|
|
|
gSmmCoreSmst.CurrentlyExecutingCpu = SmmEntryContext->CurrentlyExecutingCpu;
|
|
|
|
gSmmCoreSmst.NumberOfCpus = SmmEntryContext->NumberOfCpus;
|
|
|
|
gSmmCoreSmst.CpuSaveStateSize = SmmEntryContext->CpuSaveStateSize;
|
|
|
|
gSmmCoreSmst.CpuSaveState = SmmEntryContext->CpuSaveState;
|
2010-02-26 00:41:19 +01:00
|
|
|
|
2011-08-16 04:58:20 +02:00
|
|
|
//
|
|
|
|
// Call platform hook before Smm Dispatch
|
|
|
|
//
|
|
|
|
PlatformHookBeforeSmmDispatch ();
|
|
|
|
|
2017-11-20 09:08:28 +01:00
|
|
|
//
|
|
|
|
// Call memory management hook function
|
|
|
|
//
|
|
|
|
SmmEntryPointMemoryManagementHook ();
|
|
|
|
|
2010-02-26 00:41:19 +01:00
|
|
|
//
|
|
|
|
// If a legacy boot has occured, then make sure gSmmCorePrivate is not accessed
|
|
|
|
//
|
2012-11-02 00:51:22 +01:00
|
|
|
InLegacyBoot = mInLegacyBoot;
|
|
|
|
if (!InLegacyBoot) {
|
2010-02-26 00:41:19 +01:00
|
|
|
//
|
2012-09-25 04:44:53 +02:00
|
|
|
// Mark the InSmm flag as TRUE, it will be used by SmmBase2 protocol
|
2010-02-26 00:41:19 +01:00
|
|
|
//
|
2012-09-25 04:44:53 +02:00
|
|
|
gSmmCorePrivate->InSmm = TRUE;
|
2010-02-26 00:41:19 +01:00
|
|
|
|
|
|
|
//
|
2012-09-25 04:44:53 +02:00
|
|
|
// Check to see if this is a Synchronous SMI sent through the SMM Communication
|
|
|
|
// Protocol or an Asynchronous SMI
|
2010-02-26 00:41:19 +01:00
|
|
|
//
|
2016-11-18 03:46:43 +01:00
|
|
|
CommunicationBuffer = gSmmCorePrivate->CommunicationBuffer;
|
|
|
|
BufferSize = gSmmCorePrivate->BufferSize;
|
|
|
|
if (CommunicationBuffer != NULL) {
|
2012-09-25 04:44:53 +02:00
|
|
|
//
|
|
|
|
// Synchronous SMI for SMM Core or request from Communicate protocol
|
|
|
|
//
|
2015-08-26 03:10:39 +02:00
|
|
|
IsOverlapped = InternalIsBufferOverlapped (
|
2016-11-18 03:46:43 +01:00
|
|
|
(UINT8 *) CommunicationBuffer,
|
|
|
|
BufferSize,
|
2015-08-26 03:10:39 +02:00
|
|
|
(UINT8 *) gSmmCorePrivate,
|
|
|
|
sizeof (*gSmmCorePrivate)
|
|
|
|
);
|
2016-11-18 03:46:43 +01:00
|
|
|
if (!SmmIsBufferOutsideSmmValid ((UINTN)CommunicationBuffer, BufferSize) || IsOverlapped) {
|
2014-12-09 03:20:16 +01:00
|
|
|
//
|
2015-08-26 03:10:39 +02:00
|
|
|
// If CommunicationBuffer is not in valid address scope,
|
|
|
|
// or there is overlap between gSmmCorePrivate and CommunicationBuffer,
|
|
|
|
// return EFI_INVALID_PARAMETER
|
2014-12-09 03:20:16 +01:00
|
|
|
//
|
|
|
|
gSmmCorePrivate->CommunicationBuffer = NULL;
|
2017-11-07 06:42:21 +01:00
|
|
|
gSmmCorePrivate->ReturnStatus = EFI_ACCESS_DENIED;
|
2014-12-09 03:20:16 +01:00
|
|
|
} else {
|
2016-11-18 03:46:43 +01:00
|
|
|
CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommunicationBuffer;
|
|
|
|
BufferSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
|
2014-12-09 03:20:16 +01:00
|
|
|
Status = SmiManage (
|
|
|
|
&CommunicateHeader->HeaderGuid,
|
|
|
|
NULL,
|
|
|
|
CommunicateHeader->Data,
|
2016-11-18 03:46:43 +01:00
|
|
|
&BufferSize
|
2014-12-09 03:20:16 +01:00
|
|
|
);
|
|
|
|
//
|
|
|
|
// Update CommunicationBuffer, BufferSize and ReturnStatus
|
|
|
|
// Communicate service finished, reset the pointer to CommBuffer to NULL
|
|
|
|
//
|
2016-11-18 03:46:43 +01:00
|
|
|
gSmmCorePrivate->BufferSize = BufferSize + OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
|
2014-12-09 03:20:16 +01:00
|
|
|
gSmmCorePrivate->CommunicationBuffer = NULL;
|
|
|
|
gSmmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
|
|
|
|
}
|
2012-09-25 04:44:53 +02:00
|
|
|
}
|
2010-02-26 00:41:19 +01:00
|
|
|
}
|
2012-09-25 04:44:53 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Process Asynchronous SMI sources
|
|
|
|
//
|
|
|
|
SmiManage (NULL, NULL, NULL, NULL);
|
2011-08-16 04:58:20 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Call platform hook after Smm Dispatch
|
|
|
|
//
|
|
|
|
PlatformHookAfterSmmDispatch ();
|
2010-02-26 00:41:19 +01:00
|
|
|
|
|
|
|
//
|
2012-09-25 04:44:53 +02:00
|
|
|
// If a legacy boot has occured, then make sure gSmmCorePrivate is not accessed
|
2010-02-26 00:41:19 +01:00
|
|
|
//
|
2012-11-02 00:51:22 +01:00
|
|
|
if (!InLegacyBoot) {
|
2012-09-25 04:44:53 +02:00
|
|
|
//
|
|
|
|
// Clear the InSmm flag as we are going to leave SMM
|
|
|
|
//
|
|
|
|
gSmmCorePrivate->InSmm = FALSE;
|
|
|
|
}
|
2011-08-16 04:58:20 +02:00
|
|
|
|
|
|
|
PERF_END (NULL, "SMM", NULL, 0) ;
|
2010-02-26 00:41:19 +01:00
|
|
|
}
|
|
|
|
|
2015-11-25 09:40:49 +01:00
|
|
|
/**
|
|
|
|
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);
|
|
|
|
|
2016-10-23 17:14:00 +02:00
|
|
|
//
|
|
|
|
// 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);
|
|
|
|
|
2015-11-25 09:40:49 +01:00
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2010-02-26 00:41:19 +01:00
|
|
|
/**
|
|
|
|
The Entry Point for SMM Core
|
|
|
|
|
|
|
|
Install DXE Protocols and reload SMM Core into SMRAM and register SMM Core
|
|
|
|
EntryPoint on the SMI vector.
|
|
|
|
|
|
|
|
Note: This function is called for both DXE invocation and SMRAM invocation.
|
|
|
|
|
|
|
|
@param ImageHandle The firmware allocated handle for the EFI image.
|
|
|
|
@param SystemTable A pointer to the EFI System Table.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The entry point is executed successfully.
|
|
|
|
@retval Other Some error occurred when executing this entry point.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SmmMain (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN Index;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get SMM Core Private context passed in from SMM IPL in ImageHandle.
|
|
|
|
//
|
|
|
|
gSmmCorePrivate = (SMM_CORE_PRIVATE_DATA *)ImageHandle;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fill in SMRAM physical address for the SMM Services Table and the SMM Entry Point.
|
|
|
|
//
|
|
|
|
gSmmCorePrivate->Smst = &gSmmCoreSmst;
|
|
|
|
gSmmCorePrivate->SmmEntryPoint = SmmEntryPoint;
|
2017-11-20 09:08:28 +01:00
|
|
|
|
2010-02-26 00:41:19 +01:00
|
|
|
//
|
2015-02-02 15:42:22 +01:00
|
|
|
// No need to initialize memory service.
|
|
|
|
// It is done in constructor of PiSmmCoreMemoryAllocationLib(),
|
|
|
|
// so that the library linked with PiSmmCore can use AllocatePool() in constuctor.
|
2010-02-26 00:41:19 +01:00
|
|
|
//
|
|
|
|
|
2014-11-12 04:27:48 +01:00
|
|
|
SmramProfileInit ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Copy FullSmramRanges to SMRAM
|
|
|
|
//
|
2015-07-26 09:38:12 +02:00
|
|
|
mFullSmramRangeCount = gSmmCorePrivate->SmramRangeCount;
|
2014-11-12 04:27:48 +01:00
|
|
|
mFullSmramRanges = AllocatePool (mFullSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR));
|
|
|
|
ASSERT (mFullSmramRanges != NULL);
|
2015-07-26 09:38:12 +02:00
|
|
|
CopyMem (mFullSmramRanges, gSmmCorePrivate->SmramRanges, mFullSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR));
|
2014-11-12 04:27:48 +01:00
|
|
|
|
2010-02-26 00:41:19 +01:00
|
|
|
//
|
|
|
|
// Register all SMI Handlers required by the SMM Core
|
|
|
|
//
|
|
|
|
for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) {
|
|
|
|
Status = SmiHandlerRegister (
|
|
|
|
mSmmCoreSmiHandlers[Index].Handler,
|
|
|
|
mSmmCoreSmiHandlers[Index].HandlerType,
|
|
|
|
&mSmmCoreSmiHandlers[Index].DispatchHandle
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
}
|
2014-11-12 04:27:48 +01:00
|
|
|
|
|
|
|
RegisterSmramProfileHandler ();
|
2016-06-18 04:14:40 +02:00
|
|
|
SmramProfileInstallProtocol ();
|
2014-11-12 04:27:48 +01:00
|
|
|
|
2015-11-25 09:40:49 +01:00
|
|
|
SmmCoreInstallLoadedImage ();
|
|
|
|
|
2016-10-23 17:14:00 +02:00
|
|
|
SmmCoreInitializeMemoryAttributesTable ();
|
|
|
|
|
2017-01-20 15:14:40 +01:00
|
|
|
SmmCoreInitializeSmiHandlerProfile ();
|
|
|
|
|
2010-02-26 00:41:19 +01:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|