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.

327 lines
9.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 AGPALi.SYS.
  7. Author:
  8. John Vert (jvert) 10/21/1997
  9. Modified by:
  10. Chi-Ming Cheng 06/24/1998 Acer Labs, Inc.
  11. Wang-Kai Tsai 08/29/2000 Acer Labs, Inc.
  12. Revision History:
  13. --*/
  14. #include "ALiM1541.h"
  15. ULONG AgpExtensionSize = sizeof(AGPALi_EXTENSION);
  16. PAGP_FLUSH_PAGES AgpFlushPages;
  17. NTSTATUS
  18. AgpInitializeTarget(
  19. IN PVOID AgpExtension
  20. )
  21. /*++
  22. Routine Description:
  23. Entrypoint for target initialization. This is called first.
  24. Arguments:
  25. AgpExtension - Supplies the AGP extension
  26. Return Value:
  27. NTSTATUS
  28. --*/
  29. {
  30. ULONG VendorId = 0;
  31. PAGPALi_EXTENSION Extension = AgpExtension;
  32. UCHAR HidId;
  33. //
  34. // Make sure we are really loaded only on a ALi chipset
  35. //
  36. ReadConfigUlong(AGP_ALi_GART_BUS_ID, AGP_ALi_GART_SLOT_ID, &VendorId, 0);
  37. ASSERT((VendorId == AGP_ALi_1541_IDENTIFIER) ||
  38. (VendorId == AGP_ALi_1621_IDENTIFIER) ||
  39. (VendorId == AGP_ALi_1631_IDENTIFIER) ||
  40. (VendorId == AGP_ALi_1632_IDENTIFIER) ||
  41. (VendorId == AGP_ALi_1641_IDENTIFIER) ||
  42. (VendorId == AGP_ALi_1644_IDENTIFIER) ||
  43. (VendorId == AGP_ALi_1646_IDENTIFIER) ||
  44. (VendorId == AGP_ALi_1647_IDENTIFIER) ||
  45. (VendorId == AGP_ALi_1651_IDENTIFIER) ||
  46. (VendorId == AGP_ALi_1671_IDENTIFIER) ||
  47. (VendorId == AGP_ALi_1672_IDENTIFIER));
  48. //
  49. // Determine which particular chipset we are running on.
  50. //
  51. if (VendorId == AGP_ALi_1541_IDENTIFIER) {
  52. Extension->ChipsetType = ALi1541;
  53. AgpFlushPages = Agp1541FlushPages;
  54. } else if (VendorId == AGP_ALi_1621_IDENTIFIER) {
  55. Extension->ChipsetType = ALi1621;
  56. ReadConfigUchar(AGP_ALi_GART_BUS_ID, AGP_ALi_GART_SLOT_ID, &HidId, M1621_HIDDEN_REV_ID);
  57. switch (HidId)
  58. {
  59. case 0x31:
  60. Extension->ChipsetType = ALi1631;
  61. break;
  62. case 0x32:
  63. Extension->ChipsetType = ALi1632;
  64. break;
  65. case 0x41:
  66. Extension->ChipsetType = ALi1641;
  67. break;
  68. case 0x43:
  69. Extension->ChipsetType = ALi1621;
  70. break;
  71. default:
  72. Extension->ChipsetType = ALi1621;
  73. break;
  74. }
  75. AgpFlushPages = NULL;
  76. } else if (VendorId == AGP_ALi_1631_IDENTIFIER) {
  77. Extension->ChipsetType = ALi1631;
  78. AgpFlushPages = NULL;
  79. } else if (VendorId == AGP_ALi_1632_IDENTIFIER) {
  80. Extension->ChipsetType = ALi1632;
  81. AgpFlushPages = NULL;
  82. } else if (VendorId == AGP_ALi_1641_IDENTIFIER) {
  83. Extension->ChipsetType = ALi1641;
  84. AgpFlushPages = NULL;
  85. } else if (VendorId == AGP_ALi_1644_IDENTIFIER) {
  86. Extension->ChipsetType = ALi1644;
  87. AgpFlushPages = NULL;
  88. } else if (VendorId == AGP_ALi_1646_IDENTIFIER) {
  89. Extension->ChipsetType = ALi1646;
  90. AgpFlushPages = NULL;
  91. } else if (VendorId == AGP_ALi_1647_IDENTIFIER) {
  92. Extension->ChipsetType = ALi1647;
  93. AgpFlushPages = NULL;
  94. } else if (VendorId == AGP_ALi_1651_IDENTIFIER) {
  95. Extension->ChipsetType = ALi1651;
  96. AgpFlushPages = NULL;
  97. } else if (VendorId == AGP_ALi_1671_IDENTIFIER) {
  98. Extension->ChipsetType = ALi1671;
  99. AgpFlushPages = NULL;
  100. } else if (VendorId == AGP_ALi_1672_IDENTIFIER) {
  101. Extension->ChipsetType = ALi1672;
  102. AgpFlushPages = NULL;
  103. } else {
  104. AGPLOG(AGP_CRITICAL,
  105. ("AGPALi - AgpInitializeTarget called for platform %08lx which is not a ALi chipset!\n",
  106. VendorId));
  107. return(STATUS_UNSUCCESSFUL);
  108. }
  109. //
  110. // Initialize our chipset-specific extension
  111. //
  112. Extension->ApertureStart.QuadPart = 0;
  113. Extension->ApertureLength = 0;
  114. Extension->Gart = NULL;
  115. Extension->GartLength = 0;
  116. Extension->GartPhysical.QuadPart = 0;
  117. Extension->SpecialTarget = 0;
  118. return(STATUS_SUCCESS);
  119. }
  120. NTSTATUS
  121. AgpInitializeMaster(
  122. IN PVOID AgpExtension,
  123. OUT ULONG *AgpCapabilities
  124. )
  125. /*++
  126. Routine Description:
  127. Entrypoint for master initialization. This is called after target initialization
  128. and should be used to initialize the AGP capabilities of both master and target.
  129. Arguments:
  130. AgpExtension - Supplies the AGP extension
  131. AgpCapabilities - Returns the capabilities of this AGP device.
  132. Return Value:
  133. STATUS_SUCCESS
  134. --*/
  135. {
  136. NTSTATUS Status;
  137. PCI_AGP_CAPABILITY MasterCap;
  138. PCI_AGP_CAPABILITY TargetCap;
  139. PAGPALi_EXTENSION Extension = AgpExtension;
  140. ULONG SBAEnable;
  141. ULONG DataRate;
  142. BOOLEAN ReverseInit;
  143. #if DBG
  144. PCI_AGP_CAPABILITY CurrentCap;
  145. #endif
  146. //
  147. // Indicate that we can map memory through the GART aperture
  148. //
  149. *AgpCapabilities = AGP_CAPABILITIES_MAP_PHYSICAL;
  150. //
  151. // Get the master and target AGP capabilities
  152. //
  153. Status = AgpLibGetMasterCapability(AgpExtension, &MasterCap);
  154. if (!NT_SUCCESS(Status)) {
  155. AGPLOG(AGP_CRITICAL,
  156. ("AGPALiInitializeDevice - AgpLibGetMasterCapability failed %08lx\n"));
  157. return(Status);
  158. }
  159. //
  160. // Some broken cards (Matrox Millenium II "AGP") report no valid
  161. // supported transfer rates. These are not really AGP cards. They
  162. // have an AGP Capabilities structure that reports no capabilities.
  163. //
  164. if (MasterCap.AGPStatus.Rate == 0) {
  165. AGPLOG(AGP_CRITICAL,
  166. ("AGP440InitializeDevice - AgpLibGetMasterCapability returned no valid transfer rate\n"));
  167. return(STATUS_INVALID_DEVICE_REQUEST);
  168. }
  169. Status = AgpLibGetPciDeviceCapability(0,0,&TargetCap);
  170. if (!NT_SUCCESS(Status)) {
  171. AGPLOG(AGP_CRITICAL,
  172. ("AGPALiInitializeDevice - AgpLibGetPciDeviceCapability failed %08lx\n"));
  173. return(Status);
  174. }
  175. //
  176. // Determine the greatest common denominator for data rate.
  177. //
  178. DataRate = TargetCap.AGPStatus.Rate & MasterCap.AGPStatus.Rate;
  179. AGP_ASSERT(DataRate != 0);
  180. //
  181. // Select the highest common rate.
  182. //
  183. if (DataRate & PCI_AGP_RATE_4X) {
  184. DataRate = PCI_AGP_RATE_4X;
  185. } else if (DataRate & PCI_AGP_RATE_2X) {
  186. DataRate = PCI_AGP_RATE_2X;
  187. } else if (DataRate & PCI_AGP_RATE_1X) {
  188. DataRate = PCI_AGP_RATE_1X;
  189. }
  190. //
  191. // Previously a call was made to change the rate (successfully),
  192. // use this rate again now
  193. //
  194. if (Extension->SpecialTarget & AGP_FLAG_SPECIAL_RESERVE) {
  195. DataRate = (ULONG)((Extension->SpecialTarget &
  196. AGP_FLAG_SPECIAL_RESERVE) >>
  197. AGP_FLAG_SET_RATE_SHIFT);
  198. }
  199. //
  200. // Enable SBA if both master and target support it.
  201. //
  202. SBAEnable = (TargetCap.AGPStatus.SideBandAddressing & MasterCap.AGPStatus.SideBandAddressing);
  203. //
  204. // Before we enable AGP, apply any workarounds
  205. //
  206. AgpWorkaround(Extension);
  207. //
  208. // Enable the Master first.
  209. //
  210. ReverseInit =
  211. (Extension->SpecialTarget & AGP_FLAG_REVERSE_INITIALIZATION) ==
  212. AGP_FLAG_REVERSE_INITIALIZATION;
  213. if (ReverseInit) {
  214. MasterCap.AGPCommand.Rate = DataRate;
  215. MasterCap.AGPCommand.AGPEnable = 1;
  216. MasterCap.AGPCommand.SBAEnable = SBAEnable;
  217. MasterCap.AGPCommand.RequestQueueDepth = TargetCap.AGPStatus.RequestQueueDepthMaximum;
  218. Status = AgpLibSetMasterCapability(AgpExtension, &MasterCap);
  219. if (!NT_SUCCESS(Status)) {
  220. AGPLOG(AGP_CRITICAL,
  221. ("AGPALiInitializeDevice - AgpLibSetMasterCapability %08lx failed %08lx\n",
  222. &MasterCap,
  223. Status));
  224. }
  225. }
  226. //
  227. // Now enable the Target.
  228. //
  229. TargetCap.AGPCommand.Rate = DataRate;
  230. TargetCap.AGPCommand.AGPEnable = 1;
  231. TargetCap.AGPCommand.SBAEnable = SBAEnable;
  232. Status = AgpLibSetPciDeviceCapability(0, 0, &TargetCap);
  233. if (!NT_SUCCESS(Status)) {
  234. AGPLOG(AGP_CRITICAL,
  235. ("AGPALiInitializeDevice - AgpLibSetPciDeviceCapability %08lx for target failed %08lx\n",
  236. &TargetCap,
  237. Status));
  238. return(Status);
  239. }
  240. if (!ReverseInit) {
  241. MasterCap.AGPCommand.Rate = DataRate;
  242. MasterCap.AGPCommand.AGPEnable = 1;
  243. MasterCap.AGPCommand.SBAEnable = SBAEnable;
  244. MasterCap.AGPCommand.RequestQueueDepth = TargetCap.AGPStatus.RequestQueueDepthMaximum;
  245. Status = AgpLibSetMasterCapability(AgpExtension, &MasterCap);
  246. if (!NT_SUCCESS(Status)) {
  247. AGPLOG(AGP_CRITICAL,
  248. ("AGPALiInitializeDevice - AgpLibSetMasterCapability %08lx failed %08lx\n",
  249. &MasterCap,
  250. Status));
  251. }
  252. }
  253. #if DBG
  254. //
  255. // Read them back, see if it worked
  256. //
  257. Status = AgpLibGetMasterCapability(AgpExtension, &CurrentCap);
  258. AGP_ASSERT(NT_SUCCESS(Status));
  259. //
  260. // If the target request queue depth is greater than the master will
  261. // allow, it will be trimmed. Loosen the assert to not require an
  262. // exact match.
  263. //
  264. AGP_ASSERT(CurrentCap.AGPCommand.RequestQueueDepth <= MasterCap.AGPCommand.RequestQueueDepth);
  265. CurrentCap.AGPCommand.RequestQueueDepth = MasterCap.AGPCommand.RequestQueueDepth;
  266. AGP_ASSERT(RtlEqualMemory(&CurrentCap.AGPCommand, &MasterCap.AGPCommand, sizeof(CurrentCap.AGPCommand)));
  267. Status = AgpLibGetPciDeviceCapability(0,0,&CurrentCap);
  268. AGP_ASSERT(NT_SUCCESS(Status));
  269. AGP_ASSERT(RtlEqualMemory(&CurrentCap.AGPCommand, &TargetCap.AGPCommand, sizeof(CurrentCap.AGPCommand)));
  270. #endif
  271. return(Status);
  272. }