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.

212 lines
6.9 KiB

  1. #include "agp.h"
  2. #define PCI_ADDRESS_MEMORY_ADDRESS_MASK_64 0xFFFFFFFFFFFFFFF0UI64
  3. //
  4. // Define the location of the GART aperture control registers
  5. //
  6. //
  7. // The GART registers on the 440 live in the host-PCI bridge.
  8. // This is unfortunate, since the AGP driver attaches to the PCI-PCI (AGP)
  9. // bridge. So we have to get to the host-PCI bridge config space
  10. // and this is only possible because we KNOW this is bus 0, slot 0.
  11. //
  12. //
  13. // TBD: The GART registers on the 460 live in the GXB. Though we are trying to use
  14. // the code from 440 as much as possible. The HalGet calls may not be needed if
  15. // all the GART registers live on the PCI-PCI bridge (GXB). DOUBLE CHECK THIS
  16. // WITH THE EDS, VERIFY IT WITH JOHN VERT - NAGA G
  17. //
  18. // Compared to 440 there exists no equivalents for PAC configuration,
  19. // AGP Control & ATTBASE registers in 460GX.
  20. #define EXTRACT_LSBYTE(x) x = (x & 0xFF) // Sunil
  21. #define ONE_KB 1024
  22. #define ONE_MB (ONE_KB * ONE_KB)
  23. #define AP_256MB (256 * ONE_MB)
  24. #define AP_1GB (ONE_MB * ONE_KB)
  25. #define AP_32GB (32 * AP_1GB)
  26. #define ABOVE_TOM(x) ( (x) & (0x08) )
  27. #define AGP_460GX_IDENTIFIER 0x84E28086 // Device ID & Vendor ID
  28. // for the 460GX SAC
  29. #define APBASE_OFFSET 0x10 // Aperture Base Address:APBASE & BAPBASE are used to
  30. #define BAPBASE_OFFSET 0x98 // store the base address of the Graphics Aperture(GA).
  31. // Only one of APBASE or BAPBASE is visible at a time.
  32. // APBASE is visible when AGPSIZ[3]=0 && AGPSIZ[2:0]!=0.
  33. // BAPBASE is visible when AGPSIZ[3]=1 & AGPSIZ[2:0]!=0.
  34. // BAPBASE is used when the GA is mapped above 4GB and
  35. // APBASE when the GA is mapped below 4GB
  36. #define APSIZE_OFFSET 0xA2 // Aperture Size Register - AGPSIZ
  37. #define ATTBASE 0xFE200000 // Aperture Translation Table Base - It is a
  38. // 2MB region hard coded in 460GX to 0xFE200000h
  39. #define AGPSTATUS_OFFSET 0xE4 // AGP Status Register - The CAP_PTR is
  40. // at 0xE0h in 460GX and the AGP Status
  41. // register is at CAP_PTR+4.
  42. #define AGPCMD_OFFSET 0xE8 // AGP Command Register - CAP_PTR + 8
  43. //
  44. // 82460GX specific definitions to get to the PCI configuration space of the
  45. // SAC, GXB et al.
  46. //
  47. #define AGP460_SAC_BUS_ID 0 // The bus number where the SAC resides in 82460GX
  48. //
  49. // The following two definitions should be interpreted as of type PCI_SLOT_NUMBER
  50. // which combines the device & function number for a particular PCI device. It is
  51. // a ULONG value which should be deciphered as follows:
  52. // [xxxxxxxx xxxxxxxx xxxxxxxx YYYZZZZZ]
  53. // where x = Reserved, Y = Function Number, Z = Device Number
  54. //
  55. #define AGP460_SAC_CBN_SLOT_ID 0x10 // The Chipset Bus Number resides at Bus 0,
  56. // Device 10h & Function 0.
  57. #define AGP460_GXB_SLOT_ID 0x34 // The GXB would be accessed at Bus CBN, Device 14h
  58. // function BFN. BFN is 1 by default.
  59. #define AGP460_PAGE_SIZE_4KB (4 * ONE_KB)
  60. //
  61. // Handy macros to read & write in the PCI Configuration space
  62. //
  63. //
  64. // Read460CBN reads the CBN - Chipset Bus Number from the 82460GX SAC.
  65. // CBN is a BYTE located at Bus 0, Device 10h, Function 0, Offset 40
  66. // in the SAC Configuration space. The CBN can be read once and reused
  67. // subsequently.
  68. //
  69. void Read460CBN(PVOID CBN);
  70. void Read460Config(ULONG _CBN_,PVOID _buf_,ULONG _offset_,ULONG _size_);
  71. void Write460Config(ULONG _CBN_,PVOID _buf_,ULONG _offset_,ULONG _size_);
  72. //
  73. // Conversions from AGPSIZ[2:0] encoding to Aperture Size in MB/GB
  74. //
  75. // AGPSIZE[2:0] Aperture Size
  76. // 000 0MB (power on default; no GART SRAM present)
  77. // 001 256MB
  78. // 010 1GB
  79. // 100 32GB (only with 4MB pages)
  80. //
  81. #define AP_SIZE_0MB 0x00
  82. #define AP_SIZE_256MB 0x01
  83. #define AP_SIZE_1GB 0x02
  84. #define AP_SIZE_32GB 0x04
  85. #define AP_SIZE_COUNT_4KB 2 //Only apertures of 256M & 1G are possible with 4KB pages
  86. #define AP_SIZE_COUNT_4MB 3 //Apertures of 256M, 1G & 32G are possible with 4MB pages
  87. #define AP_MIN_SIZE AP_256MB // 0 is not counted as a possible
  88. // aperture size
  89. #define AP_MAX_SIZE_4KB AP_1GB // 1 GB is the maximum with 4KB pages
  90. #define AP_MAX_SIZE_4MB AP_1GB // 32GB is the maximum with 4MB pages
  91. #define PAGESIZE_460GX_CHIPSET (4 * ONE_KB)
  92. #define GART_PAGESHIFT_460GX 12
  93. //
  94. // Define the 82460GX GART table entry. 4KB pages are assumed. To support 4MB pages new
  95. // structures have to be defined.
  96. //
  97. typedef struct _GART_ENTRY_HW {
  98. ULONG Page : 24;
  99. ULONG Valid : 1;
  100. ULONG Coherency : 1;
  101. ULONG Parity : 1; // Parity bit is generated by Hardware. Software should
  102. // mask it out and treat it as a reserved.
  103. ULONG Reserved : 5;
  104. } GART_ENTRY_HW, *PGART_ENTRY_HW;
  105. //
  106. // GART Entry states are defined so that all software-only states
  107. // have the Valid bit clear.
  108. //
  109. #define GART_ENTRY_VALID 1 // Bit 24 is the valid bit in 460GX GART
  110. #define GART_ENTRY_FREE 0 // 000
  111. #define GART_ENTRY_WC 2 // 010
  112. #define GART_ENTRY_UC 4 // 100
  113. #define GART_ENTRY_WB 6 // 110
  114. #define GART_ENTRY_RESERVED_WC GART_ENTRY_WC
  115. #define GART_ENTRY_RESERVED_UC GART_ENTRY_UC
  116. #define GART_ENTRY_RESERVED_WB GART_ENTRY_WB
  117. //
  118. // Unlike 440, 82460GX GART driver doesn't have direct equivalent for GART PTE software
  119. // states like GART_ENTRY_VALID_WC, GART_ENTRY_VALID_UC etc. This is because of
  120. // the organization of the GART PTEs - the valid bit is disjoint from any reserved bits
  121. // and therefore have to be manipulated separately. - Naga G
  122. //
  123. typedef struct _GART_ENTRY_SW {
  124. ULONG Reserved0 : 24;
  125. ULONG Valid : 1;
  126. ULONG Reserved1 : 2;
  127. ULONG State : 3;
  128. ULONG Reserved2 : 2;
  129. } GART_ENTRY_SW, *PGART_ENTRY_SW;
  130. typedef struct _GART_PTE {
  131. union {
  132. GART_ENTRY_HW Hard;
  133. ULONG AsUlong;
  134. GART_ENTRY_SW Soft;
  135. };
  136. } GART_PTE, *PGART_PTE;
  137. //
  138. // Define the 460-specific extension
  139. //
  140. typedef struct _AGP460_EXTENSION {
  141. BOOLEAN GlobalEnable; // Software only bit. The GART will be
  142. // initialized to a known invalid state (0s)
  143. // during initialization. Other than that
  144. // no hardware control is available in 460GX
  145. // to enable/disable GART accesses. Thus, this
  146. // is not of much use !
  147. PHYSICAL_ADDRESS ApertureStart;
  148. ULONG ApertureLength; // Aperture Length in Bytes
  149. ULONG ChipsetPageSize; // Can be 4KB or 4MB.
  150. PGART_PTE Gart;
  151. ULONG GartLength; // Maximum is 2MB
  152. PHYSICAL_ADDRESS GartPhysical; // Physical address where GART starts
  153. BOOLEAN bSupportMultipleAGPDevices; // For future use.
  154. BOOLEAN bSupportsCacheCoherency; // For future use.
  155. ULONGLONG SpecialTarget;
  156. } AGP460_EXTENSION, *PAGP460_EXTENSION;
  157. NTSTATUS Agp460FlushPages(
  158. IN PAGP460_EXTENSION AgpContext,
  159. IN PMDL Mdl
  160. );