3 Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
4 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
59 OUT EFI_TIME_CAPABILITIES
* Capabilities OPTIONAL
64 Service routine for RealTimeClockInstance->GetTime
68 Time - A pointer to storage that will receive a snapshot of the current time.
70 Capabilities - A pointer to storage that will receive the capabilities of the real time clock
71 in the platform. This includes the real time clock's resolution and accuracy.
72 All reported device capabilities are rounded up. This is an OPTIONAL argument.
76 EFI_SUCEESS - The underlying GetSystemTime call occurred and returned
77 Note that in the NT32 emulation, the GetSystemTime call has no return value
78 thus you will always receive a EFI_SUCCESS on this.
81 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
85 // Check parameter for null pointer
88 return EFI_INVALID_PARAMETER
;
92 gUnix
->GetLocalTime (Time
);
94 if (Capabilities
!= NULL
) {
95 Capabilities
->Resolution
= 1;
96 Capabilities
->Accuracy
= 50000000;
97 Capabilities
->SetsToZero
= FALSE
;
111 Service routine for RealTimeClockInstance->SetTime
115 Time - A pointer to storage containing the time and date information to
116 program into the real time clock.
120 EFI_SUCEESS - The operation completed successfully.
122 EFI_INVALID_PARAMETER - One of the fields in Time is out of range.
124 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
127 // TODO: EFI_SUCCESS - add return value to function comment
132 return EFI_INVALID_PARAMETER
;
135 // Make sure that the time fields are valid
137 Status
= RtcTimeFieldsValid (Time
);
138 if (EFI_ERROR (Status
)) {
141 return EFI_UNSUPPORTED
;
147 OUT BOOLEAN
*Enabled
,
148 OUT BOOLEAN
*Pending
,
154 Service routine for RealTimeClockInstance->GetWakeupTime
157 This - Indicates the protocol instance structure.
159 Enabled - Indicates if the alarm is currently enabled or disabled.
161 Pending - Indicates if the alarm signal is pending and requires
164 Time - The current alarm setting.
168 EFI_SUCEESS - The operation completed successfully.
170 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
172 EFI_UNSUPPORTED - The operation is not supported on this platform.
176 return EFI_UNSUPPORTED
;
188 Service routine for RealTimeClockInstance->SetWakeupTime
192 Enabled - Enable or disable the wakeup alarm.
194 Time - If enable is TRUE, the time to set the wakup alarm for.
195 If enable is FALSE, then this parameter is optional, and
200 EFI_SUCEESS - The operation completed successfully.
202 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
204 EFI_INVALID_PARAMETER - A field in Time is out of range.
206 EFI_UNSUPPORTED - The operation is not supported on this platform.
210 return EFI_UNSUPPORTED
;
215 InitializeRealTimeClock (
216 IN EFI_HANDLE ImageHandle
,
217 IN EFI_SYSTEM_TABLE
*SystemTable
222 Install Real Time Clock Protocol
225 ImageHandle - Image Handle
226 SystemTable - Pointer to system table
230 EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table
237 SystemTable
->RuntimeServices
->GetTime
= UnixGetTime
;
238 SystemTable
->RuntimeServices
->SetTime
= UnixSetTime
;
239 SystemTable
->RuntimeServices
->GetWakeupTime
= UnixGetWakeupTime
;
240 SystemTable
->RuntimeServices
->SetWakeupTime
= UnixSetWakeupTime
;
243 Status
= gBS
->InstallMultipleProtocolInterfaces (
245 &gEfiRealTimeClockArchProtocolGuid
,
264 // TODO: Time - add argument and description to function comment
265 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
266 // TODO: EFI_SUCCESS - add return value to function comment
268 if (Time
->Year
< 1998 ||
272 (!DayValid (Time
)) ||
276 Time
->Nanosecond
> 999999999 ||
277 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
278 (Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
)))
280 return EFI_INVALID_PARAMETER
;
294 TODO: Add function description
298 Time - TODO: add argument description
302 TODO: add return values
307 STATIC
const INTN DayOfMonth
[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
310 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
311 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
327 TODO: Add function description
331 Time - TODO: add argument description
335 TODO: add return values
339 if (Time
->Year
% 4 == 0) {
340 if (Time
->Year
% 100 == 0) {
341 if (Time
->Year
% 400 == 0) {