--- /dev/null
+/** @file\r
+ Implement EFI RealTimeClock runtime services via Xen shared info page\r
+\r
+ Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>\r
+\r
+ 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
+**/\r
+\r
+#include <Uefi.h>\r
+#include <PiDxe.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+/**\r
+ Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME\r
+ **/\r
+STATIC\r
+VOID\r
+EpochToEfiTime (\r
+ IN UINTN EpochSeconds,\r
+ OUT EFI_TIME *Time\r
+ )\r
+{\r
+ UINTN a;\r
+ UINTN b;\r
+ UINTN c;\r
+ UINTN d;\r
+ UINTN g;\r
+ UINTN j;\r
+ UINTN m;\r
+ UINTN y;\r
+ UINTN da;\r
+ UINTN db;\r
+ UINTN dc;\r
+ UINTN dg;\r
+ UINTN hh;\r
+ UINTN mm;\r
+ UINTN ss;\r
+ UINTN J;\r
+\r
+ J = (EpochSeconds / 86400) + 2440588;\r
+ j = J + 32044;\r
+ g = j / 146097;\r
+ dg = j % 146097;\r
+ c = (((dg / 36524) + 1) * 3) / 4;\r
+ dc = dg - (c * 36524);\r
+ b = dc / 1461;\r
+ db = dc % 1461;\r
+ a = (((db / 365) + 1) * 3) / 4;\r
+ da = db - (a * 365);\r
+ y = (g * 400) + (c * 100) + (b * 4) + a;\r
+ m = (((da * 5) + 308) / 153) - 2;\r
+ d = da - (((m + 4) * 153) / 5) + 122;\r
+\r
+ Time->Year = y - 4800 + ((m + 2) / 12);\r
+ Time->Month = ((m + 2) % 12) + 1;\r
+ Time->Day = d + 1;\r
+\r
+ ss = EpochSeconds % 60;\r
+ a = (EpochSeconds - ss) / 60;\r
+ mm = a % 60;\r
+ b = (a - mm) / 60;\r
+ hh = b % 24;\r
+\r
+ Time->Hour = hh;\r
+ Time->Minute = mm;\r
+ Time->Second = ss;\r
+ Time->Nanosecond = 0;\r
+\r
+}\r
+\r
+/**\r
+ Returns the current time and date information, and the time-keeping capabilities\r
+ of the hardware platform.\r
+\r
+ @param Time A pointer to storage to receive a snapshot of the current time.\r
+ @param Capabilities An optional pointer to a buffer to receive the real time clock\r
+ device's capabilities.\r
+\r
+ @retval EFI_SUCCESS The operation completed successfully.\r
+ @retval EFI_INVALID_PARAMETER Time is NULL.\r
+ @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibGetTime (\r
+ OUT EFI_TIME *Time,\r
+ OUT EFI_TIME_CAPABILITIES *Capabilities\r
+ )\r
+{\r
+ ASSERT (Time != NULL);\r
+\r
+ //\r
+ // For now, there is nothing that we can do besides returning a bogus time,\r
+ // as Xen's timekeeping uses a shared info page which cannot be shared\r
+ // between UEFI and the OS\r
+ //\r
+ EpochToEfiTime(1421770011, Time);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Sets the current local time and date information.\r
+\r
+ @param Time A pointer to the current time.\r
+\r
+ @retval EFI_SUCCESS The operation completed successfully.\r
+ @retval EFI_INVALID_PARAMETER A time field is out of range.\r
+ @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibSetTime (\r
+ IN EFI_TIME *Time\r
+ )\r
+{\r
+ return EFI_DEVICE_ERROR;\r
+}\r
+\r
+\r
+/**\r
+ Returns the current wakeup alarm clock setting.\r
+\r
+ @param Enabled Indicates if the alarm is currently enabled or disabled.\r
+ @param Pending Indicates if the alarm signal is pending and requires acknowledgement.\r
+ @param Time The current alarm setting.\r
+\r
+ @retval EFI_SUCCESS The alarm settings were returned.\r
+ @retval EFI_INVALID_PARAMETER Any parameter is NULL.\r
+ @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.\r
+ @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibGetWakeupTime (\r
+ OUT BOOLEAN *Enabled,\r
+ OUT BOOLEAN *Pending,\r
+ OUT EFI_TIME *Time\r
+ )\r
+{\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+ Sets the system wakeup alarm clock time.\r
+\r
+ @param Enabled Enable or disable the wakeup alarm.\r
+ @param Time If Enable is TRUE, the time to set the wakeup alarm for.\r
+\r
+ @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled. If\r
+ Enable is FALSE, then the wakeup alarm was disabled.\r
+ @retval EFI_INVALID_PARAMETER A time field is out of range.\r
+ @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.\r
+ @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibSetWakeupTime (\r
+ IN BOOLEAN Enabled,\r
+ OUT EFI_TIME *Time\r
+ )\r
+{\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+ This is the declaration of an EFI image entry point. This can be the entry point to an application\r
+ written to this specification, an EFI boot service driver, or an EFI runtime driver.\r
+\r
+ @param ImageHandle Handle that identifies the loaded image.\r
+ @param SystemTable System Table for this image.\r
+\r
+ @retval EFI_SUCCESS The operation completed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibRtcInitialize (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ return EFI_SUCCESS;\r
+}\r
--- /dev/null
+#/** @file\r
+#\r
+# Copyright (c) 2015, L Ltd. All rights reserved.<BR>\r
+#\r
+# 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
+# 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
+#\r
+#**/\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = XenRealTimeClockLib\r
+ FILE_GUID = EC2557E8-7005-430B-9F6F-9BA109698248\r
+ MODULE_TYPE = BASE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = RealTimeClockLib|DXE_CORE DXE_DRIVER UEFI_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION\r
+\r
+[Sources.common]\r
+ XenRealTimeClockLib.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ OvmfPkg/OvmfPkg.dec\r
+ EmbeddedPkg/EmbeddedPkg.dec\r
+\r
+[LibraryClasses]\r
+ UefiLib\r
+ DebugLib\r
+ DxeServicesTableLib\r
+ UefiRuntimeLib\r
+\r
+[Guids]\r
+ gEfiEventVirtualAddressChangeGuid\r