PcRtcEntry.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /** @file
  2. Provides Set/Get time operations.
  3. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
  4. Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <Library/DxeServicesTableLib.h>
  8. #include "PcRtc.h"
  9. PC_RTC_MODULE_GLOBALS mModuleGlobal;
  10. EFI_HANDLE mHandle = NULL;
  11. STATIC EFI_EVENT mVirtualAddrChangeEvent;
  12. UINTN mRtcIndexRegister;
  13. UINTN mRtcTargetRegister;
  14. /**
  15. Returns the current time and date information, and the time-keeping capabilities
  16. of the hardware platform.
  17. @param Time A pointer to storage to receive a snapshot of the current time.
  18. @param Capabilities An optional pointer to a buffer to receive the real time
  19. clock device's capabilities.
  20. @retval EFI_SUCCESS The operation completed successfully.
  21. @retval EFI_INVALID_PARAMETER Time is NULL.
  22. @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
  23. **/
  24. EFI_STATUS
  25. EFIAPI
  26. PcRtcEfiGetTime (
  27. OUT EFI_TIME *Time,
  28. OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
  29. )
  30. {
  31. return PcRtcGetTime (Time, Capabilities, &mModuleGlobal);
  32. }
  33. /**
  34. Sets the current local time and date information.
  35. @param Time A pointer to the current time.
  36. @retval EFI_SUCCESS The operation completed successfully.
  37. @retval EFI_INVALID_PARAMETER A time field is out of range.
  38. @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
  39. **/
  40. EFI_STATUS
  41. EFIAPI
  42. PcRtcEfiSetTime (
  43. IN EFI_TIME *Time
  44. )
  45. {
  46. return PcRtcSetTime (Time, &mModuleGlobal);
  47. }
  48. /**
  49. Returns the current wakeup alarm clock setting.
  50. @param Enabled Indicates if the alarm is currently enabled or disabled.
  51. @param Pending Indicates if the alarm signal is pending and requires acknowledgement.
  52. @param Time The current alarm setting.
  53. @retval EFI_SUCCESS The alarm settings were returned.
  54. @retval EFI_INVALID_PARAMETER Enabled is NULL.
  55. @retval EFI_INVALID_PARAMETER Pending is NULL.
  56. @retval EFI_INVALID_PARAMETER Time is NULL.
  57. @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
  58. @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
  59. **/
  60. EFI_STATUS
  61. EFIAPI
  62. PcRtcEfiGetWakeupTime (
  63. OUT BOOLEAN *Enabled,
  64. OUT BOOLEAN *Pending,
  65. OUT EFI_TIME *Time
  66. )
  67. {
  68. return PcRtcGetWakeupTime (Enabled, Pending, Time, &mModuleGlobal);
  69. }
  70. /**
  71. Sets the system wakeup alarm clock time.
  72. @param Enabled Enable or disable the wakeup alarm.
  73. @param Time If Enable is TRUE, the time to set the wakeup alarm for.
  74. If Enable is FALSE, then this parameter is optional, and may be NULL.
  75. @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.
  76. If Enable is FALSE, then the wakeup alarm was disabled.
  77. @retval EFI_INVALID_PARAMETER A time field is out of range.
  78. @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
  79. @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
  80. **/
  81. EFI_STATUS
  82. EFIAPI
  83. PcRtcEfiSetWakeupTime (
  84. IN BOOLEAN Enabled,
  85. IN EFI_TIME *Time OPTIONAL
  86. )
  87. {
  88. return PcRtcSetWakeupTime (Enabled, Time, &mModuleGlobal);
  89. }
  90. /**
  91. Fixup internal data so that EFI can be called in virtual mode.
  92. Call the passed in Child Notify event and convert any pointers in
  93. lib to virtual mode.
  94. @param[in] Event The Event that is being processed
  95. @param[in] Context Event Context
  96. **/
  97. VOID
  98. EFIAPI
  99. LibRtcVirtualNotifyEvent (
  100. IN EFI_EVENT Event,
  101. IN VOID *Context
  102. )
  103. {
  104. // Only needed if you are going to support the OS calling RTC functions in
  105. // virtual mode. You will need to call EfiConvertPointer (). To convert any
  106. // stored physical addresses to virtual address. After the OS transitions to
  107. // calling in virtual mode, all future runtime calls will be made in virtual
  108. // mode.
  109. EfiConvertPointer (0x0, (VOID **)&mRtcIndexRegister);
  110. EfiConvertPointer (0x0, (VOID **)&mRtcTargetRegister);
  111. }
  112. /**
  113. The user Entry Point for PcRTC module.
  114. This is the entry point for PcRTC module. It installs the UEFI runtime service
  115. including GetTime(),SetTime(),GetWakeupTime(),and SetWakeupTime().
  116. @param ImageHandle The firmware allocated handle for the EFI image.
  117. @param SystemTable A pointer to the EFI System Table.
  118. @retval EFI_SUCCESS The entry point is executed successfully.
  119. @retval Others Some error occurs when executing this entry point.
  120. **/
  121. EFI_STATUS
  122. EFIAPI
  123. InitializePcRtc (
  124. IN EFI_HANDLE ImageHandle,
  125. IN EFI_SYSTEM_TABLE *SystemTable
  126. )
  127. {
  128. EFI_STATUS Status;
  129. EFI_EVENT Event;
  130. EfiInitializeLock (&mModuleGlobal.RtcLock, TPL_CALLBACK);
  131. mModuleGlobal.CenturyRtcAddress = GetCenturyRtcAddress ();
  132. if (FeaturePcdGet (PcdRtcUseMmio)) {
  133. mRtcIndexRegister = (UINTN)PcdGet64 (PcdRtcIndexRegister64);
  134. mRtcTargetRegister = (UINTN)PcdGet64 (PcdRtcTargetRegister64);
  135. }
  136. Status = PcRtcInit (&mModuleGlobal);
  137. ASSERT_EFI_ERROR (Status);
  138. Status = gBS->CreateEventEx (
  139. EVT_NOTIFY_SIGNAL,
  140. TPL_CALLBACK,
  141. PcRtcAcpiTableChangeCallback,
  142. NULL,
  143. &gEfiAcpi10TableGuid,
  144. &Event
  145. );
  146. ASSERT_EFI_ERROR (Status);
  147. Status = gBS->CreateEventEx (
  148. EVT_NOTIFY_SIGNAL,
  149. TPL_CALLBACK,
  150. PcRtcAcpiTableChangeCallback,
  151. NULL,
  152. &gEfiAcpiTableGuid,
  153. &Event
  154. );
  155. ASSERT_EFI_ERROR (Status);
  156. gRT->GetTime = PcRtcEfiGetTime;
  157. gRT->SetTime = PcRtcEfiSetTime;
  158. gRT->GetWakeupTime = PcRtcEfiGetWakeupTime;
  159. gRT->SetWakeupTime = PcRtcEfiSetWakeupTime;
  160. Status = gBS->InstallMultipleProtocolInterfaces (
  161. &mHandle,
  162. &gEfiRealTimeClockArchProtocolGuid,
  163. NULL,
  164. NULL
  165. );
  166. if (EFI_ERROR (Status)) {
  167. ASSERT_EFI_ERROR (Status);
  168. return Status;
  169. }
  170. if (FeaturePcdGet (PcdRtcUseMmio)) {
  171. // Register for the virtual address change event
  172. Status = gBS->CreateEventEx (
  173. EVT_NOTIFY_SIGNAL,
  174. TPL_NOTIFY,
  175. LibRtcVirtualNotifyEvent,
  176. NULL,
  177. &gEfiEventVirtualAddressChangeGuid,
  178. &mVirtualAddrChangeEvent
  179. );
  180. ASSERT_EFI_ERROR (Status);
  181. }
  182. return Status;
  183. }