--- /dev/null
+/*++\r
+\r
+Copyright (c) 2004 - 2006, Intel Corporation \r
+All rights reserved. This program and the accompanying materials \r
+are licensed and made available under the terms and conditions of the BSD License \r
+which accompanies this distribution. The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php \r
+ \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+\r
+Module Name:\r
+\r
+ RealTimeClock.c\r
+\r
+Abstract:\r
+\r
+ NT Emulation Architectural Protocol Driver as defined in Tiano\r
+\r
+--*/\r
+\r
+BOOLEAN\r
+DayValid (\r
+ IN EFI_TIME *Time\r
+ );\r
+\r
+BOOLEAN\r
+IsLeapYear (\r
+ IN EFI_TIME *Time\r
+ );\r
+\r
+EFI_STATUS\r
+RtcTimeFieldsValid (\r
+ IN EFI_TIME *Time\r
+ );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeRealTimeClock (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ );\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixGetTime (\r
+ OUT EFI_TIME * Time,\r
+ OUT EFI_TIME_CAPABILITIES * Capabilities OPTIONAL\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Service routine for RealTimeClockInstance->GetTime \r
+\r
+Arguments:\r
+\r
+ Time - A pointer to storage that will receive a snapshot of the current time.\r
+\r
+ Capabilities - A pointer to storage that will receive the capabilities of the real time clock\r
+ in the platform. This includes the real time clock's resolution and accuracy. \r
+ All reported device capabilities are rounded up. This is an OPTIONAL argument.\r
+\r
+Returns:\r
+\r
+ EFI_SUCEESS - The underlying GetSystemTime call occurred and returned\r
+ Note that in the NT32 emulation, the GetSystemTime call has no return value\r
+ thus you will always receive a EFI_SUCCESS on this.\r
+\r
+--*/\r
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+\r
+ //\r
+ // Check parameter for null pointer\r
+ //\r
+ if (Time == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+\r
+ }\r
+\r
+ gUnix->GetLocalTime (Time);
+\r
+ if (Capabilities != NULL) {\r
+ Capabilities->Resolution = 1;\r
+ Capabilities->Accuracy = 50000000;\r
+ Capabilities->SetsToZero = FALSE;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSetTime (\r
+ IN EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Service routine for RealTimeClockInstance->SetTime \r
+\r
+Arguments:\r
+\r
+ Time - A pointer to storage containing the time and date information to\r
+ program into the real time clock.\r
+\r
+Returns:\r
+\r
+ EFI_SUCEESS - The operation completed successfully.\r
+ \r
+ EFI_INVALID_PARAMETER - One of the fields in Time is out of range.\r
+\r
+ EFI_DEVICE_ERROR - The operation could not be complete due to a device error.\r
+\r
+--*/\r
+// TODO: EFI_SUCCESS - add return value to function comment\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if (Time == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ //\r
+ // Make sure that the time fields are valid\r
+ //\r
+ Status = RtcTimeFieldsValid (Time);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixGetWakeupTime (\r
+ OUT BOOLEAN *Enabled,\r
+ OUT BOOLEAN *Pending,\r
+ OUT EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Service routine for RealTimeClockInstance->GetWakeupTime\r
+\r
+Arguments:\r
+ This - Indicates the protocol instance structure.\r
+\r
+ Enabled - Indicates if the alarm is currently enabled or disabled.\r
+\r
+ Pending - Indicates if the alarm signal is pending and requires\r
+ acknowledgement.\r
+\r
+ Time - The current alarm setting.\r
+\r
+Returns:\r
+\r
+ EFI_SUCEESS - The operation completed successfully.\r
+ \r
+ EFI_DEVICE_ERROR - The operation could not be complete due to a device error.\r
+\r
+ EFI_UNSUPPORTED - The operation is not supported on this platform.\r
+\r
+--*/\r
+{\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSetWakeupTime (\r
+ IN BOOLEAN Enable,\r
+ OUT EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Service routine for RealTimeClockInstance->SetWakeupTime\r
+\r
+Arguments:\r
+\r
+ Enabled - Enable or disable the wakeup alarm.\r
+\r
+ Time - If enable is TRUE, the time to set the wakup alarm for.\r
+ If enable is FALSE, then this parameter is optional, and\r
+ may be NULL.\r
+\r
+Returns:\r
+\r
+ EFI_SUCEESS - The operation completed successfully.\r
+ \r
+ EFI_DEVICE_ERROR - The operation could not be complete due to a device error.\r
+\r
+ EFI_INVALID_PARAMETER - A field in Time is out of range.\r
+\r
+ EFI_UNSUPPORTED - The operation is not supported on this platform.\r
+\r
+--*/\r
+{\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeRealTimeClock (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Install Real Time Clock Protocol \r
+\r
+Arguments:\r
+ ImageHandle - Image Handle\r
+ SystemTable - Pointer to system table\r
+\r
+Returns:\r
+\r
+ EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_HANDLE Handle;\r
+\r
+ SystemTable->RuntimeServices->GetTime = UnixGetTime;\r
+ SystemTable->RuntimeServices->SetTime = UnixSetTime;\r
+ SystemTable->RuntimeServices->GetWakeupTime = UnixGetWakeupTime;\r
+ SystemTable->RuntimeServices->SetWakeupTime = UnixSetWakeupTime;\r
+\r
+ Handle = NULL;\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ &Handle,\r
+ &gEfiRealTimeClockArchProtocolGuid,\r
+ NULL,\r
+ NULL\r
+ );\r
+ return Status;\r
+}\r
+\r
+EFI_STATUS\r
+RtcTimeFieldsValid (\r
+ IN EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Arguments:\r
+ \r
+ Returns: \r
+--*/\r
+// TODO: Time - add argument and description to function comment\r
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
+// TODO: EFI_SUCCESS - add return value to function comment\r
+{\r
+ if (Time->Year < 1998 ||\r
+ Time->Year > 2099 ||\r
+ Time->Month < 1 ||\r
+ Time->Month > 12 ||\r
+ (!DayValid (Time)) ||\r
+ Time->Hour > 23 ||\r
+ Time->Minute > 59 ||\r
+ Time->Second > 59 ||\r
+ Time->Nanosecond > 999999999 ||\r
+ (!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||\r
+ (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))\r
+ ) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+BOOLEAN\r
+DayValid (\r
+ IN EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Time - TODO: add argument description\r
+\r
+Returns:\r
+\r
+ TODO: add return values\r
+\r
+--*/\r
+{\r
+\r
+ static const INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r
+\r
+ if (Time->Day < 1 ||\r
+ Time->Day > DayOfMonth[Time->Month - 1] ||\r
+ (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))\r
+ ) {\r
+ return FALSE;\r
+ }\r
+\r
+ return TRUE;\r
+}\r
+\r
+BOOLEAN\r
+IsLeapYear (\r
+ IN EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Time - TODO: add argument description\r
+\r
+Returns:\r
+\r
+ TODO: add return values\r
+\r
+--*/\r
+{\r
+ if (Time->Year % 4 == 0) {\r
+ if (Time->Year % 100 == 0) {\r
+ if (Time->Year % 400 == 0) {\r
+ return TRUE;\r
+ } else {\r
+ return FALSE;\r
+ }\r
+ } else {\r
+ return TRUE;\r
+ }\r
+ } else {\r
+ return FALSE;\r
+ }\r
+}\r