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