3 Copyright (c) 2006, 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 NT Emulation Architectural Protocol Driver as defined in Tiano
24 #include <Protocol/RealTimeClock.h>
25 #include <Library/DebugLib.h>
26 #include <Library/UefiDriverEntryPoint.h>
27 #include <Library/WinNtLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
48 InitializeRealTimeClock (
49 IN EFI_HANDLE ImageHandle
,
50 IN EFI_SYSTEM_TABLE
*SystemTable
57 OUT EFI_TIME_CAPABILITIES
*Capabilities OPTIONAL
62 Service routine for RealTimeClockInstance->GetTime
66 Time - A pointer to storage that will receive a snapshot of the current time.
68 Capabilities - A pointer to storage that will receive the capabilities of the real time clock
69 in the platform. This includes the real time clock's resolution and accuracy.
70 All reported device capabilities are rounded up. This is an OPTIONAL argument.
74 EFI_SUCEESS - The underlying GetSystemTime call occurred and returned
75 Note that in the NT32 emulation, the GetSystemTime call has no return value
76 thus you will always receive a EFI_SUCCESS on this.
79 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
81 SYSTEMTIME SystemTime
;
82 TIME_ZONE_INFORMATION TimeZone
;
85 // Check parameter for null pointer
88 return EFI_INVALID_PARAMETER
;
92 gWinNt
->GetLocalTime (&SystemTime
);
93 gWinNt
->GetTimeZoneInformation (&TimeZone
);
95 Time
->Year
= (UINT16
) SystemTime
.wYear
;
96 Time
->Month
= (UINT8
) SystemTime
.wMonth
;
97 Time
->Day
= (UINT8
) SystemTime
.wDay
;
98 Time
->Hour
= (UINT8
) SystemTime
.wHour
;
99 Time
->Minute
= (UINT8
) SystemTime
.wMinute
;
100 Time
->Second
= (UINT8
) SystemTime
.wSecond
;
101 Time
->Nanosecond
= (UINT32
) (SystemTime
.wMilliseconds
* 1000000);
102 Time
->TimeZone
= (INT16
) TimeZone
.Bias
;
104 if (Capabilities
!= NULL
) {
105 Capabilities
->Resolution
= 1;
106 Capabilities
->Accuracy
= 50000000;
107 Capabilities
->SetsToZero
= FALSE
;
111 if (TimeZone
.StandardDate
.wMonth
) {
112 Time
->Daylight
= EFI_TIME_ADJUST_DAYLIGHT
;
126 Service routine for RealTimeClockInstance->SetTime
130 Time - A pointer to storage containing the time and date information to
131 program into the real time clock.
135 EFI_SUCEESS - The operation completed successfully.
137 EFI_INVALID_PARAMETER - One of the fields in Time is out of range.
139 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
142 // TODO: EFI_SUCCESS - add return value to function comment
144 TIME_ZONE_INFORMATION TimeZone
;
146 SYSTEMTIME SystemTime
;
150 return EFI_INVALID_PARAMETER
;
153 // Make sure that the time fields are valid
155 Status
= RtcTimeFieldsValid (Time
);
156 if (EFI_ERROR (Status
)) {
160 // Set Daylight savings time information and Time Zone
162 gWinNt
->GetTimeZoneInformation (&TimeZone
);
163 TimeZone
.StandardDate
.wMonth
= Time
->Daylight
;
164 TimeZone
.Bias
= Time
->TimeZone
;
165 gWinNt
->SetTimeZoneInformation (&TimeZone
);
167 SystemTime
.wYear
= Time
->Year
;
168 SystemTime
.wMonth
= Time
->Month
;
169 SystemTime
.wDay
= Time
->Day
;
170 SystemTime
.wHour
= Time
->Hour
;
171 SystemTime
.wMinute
= Time
->Minute
;
172 SystemTime
.wSecond
= Time
->Second
;
173 SystemTime
.wMilliseconds
= (INT16
) (Time
->Nanosecond
/ 1000000);
175 Flag
= gWinNt
->SetLocalTime (&SystemTime
);
178 return EFI_DEVICE_ERROR
;
187 OUT BOOLEAN
*Enabled
,
188 OUT BOOLEAN
*Pending
,
194 Service routine for RealTimeClockInstance->GetWakeupTime
197 This - Indicates the protocol instance structure.
199 Enabled - Indicates if the alarm is currently enabled or disabled.
201 Pending - Indicates if the alarm signal is pending and requires
204 Time - The current alarm setting.
208 EFI_SUCEESS - The operation completed successfully.
210 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
212 EFI_UNSUPPORTED - The operation is not supported on this platform.
216 return EFI_UNSUPPORTED
;
228 Service routine for RealTimeClockInstance->SetWakeupTime
232 Enabled - Enable or disable the wakeup alarm.
234 Time - If enable is TRUE, the time to set the wakup alarm for.
235 If enable is FALSE, then this parameter is optional, and
240 EFI_SUCEESS - The operation completed successfully.
242 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
244 EFI_INVALID_PARAMETER - A field in Time is out of range.
246 EFI_UNSUPPORTED - The operation is not supported on this platform.
250 return EFI_UNSUPPORTED
;
255 InitializeRealTimeClock (
256 IN EFI_HANDLE ImageHandle
,
257 IN EFI_SYSTEM_TABLE
*SystemTable
262 Install Real Time Clock Protocol
265 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
269 EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table
272 // TODO: ImageHandle - add argument and description to function comment
273 // TODO: SystemTable - add argument and description to function comment
279 SystemTable
->RuntimeServices
->GetTime
= WinNtGetTime
;
280 SystemTable
->RuntimeServices
->SetTime
= WinNtSetTime
;
281 SystemTable
->RuntimeServices
->GetWakeupTime
= WinNtGetWakeupTime
;
282 SystemTable
->RuntimeServices
->SetWakeupTime
= WinNtSetWakeupTime
;
285 Status
= gBS
->InstallMultipleProtocolInterfaces (
287 &gEfiRealTimeClockArchProtocolGuid
,
306 // TODO: Time - add argument and description to function comment
307 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
308 // TODO: EFI_SUCCESS - add return value to function comment
310 if (Time
->Year
< 1998 ||
314 (!DayValid (Time
)) ||
318 Time
->Nanosecond
> 999999999 ||
319 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
320 (Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
)))
322 return EFI_INVALID_PARAMETER
;
336 TODO: Add function description
340 Time - TODO: add argument description
344 TODO: add return values
349 INTN DayOfMonth
[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
352 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
353 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
369 TODO: Add function description
373 Time - TODO: add argument description
377 TODO: add return values
381 if (Time
->Year
% 4 == 0) {
382 if (Time
->Year
% 100 == 0) {
383 if (Time
->Year
% 400 == 0) {