diff options
Diffstat (limited to 'ReferenceCode/Chipset/LynxPoint/Wdt')
19 files changed, 1802 insertions, 0 deletions
diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommon.c b/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommon.c new file mode 100644 index 0000000..6576aad --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommon.c @@ -0,0 +1,246 @@ +/** @file + Library that contains common parts of WdtPei and WdtDxe. Not a standalone module. + +@copyright + Copyright (c) 2010 - 2012 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + This file contains an 'Intel Peripheral Driver' and uniquely + identified as "Intel Reference Module" and is + licensed for Intel CPUs and chipsets under the terms of your + license agreement with Intel or your vendor. This file may + be modified by the user, subject to additional terms of the + license agreement +**/ +#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000) +#include "EdkIIGlueBase.h" +#endif + +#include "WdtCommon.h" + +UINT8 mAllowExpectedReset = 0; +/// +/// mWdtHobGuid is linked and used in WdtPei and WdtDxe +/// +EFI_GUID mWdtHobGuid = WDT_HOB_GUID; + +/** + Reads LPC bridge to get Watchdog Timer address + + @param[in] none + + @retval UINT32 Watchdog's address +**/ +UINT32 +WdtGetAddress ( + VOID + ) +{ + UINT32 Address; + + Address = (MmioRead32 ( + MmPciAddress (0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_LPC, + PCI_FUNCTION_NUMBER_PCH_LPC, + R_PCH_LPC_ACPI_BASE)) & B_PCH_LPC_ACPI_BASE_BAR) + + R_PCH_OC_WDT_CTL; + + return Address; +} + +/** + Reloads WDT with new timeout value and starts it. Also sets Unexpected Reset bit, which + causes the next reset to be treated as watchdog expiration - unless AllowKnownReset() + function was called too. + + @param[in] TimeoutValue Time in seconds before WDT times out. Supported range = 1 - 1024. + + @retval EFI_SUCCESS if everything's OK + @retval EFI_INVALID_PARAMETER if TimeoutValue parameter is wrong +**/ +EFI_STATUS +EFIAPI +WdtReloadAndStart ( + IN UINT32 TimeoutValue + ) +{ + UINT32 Readback; + + DEBUG ((EFI_D_INFO, "\n(Wdt) ReloadAndStartTimer(%d)\n", TimeoutValue)); + + if ((TimeoutValue > B_PCH_OC_WDT_CTL_TOV_MASK) || (TimeoutValue == 0)) { + return EFI_INVALID_PARAMETER; + } + + Readback = IoRead32 (WdtGetAddress ()); + Readback |= (B_PCH_OC_WDT_CTL_EN | B_PCH_OC_WDT_CTL_FORCE_ALL | B_PCH_OC_WDT_CTL_ICCSURV); + if (mAllowExpectedReset == 0) { + Readback |= B_PCH_OC_WDT_CTL_UNXP_RESET_STS; + } + +#if defined EFI_DEBUG && !defined USE_WDT_IN_DEBUG_BIOS + /// + /// in Debug mode, WDT will not be turned on. This is to prevent platform reboots triggered + /// by WDT expiration, which can be expected when processor is halted for debugging + /// + Readback &= ~(B_PCH_OC_WDT_CTL_EN | B_PCH_OC_WDT_CTL_FORCE_ALL | B_PCH_OC_WDT_CTL_UNXP_RESET_STS); + DEBUG ((EFI_D_INFO, "(Wdt) Wdt disabled in Debug BIOS\n")); + +#endif + + Readback &= ~(B_PCH_OC_WDT_CTL_TOV_MASK); + Readback |= ((TimeoutValue - 1) & B_PCH_OC_WDT_CTL_TOV_MASK); + IoWrite32 (WdtGetAddress (), Readback); + Readback |= B_PCH_OC_WDT_CTL_RLD; + IoWrite32 (WdtGetAddress (), Readback); + return EFI_SUCCESS; +} + +/** + Disables WDT timer. + + @param[in] None + + @retval None +**/ +VOID +EFIAPI +WdtDisable ( + VOID + ) +{ + UINT32 Readback; + + DEBUG ((EFI_D_INFO, "(Wdt) DisableTimer\n")); + + Readback = IoRead32 (WdtGetAddress ()); + Readback &= ~(B_PCH_OC_WDT_CTL_EN | B_PCH_OC_WDT_CTL_FORCE_ALL | B_PCH_OC_WDT_CTL_UNXP_RESET_STS); + IoWrite32 (WdtGetAddress (), Readback); +} + +/** + Returns WDT failure status. + + @param[in] None + + @retval V_PCH_OC_WDT_CTL_STATUS_FAILURE If there was WDT expiration or unexpected reset + @retval V_PCH_OC_WDT_CTL_STATUS_OK Otherwise +**/ +UINT8 +EFIAPI +WdtCheckStatus ( + VOID + ) +{ + UINT32 Readback; + + DEBUG ((EFI_D_INFO, "(Wdt) CheckTimerStatus\n")); + + Readback = IoRead32 (WdtGetAddress ()); + + DEBUG ((EFI_D_INFO, "(Wdt) Readback = (%x)\n", Readback)); + + if (Readback & B_PCH_OC_WDT_CTL_FAILURE_STS) { + DEBUG ((EFI_D_INFO, "(Wdt) Status = FAILURE\n")); + return V_PCH_OC_WDT_CTL_STATUS_FAILURE; + } else { + return V_PCH_OC_WDT_CTL_STATUS_OK; + } +} + +/** + Normally, each reboot performed while watchdog runs is considered a failure. + This function allows platform to perform expected reboots with WDT running, + without being interpreted as failures. + In DXE phase, it is enough to call this function any time before reset. + In PEI phase, between calling this function and performing reset, ReloadAndStart() + must not be called. + + @param[in] None + + @retval None +**/ +VOID +EFIAPI +WdtAllowKnownReset ( + VOID + ) +{ + UINT32 Readback; + + DEBUG ((EFI_D_INFO, "(Wdt) AllowKnownReset\n")); + + mAllowExpectedReset = 1; + + Readback = IoRead32 (WdtGetAddress ()); + Readback &= ~(B_PCH_OC_WDT_CTL_UNXP_RESET_STS | B_PCH_OC_WDT_CTL_FORCE_ALL); + IoWrite32 (WdtGetAddress (), Readback); +} + +/** + Returns information if WDT coverage for the duration of BIOS execution + was requested by an OS application + + @param[in] None + + @retval TRUE if WDT was requested + @retval FALSE if WDT was not requested +**/ +UINT8 +EFIAPI +IsWdtRequired ( + VOID + ) +{ + UINT32 Readback; + + DEBUG ((EFI_D_INFO, "(Wdt) IsWdtRequired")); + + Readback = IoRead32 (WdtGetAddress ()); + + if ((Readback & B_PCH_OC_WDT_CTL_AFTER_POST) != 0) { + DEBUG ((EFI_D_INFO, " - yes\n")); + return TRUE; + } else { + DEBUG ((EFI_D_INFO, " - no\n")); + return FALSE; + } + +} + +/** + Returns WDT enabled/disabled status. + + @param[in] None + + @retval TRUE if WDT is enabled + @retval FALSE if WDT is disabled +**/ +UINT8 +EFIAPI +IsWdtEnabled ( + VOID + ) +{ + UINT32 Readback; + + DEBUG ((EFI_D_INFO, "(Wdt) IsWdtEnabled")); + + Readback = IoRead32 (WdtGetAddress ()); + + if ((Readback & B_PCH_OC_WDT_CTL_EN) != 0) { + DEBUG ((EFI_D_INFO, " - yes\n")); + return TRUE; + } else { + DEBUG ((EFI_D_INFO, " - no\n")); + return FALSE; + } + +} diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommon.h b/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommon.h new file mode 100644 index 0000000..dfc6959 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommon.h @@ -0,0 +1,166 @@ +/** @file + Library that contains common parts of WdtPei and WdtDxe. Not a standalone module. + +@copyright + Copyright (c) 2010 - 2012 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + This file contains an 'Intel Peripheral Driver' and uniquely + identified as "Intel Reference Module" and is + licensed for Intel CPUs and chipsets under the terms of your + license agreement with Intel or your vendor. This file may + be modified by the user, subject to additional terms of the + license agreement +**/ +#include "PchAccess.h" + +extern UINT8 mAllowExpectedReset; +extern EFI_GUID mWdtHobGuid; + +#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000) +#define WDT_HOB_GUID \ + { \ + 0x65675786, 0xacca, 0x4b11, 0x8a, 0xb7, 0xf8, 0x43, 0xaa, 0x2a, 0x8b, 0xea \ + } +#else +#define WDT_HOB_GUID \ + { \ + 0x65675786, 0xacca, 0x4b11, \ + { \ + 0x8a, 0xb7, 0xf8, 0x43, 0xaa, 0x2a, 0x8b, 0xea \ + } \ + } +#endif +// +// HOB definitions duplicated from HOB.h which couldn't be included directly, +// because it requires either EdkIIGluePeim.h or EdkIIGlueDxe.h, +// and WdtCommon must not include any of those. +// +#ifndef _PEI_HOB_H_ +#ifndef __HOB__H__ +typedef struct _EFI_HOB_GENERIC_HEADER { + UINT16 HobType; + UINT16 HobLength; + UINT32 Reserved; +} EFI_HOB_GENERIC_HEADER; + +typedef struct _EFI_HOB_GUID_TYPE { + EFI_HOB_GENERIC_HEADER Header; + EFI_GUID Name; +} EFI_HOB_GUID_TYPE; +#endif +#endif + +typedef struct { + EFI_HOB_GUID_TYPE Header; + UINT16 TimeoutValue; + UINT8 Active; +} WDT_HOB; + +/** + Reads LPC bridge to get Watchdog Timer address + + @param[in] none + + @retval UINT32 Watchdog's address +**/ +UINT32 +WdtGetAddress ( + VOID + ); + +/** + Reloads WDT with new timeout value and starts it. Also sets Unexpected Reset bit, which + causes the next reset to be treated as watchdog expiration - unless AllowKnownReset() + function was called too. + + @param[in] TimeoutValue Time in seconds before WDT times out. Supported range = 1 - 1024. + + @retval EFI_SUCCESS if everything's OK + @retval EFI_INVALID_PARAMETER if TimeoutValue parameter is wrong +**/ +EFI_STATUS +EFIAPI +WdtReloadAndStart ( + IN UINT32 TimeoutValue + ); + +/** + Disables WDT timer. + + @param[in] None + + @retval None +**/ +VOID +EFIAPI +WdtDisable ( + VOID + ); + +/** + Returns WDT failure status. + + @param[in] None + + @retval V_PCH_OC_WDT_CTL_STATUS_FAILURE If there was WDT expiration or unexpected reset + @retval V_PCH_OC_WDT_CTL_STATUS_OK Otherwise +**/ +UINT8 +EFIAPI +WdtCheckStatus ( + VOID + ); + +/** + Normally, each reboot performed while watchdog runs is considered a failure. + This function allows platform to perform expected reboots with WDT running, + without being interpreted as failures. + In DXE phase, it is enough to call this function any time before reset. + In PEI phase, between calling this function and performing reset, ReloadAndStart() + must not be called. + + @param[in] None + + @retval None +**/ +VOID +EFIAPI +WdtAllowKnownReset ( + VOID + ); + +/** + Returns information if WDT coverage for the duration of BIOS execution + was requested by an OS application + + @param[in] None + + @retval TRUE if WDT was requested + @retval FALSE if WDT was not requested +**/ +UINT8 +EFIAPI +IsWdtRequired ( + VOID + ); + +/** + Returns WDT enabled/disabled status. + + @param[in] None + + @retval TRUE if WDT is enabled + @retval FALSE if WDT is disabled +**/ +UINT8 +EFIAPI +IsWdtEnabled ( + VOID + ); diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommonLib.cif b/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommonLib.cif new file mode 100644 index 0000000..588d9c9 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommonLib.cif @@ -0,0 +1,11 @@ +<component> + name = "WdtCommonLib" + category = ModulePart + LocalRoot = "ReferenceCode\Chipset\LynxPoint\Wdt\Common" + RefName = "WdtCommonLib" +[files] +"WdtCommonLib.sdl" +"WdtCommonLib.mak" +"WdtCommon.h" +"WdtCommon.c" +<endComponent> diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommonLib.mak b/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommonLib.mak new file mode 100644 index 0000000..8032e7d --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommonLib.mak @@ -0,0 +1,103 @@ +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* + +#************************************************************************* +# $Header: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/WdtCommonLib/WdtCommonLib.mak 1 2/08/12 9:31a Yurenlai $ +# +# $Revision: 1 $ +# +# $Date: 2/08/12 9:31a $ +#************************************************************************* +# Revision History +# ---------------- +# $Log: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/WdtCommonLib/WdtCommonLib.mak $ +# +# 1 2/08/12 9:31a Yurenlai +# Intel Lynx Point/SB eChipset initially releases. +# +#************************************************************************* +EDK : WdtCommonLib +WdtDxe : $(BUILD_DIR)\WdtDxe.mak WdtDxeBin + +WdtCommonLib : WdtCommonDxeLib WdtCommonPeiLib + +$(WdtCommonDxeLib_LIB) : WdtCommonDxeLib +$(WdtCommonPeiLib_LIB) : WdtCommonPeiLib + +WdtCommonDxeLib : $(BUILD_DIR)\WdtCommonLib.mak WdtCommonLibDxeBin + +WdtCommonPeiLib : $(BUILD_DIR)\WdtCommonLib.mak WdtCommonLibPeiBin + +$(BUILD_DIR)\WdtCommonLib.mak : $(WdtCommonLib_DIR)\$(@B).cif $(WdtCommonLib_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(WdtCommonLib_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +WdtCommonLib_INCLUDES=\ + $(EdkIIGlueLib_INCLUDES)\ + $(INTEL_PCH_INCLUDES)\ + $(WdtCommonLib_INCLUDES) + + +WdtCommonLib_DEFINES = \ + $(CFLAGS) + +DxeCpuBuildDefine = \ +!IF "$(x64_BUILD)"=="1" + /DMDE_CPU_X64\ +!ELSE + /DMDE_CPU_IA32\ +!ENDIF + +PeimCpuBuildDefine = \ + /DMDE_CPU_IA32\ + +WdtCommonLibPeim_DEFINES = \ + $(WdtCommonLib_DEFINES)\ + $(PeimCpuBuildDefine)\ + +WdtCommonLibDxe_DEFINES = \ + $(WdtCommonLib_DEFINES)\ + $(DxeCpuBuildDefine)\ + +WdtCommonLibDxeBin : + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS) \ + /f $(BUILD_DIR)\WdtCommonLib.mak all\ + "MY_INCLUDES=$(WdtCommonLib_INCLUDES)" \ + "CFLAGS=$(WdtCommonLibDxe_DEFINES)"\ + TYPE=LIBRARY \ + LIBRARY_NAME=$(WdtCommonDxeLib_LIB) + +WdtCommonLibPeiBin : +!IF "$(x64_BUILD)"=="1" + $(MAKE) /$(MAKEFLAGS) $(EDK_DEFAULTS) BUILD_DIR=$(BUILD_DIR)\IA32 \ +!ELSE + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS) \ +!ENDIF + /f $(BUILD_DIR)\WdtCommonLib.mak all\ + "MY_INCLUDES=$(WdtCommonLib_INCLUDES)" \ + "CFLAGS=$(WdtCommonLibPeim_DEFINES)"\ + TYPE=PEI_LIBRARY \ + LIBRARY_NAME=$(WdtCommonPeiLib_LIB) +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommonLib.sdl b/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommonLib.sdl new file mode 100644 index 0000000..46ed512 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Common/WdtCommonLib.sdl @@ -0,0 +1,92 @@ +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* + +#************************************************************************* +# $Header: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/WdtCommonLib/WdtCommonLib.sdl 1 2/08/12 9:31a Yurenlai $ +# +# $Revision: 1 $ +# +# $Date: 2/08/12 9:31a $ +#************************************************************************* +# Revision History +# ---------------- +# $Log: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/WdtCommonLib/WdtCommonLib.sdl $ +# +# 1 2/08/12 9:31a Yurenlai +# Intel Lynx Point/SB eChipset initially releases. +# +#************************************************************************* +TOKEN + Name = "WdtCommonLib_SUPPORT" + Value = "1" + Help = "Main switch to enable WdtCommonLib support in Project" + TokenType = Boolean + TargetMAK = Yes + Master = Yes +End + +PATH + Name = "WdtCommonLib_DIR" +End + +MODULE + Help = "Includes WdtCommonLib.mak to Project" + File = "WdtCommonLib.mak" +End + +ELINK + Name = "WdtCommonLib_INCLUDES" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "/I$(WdtCommonLib_DIR)" + Parent = "WdtCommonLib_INCLUDES" + InvokeOrder = AfterParent +End + +ELINK + Name = "WdtCommonDxeLib_LIB" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "$(BUILD_DIR)\WdtCommonDxeLib.lib" + Parent = "WdtCommonDxeLib_LIB" + InvokeOrder = AfterParent +End + +ELINK + Name = "WdtCommonPeiLib_LIB" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "$(BUILD_DIR)\WdtCommonPeiLib.lib" + Parent = "WdtCommonPeiLib_LIB" + InvokeOrder = AfterParent +End +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.c b/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.c new file mode 100644 index 0000000..ea5bd2f --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.c @@ -0,0 +1,218 @@ +/** @file + Implementation file for Watchdog Timer functionality + +@copyright + Copyright (c) 2010 - 2012 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + This file contains an 'Intel Peripheral Driver' and uniquely + identified as "Intel Reference Module" and is + licensed for Intel CPUs and chipsets under the terms of your + license agreement with Intel or your vendor. This file may + be modified by the user, subject to additional terms of the + license agreement +**/ +#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000) +#include "EdkIIGlueDxe.h" +#endif + +#include EFI_PROTOCOL_CONSUMER (PchReset) +#include "WdtCommon.h" +#include EFI_PROTOCOL_PRODUCER (Wdt) + +VOID +EFIAPI +WdtRunBeforeOsBoot ( + IN EFI_EVENT Event, + IN VOID *Context + ); + +EFI_STATUS +EFIAPI +WdtPchResetCallback ( + IN PCH_RESET_TYPE PchResetType + ); + +#define TIMEOUT_AFTER_POST_MULTIPLIER 16 +#define MINIMUM_TIMEOUT_AT_S4_EXIT 600 ///< 10 minutes +EFI_HANDLE mImageHandle; +WDT_PROTOCOL mWdtProtocol = { + WdtReloadAndStart, + WdtCheckStatus, + WdtDisable, + WdtAllowKnownReset, + IsWdtRequired, + IsWdtEnabled +}; + +PCH_RESET_CALLBACK_PROTOCOL mPchResetCallbackProtocol = { WdtPchResetCallback }; + +/** + Installs WDT protocol. + Registers a function to be executed just before booting to OS. + + @param[in] ImageHandle Image handle for this driver image + @param[in] SystemTable Pointer to the EFI System Table + + @retval EFI_SUCCESS WDT DXE driver initialization completed successfully +**/ +EFI_STATUS +WdtDxeEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT Event; + + DEBUG ((EFI_D_INFO, "(Wdt) Entry Point to WdtDxe\n")); + + mImageHandle = ImageHandle; + + Status = gBS->CreateEvent ( + EVENT_SIGNAL_EXIT_BOOT_SERVICES, + EFI_TPL_CALLBACK, + WdtRunBeforeOsBoot, + NULL, + &Event + ); + ASSERT_EFI_ERROR (Status); + + Status = EfiCreateEventLegacyBootEx ( + EFI_TPL_CALLBACK, + WdtRunBeforeOsBoot, + NULL, + &Event + ); + ASSERT_EFI_ERROR (Status); + + DEBUG ((EFI_D_INFO, "(Wdt) WDT event registration; Status = %r\n", Status)); + + Status = gBS->InstallProtocolInterface ( + &ImageHandle, + &gWdtProtocolGuid, + EFI_NATIVE_INTERFACE, + &mWdtProtocol + ); + ASSERT_EFI_ERROR (Status); + + Status = gBS->InstallProtocolInterface ( + &ImageHandle, + &gPchResetCallbackProtocolGuid, + EFI_NATIVE_INTERFACE, + &mPchResetCallbackProtocol + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +/** + Turns on watchdog timer just before booting to OS, if an OS application requested that. + Clears request status. + Uninstalls Wdt protocol to prevent other modules from interfering with actions described above. + + @param[in] Event useless here, but required in functions invoked by events + @param[in] Context useless here, but required in functions invoked by events + + @retval None +**/ +VOID +EFIAPI +WdtRunBeforeOsBoot ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + UINT32 ReloadValue; + UINT32 Readback; + EFI_STATUS Status; + EFI_BOOT_MODE BootMode; + EFI_PEI_HOB_POINTERS HobList; + WDT_HOB *WdtHob; + + gBS->CloseEvent (Event); + + DEBUG ((EFI_D_INFO, "(Wdt) RunWdtBeforeOsBoot\n")); + Status = gBS->UninstallProtocolInterface ( + mImageHandle, + &gWdtProtocolGuid, + &mWdtProtocol + ); + + Status = gBS->UninstallProtocolInterface ( + mImageHandle, + &gPchResetCallbackProtocolGuid, + &mPchResetCallbackProtocol + ); + /// + /// check boot type, there are different flows for S4/S5 + /// + EfiGetSystemConfigurationTable (&gEfiHobListGuid, (VOID **) &HobList.Raw); + if (HobList.Header->HobType != EFI_HOB_TYPE_HANDOFF) { + DEBUG ((EFI_D_ERROR, "(Wdt) Handoff Hob missing!\n")); + return; + } + + BootMode = HobList.HandoffInformationTable->BootMode; + + WdtHob = GetFirstGuidHob (&mWdtHobGuid); + if (WdtHob == NULL) { + return; + } + + Readback = IoRead32 (WdtGetAddress ()); + ReloadValue = TIMEOUT_AFTER_POST_MULTIPLIER * ((Readback & B_PCH_OC_WDT_CTL_AFTER_POST) >> 16); + + if (BootMode == BOOT_ON_S4_RESUME) { + /// + /// S4 resume: if WDT was enabled before S0->S4 transition, + /// then WDT must be turned on even though TimeoutValueAfterPost == 0 + /// unlike in S5->S0 flow, ToVaP is not set to zero after being consumed + /// + if (WdtHob->Active == 1) { + if (ReloadValue != 0) { + WdtReloadAndStart (ReloadValue); + } else { + WdtReloadAndStart (MINIMUM_TIMEOUT_AT_S4_EXIT); + } + } else { + WdtDisable (); + } + } else if (ReloadValue != 0) { + /// + /// start WDT with TimeoutValueAfterPost and clear that value from register + /// + Readback &= ~(B_PCH_OC_WDT_CTL_AFTER_POST); + IoWrite32 (WdtGetAddress (), Readback); + WdtReloadAndStart (ReloadValue); + } else { + WdtDisable (); + } + + return; +} + +/** + WDT call back function for Pch Reset. + + @param[in] PchResetType Pch Reset Types which includes PowerCycle, Globalreset. + + @retval EFI_SUCCESS The function completed successfully + @retval Others All other error conditions encountered result in an ASSERT. +**/ +EFI_STATUS +EFIAPI +WdtPchResetCallback ( + IN PCH_RESET_TYPE PchResetType + ) +{ + WdtAllowKnownReset (); + return EFI_SUCCESS; +} diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.cif b/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.cif new file mode 100644 index 0000000..84a9fad --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.cif @@ -0,0 +1,12 @@ +<component> + name = "WdtDxe" + category = ModulePart + LocalRoot = "ReferenceCode\Chipset\LynxPoint\Wdt\Dxe\" + RefName = "WdtDxe" +[files] +"WdtDxe.sdl" +"WdtDxe.dxs" +"WdtDxe.mak" +"WdtDxe.c" +"WdtDxe.inf" +<endComponent> diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.dxs b/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.dxs new file mode 100644 index 0000000..b64a661 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.dxs @@ -0,0 +1,30 @@ +/** @file + Dependencies file for Watchdog Timer functionality + +@copyright + Copyright (c) 2010 - 2012 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + This file contains a 'Sample Driver' and is licensed as such + under the terms of your license agreement with Intel or your + vendor. This file may be modified by the user, subject to + the additional terms of the license agreement + +**/ + + +#include "AutoGen.h" +#include "DxeDepex.h" +#if defined (BUILD_WITH_GLUELIB) || defined (BUILD_WITH_EDKII_GLUE_LIB) +#include "EfiDepex.h" +#endif + +DEPENDENCY_START + TRUE +DEPENDENCY_END diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.inf b/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.inf new file mode 100644 index 0000000..ceff3c7 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.inf @@ -0,0 +1,87 @@ +## @file +# Component description file for the watchdog timer driver. +# +#@copyright +# Copyright (c) 2010 - 2012 Intel Corporation. All rights reserved +# This software and associated documentation (if any) is furnished +# under a license and may only be used or copied in accordance +# with the terms of the license. Except as permitted by such +# license, no part of this software or documentation may be +# reproduced, stored in a retrieval system, or transmitted in any +# form or by any means without the express written consent of +# Intel Corporation. +# +# This file contains a 'Sample Driver' and is licensed as such +# under the terms of your license agreement with Intel or your +# vendor. This file may be modified by the user, subject to +# the additional terms of the license agreement +# + +[defines] +BASE_NAME = WdtDxe +FILE_GUID = 5AAB83E5-F027-4ca7-BFD0-16358CC9E453 +COMPONENT_TYPE = BS_DRIVER + +[sources.common] + WdtDxe.c + ../Common/WdtCommon.h + ../Common/WdtCommon.c + +# +# Edk II Glue Driver Entry Point +# + EdkIIGlueDxeDriverEntryPoint.c + + +[includes.common] + . + ../Common + $(EDK_SOURCE)/Foundation/Efi + $(EDK_SOURCE)/Foundation/Include + $(EDK_SOURCE)/Foundation/Efi/Include + $(EDK_SOURCE)/Foundation/Framework/Include + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT) + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT)/Include + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT)/Include/Library +# +# EDK II Glue Library utilizes some standard headers from EDK +# + $(EFI_SOURCE) + $(EDK_SOURCE)/Foundation + $(EDK_SOURCE)/Foundation/Framework + $(EDK_SOURCE)/Foundation/Include/IndustryStandard + $(EDK_SOURCE)/Foundation/Core/Dxe + $(EDK_SOURCE)/Foundation/Include/Pei + $(EDK_SOURCE)/Foundation/Library/Dxe/Include + $(EDK_SOURCE)/Foundation/Library/EdkIIGlueLib/Include + $(EDK_SOURCE)/Foundation/Library/EdkIIGlueLib/Include/Library + +[libraries.common] + EdkIIGlueBaseIoLibIntrinsic + EdkIIGlueBaseMemoryLib + EdkIIGlueBasePciLibPciExpress + EdkIIGlueDxeReportStatusCodeLib + EdkIIGlueDxeDebugLibReportStatusCode + EdkIIGlueUefiBootServicesTableLib + EdkIIGlueUefiRuntimeServicesTableLib + EdkIIGlueDxeServicesTableLib + EdkProtocolLib + EdkIIGlueDxeHobLib + $(PROJECT_PCH_FAMILY)ProtocolLib + EfiGuidLib + +[nmake.common] + IMAGE_ENTRY_POINT = _ModuleEntryPoint + DPX_SOURCE = WdtDxe.dxs +# +# Module Entry Point +# + C_FLAGS = $(C_FLAGS) -D __EDKII_GLUE_MODULE_ENTRY_POINT__=WdtDxeEntryPoint \ + -D __EDKII_GLUE_BASE_IO_LIB_INTRINSIC__ \ + -D __EDKII_GLUE_BASE_MEMORY_LIB__ \ + -D __EDKII_GLUE_DXE_REPORT_STATUS_CODE_LIB__ \ + -D __EDKII_GLUE_DXE_DEBUG_LIB_REPORT_STATUS_CODE__ \ + -D __EDKII_GLUE_UEFI_BOOT_SERVICES_TABLE_LIB__ \ + -D __EDKII_GLUE_UEFI_RUNTIME_SERVICES_TABLE_LIB__ \ + -D __EDKII_GLUE_DXE_SERVICES_TABLE_LIB__ \ + -D __EDKII_GLUE_DXE_HOB_LIB__
\ No newline at end of file diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.mak b/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.mak new file mode 100644 index 0000000..a36f6cd --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.mak @@ -0,0 +1,102 @@ +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* + +#************************************************************************* +# $Header: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/WdtDxe/WdtDxe.mak 3 9/26/12 3:43a Victortu $ +# +# $Revision: 3 $ +# +# $Date: 9/26/12 3:43a $ +#************************************************************************* +# Revision History +# ---------------- +# $Log: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/WdtDxe/WdtDxe.mak $ +# +# 3 9/26/12 3:43a Victortu +# Lynx Point PCH Chipset Framework Reference Code Beta 0.7.0 +# +# 2 2/24/12 2:31a Victortu +# Updated to support 4.6.5.3_IntelEDK_1117_Patch7_00. +# +# 1 2/08/12 9:32a Yurenlai +# Intel Lynx Point/SB eChipset initially releases. +# +#************************************************************************* +EDK : WdtDxe +WdtDxe : $(BUILD_DIR)\WdtDxe.mak WdtDxeBin + +$(BUILD_DIR)\WdtDxe.mak : $(WdtDxe_DIR)\$(@B).cif $(BUILD_RULES) + $(CIF2MAK) $(WdtDxe_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +WdtDxe_INCLUDES=\ + $(EdkIIGlueLib_INCLUDES)\ + $(INTEL_PCH_INCLUDES)\ + $(WdtCommonLib_INCLUDES) + +WdtDxe_LIBS=\ +!IF "$(x64_BUILD)"=="1" + $(EdkIIGlueBaseLibX64_LIB)\ +!ELSE + $(EdkIIGlueBaseLibIA32_LIB)\ +!ENDIF + $(EdkIIGlueBaseIoLibIntrinsic_LIB)\ + $(EdkIIGlueBaseMemoryLib_LIB)\ + $(EdkIIGlueBasePciLibPciExpress_LIB)\ + $(EdkIIGlueDxeReportStatusCodeLib_LIB)\ + $(EdkIIGlueDxeDebugLibReportStatusCode_LIB)\ + $(EdkIIGlueUefiBootServicesTableLib_LIB)\ + $(EdkIIGlueDxeServicesTableLib_LIB)\ + $(EDKPROTOCOLLIB)\ + $(EdkIIGlueDxeHobLib_LIB)\ + $(INTEL_PCH_PROTOCOL_LIB)\ + $(EFIGUIDLIB)\ + $(WdtCommonDxeLib_LIB) + +WdtDxe_DEFINES=\ + $(MY_DEFINES)\ + /D"__EDKII_GLUE_MODULE_ENTRY_POINT__=WdtDxeEntryPoint"\ + /D __EDKII_GLUE_BASE_IO_LIB_INTRINSIC__ \ + /D __EDKII_GLUE_BASE_MEMORY_LIB__ \ + /D __EDKII_GLUE_DXE_REPORT_STATUS_CODE_LIB__ \ + /D __EDKII_GLUE_DXE_DEBUG_LIB_REPORT_STATUS_CODE__ \ + /D __EDKII_GLUE_UEFI_BOOT_SERVICES_TABLE_LIB__\ + /D __EDKII_GLUE_DXE_SERVICES_TABLE_LIB__\ + /D __EDKII_GLUE_DXE_HOB_LIB__ + +WdtDxeBin : $(WdtDxe_LIBS) + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS)\ + /f $(BUILD_DIR)\WdtDxe.mak all\ + "MY_INCLUDES=$(WdtDxe_INCLUDES)"\ + "MY_DEFINES=$(WdtDxe_DEFINES)"\ + GUID=5AAB83E5-F027-4ca7-BFD0-16358CC9E453\ + ENTRY_POINT=_ModuleEntryPoint \ + EDKIIModule=DXEDRIVER\ + TYPE=BS_DRIVER \ + DEPEX1=$(WdtDxe_DIR)\WdtDxe.dxs \ + DEPEX1_TYPE=EFI_SECTION_DXE_DEPEX \ + COMPRESS=1 + +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.sdl b/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.sdl new file mode 100644 index 0000000..edfd5a6 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Dxe/WdtDxe.sdl @@ -0,0 +1,68 @@ +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* + +#************************************************************************* +# $Header: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/WdtDxe/WdtDxe.sdl 1 2/08/12 9:32a Yurenlai $ +# +# $Revision: 1 $ +# +# $Date: 2/08/12 9:32a $ +#************************************************************************* +# Revision History +# ---------------- +# $Log: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/WdtDxe/WdtDxe.sdl $ +# +# 1 2/08/12 9:32a Yurenlai +# Intel Lynx Point/SB eChipset initially releases. +# +#************************************************************************* +TOKEN + Name = "WdtDxe_SUPPORT" + Value = "1" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + TargetH = Yes + Master = Yes + Help = "Main switch to enable ICC support in Project in DXE Phase" +End + +MODULE + Help = "Includes WdtDxe.mak to Project" + File = "WdtDxe.mak" +End + +PATH + Name = "WdtDxe_DIR" + Help = "Icc Support commands" +End + +ELINK + Name = "$(BUILD_DIR)\WdtDxe.ffs" + Parent = "FV_MAIN" + InvokeOrder = AfterParent +End +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.c b/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.c new file mode 100644 index 0000000..c1d1e03 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.c @@ -0,0 +1,280 @@ +/** @file + Implementation file for Watchdog Timer functionality + +@copyright + Copyright (c) 2010 - 2012 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + This file contains an 'Intel Peripheral Driver' and uniquely + identified as "Intel Reference Module" and is + licensed for Intel CPUs and chipsets under the terms of your + license agreement with Intel or your vendor. This file may + be modified by the user, subject to additional terms of the + license agreement + +**/ +#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000) +#include "EdkIIGluePeim.h" +#endif + +#include EFI_PPI_CONSUMER (PchReset) +#include "WdtCommon.h" +#include EFI_PPI_PRODUCER (Wdt) + +EFI_STATUS +EFIAPI +WdtPchResetCallback ( + IN PCH_RESET_TYPE PchResetType + ); + +static WDT_PPI mWdtPpi = { + WdtReloadAndStart, + WdtCheckStatus, + WdtDisable, + WdtAllowKnownReset, + IsWdtRequired, + IsWdtEnabled +}; + +static PCH_RESET_CALLBACK_PPI mPchResetCallbackPpi = { WdtPchResetCallback }; + +EFI_STATUS +EndOfPeiCallback ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ); + +static EFI_PEI_PPI_DESCRIPTOR mInstallWdtPpi = { + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gWdtPpiGuid, + &mWdtPpi +}; + +static EFI_PEI_PPI_DESCRIPTOR mInstallPchResetCallbackPpi = { + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gPchResetCallbackPpiGuid, + &mPchResetCallbackPpi +}; + +static EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = { + (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEndOfPeiSignalPpiGuid, + EndOfPeiCallback +}; + +#define MINIMUM_TIMEOUT_AT_S3_EXIT 10 ///< seconds + +/** + Reads PCH registers to check if platform wakes from S3/S4 + + @param[in] None + + @retval TRUE if platfrom wakes from S3/S4 + @retval FALSE otherwise +**/ +UINT8 +IsWakeFromS3_S4 ( + VOID + ) +{ + UINT32 Address; + UINT16 SleepType; + + Address = MmioRead32 ( + MmPciAddress (0, + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_LPC, + PCI_FUNCTION_NUMBER_PCH_LPC, + R_PCH_LPC_ACPI_BASE) + ) & B_PCH_LPC_ACPI_BASE_BAR; + + if (IoRead16 (Address + R_PCH_ACPI_PM1_STS) & B_PCH_ACPI_PM1_STS_WAK) { + SleepType = IoRead16 (Address + R_PCH_ACPI_PM1_CNT) & B_PCH_ACPI_PM1_CNT_SLP_TYP; + if ((SleepType == V_PCH_ACPI_PM1_CNT_S3) || (SleepType == V_PCH_ACPI_PM1_CNT_S4)) { + return TRUE; + } + } + + return FALSE; +} + +/** + Initializes watchdog failure bits. + If there was an unexpected reset, enforces WDT expiration. + Stores initial WDT state in a HOB, it is useful in flows with S3/S4 resume. + Stops watchdog. + Installs watchdog PPI for other modules to use. + + @param[in] FfsHeader Pointer to Firmware File System file header. + @param[in] PeiServices General purpose services available to every PEIM. + + @retval EFI_SUCCESS When everything is OK +**/ +EFI_STATUS +WdtPeiEntryPoint ( + IN EFI_FFS_FILE_HEADER *FfsHeader, + IN EFI_PEI_SERVICES **PeiServices + ) +{ + UINT32 Readback; + EFI_STATUS Status; + UINT16 TimeoutValue; + UINT8 Active; + WDT_HOB *WdtHobPtr; + +#ifndef WDT_SUPPORT_ENABLED + /// + /// clear status bits and disable watchdog, then lock the register + /// + IoWrite32 (WdtGetAddress (), (B_PCH_OC_WDT_CTL_ICCSURV_STS | B_PCH_OC_WDT_CTL_NO_ICCSURV_STS)); + IoWrite32 (WdtGetAddress (), B_PCH_OC_WDT_CTL_LCK); +#endif + + Readback = IoRead32 (WdtGetAddress ()); + + DEBUG ((EFI_D_INFO, "(WDT) Readback = 0x%08x\n", Readback)); + /// + /// Write current Wdt settings to a HOB, they may be be needed in S3/S4 resume paths + /// + if (Readback & B_PCH_OC_WDT_CTL_EN) { + Active = 1; + TimeoutValue = (UINT16) ((Readback & B_PCH_OC_WDT_CTL_TOV_MASK) + 1); + } else { + Active = 0; + TimeoutValue = 0; + } + + Status = (*PeiServices)->CreateHob (PeiServices, EFI_HOB_TYPE_GUID_EXTENSION, sizeof (WDT_HOB), (VOID **) &WdtHobPtr); + if (EFI_ERROR (Status)) { + return Status; + } + + WdtHobPtr->Header.Name = mWdtHobGuid; + WdtHobPtr->Active = Active; + WdtHobPtr->TimeoutValue = TimeoutValue; + /// + /// If there was a WDT expiration, set Failure Status and clear timeout status bits + /// Timeout status bits are cleared by writing '1' + /// + if (Readback & (B_PCH_OC_WDT_CTL_ICCSURV_STS | B_PCH_OC_WDT_CTL_NO_ICCSURV_STS)) { + DEBUG ((EFI_D_ERROR, "(WDT) Expiration detected.\n", Readback)); + Readback |= B_PCH_OC_WDT_CTL_FAILURE_STS; + Readback |= (B_PCH_OC_WDT_CTL_ICCSURV_STS | B_PCH_OC_WDT_CTL_NO_ICCSURV_STS); + Readback &= ~(B_PCH_OC_WDT_CTL_UNXP_RESET_STS); + } else { + /// + /// If there was unexpected reset but no WDT expiration and no resume from S3/S4, + /// clear unexpected reset status and enforce expiration. This is to inform Firmware + /// which has no access to unexpected reset status bit, that something went wrong. + /// + if ((Readback & B_PCH_OC_WDT_CTL_UNXP_RESET_STS) && !IsWakeFromS3_S4 ()) { +#if defined EFI_DEBUG && !defined USE_WDT_IN_DEBUG_BIOS + DEBUG ((EFI_D_ERROR, "(WDT) Unexpected reset detected and ignored.\n")); + Readback &= ~(B_PCH_OC_WDT_CTL_FAILURE_STS | B_PCH_OC_WDT_CTL_UNXP_RESET_STS); + Readback |= (B_PCH_OC_WDT_CTL_ICCSURV_STS | B_PCH_OC_WDT_CTL_NO_ICCSURV_STS); +#else + DEBUG ((EFI_D_ERROR, "(WDT) Unexpected reset detected. Enforcing Wdt expiration.\n")); + WdtReloadAndStart (1); + while (1) { + /// + /// wait for reboot caused by WDT expiration + /// + } +#endif + } else { + /// + /// No WDT expiration and no unexpected reset - clear Failure status + /// + DEBUG ((EFI_D_INFO, "(WDT) Status OK.\n", Readback)); + Readback &= ~(B_PCH_OC_WDT_CTL_FAILURE_STS); + Readback |= (B_PCH_OC_WDT_CTL_ICCSURV_STS | B_PCH_OC_WDT_CTL_NO_ICCSURV_STS); + } + } + + IoWrite32 (WdtGetAddress (), Readback); + /// + /// register an event for EndOfPei. It will support Wdt in resume from S3. + /// + Status = (**PeiServices).NotifyPpi (PeiServices, &mNotifyList); + + Status = (**PeiServices).InstallPpi (PeiServices, &mInstallWdtPpi); + + Status = (**PeiServices).InstallPpi (PeiServices, &mInstallPchResetCallbackPpi); + + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** + Support for WDT in S3 resume. + If WDT was enabled during S0->S3 transition, this function will turn on WDT + just before waking OS. Timeout value will be overridden if it was too small. + + @param[in] PeiServices General purpose services available to every PEIM. + @param[in] NotifyDescriptor The notification structure this PEIM registered on install. + @param[in] Ppi The memory discovered PPI. Not used. + + @retval EFI_SUCCESS When everything is OK + @retval EFI_NOT_FOUND WdtHob is not found +**/ +EFI_STATUS +EndOfPeiCallback ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ) +{ + WDT_HOB *WdtHob; + EFI_STATUS Status; + EFI_BOOT_MODE BootMode; + + DEBUG ((EFI_D_INFO, "(WDT) EndOfPeiCallback\n")); + Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode); + ASSERT_EFI_ERROR (Status); + WdtHob = GetFirstGuidHob (&mWdtHobGuid); + if (WdtHob == NULL) { + return EFI_NOT_FOUND; + } + + DEBUG ((EFI_D_INFO, "(WDT) BootMode %d, Hob, active %d, ToV %d\n", BootMode, WdtHob->Active, WdtHob->TimeoutValue)); + + if (BootMode == BOOT_ON_S3_RESUME) { + if (WdtHob->Active == 1) { + if (WdtHob->TimeoutValue < MINIMUM_TIMEOUT_AT_S3_EXIT) { + WdtReloadAndStart (MINIMUM_TIMEOUT_AT_S3_EXIT); + } else { + WdtReloadAndStart (WdtHob->TimeoutValue); + } + } else { + WdtDisable (); + } + } + + return EFI_SUCCESS; +} + +/** + WDT call back function for Pch Reset. + + @param[in] PchResetType Pch Reset Types which includes PowerCycle, Globalreset. + + @retval EFI_SUCCESS The function completed successfully + @retval Others All other error conditions encountered result in an ASSERT. +**/ +EFI_STATUS +EFIAPI +WdtPchResetCallback ( + IN PCH_RESET_TYPE PchResetType + ) +{ + WdtAllowKnownReset (); + return EFI_SUCCESS; +} diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.cif b/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.cif new file mode 100644 index 0000000..24fbb35 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.cif @@ -0,0 +1,12 @@ +<component> + name = "WdtPei" + category = ModulePart + LocalRoot = "ReferenceCode\Chipset\LynxPoint\Wdt\Pei\" + RefName = "WdtPei" +[files] +"WdtPei.sdl" +"WdtPei.dxs" +"WdtPei.mak" +"WdtPei.c" +"WdtPeim.inf" +<endComponent> diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.dxs b/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.dxs new file mode 100644 index 0000000..9531248 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.dxs @@ -0,0 +1,31 @@ +/** @file + Dependencies file for Watchdog Timer functionality + +@copyright + Copyright (c) 2010 - 2012 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + This file contains a 'Sample Driver' and is licensed as such + under the terms of your license agreement with Intel or your + vendor. This file may be modified by the user, subject to + the additional terms of the license agreement + +**/ + + +#include "AutoGen.h" +#include "PeimDepex.h" + +#if defined (BUILD_WITH_GLUELIB) || defined (BUILD_WITH_EDKII_GLUE_LIB) +#include "EfiDepex.h" +#endif + +DEPENDENCY_START + TRUE +DEPENDENCY_END diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.mak b/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.mak new file mode 100644 index 0000000..1c2df94 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.mak @@ -0,0 +1,94 @@ +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* + +#************************************************************************* +# $Header: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/WdtPei/WdtPei.mak 2 2/24/12 2:32a Victortu $ +# +# $Revision: 2 $ +# +# $Date: 2/24/12 2:32a $ +#************************************************************************* +# Revision History +# ---------------- +# $Log: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/WdtPei/WdtPei.mak $ +# +# 2 2/24/12 2:32a Victortu +# Updated to support 4.6.5.3_IntelEDK_1117_Patch7_00. +# +# 1 2/08/12 9:33a Yurenlai +# Intel Lynx Point/SB eChipset initially releases. +# +#************************************************************************* +EDK : WdtPei +WdtPei : $(BUILD_DIR)\WdtPei.mak WdtPeiBin + +$(BUILD_DIR)\WdtPei.mak : $(WdtPei_DIR)\$(@B).cif $(BUILD_RULES) + $(CIF2MAK) $(WdtPei_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +WdtPei_INCLUDES=\ + $(EdkIIGlueLib_INCLUDES)\ + $(INTEL_PCH_INCLUDES)\ + $(WdtCommonLib_INCLUDES)\ + +WdtPei_DEFINES=$(MY_DEFINES)\ + /D"__EDKII_GLUE_MODULE_ENTRY_POINT__=WdtPeiEntryPoint"\ + /D __EDKII_GLUE_BASE_IO_LIB_INTRINSIC__ \ + /D __EDKII_GLUE_PEI_DEBUG_LIB_REPORT_STATUS_CODE__ \ + /D __EDKII_GLUE_PEI_REPORT_STATUS_CODE_LIB__ \ + /D __EDKII_GLUE_PEI_SERVICES_LIB__ \ + /D __EDKII_GLUE_BASE_PCI_LIB_PCI_EXPRESS__ \ + /D __EDKII_GLUE_PEI_HOB_LIB__ \ +!IF "$(WDT_SUPPORT_ENABLED)"=="1" + /D WDT_SUPPORT_ENABLED +!ENDIF + +WdtPei_LIBS =\ + $(IntelPchPpiLib_LIB)\ + $(EdkIIGlueBaseLib_LIB)\ + $(EdkIIGlueBaseLibIA32_LIB)\ + $(EdkIIGlueBaseIoLibIntrinsic_LIB)\ + $(EdkIIGluePeiDebugLibReportStatusCode_LIB)\ + $(EdkIIGluePeiReportStatusCodeLib_LIB)\ + $(EdkIIGluePeiServicesLib_LIB) \ + $(EdkIIGlueBasePciLibPciExpress_LIB)\ + $(WdtCommonPeiLib_LIB)\ + $(EDKFRAMEWORKPPILIB)\ + $(EdkIIGluePeiHobLib_LIB) + +WdtPeiBin : $(WdtPei_LIBS) + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS) \ + /f $(BUILD_DIR)\WdtPei.mak all \ + "MY_INCLUDES = $(WdtPei_INCLUDES)" \ + "MY_DEFINES = $(WdtPei_DEFINES)" \ + GUID=1D88C542-9DF7-424a-AA90-02B61F286938 \ + ENTRY_POINT=_ModuleEntryPoint \ + EDKIIModule=PEIM\ + TYPE=PEIM \ + DEPEX1=$(WdtPei_DIR)\WdtPei.dxs \ + DEPEX1_TYPE=EFI_SECTION_PEI_DEPEX \ + COMPRESS=0 + +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.sdl b/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.sdl new file mode 100644 index 0000000..59d48d3 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPei.sdl @@ -0,0 +1,78 @@ +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* + +#************************************************************************* +# $Header: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/WdtPei/WdtPei.sdl 1 2/08/12 9:33a Yurenlai $ +# +# $Revision: 1 $ +# +# $Date: 2/08/12 9:33a $ +#************************************************************************* +# Revision History +# ---------------- +# $Log: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/WdtPei/WdtPei.sdl $ +# +# 1 2/08/12 9:33a Yurenlai +# Intel Lynx Point/SB eChipset initially releases. +# +#************************************************************************* +TOKEN + Name = "WdtPei_SUPPORT" + Value = "1" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + TargetH = Yes + Master = Yes + Help = "Main switch to enable Wdt support in Project in PEI Phase" +End + +TOKEN + Name = "WDT_SUPPORT_ENABLED" + Value = "1" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + TargetH = Yes +End + +MODULE + Help = "Includes WdtPei.mak to Project" + File = "WdtPei.mak" +End + +PATH + Name = "WdtPei_DIR" + Help = "Wdt Support commands" +End + +ELINK + Name = "$(BUILD_DIR)\WdtPei.ffs" + Parent = "FV_BB" + Priority = 30 + InvokeOrder = AfterParent +End +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPeim.inf b/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPeim.inf new file mode 100644 index 0000000..2f574a9 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Pei/WdtPeim.inf @@ -0,0 +1,87 @@ +## @file +# Component description file for the watchdog driver. +# +#@copyright +# Copyright (c) 2010 - 2012 Intel Corporation. All rights reserved +# This software and associated documentation (if any) is furnished +# under a license and may only be used or copied in accordance +# with the terms of the license. Except as permitted by such +# license, no part of this software or documentation may be +# reproduced, stored in a retrieval system, or transmitted in any +# form or by any means without the express written consent of +# Intel Corporation. +# +# This file contains a 'Sample Driver' and is licensed as such +# under the terms of your license agreement with Intel or your +# vendor. This file may be modified by the user, subject to +# the additional terms of the license agreement +# + +[defines] +BASE_NAME = WdtPeim +FILE_GUID = 1D88C542-9DF7-424a-AA90-02B61F286938 +COMPONENT_TYPE = PE32_PEIM + +[sources.common] + WdtPei.c + ../Common/WdtCommon.h + ../Common/WdtCommon.c + +# +# Edk II Glue Driver Entry Point +# + EdkIIGluePeimEntryPoint.c + + +[includes.common] + . + ../Common + $(EDK_SOURCE)/Foundation/Efi + $(EDK_SOURCE)/Foundation/Include + $(EDK_SOURCE)/Foundation/Efi/Include + $(EDK_SOURCE)/Foundation/Framework/Include + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT) + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT)/Include + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT)/Include/Library +# +# EDK II Glue Library utilizes some standard headers from EDK +# + $(EFI_SOURCE) + $(EDK_SOURCE)/Foundation + $(EDK_SOURCE)/Foundation/Framework + $(EDK_SOURCE)/Foundation/Include/IndustryStandard + $(EDK_SOURCE)/Foundation/Core/Dxe + $(EDK_SOURCE)/Foundation/Include/Pei + $(EDK_SOURCE)/Foundation/Library/Dxe/Include + $(EDK_SOURCE)/Foundation/Library/EdkIIGlueLib/Include + +[libraries.common] + $(PROJECT_PCH_FAMILY)PpiLib + EdkIIGlueBaseIoLibIntrinsic + EdkIIGluePeiDebugLibReportStatusCode + EdkIIGluePeiReportStatusCodeLib + EdkIIGluePeiServicesLib + EdkIIGlueBasePciLibPciExpress + PchPlatformLib + EdkFrameworkPpiLib + EdkIIGluePeiHobLib + EdkPpiLib + +[nmake.common] + IMAGE_ENTRY_POINT = _ModuleEntryPoint + DPX_SOURCE = WdtPei.dxs +# +# Module Entry Point +# + C_FLAGS = $(C_FLAGS) -D __EDKII_GLUE_MODULE_ENTRY_POINT__=WdtPeiEntryPoint + C_FLAGS = $(C_FLAGS) -D __EDKII_GLUE_BASE_IO_LIB_INTRINSIC__ \ + -D __EDKII_GLUE_PEI_DEBUG_LIB_REPORT_STATUS_CODE__ \ + -D __EDKII_GLUE_PEI_REPORT_STATUS_CODE_LIB__ \ + -D __EDKII_GLUE_PEI_SERVICES_LIB__ \ + -D __EDKII_GLUE_BASE_PCI_LIB_PCI_EXPRESS__ \ + -D __EDKII_GLUE_PEI_HOB_LIB__ + +# +# Undefine the flag below to disable and lock WDT +# + C_FLAGS = $(C_FLAGS) -DWDT_SUPPORT_ENABLED diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Wdt.cif b/ReferenceCode/Chipset/LynxPoint/Wdt/Wdt.cif new file mode 100644 index 0000000..26d94c7 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Wdt.cif @@ -0,0 +1,12 @@ +<component> + name = "Wdt" + category = ModulePart + LocalRoot = "ReferenceCode\Chipset\LynxPoint\Wdt\" + RefName = "Wdt" +[files] +"Wdt.sdl" +[parts] +"WdtCommonLib" +"WdtDxe" +"WdtPei" +<endComponent> diff --git a/ReferenceCode/Chipset/LynxPoint/Wdt/Wdt.sdl b/ReferenceCode/Chipset/LynxPoint/Wdt/Wdt.sdl new file mode 100644 index 0000000..33ff822 --- /dev/null +++ b/ReferenceCode/Chipset/LynxPoint/Wdt/Wdt.sdl @@ -0,0 +1,73 @@ +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* + +#************************************************************************* +# $Header: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/Wdt.sdl 1 2/08/12 9:31a Yurenlai $ +# +# $Revision: 1 $ +# +# $Date: 2/08/12 9:31a $ +#************************************************************************* +# Revision History +# ---------------- +# $Log: /Alaska/BIN/Chipset/Intel/SouthBridge/LynxPoint/Intel Pch SB Refcode/Wdt/Wdt.sdl $ +# +# 1 2/08/12 9:31a Yurenlai +# Intel Lynx Point/SB eChipset initially releases. +# +#************************************************************************* +TOKEN + Name = "WDT_SUPPORT" + Value = "1" + Help = "Main switch to enable WDT support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + TargetH = Yes + Master = Yes +End + +PATH + Name = "WDT_DIR" +End + +ELINK + Name = "WDT_INCLUDES" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "/I$(WDT_DIR)" + Parent = "WDT_INCLUDES" + InvokeOrder = AfterParent +End + +ELINK + Name = "/I$(WDT_DIR)\Protocol" + Parent = "WDT_INCLUDES" + InvokeOrder = AfterParent +End +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* |