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