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.

294 lines
6.3 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name:
  4. lddintrf.c
  5. Abstract:
  6. This module implements the "legacy device detection" interface
  7. supported by the PCI driver.
  8. Author:
  9. Dave Richards (daveri) 2-Oct-1998
  10. Revision History:
  11. --*/
  12. #include "pcip.h"
  13. #define LDDINTRF_VERSION 0
  14. //
  15. // Prototypes for routines exposed only through the "interface"
  16. // mechanism.
  17. //
  18. NTSTATUS
  19. lddintrf_Constructor(
  20. IN PVOID DeviceExtension,
  21. IN PVOID PciInterface,
  22. IN PVOID InterfaceSpecificData,
  23. IN USHORT Version,
  24. IN USHORT Size,
  25. IN PINTERFACE InterfaceReturn
  26. );
  27. VOID
  28. lddintrf_Reference(
  29. IN PVOID Context
  30. );
  31. VOID
  32. lddintrf_Dereference(
  33. IN PVOID Context
  34. );
  35. NTSTATUS
  36. lddintrf_Initializer(
  37. IN PVOID Instance
  38. );
  39. NTSTATUS
  40. PciLegacyDeviceDetection(
  41. IN PVOID Context,
  42. IN INTERFACE_TYPE LegacyBusType,
  43. IN ULONG BusNumber,
  44. IN ULONG SlotNumber,
  45. OUT PDEVICE_OBJECT *PhysicalDeviceObject
  46. );
  47. //
  48. // Define the Legacy Device Detection "Interface" structure.
  49. //
  50. PCI_INTERFACE PciLegacyDeviceDetectionInterface = {
  51. &GUID_LEGACY_DEVICE_DETECTION_STANDARD, // InterfaceType
  52. sizeof(LEGACY_DEVICE_DETECTION_INTERFACE),
  53. // MinSize
  54. LDDINTRF_VERSION, // MinVersion
  55. LDDINTRF_VERSION, // MaxVersion
  56. PCIIF_FDO, // Flags
  57. 0, // ReferenceCount
  58. PciInterface_LegacyDeviceDetection, // Signature
  59. lddintrf_Constructor, // Constructor
  60. lddintrf_Initializer // Instance Initializer
  61. };
  62. #ifdef ALLOC_PRAGMA
  63. #pragma alloc_text(PAGE, lddintrf_Constructor)
  64. #pragma alloc_text(PAGE, lddintrf_Dereference)
  65. #pragma alloc_text(PAGE, lddintrf_Initializer)
  66. #pragma alloc_text(PAGE, lddintrf_Reference)
  67. #pragma alloc_text(PAGE, PciLegacyDeviceDetection)
  68. #endif
  69. VOID
  70. lddintrf_Reference(
  71. IN PVOID Context
  72. )
  73. /*++
  74. Routine Description:
  75. This routine adds a reference to a legacy device detection interface.
  76. Arguments:
  77. Instance - FDO extension pointer.
  78. Return Value:
  79. None.
  80. --*/
  81. {
  82. ASSERT_PCI_FDO_EXTENSION((PPCI_FDO_EXTENSION)Context);
  83. }
  84. VOID
  85. lddintrf_Dereference(
  86. IN PVOID Context
  87. )
  88. /*++
  89. Routine Description:
  90. This routine releases a reference to a legacy device detection interface.
  91. Arguments:
  92. Instance - FDO extension pointer.
  93. Return Value:
  94. None.
  95. --*/
  96. {
  97. ASSERT_PCI_FDO_EXTENSION((PPCI_FDO_EXTENSION)Context);
  98. }
  99. NTSTATUS
  100. lddintrf_Constructor(
  101. IN PVOID DeviceExtension,
  102. IN PVOID PciInterface,
  103. IN PVOID InterfaceSpecificData,
  104. IN USHORT Version,
  105. IN USHORT Size,
  106. IN PINTERFACE InterfaceReturn
  107. )
  108. /*++
  109. Routine Description:
  110. This routine constructs a LEGACY_DEVICE_DETECTION_INTERFACE.
  111. Arguments:
  112. DeviceExtension - An FDO extenion pointer.
  113. PCIInterface - PciInterface_LegacyDeviceDetection.
  114. InterfaceSpecificData - Unused.
  115. Version - Interface version.
  116. Size - Size of the LEGACY_DEVICE_DETECTION interface object.
  117. InterfaceReturn - The interface object pointer.
  118. Return Value:
  119. Returns NTSTATUS.
  120. --*/
  121. {
  122. PLEGACY_DEVICE_DETECTION_INTERFACE standard;
  123. standard = (PLEGACY_DEVICE_DETECTION_INTERFACE)InterfaceReturn;
  124. standard->Size = sizeof( LEGACY_DEVICE_DETECTION_INTERFACE );
  125. standard->Version = LDDINTRF_VERSION;
  126. standard->Context = DeviceExtension;
  127. standard->InterfaceReference = lddintrf_Reference;
  128. standard->InterfaceDereference = lddintrf_Dereference;
  129. standard->LegacyDeviceDetection = PciLegacyDeviceDetection;
  130. return STATUS_SUCCESS;
  131. }
  132. NTSTATUS
  133. lddintrf_Initializer(
  134. IN PVOID Instance
  135. )
  136. /*++
  137. Routine Description:
  138. For legacy device detection does nothing, shouldn't actually be called.
  139. Arguments:
  140. Instance - FDO extension pointer.
  141. Return Value:
  142. Returns NTSTATUS.
  143. --*/
  144. {
  145. PCI_ASSERTMSG("PCI lddintrf_Initializer, unexpected call.", FALSE);
  146. return STATUS_UNSUCCESSFUL;
  147. }
  148. NTSTATUS
  149. PciLegacyDeviceDetection(
  150. IN PVOID Context,
  151. IN INTERFACE_TYPE LegacyBusType,
  152. IN ULONG BusNumber,
  153. IN ULONG SlotNumber,
  154. OUT PDEVICE_OBJECT *PhysicalDeviceObject
  155. )
  156. /*++
  157. Routine Description:
  158. This function searches for a legacy device, specified by LegacyBusType,
  159. BusNumber and SlotNumber, and returns a referenced physical device object
  160. as an output argument.
  161. Arguments:
  162. Context - Supplies a pointer to the interface context. This is actually
  163. the FDO for the given bus.
  164. LegacyBusType - PCIBus.
  165. BusNumber - The legacy device's bus number.
  166. SlotNumber - The legacy device's slot number.
  167. PhysicalDeviceObject - The return argument i.e. a reference physical
  168. device object if the corresponding legacy device is found.
  169. Return Value:
  170. Returns NTSTATUS.
  171. --*/
  172. {
  173. PCI_SLOT_NUMBER slotNumber;
  174. PPCI_FDO_EXTENSION fdoExtension;
  175. PPCI_PDO_EXTENSION pdoExtension;
  176. NTSTATUS status = STATUS_UNSUCCESSFUL;
  177. fdoExtension = (PPCI_FDO_EXTENSION)Context;
  178. ASSERT_PCI_FDO_EXTENSION(fdoExtension);
  179. if (LegacyBusType != PCIBus) {
  180. return STATUS_UNSUCCESSFUL;
  181. }
  182. if (fdoExtension->BaseBus != BusNumber) {
  183. return STATUS_UNSUCCESSFUL;
  184. }
  185. slotNumber.u.AsULONG = SlotNumber;
  186. ExAcquireFastMutex(&fdoExtension->SecondaryExtMutex);
  187. for (pdoExtension = fdoExtension->ChildPdoList;
  188. pdoExtension != NULL;
  189. pdoExtension = pdoExtension->Next) {
  190. if (pdoExtension->Slot.u.bits.DeviceNumber == slotNumber.u.bits.DeviceNumber &&
  191. pdoExtension->Slot.u.bits.FunctionNumber == slotNumber.u.bits.FunctionNumber) {
  192. if (pdoExtension->DeviceState != PciNotStarted) {
  193. break;
  194. }
  195. // pdoExtension->DeviceState = PciLockedBecauseNotPnp;
  196. *PhysicalDeviceObject = pdoExtension->PhysicalDeviceObject;
  197. ObReferenceObject(pdoExtension->PhysicalDeviceObject);
  198. status = STATUS_SUCCESS;
  199. break;
  200. }
  201. }
  202. ExReleaseFastMutex(&fdoExtension->SecondaryExtMutex);
  203. return status;
  204. }