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.

287 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1991-1998 Microsoft Corporation
  3. Module Name:
  4. power.c
  5. Abstract:
  6. This module contains code to handle IRP_MJ_POWER dispatches for
  7. SFFDISK (Small Form Factor Disk) devices
  8. Author:
  9. Neil Sandlin (neilsa) 26-Apr-99
  10. Environment:
  11. Kernel mode only.
  12. --*/
  13. #include "pch.h"
  14. NTSTATUS
  15. SffDiskSetFdoPowerState(
  16. IN PDEVICE_OBJECT Fdo,
  17. IN OUT PIRP Irp
  18. );
  19. NTSTATUS
  20. SffDiskSetFdoSystemPowerState(
  21. IN PDEVICE_OBJECT Fdo,
  22. IN OUT PIRP Irp
  23. );
  24. VOID
  25. SffDiskFdoSystemPowerDeviceIrpComplete(
  26. IN PDEVICE_OBJECT Fdo,
  27. IN UCHAR MinorFunction,
  28. IN POWER_STATE PowerState,
  29. IN PVOID Context,
  30. IN PIO_STATUS_BLOCK IoStatus
  31. );
  32. NTSTATUS
  33. SffDiskSetFdoDevicePowerState (
  34. IN PDEVICE_OBJECT Fdo,
  35. IN OUT PIRP Irp
  36. );
  37. #ifdef ALLOC_PRAGMA
  38. #pragma alloc_text(PAGE,SffDiskPower)
  39. #endif
  40. NTSTATUS
  41. SffDiskPower(
  42. IN PDEVICE_OBJECT DeviceObject,
  43. IN PIRP Irp
  44. )
  45. /*++
  46. Routine Description:
  47. Arguments:
  48. DeviceObject - a pointer to the object that represents the device
  49. that I/O is to be done on.
  50. Irp - a pointer to the I/O Request Packet for this request.
  51. Return Value:
  52. --*/
  53. {
  54. NTSTATUS status = STATUS_SUCCESS;
  55. PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation( Irp );
  56. PSFFDISK_EXTENSION sffdiskExtension = DeviceObject->DeviceExtension;
  57. SffDiskDump( SFFDISKSHOW, ("SffDiskPower:\n"));
  58. switch (irpSp->MinorFunction) {
  59. case IRP_MN_SET_POWER:
  60. status = SffDiskSetFdoPowerState(DeviceObject, Irp);
  61. break;
  62. case IRP_MN_QUERY_POWER:
  63. //
  64. // No need to send this irp down
  65. //
  66. status = STATUS_SUCCESS;
  67. PoStartNextPowerIrp(Irp);
  68. Irp->IoStatus.Status = status;
  69. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  70. break;
  71. default:
  72. PoStartNextPowerIrp( Irp );
  73. IoSkipCurrentIrpStackLocation(Irp);
  74. status = PoCallDriver(sffdiskExtension->TargetObject, Irp);
  75. break;
  76. }
  77. return status;
  78. }
  79. NTSTATUS
  80. SffDiskSetFdoPowerState(
  81. IN PDEVICE_OBJECT Fdo,
  82. IN OUT PIRP Irp
  83. )
  84. /*++
  85. Routine Description
  86. Dispatches the IRP based on whether a system power state
  87. or device power state transition is requested
  88. Arguments
  89. DeviceObject - Pointer to the functional device object for the pcmcia controller
  90. Irp - Pointer to the Irp for the power dispatch
  91. Return value
  92. status
  93. --*/
  94. {
  95. PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
  96. NTSTATUS status;
  97. if (irpStack->Parameters.Power.Type == DevicePowerState) {
  98. status = SffDiskSetFdoDevicePowerState(Fdo, Irp);
  99. } else if (irpStack->Parameters.Power.Type == SystemPowerState) {
  100. status = SffDiskSetFdoSystemPowerState(Fdo, Irp);
  101. } else {
  102. status = STATUS_NOT_SUPPORTED;
  103. Irp->IoStatus.Status = status;
  104. PoStartNextPowerIrp (Irp);
  105. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  106. }
  107. return status;
  108. }
  109. NTSTATUS
  110. SffDiskSetFdoSystemPowerState(
  111. IN PDEVICE_OBJECT Fdo,
  112. IN OUT PIRP Irp
  113. )
  114. /*++
  115. Routine Description
  116. Handles system power state IRPs for the pccard controller.
  117. Arguments
  118. DeviceObject - Pointer to the functional device object for the pcmcia controller
  119. Irp - Pointer to the Irp for the power dispatch
  120. Return value
  121. status
  122. --*/
  123. {
  124. PSFFDISK_EXTENSION sffdiskExtension = Fdo->DeviceExtension;
  125. PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
  126. SYSTEM_POWER_STATE newSystemState = irpStack->Parameters.Power.State.SystemState;
  127. NTSTATUS status = STATUS_SUCCESS;
  128. POWER_STATE powerState;
  129. SffDiskDump( SFFDISKSHOW, ("SffDisk: Set System Power(%d)\n", newSystemState));
  130. ASSERT(irpStack->Parameters.Power.Type == SystemPowerState);
  131. //
  132. // Find the device power state corresponding to this system state
  133. //
  134. if (newSystemState == PowerSystemWorking) {
  135. powerState.DeviceState = PowerDeviceD0;
  136. } else {
  137. powerState.DeviceState = PowerDeviceD3;
  138. }
  139. //
  140. // Send a D IRP to the stack if necessary
  141. //
  142. SffDiskDump( SFFDISKSHOW, ("SffDisk: generating D irp (%d)\n", powerState.DeviceState));
  143. status = PoRequestPowerIrp(sffdiskExtension->DeviceObject,
  144. IRP_MN_SET_POWER,
  145. powerState,
  146. SffDiskFdoSystemPowerDeviceIrpComplete,
  147. Irp,
  148. NULL
  149. );
  150. return status;
  151. }
  152. VOID
  153. SffDiskFdoSystemPowerDeviceIrpComplete(
  154. IN PDEVICE_OBJECT Fdo,
  155. IN UCHAR MinorFunction,
  156. IN POWER_STATE PowerState,
  157. IN PVOID Context,
  158. IN PIO_STATUS_BLOCK IoStatus
  159. )
  160. /*++
  161. Routine Description
  162. This routine is called on completion of a D irp generated by an S irp.
  163. Parameters
  164. DeviceObject - Pointer to the Fdo for the PCMCIA controller
  165. MinorFunction - Minor function of the IRP_MJ_POWER request
  166. PowerState - Power state requested
  167. Context - Context passed in to the completion routine
  168. IoStatus - Pointer to the status block which will contain
  169. the returned status
  170. Return Value
  171. Status
  172. --*/
  173. {
  174. PSFFDISK_EXTENSION sffdiskExtension = Fdo->DeviceExtension;
  175. PIRP Irp = Context;
  176. PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
  177. ASSERT(NT_SUCCESS(IoStatus->Status));
  178. PoSetPowerState (Fdo, SystemPowerState, irpStack->Parameters.Power.State);
  179. //
  180. // Send the S IRP to the pdo
  181. //
  182. PoStartNextPowerIrp (Irp);
  183. IoSkipCurrentIrpStackLocation(Irp);
  184. PoCallDriver(sffdiskExtension->TargetObject, Irp);
  185. }
  186. NTSTATUS
  187. SffDiskSetFdoDevicePowerState (
  188. IN PDEVICE_OBJECT Fdo,
  189. IN OUT PIRP Irp
  190. )
  191. /*++
  192. Routine Description
  193. Handles device power state IRPs for the pccard controller.
  194. Arguments
  195. DeviceObject - Pointer to the functional device object for the pcmcia controller
  196. Irp - Pointer to the Irp for the power dispatch
  197. Return value
  198. status
  199. --*/
  200. {
  201. NTSTATUS status;
  202. PSFFDISK_EXTENSION sffdiskExtension = Fdo->DeviceExtension;
  203. SffDiskDump( SFFDISKSHOW, ("SffDisk: Set Device Power\n"));
  204. PoStartNextPowerIrp (Irp);
  205. IoSkipCurrentIrpStackLocation(Irp);
  206. status = PoCallDriver(sffdiskExtension->TargetObject, Irp);
  207. return status;
  208. }