3 Copyright (c) 2004 - 2008, 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
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.
18 UNIX Emulation Architectural Protocol Driver as defined in Tiano
23 #include <Protocol/RealTimeClock.h>
25 #include <Library/BaseLib.h>
26 #include <Library/DebugLib.h>
27 #include <Library/UefiLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/UnixLib.h>
30 #include <Library/MemoryAllocationLib.h>
31 #include <Library/UefiBootServicesTableLib.h>
50 InitializeRealTimeClock (
51 IN EFI_HANDLE ImageHandle
,
52 IN EFI_SYSTEM_TABLE
*SystemTable
60 OUT EFI_TIME_CAPABILITIES
* Capabilities OPTIONAL
65 Service routine for RealTimeClockInstance->GetTime
69 Time - A pointer to storage that will receive a snapshot of the current time.
71 Capabilities - A pointer to storage that will receive the capabilities of the real time clock
72 in the platform. This includes the real time clock's resolution and accuracy.
73 All reported device capabilities are rounded up. This is an OPTIONAL argument.
77 EFI_SUCEESS - The underlying GetSystemTime call occurred and returned
78 Note that in the NT32 emulation, the GetSystemTime call has no return value
79 thus you will always receive a EFI_SUCCESS on this.
82 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
86 // Check parameter for null pointer
89 return EFI_INVALID_PARAMETER
;
93 gUnix
->GetLocalTime (Time
);
95 if (Capabilities
!= NULL
) {
96 Capabilities
->Resolution
= 1;
97 Capabilities
->Accuracy
= 50000000;
98 Capabilities
->SetsToZero
= FALSE
;
113 Service routine for RealTimeClockInstance->SetTime
117 Time - A pointer to storage containing the time and date information to
118 program into the real time clock.
122 EFI_SUCEESS - The operation completed successfully.
124 EFI_INVALID_PARAMETER - One of the fields in Time is out of range.
126 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
129 // TODO: EFI_SUCCESS - add return value to function comment
134 return EFI_INVALID_PARAMETER
;
137 // Make sure that the time fields are valid
139 Status
= RtcTimeFieldsValid (Time
);
140 if (EFI_ERROR (Status
)) {
143 return EFI_UNSUPPORTED
;
150 OUT BOOLEAN
*Enabled
,
151 OUT BOOLEAN
*Pending
,
157 Service routine for RealTimeClockInstance->GetWakeupTime
160 This - Indicates the protocol instance structure.
162 Enabled - Indicates if the alarm is currently enabled or disabled.
164 Pending - Indicates if the alarm signal is pending and requires
167 Time - The current alarm setting.
171 EFI_SUCEESS - The operation completed successfully.
173 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
175 EFI_UNSUPPORTED - The operation is not supported on this platform.
179 return EFI_UNSUPPORTED
;
192 Service routine for RealTimeClockInstance->SetWakeupTime
196 Enabled - Enable or disable the wakeup alarm.
198 Time - If enable is TRUE, the time to set the wakup alarm for.
199 If enable is FALSE, then this parameter is optional, and
204 EFI_SUCEESS - The operation completed successfully.
206 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
208 EFI_INVALID_PARAMETER - A field in Time is out of range.
210 EFI_UNSUPPORTED - The operation is not supported on this platform.
214 return EFI_UNSUPPORTED
;
219 InitializeRealTimeClock (
220 IN EFI_HANDLE ImageHandle
,
221 IN EFI_SYSTEM_TABLE
*SystemTable
226 Install Real Time Clock Protocol
229 ImageHandle - Image Handle
230 SystemTable - Pointer to system table
234 EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table
241 SystemTable
->RuntimeServices
->GetTime
= UnixGetTime
;
242 SystemTable
->RuntimeServices
->SetTime
= UnixSetTime
;
243 SystemTable
->RuntimeServices
->GetWakeupTime
= UnixGetWakeupTime
;
244 SystemTable
->RuntimeServices
->SetWakeupTime
= UnixSetWakeupTime
;
247 Status
= gBS
->InstallMultipleProtocolInterfaces (
249 &gEfiRealTimeClockArchProtocolGuid
,
268 // TODO: Time - add argument and description to function comment
269 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
270 // TODO: EFI_SUCCESS - add return value to function comment
272 if (Time
->Year
< 1998 ||
276 (!DayValid (Time
)) ||
280 Time
->Nanosecond
> 999999999 ||
281 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
282 (Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
)))
284 return EFI_INVALID_PARAMETER
;
298 TODO: Add function description
302 Time - TODO: add argument description
306 TODO: add return values
311 static const INTN DayOfMonth
[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
314 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
315 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
331 TODO: Add function description
335 Time - TODO: add argument description
339 TODO: add return values
343 if (Time
->Year
% 4 == 0) {
344 if (Time
->Year
% 100 == 0) {
345 if (Time
->Year
% 400 == 0) {