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