Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

424 lines
8.2 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. io_cmos.h
  5. Abstract:
  6. This module contains a variety of constants, function prototypes,
  7. inline functions and external data declarations used by code to
  8. access the CMOS/ECMOS and well-known, standard I/O ports.
  9. Author:
  10. Forrest Foltz (forrestf) 24-Oct-2000
  11. --*/
  12. #ifndef _IO_CMOS_H_
  13. #define _IO_CMOS_H_
  14. //
  15. // Constants used to initialize timer 0
  16. //
  17. #if defined(NEC_98)
  18. #define TIMER_CONTROL_PORT (PUCHAR)0x3fdf
  19. #define TIMER_DATA_PORT (PUCHAR)0x3fdb
  20. #define TIMER_CLOCK_IN 0x2457600
  21. #define TIMER_CONTROL_SELECT 0x76
  22. #define SPEAKER_CONTROL_PORT (PUCHAR)0x61
  23. #define SPEAKER_OFF 0x07
  24. #define SPEAKER_ON 0x06
  25. #else
  26. #define TIMER1_DATA_PORT0 (PUCHAR)0x40 // Timer1, channel 0 data port
  27. #define TIMER1_DATA_PORT1 (PUCHAR)0x41 // Timer1, channel 1 data port
  28. #define TIMER1_DATA_PORT2 (PUCHAR)0x42 // Timer1, channel 2 data port
  29. #define TIMER1_CONTROL_PORT (PUCHAR)0x43 // Timer1 control port
  30. #define TIMER2_DATA_PORT0 (PUCHAR)0x48 // Timer2, channel 0 data port
  31. #define TIMER2_CONTROL_PORT (PUCHAR)0x4B // Timer2 control port
  32. #define TIMER_COMMAND_COUNTER0 0x00 // Select channel 0
  33. #define TIMER_COMMAND_COUNTER1 0x40 // Select channel 1
  34. #define TIMER_COMMAND_COUNTER2 0x80 // Select channel 2
  35. #define TIMER_COMMAND_RW_16BIT 0x30 // Read/Write LSB firt then MSB
  36. #define TIMER_COMMAND_MODE2 4 // Use mode 2
  37. #define TIMER_COMMAND_MODE3 6
  38. #define TIMER_COMMAND_BCD 0 // Binary count down
  39. #define TIMER_COMMAND_LATCH_READ 0 // Latch read command
  40. #define TIMER_CLOCK_IN 1193167
  41. #define SPEAKER_CONTROL_PORT (PCHAR)0x61
  42. #define SPEAKER_OFF_MASK 0xFC
  43. #define SPEAKER_ON_MASK 0x03
  44. #endif
  45. //
  46. // CMOS ports
  47. //
  48. #define CMOS_ADDRESS_PORT (PCHAR)0x70
  49. #define CMOS_DATA_PORT (PCHAR)0x71
  50. #define ECMOS_ADDRESS_PORT_LSB (PCHAR)0x74
  51. #define ECMOS_ADDRESS_PORT_MSB (PCHAR)0x75
  52. #define ECMOS_DATA_PORT (PCHAR)0x76
  53. #define CMOS_STATUS_A 0x0A
  54. #define CMOS_STATUS_B 0x0B
  55. #define CMOS_STATUS_C 0x0C
  56. #define CMOS_STATUS_D 0x0D
  57. #define CMOS_STATUS_BUSY 0x80
  58. #define CMOS_STATUS_BANK1 0x10
  59. #define CMOS_BANK_1 0x100
  60. #define RTC_OFFSET_SECOND 0
  61. #define RTC_OFFSET_SECOND_ALARM 1
  62. #define RTC_OFFSET_MINUTE 2
  63. #define RTC_OFFSET_MINUTE_ALARM 3
  64. #define RTC_OFFSET_HOUR 4
  65. #define RTC_OFFSET_HOUR_ALARM 5
  66. #define RTC_OFFSET_DAY_OF_WEEK 6
  67. #define RTC_OFFSET_DATE_OF_MONTH 7
  68. #define RTC_OFFSET_MONTH 8
  69. #define RTC_OFFSET_YEAR 9
  70. #define RTC_OFFSET_CENTURY_MCA 0x37
  71. #define RTC_OFFSET_CENTURY 0x32
  72. #define RTC_OFFSET_CENTURY_DS 0x148
  73. #define REGISTER_B_DAYLIGHT_SAVINGS_TIME (1 << 0)
  74. #define REGISTER_B_24HOUR_MODE (1 << 1)
  75. #define REGISTER_B_ENABLE_ALARM_INTERRUPT (1 << 5)
  76. #define REGISTER_B_ENABLE_PERIODIC_INTERRUPT (1 << 6)
  77. VOID
  78. HalpIoDelay (
  79. VOID
  80. );
  81. #define IO_DELAY() HalpIoDelay()
  82. //
  83. // CMOS-related function prototypes
  84. //
  85. VOID
  86. HalpAcquireCmosSpinLockAndWait(
  87. VOID
  88. );
  89. //
  90. // Inline functions
  91. //
  92. __inline
  93. UCHAR
  94. BIN_TO_BCD (
  95. UCHAR Value
  96. )
  97. /*++
  98. Routine Description:
  99. This function converts an 8-bit binary value to an packed, 8-bit,
  100. two-digit BCD value.
  101. Arguments:
  102. Value - supplies the binary value to convert.
  103. Return Value:
  104. Returns a two-digit packed BCD representation of Value.
  105. --*/
  106. {
  107. UCHAR tens;
  108. UCHAR units;
  109. tens = Value / 10;
  110. units = Value % 10;
  111. return (tens << 4) + units;
  112. }
  113. __inline
  114. UCHAR
  115. BCD_TO_BIN (
  116. UCHAR Value
  117. )
  118. /*++
  119. Routine Description:
  120. This function converts a packed, 8-bit, two-digit BCD value to an
  121. 8-bit binary value.
  122. Arguments:
  123. Value - supplies the BCD value to convert.
  124. Return Value:
  125. Returns a binary representation of Value.
  126. --*/
  127. {
  128. UCHAR tens;
  129. UCHAR units;
  130. tens = (Value >> 4) & 0x0F;
  131. units = Value & 0x0F;
  132. return tens * 10 + units;
  133. }
  134. __inline
  135. UCHAR
  136. CMOS_READ (
  137. UCHAR Address
  138. )
  139. /*++
  140. Routine Description:
  141. This function reads a CMOS byte.
  142. Arguments:
  143. Address - supplies the CMOS address of the value to retrieve.
  144. Return Value:
  145. Returns the value residing in CMOS at Address.
  146. --*/
  147. {
  148. UCHAR data;
  149. UCHAR oldAddress;
  150. //
  151. // Record the current control port contents, write the address,
  152. // read the data, and restore the control port contents.
  153. //
  154. oldAddress = READ_PORT_UCHAR(CMOS_ADDRESS_PORT);
  155. WRITE_PORT_UCHAR(CMOS_ADDRESS_PORT,Address);
  156. IO_DELAY();
  157. data = READ_PORT_UCHAR(CMOS_DATA_PORT);
  158. WRITE_PORT_UCHAR(CMOS_ADDRESS_PORT,oldAddress);
  159. IO_DELAY();
  160. return data;
  161. }
  162. __inline
  163. VOID
  164. CMOS_WRITE (
  165. UCHAR Address,
  166. UCHAR Data
  167. )
  168. /*++
  169. Routine Description:
  170. This function writes a CMOS byte.
  171. Arguments:
  172. Address - supplies the CMOS address of the value to retrieve.
  173. Data - supplies the value to write at the supplied address.
  174. Return Value:
  175. None.
  176. --*/
  177. {
  178. UCHAR oldAddress;
  179. //
  180. // Record the current control port contents, write the address,
  181. // write the data, and restore the control port contents.
  182. //
  183. oldAddress = READ_PORT_UCHAR(CMOS_ADDRESS_PORT);
  184. WRITE_PORT_UCHAR(CMOS_ADDRESS_PORT,Address);
  185. IO_DELAY();
  186. WRITE_PORT_UCHAR(CMOS_DATA_PORT,Data);
  187. WRITE_PORT_UCHAR(CMOS_ADDRESS_PORT,oldAddress);
  188. IO_DELAY();
  189. }
  190. __inline
  191. UCHAR
  192. CMOS_READ_BCD (
  193. UCHAR Address
  194. )
  195. /*++
  196. Routine Description:
  197. This function reads a CMOS byte as a two-digit packed BCD value and
  198. returns its binary representation.
  199. Arguments:
  200. Address - supplies the CMOS address of the BCD value to retrieve.
  201. Return Value:
  202. Returns the binary representation of the BCD value residing in CMOS
  203. at Address.
  204. --*/
  205. {
  206. UCHAR value;
  207. value = CMOS_READ(Address);
  208. return BCD_TO_BIN(value);
  209. }
  210. __inline
  211. VOID
  212. CMOS_WRITE_BCD (
  213. UCHAR Address,
  214. UCHAR Value
  215. )
  216. /*++
  217. Routine Description:
  218. This function writes a CMOS byte as a two-digit packed BCD value.
  219. Arguments:
  220. Address - supplies the CMOS address of the BCD value to write.
  221. Value - supplies the binary representation of the value to write in
  222. CMOS.
  223. Return Value:
  224. None.
  225. --*/
  226. {
  227. UCHAR value;
  228. ASSERT(Value <= 99);
  229. value = BIN_TO_BCD(Value);
  230. CMOS_WRITE(Address,value);
  231. }
  232. __inline
  233. VOID
  234. WRITE_PORT_USHORT_PAIR (
  235. IN PUCHAR LsbPort,
  236. IN PUCHAR MsbPort,
  237. IN USHORT Value
  238. )
  239. /*++
  240. Routine Description:
  241. This function retrieves a USHORT value by reading two UCHAR values,
  242. each from one of two supplied 8 bit ports.
  243. NOTE - the LsbPort is read first, followed by the MsbPort.
  244. Arguments:
  245. LsbPort - supplies the port address from which to retrieve the
  246. least significant UCHAR value.
  247. MsbPort - supplies the port address from which to retrieve the
  248. most significant UCHAR value.
  249. Return Value:
  250. Returns the resultant USHORT value.
  251. --*/
  252. {
  253. WRITE_PORT_UCHAR(LsbPort,(UCHAR)Value);
  254. IO_DELAY();
  255. WRITE_PORT_UCHAR(MsbPort,(UCHAR)(Value >> 8));
  256. }
  257. __inline
  258. USHORT
  259. READ_PORT_USHORT_PAIR (
  260. IN PUCHAR LsbPort,
  261. IN PUCHAR MsbPort
  262. )
  263. /*++
  264. Routine Description:
  265. This function retrieves a USHORT value by reading two UCHAR values,
  266. each from one of two supplied 8 bit ports.
  267. NOTE - the LsbPort is read first, followed by the MsbPort.
  268. Arguments:
  269. LsbPort - supplies the port address from which to retrieve the
  270. least significant UCHAR value.
  271. MsbPort - supplies the port address from which to retrieve the
  272. most significant UCHAR value.
  273. Return Value:
  274. Returns the resultant USHORT value.
  275. --*/
  276. {
  277. UCHAR lsByte;
  278. UCHAR msByte;
  279. lsByte = READ_PORT_UCHAR(LsbPort);
  280. IO_DELAY();
  281. msByte = READ_PORT_UCHAR(MsbPort);
  282. return (USHORT)lsByte | ((USHORT)msByte << 8);
  283. }
  284. extern ULONG HalpCmosCenturyOffset;
  285. extern UCHAR HalpRtcRegA;
  286. extern UCHAR HalpRtcRegB;
  287. #endif