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 | Returns the current time and date information, and the time-keeping capabilities
|
---|
74 | of the hardware platform.
|
---|
75 |
|
---|
76 | @param Time A pointer to storage to receive a snapshot of the current time.
|
---|
77 | @param Capabilities An optional pointer to a buffer to receive the real time clock
|
---|
78 | device's capabilities.
|
---|
79 |
|
---|
80 | @retval EFI_SUCCESS The operation completed successfully.
|
---|
81 | @retval EFI_INVALID_PARAMETER Time is NULL.
|
---|
82 | @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
|
---|
83 | @retval EFI_UNSUPPORTED This call is not supported by this platform at the time the call is made.
|
---|
84 | The platform should describe this runtime service as unsupported at runtime
|
---|
85 | via an EFI_RT_PROPERTIES_TABLE configuration table.
|
---|
86 |
|
---|
87 | **/
|
---|
88 | EFI_STATUS
|
---|
89 | EFIAPI
|
---|
90 | LibGetTime (
|
---|
91 | OUT EFI_TIME *Time,
|
---|
92 | OUT EFI_TIME_CAPABILITIES *Capabilities
|
---|
93 | )
|
---|
94 | {
|
---|
95 | ASSERT (Time != NULL);
|
---|
96 |
|
---|
97 | //
|
---|
98 | // For now, there is nothing that we can do besides returning a bogus time,
|
---|
99 | // as Xen's timekeeping uses a shared info page which cannot be shared
|
---|
100 | // between UEFI and the OS
|
---|
101 | //
|
---|
102 | EpochToEfiTime (1421770011, Time);
|
---|
103 |
|
---|
104 | return EFI_SUCCESS;
|
---|
105 | }
|
---|
106 |
|
---|
107 | /**
|
---|
108 | Sets the current local time and date information.
|
---|
109 |
|
---|
110 | @param Time A pointer to the current time.
|
---|
111 |
|
---|
112 | @retval EFI_SUCCESS The operation completed successfully.
|
---|
113 | @retval EFI_INVALID_PARAMETER A time field is out of range.
|
---|
114 | @retval EFI_DEVICE_ERROR The time could not be set due to hardware error.
|
---|
115 | @retval EFI_UNSUPPORTED This call is not supported by this platform at the time the call is made.
|
---|
116 | The platform should describe this runtime service as unsupported at runtime
|
---|
117 | via an EFI_RT_PROPERTIES_TABLE configuration table.
|
---|
118 |
|
---|
119 | **/
|
---|
120 | EFI_STATUS
|
---|
121 | EFIAPI
|
---|
122 | LibSetTime (
|
---|
123 | IN EFI_TIME *Time
|
---|
124 | )
|
---|
125 | {
|
---|
126 | return EFI_DEVICE_ERROR;
|
---|
127 | }
|
---|
128 |
|
---|
129 | /**
|
---|
130 | Returns the current wakeup alarm clock setting.
|
---|
131 |
|
---|
132 | @param Enabled Indicates if the alarm is currently enabled or disabled.
|
---|
133 | @param Pending Indicates if the alarm signal is pending and requires acknowledgement.
|
---|
134 | @param Time The current alarm setting.
|
---|
135 |
|
---|
136 | @retval EFI_SUCCESS The alarm settings were returned.
|
---|
137 | @retval EFI_INVALID_PARAMETER Enabled is NULL.
|
---|
138 | @retval EFI_INVALID_PARAMETER Pending is NULL.
|
---|
139 | @retval EFI_INVALID_PARAMETER Time is NULL.
|
---|
140 | @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
|
---|
141 | @retval EFI_UNSUPPORTED This call is not supported by this platform at the time the call is made.
|
---|
142 | The platform should describe this runtime service as unsupported at runtime
|
---|
143 | via an EFI_RT_PROPERTIES_TABLE configuration table.
|
---|
144 |
|
---|
145 | **/
|
---|
146 | EFI_STATUS
|
---|
147 | EFIAPI
|
---|
148 | LibGetWakeupTime (
|
---|
149 | OUT BOOLEAN *Enabled,
|
---|
150 | OUT BOOLEAN *Pending,
|
---|
151 | OUT EFI_TIME *Time
|
---|
152 | )
|
---|
153 | {
|
---|
154 | return EFI_UNSUPPORTED;
|
---|
155 | }
|
---|
156 |
|
---|
157 | /**
|
---|
158 | Sets the system wakeup alarm clock time.
|
---|
159 |
|
---|
160 | @param Enabled Enable or disable the wakeup alarm.
|
---|
161 | @param Time If Enable is TRUE, the time to set the wakeup alarm for.
|
---|
162 |
|
---|
163 | @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled. If
|
---|
164 | Enable is FALSE, then the wakeup alarm was disabled.
|
---|
165 | @retval EFI_INVALID_PARAMETER Enabled is NULL.
|
---|
166 | @retval EFI_INVALID_PARAMETER Pending is NULL.
|
---|
167 | @retval EFI_INVALID_PARAMETER Time is NULL.
|
---|
168 | @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
|
---|
169 | @retval EFI_UNSUPPORTED This call is not supported by this platform at the time the call is made.
|
---|
170 | The platform should describe this runtime service as unsupported at runtime
|
---|
171 | via an EFI_RT_PROPERTIES_TABLE configuration table.
|
---|
172 |
|
---|
173 | **/
|
---|
174 | EFI_STATUS
|
---|
175 | EFIAPI
|
---|
176 | LibSetWakeupTime (
|
---|
177 | IN BOOLEAN Enabled,
|
---|
178 | OUT EFI_TIME *Time
|
---|
179 | )
|
---|
180 | {
|
---|
181 | return EFI_UNSUPPORTED;
|
---|
182 | }
|
---|
183 |
|
---|
184 | /**
|
---|
185 | This is the declaration of an EFI image entry point. This can be the entry point to an application
|
---|
186 | written to this specification, an EFI boot service driver, or an EFI runtime driver.
|
---|
187 |
|
---|
188 | @param ImageHandle Handle that identifies the loaded image.
|
---|
189 | @param SystemTable System Table for this image.
|
---|
190 |
|
---|
191 | @retval EFI_SUCCESS The operation completed successfully.
|
---|
192 |
|
---|
193 | **/
|
---|
194 | EFI_STATUS
|
---|
195 | EFIAPI
|
---|
196 | LibRtcInitialize (
|
---|
197 | IN EFI_HANDLE ImageHandle,
|
---|
198 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
199 | )
|
---|
200 | {
|
---|
201 | return EFI_SUCCESS;
|
---|
202 | }
|
---|