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.

237 lines
7.8 KiB

  1. //
  2. // agpALi.sys is a driver, make sure we get the appropriate linkage.
  3. //
  4. #define _NTDRIVER_
  5. #include "stdarg.h"
  6. #include "stdio.h"
  7. #include "ntddk.h"
  8. #include "agp.h"
  9. //
  10. // Define the location of the GART aperture control registers
  11. //
  12. //
  13. // The GART registers on the ALi M1541 live in the host-PCI bridge.
  14. // This is unfortunate, since the AGP driver attaches to the PCI-PCI (AGP)
  15. // bridge. So we have to get to the host-PCI bridge config space
  16. // and this is only possible because we KNOW this is bus 0, slot 0.
  17. //
  18. #define AGP_ALi_GART_BUS_ID 0
  19. #define AGP_ALi_GART_SLOT_ID 0
  20. #define AGP_ALi_P2P_SLOT_ID 1
  21. #define AGP_VGA_BUS_ID 1
  22. #define AGP_VGA_SLOT_ID 0
  23. #define AGP_ALi_1541_IDENTIFIER 0x154110b9
  24. #define AGP_ALi_1621_IDENTIFIER 0x162110b9
  25. #define AGP_ALi_1631_IDENTIFIER 0x163110b9
  26. #define AGP_ALi_1632_IDENTIFIER 0x163210b9
  27. #define AGP_ALi_1641_IDENTIFIER 0x164110b9
  28. #define AGP_ALi_1644_IDENTIFIER 0x164410b9
  29. #define AGP_ALi_1646_IDENTIFIER 0x164610b9
  30. #define AGP_ALi_1647_IDENTIFIER 0x164710b9
  31. #define AGP_ALi_1651_IDENTIFIER 0x165110b9
  32. #define AGP_ALi_1661_IDENTIFIER 0x166110b9
  33. #define AGP_ALi_1667_IDENTIFIER 0x166710b9
  34. #define APBASE_OFFSET 0x10 // Aperture Base Address
  35. #define AGP_STATUS_OFFSET 0xB4 // AGP Status Register
  36. #define APCTRL_OFFSET 0xBC // Aperture Translation Table Base
  37. #define GTLBCTRL_OFFSET 0xC0 // GTLB Control Register
  38. #define GTLBTAGCLR_OFFSET 0xC4 // GTLB TAG Clear Register
  39. #define L1_2_CACHE_FLUSH_CTRL 0xD0 // L1/L2 Cache Flush Control
  40. #define M1541_Lock_WR 0x90 // M1541 AGP Status Lock Read/Write Control
  41. #define M1621_Lock_WR 0xC8 // M1621 AGP Status Lock Read/Write Control
  42. #define PCI_STATUS_REG 0x4 // PCI Status Register
  43. #define CAP_PTR 0x34 // PCI Capability Pointer
  44. #define AGP_ID 0x2 // AGP Capability ID
  45. #define M1621_HIDDEN_REV_ID 0xFB // M1621 series Hidden Revision ID
  46. #define ReadConfigUlong(_bus_,_slot_,_buf_,_offset_) \
  47. { \
  48. ULONG _len_; \
  49. _len_ = HalGetBusDataByOffset(PCIConfiguration, \
  50. (_bus_), \
  51. (_slot_), \
  52. (_buf_), \
  53. (_offset_), \
  54. 4); \
  55. ASSERT(_len_ == 4); \
  56. }
  57. #define ReadConfigUlongSafe(_bus_,_slot_,_buf_,_offset_) \
  58. { \
  59. HalGetBusDataByOffset(PCIConfiguration, \
  60. (_bus_), \
  61. (_slot_), \
  62. (_buf_), \
  63. (_offset_), \
  64. 4); \
  65. }
  66. #define ReadConfigUchar(_bus_,_slot_,_buf_,_offset_) \
  67. { \
  68. ULONG _len_; \
  69. _len_ = HalGetBusDataByOffset(PCIConfiguration, \
  70. (_bus_), \
  71. (_slot_), \
  72. (_buf_), \
  73. (_offset_), \
  74. 1); \
  75. ASSERT(_len_ == 1); \
  76. }
  77. #define WriteConfigUlong(_bus_,_slot_,_buf_,_offset_) \
  78. { \
  79. ULONG _len_; \
  80. _len_ = HalSetBusDataByOffset(PCIConfiguration, \
  81. (_bus_), \
  82. (_slot_), \
  83. (_buf_), \
  84. (_offset_), \
  85. 4); \
  86. ASSERT(_len_ == 4); \
  87. }
  88. #define WriteConfigUchar(_bus_,_slot_,_buf_,_offset_) \
  89. { \
  90. ULONG _len_; \
  91. _len_ = HalSetBusDataByOffset(PCIConfiguration, \
  92. (_bus_), \
  93. (_slot_), \
  94. (_buf_), \
  95. (_offset_), \
  96. 1); \
  97. ASSERT(_len_ == 1); \
  98. }
  99. #define AP_SIZE_4MB 0x03
  100. #define AP_SIZE_8MB 0x04
  101. #define AP_SIZE_16MB 0x06
  102. #define AP_SIZE_32MB 0x07
  103. #define AP_SIZE_64MB 0x08
  104. #define AP_SIZE_128MB 0x09
  105. #define AP_SIZE_256MB 0x0A
  106. #define AP_SIZE_COUNT 7
  107. #define AP_MIN_SIZE (4 * 1024 * 1024)
  108. #define AP_MAX_SIZE (256 * 1024 * 1024)
  109. //
  110. // Define the GART table entry.
  111. //
  112. typedef struct _GART_ENTRY_HW {
  113. ULONG Valid : 1;
  114. ULONG Reserved : 11;
  115. ULONG Page : 20;
  116. } GART_ENTRY_HW, *PGART_ENTRY_HW;
  117. //
  118. // GART Entry states are defined so that all software-only states
  119. // have the Valid bit clear.
  120. //
  121. #define GART_ENTRY_VALID 1 // 001
  122. #define GART_ENTRY_FREE 0 // 000
  123. #define GART_ENTRY_WC 2 // 010
  124. #define GART_ENTRY_UC 4 // 100
  125. #define GART_ENTRY_RESERVED_WC GART_ENTRY_WC
  126. #define GART_ENTRY_RESERVED_UC GART_ENTRY_UC
  127. #define GART_ENTRY_VALID_WC (GART_ENTRY_VALID)
  128. #define GART_ENTRY_VALID_UC (GART_ENTRY_VALID)
  129. typedef struct _GART_ENTRY_SW {
  130. ULONG State : 3;
  131. ULONG Reserved : 29;
  132. } GART_ENTRY_SW, *PGART_ENTRY_SW;
  133. typedef struct _GART_PTE {
  134. union {
  135. GART_ENTRY_HW Hard;
  136. ULONG AsUlong;
  137. GART_ENTRY_SW Soft;
  138. };
  139. } GART_PTE, *PGART_PTE;
  140. //
  141. // Define the layout of the hardware registers
  142. //
  143. typedef struct _APCTRL {
  144. ULONG ApSize : 4;
  145. ULONG Reserved1 : 8;
  146. ULONG ATTBase : 20;
  147. } APCTRL, *PAPCTRL;
  148. typedef struct _GTLBCTRL {
  149. ULONG GartLevelSelect : 1;
  150. ULONG Reserved1 : 3;
  151. ULONG GTLBSize : 2;
  152. ULONG Reserved2 : 1;
  153. ULONG GTLB_ENJ : 1; // 0:Enable 1:Desable
  154. ULONG NLVM_Base : 12;
  155. ULONG NLVM_Top : 12;
  156. } GTLBCTRL, *PGTLBCTRL;
  157. typedef struct _GTLBTAGCLR {
  158. ULONG GTLBTagClear : 1;
  159. ULONG ClearAllTag : 1;
  160. ULONG ClearGDir : 1;
  161. ULONG Reserved2 : 12;
  162. ULONG Page : 17;
  163. } GTLBTAGCLR, *PGTLBTAGCLR;
  164. typedef struct _CACHECTRL {
  165. ULONG Reserved1 : 8;
  166. ULONG Flush_Enable : 1;
  167. ULONG Reserved2 : 3;
  168. ULONG Address : 20;
  169. } CACHECTRL, *PCACHECTRL;
  170. //
  171. // Define the different chipsets supported by this driver.
  172. //
  173. typedef enum _ALI_CHIPSET_TYPE {
  174. ALi1541,
  175. ALi1621,
  176. ALi1631,
  177. ALi1632,
  178. ALi1641,
  179. ALi1644,
  180. ALi1646,
  181. ALi1647,
  182. ALi1651,
  183. ALi1661,
  184. ALi1667
  185. } ALI_CHIPSET_TYPE;
  186. //
  187. // Define the ALi-specific extension
  188. //
  189. typedef struct _AGPALi_EXTENSION {
  190. PHYSICAL_ADDRESS ApertureStart;
  191. ULONG ApertureLength;
  192. PGART_PTE Gart;
  193. ULONG GartLength;
  194. PHYSICAL_ADDRESS GartPhysical;
  195. ALI_CHIPSET_TYPE ChipsetType;
  196. ULONGLONG SpecialTarget;
  197. } AGPALi_EXTENSION, *PAGPALi_EXTENSION;
  198. NTSTATUS
  199. Agp1541FlushPages(
  200. IN PAGPALi_EXTENSION AgpContext,
  201. IN PMDL Mdl
  202. );
  203. VOID
  204. AgpWorkaround(
  205. IN PVOID AgpExtension
  206. );