3 Copyright (c) 2006, 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 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
58 OUT EFI_TIME_CAPABILITIES
*Capabilities OPTIONAL
63 Service routine for RealTimeClockInstance->GetTime
67 Time - A pointer to storage that will receive a snapshot of the current time.
69 Capabilities - A pointer to storage that will receive the capabilities of the real time clock
70 in the platform. This includes the real time clock's resolution and accuracy.
71 All reported device capabilities are rounded up. This is an OPTIONAL argument.
75 EFI_SUCEESS - The underlying GetSystemTime call occurred and returned
76 Note that in the NT32 emulation, the GetSystemTime call has no return value
77 thus you will always receive a EFI_SUCCESS on this.
80 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
82 SYSTEMTIME SystemTime
;
83 TIME_ZONE_INFORMATION TimeZone
;
86 // Check parameter for null pointer
89 return EFI_INVALID_PARAMETER
;
93 gWinNt
->GetLocalTime (&SystemTime
);
94 gWinNt
->GetTimeZoneInformation (&TimeZone
);
96 Time
->Year
= (UINT16
) SystemTime
.wYear
;
97 Time
->Month
= (UINT8
) SystemTime
.wMonth
;
98 Time
->Day
= (UINT8
) SystemTime
.wDay
;
99 Time
->Hour
= (UINT8
) SystemTime
.wHour
;
100 Time
->Minute
= (UINT8
) SystemTime
.wMinute
;
101 Time
->Second
= (UINT8
) SystemTime
.wSecond
;
102 Time
->Nanosecond
= (UINT32
) (SystemTime
.wMilliseconds
* 1000000);
103 Time
->TimeZone
= (INT16
) TimeZone
.Bias
;
105 if (Capabilities
!= NULL
) {
106 Capabilities
->Resolution
= 1;
107 Capabilities
->Accuracy
= 50000000;
108 Capabilities
->SetsToZero
= FALSE
;
112 if (TimeZone
.StandardDate
.wMonth
) {
113 Time
->Daylight
= EFI_TIME_ADJUST_DAYLIGHT
;
128 Service routine for RealTimeClockInstance->SetTime
132 Time - A pointer to storage containing the time and date information to
133 program into the real time clock.
137 EFI_SUCEESS - The operation completed successfully.
139 EFI_INVALID_PARAMETER - One of the fields in Time is out of range.
141 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
144 // TODO: EFI_SUCCESS - add return value to function comment
146 TIME_ZONE_INFORMATION TimeZone
;
148 SYSTEMTIME SystemTime
;
152 return EFI_INVALID_PARAMETER
;
155 // Make sure that the time fields are valid
157 Status
= RtcTimeFieldsValid (Time
);
158 if (EFI_ERROR (Status
)) {
162 // Set Daylight savings time information and Time Zone
164 gWinNt
->GetTimeZoneInformation (&TimeZone
);
165 TimeZone
.StandardDate
.wMonth
= Time
->Daylight
;
166 TimeZone
.Bias
= Time
->TimeZone
;
167 gWinNt
->SetTimeZoneInformation (&TimeZone
);
169 SystemTime
.wYear
= Time
->Year
;
170 SystemTime
.wMonth
= Time
->Month
;
171 SystemTime
.wDay
= Time
->Day
;
172 SystemTime
.wHour
= Time
->Hour
;
173 SystemTime
.wMinute
= Time
->Minute
;
174 SystemTime
.wSecond
= Time
->Second
;
175 SystemTime
.wMilliseconds
= (INT16
) (Time
->Nanosecond
/ 1000000);
177 Flag
= gWinNt
->SetLocalTime (&SystemTime
);
180 return EFI_DEVICE_ERROR
;
190 OUT BOOLEAN
*Enabled
,
191 OUT BOOLEAN
*Pending
,
197 Service routine for RealTimeClockInstance->GetWakeupTime
200 This - Indicates the protocol instance structure.
202 Enabled - Indicates if the alarm is currently enabled or disabled.
204 Pending - Indicates if the alarm signal is pending and requires
207 Time - The current alarm setting.
211 EFI_SUCEESS - The operation completed successfully.
213 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
215 EFI_UNSUPPORTED - The operation is not supported on this platform.
219 return EFI_UNSUPPORTED
;
232 Service routine for RealTimeClockInstance->SetWakeupTime
236 Enabled - Enable or disable the wakeup alarm.
238 Time - If enable is TRUE, the time to set the wakup alarm for.
239 If enable is FALSE, then this parameter is optional, and
244 EFI_SUCEESS - The operation completed successfully.
246 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
248 EFI_INVALID_PARAMETER - A field in Time is out of range.
250 EFI_UNSUPPORTED - The operation is not supported on this platform.
254 return EFI_UNSUPPORTED
;
259 InitializeRealTimeClock (
260 IN EFI_HANDLE ImageHandle
,
261 IN EFI_SYSTEM_TABLE
*SystemTable
266 Install Real Time Clock Protocol
269 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
273 EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table
276 // TODO: ImageHandle - add argument and description to function comment
277 // TODO: SystemTable - add argument and description to function comment
283 SystemTable
->RuntimeServices
->GetTime
= WinNtGetTime
;
284 SystemTable
->RuntimeServices
->SetTime
= WinNtSetTime
;
285 SystemTable
->RuntimeServices
->GetWakeupTime
= WinNtGetWakeupTime
;
286 SystemTable
->RuntimeServices
->SetWakeupTime
= WinNtSetWakeupTime
;
289 Status
= gBS
->InstallMultipleProtocolInterfaces (
291 &gEfiRealTimeClockArchProtocolGuid
,
310 // TODO: Time - add argument and description to function comment
311 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
312 // TODO: EFI_SUCCESS - add return value to function comment
314 if (Time
->Year
< 1998 ||
318 (!DayValid (Time
)) ||
322 Time
->Nanosecond
> 999999999 ||
323 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
324 (Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
)))
326 return EFI_INVALID_PARAMETER
;
340 TODO: Add function description
344 Time - TODO: add argument description
348 TODO: add return values
353 INTN DayOfMonth
[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
356 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
357 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
373 TODO: Add function description
377 Time - TODO: add argument description
381 TODO: add return values
385 if (Time
->Year
% 4 == 0) {
386 if (Time
->Year
% 100 == 0) {
387 if (Time
->Year
% 400 == 0) {