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