]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / 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
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
18STATIC\r
19VOID\r
20EpochToEfiTime (\r
21 IN UINTN EpochSeconds,\r
22 OUT EFI_TIME *Time\r
23 )\r
24{\r
ac0a286f
MK
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
2ac5866c
AB
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
a9255967 56 Time->Year = (UINT16)(y - 4800 + ((m + 2) / 12));\r
2ac5866c 57 Time->Month = ((m + 2) % 12) + 1;\r
a9255967 58 Time->Day = (UINT8)(d + 1);\r
2ac5866c
AB
59\r
60 ss = EpochSeconds % 60;\r
61 a = (EpochSeconds - ss) / 60;\r
62 mm = a % 60;\r
ac0a286f 63 b = (a - mm) / 60;\r
2ac5866c
AB
64 hh = b % 24;\r
65\r
ac0a286f
MK
66 Time->Hour = (UINT8)hh;\r
67 Time->Minute = (UINT8)mm;\r
68 Time->Second = (UINT8)ss;\r
69 Time->Nanosecond = 0;\r
2ac5866c
AB
70}\r
71\r
72/**\r
73 Returns the current time and date information, and the time-keeping capabilities\r
74 of the hardware platform.\r
75\r
76 @param Time A pointer to storage to receive a snapshot of the current time.\r
77 @param Capabilities An optional pointer to a buffer to receive the real time clock\r
78 device's capabilities.\r
79\r
80 @retval EFI_SUCCESS The operation completed successfully.\r
81 @retval EFI_INVALID_PARAMETER Time is NULL.\r
82 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.\r
83\r
84**/\r
85EFI_STATUS\r
86EFIAPI\r
87LibGetTime (\r
88 OUT EFI_TIME *Time,\r
89 OUT EFI_TIME_CAPABILITIES *Capabilities\r
90 )\r
91{\r
92 ASSERT (Time != NULL);\r
93\r
94 //\r
95 // For now, there is nothing that we can do besides returning a bogus time,\r
96 // as Xen's timekeeping uses a shared info page which cannot be shared\r
97 // between UEFI and the OS\r
98 //\r
ac0a286f 99 EpochToEfiTime (1421770011, Time);\r
2ac5866c
AB
100\r
101 return EFI_SUCCESS;\r
102}\r
103\r
104/**\r
105 Sets the current local time and date information.\r
106\r
107 @param Time A pointer to the current time.\r
108\r
109 @retval EFI_SUCCESS The operation completed successfully.\r
110 @retval EFI_INVALID_PARAMETER A time field is out of range.\r
111 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.\r
112\r
113**/\r
114EFI_STATUS\r
115EFIAPI\r
116LibSetTime (\r
ac0a286f 117 IN EFI_TIME *Time\r
2ac5866c
AB
118 )\r
119{\r
120 return EFI_DEVICE_ERROR;\r
121}\r
122\r
2ac5866c
AB
123/**\r
124 Returns the current wakeup alarm clock setting.\r
125\r
126 @param Enabled Indicates if the alarm is currently enabled or disabled.\r
127 @param Pending Indicates if the alarm signal is pending and requires acknowledgement.\r
128 @param Time The current alarm setting.\r
129\r
130 @retval EFI_SUCCESS The alarm settings were returned.\r
131 @retval EFI_INVALID_PARAMETER Any parameter is NULL.\r
132 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.\r
133 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r
134\r
135**/\r
136EFI_STATUS\r
137EFIAPI\r
138LibGetWakeupTime (\r
ac0a286f
MK
139 OUT BOOLEAN *Enabled,\r
140 OUT BOOLEAN *Pending,\r
141 OUT EFI_TIME *Time\r
2ac5866c
AB
142 )\r
143{\r
144 return EFI_UNSUPPORTED;\r
145}\r
146\r
147/**\r
148 Sets the system wakeup alarm clock time.\r
149\r
150 @param Enabled Enable or disable the wakeup alarm.\r
151 @param Time If Enable is TRUE, the time to set the wakeup alarm for.\r
152\r
153 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled. If\r
154 Enable is FALSE, then the wakeup alarm was disabled.\r
155 @retval EFI_INVALID_PARAMETER A time field is out of range.\r
156 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.\r
157 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r
158\r
159**/\r
160EFI_STATUS\r
161EFIAPI\r
162LibSetWakeupTime (\r
ac0a286f
MK
163 IN BOOLEAN Enabled,\r
164 OUT EFI_TIME *Time\r
2ac5866c
AB
165 )\r
166{\r
167 return EFI_UNSUPPORTED;\r
168}\r
169\r
170/**\r
171 This is the declaration of an EFI image entry point. This can be the entry point to an application\r
172 written to this specification, an EFI boot service driver, or an EFI runtime driver.\r
173\r
174 @param ImageHandle Handle that identifies the loaded image.\r
175 @param SystemTable System Table for this image.\r
176\r
177 @retval EFI_SUCCESS The operation completed successfully.\r
178\r
179**/\r
180EFI_STATUS\r
181EFIAPI\r
182LibRtcInitialize (\r
ac0a286f
MK
183 IN EFI_HANDLE ImageHandle,\r
184 IN EFI_SYSTEM_TABLE *SystemTable\r
2ac5866c
AB
185 )\r
186{\r
187 return EFI_SUCCESS;\r
188}\r