VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtcEntry.c@ 107064

Last change on this file since 107064 was 105670, checked in by vboxsync, 6 months ago

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette