]>
Commit | Line | Data |
---|---|---|
6ae81428 | 1 | /**@file\r |
49993bed | 2 | \r |
8f2a5f80 HT |
3 | Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r |
4 | This program and the accompanying materials \r | |
49993bed | 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 | RealTimeClock.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | NT Emulation Architectural Protocol Driver as defined in Tiano\r | |
19 | \r | |
6ae81428 | 20 | **/\r |
49993bed | 21 | \r |
60c93673 | 22 | #include <Uefi.h>\r |
f2569572 A |
23 | #include <WinNtDxe.h>\r |
24 | #include <Protocol/RealTimeClock.h>\r | |
25 | #include <Library/DebugLib.h>\r | |
26 | #include <Library/UefiDriverEntryPoint.h>\r | |
27 | #include <Library/WinNtLib.h>\r | |
28 | #include <Library/UefiBootServicesTableLib.h>\r | |
49993bed | 29 | \r |
30 | \r | |
49993bed | 31 | BOOLEAN\r |
32 | DayValid (\r | |
33 | IN EFI_TIME *Time\r | |
34 | );\r | |
35 | \r | |
36 | BOOLEAN\r | |
37 | IsLeapYear (\r | |
38 | IN EFI_TIME *Time\r | |
39 | );\r | |
40 | \r | |
41 | EFI_STATUS\r | |
42 | RtcTimeFieldsValid (\r | |
43 | IN EFI_TIME *Time\r | |
44 | );\r | |
45 | \r | |
46 | EFI_STATUS\r | |
47 | EFIAPI\r | |
48 | InitializeRealTimeClock (\r | |
49 | IN EFI_HANDLE ImageHandle,\r | |
50 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
51 | );\r | |
52 | \r | |
49993bed | 53 | EFI_STATUS\r |
54 | EFIAPI\r | |
55 | WinNtGetTime (\r | |
56 | OUT EFI_TIME *Time,\r | |
57 | OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL\r | |
58 | )\r | |
59 | /*++\r | |
60 | \r | |
61 | Routine Description:\r | |
62 | Service routine for RealTimeClockInstance->GetTime \r | |
63 | \r | |
64 | Arguments:\r | |
65 | \r | |
66 | Time - A pointer to storage that will receive a snapshot of the current time.\r | |
67 | \r | |
68 | Capabilities - A pointer to storage that will receive the capabilities of the real time clock\r | |
69 | in the platform. This includes the real time clock's resolution and accuracy. \r | |
70 | All reported device capabilities are rounded up. This is an OPTIONAL argument.\r | |
71 | \r | |
72 | Returns:\r | |
73 | \r | |
74 | EFI_SUCEESS - The underlying GetSystemTime call occurred and returned\r | |
75 | Note that in the NT32 emulation, the GetSystemTime call has no return value\r | |
76 | thus you will always receive a EFI_SUCCESS on this.\r | |
77 | \r | |
78 | --*/\r | |
79 | // TODO: EFI_INVALID_PARAMETER - add return value to function comment\r | |
80 | {\r | |
81 | SYSTEMTIME SystemTime;\r | |
82 | TIME_ZONE_INFORMATION TimeZone;\r | |
83 | \r | |
84 | //\r | |
85 | // Check parameter for null pointer\r | |
86 | //\r | |
87 | if (Time == NULL) {\r | |
88 | return EFI_INVALID_PARAMETER;\r | |
89 | \r | |
90 | }\r | |
91 | \r | |
92 | gWinNt->GetLocalTime (&SystemTime);\r | |
93 | gWinNt->GetTimeZoneInformation (&TimeZone);\r | |
94 | \r | |
95 | Time->Year = (UINT16) SystemTime.wYear;\r | |
96 | Time->Month = (UINT8) SystemTime.wMonth;\r | |
97 | Time->Day = (UINT8) SystemTime.wDay;\r | |
98 | Time->Hour = (UINT8) SystemTime.wHour;\r | |
99 | Time->Minute = (UINT8) SystemTime.wMinute;\r | |
100 | Time->Second = (UINT8) SystemTime.wSecond;\r | |
101 | Time->Nanosecond = (UINT32) (SystemTime.wMilliseconds * 1000000);\r | |
102 | Time->TimeZone = (INT16) TimeZone.Bias;\r | |
103 | \r | |
104 | if (Capabilities != NULL) {\r | |
105 | Capabilities->Resolution = 1;\r | |
106 | Capabilities->Accuracy = 50000000;\r | |
107 | Capabilities->SetsToZero = FALSE;\r | |
108 | }\r | |
109 | \r | |
110 | Time->Daylight = 0;\r | |
111 | if (TimeZone.StandardDate.wMonth) {\r | |
112 | Time->Daylight = EFI_TIME_ADJUST_DAYLIGHT;\r | |
113 | }\r | |
114 | \r | |
115 | return EFI_SUCCESS;\r | |
116 | }\r | |
117 | \r | |
49993bed | 118 | EFI_STATUS\r |
119 | EFIAPI\r | |
120 | WinNtSetTime (\r | |
121 | IN EFI_TIME *Time\r | |
122 | )\r | |
123 | /*++\r | |
124 | \r | |
125 | Routine Description:\r | |
126 | Service routine for RealTimeClockInstance->SetTime \r | |
127 | \r | |
128 | Arguments:\r | |
129 | \r | |
130 | Time - A pointer to storage containing the time and date information to\r | |
131 | program into the real time clock.\r | |
132 | \r | |
133 | Returns:\r | |
134 | \r | |
135 | EFI_SUCEESS - The operation completed successfully.\r | |
136 | \r | |
137 | EFI_INVALID_PARAMETER - One of the fields in Time is out of range.\r | |
138 | \r | |
139 | EFI_DEVICE_ERROR - The operation could not be complete due to a device error.\r | |
140 | \r | |
141 | --*/\r | |
142 | // TODO: EFI_SUCCESS - add return value to function comment\r | |
143 | {\r | |
144 | TIME_ZONE_INFORMATION TimeZone;\r | |
145 | EFI_STATUS Status;\r | |
146 | SYSTEMTIME SystemTime;\r | |
147 | BOOL Flag;\r | |
148 | \r | |
149 | if (Time == NULL) {\r | |
150 | return EFI_INVALID_PARAMETER;\r | |
151 | }\r | |
152 | //\r | |
153 | // Make sure that the time fields are valid\r | |
154 | //\r | |
155 | Status = RtcTimeFieldsValid (Time);\r | |
156 | if (EFI_ERROR (Status)) {\r | |
157 | return Status;\r | |
158 | }\r | |
159 | //\r | |
160 | // Set Daylight savings time information and Time Zone\r | |
161 | //\r | |
162 | gWinNt->GetTimeZoneInformation (&TimeZone);\r | |
163 | TimeZone.StandardDate.wMonth = Time->Daylight;\r | |
164 | TimeZone.Bias = Time->TimeZone;\r | |
165 | gWinNt->SetTimeZoneInformation (&TimeZone);\r | |
166 | \r | |
167 | SystemTime.wYear = Time->Year;\r | |
168 | SystemTime.wMonth = Time->Month;\r | |
169 | SystemTime.wDay = Time->Day;\r | |
170 | SystemTime.wHour = Time->Hour;\r | |
171 | SystemTime.wMinute = Time->Minute;\r | |
172 | SystemTime.wSecond = Time->Second;\r | |
173 | SystemTime.wMilliseconds = (INT16) (Time->Nanosecond / 1000000);\r | |
174 | \r | |
175 | Flag = gWinNt->SetLocalTime (&SystemTime);\r | |
176 | \r | |
177 | if (!Flag) {\r | |
178 | return EFI_DEVICE_ERROR;\r | |
179 | } else {\r | |
180 | return EFI_SUCCESS;\r | |
181 | }\r | |
182 | }\r | |
183 | \r | |
49993bed | 184 | EFI_STATUS\r |
185 | EFIAPI\r | |
186 | WinNtGetWakeupTime (\r | |
187 | OUT BOOLEAN *Enabled,\r | |
188 | OUT BOOLEAN *Pending,\r | |
189 | OUT EFI_TIME *Time\r | |
190 | )\r | |
191 | /*++\r | |
192 | \r | |
193 | Routine Description:\r | |
194 | Service routine for RealTimeClockInstance->GetWakeupTime\r | |
195 | \r | |
196 | Arguments:\r | |
197 | This - Indicates the protocol instance structure.\r | |
198 | \r | |
199 | Enabled - Indicates if the alarm is currently enabled or disabled.\r | |
200 | \r | |
201 | Pending - Indicates if the alarm signal is pending and requires\r | |
202 | acknowledgement.\r | |
203 | \r | |
204 | Time - The current alarm setting.\r | |
205 | \r | |
206 | Returns:\r | |
207 | \r | |
208 | EFI_SUCEESS - The operation completed successfully.\r | |
209 | \r | |
210 | EFI_DEVICE_ERROR - The operation could not be complete due to a device error.\r | |
211 | \r | |
212 | EFI_UNSUPPORTED - The operation is not supported on this platform.\r | |
213 | \r | |
214 | --*/\r | |
215 | {\r | |
216 | return EFI_UNSUPPORTED;\r | |
217 | }\r | |
218 | \r | |
49993bed | 219 | EFI_STATUS\r |
220 | EFIAPI\r | |
221 | WinNtSetWakeupTime (\r | |
222 | IN BOOLEAN Enable,\r | |
223 | OUT EFI_TIME *Time\r | |
224 | )\r | |
225 | /*++\r | |
226 | \r | |
227 | Routine Description:\r | |
228 | Service routine for RealTimeClockInstance->SetWakeupTime\r | |
229 | \r | |
230 | Arguments:\r | |
231 | \r | |
232 | Enabled - Enable or disable the wakeup alarm.\r | |
233 | \r | |
234 | Time - If enable is TRUE, the time to set the wakup alarm for.\r | |
235 | If enable is FALSE, then this parameter is optional, and\r | |
236 | may be NULL.\r | |
237 | \r | |
238 | Returns:\r | |
239 | \r | |
240 | EFI_SUCEESS - The operation completed successfully.\r | |
241 | \r | |
242 | EFI_DEVICE_ERROR - The operation could not be complete due to a device error.\r | |
243 | \r | |
244 | EFI_INVALID_PARAMETER - A field in Time is out of range.\r | |
245 | \r | |
246 | EFI_UNSUPPORTED - The operation is not supported on this platform.\r | |
247 | \r | |
248 | --*/\r | |
249 | {\r | |
250 | return EFI_UNSUPPORTED;\r | |
251 | }\r | |
252 | \r | |
253 | EFI_STATUS\r | |
254 | EFIAPI\r | |
255 | InitializeRealTimeClock (\r | |
256 | IN EFI_HANDLE ImageHandle,\r | |
257 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
258 | )\r | |
259 | /*++\r | |
260 | \r | |
261 | Routine Description:\r | |
262 | Install Real Time Clock Protocol \r | |
263 | \r | |
264 | Arguments:\r | |
265 | (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r | |
266 | \r | |
267 | Returns:\r | |
268 | \r | |
269 | EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table\r | |
270 | \r | |
271 | --*/\r | |
272 | // TODO: ImageHandle - add argument and description to function comment\r | |
273 | // TODO: SystemTable - add argument and description to function comment\r | |
274 | {\r | |
275 | EFI_STATUS Status;\r | |
276 | EFI_HANDLE Handle;\r | |
277 | \r | |
278 | \r | |
279 | SystemTable->RuntimeServices->GetTime = WinNtGetTime;\r | |
280 | SystemTable->RuntimeServices->SetTime = WinNtSetTime;\r | |
281 | SystemTable->RuntimeServices->GetWakeupTime = WinNtGetWakeupTime;\r | |
282 | SystemTable->RuntimeServices->SetWakeupTime = WinNtSetWakeupTime;\r | |
283 | \r | |
284 | Handle = NULL;\r | |
285 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
286 | &Handle,\r | |
287 | &gEfiRealTimeClockArchProtocolGuid,\r | |
288 | NULL,\r | |
289 | NULL\r | |
290 | );\r | |
291 | return Status;\r | |
292 | }\r | |
293 | \r | |
294 | EFI_STATUS\r | |
295 | RtcTimeFieldsValid (\r | |
296 | IN EFI_TIME *Time\r | |
297 | )\r | |
298 | /*++\r | |
299 | \r | |
300 | Routine Description:\r | |
301 | \r | |
302 | Arguments:\r | |
303 | \r | |
304 | Returns: \r | |
305 | --*/\r | |
306 | // TODO: Time - add argument and description to function comment\r | |
307 | // TODO: EFI_INVALID_PARAMETER - add return value to function comment\r | |
308 | // TODO: EFI_SUCCESS - add return value to function comment\r | |
309 | {\r | |
310 | if (Time->Year < 1998 ||\r | |
311 | Time->Year > 2099 ||\r | |
312 | Time->Month < 1 ||\r | |
313 | Time->Month > 12 ||\r | |
314 | (!DayValid (Time)) ||\r | |
315 | Time->Hour > 23 ||\r | |
316 | Time->Minute > 59 ||\r | |
317 | Time->Second > 59 ||\r | |
318 | Time->Nanosecond > 999999999 ||\r | |
319 | (!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||\r | |
320 | (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))\r | |
321 | ) {\r | |
322 | return EFI_INVALID_PARAMETER;\r | |
323 | }\r | |
324 | \r | |
325 | return EFI_SUCCESS;\r | |
326 | }\r | |
327 | \r | |
328 | BOOLEAN\r | |
329 | DayValid (\r | |
330 | IN EFI_TIME *Time\r | |
331 | )\r | |
332 | /*++\r | |
333 | \r | |
334 | Routine Description:\r | |
335 | \r | |
336 | TODO: Add function description\r | |
337 | \r | |
338 | Arguments:\r | |
339 | \r | |
340 | Time - TODO: add argument description\r | |
341 | \r | |
342 | Returns:\r | |
343 | \r | |
344 | TODO: add return values\r | |
345 | \r | |
346 | --*/\r | |
347 | {\r | |
348 | \r | |
349 | INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r | |
350 | \r | |
351 | if (Time->Day < 1 ||\r | |
352 | Time->Day > DayOfMonth[Time->Month - 1] ||\r | |
353 | (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))\r | |
354 | ) {\r | |
355 | return FALSE;\r | |
356 | }\r | |
357 | \r | |
358 | return TRUE;\r | |
359 | }\r | |
360 | \r | |
361 | BOOLEAN\r | |
362 | IsLeapYear (\r | |
363 | IN EFI_TIME *Time\r | |
364 | )\r | |
365 | /*++\r | |
366 | \r | |
367 | Routine Description:\r | |
368 | \r | |
369 | TODO: Add function description\r | |
370 | \r | |
371 | Arguments:\r | |
372 | \r | |
373 | Time - TODO: add argument description\r | |
374 | \r | |
375 | Returns:\r | |
376 | \r | |
377 | TODO: add return values\r | |
378 | \r | |
379 | --*/\r | |
380 | {\r | |
381 | if (Time->Year % 4 == 0) {\r | |
382 | if (Time->Year % 100 == 0) {\r | |
383 | if (Time->Year % 400 == 0) {\r | |
384 | return TRUE;\r | |
385 | } else {\r | |
386 | return FALSE;\r | |
387 | }\r | |
388 | } else {\r | |
389 | return TRUE;\r | |
390 | }\r | |
391 | } else {\r | |
392 | return FALSE;\r | |
393 | }\r | |
394 | }\r |