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.

155 lines
4.9 KiB

  1. /*****************************************************************************
  2. ** **
  3. ** COPYRIGHT (C) 2000, 2001 MKNET CORPORATION **
  4. ** DEVELOPED FOR THE MK7100-BASED VFIR PCI CONTROLLER. **
  5. ** **
  6. *****************************************************************************/
  7. /**********************************************************************
  8. Module Name:
  9. WINPCI.C
  10. Routines:
  11. FindAndSetupPciDevice
  12. Comments:
  13. Windows-NDIS PCI.
  14. **********************************************************************/
  15. #include "precomp.h"
  16. #pragma hdrstop
  17. //-----------------------------------------------------------------------------
  18. // Procedure: [FindAndSetupPciDevice]
  19. //
  20. // Description: This routine finds an adapter for the driver to load on
  21. // The critical piece to understanding this routine is that
  22. // the System will not let us read any information from PCI
  23. // space from any slot but the one that the System thinks
  24. // we should be using. The configuration manager rules this
  25. // land... The Slot number used by this routine is just a
  26. // placeholder, it could be zero even.
  27. //
  28. // This code has enough flexibility to support multiple
  29. // PCI adapters. For now we only do one.
  30. //
  31. // Arguments:
  32. // Adapter - ptr to Adapter object instance
  33. // VendorID - Vendor ID of the adapter.
  34. // DeviceID - Device ID of the adapter.
  35. // PciCardsFound - A structure that contains an array of the IO addresses,
  36. // IRQ, and node addresses of each PCI card that we find.
  37. //
  38. // NOTE: due to NT 5's Plug and Play configuration manager
  39. // this routine will never return more than one device.
  40. //
  41. // Returns:
  42. // USHORT - Number of MK7 based PCI adapters found in the scanned bus
  43. //-----------------------------------------------------------------------------
  44. USHORT FindAndSetupPciDevice(IN PMK7_ADAPTER Adapter,
  45. NDIS_HANDLE WrapperConfigurationContext,
  46. IN USHORT VendorID,
  47. IN USHORT DeviceID,
  48. OUT PPCI_CARDS_FOUND_STRUC pPciCardsFound )
  49. {
  50. NDIS_STATUS stat;
  51. ULONG Device_Vendor_Id = 0;
  52. USHORT Slot = 0;
  53. /*
  54. * We should only need 2 adapter resources (2 IO and 1 interrupt),
  55. * but I've seen devices get extra resources.
  56. * So give the NdisMQueryAdapterResources call room for 10 resources.
  57. */
  58. #define RESOURCE_LIST_BUF_SIZE (sizeof(NDIS_RESOURCE_LIST) + (10*sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)))
  59. UCHAR buf[RESOURCE_LIST_BUF_SIZE];
  60. PNDIS_RESOURCE_LIST resList = (PNDIS_RESOURCE_LIST)buf;
  61. UINT bufSize = RESOURCE_LIST_BUF_SIZE;
  62. //****************************************
  63. // Verify the device is ours.
  64. //****************************************
  65. NdisReadPciSlotInformation(
  66. Adapter->MK7AdapterHandle,
  67. Slot,
  68. PCI_VENDOR_ID_REGISTER,
  69. (PVOID) &Device_Vendor_Id,
  70. sizeof (ULONG));
  71. if ( (((USHORT) Device_Vendor_Id) != VendorID) ||
  72. (((USHORT) (Device_Vendor_Id >> 16)) != DeviceID) ) {
  73. pPciCardsFound->NumFound = 0;
  74. return (0);
  75. }
  76. //****************************************
  77. // Controller revision id
  78. //****************************************
  79. NdisReadPciSlotInformation(
  80. Adapter->MK7AdapterHandle,
  81. Slot,
  82. PCI_REV_ID_REGISTER,
  83. &pPciCardsFound->PciSlotInfo[0].ChipRevision,
  84. sizeof(pPciCardsFound->PciSlotInfo[0].ChipRevision));
  85. //****************************************
  86. // SubDevice and SubVendor ID
  87. // (We may want this in the future.)
  88. //****************************************
  89. // NdisReadPciSlotInformation(
  90. // Adapter->MK7AdapterHandle,
  91. // Slot,
  92. // PCI_SUBVENDOR_ID_REGISTER,
  93. // &pPciCardsFound->PciSlotInfo[found].SubVendor_DeviceID,
  94. // 0x4);
  95. //
  96. pPciCardsFound->PciSlotInfo[0].SlotNumber = (USHORT) 0;
  97. NdisMQueryAdapterResources(&stat, WrapperConfigurationContext, resList, &bufSize);
  98. if (stat == NDIS_STATUS_SUCCESS) {
  99. PCM_PARTIAL_RESOURCE_DESCRIPTOR resDesc;
  100. BOOLEAN haveIRQ = FALSE,
  101. haveIOAddr = FALSE;
  102. UINT i;
  103. for (resDesc = resList->PartialDescriptors, i = 0;
  104. i < resList->Count;
  105. resDesc++, i++) {
  106. switch (resDesc->Type) {
  107. case CmResourceTypePort:
  108. if (!haveIOAddr) {
  109. if (resDesc->Flags & CM_RESOURCE_PORT_IO) {
  110. pPciCardsFound->PciSlotInfo[0].BaseIo =
  111. resDesc->u.Port.Start.LowPart;
  112. haveIOAddr = TRUE;
  113. }
  114. }
  115. break;
  116. case CmResourceTypeInterrupt:
  117. if (!haveIRQ) {
  118. pPciCardsFound->PciSlotInfo[0].Irq =
  119. (UCHAR) (resDesc->u.Port.Start.LowPart);
  120. haveIRQ = TRUE;
  121. }
  122. break;
  123. case CmResourceTypeMemory:
  124. break;
  125. }
  126. }
  127. }
  128. return(1);
  129. }