From d086010e5bb61cc9f8f4e13943c62f5ce59420e3 Mon Sep 17 00:00:00 2001 From: Guo Mang Date: Wed, 3 Aug 2016 13:21:51 +0800 Subject: BraswellPlatformPkg: Add Common/PlatformSmm Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Guo Mang Reviewed-by: David Wei --- .../Common/PlatformSmm/PlatformSmm.c | 301 +++++++++++++++++++++ .../Common/PlatformSmm/PlatformSmm.h | 190 +++++++++++++ .../Common/PlatformSmm/PlatformSmm.inf | 102 +++++++ 3 files changed, 593 insertions(+) create mode 100644 BraswellPlatformPkg/Common/PlatformSmm/PlatformSmm.c create mode 100644 BraswellPlatformPkg/Common/PlatformSmm/PlatformSmm.h create mode 100644 BraswellPlatformPkg/Common/PlatformSmm/PlatformSmm.inf diff --git a/BraswellPlatformPkg/Common/PlatformSmm/PlatformSmm.c b/BraswellPlatformPkg/Common/PlatformSmm/PlatformSmm.c new file mode 100644 index 0000000000..c3aa883564 --- /dev/null +++ b/BraswellPlatformPkg/Common/PlatformSmm/PlatformSmm.c @@ -0,0 +1,301 @@ +/** @file + Generic template for a child of the IchSmm driver. + + Copyright (c) 2004 - 2015, 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 + 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 "PlatformSmm.h" +#include + +/** + Initializes the SMM Handler Driver + + @param[in] ImageHandle + @param[in] SystemTable + + @retval None + +**/ +EFI_STATUS +EFIAPI +InitializePlatformSmm ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + EFI_SMM_POWER_BUTTON_REGISTER_CONTEXT PowerButtonContext; + EFI_SMM_POWER_BUTTON_DISPATCH2_PROTOCOL *PowerButtonDispatch; + EFI_SMM_ICHN_DISPATCH_PROTOCOL *IchnDispatch; + EFI_SMM_SX_DISPATCH2_PROTOCOL *SxDispatch; + EFI_SMM_SX_REGISTER_CONTEXT EntryDispatchContext; + EFI_SMM_SW_DISPATCH2_PROTOCOL *SwDispatch; + EFI_SMM_SW_REGISTER_CONTEXT SwContext; + + // + // Get the Power Button protocol + // + Status = gSmst->SmmLocateProtocol ( + &gEfiSmmPowerButtonDispatch2ProtocolGuid, + NULL, + (VOID **) &PowerButtonDispatch + ); + ASSERT_EFI_ERROR (Status); + + + PowerButtonContext.Phase = EfiPowerButtonEntry; + Status = PowerButtonDispatch->Register ( + PowerButtonDispatch, + PowerButtonCallback, + &PowerButtonContext, + &Handle + ); + ASSERT_EFI_ERROR (Status); + + // + // Get the Sx dispatch protocol + // + Status = gSmst->SmmLocateProtocol ( + &gEfiSmmSxDispatch2ProtocolGuid, + NULL, + (VOID **) &SxDispatch + ); + ASSERT_EFI_ERROR (Status); + + // + // Register entry phase call back function + // + EntryDispatchContext.Type = SxS3; + EntryDispatchContext.Phase = SxEntry; + Status = SxDispatch->Register ( + SxDispatch, + S3SleepEntryCallBack, + &EntryDispatchContext, + &Handle + ); + + EntryDispatchContext.Type = SxS4; + Status = SxDispatch->Register ( + SxDispatch, + S4SleepCallBack, + &EntryDispatchContext, + &Handle + ); + ASSERT_EFI_ERROR (Status); + + EntryDispatchContext.Type = SxS5; + Status = SxDispatch->Register ( + SxDispatch, + S5SleepCallBack, + &EntryDispatchContext, + &Handle + ); + ASSERT_EFI_ERROR (Status); + + // + // Get the Sw dispatch protocol + // + Status = gSmst->SmmLocateProtocol ( + &gEfiSmmSwDispatch2ProtocolGuid, + NULL, + (VOID **) &SwDispatch + ); + ASSERT_EFI_ERROR (Status); + + // + // Sample software SMI handler. + // Register ACPI enable handler + // + SwContext.SwSmiInputValue = ACPI_ENABLE; + Status = SwDispatch->Register ( + SwDispatch, + EnableAcpiCallback, + &SwContext, + &Handle + ); + ASSERT_EFI_ERROR (Status); + + // + // Sample software SMI handler. + // Register ACPI disable handler. + // + SwContext.SwSmiInputValue = ACPI_DISABLE; + Status = SwDispatch->Register ( + SwDispatch, + DisableAcpiCallback, + &SwContext, + &Handle + ); + ASSERT_EFI_ERROR (Status); + + // + // Get the ICHn protocol + // + Status = gSmst->SmmLocateProtocol ( + &gEfiSmmIchnDispatchProtocolGuid, + NULL, + (VOID **) &IchnDispatch + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +/** + @param[in] DispatchHandle The handle of this callback, obtained when registering + @param[in] DispatchContext The predefined context which contained sleep type and phase + + @retval EFI_SUCCESS Operation successfully performed + +**/ +EFI_STATUS +S3SleepEntryCallBack ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ) + +{ +// +// Add code here +// + + + return EFI_SUCCESS; +} + +/** + When a power button event happens, it shuts off the machine. + + @param[in] DispatchHandle The handle of this callback, obtained when registering + @param[in] DispatchContext The predefined context which contained sleep type and phase + + @retval + +**/ +EFI_STATUS +PowerButtonCallback ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ) +{ + // + // Add code here + // + + return EFI_SUCCESS; +} + +/** + @param[in] DispatchHandle The handle of this callback, obtained when registering + @param[in] DispatchContext The predefined context which contained sleep type and phase + +**/ +EFI_STATUS +EFIAPI +S5SleepCallBack ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ) +{ + // + // Add code here + // + + return EFI_SUCCESS; +} + +/** + @param[in] DispatchHandle The handle of this callback, obtained when registering + @param[in] DispatchContext The predefined context which contained sleep type and phase + + @retval Clears the Save State bit in the clock. + +**/ +EFI_STATUS +EFIAPI +S4SleepCallBack ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ) +{ + // + // Add code here + // + + return EFI_SUCCESS; +} + + + +/** + Sample software SMI handler to enable ACPI mode. + + + @param[in] DispatchHandle EFI Handle + @param[in] DispatchContext Pointer to the EFI_SMM_SW_DISPATCH_CONTEXT + + @retval Nothing + +**/ +EFI_STATUS +EFIAPI +EnableAcpiCallback ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ) +{ + + return EFI_SUCCESS; +} + +/** + Sample Software SMI handler. + + + @param[in] DispatchHandle EFI Handle + @param[in] DispatchContext Pointer to the EFI_SMM_SW_DISPATCH_CONTEXT + + @retval Nothing + +**/ +EFI_STATUS +EFIAPI +DisableAcpiCallback ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ) +{ + + + return EFI_SUCCESS; +} + + + + + + + + diff --git a/BraswellPlatformPkg/Common/PlatformSmm/PlatformSmm.h b/BraswellPlatformPkg/Common/PlatformSmm/PlatformSmm.h new file mode 100644 index 0000000000..57e8992f34 --- /dev/null +++ b/BraswellPlatformPkg/Common/PlatformSmm/PlatformSmm.h @@ -0,0 +1,190 @@ +/** @file + SMM handler driver implementation. + + Copyright (c) 2004 - 2015, 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 + 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 _PLATFORM_H +#define _PLATFORM_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Protocol/GlobalNvsArea.h" +#include +#include +#include +#include +#include "PchAccess.h" +#include "PlatformBaseAddresses.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef struct { + UINT8 Register; + UINT8 Function; + UINT8 Device; + UINT8 Bus; + UINT32 ExtendedRegister; +} SMM_PCI_IO_ADDRESS; + +typedef struct { + CHAR8 BoardAaNumber[7]; + UINTN BoardFabNumber; +} BOARD_AA_NUMBER_DECODE; + +// +// BugBug -- Need to get these two values from acpi.h, but right now, they are +// declared in platform-specific variants of this file, so no easy +// way to pick-up the include file and work across platforms. +// Need these definitions to go into a file like common\acpi.h. +// +#define ACPI_ENABLE 0xA0 +#define ACPI_DISABLE 0xA1 + +#define APM_12_FUNCS 0x50 +#define SMI_SET_SMMVARIABLE_PROTOCOL 0x51 // this is used in Cpu\Pentium\Smm\Base\SmmBase.c + +#define SMI_CMD_GET_MSEG_STATUS 0x70 +#define SMI_CMD_UPDATE_MSEG_SIZE 0x71 +#define SMI_CMD_LOAD_STM 0x72 +#define SMI_CMD_UNLOAD_STM 0x73 +#define SMI_CMD_GET_SMRAM_RANGES 0x74 + +#define PCAT_RTC_ADDRESS_REGISTER 0x74 +#define PCAT_RTC_DATA_REGISTER 0x75 + +#define RTC_ADDRESS_SECOND 0x00 +#define RTC_ADDRESS_SECOND_ALARM 0x01 +#define RTC_ADDRESS_MINUTE 0x02 +#define RTC_ADDRESS_MINUTE_ALARM 0x03 +#define RTC_ADDRESS_HOUR 0x04 +#define RTC_ADDRESS_HOUR_ALARM 0x05 + +#define RTC_ADDRESS_REGISTER_A 0x0A +#define RTC_ADDRESS_REGISTER_B 0x0B +#define RTC_ADDRESS_REGISTER_C 0x0C +#define RTC_ADDRESS_REGISTER_D 0x0D + +#define B_RTC_ALARM_INT_ENABLE 0x20 +#define B_RTC_ALARM_INT_STATUS 0x20 + +#define B_RTC_DATE_ALARM_MASK 0x3F + +#define PCAT_CMOS_2_ADDRESS_REGISTER 0x72 +#define PCAT_CMOS_2_DATA_REGISTER 0x73 + +#define EC_C_PORT 0x66 +#define SMC_SMI_DISABLE 0xBC +#define SMC_ENABLE_ACPI_MODE 0xAA // Enable ACPI mode + +#define IO_MISC 156 + +#define MAXIMUM_NUMBER_OF_PSTATES 12 +#define ICH_SMM_DATA_PORT 0xB3 + +#define EFI_IA32_PMG_CST_CONFIG 0x000000E2 +#define B_EFI_CST_CONTROL_LOCK BIT15 +#define B_EFI_IO_MWAIT_REDIRECTION_ENABLE BIT10 +#define EFI_IA32_PMG_IO_CAPTURE_ADDR 0x000000E4 + +extern EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *mPciRootBridgeIo; + +// +// Callback function prototypes +// +EFI_STATUS +EFIAPI +PowerButtonCallback ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ); + +EFI_STATUS +S5SleepWakeOnLanCallBack ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ); + +EFI_STATUS +EFIAPI +S5SleepCallBack ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ); + +EFI_STATUS +EFIAPI +S4SleepCallBack ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ); + +EFI_STATUS +EFIAPI +EnableAcpiCallback ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ); + +EFI_STATUS +EFIAPI +DisableAcpiCallback ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ); + + +EFI_STATUS +EFIAPI +S3SleepEntryCallBack ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ); + + +#endif + diff --git a/BraswellPlatformPkg/Common/PlatformSmm/PlatformSmm.inf b/BraswellPlatformPkg/Common/PlatformSmm/PlatformSmm.inf new file mode 100644 index 0000000000..211140c68e --- /dev/null +++ b/BraswellPlatformPkg/Common/PlatformSmm/PlatformSmm.inf @@ -0,0 +1,102 @@ +## @file +# Component description file for SMM Platform handler module +# +# Provides platform specific handlers for different SMI events. The module will +# register handlers for sleep state transitions as well as other software SMI +# events. +# +# Copyright (c) 1999 - 2015, 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 +# 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 = 0x00010005 + BASE_NAME = PlatformSmm + FILE_GUID = 1D21C876-2C4F-4a3b-BFEC-A9940920BC6D + MODULE_TYPE = DXE_SMM_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = InitializePlatformSmm + PI_SPECIFICATION_VERSION = 0x0001000A + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + PlatformSmm.c + +[LibraryClasses] + UefiDriverEntryPoint + UefiBootServicesTableLib + DebugLib + IoLib + BaseLib + BaseMemoryLib + DevicePathLib + HobLib + S3BootScriptLib + StallSmmLib + PchPlatformLib + ReportStatusCodeLib + +[Guids] + + ## SOMETIMES_CONSUMES ## Variable:L"AcpiGlobalVariable" + gEfiAcpiVariableCompatiblityGuid + + ## SOMETIMES_CONSUMES + gEfiAcpiVariableGuid + +[Protocols] + ## CONSUMES + gEfiSmmIchnDispatchProtocolGuid + + ## CONSUMES + gEfiGlobalNvsAreaProtocolGuid + + ## CONSUMES + gEfiSmmSwDispatch2ProtocolGuid + + ## SOMETIMES_CONSUMES + gEfiSmmPowerButtonDispatch2ProtocolGuid + + ## CONSUMES + gEfiSmmSxDispatch2ProtocolGuid + + ## CONSUMES + gEfiSmmVariableProtocolGuid + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + IntelFrameworkPkg/IntelFrameworkPkg.dec + ChvRefCodePkg/ChvRefCodePkg.dec + BraswellPlatformPkg/BraswellPlatformPkg.dec + IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec + +[Pcd] + ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress + gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendStart ## CONSUMES + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdS3AcpiReservedMemorySize ## SOMETIMES_CONSUMES + gEfiEdkIIPlatformTokenSpaceGuid.PcdSystemConfiguration + +[Depex] + gEfiSmmBase2ProtocolGuid AND + gEfiSmmAccess2ProtocolGuid AND + gEfiSmmPowerButtonDispatch2ProtocolGuid AND + gEfiSmmSxDispatch2ProtocolGuid AND + gEfiSmmIchnDispatchProtocolGuid AND + gEfiSmmSwDispatch2ProtocolGuid AND + gEfiVariableArchProtocolGuid + -- cgit v1.2.3