ReactOS  0.4.13-dev-651-g5dbc677
power.c File Reference
#include "usbport.h"
#include <debug.h>
Include dependency graph for power.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI USBPORT_CompletePdoWaitWake (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_HcWakeDpc (IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
VOID NTAPI USBPORT_HcQueueWakeDpc (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_CompletePendingIdleIrp (IN PDEVICE_OBJECT PdoDevice)
 
VOID NTAPI USBPORT_DoSetPowerD0 (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_SuspendController (IN PDEVICE_OBJECT FdoDevice)
 
NTSTATUS NTAPI USBPORT_ResumeController (IN PDEVICE_OBJECT FdoDevice)
 
NTSTATUS NTAPI USBPORT_PdoDevicePowerState (IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
 
VOID NTAPI USBPORT_CancelPendingWakeIrp (IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
 
NTSTATUS NTAPI USBPORT_PdoPower (IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
 
NTSTATUS NTAPI USBPORT_HcWake (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
 
NTSTATUS NTAPI USBPORT_DevicePowerState (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
 
NTSTATUS NTAPI USBPORT_SystemPowerState (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
 
NTSTATUS NTAPI USBPORT_FdoPower (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
 
VOID NTAPI USBPORT_DoIdleNotificationCallback (IN PVOID Context)
 
NTSTATUS NTAPI USBPORT_IdleNotification (IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
 
VOID NTAPI USBPORT_AdjustDeviceCapabilities (IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_OBJECT PdoDevice)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file power.c.

Function Documentation

◆ USBPORT_AdjustDeviceCapabilities()

VOID NTAPI USBPORT_AdjustDeviceCapabilities ( IN PDEVICE_OBJECT  FdoDevice,
IN PDEVICE_OBJECT  PdoDevice 
)

Definition at line 668 of file power.c.

670 {
674 
675  DPRINT("USBPORT_AdjustDeviceCapabilities: ... \n");
676 
677  FdoExtension = FdoDevice->DeviceExtension;
678  PdoExtension = PdoDevice->DeviceExtension;
679  Capabilities = &PdoExtension->Capabilities;
680 
682  &FdoExtension->Capabilities,
683  sizeof(DEVICE_CAPABILITIES));
684 
685  Capabilities->DeviceD1 = FALSE;
686  Capabilities->DeviceD2 = TRUE;
687 
688  Capabilities->Removable = FALSE;
689  Capabilities->UniqueID = FALSE;
690 
691  Capabilities->WakeFromD0 = TRUE;
692  Capabilities->WakeFromD1 = FALSE;
693  Capabilities->WakeFromD2 = TRUE;
694  Capabilities->WakeFromD3 = FALSE;
695 
696  Capabilities->Address = 0;
697  Capabilities->UINumber = 0;
698 
699  if (Capabilities->SystemWake == PowerSystemUnspecified)
700  Capabilities->SystemWake = PowerSystemWorking;
701 
702  Capabilities->DeviceWake = PowerDeviceD2;
703 
708 }
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
DEVICE_CAPABILITIES
Definition: iotypes.h:927
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
void DPRINT(...)
Definition: polytest.cpp:61
* PDEVICE_CAPABILITIES
Definition: iotypes.h:927

Referenced by USBPORT_CreatePdo().

◆ USBPORT_CancelPendingWakeIrp()

VOID NTAPI USBPORT_CancelPendingWakeIrp ( IN PDEVICE_OBJECT  PdoDevice,
IN PIRP  Irp 
)

Definition at line 293 of file power.c.

295 {
297  KIRQL OldIrql;
299 
300  DPRINT("USBPORT_CancelPendingWakeIrp: ... \n");
301 
302  IoReleaseCancelSpinLock(Irp->CancelIrql);
303  PdoExtension = PdoDevice->DeviceExtension;
304  FdoExtension = PdoExtension->FdoDevice->DeviceExtension;
305 
306  KeAcquireSpinLock(&FdoExtension->PowerWakeSpinLock, &OldIrql);
307 
308  if (PdoExtension->WakeIrp == Irp)
309  {
310  PdoExtension->WakeIrp = NULL;
311  }
312 
313  KeReleaseSpinLock(&FdoExtension->PowerWakeSpinLock, OldIrql);
314 
315  Irp->IoStatus.Status = STATUS_CANCELLED;
316  Irp->IoStatus.Information = 0;
318 }
_In_ PIRP Irp
Definition: csq.h:116
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define IO_NO_INCREMENT
Definition: iotypes.h:565

Referenced by USBPORT_PdoPower().

◆ USBPORT_CompletePdoWaitWake()

VOID NTAPI USBPORT_CompletePdoWaitWake ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 15 of file power.c.

16 {
18  PDEVICE_OBJECT PdoDevice;
20  PIRP Irp;
21  KIRQL OldIrql;
22 
23  DPRINT("USBPORT_CompletePdoWaitWake: ... \n");
24 
25  FdoExtension = FdoDevice->DeviceExtension;
26  PdoDevice = FdoExtension->RootHubPdo;
27  PdoExtension = PdoDevice->DeviceExtension;
28 
29  KeAcquireSpinLock(&FdoExtension->PowerWakeSpinLock, &OldIrql);
30 
31  Irp = PdoExtension->WakeIrp;
32 
33  if (Irp && IoSetCancelRoutine(Irp, NULL))
34  {
35  PdoExtension->WakeIrp = NULL;
36  KeReleaseSpinLock(&FdoExtension->PowerWakeSpinLock, OldIrql);
37 
38  DPRINT("USBPORT_CompletePdoWaitWake: Complete Irp - %p\n", Irp);
39 
40  Irp->IoStatus.Status = STATUS_SUCCESS;
41  Irp->IoStatus.Information = 0;
43 
44  return;
45  }
46 
47  KeReleaseSpinLock(&FdoExtension->PowerWakeSpinLock, OldIrql);
48 }
_In_ PIRP Irp
Definition: csq.h:116
IoSetCancelRoutine(Irp, CancelRoutine)
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define IO_NO_INCREMENT
Definition: iotypes.h:565
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by USBPORT_HcWakeDpc(), USBPORT_IsrDpc(), and USBPORT_PdoDevicePowerState().

◆ USBPORT_CompletePendingIdleIrp()

VOID NTAPI USBPORT_CompletePendingIdleIrp ( IN PDEVICE_OBJECT  PdoDevice)

Definition at line 75 of file power.c.

76 {
78  PDEVICE_OBJECT FdoDevice;
80  PIRP Irp;
81 
82  DPRINT("USBPORT_CompletePendingIdleIrp: ... \n");
83 
84  PdoExtension = PdoDevice->DeviceExtension;
85  FdoDevice = PdoExtension->FdoDevice;
86  FdoExtension = FdoDevice->DeviceExtension;
87 
88  Irp = IoCsqRemoveNextIrp(&FdoExtension->IdleIoCsq, 0);
89 
90  if (Irp)
91  {
92  InterlockedDecrement(&FdoExtension->IdleLockCounter);
93 
94  DPRINT("USBPORT_CompletePendingIdleIrp: Complete Irp - %p\n", Irp);
95 
96  Irp->IoStatus.Status = STATUS_CANCELLED;
97  Irp->IoStatus.Information = 0;
99  }
100 }
NTKERNELAPI PIRP NTAPI IoCsqRemoveNextIrp(_Inout_ PIO_CSQ Csq, _In_opt_ PVOID PeekContext)
IoCsqRemoveNextIrp - Removes the next IRP from the queue.
Definition: csq.c:398
_In_ PIRP Irp
Definition: csq.h:116
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define InterlockedDecrement
Definition: armddk.h:52
#define IO_NO_INCREMENT
Definition: iotypes.h:565

Referenced by USBPORT_PdoDevicePowerState().

◆ USBPORT_DevicePowerState()

NTSTATUS NTAPI USBPORT_DevicePowerState ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp 
)

Definition at line 471 of file power.c.

473 {
474  DPRINT1("USBPORT_DevicePowerState: UNIMPLEMENTED. FIXME. \n");
475  return STATUS_SUCCESS;
476 }
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by USBPORT_FdoPower().

◆ USBPORT_DoIdleNotificationCallback()

VOID NTAPI USBPORT_DoIdleNotificationCallback ( IN PVOID  Context)

Definition at line 545 of file power.c.

546 {
547  PIO_STACK_LOCATION IoStack;
548  PDEVICE_OBJECT FdoDevice;
551  PIRP NextIrp;
552  LARGE_INTEGER CurrentTime = {{0, 0}};
553  PTIMER_WORK_QUEUE_ITEM IdleQueueItem;
554  PDEVICE_OBJECT PdoDevice;
555  PUSB_IDLE_CALLBACK_INFO IdleCallbackInfo;
556  KIRQL OldIrql;
557 
558  DPRINT("USBPORT_DoIdleNotificationCallback \n");
559 
560  IdleQueueItem = Context;
561 
562  FdoDevice = IdleQueueItem->FdoDevice;
563  FdoExtension = FdoDevice->DeviceExtension;
564  PdoDevice = FdoExtension->RootHubPdo;
565  PdoExtension = PdoDevice->DeviceExtension;
566 
567  KeQuerySystemTime(&CurrentTime);
568 
569  if ((FdoExtension->IdleTime.QuadPart == 0) ||
570  (((CurrentTime.QuadPart - FdoExtension->IdleTime.QuadPart) / 10000) >= 500))
571  {
572  if (PdoExtension->CommonExtension.DevicePowerState == PowerDeviceD0 &&
573  FdoExtension->CommonExtension.DevicePowerState == PowerDeviceD0)
574  {
575  NextIrp = IoCsqRemoveNextIrp(&FdoExtension->IdleIoCsq, NULL);
576 
577  if (NextIrp)
578  {
579  IoStack = IoGetCurrentIrpStackLocation(NextIrp);
580  IdleCallbackInfo = IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
581 
582  if (IdleCallbackInfo && IdleCallbackInfo->IdleCallback)
583  {
584  IdleCallbackInfo->IdleCallback(IdleCallbackInfo->IdleContext);
585  }
586 
587  if (NextIrp->Cancel)
588  {
589  InterlockedDecrement(&FdoExtension->IdleLockCounter);
590 
591  NextIrp->IoStatus.Status = STATUS_CANCELLED;
592  NextIrp->IoStatus.Information = 0;
594  }
595  else
596  {
597  IoCsqInsertIrp(&FdoExtension->IdleIoCsq, NextIrp, NULL);
598  }
599  }
600  }
601  }
602 
603  KeAcquireSpinLock(&FdoExtension->TimerFlagsSpinLock, &OldIrql);
605  KeReleaseSpinLock(&FdoExtension->TimerFlagsSpinLock, OldIrql);
606 
607  ExFreePoolWithTag(IdleQueueItem, USB_PORT_TAG);
608 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define USBPORT_TMFLAG_IDLE_QUEUEITEM_ON
Definition: usbport.h:98
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:444
NTKERNELAPI PIRP NTAPI IoCsqRemoveNextIrp(_Inout_ PIO_CSQ Csq, _In_opt_ PVOID PeekContext)
IoCsqRemoveNextIrp - Removes the next IRP from the queue.
Definition: csq.c:398
NTKERNELAPI VOID NTAPI IoCsqInsertIrp(_Inout_ PIO_CSQ Csq, _Inout_ PIRP Irp, _Out_opt_ PIO_CSQ_IRP_CONTEXT Context)
Insert an IRP into the CSQ.
Definition: csq.c:177
#define USB_PORT_TAG
Definition: usbport.h:44
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define InterlockedDecrement
Definition: armddk.h:52
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
struct tagContext Context
Definition: acpixf.h:1012
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by USBPORT_TimerDpc().

◆ USBPORT_DoSetPowerD0()

VOID NTAPI USBPORT_DoSetPowerD0 ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 104 of file power.c.

105 {
106  DPRINT("USBPORT_DoSetPowerD0: FIXME!\n");
107  return;
108 }
void DPRINT(...)
Definition: polytest.cpp:61

Referenced by USBPORT_WorkerThread().

◆ USBPORT_FdoPower()

NTSTATUS NTAPI USBPORT_FdoPower ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp 
)

Definition at line 489 of file power.c.

491 {
493  PIO_STACK_LOCATION IoStack;
495 
496  DPRINT("USBPORT_FdoPower: ... \n");
497 
498  FdoExtension = FdoDevice->DeviceExtension;
500 
501  switch (IoStack->MinorFunction)
502  {
503  case IRP_MN_WAIT_WAKE:
504  DPRINT("USBPORT_FdoPower: IRP_MN_WAIT_WAKE\n");
505  Status = USBPORT_HcWake(FdoDevice, Irp);
506  return Status;
507 
509  DPRINT("USBPORT_FdoPower: IRP_MN_POWER_SEQUENCE\n");
510  break;
511 
512  case IRP_MN_SET_POWER:
513  DPRINT("USBPORT_FdoPower: IRP_MN_SET_POWER\n");
514  if (IoStack->Parameters.Power.Type == DevicePowerState)
515  {
516  Status = USBPORT_DevicePowerState(FdoDevice, Irp);
517  }
518  else
519  {
520  Status = USBPORT_SystemPowerState(FdoDevice, Irp);
521  }
522 
523  if (Status != STATUS_PENDING)
524  break;
525 
526  return Status;
527 
528  case IRP_MN_QUERY_POWER:
529  DPRINT("USBPORT_FdoPower: IRP_MN_QUERY_POWER\n");
530  Irp->IoStatus.Status = STATUS_SUCCESS;
531  break;
532 
533  default:
534  DPRINT1("USBPORT_FdoPower: unknown IRP_MN_POWER!\n");
535  break;
536  }
537 
540  return PoCallDriver(FdoExtension->CommonExtension.LowerDevice, Irp);
541 }
#define IRP_MN_POWER_SEQUENCE
#define IRP_MN_QUERY_POWER
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI USBPORT_DevicePowerState(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: power.c:471
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
NTSTATUS NTAPI USBPORT_HcWake(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: power.c:462
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
NTSTATUS NTAPI USBPORT_SystemPowerState(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: power.c:480
#define IRP_MN_SET_POWER
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
#define DPRINT1
Definition: precomp.h:8
#define IRP_MN_WAIT_WAKE
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by USBPORT_Dispatch().

◆ USBPORT_HcQueueWakeDpc()

VOID NTAPI USBPORT_HcQueueWakeDpc ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 63 of file power.c.

64 {
66 
67  DPRINT("USBPORT_HcQueueWakeDpc: ... \n");
68 
69  FdoExtension = FdoDevice->DeviceExtension;
70  KeInsertQueueDpc(&FdoExtension->HcWakeDpc, NULL, NULL);
71 }
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:724
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61

Referenced by USBPORT_InvalidateRootHub().

◆ USBPORT_HcWake()

NTSTATUS NTAPI USBPORT_HcWake ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp 
)

Definition at line 462 of file power.c.

464 {
465  DPRINT1("USBPORT_HcWake: UNIMPLEMENTED. FIXME. \n");
466  return STATUS_SUCCESS;
467 }
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by USBPORT_FdoPower().

◆ USBPORT_HcWakeDpc()

VOID NTAPI USBPORT_HcWakeDpc ( IN PRKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 52 of file power.c.

56 {
57  DPRINT("USBPORT_HcWakeDpc: ... \n");
59 }
VOID NTAPI USBPORT_CompletePdoWaitWake(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:15
void DPRINT(...)
Definition: polytest.cpp:61
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675

Referenced by USBPORT_StartDevice().

◆ USBPORT_IdleNotification()

NTSTATUS NTAPI USBPORT_IdleNotification ( IN PDEVICE_OBJECT  PdoDevice,
IN PIRP  Irp 
)

Definition at line 612 of file power.c.

614 {
616  PDEVICE_OBJECT FdoDevice;
618  LONG LockCounter;
620 
621  DPRINT("USBPORT_IdleNotification: Irp - %p\n", Irp);
622 
623  PdoExtension = PdoDevice->DeviceExtension;
624  FdoDevice = PdoExtension->FdoDevice;
625  FdoExtension = FdoDevice->DeviceExtension;
626 
627  LockCounter = InterlockedIncrement(&FdoExtension->IdleLockCounter);
628 
629  if (LockCounter != 0)
630  {
631  if (Status != STATUS_PENDING)
632  {
633  InterlockedDecrement(&FdoExtension->IdleLockCounter);
634 
635  Irp->IoStatus.Status = Status;
636  Irp->IoStatus.Information = 0;
638 
639  return Status;
640  }
641 
643  }
644 
645  if (Status != STATUS_PENDING)
646  {
647  InterlockedDecrement(&FdoExtension->IdleLockCounter);
648 
649  Irp->IoStatus.Status = Status;
650  Irp->IoStatus.Information = 0;
652 
653  return Status;
654  }
655 
656  Irp->IoStatus.Status = STATUS_PENDING;
658 
659  KeQuerySystemTime(&FdoExtension->IdleTime);
660 
661  IoCsqInsertIrp(&FdoExtension->IdleIoCsq, Irp, 0);
662 
663  return Status;
664 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
_In_ PIRP Irp
Definition: csq.h:116
NTKERNELAPI VOID NTAPI IoCsqInsertIrp(_Inout_ PIO_CSQ Csq, _Inout_ PIRP Irp, _Out_opt_ PIO_CSQ_IRP_CONTEXT Context)
Insert an IRP into the CSQ.
Definition: csq.c:177
LONG NTSTATUS
Definition: precomp.h:26
long LONG
Definition: pedump.c:60
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
#define InterlockedDecrement
Definition: armddk.h:52
Status
Definition: gdiplustypes.h:24
#define InterlockedIncrement
Definition: armddk.h:53
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
#define IO_NO_INCREMENT
Definition: iotypes.h:565
IoMarkIrpPending(Irp)

Referenced by USBPORT_PdoInternalDeviceControl().

◆ USBPORT_PdoDevicePowerState()

NTSTATUS NTAPI USBPORT_PdoDevicePowerState ( IN PDEVICE_OBJECT  PdoDevice,
IN PIRP  Irp 
)

Definition at line 232 of file power.c.

234 {
236  PDEVICE_OBJECT FdoDevice;
238  PIO_STACK_LOCATION IoStack;
241 
242  PdoExtension = PdoDevice->DeviceExtension;
243  FdoDevice = PdoExtension->FdoDevice;
244  FdoExtension = FdoDevice->DeviceExtension;
246 
247  State = IoStack->Parameters.Power.State;
248 
249  DPRINT1("USBPORT_PdoDevicePowerState: Irp - %p, State - %x\n",
250  Irp,
251  State.DeviceState);
252 
253  if (State.DeviceState == PowerDeviceD0)
254  {
255  if (FdoExtension->CommonExtension.DevicePowerState == PowerDeviceD0)
256  {
257  // FIXME FdoExtension->Flags
258  while (FdoExtension->SetPowerLockCounter)
259  {
260  USBPORT_Wait(FdoDevice, 10);
261  }
262 
263  USBPORT_ResumeController(FdoDevice);
264 
265  PdoExtension->CommonExtension.DevicePowerState = PowerDeviceD0;
266 
267  USBPORT_CompletePdoWaitWake(FdoDevice);
269  }
270  else
271  {
272  DPRINT1("USBPORT_PdoDevicePowerState: FdoExtension->Flags - %lx\n",
273  FdoExtension->Flags);
274 
275  DbgBreakPoint();
277  }
278  }
279  else if (State.DeviceState == PowerDeviceD1 ||
280  State.DeviceState == PowerDeviceD2 ||
281  State.DeviceState == PowerDeviceD3)
282  {
283  FdoExtension->TimerFlags |= USBPORT_TMFLAG_WAKE;
284  USBPORT_SuspendController(FdoDevice);
285  PdoExtension->CommonExtension.DevicePowerState = State.DeviceState;
286  }
287 
288  return Status;
289 }
VOID NTAPI USBPORT_SuspendController(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:112
#define USBPORT_TMFLAG_WAKE
Definition: usbport.h:97
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI USBPORT_CompletePdoWaitWake(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:15
void DbgBreakPoint()
Definition: mach.c:558
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
PVOID DeviceExtension
Definition: env_spec_w32.h:418
NTSTATUS NTAPI USBPORT_ResumeController(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:146
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
enum State_ State
Definition: pofuncs.h:54
VOID NTAPI USBPORT_CompletePendingIdleIrp(IN PDEVICE_OBJECT PdoDevice)
Definition: power.c:75
#define DPRINT1
Definition: precomp.h:8
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by USBPORT_PdoPower().

◆ USBPORT_PdoPower()

NTSTATUS NTAPI USBPORT_PdoPower ( IN PDEVICE_OBJECT  PdoDevice,
IN PIRP  Irp 
)

Definition at line 322 of file power.c.

324 {
326  PDEVICE_OBJECT FdoDevice;
327  PIO_STACK_LOCATION IoStack;
330  KIRQL OldIrql;
331 
332  DPRINT("USBPORT_PdoPower: Irp - %p\n", Irp);
333 
334  PdoExtension = PdoDevice->DeviceExtension;
335  FdoDevice = PdoExtension->FdoDevice;
336  FdoExtension = FdoDevice->DeviceExtension;
338 
339  Status = Irp->IoStatus.Status;
340 
341  switch (IoStack->MinorFunction)
342  {
343  case IRP_MN_WAIT_WAKE:
344  DPRINT("USBPORT_PdoPower: IRP_MN_WAIT_WAKE\n");
345 
346  if (!(FdoExtension->Flags & USBPORT_FLAG_HC_STARTED))
347  {
348  /* The device does not support wake-up */
350  break;
351  }
352 
353  KeAcquireSpinLock(&FdoExtension->PowerWakeSpinLock, &OldIrql);
354 
356 
357  /* Check if the IRP has been cancelled */
358  if (Irp->Cancel)
359  {
361  {
362  /* IRP has been cancelled, release cancel spinlock */
363  KeReleaseSpinLock(&FdoExtension->PowerWakeSpinLock, OldIrql);
364 
365  DPRINT("USBPORT_PdoPower: IRP_MN_WAIT_WAKE - STATUS_CANCELLED\n");
366 
367  /* IRP is cancelled */
369  break;
370  }
371  }
372 
373  if (!PdoExtension->WakeIrp)
374  {
375  /* The driver received the IRP
376  and is waiting for the device to signal wake-up. */
377 
378  DPRINT("USBPORT_PdoPower: IRP_MN_WAIT_WAKE - No WakeIrp\n");
379 
381  PdoExtension->WakeIrp = Irp;
382 
383  KeReleaseSpinLock(&FdoExtension->PowerWakeSpinLock, OldIrql);
384  return STATUS_PENDING;
385  }
386  else
387  {
388  /* An IRP_MN_WAIT_WAKE request is already pending and must be
389  completed or canceled before another IRP_MN_WAIT_WAKE request
390  can be issued. */
391 
393  {
394  DPRINT("USBPORT_PdoPower: IRP_MN_WAIT_WAKE - STATUS_DEVICE_BUSY\n");
395 
396  KeReleaseSpinLock(&FdoExtension->PowerWakeSpinLock, OldIrql);
399  break;
400  }
401  else
402  {
403  ASSERT(FALSE);
404  KeReleaseSpinLock(&FdoExtension->PowerWakeSpinLock, OldIrql);
405  return Status;
406  }
407  }
408 
410  DPRINT("USBPORT_PdoPower: IRP_MN_POWER_SEQUENCE\n");
412  break;
413 
414  case IRP_MN_SET_POWER:
415  DPRINT("USBPORT_PdoPower: IRP_MN_SET_POWER\n");
416 
417  if (IoStack->Parameters.Power.Type == DevicePowerState)
418  {
419  DPRINT("USBPORT_PdoPower: IRP_MN_SET_POWER/DevicePowerState\n");
420  Status = USBPORT_PdoDevicePowerState(PdoDevice, Irp);
422  break;
423  }
424 
425  DPRINT("USBPORT_PdoPower: IRP_MN_SET_POWER/SystemPowerState \n");
426 
427  if (IoStack->Parameters.Power.State.SystemState == PowerSystemWorking)
428  {
429  FdoExtension->TimerFlags |= USBPORT_TMFLAG_WAKE;
430  }
431  else
432  {
433  FdoExtension->TimerFlags &= ~USBPORT_TMFLAG_WAKE;
434  }
435 
437 
439  break;
440 
441  case IRP_MN_QUERY_POWER:
442  DPRINT("USBPORT_PdoPower: IRP_MN_QUERY_POWER\n");
445  break;
446 
447  default:
448  DPRINT1("USBPORT_PdoPower: unknown IRP_MN_POWER!\n");
450  break;
451  }
452 
453  Irp->IoStatus.Status = Status;
454  Irp->IoStatus.Information = 0;
456 
457  return Status;
458 }
#define IRP_MN_POWER_SEQUENCE
#define IRP_MN_QUERY_POWER
VOID NTAPI USBPORT_CancelPendingWakeIrp(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: power.c:293
#define USBPORT_TMFLAG_WAKE
Definition: usbport.h:97
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
IoSetCancelRoutine(Irp, CancelRoutine)
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS NTAPI USBPORT_PdoDevicePowerState(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: power.c:232
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define IRP_MN_SET_POWER
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define IRP_MN_WAIT_WAKE
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
return STATUS_SUCCESS
Definition: btrfs.c:2777
IoMarkIrpPending(Irp)
#define USBPORT_FLAG_HC_STARTED
Definition: usbport.h:67

Referenced by USBPORT_Dispatch().

◆ USBPORT_ResumeController()

NTSTATUS NTAPI USBPORT_ResumeController ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 146 of file power.c.

147 {
151  KIRQL OldIrql;
152  MPSTATUS MpStatus;
153 
154  DPRINT1("USBPORT_ResumeController: ... \n");
155 
156  FdoExtension = FdoDevice->DeviceExtension;
157  Packet = &FdoExtension->MiniPortInterface->Packet;
158 
159  if (!(FdoExtension->Flags & USBPORT_FLAG_HC_SUSPEND))
160  {
161  return Status;
162  }
163 
164  KeAcquireSpinLock(&FdoExtension->TimerFlagsSpinLock, &OldIrql);
165 
166  FdoExtension->TimerFlags &= ~(USBPORT_TMFLAG_HC_SUSPENDED |
168 
169  KeReleaseSpinLock(&FdoExtension->TimerFlagsSpinLock, OldIrql);
170 
171  if (!(FdoExtension->MiniPortFlags & USBPORT_MPFLAG_SUSPENDED))
172  {
174  return Status;
175  }
176 
177  FdoExtension->MiniPortFlags &= ~USBPORT_MPFLAG_SUSPENDED;
178 
179  if (!Packet->ResumeController(FdoExtension->MiniPortExt))
180  {
181  Status = USBPORT_Wait(FdoDevice, 100);
182 
184  return Status;
185  }
186 
187  KeAcquireSpinLock(&FdoExtension->TimerFlagsSpinLock, &OldIrql);
188  FdoExtension->TimerFlags |= (USBPORT_TMFLAG_HC_SUSPENDED |
190  KeReleaseSpinLock(&FdoExtension->TimerFlagsSpinLock, OldIrql);
191 
192  USBPORT_MiniportInterrupts(FdoDevice, FALSE);
193 
194  Packet->StopController(FdoExtension->MiniPortExt, 1);
195 
196  USBPORT_NukeAllEndpoints(FdoDevice);
197 
198  RtlZeroMemory(FdoExtension->MiniPortExt, Packet->MiniPortExtensionSize);
199 
200  RtlZeroMemory((PVOID)FdoExtension->UsbPortResources.StartVA,
201  Packet->MiniPortResourcesSize);
202 
203  FdoExtension->UsbPortResources.IsChirpHandled = TRUE;
204 
205  MpStatus = Packet->StartController(FdoExtension->MiniPortExt,
206  &FdoExtension->UsbPortResources);
207 
208  FdoExtension->UsbPortResources.IsChirpHandled = FALSE;
209 
210  if (!MpStatus)
211  {
212  USBPORT_MiniportInterrupts(FdoDevice, TRUE);
213  }
214 
215  KeAcquireSpinLock(&FdoExtension->TimerFlagsSpinLock, &OldIrql);
216 
217  FdoExtension->TimerFlags &= ~(USBPORT_TMFLAG_HC_SUSPENDED |
220 
221  KeReleaseSpinLock(&FdoExtension->TimerFlagsSpinLock, OldIrql);
222 
223  Status = USBPORT_Wait(FdoDevice, 100);
224 
226 
227  return Status;
228 }
ULONG MPSTATUS
Definition: usbmport.h:131
#define TRUE
Definition: types.h:120
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
VOID NTAPI USBPORT_NukeAllEndpoints(IN PDEVICE_OBJECT FdoDevice)
Definition: endpoint.c:300
LONG NTSTATUS
Definition: precomp.h:26
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
VOID NTAPI USBPORT_MiniportInterrupts(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsEnable)
Definition: usbport.c:555
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define USBPORT_TMFLAG_RH_SUSPENDED
Definition: usbport.h:95
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define USBPORT_TMFLAG_HC_RESUME
Definition: usbport.h:94
Status
Definition: gdiplustypes.h:24
#define USBPORT_FLAG_HC_SUSPEND
Definition: usbport.h:70
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define USBPORT_TMFLAG_HC_SUSPENDED
Definition: usbport.h:93
#define USBPORT_MPFLAG_SUSPENDED
Definition: usbport.h:102

Referenced by USBPORT_PdoDevicePowerState().

◆ USBPORT_SuspendController()

VOID NTAPI USBPORT_SuspendController ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 112 of file power.c.

113 {
116 
117  DPRINT1("USBPORT_SuspendController \n");
118 
119  FdoExtension = FdoDevice->DeviceExtension;
120  Packet = &FdoExtension->MiniPortInterface->Packet;
121 
123 
124  USBPORT_FlushController(FdoDevice);
125 
127  {
128  return;
129  }
130 
132 
133  if (FdoExtension->MiniPortFlags & USBPORT_MPFLAG_INTERRUPTS_ENABLED)
134  {
135  FdoExtension->MiniPortFlags |= USBPORT_MPFLAG_SUSPENDED;
136 
137  USBPORT_Wait(FdoDevice, 10);
138  Packet->SuspendController(FdoExtension->MiniPortExt);
139  }
140 
142 }
VOID NTAPI USBPORT_FlushController(IN PDEVICE_OBJECT FdoDevice)
Definition: queue.c:1259
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
#define USBPORT_TMFLAG_RH_SUSPENDED
Definition: usbport.h:95
#define USBPORT_FLAG_HC_SUSPEND
Definition: usbport.h:70
#define USBPORT_MPFLAG_INTERRUPTS_ENABLED
Definition: usbport.h:101
#define DPRINT1
Definition: precomp.h:8
#define USBPORT_TMFLAG_HC_SUSPENDED
Definition: usbport.h:93
#define USBPORT_MPFLAG_SUSPENDED
Definition: usbport.h:102

Referenced by USBPORT_PdoDevicePowerState().

◆ USBPORT_SystemPowerState()

NTSTATUS NTAPI USBPORT_SystemPowerState ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp 
)

Definition at line 480 of file power.c.

482 {
483  DPRINT1("USBPORT_SystemPowerState: UNIMPLEMENTED. FIXME. \n");
484  return STATUS_SUCCESS;
485 }
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by USBPORT_FdoPower().