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.

340 lines
9.2 KiB

  1. //***************************************************************************
  2. //
  3. // Module Name:
  4. //
  5. // pciprobe.c
  6. //
  7. // Abstract:
  8. //
  9. // Probe PCI and get access range
  10. //
  11. // Environment:
  12. //
  13. // Kernel mode
  14. //
  15. //
  16. // Copyright (c) 1994-1998 3Dlabs Inc. Ltd. All rights reserved.
  17. // Copyright (c) 1995-1999 Microsoft Corporation. All Rights Reserved.
  18. //
  19. //***************************************************************************
  20. #include "permedia.h"
  21. #if defined(ALLOC_PRAGMA)
  22. #pragma alloc_text(PAGE, Permedia2AssignResources)
  23. #pragma alloc_text(PAGE, Permedia2AssignResourcesNT4)
  24. #endif
  25. #define CreativeSubVendorID 0x1102
  26. #define PiccasoSubVendorID 0x148C
  27. #define PiccasoSubSystemID 0x0100
  28. #define SynergyA8SubVendorID 0x1048
  29. #define SynergyA8SubSystemID 0x0A32
  30. BOOLEAN
  31. Permedia2AssignResources(
  32. PVOID HwDeviceExtension,
  33. PVIDEO_PORT_CONFIG_INFO ConfigInfo,
  34. ULONG NumRegions,
  35. PVIDEO_ACCESS_RANGE AccessRange
  36. )
  37. /*++
  38. Routine Description:
  39. //
  40. // Look for a Permedia2 adapter and return the address regions for
  41. // that adapter.
  42. //
  43. --*/
  44. {
  45. PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
  46. PCI_COMMON_CONFIG PCIFunctionConfig;
  47. PPCI_COMMON_CONFIG PciData = &PCIFunctionConfig;
  48. BOOLEAN bRet;
  49. USHORT VendorID;
  50. USHORT DeviceID;
  51. VP_STATUS status;
  52. ULONG i;
  53. ULONG VgaStatus;
  54. //
  55. // assume we fail to catch all errors.
  56. //
  57. bRet = FALSE;
  58. #if DBG
  59. DEBUG_PRINT((2, "Permedia2AssignResources: read PCI config space (bus %d):-\n",
  60. (int)ConfigInfo->SystemIoBusNumber));
  61. DumpPCIConfigSpace(HwDeviceExtension, ConfigInfo->SystemIoBusNumber, 0);
  62. #endif
  63. VideoPortGetBusData( HwDeviceExtension,
  64. PCIConfiguration,
  65. 0,
  66. PciData,
  67. 0,
  68. PCI_COMMON_HDR_LENGTH );
  69. hwDeviceExtension->bDMAEnabled = PciData->Command & PCI_ENABLE_BUS_MASTER;
  70. if (!hwDeviceExtension->bDMAEnabled)
  71. {
  72. DEBUG_PRINT((1, "PERM2: enabling DMA for VGA card\n"));
  73. PciData->Command |= PCI_ENABLE_BUS_MASTER;
  74. VideoPortSetBusData( HwDeviceExtension,
  75. PCIConfiguration,
  76. 0,
  77. PciData,
  78. 0,
  79. PCI_COMMON_HDR_LENGTH );
  80. }
  81. VendorID = PciData->VendorID;
  82. DeviceID = PciData->DeviceID;
  83. hwDeviceExtension->deviceInfo.VendorId = VendorID;
  84. hwDeviceExtension->deviceInfo.DeviceId = DeviceID;
  85. hwDeviceExtension->deviceInfo.RevisionId = PciData->RevisionID;
  86. hwDeviceExtension->deviceInfo.SubsystemVendorId =
  87. PciData->u.type0.SubVendorID;
  88. hwDeviceExtension->deviceInfo.SubsystemId =
  89. PciData->u.type0.SubSystemID;
  90. if( ( PciData->u.type0.SubVendorID == PiccasoSubVendorID ) &&
  91. ( PciData->u.type0.SubSystemID == PiccasoSubSystemID ) )
  92. {
  93. return(FALSE);
  94. }
  95. if( ( PciData->u.type0.SubVendorID == SynergyA8SubVendorID ) &&
  96. ( PciData->u.type0.SubSystemID == SynergyA8SubSystemID ) )
  97. {
  98. return(FALSE);
  99. }
  100. //
  101. // check if SubSystemID/SubVendorID bits are read only
  102. //
  103. if( PciData->u.type0.SubVendorID == CreativeSubVendorID )
  104. {
  105. hwDeviceExtension->HardwiredSubSystemId = FALSE;
  106. }
  107. else
  108. {
  109. hwDeviceExtension->HardwiredSubSystemId = TRUE;
  110. }
  111. hwDeviceExtension->pciBus = ConfigInfo->SystemIoBusNumber;
  112. hwDeviceExtension->deviceInfo.DeltaRevId = 0;
  113. //
  114. // in multi-adapter systems we need to check if the VGA on this device
  115. // is active
  116. //
  117. VideoPortGetVgaStatus( HwDeviceExtension, &VgaStatus );
  118. hwDeviceExtension->bVGAEnabled =
  119. (VgaStatus & DEVICE_VGA_ENABLED) ? TRUE : FALSE;
  120. if(!hwDeviceExtension->bVGAEnabled)
  121. {
  122. //
  123. // in a multi-adapter system we'll need to turn on the memory
  124. // space for the secondary adapters
  125. //
  126. DEBUG_PRINT((1, "PERM2: enabling memory space access for the secondary card\n"));
  127. PciData->Command |= PCI_ENABLE_MEMORY_SPACE;
  128. VideoPortSetBusData( HwDeviceExtension,
  129. PCIConfiguration,
  130. 0,
  131. PciData,
  132. 0,
  133. PCI_COMMON_HDR_LENGTH );
  134. }
  135. hwDeviceExtension->PciSpeed =
  136. (PciData->Status & PCI_STATUS_66MHZ_CAPABLE) ? 66 : 33;
  137. DEBUG_PRINT((2, "VGAEnabled = %d. Pci Speed = %d\n",
  138. hwDeviceExtension->bVGAEnabled,
  139. hwDeviceExtension->PciSpeed));
  140. VideoPortZeroMemory((PVOID)AccessRange,
  141. NumRegions * sizeof(VIDEO_ACCESS_RANGE));
  142. //
  143. // these should be zero but just in case
  144. //
  145. ConfigInfo->BusInterruptLevel = 0;
  146. ConfigInfo->BusInterruptVector = 0;
  147. i = 0;
  148. status = VideoPortGetAccessRanges(HwDeviceExtension,
  149. 0,
  150. NULL,
  151. NumRegions,
  152. AccessRange,
  153. &VendorID,
  154. &DeviceID,
  155. &i);
  156. if (status == NO_ERROR)
  157. {
  158. DEBUG_PRINT((2, "VideoPortGetAccessRanges succeeded\n"));
  159. }
  160. else
  161. {
  162. DEBUG_PRINT((2, "VideoPortGetAccessRanges failed. error 0x%x\n", status));
  163. goto ReturnValue;
  164. }
  165. //
  166. // get an updated copy of the config space
  167. //
  168. VideoPortGetBusData(HwDeviceExtension,
  169. PCIConfiguration,
  170. 0,
  171. PciData,
  172. 0,
  173. PCI_COMMON_HDR_LENGTH);
  174. #if DBG
  175. DEBUG_PRINT((2, "Final set of base addresses\n"));
  176. for (i = 0; i < NumRegions; ++i)
  177. {
  178. if (AccessRange[i].RangeLength == 0)
  179. break;
  180. DEBUG_PRINT((2, "%d: Addr 0x%x.0x%08x, Length 0x%08x, InIo %d, visible %d, share %d\n", i,
  181. AccessRange[i].RangeStart.HighPart,
  182. AccessRange[i].RangeStart.LowPart,
  183. AccessRange[i].RangeLength,
  184. AccessRange[i].RangeInIoSpace,
  185. AccessRange[i].RangeVisible,
  186. AccessRange[i].RangeShareable));
  187. }
  188. #endif
  189. //
  190. // try to enable for DMA transfers
  191. //
  192. ConfigInfo->Master=1;
  193. bRet = TRUE;
  194. ReturnValue:
  195. return(bRet);
  196. }
  197. BOOLEAN
  198. Permedia2AssignResourcesNT4(
  199. PVOID HwDeviceExtension,
  200. PVIDEO_PORT_CONFIG_INFO ConfigInfo,
  201. ULONG NumRegions,
  202. PVIDEO_ACCESS_RANGE AccessRange
  203. )
  204. /*++
  205. Routine Description:
  206. //
  207. // Look for a Permedia2 adapter and return the address regions for
  208. // that adapter.
  209. //
  210. --*/
  211. {
  212. PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
  213. BOOLEAN bRet;
  214. USHORT VendorID, DeviceID;
  215. USHORT *pVenID, *pDevID;
  216. VP_STATUS status;
  217. ULONG i;
  218. USHORT VenID[] = { VENDOR_ID_3DLABS,
  219. VENDOR_ID_TI,
  220. 0 };
  221. USHORT DevID[] = { PERMEDIA2_ID,
  222. PERMEDIA_P2_ID,
  223. PERMEDIA_P2S_ID,
  224. 0 };
  225. if( hwDeviceExtension->NtVersion != NT4)
  226. {
  227. DEBUG_PRINT((0, "Permedia2AssignResourcesNT4: This function can only be called on NT 4\n"));
  228. return (FALSE);
  229. }
  230. else
  231. {
  232. bRet = FALSE;
  233. //
  234. // Since we do not support multi-mon on NT 4, we
  235. // assume this is the only video card in the system.
  236. //
  237. hwDeviceExtension->bVGAEnabled = 1;
  238. VideoPortZeroMemory((PVOID)AccessRange,
  239. NumRegions * sizeof(VIDEO_ACCESS_RANGE));
  240. for( pVenID = &(VenID[0]); *pVenID != 0; pVenID++)
  241. {
  242. for( pDevID = &(DevID[0]); *pDevID != 0; pDevID++)
  243. {
  244. i = 0;
  245. status = VideoPortGetAccessRanges(HwDeviceExtension,
  246. 0,
  247. NULL,
  248. NumRegions,
  249. (PVIDEO_ACCESS_RANGE) AccessRange,
  250. pVenID,
  251. pDevID,
  252. &i);
  253. if (status == NO_ERROR)
  254. {
  255. DEBUG_PRINT((2, "VideoPortGetAccessRanges succeeded\n"));
  256. bRet = TRUE;
  257. return(bRet);
  258. }
  259. }
  260. }
  261. return(bRet);
  262. }
  263. }