3 Copyright (c) 2006 - 2011, 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
= (UINT8
) TimeZone
.StandardDate
.wMonth
;
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 Flag
= gWinNt
->SetTimeZoneInformation (&TimeZone
);
167 return EFI_DEVICE_ERROR
;
170 SystemTime
.wYear
= Time
->Year
;
171 SystemTime
.wMonth
= Time
->Month
;
172 SystemTime
.wDay
= Time
->Day
;
173 SystemTime
.wHour
= Time
->Hour
;
174 SystemTime
.wMinute
= Time
->Minute
;
175 SystemTime
.wSecond
= Time
->Second
;
176 SystemTime
.wMilliseconds
= (INT16
) (Time
->Nanosecond
/ 1000000);
178 Flag
= gWinNt
->SetLocalTime (&SystemTime
);
181 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
;
231 Service routine for RealTimeClockInstance->SetWakeupTime
235 Enabled - Enable or disable the wakeup alarm.
237 Time - If enable is TRUE, the time to set the wakup alarm for.
238 If enable is FALSE, then this parameter is optional, and
243 EFI_SUCEESS - The operation completed successfully.
245 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
247 EFI_INVALID_PARAMETER - A field in Time is out of range.
249 EFI_UNSUPPORTED - The operation is not supported on this platform.
253 return EFI_UNSUPPORTED
;
258 InitializeRealTimeClock (
259 IN EFI_HANDLE ImageHandle
,
260 IN EFI_SYSTEM_TABLE
*SystemTable
265 Install Real Time Clock Protocol
268 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
272 EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table
275 // TODO: ImageHandle - add argument and description to function comment
276 // TODO: SystemTable - add argument and description to function comment
282 SystemTable
->RuntimeServices
->GetTime
= WinNtGetTime
;
283 SystemTable
->RuntimeServices
->SetTime
= WinNtSetTime
;
284 SystemTable
->RuntimeServices
->GetWakeupTime
= WinNtGetWakeupTime
;
285 SystemTable
->RuntimeServices
->SetWakeupTime
= WinNtSetWakeupTime
;
288 Status
= gBS
->InstallMultipleProtocolInterfaces (
290 &gEfiRealTimeClockArchProtocolGuid
,
309 // TODO: Time - add argument and description to function comment
310 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
311 // TODO: EFI_SUCCESS - add return value to function comment
313 if (Time
->Year
< 1998 ||
317 (!DayValid (Time
)) ||
321 Time
->Nanosecond
> 999999999 ||
322 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
323 (Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
)))
325 return EFI_INVALID_PARAMETER
;
339 TODO: Add function description
343 Time - TODO: add argument description
347 TODO: add return values
352 INTN DayOfMonth
[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
355 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
356 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
372 TODO: Add function description
376 Time - TODO: add argument description
380 TODO: add return values
384 if (Time
->Year
% 4 == 0) {
385 if (Time
->Year
% 100 == 0) {
386 if (Time
->Year
% 400 == 0) {