TianoCore EDK2 master
Loading...
Searching...
No Matches
WatchdogTimer.c
Go to the documentation of this file.
1
9#include "WatchdogTimer.h"
10
11//
12// Handle for the Watchdog Timer Architectural Protocol instance produced by this driver
13//
14EFI_HANDLE mWatchdogTimerHandle = NULL;
15
16//
17// The Watchdog Timer Architectural Protocol instance produced by this driver
18//
23};
24
25//
26// The watchdog timer period in 100 ns units
27//
28UINT64 mWatchdogTimerPeriod = 0;
29
30//
31// The notification function to call if the watchdig timer fires
32//
33EFI_WATCHDOG_TIMER_NOTIFY mWatchdogTimerNotifyFunction = NULL;
34
35//
36// The one-shot timer event that is armed when the watchdog timer is enabled
37//
38EFI_EVENT mWatchdogTimerEvent;
39
55VOID
56EFIAPI
58 IN EFI_EVENT Timer,
59 IN VOID *Context
60 )
61{
62 REPORT_STATUS_CODE (EFI_ERROR_CODE | EFI_ERROR_MINOR, (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_TIMER_EXPIRED));
63
64 //
65 // If a notification function has been registered, then call it
66 //
67 if (mWatchdogTimerNotifyFunction != NULL) {
68 mWatchdogTimerNotifyFunction (mWatchdogTimerPeriod);
69 }
70
71 DEBUG ((DEBUG_ERROR, "Watchdog Timer resetting system\n"));
72
73 //
74 // Reset the platform
75 //
76 gRT->ResetSystem (EfiResetCold, EFI_TIMEOUT, 0, NULL);
77}
78
103EFIAPI
107 )
108{
109 //
110 // If NotifyFunction is NULL, and a handler was not previously registered,
111 // return EFI_INVALID_PARAMETER.
112 //
113 if ((NotifyFunction == NULL) && (mWatchdogTimerNotifyFunction == NULL)) {
114 return EFI_INVALID_PARAMETER;
115 }
116
117 //
118 // If NotifyFunction is not NULL, and a handler is already registered,
119 // return EFI_ALREADY_STARTED.
120 //
121 if ((NotifyFunction != NULL) && (mWatchdogTimerNotifyFunction != NULL)) {
122 return EFI_ALREADY_STARTED;
123 }
124
125 mWatchdogTimerNotifyFunction = NotifyFunction;
126
127 return EFI_SUCCESS;
128}
129
149EFIAPI
152 IN UINT64 TimerPeriod
153 )
154{
155 mWatchdogTimerPeriod = TimerPeriod;
156
157 return gBS->SetTimer (
158 mWatchdogTimerEvent,
159 (mWatchdogTimerPeriod == 0) ? TimerCancel : TimerRelative,
160 mWatchdogTimerPeriod
161 );
162}
163
182EFIAPI
185 IN UINT64 *TimerPeriod
186 )
187{
188 if (TimerPeriod == NULL) {
189 return EFI_INVALID_PARAMETER;
190 }
191
192 *TimerPeriod = mWatchdogTimerPeriod;
193
194 return EFI_SUCCESS;
195}
196
207EFIAPI
209 IN EFI_HANDLE ImageHandle,
210 IN EFI_SYSTEM_TABLE *SystemTable
211 )
212{
213 EFI_STATUS Status;
214
215 //
216 // Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet.
217 //
218 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);
219
220 //
221 // Create the timer event to implement a simple watchdog timer
222 //
223 Status = gBS->CreateEvent (
224 EVT_TIMER | EVT_NOTIFY_SIGNAL,
225 TPL_NOTIFY,
227 NULL,
228 &mWatchdogTimerEvent
229 );
230 ASSERT_EFI_ERROR (Status);
231
232 //
233 // Install the Watchdog Timer Arch Protocol onto a new handle
234 //
235 Status = gBS->InstallMultipleProtocolInterfaces (
236 &mWatchdogTimerHandle,
237 &gEfiWatchdogTimerArchProtocolGuid,
239 NULL
240 );
241 ASSERT_EFI_ERROR (Status);
242
243 return EFI_SUCCESS;
244}
STATIC EFI_WATCHDOG_TIMER_ARCH_PROTOCOL mWatchdogTimer
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)
Definition: DebugLib.h:535
#define REPORT_STATUS_CODE(Type, Value)
VOID(EFIAPI * EFI_WATCHDOG_TIMER_NOTIFY)(IN UINT64 Time)
Definition: WatchdogTimer.h:37
#define EFI_ERROR_MINOR
Definition: PiStatusCode.h:58
VOID EFIAPI NotifyFunction(IN EFI_EVENT Event, IN VOID *Context)
Definition: ScsiBus.c:1492
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
@ EfiResetCold
@ TimerCancel
Definition: UefiSpec.h:531
@ TimerRelative
Definition: UefiSpec.h:539
VOID EFIAPI WatchdogTimerDriverExpires(IN EFI_EVENT Timer, IN VOID *Context)
Definition: WatchdogTimer.c:57
EFI_STATUS EFIAPI WatchdogTimerDriverSetTimerPeriod(IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, IN UINT64 TimerPeriod)
EFI_STATUS EFIAPI WatchdogTimerDriverRegisterHandler(IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction)
EFI_STATUS EFIAPI WatchdogTimerDriverInitialize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI WatchdogTimerDriverGetTimerPeriod(IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, IN UINT64 *TimerPeriod)