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