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.

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