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.

148 lines
4.5 KiB

  1. #include "agp.h"
  2. //
  3. // Define the location of the GART aperture control registers
  4. //
  5. //
  6. // The GART registers on the 440 live in the host-PCI bridge.
  7. // This is unfortunate, since the AGP driver attaches to the PCI-PCI (AGP)
  8. // bridge. So we have to get to the host-PCI bridge config space
  9. // and this is only possible because we KNOW this is bus 0, slot 0.
  10. //
  11. #define AGP_440_GART_BUS_ID 0
  12. #define AGP_440_GART_SLOT_ID 0
  13. #define AGP_440LX_IDENTIFIER 0x71808086
  14. #define AGP_440LX2_IDENTIFIER 0x71828086
  15. #define AGP_440BX_IDENTIFIER 0x71908086
  16. #define AGP_815_IDENTIFIER 0x11308086
  17. #define APBASE_OFFSET 0x10 // Aperture Base Address
  18. #define APSIZE_OFFSET 0xB4 // Aperture Size Register
  19. #define PACCFG_OFFSET 0x50 // PAC Configuration Register
  20. #define AGPCTRL_OFFSET 0xB0 // AGP Control Register
  21. #define ATTBASE_OFFSET 0xB8 // Aperture Translation Table Base
  22. #define READ_SYNC_ENABLE 0x2000
  23. #define Read440Config(_buf_,_offset_,_size_) \
  24. { \
  25. ULONG _len_; \
  26. _len_ = HalGetBusDataByOffset(PCIConfiguration, \
  27. AGP_440_GART_BUS_ID, \
  28. AGP_440_GART_SLOT_ID, \
  29. (_buf_), \
  30. (_offset_), \
  31. (_size_)); \
  32. ASSERT(_len_ == (_size_)); \
  33. }
  34. #define Write440Config(_buf_,_offset_,_size_) \
  35. { \
  36. ULONG _len_; \
  37. _len_ = HalSetBusDataByOffset(PCIConfiguration, \
  38. AGP_440_GART_BUS_ID, \
  39. AGP_440_GART_SLOT_ID, \
  40. (_buf_), \
  41. (_offset_), \
  42. (_size_)); \
  43. ASSERT(_len_ == (_size_)); \
  44. }
  45. //
  46. // Conversions from APSIZE encoding to MB
  47. //
  48. // 0x3F (b 11 1111) = 4MB
  49. // 0x3E (b 11 1110) = 8MB
  50. // 0x3C (b 11 1100) = 16MB
  51. // 0x38 (b 11 1000) = 32MB
  52. // 0x30 (b 11 0000) = 64MB
  53. // 0x20 (b 10 0000) = 128MB
  54. // 0x00 (b 00 0000) = 256MB
  55. #define AP_SIZE_4MB 0x3F
  56. #define AP_SIZE_8MB 0x3E
  57. #define AP_SIZE_16MB 0x3C
  58. #define AP_SIZE_32MB 0x38
  59. #define AP_SIZE_64MB 0x30
  60. #define AP_SIZE_128MB 0x20
  61. #define AP_SIZE_256MB 0x00
  62. #define AP_SIZE_COUNT 7
  63. #define AP_MIN_SIZE (4 * 1024 * 1024)
  64. #define AP_MAX_SIZE (256 * 1024 * 1024)
  65. #define AP_815_SIZE_COUNT 2
  66. #define AP_815_MAX_SIZE (64 * 1024 * 1024)
  67. //
  68. // Define the GART table entry.
  69. //
  70. typedef struct _GART_ENTRY_HW {
  71. ULONG Valid : 1;
  72. ULONG Reserved : 11;
  73. ULONG Page : 20;
  74. } GART_ENTRY_HW, *PGART_ENTRY_HW;
  75. //
  76. // GART Entry states are defined so that all software-only states
  77. // have the Valid bit clear.
  78. //
  79. #define GART_ENTRY_VALID 1 // 001
  80. #define GART_ENTRY_FREE 0 // 000
  81. #define GART_ENTRY_WC 2 // 010
  82. #define GART_ENTRY_UC 4 // 100
  83. #define GART_ENTRY_RESERVED_WC GART_ENTRY_WC
  84. #define GART_ENTRY_RESERVED_UC GART_ENTRY_UC
  85. #define GART_ENTRY_VALID_WC (GART_ENTRY_VALID)
  86. #define GART_ENTRY_VALID_UC (GART_ENTRY_VALID)
  87. typedef struct _GART_ENTRY_SW {
  88. ULONG State : 3;
  89. ULONG Reserved : 29;
  90. } GART_ENTRY_SW, *PGART_ENTRY_SW;
  91. typedef struct _GART_PTE {
  92. union {
  93. GART_ENTRY_HW Hard;
  94. ULONG AsUlong;
  95. GART_ENTRY_SW Soft;
  96. };
  97. } GART_PTE, *PGART_PTE;
  98. //
  99. // Define the layout of the hardware registers
  100. //
  101. typedef struct _AGPCTRL {
  102. ULONG Reserved1 : 7;
  103. ULONG GTLB_Enable : 1;
  104. ULONG Reserved2 : 24;
  105. } AGPCTRL, *PAGPCTRL;
  106. typedef struct _PACCFG {
  107. USHORT Reserved1 : 9;
  108. USHORT GlobalEnable : 1;
  109. USHORT PCIEnable : 1;
  110. USHORT Reserved2 : 5;
  111. } PACCFG, *PPACCFG;
  112. //
  113. // Define the 440-specific extension
  114. //
  115. typedef struct _AGP440_EXTENSION {
  116. BOOLEAN GlobalEnable;
  117. BOOLEAN PCIEnable;
  118. PHYSICAL_ADDRESS ApertureStart;
  119. ULONG ApertureLength;
  120. PGART_PTE Gart;
  121. ULONG GartLength;
  122. PHYSICAL_ADDRESS GartPhysical;
  123. ULONGLONG SpecialTarget;
  124. } AGP440_EXTENSION, *PAGP440_EXTENSION;