2 Emu RTC Architectural Protocol Driver as defined in PI
4 Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
5 Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/UefiLib.h>
20 #include <Library/UefiDriverEntryPoint.h>
21 #include <Library/EmuThunkLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
25 #include <Protocol/RealTimeClock.h>
44 InitializeRealTimeClock (
45 IN EFI_HANDLE ImageHandle
,
46 IN EFI_SYSTEM_TABLE
*SystemTable
53 OUT EFI_TIME_CAPABILITIES
* Capabilities OPTIONAL
58 Service routine for RealTimeClockInstance->GetTime
62 Time - A pointer to storage that will receive a snapshot of the current time.
64 Capabilities - A pointer to storage that will receive the capabilities of the real time clock
65 in the platform. This includes the real time clock's resolution and accuracy.
66 All reported device capabilities are rounded up. This is an OPTIONAL argument.
70 EFI_SUCEESS - The underlying GetSystemTime call occurred and returned
71 Note that in the NT32 emulation, the GetSystemTime call has no return value
72 thus you will always receive a EFI_SUCCESS on this.
78 // Check parameter for null pointer
81 return EFI_INVALID_PARAMETER
;
85 gEmuThunk
->GetTime (Time
, Capabilities
);
98 Service routine for RealTimeClockInstance->SetTime
102 Time - A pointer to storage containing the time and date information to
103 program into the real time clock.
107 EFI_SUCEESS - The operation completed successfully.
109 EFI_INVALID_PARAMETER - One of the fields in Time is out of range.
111 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
118 return EFI_INVALID_PARAMETER
;
121 // Make sure that the time fields are valid
123 Status
= RtcTimeFieldsValid (Time
);
124 if (EFI_ERROR (Status
)) {
127 return EFI_UNSUPPORTED
;
133 OUT BOOLEAN
*Enabled
,
134 OUT BOOLEAN
*Pending
,
140 Service routine for RealTimeClockInstance->GetWakeupTime
143 This - Indicates the protocol instance structure.
145 Enabled - Indicates if the alarm is currently enabled or disabled.
147 Pending - Indicates if the alarm signal is pending and requires
150 Time - The current alarm setting.
154 EFI_SUCEESS - The operation completed successfully.
156 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
158 EFI_UNSUPPORTED - The operation is not supported on this platform.
162 return EFI_UNSUPPORTED
;
174 Service routine for RealTimeClockInstance->SetWakeupTime
178 Enabled - Enable or disable the wakeup alarm.
180 Time - If enable is TRUE, the time to set the wakup alarm for.
181 If enable is FALSE, then this parameter is optional, and
186 EFI_SUCEESS - The operation completed successfully.
188 EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
190 EFI_INVALID_PARAMETER - A field in Time is out of range.
192 EFI_UNSUPPORTED - The operation is not supported on this platform.
196 return EFI_UNSUPPORTED
;
201 InitializeRealTimeClock (
202 IN EFI_HANDLE ImageHandle
,
203 IN EFI_SYSTEM_TABLE
*SystemTable
208 Install Real Time Clock Protocol
211 ImageHandle - Image Handle
212 SystemTable - Pointer to system table
216 EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table
223 SystemTable
->RuntimeServices
->GetTime
= EmuGetTime
;
224 SystemTable
->RuntimeServices
->SetTime
= EmuSetTime
;
225 SystemTable
->RuntimeServices
->GetWakeupTime
= EmuGetWakeupTime
;
226 SystemTable
->RuntimeServices
->SetWakeupTime
= EmuSetWakeupTime
;
229 Status
= gBS
->InstallMultipleProtocolInterfaces (
231 &gEfiRealTimeClockArchProtocolGuid
,
251 if (Time
->Year
< 1998 ||
255 (!DayValid (Time
)) ||
259 Time
->Nanosecond
> 999999999 ||
260 (!(Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
|| (Time
->TimeZone
>= -1440 && Time
->TimeZone
<= 1440))) ||
261 (Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
)))
263 return EFI_INVALID_PARAMETER
;
275 STATIC
const INTN DayOfMonth
[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
278 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
279 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
292 if (Time
->Year
% 4 == 0) {
293 if (Time
->Year
% 100 == 0) {
294 if (Time
->Year
% 400 == 0) {