Leaked source code of windows server 2003
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.

608 lines
10 KiB

  1. /*++
  2. Copyright (c) 1995 Intel Corporation
  3. Module Name:
  4. i64ioacc.c
  5. Abstract:
  6. This module implements the I/O Register access routines.
  7. Author:
  8. Bernard Lint, M. Jayakumar Sep 16 '97
  9. Environment:
  10. Kernel mode
  11. Revision History:
  12. --*/
  13. #pragma warning(disable:4200) // unsized array in halp
  14. #include "halp.h"
  15. #include "kxia64.h"
  16. extern ULONGLONG IoPortPhysicalBase;
  17. ULONGLONG HalpGetPortVirtualAddress(
  18. UINT_PTR Port
  19. )
  20. {
  21. /*++
  22. Routine Description:
  23. This routine gives 32 bit virtual address for the I/O Port specified.
  24. Arguements:
  25. PORT - Supplies PORT address of the I/O PORT.
  26. Returned Value:
  27. PUCHAR - 32bit virtual address value.
  28. --*/
  29. //
  30. // PUCHAR VirtualIOBase;
  31. //
  32. UINT_PTR ShiftedPort,PortIndex;
  33. //
  34. // Shifting operation applicable to integrals only. ULONG for 32 bits
  35. //
  36. ShiftedPort = (UINT_PTR)Port;
  37. //
  38. // Limit arguement PORT to 16 bit quantity
  39. //
  40. ShiftedPort = ShiftedPort & IO_PORT_MASK;
  41. //
  42. // Capture bits [11:0]
  43. //
  44. PortIndex = ShiftedPort & BYTE_ADDRESS_MASK;
  45. //
  46. // Position it to point to 32 bit boundary
  47. //
  48. ShiftedPort = ShiftedPort & BYTE_ADDRESS_CLEAR;
  49. //
  50. // Shifted to page boundary. ShiftedPORT[[1:0] are zero.
  51. // PORT[15:2] shifted to ShiftedPort[25:12]
  52. //
  53. ShiftedPort = ShiftedPort << 10;
  54. //
  55. // Bits 1:0 has now 4 byte PORT address
  56. //
  57. ShiftedPort = ShiftedPort | PortIndex;
  58. // return (VIRTUAL_IO_BASE | ShiftedPort);
  59. //
  60. // Assume 1-to-to mapping of IO ports.
  61. //
  62. if (IsPsrDtOn()) {
  63. return (VIRTUAL_IO_BASE | ShiftedPort);
  64. } else {
  65. return (IoPortPhysicalBase | ShiftedPort | 0x8000000000000000);
  66. }
  67. }
  68. VOID
  69. HalpFillTbForIOPortSpace(
  70. ULONGLONG PhysicalAddress,
  71. UINT_PTR VirtualAddress,
  72. ULONG SlotNumber
  73. )
  74. {
  75. /*++
  76. Routine Description:
  77. This routine fills the translation buffer for the translation requested
  78. Arguements:
  79. PhysicalAddress - Supplies Physical Address to be mapped for the virtual
  80. address.
  81. VirtualAddress - Supplies Virtual Address.
  82. SlotNumber - Slot number of the Translation Buffer to be used.
  83. --*/
  84. ULONGLONG IITR,Attribute;
  85. UINT_PTR IFA;
  86. IFA = VirtualAddress;
  87. IITR = PhysicalAddress & IITR_PPN_MASK;
  88. IITR = IITR | (IO_SPACE_SIZE << IDTR_PS);
  89. Attribute = PhysicalAddress & IITR_ATTRIBUTE_PPN_MASK;
  90. Attribute = Attribute | IO_SPACE_ATTRIBUTE;
  91. HalpInsertTranslationRegister(IFA,SlotNumber,Attribute,IITR);
  92. return;
  93. }
  94. UCHAR
  95. READ_PORT_UCHAR(
  96. PUCHAR Port
  97. )
  98. {
  99. /*++
  100. Routine Description:
  101. Reads a byte location from the PORT
  102. Arguements:
  103. PORT - Supplies the PORT address to read from
  104. Return Value:
  105. UCHAR - Returns the byte read from the PORT specified.
  106. --*/
  107. ULONGLONG VirtualPort;
  108. UCHAR LoadData;
  109. VirtualPort = HalpGetPortVirtualAddress((UINT_PTR)Port);
  110. __mf();
  111. LoadData = *(volatile UCHAR *)VirtualPort;
  112. __mfa();
  113. return (LoadData);
  114. }
  115. USHORT
  116. READ_PORT_USHORT (
  117. PUSHORT Port
  118. )
  119. {
  120. /*++
  121. Routine Description:
  122. Reads a word location (16 bit unsigned value) from the PORT
  123. Arguements:
  124. PORT - Supplies the PORT address to read from.
  125. Returned Value:
  126. USHORT - Returns the 16 bit unsigned value from the PORT specified.
  127. --*/
  128. ULONGLONG VirtualPort;
  129. USHORT LoadData;
  130. VirtualPort = HalpGetPortVirtualAddress((UINT_PTR)Port);
  131. __mf();
  132. LoadData = *(volatile USHORT *)VirtualPort;
  133. __mfa();
  134. return (LoadData);
  135. }
  136. ULONG
  137. READ_PORT_ULONG (
  138. PULONG Port
  139. )
  140. {
  141. /*++
  142. Routine Description:
  143. Reads a longword location (32bit unsigned value) from the PORT.
  144. Arguements:
  145. PORT - Supplies PORT address to read from.
  146. Returned Value:
  147. ULONG - Returns the 32 bit unsigned value (ULONG) from the PORT specified.
  148. --*/
  149. ULONGLONG VirtualPort;
  150. ULONG LoadData;
  151. VirtualPort = HalpGetPortVirtualAddress((UINT_PTR)Port);
  152. __mf();
  153. LoadData = *(volatile ULONG *)VirtualPort;
  154. __mfa();
  155. return (LoadData);
  156. }
  157. VOID
  158. READ_PORT_BUFFER_UCHAR (
  159. PUCHAR Port,
  160. PUCHAR Buffer,
  161. ULONG Count
  162. )
  163. {
  164. /*++
  165. Routine Description:
  166. Reads multiple bytes from the specified PORT address into the
  167. destination buffer.
  168. Arguements:
  169. PORT - The address of the PORT to read from.
  170. Buffer - A pointer to the buffer to fill with the data read from the PORT.
  171. Count - Supplies the number of bytes to read.
  172. Return Value:
  173. None.
  174. --*/
  175. ULONGLONG VirtualPort;
  176. //
  177. // PUCHAR ReadBuffer = Buffer;
  178. //
  179. //
  180. // ULONG ReadCount;
  181. //
  182. VirtualPort = HalpGetPortVirtualAddress((UINT_PTR)Port);
  183. HalpLoadBufferUCHAR((PUCHAR)VirtualPort, Buffer, Count);
  184. }
  185. VOID
  186. READ_PORT_BUFFER_USHORT (
  187. PUSHORT Port,
  188. PUSHORT Buffer,
  189. ULONG Count
  190. )
  191. {
  192. /*++
  193. Routine Description:
  194. Reads multiple words (16bits) from the speicified PORT address into
  195. the destination buffer.
  196. Arguements:
  197. Port - Supplies the address of the PORT to read from.
  198. Buffer - A pointer to the buffer to fill with the data
  199. read from the PORT.
  200. Count - Supplies the number of words to read.
  201. --*/
  202. ULONGLONG VirtualPort;
  203. //
  204. // PUSHORT ReadBuffer = Buffer;
  205. // ULONG ReadCount;
  206. //
  207. VirtualPort = HalpGetPortVirtualAddress((UINT_PTR)Port);
  208. //
  209. // We don't need memory fence in between INs?.
  210. // So, it is out of the loop to improve performance.
  211. //
  212. HalpLoadBufferUSHORT((PUSHORT)VirtualPort, Buffer, Count);
  213. }
  214. VOID
  215. READ_PORT_BUFFER_ULONG (
  216. PULONG Port,
  217. PULONG Buffer,
  218. ULONG Count
  219. )
  220. {
  221. /*++
  222. Routine Description:
  223. Reads multiple longwords (32bits) from the speicified PORT
  224. address into the destination buffer.
  225. Arguements:
  226. Port - Supplies the address of the PORT to read from.
  227. Buffer - A pointer to the buffer to fill with the data
  228. read from the PORT.
  229. Count - Supplies the number of long words to read.
  230. --*/
  231. ULONGLONG VirtualPort;
  232. VirtualPort = HalpGetPortVirtualAddress((UINT_PTR)Port);
  233. //
  234. // We don't need memory fence in between INs.
  235. // So, it is out of the loop to improve performance.
  236. //
  237. HalpLoadBufferULONG((PULONG)VirtualPort, Buffer,Count);
  238. }
  239. VOID
  240. WRITE_PORT_UCHAR (
  241. PUCHAR Port,
  242. UCHAR Value
  243. )
  244. {
  245. /*++
  246. Routine Description:
  247. Writes a byte to the Port specified.
  248. Arguements:
  249. Port - The port address of the I/O Port.
  250. Value - The value to be written to the I/O Port.
  251. Return Value:
  252. None.
  253. --*/
  254. ULONGLONG VirtualPort;
  255. VirtualPort = HalpGetPortVirtualAddress((UINT_PTR)Port);
  256. *(volatile UCHAR *)VirtualPort = Value;
  257. __mf();
  258. __mfa();
  259. }
  260. VOID
  261. WRITE_PORT_USHORT (
  262. PUSHORT Port,
  263. USHORT Value
  264. )
  265. {
  266. /*++
  267. Routine Description:
  268. Writes a 16 bit SHORT Integer to the Port specified.
  269. Arguements:
  270. Port - The port address of the I/O Port.
  271. Value - The value to be written to the I/O Port.
  272. Return Value:
  273. None.
  274. --*/
  275. ULONGLONG VirtualPort;
  276. VirtualPort = HalpGetPortVirtualAddress((UINT_PTR)Port);
  277. *(volatile USHORT *)VirtualPort = Value;
  278. __mf();
  279. __mfa();
  280. }
  281. VOID
  282. WRITE_PORT_ULONG (
  283. PULONG Port,
  284. ULONG Value
  285. )
  286. {
  287. /*++
  288. Routine Description:
  289. Writes a 32 bit Long Word to the Port specified.
  290. Arguements:
  291. Port - The port address of the I/O Port.
  292. Value - The value to be written to the I/O Port.
  293. Return Value:
  294. None.
  295. --*/
  296. ULONGLONG VirtualPort;
  297. VirtualPort = HalpGetPortVirtualAddress((UINT_PTR)Port);
  298. *(volatile ULONG *)VirtualPort = Value;
  299. __mf();
  300. __mfa();
  301. }
  302. VOID
  303. WRITE_PORT_BUFFER_UCHAR (
  304. PUCHAR Port,
  305. PUCHAR Buffer,
  306. ULONG Count
  307. )
  308. {
  309. /*++
  310. Routine Description:
  311. Writes multiple bytes from the source buffer to the specified Port address.
  312. Arguements:
  313. Port - The address of the Port to write to.
  314. Buffer - A pointer to the buffer containing the data to write to the Port.
  315. Count - Supplies the number of bytes to write.
  316. Return Value:
  317. None.
  318. --*/
  319. ULONGLONG VirtualPort;
  320. VirtualPort = HalpGetPortVirtualAddress((UINT_PTR)Port);
  321. HalpStoreBufferUCHAR((PUCHAR)VirtualPort,Buffer,Count);
  322. }
  323. VOID
  324. WRITE_PORT_BUFFER_USHORT (
  325. PUSHORT Port,
  326. PUSHORT Buffer,
  327. ULONG Count
  328. )
  329. {
  330. /*++
  331. Routine Description:
  332. Writes multiple 16bit short integers from the source buffer to the specified Port address.
  333. Arguements:
  334. Port - The address of the Port to write to.
  335. Buffer - A pointer to the buffer containing the data to write to the Port.
  336. Count - Supplies the number of (16 bit) words to write.
  337. Return Value:
  338. None.
  339. --*/
  340. ULONGLONG VirtualPort;
  341. VirtualPort = HalpGetPortVirtualAddress((UINT_PTR)Port);
  342. HalpStoreBufferUSHORT((PUSHORT)VirtualPort,Buffer, Count);
  343. }
  344. VOID
  345. WRITE_PORT_BUFFER_ULONG (
  346. PULONG Port,
  347. PULONG Buffer,
  348. ULONG Count
  349. )
  350. {
  351. /*++
  352. Routine Description:
  353. Writes multiple 32bit long words from the source buffer to the specified Port address.
  354. Arguements:
  355. Port - The address of the Port to write to.
  356. Buffer - A pointer to the buffer containing the data to write to the Port.
  357. Count - Supplies the number of (32 bit) long words to write.
  358. Return Value:
  359. None.
  360. --*/
  361. ULONGLONG VirtualPort;
  362. VirtualPort = HalpGetPortVirtualAddress((UINT_PTR)Port);
  363. HalpStoreBufferULONG((PULONG)VirtualPort,Buffer, Count);
  364. }