2008-04-09 09:07:50 +02:00
|
|
|
/** @file
|
2008-11-17 05:33:19 +01:00
|
|
|
Implementation of Watchdog Timer Architectural Protocol using UEFI APIs.
|
2008-04-09 09:07:50 +02:00
|
|
|
|
|
|
|
Copyright (c) 2006 - 2008, Intel Corporation
|
2007-06-28 10:36:46 +02:00
|
|
|
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.
|
|
|
|
|
2008-04-09 09:07:50 +02:00
|
|
|
**/
|
2007-06-28 10:36:46 +02:00
|
|
|
|
2008-02-20 03:09:13 +01:00
|
|
|
#include "WatchdogTimer.h"
|
2007-06-28 10:36:46 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Handle for the Watchdog Timer Architectural Protocol instance produced by this driver
|
|
|
|
//
|
2008-11-17 05:33:19 +01:00
|
|
|
EFI_HANDLE mWatchdogTimerHandle = NULL;
|
2007-06-28 10:36:46 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// The Watchdog Timer Architectural Protocol instance produced by this driver
|
|
|
|
//
|
|
|
|
EFI_WATCHDOG_TIMER_ARCH_PROTOCOL mWatchdogTimer = {
|
|
|
|
WatchdogTimerDriverRegisterHandler,
|
|
|
|
WatchdogTimerDriverSetTimerPeriod,
|
|
|
|
WatchdogTimerDriverGetTimerPeriod
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2008-11-17 05:33:19 +01:00
|
|
|
// The watchdog timer period in 100 ns units
|
2007-06-28 10:36:46 +02:00
|
|
|
//
|
2008-11-17 05:33:19 +01:00
|
|
|
UINT64 mWatchdogTimerPeriod = 0;
|
2007-06-28 10:36:46 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// The notification function to call if the watchdig timer fires
|
|
|
|
//
|
2008-11-17 05:33:19 +01:00
|
|
|
EFI_WATCHDOG_TIMER_NOTIFY mWatchdogTimerNotifyFunction = NULL;
|
2007-06-28 10:36:46 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// The one-shot timer event that is armed when the watchdog timer is enabled
|
|
|
|
//
|
2008-11-17 05:33:19 +01:00
|
|
|
EFI_EVENT mWatchdogTimerEvent;
|
2007-06-28 10:36:46 +02:00
|
|
|
|
2008-07-11 08:49:09 +02:00
|
|
|
|
|
|
|
/**
|
2008-11-17 05:33:19 +01:00
|
|
|
Notification function that is called if the watchdog timer is fired.
|
2008-07-11 08:49:09 +02:00
|
|
|
|
2008-11-17 05:33:19 +01:00
|
|
|
Notification function for the one-shot timer event that was signaled
|
|
|
|
when the watchdog timer expired. If a handler has been registered with
|
|
|
|
the Watchdog Timer Architectural Protocol, then that handler is called
|
|
|
|
passing in the time period that has passed that cause the watchdog timer
|
|
|
|
to fire. Then, a call to the Runtime Service ResetSystem() is made to
|
|
|
|
reset the platform.
|
2008-07-11 08:49:09 +02:00
|
|
|
|
2008-11-17 05:33:19 +01:00
|
|
|
@param Timer The one-shot timer event that was signaled when the
|
|
|
|
watchdog timer expired.
|
2008-07-11 08:49:09 +02:00
|
|
|
@param Context The context that was registered when the event Timer was created.
|
|
|
|
|
|
|
|
**/
|
2007-06-28 10:36:46 +02:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
WatchdogTimerDriverExpires (
|
|
|
|
IN EFI_EVENT Timer,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
2007-07-03 20:34:24 +02:00
|
|
|
REPORT_STATUS_CODE (EFI_ERROR_CODE | EFI_ERROR_MINOR, PcdGet32 (PcdStatusCodeValueEfiWatchDogTimerExpired));
|
2007-06-28 10:36:46 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// If a notification function has been registered, then call it
|
|
|
|
//
|
|
|
|
if (mWatchdogTimerNotifyFunction != NULL) {
|
|
|
|
mWatchdogTimerNotifyFunction (mWatchdogTimerPeriod);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Reset the platform
|
|
|
|
//
|
|
|
|
gRT->ResetSystem (EfiResetCold, EFI_TIMEOUT, 0, NULL);
|
|
|
|
}
|
|
|
|
|
2007-07-03 20:34:24 +02:00
|
|
|
|
2008-07-11 08:49:09 +02:00
|
|
|
/**
|
2008-11-17 05:33:19 +01:00
|
|
|
Registers a handler that is to be invoked when the watchdog timer fires.
|
|
|
|
|
2007-06-28 10:36:46 +02:00
|
|
|
This function registers a handler that is to be invoked when the watchdog
|
|
|
|
timer fires. By default, the EFI_WATCHDOG_TIMER protocol will call the
|
|
|
|
Runtime Service ResetSystem() when the watchdog timer fires. If a
|
|
|
|
NotifyFunction is registered, then the NotifyFunction will be called before
|
|
|
|
the Runtime Service ResetSystem() is called. If NotifyFunction is NULL, then
|
|
|
|
the watchdog handler is unregistered. If a watchdog handler is registered,
|
|
|
|
then EFI_SUCCESS is returned. If an attempt is made to register a handler
|
|
|
|
when a handler is already registered, then EFI_ALREADY_STARTED is returned.
|
|
|
|
If an attempt is made to uninstall a handler when a handler is not installed,
|
|
|
|
then return EFI_INVALID_PARAMETER.
|
|
|
|
|
2008-07-11 08:49:09 +02:00
|
|
|
@param This The EFI_WATCHDOG_TIMER_ARCH_PROTOCOL instance.
|
|
|
|
@param NotifyFunction The function to call when the watchdog timer fires. If this
|
|
|
|
is NULL, then the handler will be unregistered.
|
2007-06-28 10:36:46 +02:00
|
|
|
|
2008-11-17 05:33:19 +01:00
|
|
|
@retval EFI_SUCCESS The watchdog timer handler was registered or unregistered.
|
|
|
|
@retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and a handler is already registered.
|
|
|
|
@retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not previously registered.
|
2007-06-28 10:36:46 +02:00
|
|
|
|
2008-07-11 08:49:09 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
WatchdogTimerDriverRegisterHandler (
|
|
|
|
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
|
|
|
IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
|
|
|
|
)
|
2007-06-28 10:36:46 +02:00
|
|
|
{
|
2008-11-17 05:33:19 +01:00
|
|
|
//
|
|
|
|
// If NotifyFunction is NULL, and a handler was not previously registered,
|
|
|
|
// return EFI_INVALID_PARAMETER.
|
|
|
|
//
|
2007-06-28 10:36:46 +02:00
|
|
|
if (NotifyFunction == NULL && mWatchdogTimerNotifyFunction == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2008-11-17 05:33:19 +01:00
|
|
|
//
|
|
|
|
// If NotifyFunction is not NULL, and a handler is already registered,
|
|
|
|
// return EFI_ALREADY_STARTED.
|
|
|
|
//
|
2007-06-28 10:36:46 +02:00
|
|
|
if (NotifyFunction != NULL && mWatchdogTimerNotifyFunction != NULL) {
|
|
|
|
return EFI_ALREADY_STARTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
mWatchdogTimerNotifyFunction = NotifyFunction;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-07-11 08:49:09 +02:00
|
|
|
/**
|
2008-11-17 05:33:19 +01:00
|
|
|
Sets the amount of time in the future to fire the watchdog timer.
|
|
|
|
|
2007-06-28 10:36:46 +02:00
|
|
|
This function sets the amount of time to wait before firing the watchdog
|
2008-11-17 05:33:19 +01:00
|
|
|
timer to TimerPeriod 100 ns units. If TimerPeriod is 0, then the watchdog
|
2007-06-28 10:36:46 +02:00
|
|
|
timer is disabled.
|
|
|
|
|
2008-07-11 08:49:09 +02:00
|
|
|
@param This The EFI_WATCHDOG_TIMER_ARCH_PROTOCOL instance.
|
2008-11-17 05:33:19 +01:00
|
|
|
@param TimerPeriod The amount of time in 100 ns units to wait before the watchdog
|
2008-07-11 08:49:09 +02:00
|
|
|
timer is fired. If TimerPeriod is zero, then the watchdog
|
|
|
|
timer is disabled.
|
2007-06-28 10:36:46 +02:00
|
|
|
|
2008-11-17 05:33:19 +01:00
|
|
|
@retval EFI_SUCCESS The watchdog timer has been programmed to fire in Time
|
|
|
|
100 ns units.
|
|
|
|
@retval EFI_DEVICE_ERROR A watchdog timer could not be programmed due to a device
|
2008-07-11 08:49:09 +02:00
|
|
|
error.
|
2007-06-28 10:36:46 +02:00
|
|
|
|
2008-07-11 08:49:09 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
WatchdogTimerDriverSetTimerPeriod (
|
|
|
|
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
|
|
|
IN UINT64 TimerPeriod
|
|
|
|
)
|
2007-06-28 10:36:46 +02:00
|
|
|
{
|
|
|
|
mWatchdogTimerPeriod = TimerPeriod;
|
|
|
|
|
|
|
|
return gBS->SetTimer (
|
|
|
|
mWatchdogTimerEvent,
|
|
|
|
(mWatchdogTimerPeriod == 0) ? TimerCancel : TimerRelative,
|
|
|
|
mWatchdogTimerPeriod
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-07-11 08:49:09 +02:00
|
|
|
/**
|
2008-11-17 05:33:19 +01:00
|
|
|
Retrieves the amount of time in 100 ns units that the system will wait before firing the watchdog timer.
|
|
|
|
|
2007-06-28 10:36:46 +02:00
|
|
|
This function retrieves the amount of time the system will wait before firing
|
|
|
|
the watchdog timer. This period is returned in TimerPeriod, and EFI_SUCCESS
|
|
|
|
is returned. If TimerPeriod is NULL, then EFI_INVALID_PARAMETER is returned.
|
|
|
|
|
2008-07-11 08:49:09 +02:00
|
|
|
@param This The EFI_WATCHDOG_TIMER_ARCH_PROTOCOL instance.
|
2008-11-17 05:33:19 +01:00
|
|
|
@param TimerPeriod A pointer to the amount of time in 100 ns units that the system
|
2008-07-11 08:49:09 +02:00
|
|
|
will wait before the watchdog timer is fired. If TimerPeriod of
|
|
|
|
zero is returned, then the watchdog timer is disabled.
|
2007-06-28 10:36:46 +02:00
|
|
|
|
2008-11-17 05:33:19 +01:00
|
|
|
@retval EFI_SUCCESS The amount of time that the system will wait before
|
2008-07-11 08:49:09 +02:00
|
|
|
firing the watchdog timer was returned in TimerPeriod.
|
2008-11-17 05:33:19 +01:00
|
|
|
@retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
|
2007-06-28 10:36:46 +02:00
|
|
|
|
2008-07-11 08:49:09 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
WatchdogTimerDriverGetTimerPeriod (
|
|
|
|
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
|
|
|
IN UINT64 *TimerPeriod
|
|
|
|
)
|
2007-06-28 10:36:46 +02:00
|
|
|
{
|
|
|
|
if (TimerPeriod == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
*TimerPeriod = mWatchdogTimerPeriod;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-07-11 08:49:09 +02:00
|
|
|
/**
|
2008-11-17 05:33:19 +01:00
|
|
|
Entry point of the Watchdog Timer Architectural Protocol driver.
|
2008-07-11 08:49:09 +02:00
|
|
|
|
2008-11-17 05:33:19 +01:00
|
|
|
@param ImageHandle The image handle of this driver.
|
|
|
|
@param SystemTable The pointer of EFI_SYSTEM_TABLE.
|
2008-07-11 08:49:09 +02:00
|
|
|
|
2008-11-17 05:33:19 +01:00
|
|
|
@retval EFI_SUCCESS Watchdog Timer Architectural Protocol successfully installed.
|
2008-07-11 08:49:09 +02:00
|
|
|
|
|
|
|
**/
|
2007-06-28 10:36:46 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
WatchdogTimerDriverInitialize (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
//
|
2008-11-17 05:33:19 +01:00
|
|
|
// Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet.
|
2007-06-28 10:36:46 +02:00
|
|
|
//
|
|
|
|
ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);
|
|
|
|
|
|
|
|
//
|
2008-11-17 05:33:19 +01:00
|
|
|
// Create the timer event to implement a simple watchdog timer
|
2007-06-28 10:36:46 +02:00
|
|
|
//
|
|
|
|
Status = gBS->CreateEvent (
|
|
|
|
EVT_TIMER | EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
WatchdogTimerDriverExpires,
|
|
|
|
NULL,
|
|
|
|
&mWatchdogTimerEvent
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Install the Watchdog Timer Arch Protocol onto a new handle
|
|
|
|
//
|
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
|
|
|
&mWatchdogTimerHandle,
|
|
|
|
&gEfiWatchdogTimerArchProtocolGuid,
|
|
|
|
&mWatchdogTimer,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2008-11-17 05:33:19 +01:00
|
|
|
return EFI_SUCCESS;
|
2007-06-28 10:36:46 +02:00
|
|
|
}
|