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.

130 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1991 - 2001 Microsoft Corporation
  3. Module Name:
  4. ##### ##### ## # ## ##### ##### #### ##### #####
  5. ## ## ## ## ## ### ## ## ## ## ## # ## ## ## ##
  6. ## ## ## ## ## ### ## ## ## ## ## ## ## ## ##
  7. ## ## ## ## ## # # ## ##### ##### ## ## ## ## ##
  8. ##### ## ## ### ### ## #### ## ##### #####
  9. ## ## ## ### ### ## ## ## ## ## # ## ##
  10. ## ##### ## ## ##### ## ## ## #### ## ##
  11. Abstract:
  12. This module process all power management IRPs.
  13. Author:
  14. Wesley Witt (wesw) 1-Oct-2001
  15. Environment:
  16. Kernel mode only.
  17. Notes:
  18. --*/
  19. #include "internal.h"
  20. #ifdef ALLOC_PRAGMA
  21. #pragma alloc_text(PAGE,WdPower)
  22. #endif
  23. NTSTATUS
  24. WdPower(
  25. IN PDEVICE_OBJECT DeviceObject,
  26. IN PIRP Irp
  27. )
  28. /*++
  29. Routine Description:
  30. Arguments:
  31. DeviceObject - a pointer to the object that represents the device
  32. that I/O is to be done on.
  33. Irp - a pointer to the I/O Request Packet for this request.
  34. Return Value:
  35. --*/
  36. {
  37. NTSTATUS Status = STATUS_SUCCESS;
  38. PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  39. PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
  40. ULONG TimeoutValue;
  41. switch (IrpSp->MinorFunction) {
  42. case IRP_MN_WAIT_WAKE:
  43. case IRP_MN_POWER_SEQUENCE:
  44. case IRP_MN_QUERY_POWER:
  45. Status = STATUS_SUCCESS;
  46. break;
  47. case IRP_MN_SET_POWER:
  48. switch (IrpSp->Parameters.Power.State.SystemState) {
  49. case PowerSystemSleeping1:
  50. //
  51. // The system is being suspended
  52. //
  53. WdHandlerStopTimer( DeviceExtension );
  54. break;
  55. case PowerSystemHibernate:
  56. //
  57. // The system is hibernating
  58. //
  59. WdHandlerStopTimer( DeviceExtension );
  60. break;
  61. case PowerSystemWorking:
  62. //
  63. // The system is waking up from suspend/hibernate
  64. //
  65. WdHandlerStartTimer( DeviceExtension );
  66. break;
  67. case PowerSystemShutdown:
  68. //
  69. // The system is shutting down normally
  70. //
  71. if (ShutdownCountTime > MIN_TIMEOUT_VALUE) {
  72. TimeoutValue = ShutdownCountTime;
  73. } else {
  74. TimeoutValue = (ULONG)DeviceExtension->MaxCount;
  75. }
  76. WdHandlerSetTimeoutValue( DeviceExtension, TimeoutValue, TRUE );
  77. switch (IrpSp->Parameters.Power.ShutdownType) {
  78. case PowerActionShutdownOff:
  79. TimeoutValue = 1;
  80. break;
  81. case PowerActionShutdownReset:
  82. TimeoutValue = 0;
  83. break;
  84. }
  85. WdHandlerSetTriggerAction( DeviceExtension, TimeoutValue );
  86. break;
  87. }
  88. Status = STATUS_SUCCESS;
  89. break;
  90. default:
  91. Status = Irp->IoStatus.Status;
  92. break;
  93. }
  94. Irp->IoStatus.Status = Status;
  95. PoStartNextPowerIrp(Irp);
  96. IoSkipCurrentIrpStackLocation( Irp );
  97. return PoCallDriver( DeviceExtension->TargetObject, Irp );
  98. }