]> git.proxmox.com Git - mirror_edk2.git/blame - EdkUnixPkg/Dxe/UnixThunk/Chipset/RealTimeClock/RealTimeClock.c
Change many windows references to unix.
[mirror_edk2.git] / EdkUnixPkg / Dxe / UnixThunk / Chipset / RealTimeClock / RealTimeClock.c
CommitLineData
c9093a06 1/*++\r
2\r
3Copyright (c) 2004 - 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 RealTimeClock.c\r
15\r
16Abstract:\r
17\r
377fc2ae 18 UNIX Emulation Architectural Protocol Driver as defined in Tiano\r
c9093a06 19\r
20--*/\r
21\r
22BOOLEAN\r
23DayValid (\r
24 IN EFI_TIME *Time\r
25 );\r
26\r
27BOOLEAN\r
28IsLeapYear (\r
29 IN EFI_TIME *Time\r
30 );\r
31\r
32EFI_STATUS\r
33RtcTimeFieldsValid (\r
34 IN EFI_TIME *Time\r
35 );\r
36\r
37EFI_STATUS\r
38EFIAPI\r
39InitializeRealTimeClock (\r
40 IN EFI_HANDLE ImageHandle,\r
41 IN EFI_SYSTEM_TABLE *SystemTable\r
42 );\r
43\r
44STATIC\r
45EFI_STATUS\r
46EFIAPI\r
47UnixGetTime (\r
48 OUT EFI_TIME * Time,\r
49 OUT EFI_TIME_CAPABILITIES * Capabilities OPTIONAL\r
50 )\r
51/*++\r
52\r
53Routine Description:\r
54 Service routine for RealTimeClockInstance->GetTime \r
55\r
56Arguments:\r
57\r
58 Time - A pointer to storage that will receive a snapshot of the current time.\r
59\r
60 Capabilities - A pointer to storage that will receive the capabilities of the real time clock\r
61 in the platform. This includes the real time clock's resolution and accuracy. \r
62 All reported device capabilities are rounded up. This is an OPTIONAL argument.\r
63\r
64Returns:\r
65\r
66 EFI_SUCEESS - The underlying GetSystemTime call occurred and returned\r
67 Note that in the NT32 emulation, the GetSystemTime call has no return value\r
68 thus you will always receive a EFI_SUCCESS on this.\r
69\r
70--*/\r
71// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
72{\r
73\r
74 //\r
75 // Check parameter for null pointer\r
76 //\r
77 if (Time == NULL) {\r
78 return EFI_INVALID_PARAMETER;\r
79\r
80 }\r
81\r
82 gUnix->GetLocalTime (Time);
83\r
84 if (Capabilities != NULL) {\r
85 Capabilities->Resolution = 1;\r
86 Capabilities->Accuracy = 50000000;\r
87 Capabilities->SetsToZero = FALSE;\r
88 }\r
89\r
90 return EFI_SUCCESS;\r
91}\r
92\r
93STATIC\r
94EFI_STATUS\r
95EFIAPI\r
96UnixSetTime (\r
97 IN EFI_TIME *Time\r
98 )\r
99/*++\r
100\r
101Routine Description:\r
102 Service routine for RealTimeClockInstance->SetTime \r
103\r
104Arguments:\r
105\r
106 Time - A pointer to storage containing the time and date information to\r
107 program into the real time clock.\r
108\r
109Returns:\r
110\r
111 EFI_SUCEESS - The operation completed successfully.\r
112 \r
113 EFI_INVALID_PARAMETER - One of the fields in Time is out of range.\r
114\r
115 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.\r
116\r
117--*/\r
118// TODO: EFI_SUCCESS - add return value to function comment\r
119{\r
120 EFI_STATUS Status;\r
121\r
122 if (Time == NULL) {\r
123 return EFI_INVALID_PARAMETER;\r
124 }\r
125 //\r
126 // Make sure that the time fields are valid\r
127 //\r
128 Status = RtcTimeFieldsValid (Time);\r
129 if (EFI_ERROR (Status)) {\r
130 return Status;\r
131 }\r
132 return EFI_UNSUPPORTED;\r
133}\r
134\r
135STATIC\r
136EFI_STATUS\r
137EFIAPI\r
138UnixGetWakeupTime (\r
139 OUT BOOLEAN *Enabled,\r
140 OUT BOOLEAN *Pending,\r
141 OUT EFI_TIME *Time\r
142 )\r
143/*++\r
144\r
145Routine Description:\r
146 Service routine for RealTimeClockInstance->GetWakeupTime\r
147\r
148Arguments:\r
149 This - Indicates the protocol instance structure.\r
150\r
151 Enabled - Indicates if the alarm is currently enabled or disabled.\r
152\r
153 Pending - Indicates if the alarm signal is pending and requires\r
154 acknowledgement.\r
155\r
156 Time - The current alarm setting.\r
157\r
158Returns:\r
159\r
160 EFI_SUCEESS - The operation completed successfully.\r
161 \r
162 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.\r
163\r
164 EFI_UNSUPPORTED - The operation is not supported on this platform.\r
165\r
166--*/\r
167{\r
168 return EFI_UNSUPPORTED;\r
169}\r
170\r
171STATIC\r
172EFI_STATUS\r
173EFIAPI\r
174UnixSetWakeupTime (\r
175 IN BOOLEAN Enable,\r
176 OUT EFI_TIME *Time\r
177 )\r
178/*++\r
179\r
180Routine Description:\r
181 Service routine for RealTimeClockInstance->SetWakeupTime\r
182\r
183Arguments:\r
184\r
185 Enabled - Enable or disable the wakeup alarm.\r
186\r
187 Time - If enable is TRUE, the time to set the wakup alarm for.\r
188 If enable is FALSE, then this parameter is optional, and\r
189 may be NULL.\r
190\r
191Returns:\r
192\r
193 EFI_SUCEESS - The operation completed successfully.\r
194 \r
195 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.\r
196\r
197 EFI_INVALID_PARAMETER - A field in Time is out of range.\r
198\r
199 EFI_UNSUPPORTED - The operation is not supported on this platform.\r
200\r
201--*/\r
202{\r
203 return EFI_UNSUPPORTED;\r
204}\r
205\r
206EFI_STATUS\r
207EFIAPI\r
208InitializeRealTimeClock (\r
209 IN EFI_HANDLE ImageHandle,\r
210 IN EFI_SYSTEM_TABLE *SystemTable\r
211 )\r
212/*++\r
213\r
214Routine Description:\r
215 Install Real Time Clock Protocol \r
216\r
217Arguments:\r
218 ImageHandle - Image Handle\r
219 SystemTable - Pointer to system table\r
220\r
221Returns:\r
222\r
223 EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table\r
224\r
225--*/\r
226{\r
227 EFI_STATUS Status;\r
228 EFI_HANDLE Handle;\r
229\r
230 SystemTable->RuntimeServices->GetTime = UnixGetTime;\r
231 SystemTable->RuntimeServices->SetTime = UnixSetTime;\r
232 SystemTable->RuntimeServices->GetWakeupTime = UnixGetWakeupTime;\r
233 SystemTable->RuntimeServices->SetWakeupTime = UnixSetWakeupTime;\r
234\r
235 Handle = NULL;\r
236 Status = gBS->InstallMultipleProtocolInterfaces (\r
237 &Handle,\r
238 &gEfiRealTimeClockArchProtocolGuid,\r
239 NULL,\r
240 NULL\r
241 );\r
242 return Status;\r
243}\r
244\r
245EFI_STATUS\r
246RtcTimeFieldsValid (\r
247 IN EFI_TIME *Time\r
248 )\r
249/*++\r
250\r
251Routine Description:\r
252\r
253 Arguments:\r
254 \r
255 Returns: \r
256--*/\r
257// TODO: Time - add argument and description to function comment\r
258// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
259// TODO: EFI_SUCCESS - add return value to function comment\r
260{\r
261 if (Time->Year < 1998 ||\r
262 Time->Year > 2099 ||\r
263 Time->Month < 1 ||\r
264 Time->Month > 12 ||\r
265 (!DayValid (Time)) ||\r
266 Time->Hour > 23 ||\r
267 Time->Minute > 59 ||\r
268 Time->Second > 59 ||\r
269 Time->Nanosecond > 999999999 ||\r
270 (!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||\r
271 (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))\r
272 ) {\r
273 return EFI_INVALID_PARAMETER;\r
274 }\r
275\r
276 return EFI_SUCCESS;\r
277}\r
278\r
279BOOLEAN\r
280DayValid (\r
281 IN EFI_TIME *Time\r
282 )\r
283/*++\r
284\r
285Routine Description:\r
286\r
287 TODO: Add function description\r
288\r
289Arguments:\r
290\r
291 Time - TODO: add argument description\r
292\r
293Returns:\r
294\r
295 TODO: add return values\r
296\r
297--*/\r
298{\r
299\r
300 static const INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r
301\r
302 if (Time->Day < 1 ||\r
303 Time->Day > DayOfMonth[Time->Month - 1] ||\r
304 (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))\r
305 ) {\r
306 return FALSE;\r
307 }\r
308\r
309 return TRUE;\r
310}\r
311\r
312BOOLEAN\r
313IsLeapYear (\r
314 IN EFI_TIME *Time\r
315 )\r
316/*++\r
317\r
318Routine Description:\r
319\r
320 TODO: Add function description\r
321\r
322Arguments:\r
323\r
324 Time - TODO: add argument description\r
325\r
326Returns:\r
327\r
328 TODO: add return values\r
329\r
330--*/\r
331{\r
332 if (Time->Year % 4 == 0) {\r
333 if (Time->Year % 100 == 0) {\r
334 if (Time->Year % 400 == 0) {\r
335 return TRUE;\r
336 } else {\r
337 return FALSE;\r
338 }\r
339 } else {\r
340 return TRUE;\r
341 }\r
342 } else {\r
343 return FALSE;\r
344 }\r
345}\r