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.

298 lines
6.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. POWER.C
  5. Abstract:
  6. This module contains contains the power calls for the serenum bus driver.
  7. @@BEGIN_DDKSPLIT
  8. Author:
  9. Jay Senior
  10. @@END_DDKSPLIT
  11. Environment:
  12. kernel mode only
  13. Notes:
  14. @@BEGIN_DDKSPLIT
  15. Revision History:
  16. Louis J. Giliberto, Jr. 07-Jan-2000
  17. @@END_DDKSPLIT
  18. --*/
  19. #include "pch.h"
  20. #ifdef ALLOC_PRAGMA
  21. //#pragma alloc_text (PAGE, Serenum_Power)
  22. //#pragma alloc_text (PAGE, Serenum_FDO_Power)
  23. //#pragma alloc_text (PAGE, Serenum_PDO_Power)
  24. #endif
  25. NTSTATUS
  26. Serenum_FDOPowerComplete (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
  27. IN PVOID Context)
  28. /*++
  29. --*/
  30. {
  31. POWER_STATE powerState;
  32. POWER_STATE_TYPE powerType;
  33. PIO_STACK_LOCATION stack;
  34. PFDO_DEVICE_DATA data;
  35. UNREFERENCED_PARAMETER(Context);
  36. if (Irp->PendingReturned) {
  37. IoMarkIrpPending(Irp);
  38. }
  39. data = (PFDO_DEVICE_DATA)DeviceObject->DeviceExtension;
  40. stack = IoGetCurrentIrpStackLocation(Irp);
  41. powerType = stack->Parameters.Power.Type;
  42. powerState = stack->Parameters.Power.State;
  43. switch (stack->MinorFunction) {
  44. case IRP_MN_SET_POWER:
  45. switch (powerType) {
  46. case DevicePowerState:
  47. //
  48. // Powering Up
  49. //
  50. ASSERT(powerState.DeviceState < data->DeviceState);
  51. data->DeviceState = powerState.DeviceState;
  52. PoSetPowerState(data->Self, powerType, powerState);
  53. break;
  54. default:
  55. break;
  56. }
  57. break;
  58. case IRP_MN_QUERY_POWER:
  59. ASSERT(IRP_MN_QUERY_POWER != stack->MinorFunction);
  60. break;
  61. default:
  62. //
  63. // Basically, this is ASSERT(0)
  64. //
  65. ASSERT(0xBADBAD == IRP_MN_QUERY_POWER);
  66. break;
  67. }
  68. PoStartNextPowerIrp(Irp);
  69. Serenum_DecIoCount(data);
  70. return STATUS_SUCCESS; // Continue completion...
  71. }
  72. NTSTATUS
  73. Serenum_FDO_Power(PFDO_DEVICE_DATA Data, PIRP Irp)
  74. /*++
  75. --*/
  76. {
  77. NTSTATUS status;
  78. BOOLEAN hookit = FALSE;
  79. POWER_STATE powerState;
  80. POWER_STATE_TYPE powerType;
  81. PIO_STACK_LOCATION stack;
  82. stack = IoGetCurrentIrpStackLocation(Irp);
  83. powerType = stack->Parameters.Power.Type;
  84. powerState = stack->Parameters.Power.State;
  85. status = Serenum_IncIoCount (Data);
  86. if (!NT_SUCCESS(status)) {
  87. Irp->IoStatus.Information = 0;
  88. Irp->IoStatus.Status = status;
  89. PoStartNextPowerIrp(Irp);
  90. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  91. return status;
  92. }
  93. switch (stack->MinorFunction) {
  94. case IRP_MN_SET_POWER:
  95. //
  96. // If it hasn't started, we just pass it through
  97. //
  98. if (Data->Started != TRUE) {
  99. status = Irp->IoStatus.Status = STATUS_SUCCESS;
  100. break;
  101. }
  102. Serenum_KdPrint(Data, SER_DBG_PNP_TRACE,
  103. ("Serenum-PnP Setting %s state to %d\n",
  104. ((powerType == SystemPowerState) ? "System" : "Device"),
  105. powerState.SystemState));
  106. switch (powerType) {
  107. case DevicePowerState:
  108. status = Irp->IoStatus.Status = STATUS_SUCCESS;
  109. if (Data->DeviceState < powerState.DeviceState) {
  110. PoSetPowerState (Data->Self, powerType, powerState);
  111. Data->DeviceState = powerState.DeviceState;
  112. } else if (Data->DeviceState > powerState.DeviceState) {
  113. //
  114. // Powering Up
  115. //
  116. hookit = TRUE;
  117. }
  118. break;
  119. case SystemPowerState:
  120. //
  121. // status should be STATUS_SUCCESS
  122. //
  123. break;
  124. }
  125. break;
  126. case IRP_MN_QUERY_POWER:
  127. status = Irp->IoStatus.Status = STATUS_SUCCESS;
  128. break;
  129. default:
  130. //
  131. // status should be STATUS_SUCCESS
  132. //
  133. break;
  134. }
  135. IoCopyCurrentIrpStackLocationToNext (Irp);
  136. if (hookit) {
  137. status = Serenum_IncIoCount (Data);
  138. ASSERT (STATUS_SUCCESS == status);
  139. IoSetCompletionRoutine(Irp, Serenum_FDOPowerComplete, NULL, TRUE, TRUE,
  140. TRUE);
  141. status = PoCallDriver (Data->TopOfStack, Irp);
  142. } else {
  143. PoStartNextPowerIrp (Irp);
  144. status = PoCallDriver (Data->TopOfStack, Irp);
  145. }
  146. Serenum_DecIoCount (Data);
  147. return status;
  148. }
  149. NTSTATUS
  150. Serenum_PDO_Power (
  151. PPDO_DEVICE_DATA PdoData,
  152. PIRP Irp
  153. )
  154. /*++
  155. --*/
  156. {
  157. NTSTATUS status = STATUS_SUCCESS;
  158. PIO_STACK_LOCATION stack;
  159. POWER_STATE powerState;
  160. POWER_STATE_TYPE powerType;
  161. stack = IoGetCurrentIrpStackLocation (Irp);
  162. powerType = stack->Parameters.Power.Type;
  163. powerState = stack->Parameters.Power.State;
  164. switch (stack->MinorFunction) {
  165. case IRP_MN_SET_POWER:
  166. switch (powerType) {
  167. case DevicePowerState:
  168. if (PdoData->DeviceState > powerState.DeviceState) {
  169. PoSetPowerState (PdoData->Self, powerType, powerState);
  170. PdoData->DeviceState = powerState.DeviceState;
  171. } else if (PdoData->DeviceState < powerState.DeviceState) {
  172. //
  173. // Powering down.
  174. //
  175. PoSetPowerState (PdoData->Self, powerType, powerState);
  176. PdoData->DeviceState = powerState.DeviceState;
  177. }
  178. break;
  179. case SystemPowerState:
  180. //
  181. // Default to STATUS_SUCCESS
  182. //
  183. break;
  184. default:
  185. status = STATUS_NOT_IMPLEMENTED;
  186. break;
  187. }
  188. break;
  189. case IRP_MN_QUERY_POWER:
  190. //
  191. // Default to STATUS_SUCCESS
  192. //
  193. break;
  194. case IRP_MN_WAIT_WAKE:
  195. case IRP_MN_POWER_SEQUENCE:
  196. status = STATUS_NOT_IMPLEMENTED;
  197. break;
  198. default:
  199. status = Irp->IoStatus.Status;
  200. }
  201. Irp->IoStatus.Status = status;
  202. PoStartNextPowerIrp (Irp);
  203. IoCompleteRequest (Irp, IO_NO_INCREMENT);
  204. return status;
  205. }
  206. NTSTATUS
  207. Serenum_Power (
  208. IN PDEVICE_OBJECT DeviceObject,
  209. IN PIRP Irp
  210. )
  211. /*++
  212. --*/
  213. {
  214. PIO_STACK_LOCATION irpStack;
  215. NTSTATUS status;
  216. PCOMMON_DEVICE_DATA commonData;
  217. status = STATUS_SUCCESS;
  218. irpStack = IoGetCurrentIrpStackLocation (Irp);
  219. ASSERT (IRP_MJ_POWER == irpStack->MajorFunction);
  220. commonData = (PCOMMON_DEVICE_DATA) DeviceObject->DeviceExtension;
  221. if (commonData->IsFDO) {
  222. status =
  223. Serenum_FDO_Power ((PFDO_DEVICE_DATA) DeviceObject->DeviceExtension,
  224. Irp);
  225. } else {
  226. status =
  227. Serenum_PDO_Power ((PPDO_DEVICE_DATA) DeviceObject->DeviceExtension,
  228. Irp);
  229. }
  230. return status;
  231. }