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.

379 lines
12 KiB

  1. /******************************************************************************\
  2. *
  3. * FileName: AGPCPQ.H
  4. *
  5. * Group: AGP (Accelerated Graphics Port)
  6. *
  7. * Level: Driver
  8. *
  9. * Date: December 15, 1997
  10. *
  11. * Author: John Theisen
  12. *
  13. ********************************************************************************
  14. *
  15. * Module Functional Description:
  16. *
  17. * This is the header file for Compaq's Accelerated Graphics Port (AGP)
  18. * GART MiniPort driver.
  19. *
  20. ********************************************************************************
  21. *
  22. * History:
  23. *
  24. * DATE REV. DESCRIPTION DELEVOPER
  25. * -------- ---- ------------------------------------ -------------------------
  26. *
  27. * 12/15/97 1.00 Initial Revision. John Theisen
  28. *
  29. \******************************************************************************/
  30. #define _NTDRIVER_
  31. #include "stdarg.h"
  32. #include "stdio.h"
  33. #include "ntos.h"
  34. #include "pci.h"
  35. #include "wdmguid.h"
  36. #include "zwapi.h"
  37. #include "ntpoapi.h"
  38. #include "agp.h"
  39. //
  40. // Device/Function/Bus numbers for the primary and secondary north bridges.
  41. //
  42. // "Primary" values are the same for RCC and Draco.
  43. // "Secondary" values are only relevant on RCC HPSA machines.
  44. // (By definition, if a northbridge exists at this location, then it is an HPSA machine.)
  45. //
  46. #define PRIMARY_LE_BUS_ID 0
  47. #define SECONDARY_LE_BUS_ID 0
  48. //
  49. // PCI_SLOT_NUMBER type = ULONG == [XXXXXXXX XXXXXXXX XXXXXXXX YYYZZZZZ]
  50. //
  51. // Where X = reserved
  52. // Y = function number 0 - 7
  53. // Z = device number 0 - 255
  54. //
  55. #define MAKE_PCI_SLOT_NUMBER(dev, func) ((func << 5) + (dev))
  56. #define PRIMARY_LE_HOST_DEVICE 0
  57. #define PRIMARY_LE_HOST_FUNCTION 0
  58. #define PRIMARY_LE_PCI_DEVICE PRIMARY_LE_HOST_DEVICE
  59. #define PRIMARY_LE_PCI_FUNCION 1
  60. #define SECONDARY_LE_HOST_DEVICE 17
  61. #define SECONDARY_LE_HOST_FUNCTION 0
  62. #define SECONDARY_LE_PCI_DEVICE SECONDARY_LE_HOST_DEVICE
  63. #define SECONDARY_LE_PCI_FUNCION 1
  64. #define PRIMARY_LE_HOSTPCI_SLOT_ID MAKE_PCI_SLOT_NUMBER(PRIMARY_LE_HOST_DEVICE, PRIMARY_LE_HOST_FUNCTION)
  65. #define PRIMARY_LE_PCIPCI_SLOT_ID MAKE_PCI_SLOT_NUMBER(PRIMARY_LE_PCI_DEVICE, PRIMARY_LE_PCI_FUNCION)
  66. #define SECONDARY_LE_HOSTPCI_SLOT_ID MAKE_PCI_SLOT_NUMBER(SECONDARY_LE_HOST_DEVICE, SECONDARY_LE_HOST_FUNCTION)
  67. #define SECONDARY_LE_PCIPCI_SLOT_ID MAKE_PCI_SLOT_NUMBER(SECONDARY_LE_PCI_DEVICE, SECONDARY_LE_PCI_FUNCION)
  68. //
  69. //
  70. //
  71. #define AGP_CPQ_BUS_ID PRIMARY_LE_BUS_ID
  72. #define AGP_CPQ_HOSTPCI_SLOT_ID PRIMARY_LE_HOSTPCI_SLOT_ID
  73. #define AGP_CPQ_PCIPCI_SLOT_ID PRIMARY_LE_PCIPCI_SLOT_ID
  74. #define OFFSET_DEVICE_VENDOR_ID 0x00
  75. #define OFFSET_BAR0 0x10 // Base of AGP Device Address Space
  76. #define OFFSET_BAR1 0x14 // Memory Mapped Control Registers Pointer
  77. #define OFFSET_AP_SIZE 0x8C // For the RCC chipsets. Draco doesn't implement this.
  78. #define OFFSET_REV_ID 0x08 // Silicon Revision ID (on RCC chipsets).
  79. #define MAX_REV_ID_TO_LIMIT_1X 4 // Maximum Silicon Rev ID that has the 2X bug.
  80. #define MAX_REV_ID_TO_FIX_RQ 5 // Macimum Silicon Rev ID that has the RQ bug.
  81. #define OFFSET_SHADOW_BYTE 0x93 // Byte that contains the shaddow enable bit (bit 3).
  82. #define FLAG_DISABLE_SHADOW 0x08
  83. #define MASK_ENABLE_SHADOW (~FLAG_DISABLE_SHADOW)
  84. //
  85. // RCC Vendor-Device IDs (as of August 1998):
  86. //
  87. // CNB_20_LE (function 0) -- 0x00071166
  88. // CNB_20_LE (function 1) -- 0x00051166
  89. // CNB_20_HE (function 0) -- 0x00081166
  90. // CNB_20_HE (function 1) -- 0x00091166
  91. //
  92. #define AGP_CNB20_LE_IDENTIFIER 0x00071166 // * function 0 ID.
  93. #define AGP_CNB20_HE_IDENTIFIER 0x00081166
  94. #define AGP_CNB20_HE4X_IDENTIFIER 0x00131166
  95. #define AGP_CMIC_GC_IDENTIFIER 0x00151166
  96. #define AGP_DRACO_IDENTIFIER 0xAE6C0E11 // * Note, support for this chipset is no longer required.
  97. #define AP_SIZE_DEFAULT 0x10000000 // all chipsets default to 256MB
  98. #define AP_MAX_SIZE_CNB20_LE 0x80000000 // 2GB
  99. #define AP_MAX_SIZE_CNB20_HE 0x80000000 // 2GB
  100. #define AP_MAX_SIZE_DRACO 0x10000000 // 256MB
  101. #define AP_SIZE_COUNT_CNB20_LE 7
  102. #define AP_SIZE_COUNT_CNB20_HE 7
  103. #define AP_SIZE_COUNT_DRACO 1
  104. #define LOWEST_REVISION_ID_SUPPORTED 1
  105. #define MAX_CACHED_ENTRIES_TO_INVALIDATE 3
  106. #define MASK_LOW_TWENTYFIVE (~0x01FFFFFF)
  107. #define ALL_ONES (~0x0)
  108. //
  109. // Conversions from BAR0 read/write-attribute-encoding to aperture sizes.
  110. //
  111. // 0x00000000 (b 0000 0000 ...) = 0MB
  112. // 0xFE000000 (b 1111 1110 ...) = 32MB
  113. // 0xFC000000 (b 1111 1100 ...) = 64MB
  114. // 0xF8000000 (b 1111 1000 ...) = 128MB
  115. // 0xF0000000 (b 1111 0000 ...) = 256MB
  116. // 0xE0000000 (b 1110 0000 ...) = 512MB
  117. // 0xC0000000 (b 1100 0000 ...) = 1GB
  118. // 0x80000000 (b 1000 0000 ...) = 2GB
  119. #define BAR0_CODED_AP_SIZE_0MB 0x00000000
  120. #define BAR0_CODED_AP_SIZE_32MB 0xFE000000
  121. #define BAR0_CODED_AP_SIZE_64MB 0xFC000000
  122. #define BAR0_CODED_AP_SIZE_128MB 0xF8000000
  123. #define BAR0_CODED_AP_SIZE_256MB 0xF0000000
  124. #define BAR0_CODED_AP_SIZE_512MB 0xE0000000
  125. #define BAR0_CODED_AP_SIZE_1GB 0xC0000000
  126. #define BAR0_CODED_AP_SIZE_2GB 0x80000000
  127. //
  128. // Conversions from the values in bits 3:1 of the AGP Device
  129. // Address Space Size Register to aperture sizes.
  130. //
  131. // 0 (b 000) = 32MB
  132. // 1 (b 001) = 64MB
  133. // 2 (b 010) = 128MB
  134. // 3 (b 011) = 256MB
  135. // 4 (b 100) = 512MB
  136. // 5 (b 101) = 1GB
  137. // 6 (b 110) = 2GB
  138. // 7 (b 111) -> "Reserved"
  139. //
  140. #define SET_AP_SIZE_32MB 0
  141. #define SET_AP_SIZE_64MB 1
  142. #define SET_AP_SIZE_128MB 2
  143. #define SET_AP_SIZE_256MB 3
  144. #define SET_AP_SIZE_512MB 4
  145. #define SET_AP_SIZE_1GB 5
  146. #define SET_AP_SIZE_2GB 6
  147. #define BYTES_2G 0x80000000UL // 2G Value, to avoid integral const. overflow
  148. //
  149. // Taken from config.c
  150. //
  151. typedef struct _BUS_SLOT_ID {
  152. ULONG BusId;
  153. ULONG SlotId;
  154. } BUS_SLOT_ID, *PBUS_SLOT_ID;
  155. //
  156. // Macros for reading and writing to the Host-PCI Bridge registers
  157. //
  158. #define ReadCPQConfig(_buf_,_offset_,_size_) \
  159. { \
  160. ULONG _len_; \
  161. _len_ = HalGetBusDataByOffset(PCIConfiguration, \
  162. AGP_CPQ_BUS_ID, \
  163. AGP_CPQ_HOSTPCI_SLOT_ID, \
  164. (_buf_), \
  165. (_offset_), \
  166. (_size_)); \
  167. ASSERT(_len_ == (_size_)); \
  168. }
  169. #define WriteCPQConfig(_buf_,_offset_,_size_) \
  170. { \
  171. ULONG _len_; \
  172. _len_ = HalSetBusDataByOffset(PCIConfiguration, \
  173. AGP_CPQ_BUS_ID, \
  174. AGP_CPQ_HOSTPCI_SLOT_ID, \
  175. (_buf_), \
  176. (_offset_), \
  177. (_size_)); \
  178. ASSERT(_len_ == (_size_)); \
  179. }
  180. //
  181. // Macro to translate the APSIZE encoding into MB.
  182. //
  183. #define TranslateCodedValueIntoApSize(_apsize_, _value_) \
  184. { \
  185. _apsize_ = (((_value_ & MASK_LOW_TWENTYFIVE) ^ ALL_ONES) + 1); \
  186. }
  187. //
  188. // GART table entry.
  189. //
  190. typedef struct _GART_ENTRY_HW {
  191. ULONG Valid : 1;
  192. ULONG Linked : 1;
  193. ULONG Dirty : 1;
  194. ULONG Rsrvd1 : 9;
  195. ULONG Page : 20;
  196. } GART_ENTRY_HW, *PGART_ENTRY_HW;
  197. typedef struct _GART_ENTRY_SW {
  198. ULONG State : 5;
  199. ULONG Rsrvd1 : 27;
  200. } GART_ENTRY_SW, *PGART_ENTRY_SW;
  201. typedef struct _GART_PTE {
  202. union {
  203. GART_ENTRY_HW Hard;
  204. ULONG AsUlong;
  205. GART_ENTRY_SW Soft;
  206. };
  207. } GART_PTE, *PGART_PTE;
  208. //
  209. // GART Entry bits
  210. //
  211. #define GART_ENTRY_INVALID 0x00 // 00000
  212. #define GART_ENTRY_VALID 0x01 // 00001
  213. #define GART_ENTRY_LINKED 0x02 // 00010
  214. #define GART_ENTRY_DIRTY 0x04 // 00100
  215. #define GART_ENTRY_WC 0x08 // 01000
  216. #define GART_ENTRY_UC 0x10 // 10000
  217. //
  218. // Defined GART Entry states.
  219. //
  220. #define GART_ENTRY_FREE GART_ENTRY_INVALID
  221. #define GART_ENTRY_RESERVED_WC GART_ENTRY_WC
  222. #define GART_ENTRY_RESERVED_UC GART_ENTRY_UC
  223. #define GART_ENTRY_VALID_WC (GART_ENTRY_VALID)
  224. #define GART_ENTRY_VALID_UC (GART_ENTRY_VALID)
  225. #define GART_ENTRY_VALID_WC_LINKED (GART_ENTRY_VALID_WC | GART_ENTRY_LINKED)
  226. #define GART_ENTRY_VALID_UC_LINKED (GART_ENTRY_VALID_UC | GART_ENTRY_LINKED)
  227. //
  228. // Memory Mapped Control Registers.
  229. //
  230. typedef struct _GART_CACHE_ENTRY_CONTROL_REGISTER {
  231. ULONG volatile GartEntryInvalidate:1;
  232. ULONG volatile GartEntryUpdate:1;
  233. ULONG Rsrvd1:10;
  234. ULONG volatile GartEntryOffset:20;
  235. } GART_CACHE_ENTRY_CONTROL_REGISTER, *PGART_CACHE_ENTRY_CONTROL_REGISTER;
  236. typedef struct _GART_CACHE_ENTRY_CONTROL {
  237. union {
  238. GART_CACHE_ENTRY_CONTROL_REGISTER AsBits;
  239. ULONG volatile AsDword;
  240. };
  241. } GART_CACHE_ENTRY_CONTROL, *PGART_CACHE_ENTRY_CONTROL;
  242. typedef struct _MM_CONTROL_REGS {
  243. UCHAR RevisionID;
  244. struct _GART_CAPABILITES {
  245. UCHAR ValidBitErrorReportingSupported:1;
  246. UCHAR LinkingSupported:1;
  247. UCHAR TwoLevelAddrTransSupported:1;
  248. UCHAR BusCountersSupported:1;
  249. UCHAR Rsrvd1:4;
  250. } Capabilities;
  251. struct _GART_FEATURE_CONTROL {
  252. UCHAR ValidBitErrorReportingEnable:1;
  253. UCHAR LinkingEnable:1;
  254. UCHAR Rsrvd1:1;
  255. UCHAR GARTCacheEnable:1;
  256. UCHAR Rsrvd2:4;
  257. } FeatureControl;
  258. struct _GART_FEATURE_STATUS {
  259. UCHAR volatile ValidBitErrorDetected:1;
  260. UCHAR Rsrvd1:7;
  261. } FeatureStatus;
  262. struct _GART_BASE_ADDRESS {
  263. ULONG Rsrvd1:12;
  264. ULONG Page:20;
  265. } GartBase;
  266. struct _GART_AND_DIR_CACHE_SIZES {
  267. ULONG MaxTableEntries:16;
  268. ULONG MaxDirEntries:16;
  269. } CacheSize;
  270. struct _GART_CACHE_CONTROL {
  271. ULONG volatile GartAndDirCacheInvalidate:1;
  272. ULONG Rsrvd1:31;
  273. } CacheControl;
  274. GART_CACHE_ENTRY_CONTROL CacheEntryControl;
  275. struct _POSTED_WRITE_BUFFER_CONTROL {
  276. UCHAR volatile Flush:1;
  277. UCHAR Rsrvd1:7;
  278. } PostedWriteBufferControl;
  279. struct _AGP_BUS_COUNTERS_COMMAND {
  280. UCHAR volatile ClearCounters:1;
  281. UCHAR EnableUtilization:1;
  282. UCHAR EnableBandwidth:1;
  283. UCHAR EnableLatency:1;
  284. UCHAR Rsrvd1:4;
  285. } BusCounters;
  286. USHORT Rsrvd1;
  287. ULONG BusUtilizationCounter;
  288. ULONG BusBandwidthCounter;
  289. ULONG BusLatencyCounter;
  290. } MM_CONTROL_REGS, *PMM_CONTROL_REGS;
  291. typedef struct _AGP_DEVICE_ADDRESS_SPACE_SIZE_REG {
  292. UCHAR Rsrvd1:4;
  293. UCHAR ApSize:3;
  294. UCHAR AgpValid:1;
  295. } AGP_DAS_SIZE_REG, *PAGP_DAS_SIZE_REG;
  296. typedef struct _AGP_AP_SIZE_REG {
  297. union {
  298. AGP_DAS_SIZE_REG AsBits;
  299. UCHAR AsByte;
  300. };
  301. } AGP_AP_SIZE_REG, *PAGP_AP_SIZE_REG;
  302. //
  303. // Compaq-specific extension
  304. //
  305. typedef struct _AGPCPQ_EXTENSION {
  306. PMM_CONTROL_REGS MMIO;
  307. PHYSICAL_ADDRESS ApertureStart;
  308. ULONG ApertureLength;
  309. PGART_PTE Gart;
  310. PVOID Dir;
  311. ULONG GartLength;
  312. ULONG MaxGartLength;
  313. ULONG DeviceVendorID;
  314. ULONG GartPointer;
  315. BOOLEAN IsHPSA;
  316. ULONGLONG SpecialTarget;
  317. } AGPCPQ_EXTENSION, *PAGPCPQ_EXTENSION;
  318. //
  319. // Taken from Config.c
  320. //
  321. extern
  322. NTSTATUS
  323. ApGetSetBusData(
  324. IN PBUS_SLOT_ID BusSlotId,
  325. IN BOOLEAN Read,
  326. IN PVOID Buffer,
  327. IN ULONG Offset,
  328. IN ULONG Length
  329. );
  330. extern
  331. NTSTATUS
  332. DnbSetShadowBit(
  333. ULONG SetToOne
  334. );