SetWatchdogTimer.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou/** @file
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou UEFI Miscellaneous boot Services SetWatchdogTimer service implementation
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou
c5e0ece05310eec3c585344bcff875855f3f507aCathy ZhouCopyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
c5e0ece05310eec3c585344bcff875855f3f507aCathy ZhouThis program and the accompanying materials
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhouare licensed and made available under the terms and conditions of the BSD License
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhouwhich accompanies this distribution. The full text of the license may be found at
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhouhttp://opensource.org/licenses/bsd-license.php
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou
c5e0ece05310eec3c585344bcff875855f3f507aCathy ZhouTHE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
c5e0ece05310eec3c585344bcff875855f3f507aCathy ZhouWITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou**/
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou#include "DxeMain.h"
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou#define WATCHDOG_TIMER_CALIBRATE_PER_SECOND 10000000
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou/**
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou Sets the system's watchdog timer.
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou @param Timeout The number of seconds to set the watchdog timer to.
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou A value of zero disables the timer.
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou @param WatchdogCode The numeric code to log on a watchdog timer timeout
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou event. The firmware reserves codes 0x0000 to 0xFFFF.
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou Loaders and operating systems may use other timeout
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou codes.
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou @param DataSize The size, in bytes, of WatchdogData.
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou @param WatchdogData A data buffer that includes a Null-terminated Unicode
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou string, optionally followed by additional binary data.
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou The string is a description that the call may use to
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou further indicate the reason to be logged with a
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou watchdog event.
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou @return EFI_SUCCESS Timeout has been set
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou @return EFI_NOT_AVAILABLE_YET WatchdogTimer is not available yet
c5e0ece05310eec3c585344bcff875855f3f507aCathy Zhou @return EFI_UNSUPPORTED System does not have a timer (currently not used)
@return EFI_DEVICE_ERROR Could not complete due to hardware error
**/
EFI_STATUS
EFIAPI
CoreSetWatchdogTimer (
IN UINTN Timeout,
IN UINT64 WatchdogCode,
IN UINTN DataSize,
IN CHAR16 *WatchdogData OPTIONAL
)
{
EFI_STATUS Status;
//
// Check our architectural protocol
//
if (gWatchdogTimer == NULL) {
return EFI_NOT_AVAILABLE_YET;
}
//
// Attempt to set the timeout
//
Status = gWatchdogTimer->SetTimerPeriod (gWatchdogTimer, MultU64x32 (Timeout, WATCHDOG_TIMER_CALIBRATE_PER_SECOND));
//
// Check for errors
//
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}