]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/PcRtc/Ipf/IpfPcRtc.c
ef2260b214437dd6b817ef3c69e80bc969408c7a
[mirror_edk2.git] / DuetPkg / PcRtc / Ipf / IpfPcRtc.c
1 /*++
2
3 Copyright (c) 2005, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13 IpfPcRtc.c
14
15 Abstract:
16 Register the extended SAL infrastructure.
17
18 Make the EFI RT APIs call extended SAL calls via the RT lib wrappers.
19 We can not do this on IA-32 as RT lib wrappers call via rRT.
20
21 --*/
22
23 #include "RealTimeClock.h"
24
25 //
26 // Don't use directly after virtual address have been registered.
27 //
28 static PC_RTC_MODULE_GLOBALS mModuleGlobal;
29
30 SAL_RETURN_REGS
31 PcRtcEsalServicesClassCommonEntry (
32 IN UINT64 FunctionId,
33 IN UINT64 Arg2,
34 IN UINT64 Arg3,
35 IN UINT64 Arg4,
36 IN UINT64 Arg5,
37 IN UINT64 Arg6,
38 IN UINT64 Arg7,
39 IN UINT64 Arg8,
40 IN SAL_EXTENDED_SAL_PROC ExtendedSalProc,
41 IN BOOLEAN VirtualMode,
42 IN PC_RTC_MODULE_GLOBALS *Global
43 )
44 /*++
45
46 Routine Description:
47
48 Main entry for Extended SAL Reset Services
49
50 Arguments:
51
52 FunctionId Function Id which needed to be called.
53 Arg2 EFI_RESET_TYPE, whether WARM of COLD reset
54 Arg3 Last EFI_STATUS
55 Arg4 Data Size of UNICODE STRING passed in ARG5
56 Arg5 Unicode String which CHAR16*
57
58 Returns:
59
60 SAL_RETURN_REGS
61
62 --*/
63 // TODO: Arg6 - add argument and description to function comment
64 // TODO: Arg7 - add argument and description to function comment
65 // TODO: Arg8 - add argument and description to function comment
66 // TODO: ExtendedSalProc - add argument and description to function comment
67 // TODO: VirtualMode - add argument and description to function comment
68 // TODO: Global - add argument and description to function comment
69 {
70 EFI_STATUS EfiStatus;
71 SAL_RETURN_REGS ReturnVal;
72
73 switch (FunctionId) {
74 case GetTime:
75 EfiStatus = PcRtcGetTime ((EFI_TIME *) Arg2, (EFI_TIME_CAPABILITIES *) Arg3, Global);
76 break;
77
78 case SetTime:
79 EfiStatus = PcRtcSetTime ((EFI_TIME *) Arg2, Global);
80 break;
81
82 case GetWakeupTime:
83 EfiStatus = PcRtcGetWakeupTime ((BOOLEAN *) Arg2, (BOOLEAN *) Arg3, (EFI_TIME *) Arg4, Global);
84 break;
85
86 case SetWakeupTime:
87 EfiStatus = PcRtcSetWakeupTime ((BOOLEAN) Arg2, (EFI_TIME *) Arg3, Global);
88 break;
89
90 case InitializeThreshold:
91 EfiStatus = EFI_SAL_NOT_IMPLEMENTED;
92 break;
93
94 case BumpThresholdCount:
95 EfiStatus = EFI_SAL_NOT_IMPLEMENTED;
96 break;
97
98 case GetThresholdCount:
99 EfiStatus = EFI_SAL_NOT_IMPLEMENTED;
100 break;
101
102 case GetRtcFreq:
103 EfiStatus = EFI_SAL_NOT_IMPLEMENTED;
104 break;
105
106 default:
107 EfiStatus = EFI_SAL_INVALID_ARGUMENT;
108 break;;
109 }
110
111 ReturnVal.Status = EfiStatus;
112 return ReturnVal;
113 }
114
115 EFI_STATUS
116 EFIAPI
117 InitializePcRtc (
118 IN EFI_HANDLE ImageHandle,
119 IN EFI_SYSTEM_TABLE *SystemTable
120 )
121 /*++
122
123 Routine Description:
124
125 Arguments:
126
127
128
129 Returns:
130 --*/
131 // TODO: ImageHandle - add argument and description to function comment
132 // TODO: SystemTable - add argument and description to function comment
133 // TODO: EFI_SUCCESS - add return value to function comment
134 {
135 EFI_TIME Time;
136 EFI_TIME_CAPABILITIES Capabilities;
137 EFI_STATUS EfiStatus;
138
139 EfiInitializeRuntimeDriverLib (ImageHandle, SystemTable, NULL);
140
141 EfiInitializeLock (&mModuleGlobal.RtcLock, EFI_TPL_HIGH_LEVEL);
142
143 EfiStatus = PcRtcInit (&mModuleGlobal);
144 if (EFI_ERROR (EfiStatus)) {
145 return EfiStatus;
146 }
147
148 RegisterEsalClass (
149 &gEfiExtendedSalRtcServicesProtocolGuid,
150 &mModuleGlobal,
151 PcRtcEsalServicesClassCommonEntry,
152 GetTime,
153 PcRtcEsalServicesClassCommonEntry,
154 SetTime,
155 PcRtcEsalServicesClassCommonEntry,
156 GetWakeupTime,
157 PcRtcEsalServicesClassCommonEntry,
158 SetWakeupTime,
159 PcRtcEsalServicesClassCommonEntry,
160 GetRtcFreq,
161 PcRtcEsalServicesClassCommonEntry,
162 InitializeThreshold,
163 PcRtcEsalServicesClassCommonEntry,
164 BumpThresholdCount,
165 PcRtcEsalServicesClassCommonEntry,
166 GetThresholdCount,
167 NULL
168 );
169 //
170 // the following code is to initialize the RTC fields in case the values read
171 // back from CMOS are invalid at the first time.
172 //
173 EfiStatus = PcRtcGetTime (&Time, &Capabilities, &mModuleGlobal);
174 if (EFI_ERROR (EfiStatus)) {
175 Time.Second = RTC_INIT_SECOND;
176 Time.Minute = RTC_INIT_MINUTE;
177 Time.Hour = RTC_INIT_HOUR;
178 Time.Day = RTC_INIT_DAY;
179 Time.Month = RTC_INIT_MONTH;
180 Time.Year = RTC_INIT_YEAR;
181 PcRtcSetTime (&Time, &mModuleGlobal);
182 }
183
184 return EFI_SUCCESS;
185 }