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
25 // Include common header file for this module.
27 #include "CommonHeader.h"
46 InitializeRealTimeClock (
47 IN EFI_HANDLE ImageHandle
,
48 IN EFI_SYSTEM_TABLE
*SystemTable
56 OUT EFI_TIME_CAPABILITIES
*Capabilities OPTIONAL
61 Service routine for RealTimeClockInstance->GetTime
65 Time - A pointer to storage that will receive a snapshot of the current time.
67 Capabilities - A pointer to storage that will receive the capabilities of the real time clock
68 in the platform. This includes the real time clock's resolution and accuracy.
69 All reported device capabilities are rounded up. This is an OPTIONAL argument.
73 EFI_SUCEESS - The underlying GetSystemTime call occurred and returned
74 Note that in the NT32 emulation, the GetSystemTime call has no return value
75 thus you will always receive a EFI_SUCCESS on this.
78 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
80 SYSTEMTIME SystemTime
;
81 TIME_ZONE_INFORMATION TimeZone
;
84 // Check parameter for null pointer
87 return EFI_INVALID_PARAMETER
;
91 gWinNt
->GetLocalTime (&SystemTime
);
92 gWinNt
->GetTimeZoneInformation (&TimeZone
);
94 Time
->Year
= (UINT16
) SystemTime
.wYear
;
95 Time
->Month
= (UINT8
) SystemTime
.wMonth
;
96 Time
->Day
= (UINT8
) SystemTime
.wDay
;
97 Time
->Hour
= (UINT8
) SystemTime
.wHour
;
98 Time
->Minute
= (UINT8
) SystemTime
.wMinute
;
99 Time
->Second
= (UINT8
) SystemTime
.wSecond
;
100 Time
->Nanosecond
= (UINT32
) (SystemTime
.wMilliseconds
* 1000000);
101 Time
->TimeZone
= (INT16
) TimeZone
.Bias
;
103 if (Capabilities
!= NULL
) {
104 Capabilities
->Resolution
= 1;
105 Capabilities
->Accuracy
= 50000000;
106 Capabilities
->SetsToZero
= FALSE
;
110 if (TimeZone
.StandardDate
.wMonth
) {
111 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
;
188 OUT BOOLEAN
*Enabled
,
189 OUT BOOLEAN
*Pending
,
195 Service routine for RealTimeClockInstance->GetWakeupTime
198 This - Indicates the protocol instance structure.
200 Enabled - Indicates if the alarm is currently enabled or disabled.
202 Pending - Indicates if the alarm signal is pending and requires
205 Time - The current alarm setting.
209 EFI_SUCEESS - The operation completed successfully.
211 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
213 EFI_UNSUPPORTED - The operation is not supported on this platform.
217 return EFI_UNSUPPORTED
;
230 Service routine for RealTimeClockInstance->SetWakeupTime
234 Enabled - Enable or disable the wakeup alarm.
236 Time - If enable is TRUE, the time to set the wakup alarm for.
237 If enable is FALSE, then this parameter is optional, and
242 EFI_SUCEESS - The operation completed successfully.
244 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
246 EFI_INVALID_PARAMETER - A field in Time is out of range.
248 EFI_UNSUPPORTED - The operation is not supported on this platform.
252 return EFI_UNSUPPORTED
;
257 InitializeRealTimeClock (
258 IN EFI_HANDLE ImageHandle
,
259 IN EFI_SYSTEM_TABLE
*SystemTable
264 Install Real Time Clock Protocol
267 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
271 EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table
274 // TODO: ImageHandle - add argument and description to function comment
275 // TODO: SystemTable - add argument and description to function comment
281 SystemTable
->RuntimeServices
->GetTime
= WinNtGetTime
;
282 SystemTable
->RuntimeServices
->SetTime
= WinNtSetTime
;
283 SystemTable
->RuntimeServices
->GetWakeupTime
= WinNtGetWakeupTime
;
284 SystemTable
->RuntimeServices
->SetWakeupTime
= WinNtSetWakeupTime
;
287 Status
= gBS
->InstallMultipleProtocolInterfaces (
289 &gEfiRealTimeClockArchProtocolGuid
,
308 // TODO: Time - add argument and description to function comment
309 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
310 // TODO: EFI_SUCCESS - add return value to function comment
312 if (Time
->Year
< 1998 ||
316 (!DayValid (Time
)) ||
320 Time
->Nanosecond
> 999999999 ||
321 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
322 (Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
)))
324 return EFI_INVALID_PARAMETER
;
338 TODO: Add function description
342 Time - TODO: add argument description
346 TODO: add return values
351 INTN DayOfMonth
[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
354 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
355 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
371 TODO: Add function description
375 Time - TODO: add argument description
379 TODO: add return values
383 if (Time
->Year
% 4 == 0) {
384 if (Time
->Year
% 100 == 0) {
385 if (Time
->Year
% 400 == 0) {