]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.c
Add comments and DoxyGen format for these files.
[mirror_edk2.git] / MdeModulePkg / Universal / WatchdogTimerDxe / WatchdogTimer.c
CommitLineData
504214c4
LG
1/** @file\r
2 \r
3 Generic watchdog timer services implemenetation using UEFI APIs and\r
4 install watchdog timer architecture protocol.\r
5 \r
6Copyright (c) 2006 - 2008, Intel Corporation\r
de4c8a30 7All rights reserved. This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
504214c4 15**/\r
de4c8a30 16\r
4dd60a17 17#include "WatchdogTimer.h"\r
de4c8a30 18\r
19//\r
20// Handle for the Watchdog Timer Architectural Protocol instance produced by this driver\r
21//\r
22EFI_HANDLE mWatchdogTimerHandle = NULL;\r
23\r
24//\r
25// The Watchdog Timer Architectural Protocol instance produced by this driver\r
26//\r
27EFI_WATCHDOG_TIMER_ARCH_PROTOCOL mWatchdogTimer = {\r
28 WatchdogTimerDriverRegisterHandler,\r
29 WatchdogTimerDriverSetTimerPeriod,\r
30 WatchdogTimerDriverGetTimerPeriod\r
31};\r
32\r
33//\r
34// The watchdog timer period in 100 nS units\r
35//\r
36UINT64 mWatchdogTimerPeriod = 0;\r
37\r
38//\r
39// The notification function to call if the watchdig timer fires\r
40//\r
41EFI_WATCHDOG_TIMER_NOTIFY mWatchdogTimerNotifyFunction = NULL;\r
42\r
43//\r
44// The one-shot timer event that is armed when the watchdog timer is enabled\r
45//\r
46EFI_EVENT mWatchdogTimerEvent;\r
47\r
48//\r
49// Worker Functions\r
50//\r
51STATIC\r
52VOID\r
53EFIAPI\r
54WatchdogTimerDriverExpires (\r
55 IN EFI_EVENT Timer,\r
56 IN VOID *Context\r
57 )\r
58/*++\r
59\r
60 Routine Description:\r
61\r
62 Notification function that is called if the watchdog timer is fired. If a\r
63 handler has been registered with the Watchdog Timer Architectural Protocol,\r
64 then that handler is called passing in the time period that has passed that\r
65 cause the watchdog timer to fire. Then, a call to the Runtime Service\r
66 ResetSystem() is made to reset the platform.\r
67\r
68 Arguments:\r
69\r
70 Timer - The one-shot timer event that was signaled when the watchdog timer\r
71 expired.\r
72\r
73 Context - The context that was registered when the event Timer was created.\r
74\r
75 Returns:\r
76\r
77 None.\r
78\r
79--*/\r
80{\r
ba237732 81 REPORT_STATUS_CODE (EFI_ERROR_CODE | EFI_ERROR_MINOR, PcdGet32 (PcdStatusCodeValueEfiWatchDogTimerExpired));\r
de4c8a30 82\r
83 //\r
84 // If a notification function has been registered, then call it\r
85 //\r
86 if (mWatchdogTimerNotifyFunction != NULL) {\r
87 mWatchdogTimerNotifyFunction (mWatchdogTimerPeriod);\r
88 }\r
89 //\r
90 // Reset the platform\r
91 //\r
92 gRT->ResetSystem (EfiResetCold, EFI_TIMEOUT, 0, NULL);\r
93}\r
94\r
ba237732 95\r
de4c8a30 96EFI_STATUS\r
97EFIAPI\r
98WatchdogTimerDriverRegisterHandler (\r
99 IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,\r
100 IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction\r
101 )\r
102/*++\r
103\r
104Routine Description:\r
105\r
106 This function registers a handler that is to be invoked when the watchdog\r
107 timer fires. By default, the EFI_WATCHDOG_TIMER protocol will call the\r
108 Runtime Service ResetSystem() when the watchdog timer fires. If a\r
109 NotifyFunction is registered, then the NotifyFunction will be called before\r
110 the Runtime Service ResetSystem() is called. If NotifyFunction is NULL, then\r
111 the watchdog handler is unregistered. If a watchdog handler is registered,\r
112 then EFI_SUCCESS is returned. If an attempt is made to register a handler\r
113 when a handler is already registered, then EFI_ALREADY_STARTED is returned.\r
114 If an attempt is made to uninstall a handler when a handler is not installed,\r
115 then return EFI_INVALID_PARAMETER.\r
116\r
117Arguments:\r
118\r
119 This - The EFI_WATCHDOG_TIMER_ARCH_PROTOCOL instance.\r
120\r
121 NotifyFunction - The function to call when the watchdog timer fires. If this\r
122 is NULL, then the handler will be unregistered.\r
123\r
124Returns:\r
125\r
126 EFI_SUCCESS - The watchdog timer handler was registered or\r
127 unregistered.\r
128\r
129 EFI_ALREADY_STARTED - NotifyFunction is not NULL, and a handler is already\r
130 registered.\r
131\r
132 EFI_INVALID_PARAMETER - NotifyFunction is NULL, and a handler was not\r
133 previously registered.\r
134\r
135--*/\r
136{\r
137 if (NotifyFunction == NULL && mWatchdogTimerNotifyFunction == NULL) {\r
138 return EFI_INVALID_PARAMETER;\r
139 }\r
140\r
141 if (NotifyFunction != NULL && mWatchdogTimerNotifyFunction != NULL) {\r
142 return EFI_ALREADY_STARTED;\r
143 }\r
144\r
145 mWatchdogTimerNotifyFunction = NotifyFunction;\r
146\r
147 return EFI_SUCCESS;\r
148}\r
149\r
150EFI_STATUS\r
151EFIAPI\r
152WatchdogTimerDriverSetTimerPeriod (\r
153 IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,\r
154 IN UINT64 TimerPeriod\r
155 )\r
156/*++\r
157\r
158Routine Description:\r
159\r
160 This function sets the amount of time to wait before firing the watchdog\r
161 timer to TimerPeriod 100 nS units. If TimerPeriod is 0, then the watchdog\r
162 timer is disabled.\r
163\r
164Arguments:\r
165\r
166 This - The EFI_WATCHDOG_TIMER_ARCH_PROTOCOL instance.\r
167\r
168 TimerPeriod - The amount of time in 100 nS units to wait before the watchdog\r
169 timer is fired. If TimerPeriod is zero, then the watchdog\r
170 timer is disabled.\r
171\r
172Returns:\r
173\r
174 EFI_SUCCESS - The watchdog timer has been programmed to fire in Time\r
175 100 nS units.\r
176\r
177 EFI_DEVICE_ERROR - A watchdog timer could not be programmed due to a device\r
178 error.\r
179\r
180--*/\r
181{\r
182 mWatchdogTimerPeriod = TimerPeriod;\r
183\r
184 return gBS->SetTimer (\r
185 mWatchdogTimerEvent,\r
186 (mWatchdogTimerPeriod == 0) ? TimerCancel : TimerRelative,\r
187 mWatchdogTimerPeriod\r
188 );\r
189}\r
190\r
191EFI_STATUS\r
192EFIAPI\r
193WatchdogTimerDriverGetTimerPeriod (\r
194 IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,\r
195 IN UINT64 *TimerPeriod\r
196 )\r
197/*++\r
198\r
199Routine Description:\r
200\r
201 This function retrieves the amount of time the system will wait before firing\r
202 the watchdog timer. This period is returned in TimerPeriod, and EFI_SUCCESS\r
203 is returned. If TimerPeriod is NULL, then EFI_INVALID_PARAMETER is returned.\r
204\r
205Arguments:\r
206\r
207 This - The EFI_WATCHDOG_TIMER_ARCH_PROTOCOL instance.\r
208\r
209 TimerPeriod - A pointer to the amount of time in 100 nS units that the system\r
210 will wait before the watchdog timer is fired. If TimerPeriod of\r
211 zero is returned, then the watchdog timer is disabled.\r
212\r
213Returns:\r
214\r
215 EFI_SUCCESS - The amount of time that the system will wait before\r
216 firing the watchdog timer was returned in TimerPeriod.\r
217\r
218 EFI_INVALID_PARAMETER - TimerPeriod is NULL.\r
219\r
220--*/\r
221{\r
222 if (TimerPeriod == NULL) {\r
223 return EFI_INVALID_PARAMETER;\r
224 }\r
225\r
226 *TimerPeriod = mWatchdogTimerPeriod;\r
227\r
228 return EFI_SUCCESS;\r
229}\r
230\r
231EFI_STATUS\r
232EFIAPI\r
233WatchdogTimerDriverInitialize (\r
234 IN EFI_HANDLE ImageHandle,\r
235 IN EFI_SYSTEM_TABLE *SystemTable\r
236 )\r
237/*++\r
238\r
239Routine Description:\r
240\r
241 Initialize the Watchdog Timer Architectural Protocol driver\r
242\r
243Arguments:\r
244\r
245 ImageHandle - ImageHandle of the loaded driver\r
246\r
247 SystemTable - Pointer to the System Table\r
248\r
249Returns:\r
250\r
251 EFI_SUCCESS - Timer Architectural Protocol created\r
252\r
253 EFI_OUT_OF_RESOURCES - Not enough resources available to initialize driver.\r
254\r
255 EFI_DEVICE_ERROR - A device error occured attempting to initialize the driver.\r
256\r
257--*/\r
258{\r
259 EFI_STATUS Status;\r
260\r
de4c8a30 261 //\r
262 // Make sure the Watchdog Timer Architectural Protocol is not already installed in the system\r
263 //\r
264 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);\r
265\r
266 //\r
267 // Create the timer event used to implement a simple watchdog timer\r
268 //\r
269 Status = gBS->CreateEvent (\r
270 EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
271 TPL_NOTIFY,\r
272 WatchdogTimerDriverExpires,\r
273 NULL,\r
274 &mWatchdogTimerEvent\r
275 );\r
276 ASSERT_EFI_ERROR (Status);\r
277\r
278 //\r
279 // Install the Watchdog Timer Arch Protocol onto a new handle\r
280 //\r
281 Status = gBS->InstallMultipleProtocolInterfaces (\r
282 &mWatchdogTimerHandle,\r
283 &gEfiWatchdogTimerArchProtocolGuid,\r
284 &mWatchdogTimer,\r
285 NULL\r
286 );\r
287 ASSERT_EFI_ERROR (Status);\r
288\r
de4c8a30 289 return Status;\r
290}\r