ReactOS  0.4.14-dev-552-g2fad488
cmos.c File Reference
#include <hal.h>
#include <debug.h>
Include dependency graph for cmos.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

UCHAR FORCEINLINE HalpReadCmos (IN UCHAR Reg)
 
VOID FORCEINLINE HalpWriteCmos (IN UCHAR Reg, IN UCHAR Value)
 
ULONG NTAPI HalpGetCmosData (IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Length)
 
ULONG NTAPI HalpSetCmosData (IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Length)
 
ARC_STATUS NTAPI HalGetEnvironmentVariable (IN PCH Name, IN USHORT ValueLength, IN PCH Value)
 
ARC_STATUS NTAPI HalSetEnvironmentVariable (IN PCH Name, IN PCH Value)
 
BOOLEAN NTAPI HalQueryRealTimeClock (OUT PTIME_FIELDS Time)
 
BOOLEAN NTAPI HalSetRealTimeClock (IN PTIME_FIELDS Time)
 

Variables

KSPIN_LOCK HalpSystemHardwareLock
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file cmos.c.

Function Documentation

◆ HalGetEnvironmentVariable()

ARC_STATUS NTAPI HalGetEnvironmentVariable ( IN PCH  Name,
IN USHORT  ValueLength,
IN PCH  Value 
)

Definition at line 156 of file cmos.c.

159 {
160  UCHAR Val;
161 
162  /* Only variable supported on x86 */
163  if (_stricmp(Name, "LastKnownGood")) return ENOENT;
164 
165  /* FIXME: Acquire CMOS Lock */
166 
167  /* Query the current value */
168  Val = HalpReadCmos(RTC_REGISTER_B) & 0x01;
169 
170  /* FIXME: Release CMOS lock */
171 
172  /* Check the flag */
173  if (Val)
174  {
175  /* Return false */
176  strncpy(Value, "FALSE", ValueLength);
177  }
178  else
179  {
180  /* Return true */
181  strncpy(Value, "TRUE", ValueLength);
182  }
183 
184  /* Return success */
185  return ESUCCESS;
186 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
Definition: arc.h:32
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define _stricmp
Definition: cat.c:22
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
#define RTC_REGISTER_B
Definition: halp.h:17
unsigned char UCHAR
Definition: xmlstorage.h:181
_In_ GUID _In_ PVOID _In_ ULONG ValueLength
Definition: hubbusif.h:311
Definition: arc.h:46

◆ HalpGetCmosData()

ULONG NTAPI HalpGetCmosData ( IN ULONG  BusNumber,
IN ULONG  SlotNumber,
IN PVOID  Buffer,
IN ULONG  Length 
)

Definition at line 47 of file cmos.c.

51 {
54  ULONG Len = Length;
55 
56  /* FIXME: Acquire CMOS Lock */
57 
58  /* Do nothing if we don't have a length */
59  if (!Length) return 0;
60 
61  /* Check if this is simple CMOS */
62  if (!BusNumber)
63  {
64  /* Loop the buffer up to 0xFF */
65  while ((Len > 0) && (Address < 0x100))
66  {
67  /* Read the data */
69 
70  /* Update position and length */
71  Ptr++;
72  Address++;
73  Len--;
74  }
75  }
76  else if (BusNumber == 1)
77  {
78  /* Loop the buffer up to 0xFFFF */
79  while ((Len > 0) && (Address < 0x10000))
80  {
81  /* Write the data */
83 
84  /* Update position and length */
85  Ptr++;
86  Address++;
87  Len--;
88  }
89  }
90 
91  /* FIXME: Release the CMOS Lock */
92 
93  /* Return length read */
94  return Length - Len;
95 }
unsigned char * PUCHAR
Definition: retypes.h:3
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
static WCHAR Address[46]
Definition: ping.c:68
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
Definition: bufpool.h:45
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
#define Len
Definition: deflate.h:82
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG SlotNumber
Definition: halfuncs.h:156
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned int ULONG
Definition: retypes.h:1

Referenced by HalGetBusDataByOffset().

◆ HalpReadCmos()

UCHAR FORCEINLINE HalpReadCmos ( IN UCHAR  Reg)

Definition at line 24 of file cmos.c.

25 {
26  /* Select the register */
28 
29  /* Query the value */
31 }
#define CMOS_CONTROL_PORT
Definition: halp.h:14
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:528
#define CMOS_DATA_PORT
Definition: halp.h:15
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:532

Referenced by HalGetEnvironmentVariable(), HalpClockInterruptHandler(), HalpGetCmosData(), HalpInitializeClock(), HalpInitializeTsc(), HalQueryRealTimeClock(), HalSetEnvironmentVariable(), HalSetRealTimeClock(), HalStartProfileInterrupt(), HalStopProfileInterrupt(), and RtcSetClockRate().

◆ HalpSetCmosData()

ULONG NTAPI HalpSetCmosData ( IN ULONG  BusNumber,
IN ULONG  SlotNumber,
IN PVOID  Buffer,
IN ULONG  Length 
)

Definition at line 99 of file cmos.c.

103 {
104  PUCHAR Ptr = (PUCHAR)Buffer;
106  ULONG Len = Length;
107 
108  /* FIXME: Acquire CMOS Lock */
109 
110  /* Do nothing if we don't have a length */
111  if (!Length) return 0;
112 
113  /* Check if this is simple CMOS */
114  if (!BusNumber)
115  {
116  /* Loop the buffer up to 0xFF */
117  while ((Len > 0) && (Address < 0x100))
118  {
119  /* Write the data */
121 
122  /* Update position and length */
123  Ptr++;
124  Address++;
125  Len--;
126  }
127  }
128  else if (BusNumber == 1)
129  {
130  /* Loop the buffer up to 0xFFFF */
131  while ((Len > 0) && (Address < 0x10000))
132  {
133  /* Write the data */
135 
136  /* Update position and length */
137  Ptr++;
138  Address++;
139  Len--;
140  }
141  }
142 
143  /* FIXME: Release the CMOS Lock */
144 
145  /* Return length read */
146  return Length - Len;
147 }
VOID FORCEINLINE HalpWriteCmos(IN UCHAR Reg, IN UCHAR Value)
Definition: cmos.c:35
unsigned char * PUCHAR
Definition: retypes.h:3
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
static WCHAR Address[46]
Definition: ping.c:68
Definition: bufpool.h:45
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
#define Len
Definition: deflate.h:82
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG SlotNumber
Definition: halfuncs.h:156
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned int ULONG
Definition: retypes.h:1

Referenced by HalSetBusDataByOffset().

◆ HalpWriteCmos()

VOID FORCEINLINE HalpWriteCmos ( IN UCHAR  Reg,
IN UCHAR  Value 
)

Definition at line 35 of file cmos.c.

37 {
38  /* Select the register */
40 
41  /* Write the value */
43 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define CMOS_CONTROL_PORT
Definition: halp.h:14
#define CMOS_DATA_PORT
Definition: halp.h:15
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:532

Referenced by HalpInitializeClock(), HalpInitializeTsc(), HalpSetCmosData(), HalSetEnvironmentVariable(), HalSetRealTimeClock(), HalStartProfileInterrupt(), HalStopProfileInterrupt(), and RtcSetClockRate().

◆ HalQueryRealTimeClock()

BOOLEAN NTAPI HalQueryRealTimeClock ( OUT PTIME_FIELDS  Time)

Definition at line 234 of file cmos.c.

235 {
236  /* FIXME: Acquire CMOS Lock */
237 
238  /* Loop while update is in progress */
240 
241  /* Set the time data */
242  Time->Second = BCD_INT(HalpReadCmos(0));
243  Time->Minute = BCD_INT(HalpReadCmos(2));
244  Time->Hour = BCD_INT(HalpReadCmos(4));
245  Time->Weekday = BCD_INT(HalpReadCmos(6));
246  Time->Day = BCD_INT(HalpReadCmos(7));
247  Time->Month = BCD_INT(HalpReadCmos(8));
248  Time->Year = BCD_INT(HalpReadCmos(9));
249  Time->Milliseconds = 0;
250 
251  /* FIXME: Check century byte */
252 
253  /* Compensate for the century field */
254  Time->Year += (Time->Year > 80) ? 1900: 2000;
255 
256  /* FIXME: Release CMOS Lock */
257 
258  /* Always return TRUE */
259  return TRUE;
260 }
#define TRUE
Definition: types.h:120
#define BCD_INT(bcd)
Definition: hwinfo.c:13
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
#define RTC_REGISTER_A
Definition: xboxrtc.c:21
#define RTC_REG_A_UIP
Definition: xboxrtc.c:22
static PLARGE_INTEGER Time
Definition: time.c:105

◆ HalSetEnvironmentVariable()

ARC_STATUS NTAPI HalSetEnvironmentVariable ( IN PCH  Name,
IN PCH  Value 
)

Definition at line 193 of file cmos.c.

195 {
196  UCHAR Val;
197 
198  /* Only variable supported on x86 */
199  if (_stricmp(Name, "LastKnownGood")) return ENOMEM;
200 
201  /* Check if this is true or false */
202  if (!_stricmp(Value, "TRUE"))
203  {
204  /* It's true, acquire CMOS lock (FIXME) */
205 
206  /* Read the current value and add the flag */
207  Val = HalpReadCmos(RTC_REGISTER_B) | 1;
208  }
209  else if (!_stricmp(Value, "FALSE"))
210  {
211  /* It's false, acquire CMOS lock (FIXME) */
212 
213  /* Read the current value and mask out the flag */
214  Val = HalpReadCmos(RTC_REGISTER_B) & ~1;
215  }
216  else
217  {
218  /* Fail */
219  return ENOMEM;
220  }
221 
222  /* Write new value */
224 
225  /* Release the lock and return success */
226  return ESUCCESS;
227 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
VOID FORCEINLINE HalpWriteCmos(IN UCHAR Reg, IN UCHAR Value)
Definition: cmos.c:35
Definition: arc.h:32
#define _stricmp
Definition: cat.c:22
Definition: arc.h:48
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
#define RTC_REGISTER_B
Definition: halp.h:17
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ HalSetRealTimeClock()

BOOLEAN NTAPI HalSetRealTimeClock ( IN PTIME_FIELDS  Time)

Definition at line 267 of file cmos.c.

268 {
269  /* FIXME: Acquire CMOS Lock */
270 
271  /* Loop while update is in progress */
273 
274  /* Write time fields to CMOS RTC */
275  HalpWriteCmos(0, INT_BCD(Time->Second));
276  HalpWriteCmos(2, INT_BCD(Time->Minute));
277  HalpWriteCmos(4, INT_BCD(Time->Hour));
278  HalpWriteCmos(6, INT_BCD(Time->Weekday));
279  HalpWriteCmos(7, INT_BCD(Time->Day));
280  HalpWriteCmos(8, INT_BCD(Time->Month));
281  HalpWriteCmos(9, INT_BCD(Time->Year % 100));
282 
283  /* FIXME: Set the century byte */
284 
285  /* FIXME: Release the CMOS Lock */
286 
287  /* Always return TRUE */
288  return TRUE;
289 }
VOID FORCEINLINE HalpWriteCmos(IN UCHAR Reg, IN UCHAR Value)
Definition: cmos.c:35
#define TRUE
Definition: types.h:120
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
#define RTC_REGISTER_A
Definition: xboxrtc.c:21
#define INT_BCD(int)
Definition: halp.h:31
#define RTC_REG_A_UIP
Definition: xboxrtc.c:22
static PLARGE_INTEGER Time
Definition: time.c:105

Variable Documentation

◆ HalpSystemHardwareLock

KSPIN_LOCK HalpSystemHardwareLock

Definition at line 18 of file cmos.c.

Referenced by HalInitSystem().