2 Implementation of Watchdog Timer Architectural Protocol using UEFI APIs.
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "WatchdogTimer.h"
18 // Handle for the Watchdog Timer Architectural Protocol instance produced by this driver
20 EFI_HANDLE mWatchdogTimerHandle
= NULL
;
23 // The Watchdog Timer Architectural Protocol instance produced by this driver
25 EFI_WATCHDOG_TIMER_ARCH_PROTOCOL mWatchdogTimer
= {
26 WatchdogTimerDriverRegisterHandler
,
27 WatchdogTimerDriverSetTimerPeriod
,
28 WatchdogTimerDriverGetTimerPeriod
32 // The watchdog timer period in 100 ns units
34 UINT64 mWatchdogTimerPeriod
= 0;
37 // The notification function to call if the watchdig timer fires
39 EFI_WATCHDOG_TIMER_NOTIFY mWatchdogTimerNotifyFunction
= NULL
;
42 // The one-shot timer event that is armed when the watchdog timer is enabled
44 EFI_EVENT mWatchdogTimerEvent
;
48 Notification function that is called if the watchdog timer is fired.
50 Notification function for the one-shot timer event that was signaled
51 when the watchdog timer expired. If a handler has been registered with
52 the Watchdog Timer Architectural Protocol, then that handler is called
53 passing in the time period that has passed that cause the watchdog timer
54 to fire. Then, a call to the Runtime Service ResetSystem() is made to
57 @param Timer The one-shot timer event that was signaled when the
58 watchdog timer expired.
59 @param Context The context that was registered when the event Timer was created.
64 WatchdogTimerDriverExpires (
69 REPORT_STATUS_CODE (EFI_ERROR_CODE
| EFI_ERROR_MINOR
, (EFI_COMPUTING_UNIT_HOST_PROCESSOR
| EFI_CU_HP_EC_TIMER_EXPIRED
));
72 // If a notification function has been registered, then call it
74 if (mWatchdogTimerNotifyFunction
!= NULL
) {
75 mWatchdogTimerNotifyFunction (mWatchdogTimerPeriod
);
78 DEBUG ((EFI_D_ERROR
, "Watchdog Timer reseting system\n"));
83 gRT
->ResetSystem (EfiResetCold
, EFI_TIMEOUT
, 0, NULL
);
88 Registers a handler that is to be invoked when the watchdog timer fires.
90 This function registers a handler that is to be invoked when the watchdog
91 timer fires. By default, the EFI_WATCHDOG_TIMER protocol will call the
92 Runtime Service ResetSystem() when the watchdog timer fires. If a
93 NotifyFunction is registered, then the NotifyFunction will be called before
94 the Runtime Service ResetSystem() is called. If NotifyFunction is NULL, then
95 the watchdog handler is unregistered. If a watchdog handler is registered,
96 then EFI_SUCCESS is returned. If an attempt is made to register a handler
97 when a handler is already registered, then EFI_ALREADY_STARTED is returned.
98 If an attempt is made to uninstall a handler when a handler is not installed,
99 then return EFI_INVALID_PARAMETER.
101 @param This The EFI_WATCHDOG_TIMER_ARCH_PROTOCOL instance.
102 @param NotifyFunction The function to call when the watchdog timer fires. If this
103 is NULL, then the handler will be unregistered.
105 @retval EFI_SUCCESS The watchdog timer handler was registered or unregistered.
106 @retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and a handler is already registered.
107 @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not previously registered.
112 WatchdogTimerDriverRegisterHandler (
113 IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL
*This
,
114 IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
118 // If NotifyFunction is NULL, and a handler was not previously registered,
119 // return EFI_INVALID_PARAMETER.
121 if (NotifyFunction
== NULL
&& mWatchdogTimerNotifyFunction
== NULL
) {
122 return EFI_INVALID_PARAMETER
;
125 // If NotifyFunction is not NULL, and a handler is already registered,
126 // return EFI_ALREADY_STARTED.
128 if (NotifyFunction
!= NULL
&& mWatchdogTimerNotifyFunction
!= NULL
) {
129 return EFI_ALREADY_STARTED
;
132 mWatchdogTimerNotifyFunction
= NotifyFunction
;
138 Sets the amount of time in the future to fire the watchdog timer.
140 This function sets the amount of time to wait before firing the watchdog
141 timer to TimerPeriod 100 ns units. If TimerPeriod is 0, then the watchdog
144 @param This The EFI_WATCHDOG_TIMER_ARCH_PROTOCOL instance.
145 @param TimerPeriod The amount of time in 100 ns units to wait before the watchdog
146 timer is fired. If TimerPeriod is zero, then the watchdog
149 @retval EFI_SUCCESS The watchdog timer has been programmed to fire in Time
151 @retval EFI_DEVICE_ERROR A watchdog timer could not be programmed due to a device
157 WatchdogTimerDriverSetTimerPeriod (
158 IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL
*This
,
159 IN UINT64 TimerPeriod
162 mWatchdogTimerPeriod
= TimerPeriod
;
164 return gBS
->SetTimer (
166 (mWatchdogTimerPeriod
== 0) ? TimerCancel
: TimerRelative
,
172 Retrieves the amount of time in 100 ns units that the system will wait before firing the watchdog timer.
174 This function retrieves the amount of time the system will wait before firing
175 the watchdog timer. This period is returned in TimerPeriod, and EFI_SUCCESS
176 is returned. If TimerPeriod is NULL, then EFI_INVALID_PARAMETER is returned.
178 @param This The EFI_WATCHDOG_TIMER_ARCH_PROTOCOL instance.
179 @param TimerPeriod A pointer to the amount of time in 100 ns units that the system
180 will wait before the watchdog timer is fired. If TimerPeriod of
181 zero is returned, then the watchdog timer is disabled.
183 @retval EFI_SUCCESS The amount of time that the system will wait before
184 firing the watchdog timer was returned in TimerPeriod.
185 @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
190 WatchdogTimerDriverGetTimerPeriod (
191 IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL
*This
,
192 IN UINT64
*TimerPeriod
195 if (TimerPeriod
== NULL
) {
196 return EFI_INVALID_PARAMETER
;
199 *TimerPeriod
= mWatchdogTimerPeriod
;
205 Entry point of the Watchdog Timer Architectural Protocol driver.
207 @param ImageHandle The image handle of this driver.
208 @param SystemTable The pointer of EFI_SYSTEM_TABLE.
210 @retval EFI_SUCCESS Watchdog Timer Architectural Protocol successfully installed.
215 WatchdogTimerDriverInitialize (
216 IN EFI_HANDLE ImageHandle
,
217 IN EFI_SYSTEM_TABLE
*SystemTable
223 // Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet.
225 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiWatchdogTimerArchProtocolGuid
);
228 // Create the timer event to implement a simple watchdog timer
230 Status
= gBS
->CreateEvent (
231 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
233 WatchdogTimerDriverExpires
,
237 ASSERT_EFI_ERROR (Status
);
240 // Install the Watchdog Timer Arch Protocol onto a new handle
242 Status
= gBS
->InstallMultipleProtocolInterfaces (
243 &mWatchdogTimerHandle
,
244 &gEfiWatchdogTimerArchProtocolGuid
,
248 ASSERT_EFI_ERROR (Status
);