PcRtcEntry.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /** @file
  2. Provides Set/Get time operations.
  3. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "PcRtc.h"
  7. PC_RTC_MODULE_GLOBALS mModuleGlobal;
  8. EFI_HANDLE mHandle = NULL;
  9. /**
  10. Returns the current time and date information, and the time-keeping capabilities
  11. of the hardware platform.
  12. @param Time A pointer to storage to receive a snapshot of the current time.
  13. @param Capabilities An optional pointer to a buffer to receive the real time
  14. clock device's capabilities.
  15. @retval EFI_SUCCESS The operation completed successfully.
  16. @retval EFI_INVALID_PARAMETER Time is NULL.
  17. @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
  18. **/
  19. EFI_STATUS
  20. EFIAPI
  21. PcRtcEfiGetTime (
  22. OUT EFI_TIME *Time,
  23. OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
  24. )
  25. {
  26. return PcRtcGetTime (Time, Capabilities, &mModuleGlobal);
  27. }
  28. /**
  29. Sets the current local time and date information.
  30. @param Time A pointer to the current time.
  31. @retval EFI_SUCCESS The operation completed successfully.
  32. @retval EFI_INVALID_PARAMETER A time field is out of range.
  33. @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
  34. **/
  35. EFI_STATUS
  36. EFIAPI
  37. PcRtcEfiSetTime (
  38. IN EFI_TIME *Time
  39. )
  40. {
  41. return PcRtcSetTime (Time, &mModuleGlobal);
  42. }
  43. /**
  44. Returns the current wakeup alarm clock setting.
  45. @param Enabled Indicates if the alarm is currently enabled or disabled.
  46. @param Pending Indicates if the alarm signal is pending and requires acknowledgement.
  47. @param Time The current alarm setting.
  48. @retval EFI_SUCCESS The alarm settings were returned.
  49. @retval EFI_INVALID_PARAMETER Enabled is NULL.
  50. @retval EFI_INVALID_PARAMETER Pending is NULL.
  51. @retval EFI_INVALID_PARAMETER Time is NULL.
  52. @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
  53. @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
  54. **/
  55. EFI_STATUS
  56. EFIAPI
  57. PcRtcEfiGetWakeupTime (
  58. OUT BOOLEAN *Enabled,
  59. OUT BOOLEAN *Pending,
  60. OUT EFI_TIME *Time
  61. )
  62. {
  63. return PcRtcGetWakeupTime (Enabled, Pending, Time, &mModuleGlobal);
  64. }
  65. /**
  66. Sets the system wakeup alarm clock time.
  67. @param Enabled Enable or disable the wakeup alarm.
  68. @param Time If Enable is TRUE, the time to set the wakeup alarm for.
  69. If Enable is FALSE, then this parameter is optional, and may be NULL.
  70. @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.
  71. If Enable is FALSE, then the wakeup alarm was disabled.
  72. @retval EFI_INVALID_PARAMETER A time field is out of range.
  73. @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
  74. @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
  75. **/
  76. EFI_STATUS
  77. EFIAPI
  78. PcRtcEfiSetWakeupTime (
  79. IN BOOLEAN Enabled,
  80. IN EFI_TIME *Time OPTIONAL
  81. )
  82. {
  83. return PcRtcSetWakeupTime (Enabled, Time, &mModuleGlobal);
  84. }
  85. /**
  86. The user Entry Point for PcRTC module.
  87. This is the entrhy point for PcRTC module. It installs the UEFI runtime service
  88. including GetTime(),SetTime(),GetWakeupTime(),and SetWakeupTime().
  89. @param ImageHandle The firmware allocated handle for the EFI image.
  90. @param SystemTable A pointer to the EFI System Table.
  91. @retval EFI_SUCCESS The entry point is executed successfully.
  92. @retval Others Some error occurs when executing this entry point.
  93. **/
  94. EFI_STATUS
  95. EFIAPI
  96. InitializePcRtc (
  97. IN EFI_HANDLE ImageHandle,
  98. IN EFI_SYSTEM_TABLE *SystemTable
  99. )
  100. {
  101. EFI_STATUS Status;
  102. EFI_EVENT Event;
  103. EfiInitializeLock (&mModuleGlobal.RtcLock, TPL_CALLBACK);
  104. mModuleGlobal.CenturyRtcAddress = GetCenturyRtcAddress ();
  105. Status = PcRtcInit (&mModuleGlobal);
  106. ASSERT_EFI_ERROR (Status);
  107. Status = gBS->CreateEventEx (
  108. EVT_NOTIFY_SIGNAL,
  109. TPL_CALLBACK,
  110. PcRtcAcpiTableChangeCallback,
  111. NULL,
  112. &gEfiAcpi10TableGuid,
  113. &Event
  114. );
  115. ASSERT_EFI_ERROR (Status);
  116. Status = gBS->CreateEventEx (
  117. EVT_NOTIFY_SIGNAL,
  118. TPL_CALLBACK,
  119. PcRtcAcpiTableChangeCallback,
  120. NULL,
  121. &gEfiAcpiTableGuid,
  122. &Event
  123. );
  124. ASSERT_EFI_ERROR (Status);
  125. gRT->GetTime = PcRtcEfiGetTime;
  126. gRT->SetTime = PcRtcEfiSetTime;
  127. gRT->GetWakeupTime = PcRtcEfiGetWakeupTime;
  128. gRT->SetWakeupTime = PcRtcEfiSetWakeupTime;
  129. Status = gBS->InstallMultipleProtocolInterfaces (
  130. &mHandle,
  131. &gEfiRealTimeClockArchProtocolGuid,
  132. NULL,
  133. NULL
  134. );
  135. ASSERT_EFI_ERROR (Status);
  136. return Status;
  137. }