Source code of Windows XP (NT5)
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.

200 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. power.c
  5. Abstract: ESC/POS (serial) interface for USB Point-of-Sale devices
  6. Author:
  7. ervinp
  8. Environment:
  9. Kernel mode
  10. Revision History:
  11. --*/
  12. #include <WDM.H>
  13. #include <usbdi.h>
  14. #include <usbdlib.h>
  15. #include <usbioctl.h>
  16. #include "escpos.h"
  17. #include "debug.h"
  18. NTSTATUS FDO_Power(PARENTFDOEXT *parentFdoExt, PIRP irp)
  19. /*++
  20. Routine Description:
  21. Dispatch routine for Power IRPs (MajorFunction == IRP_MJ_Power)
  22. Note: We may or may not have set the DO_POWER_PAGABLE bit
  23. for the filter device object in AddDevice().
  24. Therefore, we don't know whether or not this function
  25. can be called at DISPATCH_LEVEL; so the power-handling
  26. code must be locked.
  27. Arguments:
  28. parentFdoExt - device extension for targetted device object
  29. irp - Io Request Packet
  30. Return Value:
  31. NT status code
  32. --*/
  33. {
  34. PIO_STACK_LOCATION irpSp;
  35. NTSTATUS status;
  36. irpSp = IoGetCurrentIrpStackLocation(irp);
  37. switch (irpSp->MinorFunction){
  38. case IRP_MN_SET_POWER:
  39. DBGVERBOSE(("IRP_MN_SET_POWER"));
  40. switch (irpSp->Parameters.Power.Type) {
  41. case SystemPowerState:
  42. /*
  43. * For system power states, just pass the IRP down.
  44. */
  45. break;
  46. case DevicePowerState:
  47. switch (irpSp->Parameters.Power.State.DeviceState) {
  48. case PowerDeviceD0:
  49. /*
  50. * Resume from APM Suspend
  51. *
  52. * Do nothing here;
  53. * Send down the read IRPs in the completion
  54. * routine for this (the power) IRP.
  55. */
  56. break;
  57. case PowerDeviceD1:
  58. case PowerDeviceD2:
  59. case PowerDeviceD3:
  60. /*
  61. * Suspend
  62. */
  63. if (parentFdoExt->state == STATE_STARTED){
  64. parentFdoExt->state = STATE_SUSPENDED;
  65. }
  66. break;
  67. }
  68. break;
  69. }
  70. break;
  71. default:
  72. DBGVERBOSE(("Power, minorFunc = %d ", (ULONG)irpSp->MinorFunction));
  73. break;
  74. }
  75. /*
  76. * Whether we are completing or relaying this power IRP,
  77. * we must call PoStartNextPowerIrp.
  78. */
  79. PoStartNextPowerIrp(irp);
  80. /*
  81. * Send the IRP down the driver stack,
  82. * using PoCallDriver (not IoCallDriver, as for non-power irps).
  83. */
  84. IoCopyCurrentIrpStackLocationToNext(irp);
  85. IncrementPendingActionCount(parentFdoExt);
  86. IoSetCompletionRoutine( irp,
  87. FDO_PowerComplete,
  88. (PVOID)parentFdoExt, // context
  89. TRUE,
  90. TRUE,
  91. TRUE);
  92. status = PoCallDriver(parentFdoExt->physicalDevObj, irp);
  93. return status;
  94. }
  95. NTSTATUS FDO_PowerComplete(
  96. IN PDEVICE_OBJECT devObj,
  97. IN PIRP irp,
  98. IN PVOID context)
  99. /*++
  100. Routine Description:
  101. Completion routine for Power IRPs (MajorFunction == IRP_MJ_Power)
  102. Arguments:
  103. devObj - targetted device object
  104. irp - Io Request Packet
  105. context - context value passed to IoSetCompletionRoutine by FDO_Power
  106. Return Value:
  107. NT status code
  108. --*/
  109. {
  110. PIO_STACK_LOCATION irpSp;
  111. PARENTFDOEXT *parentFdoExt = (PARENTFDOEXT *)context;
  112. ASSERT(parentFdoExt);
  113. irpSp = IoGetCurrentIrpStackLocation(irp);
  114. ASSERT(irpSp->MajorFunction == IRP_MJ_POWER);
  115. if (NT_SUCCESS(irp->IoStatus.Status)){
  116. switch (irpSp->MinorFunction){
  117. case IRP_MN_SET_POWER:
  118. switch (irpSp->Parameters.Power.Type){
  119. case DevicePowerState:
  120. switch (irpSp->Parameters.Power.State.DeviceState){
  121. case PowerDeviceD0:
  122. if (parentFdoExt->state == STATE_SUSPENDED){
  123. parentFdoExt->state = STATE_STARTED;
  124. }
  125. break;
  126. }
  127. break;
  128. }
  129. break;
  130. }
  131. }
  132. /*
  133. * Decrement the pendingActionCount, which we incremented in FDO_Power.
  134. */
  135. DecrementPendingActionCount(parentFdoExt);
  136. return STATUS_SUCCESS;
  137. }