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.

289 lines
9.4 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. dispatch.c
  5. Abstract:
  6. This module contains the PNP, IOCTL, and Power dispatch routines for softpci.sys
  7. Author:
  8. Nicholas Owens (nichow) 11-Mar-1999
  9. Revision History:
  10. --*/
  11. #include "pch.h"
  12. #ifdef ALLOC_PRAGMA
  13. #pragma alloc_text (PAGE, SoftPCIDispatchPnP)
  14. #pragma alloc_text (PAGE, SoftPCIDispatchPower)
  15. #pragma alloc_text (PAGE, SoftPCIDispatchDeviceControl)
  16. #endif
  17. #define MAX_PNP_IRP_SUPPORTED 0x18
  18. PDRIVER_DISPATCH SoftPciFilterPnPDispatchTable[] = {
  19. SoftPCIFilterStartDevice, // IRP_MN_START_DEVICE 0x00
  20. SoftPCIPassIrpDownSuccess, // IRP_MN_QUERY_REMOVE_DEVICE 0x01
  21. SoftPCIIrpRemoveDevice, // IRP_MN_REMOVE_DEVICE 0x02
  22. SoftPCIPassIrpDownSuccess, // IRP_MN_CANCEL_REMOVE_DEVICE 0x03
  23. SoftPCIPassIrpDownSuccess, // IRP_MN_STOP_DEVICE 0x04
  24. SoftPCIPassIrpDownSuccess, // IRP_MN_QUERY_STOP_DEVICE 0x05
  25. SoftPCIPassIrpDownSuccess, // IRP_MN_CANCEL_STOP_DEVICE 0x06
  26. SoftPCIPassIrpDown, // IRP_MN_QUERY_DEVICE_RELATIONS 0x07
  27. SoftPCIFilterQueryInterface, // IRP_MN_QUERY_INTERFACE 0x08
  28. SoftPCIPassIrpDownSuccess, // IRP_MN_QUERY_CAPABILITIES 0x09
  29. SoftPCIPassIrpDown, // IRP_MN_QUERY_RESOURCES 0x0A
  30. SoftPCIPassIrpDown, // IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
  31. SoftPCIPassIrpDown, // IRP_MN_QUERY_DEVICE_TEXT 0x0C
  32. SoftPCIPassIrpDown, // IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
  33. SoftPCIPassIrpDown, // IRP_MN_IRP_UNKNOWN 0x0E
  34. SoftPCIPassIrpDown, // IRP_MN_READ_CONFIG 0x0F
  35. SoftPCIPassIrpDown, // IRP_MN_WRITE_CONFIG 0x10
  36. SoftPCIPassIrpDown, // IRP_MN_EJECT 0x11
  37. SoftPCIPassIrpDown, // IRP_MN_SET_LOCK 0x12
  38. SoftPCIPassIrpDown, // IRP_MN_QUERY_ID 0x13
  39. SoftPCIPassIrpDown, // IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
  40. SoftPCIPassIrpDown, // IRP_MN_QUERY_BUS_INFORMATION 0x15
  41. SoftPCIPassIrpDown, // IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
  42. SoftPCIPassIrpDownSuccess, // IRP_MN_SURPRISE_REMOVAL 0x17
  43. SoftPCIPassIrpDown, // IRP_MN_QUERY_LEGACY_BUS_REQUIREMENTS0x18
  44. };
  45. PDRIVER_DISPATCH SoftPciFdoPnPDispatchTable[] = {
  46. #ifdef SIMULATE_MSI
  47. SoftPCI_FdoStartDevice, // IRP_MN_START_DEVICE 0x00
  48. #else
  49. SoftPCIPassIrpDownSuccess, // IRP_MN_START_DEVICE 0x00
  50. #endif
  51. SoftPCIPassIrpDownSuccess, // IRP_MN_QUERY_REMOVE_DEVICE 0x01
  52. SoftPCIIrpRemoveDevice, // IRP_MN_REMOVE_DEVICE 0x02
  53. SoftPCIPassIrpDownSuccess, // IRP_MN_CANCEL_REMOVE_DEVICE 0x03
  54. SoftPCIPassIrpDownSuccess, // IRP_MN_STOP_DEVICE 0x04
  55. SoftPCIPassIrpDownSuccess, // IRP_MN_QUERY_STOP_DEVICE 0x05
  56. SoftPCIPassIrpDownSuccess, // IRP_MN_CANCEL_STOP_DEVICE 0x06
  57. SoftPCIPassIrpDown, // IRP_MN_QUERY_DEVICE_RELATIONS 0x07
  58. SoftPCIPassIrpDown, // IRP_MN_QUERY_INTERFACE 0x08
  59. SoftPCIPassIrpDownSuccess, // IRP_MN_QUERY_CAPABILITIES 0x09
  60. SoftPCIPassIrpDown, // IRP_MN_QUERY_RESOURCES 0x0A
  61. SoftPCIPassIrpDown, // IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
  62. SoftPCIPassIrpDown, // IRP_MN_QUERY_DEVICE_TEXT 0x0C
  63. SoftPCI_FdoFilterRequirements, // IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
  64. SoftPCIPassIrpDown, // IRP_MN_IRP_UNKNOWN 0x0E
  65. SoftPCIPassIrpDown, // IRP_MN_READ_CONFIG 0x0F
  66. SoftPCIPassIrpDown, // IRP_MN_WRITE_CONFIG 0x10
  67. SoftPCIPassIrpDown, // IRP_MN_EJECT 0x11
  68. SoftPCIPassIrpDown, // IRP_MN_SET_LOCK 0x12
  69. SoftPCIPassIrpDown, // IRP_MN_QUERY_ID 0x13
  70. SoftPCIPassIrpDown, // IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
  71. SoftPCIPassIrpDown, // IRP_MN_QUERY_BUS_INFORMATION 0x15
  72. SoftPCIPassIrpDown, // IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
  73. SoftPCIPassIrpDownSuccess, // IRP_MN_SURPRISE_REMOVAL 0x17
  74. SoftPCIPassIrpDown, // IRP_MN_QUERY_LEGACY_BUS_REQUIREMENTS0x18
  75. };
  76. PDRIVER_DISPATCH SoftPciIOCTLDispatchTable[] = {
  77. SoftPCIIoctlAddDevice, // SOFTPCI_IOCTL_CREATE_DEVICE
  78. SoftPCIIoctlRemoveDevice, // SOFTPCI_IOCTL_WRITE_DELETE_DEVICE
  79. SoftPCIIoctlGetDevice, // SOFTPCI_IOCTL_GET_DEVICE
  80. SoftPCIIocltReadWriteConfig, // SOFTPCI_IOCTL_RW_CONFIG
  81. SoftPCIIoctlGetDeviceCount // SOFTPCI_IOCTL_GET_DEVICE_COUNT
  82. };
  83. NTSTATUS
  84. SoftPCIDispatchPnP(
  85. IN PDEVICE_OBJECT DeviceObject,
  86. IN PIRP Irp
  87. )
  88. /*++
  89. Routine Description:
  90. Dispatches PnP Irps for FDO and FilterDOs
  91. Arguments:
  92. DeviceObject - pointer to the device object.
  93. Irp - PnP Irp to be dispatched.
  94. Return Value:
  95. NTSTATUS.
  96. --*/
  97. {
  98. NTSTATUS status = STATUS_SUCCESS;
  99. PIO_STACK_LOCATION irpSp;
  100. PSOFTPCI_DEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
  101. irpSp = IoGetCurrentIrpStackLocation(Irp);
  102. //
  103. // Call the appropriate minor Irp Code handler.
  104. //
  105. if (irpSp->MinorFunction <= MAX_PNP_IRP_SUPPORTED) {
  106. if (deviceExtension->FilterDevObj) {
  107. status = SoftPciFilterPnPDispatchTable[irpSp->MinorFunction](DeviceObject,
  108. Irp
  109. );
  110. } else {
  111. status = SoftPciFdoPnPDispatchTable[irpSp->MinorFunction](DeviceObject,
  112. Irp
  113. );
  114. }
  115. } else {
  116. status = SoftPCIPassIrpDown(DeviceObject, Irp);
  117. }
  118. return status;
  119. }
  120. NTSTATUS
  121. SoftPCIDispatchPower(
  122. IN PDEVICE_OBJECT DeviceObject,
  123. IN PIRP Irp
  124. )
  125. /*++
  126. Routine Description:
  127. Dispatches Power IRPs
  128. Arguments:
  129. DeviceObject - pointer to the device object.
  130. Irp - PnP Irp to be dispatched.
  131. Return Value:
  132. NTSTATUS.
  133. --*/
  134. {
  135. PSOFTPCI_DEVICE_EXTENSION devExt = (PSOFTPCI_DEVICE_EXTENSION) DeviceObject->DeviceExtension;
  136. if (devExt->FilterDevObj) {
  137. //
  138. // If this is our FilterDO just pass the IRP on down
  139. //
  140. return SoftPCIDefaultPowerHandler(DeviceObject,
  141. Irp);
  142. }else{
  143. //
  144. // Otherwise lets pretend to power manage our device
  145. //
  146. return SoftPCIFDOPowerHandler(DeviceObject,
  147. Irp);
  148. }
  149. }
  150. NTSTATUS
  151. SoftPCIDispatchDeviceControl(
  152. IN PDEVICE_OBJECT DeviceObject,
  153. IN PIRP Irp
  154. )
  155. /*++
  156. Routine Description:
  157. Dispatches IOCTLS for FilterDOs.
  158. Arguments:
  159. DeviceObject - pointer to the device object.
  160. Irp - PnP Irp to be dispatched.
  161. Return Value:
  162. NTSTATUS.
  163. --*/
  164. {
  165. NTSTATUS status = STATUS_SUCCESS;
  166. ULONG ioControlCode = IoGetCurrentIrpStackLocation(Irp)->
  167. Parameters.DeviceIoControl.IoControlCode;
  168. //
  169. // Make sure it is our IOCTL Type
  170. //
  171. if ((DEVICE_TYPE_FROM_CTL_CODE(ioControlCode)) == SOFTPCI_IOCTL_TYPE) {
  172. //
  173. // Make sure it is an IOCTL function we support
  174. //
  175. if (SOFTPCI_IOCTL(ioControlCode) <= MAX_IOCTL_CODE_SUPPORTED) {
  176. //
  177. // Dispatch Device Control IOCTL
  178. //
  179. status = SoftPciIOCTLDispatchTable[SOFTPCI_IOCTL(ioControlCode)](DeviceObject,
  180. Irp
  181. );
  182. //
  183. // Set Status of Irp and complete it
  184. //
  185. Irp->IoStatus.Status = status;
  186. //
  187. // Complete the Irp.
  188. //
  189. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  190. }else{
  191. //
  192. // We dont support this IOCTL function so fail and complete.
  193. //
  194. status = STATUS_NOT_SUPPORTED;
  195. Irp->IoStatus.Status = status;
  196. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  197. return status;
  198. }
  199. } else {
  200. status = SoftPCIPassIrpDown(DeviceObject, Irp);
  201. }
  202. return status;
  203. }