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.

272 lines
7.9 KiB

  1. /*++
  2. Copyright (c) 1996, 1997 Microsoft Corporation
  3. Module Name:
  4. init.c
  5. Abstract:
  6. This module contains the initialization code for AGP440.SYS.
  7. Author:
  8. John Vert (jvert) 10/21/1997
  9. Revision History:
  10. --*/
  11. #include "agp440.h"
  12. ULONG AgpExtensionSize = sizeof(AGP440_EXTENSION);
  13. PAGP_FLUSH_PAGES AgpFlushPages = NULL; // not implemented
  14. NTSTATUS
  15. AgpInitializeTarget(
  16. IN PVOID AgpExtension
  17. )
  18. /*++
  19. Routine Description:
  20. Entrypoint for target initialization. This is called first.
  21. Arguments:
  22. AgpExtension - Supplies the AGP extension
  23. Return Value:
  24. NTSTATUS
  25. --*/
  26. {
  27. PAGP440_EXTENSION Extension = AgpExtension;
  28. //
  29. // Initialize our chipset-specific extension
  30. //
  31. Extension->ApertureStart.QuadPart = 0;
  32. Extension->ApertureLength = 0;
  33. Extension->Gart = NULL;
  34. Extension->GartLength = 0;
  35. Extension->GlobalEnable = FALSE;
  36. Extension->PCIEnable = FALSE;
  37. Extension->GartPhysical.QuadPart = 0;
  38. Extension->SpecialTarget = 0;
  39. return(STATUS_SUCCESS);
  40. }
  41. NTSTATUS
  42. AgpInitializeMaster(
  43. IN PVOID AgpExtension,
  44. OUT ULONG *AgpCapabilities
  45. )
  46. /*++
  47. Routine Description:
  48. Entrypoint for master initialization. This is called after target initialization
  49. and should be used to initialize the AGP capabilities of both master and target.
  50. This is also called when the master transitions into the D0 state.
  51. Arguments:
  52. AgpExtension - Supplies the AGP extension
  53. AgpCapabilities - Returns the capabilities of this AGP device.
  54. Return Value:
  55. STATUS_SUCCESS
  56. --*/
  57. {
  58. NTSTATUS Status;
  59. PCI_AGP_CAPABILITY MasterCap;
  60. PCI_AGP_CAPABILITY TargetCap;
  61. PAGP440_EXTENSION Extension = AgpExtension;
  62. ULONG SBAEnable;
  63. ULONG DataRate;
  64. ULONG FastWrite;
  65. BOOLEAN ReverseInit;
  66. ULONG VendorId = 0;
  67. ULONG AgpCtrl = 0;
  68. #if DBG
  69. PCI_AGP_CAPABILITY CurrentCap;
  70. #endif
  71. //
  72. // Intel says if all BIOS manufacturers perform RMW ops on this
  73. // register, then it will always be set, however two video OEMs
  74. // have complained of systems where this was not set, and was
  75. // causing the system to freeze, so we'll hard code it just in
  76. // case (only affects 440LX)
  77. //
  78. Read440Config(&VendorId, 0, sizeof(VendorId));
  79. if ((VendorId == AGP_440LX_IDENTIFIER) ||
  80. (VendorId == AGP_440LX2_IDENTIFIER)) {
  81. Read440Config(&AgpCtrl, AGPCTRL_OFFSET, sizeof(AgpCtrl));
  82. AgpCtrl |= READ_SYNC_ENABLE;
  83. Write440Config(&AgpCtrl, AGPCTRL_OFFSET, sizeof(AgpCtrl));
  84. }
  85. //
  86. // Indicate that we can map memory through the GART aperture
  87. //
  88. *AgpCapabilities = AGP_CAPABILITIES_MAP_PHYSICAL;
  89. //
  90. // Get the master and target AGP capabilities
  91. //
  92. Status = AgpLibGetMasterCapability(AgpExtension, &MasterCap);
  93. if (!NT_SUCCESS(Status)) {
  94. AGPLOG(AGP_CRITICAL,
  95. ("AGP440InitializeDevice - AgpLibGetMasterCapability failed %08lx\n"));
  96. return(Status);
  97. }
  98. //
  99. // Some broken cards (Matrox Millenium II "AGP") report no valid
  100. // supported transfer rates. These are not really AGP cards. They
  101. // have an AGP Capabilities structure that reports no capabilities.
  102. //
  103. if (MasterCap.AGPStatus.Rate == 0) {
  104. AGPLOG(AGP_CRITICAL,
  105. ("AGP440InitializeDevice - AgpLibGetMasterCapability returned no valid transfer rate\n"));
  106. return(STATUS_INVALID_DEVICE_REQUEST);
  107. }
  108. Status = AgpLibGetPciDeviceCapability(0,0,&TargetCap);
  109. if (!NT_SUCCESS(Status)) {
  110. AGPLOG(AGP_CRITICAL,
  111. ("AGP440InitializeDevice - AgpLibGetPciDeviceCapability failed %08lx\n"));
  112. return(Status);
  113. }
  114. //
  115. // Determine the greatest common denominator for data rate.
  116. //
  117. DataRate = TargetCap.AGPStatus.Rate & MasterCap.AGPStatus.Rate;
  118. AGP_ASSERT(DataRate != 0);
  119. //
  120. // Select the highest common rate.
  121. //
  122. if (DataRate & PCI_AGP_RATE_4X) {
  123. DataRate = PCI_AGP_RATE_4X;
  124. } else if (DataRate & PCI_AGP_RATE_2X) {
  125. DataRate = PCI_AGP_RATE_2X;
  126. } else if (DataRate & PCI_AGP_RATE_1X) {
  127. DataRate = PCI_AGP_RATE_1X;
  128. }
  129. //
  130. // Previously a call was made to change the rate (successfully),
  131. // use this rate again now
  132. //
  133. if (Extension->SpecialTarget & AGP_FLAG_SPECIAL_RESERVE) {
  134. DataRate = (ULONG)((Extension->SpecialTarget &
  135. AGP_FLAG_SPECIAL_RESERVE) >>
  136. AGP_FLAG_SET_RATE_SHIFT);
  137. }
  138. //
  139. // Enable SBA if both master and target support it.
  140. //
  141. SBAEnable = (TargetCap.AGPStatus.SideBandAddressing & MasterCap.AGPStatus.SideBandAddressing);
  142. //
  143. // Enable FastWrite if both master and target support it.
  144. //
  145. FastWrite = (TargetCap.AGPStatus.FastWrite & MasterCap.AGPStatus.FastWrite);
  146. //
  147. // Enable the Master first.
  148. //
  149. ReverseInit =
  150. (Extension->SpecialTarget & AGP_FLAG_REVERSE_INITIALIZATION) ==
  151. AGP_FLAG_REVERSE_INITIALIZATION;
  152. if (ReverseInit) {
  153. MasterCap.AGPCommand.Rate = DataRate;
  154. MasterCap.AGPCommand.AGPEnable = 1;
  155. MasterCap.AGPCommand.SBAEnable = SBAEnable;
  156. MasterCap.AGPCommand.FastWriteEnable = FastWrite;
  157. MasterCap.AGPCommand.FourGBEnable = 0;
  158. MasterCap.AGPCommand.RequestQueueDepth = TargetCap.AGPStatus.RequestQueueDepthMaximum;
  159. Status = AgpLibSetMasterCapability(AgpExtension, &MasterCap);
  160. if (!NT_SUCCESS(Status)) {
  161. AGPLOG(AGP_CRITICAL,
  162. ("AGP440InitializeDevice - AgpLibSetMasterCapability %08lx failed %08lx\n",
  163. &MasterCap,
  164. Status));
  165. }
  166. }
  167. //
  168. // Now enable the Target.
  169. //
  170. TargetCap.AGPCommand.Rate = DataRate;
  171. TargetCap.AGPCommand.AGPEnable = 1;
  172. TargetCap.AGPCommand.SBAEnable = SBAEnable;
  173. TargetCap.AGPCommand.FastWriteEnable = FastWrite;
  174. TargetCap.AGPCommand.FourGBEnable = 0;
  175. Status = AgpLibSetPciDeviceCapability(0, 0, &TargetCap);
  176. if (!NT_SUCCESS(Status)) {
  177. AGPLOG(AGP_CRITICAL,
  178. ("AGP440InitializeDevice - AgpLibSetPciDeviceCapability %08lx for target failed %08lx\n",
  179. &TargetCap,
  180. Status));
  181. return(Status);
  182. }
  183. if (!ReverseInit) {
  184. MasterCap.AGPCommand.Rate = DataRate;
  185. MasterCap.AGPCommand.AGPEnable = 1;
  186. MasterCap.AGPCommand.SBAEnable = SBAEnable;
  187. MasterCap.AGPCommand.FastWriteEnable = FastWrite;
  188. MasterCap.AGPCommand.FourGBEnable = 0;
  189. MasterCap.AGPCommand.RequestQueueDepth = TargetCap.AGPStatus.RequestQueueDepthMaximum;
  190. Status = AgpLibSetMasterCapability(AgpExtension, &MasterCap);
  191. if (!NT_SUCCESS(Status)) {
  192. AGPLOG(AGP_CRITICAL,
  193. ("AGP440InitializeDevice - AgpLibSetMasterCapability %08lx failed %08lx\n",
  194. &MasterCap,
  195. Status));
  196. }
  197. }
  198. #if DBG
  199. //
  200. // Read them back, see if it worked
  201. //
  202. Status = AgpLibGetMasterCapability(AgpExtension, &CurrentCap);
  203. AGP_ASSERT(NT_SUCCESS(Status));
  204. //
  205. // If the target request queue depth is greater than the master will
  206. // allow, it will be trimmed. Loosen the assert to not require an
  207. // exact match.
  208. //
  209. AGP_ASSERT(CurrentCap.AGPCommand.RequestQueueDepth <= MasterCap.AGPCommand.RequestQueueDepth);
  210. CurrentCap.AGPCommand.RequestQueueDepth = MasterCap.AGPCommand.RequestQueueDepth;
  211. AGP_ASSERT(RtlEqualMemory(&CurrentCap.AGPCommand, &MasterCap.AGPCommand, sizeof(CurrentCap.AGPCommand)));
  212. Status = AgpLibGetPciDeviceCapability(0,0,&CurrentCap);
  213. AGP_ASSERT(NT_SUCCESS(Status));
  214. AGP_ASSERT(RtlEqualMemory(&CurrentCap.AGPCommand, &TargetCap.AGPCommand, sizeof(CurrentCap.AGPCommand)));
  215. #endif
  216. return(Status);
  217. }