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