ReactOS 0.4.15-dev-5893-g1bb4167
cmos.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS HAL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: CMOS Access Routines (Real Time Clock and LastKnownGood)
5 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
6 * Eric Kohl
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <hal.h>
12
13#define NDEBUG
14#include <debug.h>
15
16/* GLOBALS *******************************************************************/
17
19
20/* PRIVATE FUNCTIONS *********************************************************/
21
26{
27 /* Select the register */
29
30 /* Query the value */
32}
33
35VOID
39{
40 /* Select the register */
42
43 /* Write the value */
45}
46
54{
58
59 /* Do nothing if we don't have a length */
60 if (!Length) return 0;
61
62 /* Acquire CMOS Lock */
64
65 /* Check if this is simple CMOS */
66 if (BusNumber == 0)
67 {
68 /* Loop the buffer up to 0xFF */
69 while ((Len > 0) && (Address < 0x100))
70 {
71 /* Read the data */
73
74 /* Update position and length */
75 Ptr++;
76 Address++;
77 Len--;
78 }
79 }
80 else if (BusNumber == 1)
81 {
82 /* Loop the buffer up to 0xFFFF */
83 while ((Len > 0) && (Address < 0x10000))
84 {
85 /* Write the data */
87
88 /* Update position and length */
89 Ptr++;
90 Address++;
91 Len--;
92 }
93 }
94
95 /* Release CMOS Lock */
97
98 /* Return length read */
99 return Length - Len;
100}
101
102ULONG
103NTAPI
108{
111 ULONG Len = Length;
112
113 /* Do nothing if we don't have a length */
114 if (!Length) return 0;
115
116 /* Acquire CMOS Lock */
118
119 /* Check if this is simple CMOS */
120 if (BusNumber == 0)
121 {
122 /* Loop the buffer up to 0xFF */
123 while ((Len > 0) && (Address < 0x100))
124 {
125 /* Write the data */
127
128 /* Update position and length */
129 Ptr++;
130 Address++;
131 Len--;
132 }
133 }
134 else if (BusNumber == 1)
135 {
136 /* Loop the buffer up to 0xFFFF */
137 while ((Len > 0) && (Address < 0x10000))
138 {
139 /* Write the data */
141
142 /* Update position and length */
143 Ptr++;
144 Address++;
145 Len--;
146 }
147 }
148
149 /* Release CMOS Lock */
151
152 /* Return length read */
153 return Length - Len;
154}
155
156CODE_SEG("INIT")
157VOID
158NTAPI
160{
161 /* Set default century offset byte */
163
164 /* No support for EISA or MCA */
166}
167
168/* PUBLIC FUNCTIONS **********************************************************/
169
170/*
171 * @implemented
172 */
174NTAPI
176 _In_ PCH Name,
179{
180 UCHAR Val;
181
182 /* Only variable supported on x86 */
183 if (_stricmp(Name, "LastKnownGood")) return ENOENT;
184
185 /* Acquire CMOS Lock */
187
188 /* Query the current value */
189 Val = HalpReadCmos(RTC_REGISTER_B) & 0x01;
190
191 /* Release CMOS lock */
193
194 /* Check the flag */
195 if (Val)
196 {
197 /* Return false */
198 strncpy(Value, "FALSE", ValueLength);
199 }
200 else
201 {
202 /* Return true */
203 strncpy(Value, "TRUE", ValueLength);
204 }
205
206 /* Return success */
207 return ESUCCESS;
208}
209
210/*
211 * @implemented
212 */
214NTAPI
216 IN PCH Value)
217{
218 UCHAR Val;
219
220 /* Only variable supported on x86 */
221 if (_stricmp(Name, "LastKnownGood")) return ENOMEM;
222
223 /* Check if this is true or false */
224 if (!_stricmp(Value, "TRUE"))
225 {
226 /* It's true, acquire CMOS lock */
228
229 /* Read the current value and add the flag */
230 Val = HalpReadCmos(RTC_REGISTER_B) | 1;
231 }
232 else if (!_stricmp(Value, "FALSE"))
233 {
234 /* It's false, acquire CMOS lock */
236
237 /* Read the current value and mask out the flag */
238 Val = HalpReadCmos(RTC_REGISTER_B) & ~1;
239 }
240 else
241 {
242 /* Fail */
243 return ENOMEM;
244 }
245
246 /* Write new value */
248
249 /* Release the lock and return success */
251 return ESUCCESS;
252}
253
254/*
255 * @implemented
256 */
258NTAPI
260{
261 /* Acquire CMOS Lock */
263
264 /* Loop while update is in progress */
266
267 /* Set the time data */
268 Time->Second = BCD_INT(HalpReadCmos(0));
269 Time->Minute = BCD_INT(HalpReadCmos(2));
270 Time->Hour = BCD_INT(HalpReadCmos(4));
271 Time->Weekday = BCD_INT(HalpReadCmos(6));
272 Time->Day = BCD_INT(HalpReadCmos(7));
273 Time->Month = BCD_INT(HalpReadCmos(8));
274 Time->Year = BCD_INT(HalpReadCmos(9));
275 Time->Milliseconds = 0;
276
277 /* FIXME: Check century byte */
278
279 /* Compensate for the century field */
280 Time->Year += (Time->Year > 80) ? 1900: 2000;
281
282 /* Release CMOS lock */
284
285 /* Always return TRUE */
286 return TRUE;
287}
288
289/*
290 * @implemented
291 */
293NTAPI
295{
296 /* Acquire CMOS Lock */
298
299 /* Loop while update is in progress */
301
302 /* Write time fields to CMOS RTC */
303 HalpWriteCmos(0, INT_BCD(Time->Second));
304 HalpWriteCmos(2, INT_BCD(Time->Minute));
305 HalpWriteCmos(4, INT_BCD(Time->Hour));
306 HalpWriteCmos(6, INT_BCD(Time->Weekday));
307 HalpWriteCmos(7, INT_BCD(Time->Day));
308 HalpWriteCmos(8, INT_BCD(Time->Month));
309 HalpWriteCmos(9, INT_BCD(Time->Year % 100));
310
311 /* FIXME: Set the century byte */
312
313 /* Release CMOS lock */
315
316 /* Always return TRUE */
317 return TRUE;
318}
unsigned char BOOLEAN
#define ENOENT
Definition: acclib.h:79
#define ENOMEM
Definition: acclib.h:84
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
ULONG HalpBusType
Definition: pcibus.c:18
#define _stricmp
Definition: cat.c:22
Definition: bufpool.h:45
#define _Requires_lock_held_(lock)
#define Len
Definition: deflate.h:82
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
ULONG NTAPI HalpSetCmosData(IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Length)
Definition: cmos.c:104
BOOLEAN NTAPI HalQueryRealTimeClock(OUT PTIME_FIELDS Time)
Definition: cmos.c:259
ARC_STATUS NTAPI HalGetEnvironmentVariable(_In_ PCH Name, _In_ USHORT ValueLength, _Out_writes_z_(ValueLength) PCH Value)
Definition: cmos.c:175
VOID NTAPI HalpInitializeCmos(VOID)
Definition: cmos.c:159
BOOLEAN NTAPI HalSetRealTimeClock(IN PTIME_FIELDS Time)
Definition: cmos.c:294
ARC_STATUS NTAPI HalSetEnvironmentVariable(IN PCH Name, IN PCH Value)
Definition: cmos.c:215
ULONG NTAPI HalpGetCmosData(_In_ ULONG BusNumber, _In_ ULONG SlotNumber, _Out_writes_bytes_(Length) PVOID Buffer, _In_ ULONG Length)
Definition: cmos.c:49
UCHAR HalpCmosCenturyOffset
Definition: cmos.c:18
KSPIN_LOCK HalpSystemHardwareLock
Definition: spinlock.c:25
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:243
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:226
VOID NTAPI HalpWriteCmos(_In_ UCHAR Reg, _In_ UCHAR Value)
Definition: cmos.c:132
UCHAR NTAPI HalpReadCmos(_In_ UCHAR Reg)
Definition: cmos.c:123
#define RTC_REGISTER_B
Definition: halhw.h:15
#define CMOS_CONTROL_PORT
Definition: halhw.h:11
#define CMOS_DATA_PORT
Definition: halhw.h:12
#define INT_BCD(int)
Definition: halp.h:59
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
#define ASSERT(a)
Definition: mode.c:44
static PLARGE_INTEGER Time
Definition: time.c:105
#define _Out_writes_z_(size)
Definition: ms_sal.h:352
#define _Out_writes_bytes_(size)
Definition: ms_sal.h:350
#define _In_
Definition: ms_sal.h:308
#define MACHINE_TYPE_ISA
Definition: ketypes.h:52
CHAR * PCH
Definition: ntbasedef.h:391
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define BCD_INT(bcd)
Definition: hwinfo.c:13
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21
unsigned short USHORT
Definition: pedump.c:61
static WCHAR Address[46]
Definition: ping.c:68
@ ESUCCESS
Definition: arc.h:32
ULONG ARC_STATUS
Definition: arc.h:4
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:275
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:68
#define RTC_REG_A_UIP
Definition: xboxrtc.c:22
#define RTC_REGISTER_A
Definition: xboxrtc.c:21
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160
unsigned char UCHAR
Definition: xmlstorage.h:181