diff options
author | Guo Mang <mang.guo@intel.com> | 2016-12-23 14:25:12 +0800 |
---|---|---|
committer | Guo Mang <mang.guo@intel.com> | 2017-05-09 13:03:02 +0800 |
commit | 490a6b3db5981e556178a96a194264a509ca5d81 (patch) | |
tree | a3cc1035749bc044b47619214d42d82e7ba06296 | |
parent | 61fa1b525ef6c4b5209bffe427f5653dc8c608ed (diff) | |
download | edk2-platforms-490a6b3db5981e556178a96a194264a509ca5d81.tar.xz |
BroxtonPlatformPkg: Add SmramSaveInfoHandlerSmm
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Guo Mang <mang.guo@intel.com>
3 files changed, 276 insertions, 0 deletions
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/S3/SmramSaveInfoHandlerSmm/SmramSaveInfoHandlerSmm.c b/Platform/BroxtonPlatformPkg/Common/Features/S3/SmramSaveInfoHandlerSmm/SmramSaveInfoHandlerSmm.c new file mode 100644 index 0000000000..82efcfe366 --- /dev/null +++ b/Platform/BroxtonPlatformPkg/Common/Features/S3/SmramSaveInfoHandlerSmm/SmramSaveInfoHandlerSmm.c @@ -0,0 +1,185 @@ +/** @file
+ A helper driver to save information to SMRAM after SMRR is enabled.
+
+ Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
+
+ 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 "SmramSaveInfoHandlerSmm.h"
+
+#define SMM_FROM_CPU_DRIVER_SAVE_INFO 0x81
+
+#define EFI_SMRAM_CPU_NVS_HEADER_GUID \
+ { \
+ 0x429501d9, 0xe447, 0x40f4, 0x86, 0x7b, 0x75, 0xc9, 0x3a, 0x1d, 0xb5, 0x4e \
+ }
+
+GLOBAL_REMOVE_IF_UNREFERENCED UINT8 mSmiDataRegister;
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mLocked = FALSE;
+EFI_GUID mSmramCpuNvsHeaderGuid = EFI_SMRAM_CPU_NVS_HEADER_GUID;
+
+CPU_INFO_PROTOCOL *mCpuInfoProtocol;
+
+
+/**
+ Dispatch function for a Software SMI handler.
+
+ Save CPU data to SMRAM.
+ To be fixed: Need to negotiate a base address for the saved data in SMRAM.
+
+ @param[in] DispatchHandle The handle of this dispatch function.
+ @param[in] DispatchContext The pointer to the dispatch function's context.
+ The SwSmiInputValue field is filled in
+ by the software dispatch driver prior to
+ invoking this dispatch function.
+ The dispatch function will only be called
+ for input values for which it is registered.
+
+**/
+EFI_STATUS
+SmramSaveInfoHandler (
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_REGISTER_CONTEXT *DispatchContext
+ )
+{
+ EFI_STATUS Status;
+ UINT64 VarData[3];
+ EFI_PHYSICAL_ADDRESS SmramDataAddress;
+
+ ASSERT (DispatchContext != NULL);
+ ASSERT (DispatchContext->SwSmiInputValue == mCpuInfoProtocol->CpuInfo->SmmbaseSwSmiNumber);
+ DEBUG ((EFI_D_INFO, "SmramSaveInfoHandler() Enter\n"));
+ DEBUG ((EFI_D_INFO, "mLocked = %x\n",mLocked));
+ DEBUG ((EFI_D_INFO, "mSmiDataRegister = 0x%02x\n",mSmiDataRegister));
+ DEBUG ((EFI_D_INFO, "IoRead8 (mSmiDataRegister) = 0x%02x\n",IoRead8 (mSmiDataRegister)));
+
+ if (!mLocked && IoRead8 (mSmiDataRegister) == SMM_FROM_CPU_DRIVER_SAVE_INFO) {
+ VarData[2] = mCpuInfoProtocol->SmramCpuInfo->LockBoxSize;
+ VarData[1] = mCpuInfoProtocol->SmramCpuInfo->SmramCpuData;
+
+ Status = gSmst->SmmAllocatePages (
+ AllocateAnyPages,
+ EfiRuntimeServicesData,
+ EFI_SIZE_TO_PAGES ((UINTN) VarData[2]),
+ &SmramDataAddress
+ );
+ ASSERT_EFI_ERROR (Status);
+ DEBUG ((DEBUG_INFO, "CPU SMRAM NVS Data - %x\n", SmramDataAddress));
+ DEBUG ((DEBUG_INFO, "CPU SMRAM NVS Data size - %x\n", VarData[2]));
+ VarData[0] = (UINT64) SmramDataAddress;
+ CopyMem (
+ (VOID *) (UINTN) (VarData[0]),
+ (VOID *) (UINTN) (VarData[1]),
+ (UINTN) (VarData[2])
+ );
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+/**
+ Smm Ready To Lock event notification handler.
+ It sets a flag indicating that SMRAM has been locked.
+
+ @param[in] Protocol Points to the protocol's unique identifier.
+ @param[in] Interface Points to the interface instance.
+ @param[in] Handle The handle on which the interface was installed.
+
+ @retval EFI_SUCCESS Notification handler runs successfully.
+
+ **/
+EFI_STATUS
+EFIAPI
+SmmReadyToLockEventNotify (
+ IN CONST EFI_GUID *Protocol,
+ IN VOID *Interface,
+ IN EFI_HANDLE Handle
+ )
+{
+ mLocked = TRUE;
+ return EFI_SUCCESS;
+}
+
+
+/**
+ Entry point function of this driver.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+SmramSaveInfoHandlerSmmMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ VOID *Registration;
+ EFI_SMM_SW_DISPATCH2_PROTOCOL *SmmSwDispatch;
+ EFI_SMM_SW_REGISTER_CONTEXT SmmSwDispatchContext;
+ EFI_HANDLE DispatchHandle;
+
+ DEBUG ((EFI_D_INFO, "SmramSaveInfoHandlerSmmMain() Enter\n"));
+ //
+ // Get SMI data register
+ //
+ mSmiDataRegister = R_APM_STS;
+
+ //
+ // Register software SMI handler
+ //
+ Status = gSmst->SmmLocateProtocol (
+ &gEfiSmmSwDispatch2ProtocolGuid,
+ NULL,
+ (VOID **) &SmmSwDispatch
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Locate CPU Info Protocol
+ //
+ Status = gBS->LocateProtocol (
+ &gCpuInfoProtocolGuid,
+ NULL,
+ (VOID **) &mCpuInfoProtocol
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ SmmSwDispatchContext.SwSmiInputValue = mCpuInfoProtocol->CpuInfo->SmmbaseSwSmiNumber;
+
+ Status = SmmSwDispatch->Register (
+ SmmSwDispatch,
+ (EFI_SMM_HANDLER_ENTRY_POINT2) &SmramSaveInfoHandler,
+ &SmmSwDispatchContext,
+ &DispatchHandle
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Register SMM Ready To Lock Protocol notification
+ //
+ Status = gSmst->SmmRegisterProtocolNotify (
+ &gEfiSmmReadyToLockProtocolGuid,
+ SmmReadyToLockEventNotify,
+ &Registration
+ );
+ ASSERT_EFI_ERROR (Status);
+ DEBUG ((EFI_D_INFO, "SmramSaveInfoHandlerSmmMain() Exit\n"));
+
+ return Status;
+}
+
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/S3/SmramSaveInfoHandlerSmm/SmramSaveInfoHandlerSmm.h b/Platform/BroxtonPlatformPkg/Common/Features/S3/SmramSaveInfoHandlerSmm/SmramSaveInfoHandlerSmm.h new file mode 100644 index 0000000000..e10875ddbb --- /dev/null +++ b/Platform/BroxtonPlatformPkg/Common/Features/S3/SmramSaveInfoHandlerSmm/SmramSaveInfoHandlerSmm.h @@ -0,0 +1,33 @@ +/** @file
+ Header file for the SMM SMRAM Save Info Handler Driver.
+
+ Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+
+ 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.
+
+**/
+
+#ifndef _SMM_SMRAM_SAVE_INFO_HANDLER_H_
+#define _SMM_SMRAM_SAVE_INFO_HANDLER_H_
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/IoLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/SmmServicesTableLib.h>
+#include <Library/HobLib.h>
+#include <ScAccess.h>
+#include <Protocol/SmmSwDispatch2.h>
+#include <Protocol/SmmReadyToLock.h>
+#include <Protocol/SmmControl2.h>
+#include <Protocol/CpuInfo.h>
+
+#endif
+
diff --git a/Platform/BroxtonPlatformPkg/Common/Features/S3/SmramSaveInfoHandlerSmm/SmramSaveInfoHandlerSmm.inf b/Platform/BroxtonPlatformPkg/Common/Features/S3/SmramSaveInfoHandlerSmm/SmramSaveInfoHandlerSmm.inf new file mode 100644 index 0000000000..f0947efae6 --- /dev/null +++ b/Platform/BroxtonPlatformPkg/Common/Features/S3/SmramSaveInfoHandlerSmm/SmramSaveInfoHandlerSmm.inf @@ -0,0 +1,58 @@ +## @file
+# A helper driver to save information to SMRAM after SMRR is enabled.
+#
+# Copyright (c) 1999 - 2016, Intel Corporation. All rights reserved.<BR>
+#
+# 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.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = SmramSaveInfoHandlerSmm
+ FILE_GUID = 63296C52-01CF-4eea-A47C-782A14DA6894
+ VERSION_STRING = 1.0
+ MODULE_TYPE = DXE_SMM_DRIVER
+ PI_SPECIFICATION_VERSION = 1.10
+ ENTRY_POINT = SmramSaveInfoHandlerSmmMain
+
+[BuildOptions]
+################################################################################
+#
+# Sources Section - list of files that are required for the build to succeed.
+#
+################################################################################
+
+[Packages]
+ MdePkg/MdePkg.dec
+ IntelFrameworkPkg/IntelFrameworkPkg.dec
+ BroxtonSiPkg/BroxtonSiPkg.dec
+
+[LibraryClasses]
+ BaseMemoryLib
+ DebugLib
+ IoLib
+ UefiDriverEntryPoint
+ UefiRuntimeServicesTableLib
+ SmmServicesTableLib
+ HobLib
+
+[Sources]
+ SmramSaveInfoHandlerSmm.c
+ SmramSaveInfoHandlerSmm.h
+
+[Protocols]
+ gEfiSmmSwDispatch2ProtocolGuid ## CONSUMED
+ gEfiSmmControl2ProtocolGuid ## CONSUMED
+ gEfiSmmReadyToLockProtocolGuid ## CONSUMED
+ gCpuInfoProtocolGuid ## CONSUMED
+
+[Depex]
+ gEfiSmmSwDispatch2ProtocolGuid AND
+ gEfiSmmControl2ProtocolGuid
|