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.

219 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. power.c
  5. Abstract: NULL filter driver -- boilerplate code
  6. Author:
  7. ervinp
  8. Environment:
  9. Kernel mode
  10. Revision History:
  11. --*/
  12. #include <WDM.H>
  13. #include "filter.h"
  14. #ifdef ALLOC_PRAGMA
  15. #ifdef HANDLE_DEVICE_USAGE
  16. #pragma alloc_text(PAGEPOWR, VA_Power)
  17. #endif // HANDLE_DEVICE_USAGE
  18. #endif
  19. NTSTATUS VA_Power(struct DEVICE_EXTENSION *devExt, PIRP irp)
  20. /*++
  21. Routine Description:
  22. Dispatch routine for Power IRPs (MajorFunction == IRP_MJ_Power)
  23. Note:
  24. If HANDLE_DEVICE_USAGE is defined
  25. This function may or may not be locked down, depending on the lower
  26. device object and if the device is in the paging path, so we can't
  27. use the PAGED_CODE() macro. Furthermore, we can't use PagedPool.
  28. Otherwise
  29. This function is left locked down.
  30. Arguments:
  31. devExt - device extension for targetted device object
  32. irp - Io Request Packet
  33. Return Value:
  34. NT status code
  35. --*/
  36. {
  37. PIO_STACK_LOCATION irpSp;
  38. NTSTATUS status;
  39. irpSp = IoGetCurrentIrpStackLocation(irp);
  40. TRACE(TL_PNP_WARNING,("VA_Power, minorFunc = %d ", (ULONG)irpSp->MinorFunction));
  41. switch (irpSp->MinorFunction){
  42. case IRP_MN_SET_POWER:
  43. switch (irpSp->Parameters.Power.Type) {
  44. case SystemPowerState:
  45. /*
  46. * For system power states, just pass the IRP down.
  47. */
  48. break;
  49. case DevicePowerState:
  50. switch (irpSp->Parameters.Power.State.DeviceState) {
  51. case PowerDeviceD0:
  52. /*
  53. * Resume from APM Suspend
  54. *
  55. * Do nothing here;
  56. * Send down the read IRPs in the completion
  57. * routine for this (the power) IRP.
  58. */
  59. break;
  60. case PowerDeviceD1:
  61. case PowerDeviceD2:
  62. case PowerDeviceD3:
  63. /*
  64. * Suspend
  65. */
  66. if (devExt->state == STATE_STARTED){
  67. devExt->state = STATE_SUSPENDED;
  68. }
  69. break;
  70. }
  71. break;
  72. }
  73. break;
  74. }
  75. /*
  76. * Send the IRP down the driver stack,
  77. * using PoCallDriver (not IoCallDriver, as for non-power irps).
  78. */
  79. IncrementPendingActionCount(devExt);
  80. IoCopyCurrentIrpStackLocationToNext(irp);
  81. IoSetCompletionRoutine( irp,
  82. VA_PowerComplete,
  83. (PVOID)devExt, // context
  84. TRUE,
  85. TRUE,
  86. TRUE);
  87. status = PoCallDriver(devExt->topDevObj, irp);
  88. return status;
  89. }
  90. NTSTATUS VA_PowerComplete(
  91. IN PDEVICE_OBJECT devObj,
  92. IN PIRP irp,
  93. IN PVOID context)
  94. /*++
  95. Routine Description:
  96. Completion routine for Power IRPs (MajorFunction == IRP_MJ_Power)
  97. Arguments:
  98. devObj - targetted device object
  99. irp - Io Request Packet
  100. context - context value passed to IoSetCompletionRoutine by VA_Power
  101. Return Value:
  102. NT status code
  103. --*/
  104. {
  105. PIO_STACK_LOCATION irpSp;
  106. struct DEVICE_EXTENSION *devExt = (struct DEVICE_EXTENSION *)context;
  107. ASSERT(devExt);
  108. ASSERT(devExt->signature == DEVICE_EXTENSION_SIGNATURE);
  109. /*
  110. * If the lower driver returned PENDING, mark our stack location as
  111. * pending also.
  112. */
  113. if (irp->PendingReturned){
  114. IoMarkIrpPending(irp);
  115. }
  116. irpSp = IoGetCurrentIrpStackLocation(irp);
  117. ASSERT(irpSp->MajorFunction == IRP_MJ_POWER);
  118. if (NT_SUCCESS(irp->IoStatus.Status)){
  119. switch (irpSp->MinorFunction){
  120. case IRP_MN_SET_POWER:
  121. switch (irpSp->Parameters.Power.Type){
  122. case DevicePowerState:
  123. switch (irpSp->Parameters.Power.State.DeviceState){
  124. case PowerDeviceD0:
  125. if (devExt->state == STATE_SUSPENDED){
  126. devExt->state = STATE_STARTED;
  127. }
  128. break;
  129. }
  130. break;
  131. }
  132. break;
  133. }
  134. }
  135. /*
  136. * Whether we are completing or relaying this power IRP,
  137. * we must call PoStartNextPowerIrp.
  138. */
  139. PoStartNextPowerIrp(irp);
  140. /*
  141. * Decrement the pendingActionCount, which we incremented in VA_Power.
  142. */
  143. DecrementPendingActionCount(devExt);
  144. return STATUS_SUCCESS;
  145. }