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. PCMCIA memory card devices
  8. Author:
  9. Neil Sandlin (neilsa) 26-Apr-99
  10. Environment:
  11. Kernel mode only.
  12. --*/
  13. #include "pch.h"
  14. NTSTATUS
  15. MemCardSetFdoPowerState(
  16. IN PDEVICE_OBJECT Fdo,
  17. IN OUT PIRP Irp
  18. );
  19. NTSTATUS
  20. MemCardSetFdoSystemPowerState(
  21. IN PDEVICE_OBJECT Fdo,
  22. IN OUT PIRP Irp
  23. );
  24. VOID
  25. MemCardFdoSystemPowerDeviceIrpComplete(
  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. MemCardSetFdoDevicePowerState (
  34. IN PDEVICE_OBJECT Fdo,
  35. IN OUT PIRP Irp
  36. );
  37. #ifdef ALLOC_PRAGMA
  38. #pragma alloc_text(PAGE,MemCardPower)
  39. #endif
  40. NTSTATUS
  41. MemCardPower(
  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. PMEMCARD_EXTENSION memcardExtension = DeviceObject->DeviceExtension;
  57. MemCardDump( MEMCARDSHOW, ("MemCardPower:\n"));
  58. switch (irpSp->MinorFunction) {
  59. case IRP_MN_SET_POWER:
  60. status = MemCardSetFdoPowerState(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(memcardExtension->TargetObject, Irp);
  75. break;
  76. }
  77. return status;
  78. }
  79. NTSTATUS
  80. MemCardSetFdoPowerState(
  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 = MemCardSetFdoDevicePowerState(Fdo, Irp);
  99. } else if (irpStack->Parameters.Power.Type == SystemPowerState) {
  100. status = MemCardSetFdoSystemPowerState(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. MemCardSetFdoSystemPowerState(
  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. PMEMCARD_EXTENSION memcardExtension = 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. MemCardDump( MEMCARDSHOW, ("MemCard: 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. MemCardDump( MEMCARDSHOW, ("MemCard: generating D irp (%d)\n", powerState.DeviceState));
  143. status = PoRequestPowerIrp(memcardExtension->DeviceObject,
  144. IRP_MN_SET_POWER,
  145. powerState,
  146. MemCardFdoSystemPowerDeviceIrpComplete,
  147. Irp,
  148. NULL
  149. );
  150. return status;
  151. }
  152. VOID
  153. MemCardFdoSystemPowerDeviceIrpComplete(
  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. PMEMCARD_EXTENSION memcardExtension = 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(memcardExtension->TargetObject, Irp);
  185. }
  186. NTSTATUS
  187. MemCardSetFdoDevicePowerState (
  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. PMEMCARD_EXTENSION memcardExtension = Fdo->DeviceExtension;
  203. MemCardDump( MEMCARDSHOW, ("MemCard: Set Device Power\n"));
  204. PoStartNextPowerIrp (Irp);
  205. IoSkipCurrentIrpStackLocation(Irp);
  206. status = PoCallDriver(memcardExtension->TargetObject, Irp);
  207. return status;
  208. }