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.

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