]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c
OvmfPkg: Apply uncrustify changes
[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 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
84 **/
85 EFI_STATUS
86 EFIAPI
87 LibGetTime (
88 OUT EFI_TIME *Time,
89 OUT EFI_TIME_CAPABILITIES *Capabilities
90 )
91 {
92 ASSERT (Time != NULL);
93
94 //
95 // For now, there is nothing that we can do besides returning a bogus time,
96 // as Xen's timekeeping uses a shared info page which cannot be shared
97 // between UEFI and the OS
98 //
99 EpochToEfiTime (1421770011, Time);
100
101 return EFI_SUCCESS;
102 }
103
104 /**
105 Sets the current local time and date information.
106
107 @param Time A pointer to the current time.
108
109 @retval EFI_SUCCESS The operation completed successfully.
110 @retval EFI_INVALID_PARAMETER A time field is out of range.
111 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
112
113 **/
114 EFI_STATUS
115 EFIAPI
116 LibSetTime (
117 IN EFI_TIME *Time
118 )
119 {
120 return EFI_DEVICE_ERROR;
121 }
122
123 /**
124 Returns the current wakeup alarm clock setting.
125
126 @param Enabled Indicates if the alarm is currently enabled or disabled.
127 @param Pending Indicates if the alarm signal is pending and requires acknowledgement.
128 @param Time The current alarm setting.
129
130 @retval EFI_SUCCESS The alarm settings were returned.
131 @retval EFI_INVALID_PARAMETER Any parameter is NULL.
132 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
133 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
134
135 **/
136 EFI_STATUS
137 EFIAPI
138 LibGetWakeupTime (
139 OUT BOOLEAN *Enabled,
140 OUT BOOLEAN *Pending,
141 OUT EFI_TIME *Time
142 )
143 {
144 return EFI_UNSUPPORTED;
145 }
146
147 /**
148 Sets the system wakeup alarm clock time.
149
150 @param Enabled Enable or disable the wakeup alarm.
151 @param Time If Enable is TRUE, the time to set the wakeup alarm for.
152
153 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled. If
154 Enable is FALSE, then the wakeup alarm was disabled.
155 @retval EFI_INVALID_PARAMETER A time field is out of range.
156 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
157 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
158
159 **/
160 EFI_STATUS
161 EFIAPI
162 LibSetWakeupTime (
163 IN BOOLEAN Enabled,
164 OUT EFI_TIME *Time
165 )
166 {
167 return EFI_UNSUPPORTED;
168 }
169
170 /**
171 This is the declaration of an EFI image entry point. This can be the entry point to an application
172 written to this specification, an EFI boot service driver, or an EFI runtime driver.
173
174 @param ImageHandle Handle that identifies the loaded image.
175 @param SystemTable System Table for this image.
176
177 @retval EFI_SUCCESS The operation completed successfully.
178
179 **/
180 EFI_STATUS
181 EFIAPI
182 LibRtcInitialize (
183 IN EFI_HANDLE ImageHandle,
184 IN EFI_SYSTEM_TABLE *SystemTable
185 )
186 {
187 return EFI_SUCCESS;
188 }