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