3 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
12 NT Emulation Architectural Protocol Driver as defined in Tiano
18 #include <Protocol/RealTimeClock.h>
19 #include <Library/DebugLib.h>
20 #include <Library/UefiDriverEntryPoint.h>
21 #include <Library/WinNtLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
42 InitializeRealTimeClock (
43 IN EFI_HANDLE ImageHandle
,
44 IN EFI_SYSTEM_TABLE
*SystemTable
51 OUT EFI_TIME_CAPABILITIES
*Capabilities OPTIONAL
56 Service routine for RealTimeClockInstance->GetTime
60 Time - A pointer to storage that will receive a snapshot of the current time.
62 Capabilities - A pointer to storage that will receive the capabilities of the real time clock
63 in the platform. This includes the real time clock's resolution and accuracy.
64 All reported device capabilities are rounded up. This is an OPTIONAL argument.
68 EFI_SUCEESS - The underlying GetSystemTime call occurred and returned
69 Note that in the NT32 emulation, the GetSystemTime call has no return value
70 thus you will always receive a EFI_SUCCESS on this.
73 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
75 SYSTEMTIME SystemTime
;
76 TIME_ZONE_INFORMATION TimeZone
;
79 // Check parameter for null pointer
82 return EFI_INVALID_PARAMETER
;
86 gWinNt
->GetLocalTime (&SystemTime
);
87 gWinNt
->GetTimeZoneInformation (&TimeZone
);
89 Time
->Year
= (UINT16
) SystemTime
.wYear
;
90 Time
->Month
= (UINT8
) SystemTime
.wMonth
;
91 Time
->Day
= (UINT8
) SystemTime
.wDay
;
92 Time
->Hour
= (UINT8
) SystemTime
.wHour
;
93 Time
->Minute
= (UINT8
) SystemTime
.wMinute
;
94 Time
->Second
= (UINT8
) SystemTime
.wSecond
;
95 Time
->Nanosecond
= (UINT32
) (SystemTime
.wMilliseconds
* 1000000);
96 Time
->TimeZone
= (INT16
) TimeZone
.Bias
;
98 if (Capabilities
!= NULL
) {
99 Capabilities
->Resolution
= 1;
100 Capabilities
->Accuracy
= 50000000;
101 Capabilities
->SetsToZero
= FALSE
;
105 if (TimeZone
.StandardDate
.wMonth
) {
106 Time
->Daylight
= (UINT8
) TimeZone
.StandardDate
.wMonth
;
120 Service routine for RealTimeClockInstance->SetTime
124 Time - A pointer to storage containing the time and date information to
125 program into the real time clock.
129 EFI_SUCEESS - The operation completed successfully.
131 EFI_INVALID_PARAMETER - One of the fields in Time is out of range.
133 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
136 // TODO: EFI_SUCCESS - add return value to function comment
138 TIME_ZONE_INFORMATION TimeZone
;
140 SYSTEMTIME SystemTime
;
144 return EFI_INVALID_PARAMETER
;
147 // Make sure that the time fields are valid
149 Status
= RtcTimeFieldsValid (Time
);
150 if (EFI_ERROR (Status
)) {
154 // Set Daylight savings time information and Time Zone
156 gWinNt
->GetTimeZoneInformation (&TimeZone
);
157 TimeZone
.StandardDate
.wMonth
= Time
->Daylight
;
158 TimeZone
.Bias
= Time
->TimeZone
;
159 Flag
= gWinNt
->SetTimeZoneInformation (&TimeZone
);
161 return EFI_DEVICE_ERROR
;
164 SystemTime
.wYear
= Time
->Year
;
165 SystemTime
.wMonth
= Time
->Month
;
166 SystemTime
.wDay
= Time
->Day
;
167 SystemTime
.wHour
= Time
->Hour
;
168 SystemTime
.wMinute
= Time
->Minute
;
169 SystemTime
.wSecond
= Time
->Second
;
170 SystemTime
.wMilliseconds
= (INT16
) (Time
->Nanosecond
/ 1000000);
172 Flag
= gWinNt
->SetLocalTime (&SystemTime
);
175 return EFI_DEVICE_ERROR
;
184 OUT BOOLEAN
*Enabled
,
185 OUT BOOLEAN
*Pending
,
191 Service routine for RealTimeClockInstance->GetWakeupTime
194 This - Indicates the protocol instance structure.
196 Enabled - Indicates if the alarm is currently enabled or disabled.
198 Pending - Indicates if the alarm signal is pending and requires
201 Time - The current alarm setting.
205 EFI_SUCEESS - The operation completed successfully.
207 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
209 EFI_UNSUPPORTED - The operation is not supported on this platform.
213 return EFI_UNSUPPORTED
;
225 Service routine for RealTimeClockInstance->SetWakeupTime
229 Enabled - Enable or disable the wakeup alarm.
231 Time - If enable is TRUE, the time to set the wakup alarm for.
232 If enable is FALSE, then this parameter is optional, and
237 EFI_SUCEESS - The operation completed successfully.
239 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
241 EFI_INVALID_PARAMETER - A field in Time is out of range.
243 EFI_UNSUPPORTED - The operation is not supported on this platform.
247 return EFI_UNSUPPORTED
;
252 InitializeRealTimeClock (
253 IN EFI_HANDLE ImageHandle
,
254 IN EFI_SYSTEM_TABLE
*SystemTable
259 Install Real Time Clock Protocol
262 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
266 EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table
269 // TODO: ImageHandle - add argument and description to function comment
270 // TODO: SystemTable - add argument and description to function comment
276 SystemTable
->RuntimeServices
->GetTime
= WinNtGetTime
;
277 SystemTable
->RuntimeServices
->SetTime
= WinNtSetTime
;
278 SystemTable
->RuntimeServices
->GetWakeupTime
= WinNtGetWakeupTime
;
279 SystemTable
->RuntimeServices
->SetWakeupTime
= WinNtSetWakeupTime
;
282 Status
= gBS
->InstallMultipleProtocolInterfaces (
284 &gEfiRealTimeClockArchProtocolGuid
,
303 // TODO: Time - add argument and description to function comment
304 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
305 // TODO: EFI_SUCCESS - add return value to function comment
307 if (Time
->Year
< 1998 ||
311 (!DayValid (Time
)) ||
315 Time
->Nanosecond
> 999999999 ||
316 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
317 (Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
)))
319 return EFI_INVALID_PARAMETER
;
333 TODO: Add function description
337 Time - TODO: add argument description
341 TODO: add return values
346 INTN DayOfMonth
[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
349 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
350 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
366 TODO: Add function description
370 Time - TODO: add argument description
374 TODO: add return values
378 if (Time
->Year
% 4 == 0) {
379 if (Time
->Year
% 100 == 0) {
380 if (Time
->Year
% 400 == 0) {