]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c
OvmfPkg/Xen: Fix VS2019 build issues
[mirror_edk2.git] / OvmfPkg / Library / XenRealTimeClockLib / XenRealTimeClockLib.c
1 /** @file
2 Implement EFI RealTimeClock runtime services via Xen shared info page
3
4 Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <Uefi.h>
11 #include <PiDxe.h>
12 #include <Library/BaseLib.h>
13 #include <Library/DebugLib.h>
14
15 /**
16 Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME
17 **/
18 STATIC
19 VOID
20 EpochToEfiTime (
21 IN UINTN EpochSeconds,
22 OUT EFI_TIME *Time
23 )
24 {
25 UINTN a;
26 UINTN b;
27 UINTN c;
28 UINTN d;
29 UINTN g;
30 UINTN j;
31 UINTN m;
32 UINTN y;
33 UINTN da;
34 UINTN db;
35 UINTN dc;
36 UINTN dg;
37 UINTN hh;
38 UINTN mm;
39 UINTN ss;
40 UINTN J;
41
42 J = (EpochSeconds / 86400) + 2440588;
43 j = J + 32044;
44 g = j / 146097;
45 dg = j % 146097;
46 c = (((dg / 36524) + 1) * 3) / 4;
47 dc = dg - (c * 36524);
48 b = dc / 1461;
49 db = dc % 1461;
50 a = (((db / 365) + 1) * 3) / 4;
51 da = db - (a * 365);
52 y = (g * 400) + (c * 100) + (b * 4) + a;
53 m = (((da * 5) + 308) / 153) - 2;
54 d = da - (((m + 4) * 153) / 5) + 122;
55
56 Time->Year = (UINT16)(y - 4800 + ((m + 2) / 12));
57 Time->Month = ((m + 2) % 12) + 1;
58 Time->Day = (UINT8)(d + 1);
59
60 ss = EpochSeconds % 60;
61 a = (EpochSeconds - ss) / 60;
62 mm = a % 60;
63 b = (a - mm) / 60;
64 hh = b % 24;
65
66 Time->Hour = (UINT8)hh;
67 Time->Minute = (UINT8)mm;
68 Time->Second = (UINT8)ss;
69 Time->Nanosecond = 0;
70
71 }
72
73 /**
74 Returns the current time and date information, and the time-keeping capabilities
75 of the hardware platform.
76
77 @param Time A pointer to storage to receive a snapshot of the current time.
78 @param Capabilities An optional pointer to a buffer to receive the real time clock
79 device's capabilities.
80
81 @retval EFI_SUCCESS The operation completed successfully.
82 @retval EFI_INVALID_PARAMETER Time is NULL.
83 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
84
85 **/
86 EFI_STATUS
87 EFIAPI
88 LibGetTime (
89 OUT EFI_TIME *Time,
90 OUT EFI_TIME_CAPABILITIES *Capabilities
91 )
92 {
93 ASSERT (Time != NULL);
94
95 //
96 // For now, there is nothing that we can do besides returning a bogus time,
97 // as Xen's timekeeping uses a shared info page which cannot be shared
98 // between UEFI and the OS
99 //
100 EpochToEfiTime(1421770011, Time);
101
102 return EFI_SUCCESS;
103 }
104
105 /**
106 Sets the current local time and date information.
107
108 @param Time A pointer to the current time.
109
110 @retval EFI_SUCCESS The operation completed successfully.
111 @retval EFI_INVALID_PARAMETER A time field is out of range.
112 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
113
114 **/
115 EFI_STATUS
116 EFIAPI
117 LibSetTime (
118 IN EFI_TIME *Time
119 )
120 {
121 return EFI_DEVICE_ERROR;
122 }
123
124
125 /**
126 Returns the current wakeup alarm clock setting.
127
128 @param Enabled Indicates if the alarm is currently enabled or disabled.
129 @param Pending Indicates if the alarm signal is pending and requires acknowledgement.
130 @param Time The current alarm setting.
131
132 @retval EFI_SUCCESS The alarm settings were returned.
133 @retval EFI_INVALID_PARAMETER Any parameter is NULL.
134 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
135 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
136
137 **/
138 EFI_STATUS
139 EFIAPI
140 LibGetWakeupTime (
141 OUT BOOLEAN *Enabled,
142 OUT BOOLEAN *Pending,
143 OUT EFI_TIME *Time
144 )
145 {
146 return EFI_UNSUPPORTED;
147 }
148
149 /**
150 Sets the system wakeup alarm clock time.
151
152 @param Enabled Enable or disable the wakeup alarm.
153 @param Time If Enable is TRUE, the time to set the wakeup alarm for.
154
155 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled. If
156 Enable is FALSE, then the wakeup alarm was disabled.
157 @retval EFI_INVALID_PARAMETER A time field is out of range.
158 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
159 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
160
161 **/
162 EFI_STATUS
163 EFIAPI
164 LibSetWakeupTime (
165 IN BOOLEAN Enabled,
166 OUT EFI_TIME *Time
167 )
168 {
169 return EFI_UNSUPPORTED;
170 }
171
172 /**
173 This is the declaration of an EFI image entry point. This can be the entry point to an application
174 written to this specification, an EFI boot service driver, or an EFI runtime driver.
175
176 @param ImageHandle Handle that identifies the loaded image.
177 @param SystemTable System Table for this image.
178
179 @retval EFI_SUCCESS The operation completed successfully.
180
181 **/
182 EFI_STATUS
183 EFIAPI
184 LibRtcInitialize (
185 IN EFI_HANDLE ImageHandle,
186 IN EFI_SYSTEM_TABLE *SystemTable
187 )
188 {
189 return EFI_SUCCESS;
190 }