ReactOS 0.4.16-dev-297-gc569aee
power.c File Reference
#include "usbhub.h"
#include <debug.h>
#include "dbg_uhub.h"
Include dependency graph for power.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define NDEBUG_USBHUB_POWER
 

Functions

VOID NTAPI USBH_CompletePowerIrp (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN NTSTATUS NtStatus)
 
VOID NTAPI USBH_HubCancelWakeIrp (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
 
VOID NTAPI USBH_HubESDRecoverySetD3Completion (IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
 
NTSTATUS NTAPI USBH_HubSetD0 (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
VOID NTAPI USBH_IdleCancelPowerHubWorker (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
 
VOID NTAPI USBH_HubQueuePortWakeIrps (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY ListIrps)
 
VOID NTAPI USBH_HubCompleteQueuedPortWakeIrps (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY ListIrps, IN NTSTATUS NtStatus)
 
VOID NTAPI USBH_HubCompletePortWakeIrps (IN PUSBHUB_FDO_EXTENSION HubExtension, IN NTSTATUS NtStatus)
 
VOID NTAPI USBH_FdoPoRequestD0Completion (IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
 
VOID NTAPI USBH_CompletePortWakeIrpsWorker (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
 
NTSTATUS NTAPI USBH_FdoWWIrpIoCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS NTAPI USBH_PowerIrpCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
VOID NTAPI USBH_FdoDeferPoRequestCompletion (IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
 
NTSTATUS NTAPI USBH_FdoPower (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN UCHAR Minor)
 
NTSTATUS NTAPI USBH_PdoPower (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp, IN UCHAR Minor)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file power.c.

◆ NDEBUG_USBHUB_POWER

#define NDEBUG_USBHUB_POWER

Definition at line 13 of file power.c.

Function Documentation

◆ USBH_CompletePortWakeIrpsWorker()

VOID NTAPI USBH_CompletePortWakeIrpsWorker ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PVOID  Context 
)

Definition at line 262 of file power.c.

264{
265 DPRINT1("USBH_CompletePortWakeIrpsWorker: UNIMPLEMENTED. FIXME\n");
267}
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI void WINAPI DbgBreakPoint(void)

◆ USBH_CompletePowerIrp()

VOID NTAPI USBH_CompletePowerIrp ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PIRP  Irp,
IN NTSTATUS  NtStatus 
)

Definition at line 18 of file power.c.

21{
22 DPRINT("USBH_CompletePowerIrp: HubExtension - %p, Irp - %p, NtStatus - %lX\n",
23 HubExtension,
24 Irp,
25 NtStatus);
26
27 Irp->IoStatus.Status = NtStatus;
28
30
31 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
32 {
33 KeSetEvent(&HubExtension->PendingRequestEvent,
35 FALSE);
36 }
37
39}
#define InterlockedDecrement
Definition: armddk.h:52
_In_ PIRP Irp
Definition: csq.h:116
#define FALSE
Definition: types.h:117
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
#define DPRINT
Definition: sndvol32.h:73
#define EVENT_INCREMENT
Definition: iotypes.h:597
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by USBH_FdoCleanup(), and USBH_PdoRemoveDevice().

◆ USBH_FdoDeferPoRequestCompletion()

VOID NTAPI USBH_FdoDeferPoRequestCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN UCHAR  MinorFunction,
IN POWER_STATE  PowerState,
IN PVOID  Context,
IN PIO_STATUS_BLOCK  IoStatus 
)

Definition at line 422 of file power.c.

427{
429 PUSBHUB_FDO_EXTENSION HubExtension = NULL;
430 PIRP PowerIrp;
431 PIO_STACK_LOCATION IoStack;
432
433 DPRINT("USBH_FdoDeferPoRequestCompletion ... \n");
434
436
437 PowerIrp = Extension->PowerIrp;
438
439 if (Extension->Common.ExtensionType == USBH_EXTENSION_TYPE_HUB)
440 {
441 HubExtension = Context;
442 }
443
444 IoStack = IoGetCurrentIrpStackLocation(PowerIrp);
445
446 if (IoStack->Parameters.Power.State.SystemState == PowerSystemWorking &&
447 HubExtension && HubExtension->LowerPDO == HubExtension->RootHubPdo)
448 {
450 USBH_CheckIdleDeferred(HubExtension);
451 }
452
454 PoStartNextPowerIrp(PowerIrp);
455 PoCallDriver(Extension->LowerDevice, PowerIrp);
456}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define NULL
Definition: types.h:112
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
#define IoCopyCurrentIrpStackLocationToNext(Irp)
Definition: ntifs_ex.h:413
@ PowerSystemWorking
Definition: ntpoapi.h:36
struct _IO_STACK_LOCATION::@3978::@4014 Power
union _IO_STACK_LOCATION::@1579 Parameters
PDEVICE_OBJECT LowerPDO
Definition: usbhub.h:149
PDEVICE_OBJECT RootHubPdo
Definition: usbhub.h:151
POWER_STATE SystemPowerState
Definition: usbhub.h:161
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
VOID NTAPI USBH_CheckIdleDeferred(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3957
#define USBH_EXTENSION_TYPE_HUB
Definition: usbhub.h:28

Referenced by USBH_FdoPower().

◆ USBH_FdoPoRequestD0Completion()

VOID NTAPI USBH_FdoPoRequestD0Completion ( IN PDEVICE_OBJECT  DeviceObject,
IN UCHAR  MinorFunction,
IN POWER_STATE  PowerState,
IN PVOID  Context,
IN PIO_STATUS_BLOCK  IoStatus 
)

Definition at line 236 of file power.c.

241{
242 PUSBHUB_FDO_EXTENSION HubExtension;
243
244 DPRINT("USBH_FdoPoRequestD0Completion ... \n");
245
246 HubExtension = Context;
247
249
250 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_WAKEUP_START;
251
252 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
253 {
254 KeSetEvent(&HubExtension->PendingRequestEvent,
256 FALSE);
257 }
258}
VOID NTAPI USBH_HubCompletePortWakeIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN NTSTATUS NtStatus)
Definition: power.c:217
#define STATUS_SUCCESS
Definition: shellext.h:65
LONG PendingRequestCount
Definition: usbhub.h:180
KEVENT PendingRequestEvent
Definition: usbhub.h:181

Referenced by USBH_FdoWWIrpIoCompletion().

◆ USBH_FdoPower()

NTSTATUS NTAPI USBH_FdoPower ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PIRP  Irp,
IN UCHAR  Minor 
)

Definition at line 460 of file power.c.

463{
465 PIO_STACK_LOCATION IoStack;
467 POWER_STATE DevicePwrState;
468 BOOLEAN IsAllPortsD3;
469 PUSBHUB_PORT_DATA PortData;
470 PDEVICE_OBJECT PdoDevice;
471 PUSBHUB_PORT_PDO_EXTENSION PortExtension;
472 ULONG Port;
473
474 DPRINT_PWR("USBH_FdoPower: HubExtension - %p, Irp - %p, Minor - %X\n",
475 HubExtension,
476 Irp,
477 Minor);
478
479 switch (Minor)
480 {
481 case IRP_MN_WAIT_WAKE:
482 DPRINT_PWR("USBH_FdoPower: IRP_MN_WAIT_WAKE\n");
483
485
488 HubExtension,
489 TRUE,
490 TRUE,
491 TRUE);
492
495 PoCallDriver(HubExtension->LowerDevice, Irp);
496
497 return STATUS_PENDING;
498
500 DPRINT_PWR("USBH_FdoPower: IRP_MN_POWER_SEQUENCE\n");
501 break;
502
503 case IRP_MN_SET_POWER:
504 DPRINT_PWR("USBH_FdoPower: IRP_MN_SET_POWER\n");
505
507 DPRINT_PWR("USBH_FdoPower: IRP_MN_SET_POWER/DevicePowerState\n");
508 PowerState = IoStack->Parameters.Power.State;
509
510 if (IoStack->Parameters.Power.Type == DevicePowerState)
511 {
512 DPRINT_PWR("USBH_FdoPower: PowerState - %x\n",
513 PowerState.DeviceState);
514
515 if (HubExtension->CurrentPowerState.DeviceState == PowerState.DeviceState)
516 {
518
521 PoCallDriver(HubExtension->LowerDevice, Irp);
522
523 return STATUS_PENDING;
524 }
525
526 switch (PowerState.DeviceState)
527 {
528 case PowerDeviceD0:
529 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_SET_D0_STATE))
530 {
531 HubExtension->HubFlags &= ~(USBHUB_FDO_FLAG_NOT_D0_STATE |
533
534 HubExtension->HubFlags |= USBHUB_FDO_FLAG_SET_D0_STATE;
535
537
540 HubExtension,
541 TRUE,
542 TRUE,
543 TRUE);
544 }
545 else
546 {
549 }
550
552 PoCallDriver(HubExtension->LowerDevice, Irp);
553 return STATUS_PENDING;
554
555 case PowerDeviceD1:
556 case PowerDeviceD2:
557 case PowerDeviceD3:
558 if (HubExtension->ResetRequestCount)
559 {
560 IoCancelIrp(HubExtension->ResetPortIrp);
561
562 KeWaitForSingleObject(&HubExtension->ResetEvent,
563 Executive,
565 FALSE,
566 NULL);
567 }
568
569 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED))
570 {
571 HubExtension->HubFlags |= (USBHUB_FDO_FLAG_NOT_D0_STATE |
573
574 IoCancelIrp(HubExtension->SCEIrp);
575
576 KeWaitForSingleObject(&HubExtension->StatusChangeEvent,
577 Executive,
579 FALSE,
580 NULL);
581 }
582
583 HubExtension->CurrentPowerState.DeviceState = PowerState.DeviceState;
584
585 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DO_SUSPENSE &&
586 USBH_CheckIdleAbort(HubExtension, TRUE, TRUE) == TRUE)
587 {
588 HubExtension->HubFlags &= ~(USBHUB_FDO_FLAG_NOT_D0_STATE |
590
591 HubExtension->CurrentPowerState.DeviceState = PowerDeviceD0;
592
594
596
597 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
599
600 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_DO_SUSPENSE;
601
602 KeReleaseSemaphore(&HubExtension->IdleSemaphore,
604 1,
605 FALSE);
606
607 return STATUS_UNSUCCESSFUL;
608 }
609
611
614 HubExtension,
615 TRUE,
616 TRUE,
617 TRUE);
618
621 PoCallDriver(HubExtension->LowerDevice, Irp);
622
623 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DO_SUSPENSE)
624 {
625 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_DO_SUSPENSE;
626
627 KeReleaseSemaphore(&HubExtension->IdleSemaphore,
629 1,
630 FALSE);
631 }
632
633 return STATUS_PENDING;
634
635 default:
636 DPRINT1("USBH_FdoPower: Unsupported PowerState.DeviceState\n");
638 break;
639 }
640 }
641 else
642 {
643 if (PowerState.SystemState != PowerSystemWorking)
644 {
646 PowerState.SystemState;
647 }
648
649 if (PowerState.SystemState == PowerSystemHibernate)
650 {
651 HubExtension->HubFlags |= USBHUB_FDO_FLAG_HIBERNATE_STATE;
652 }
653
654 PortData = HubExtension->PortData;
655
656 IsAllPortsD3 = TRUE;
657
658 if (PortData && HubExtension->HubDescriptor)
659 {
660 for (Port = 0;
661 Port < HubExtension->HubDescriptor->bNumberOfPorts;
662 Port++)
663 {
664 PdoDevice = PortData[Port].DeviceObject;
665
666 if (PdoDevice)
667 {
668 PortExtension = PdoDevice->DeviceExtension;
669
670 if (PortExtension->CurrentPowerState.DeviceState != PowerDeviceD3)
671 {
672 IsAllPortsD3 = FALSE;
673 break;
674 }
675 }
676 }
677 }
678
679 if (PowerState.SystemState == PowerSystemWorking)
680 {
681 DevicePwrState.DeviceState = PowerDeviceD0;
682 }
683 else if (HubExtension->HubFlags & USBHUB_FDO_FLAG_PENDING_WAKE_IRP ||
684 !IsAllPortsD3)
685 {
686 DevicePwrState.DeviceState = HubExtension->DeviceState[PowerState.SystemState];
687
688 if (DevicePwrState.DeviceState == PowerDeviceUnspecified)
689 {
690 goto Exit;
691 }
692 }
693 else
694 {
695 DevicePwrState.DeviceState = PowerDeviceD3;
696 }
697
698 if (DevicePwrState.DeviceState != HubExtension->CurrentPowerState.DeviceState &&
699 HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STARTED)
700 {
701 HubExtension->PowerIrp = Irp;
702
704
705 if (PoRequestPowerIrp(HubExtension->LowerPDO,
707 DevicePwrState,
709 (PVOID)HubExtension,
711 {
712 return STATUS_PENDING;
713 }
714
717 PoCallDriver(HubExtension->LowerDevice, Irp);
718
719 return STATUS_PENDING;
720 }
721
722 Exit:
723
724 HubExtension->SystemPowerState.SystemState = PowerState.SystemState;
725
726 if (PowerState.SystemState == PowerSystemWorking)
727 {
728 USBH_CheckIdleDeferred(HubExtension);
729 }
730
733
734 return PoCallDriver(HubExtension->LowerDevice, Irp);
735 }
736
737 break;
738
740 DPRINT_PWR("USBH_FdoPower: IRP_MN_QUERY_POWER\n");
741 break;
742
743 default:
744 DPRINT1("USBH_FdoPower: unknown IRP_MN_POWER!\n");
745 break;
746 }
747
750 Status = PoCallDriver(HubExtension->LowerDevice, Irp);
751
752 return Status;
753}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define DPRINT_PWR(...)
Definition: dbg_uhub.h:108
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI USBH_PowerIrpCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: power.c:349
VOID NTAPI USBH_FdoDeferPoRequestCompletion(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
Definition: power.c:422
NTSTATUS NTAPI USBH_FdoWWIrpIoCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: power.c:271
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
Status
Definition: gdiplustypes.h:25
CPPORT Port[4]
Definition: headless.c:35
#define LOW_REALTIME_PRIORITY
IoMarkIrpPending(Irp)
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
#define KernelMode
Definition: asm.h:34
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101
NTSTATUS NTAPI PoRequestPowerIrp(_In_ PDEVICE_OBJECT DeviceObject, _In_ UCHAR MinorFunction, _In_ POWER_STATE PowerState, _In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction, _In_opt_ __drv_aliasesMem PVOID Context, _Outptr_opt_ PIRP *pIrp)
Definition: power.c:659
@ PowerSystemHibernate
Definition: ntpoapi.h:40
@ DevicePowerState
Definition: ntpoapi.h:63
@ PowerDeviceD1
Definition: ntpoapi.h:50
@ PowerDeviceUnspecified
Definition: ntpoapi.h:48
@ PowerDeviceD0
Definition: ntpoapi.h:49
@ PowerDeviceD2
Definition: ntpoapi.h:51
@ PowerDeviceD3
Definition: ntpoapi.h:52
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
static void Exit(void)
Definition: sock.c:1330
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDEVICE_OBJECT DeviceObject
Definition: usbhub.h:119
POWER_STATE CurrentPowerState
Definition: usbhub.h:222
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
PUSBHUB_FDO_EXTENSION NTAPI USBH_GetRootHubExtension(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:699
NTSTATUS NTAPI USBH_SubmitStatusChangeTransfer(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2442
BOOLEAN NTAPI USBH_CheckIdleAbort(IN PUSBHUB_FDO_EXTENSION HubExtension, IN BOOLEAN IsWait, IN BOOLEAN IsExtCheck)
Definition: usbhub.c:3221
#define USBHUB_FDO_FLAG_DEVICE_STARTED
Definition: usbhub.h:33
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
#define USBHUB_FDO_FLAG_DO_SUSPENSE
Definition: usbhub.h:56
#define USBHUB_FDO_FLAG_HIBERNATE_STATE
Definition: usbhub.h:54
#define USBHUB_FDO_FLAG_NOT_D0_STATE
Definition: usbhub.h:43
#define USBHUB_FDO_FLAG_PENDING_WAKE_IRP
Definition: usbhub.h:39
#define USBHUB_FDO_FLAG_SET_D0_STATE
Definition: usbhub.h:42
#define USBHUB_FDO_FLAG_DEVICE_STOPPED
Definition: usbhub.h:37
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3034
_Out_opt_ PULONG Minor
Definition: cmfuncs.h:44
#define IRP_MN_WAIT_WAKE
#define IRP_MN_POWER_SEQUENCE
#define IRP_MN_SET_POWER
#define IRP_MN_QUERY_POWER
@ Executive
Definition: ketypes.h:415

Referenced by USBH_FdoDispatch().

◆ USBH_FdoWWIrpIoCompletion()

NTSTATUS NTAPI USBH_FdoWWIrpIoCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 271 of file power.c.

274{
275 PUSBHUB_FDO_EXTENSION HubExtension;
279 PIRP WakeIrp;
280
281 DPRINT("USBH_FdoWWIrpIoCompletion: DeviceObject - %p, Irp - %p\n",
283 Irp);
284
285 HubExtension = Context;
286
287 Status = Irp->IoStatus.Status;
288
290
291 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_PENDING_WAKE_IRP;
292
293 WakeIrp = InterlockedExchangePointer((PVOID *)&HubExtension->PendingWakeIrp,
294 NULL);
295
296 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
297 {
298 KeSetEvent(&HubExtension->PendingRequestEvent,
300 FALSE);
301 }
302
304
305 DPRINT("USBH_FdoWWIrpIoCompletion: Status - %lX\n", Status);
306
307 if (!NT_SUCCESS(Status))
308 {
309 DPRINT1("USBH_FdoWWIrpIoCompletion: DbgBreakPoint() \n");
311 }
312 else
313 {
314 PowerState.DeviceState = PowerDeviceD0;
315
316 HubExtension->HubFlags |= USBHUB_FDO_FLAG_WAKEUP_START;
318
320
321 PoRequestPowerIrp(HubExtension->LowerPDO,
325 (PVOID)HubExtension,
326 NULL);
327 }
328
329 if (!WakeIrp)
330 {
331 if (!InterlockedExchange(&HubExtension->FdoWaitWakeLock, 1))
332 {
334 }
335 }
336
337 DPRINT("USBH_FdoWWIrpIoCompletion: Status - %lX\n", Status);
338
340 {
342 }
343
344 return Status;
345}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedExchange
Definition: armddk.h:54
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
VOID NTAPI USBH_FdoPoRequestD0Completion(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
Definition: power.c:236
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define USBHUB_FDO_FLAG_WAKEUP_START
Definition: usbhub.h:49
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by USBH_FdoPower().

◆ USBH_HubCancelWakeIrp()

VOID NTAPI USBH_HubCancelWakeIrp ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PIRP  Irp 
)

Definition at line 43 of file power.c.

45{
46 DPRINT("USBH_HubCancelWakeIrp: HubExtension - %p, Irp - %p\n",
47 HubExtension,
48 Irp);
49
51
52 if (InterlockedExchange((PLONG)&HubExtension->FdoWaitWakeLock, 1))
53 {
55 Irp->IoStatus.Status = STATUS_CANCELLED;
57 }
58}
int32_t * PLONG
Definition: typedefs.h:58
#define STATUS_CANCELLED
Definition: udferr_usr.h:170

Referenced by USBH_FdoCleanup().

◆ USBH_HubCompletePortWakeIrps()

VOID NTAPI USBH_HubCompletePortWakeIrps ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN NTSTATUS  NtStatus 
)

Definition at line 217 of file power.c.

219{
220 LIST_ENTRY ListIrps;
221
222 DPRINT("USBH_HubCompletePortWakeIrps: NtStatus - %x\n", NtStatus);
223
224 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STARTED)
225 {
226 USBH_HubQueuePortWakeIrps(HubExtension, &ListIrps);
227
229 &ListIrps,
230 NtStatus);
231 }
232}
VOID NTAPI USBH_HubQueuePortWakeIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY ListIrps)
Definition: power.c:160
VOID NTAPI USBH_HubCompleteQueuedPortWakeIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY ListIrps, IN NTSTATUS NtStatus)
Definition: power.c:202
Definition: typedefs.h:120

Referenced by USBH_FdoCleanup(), and USBH_FdoPoRequestD0Completion().

◆ USBH_HubCompleteQueuedPortWakeIrps()

VOID NTAPI USBH_HubCompleteQueuedPortWakeIrps ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PLIST_ENTRY  ListIrps,
IN NTSTATUS  NtStatus 
)

Definition at line 202 of file power.c.

205{
206 DPRINT("USBH_HubCompleteQueuedPortWakeIrps ... \n");
207
208 while (!IsListEmpty(ListIrps))
209 {
210 DPRINT1("USBH_HubCompleteQueuedPortWakeIrps: UNIMPLEMENTED. FIXME\n");
212 }
213}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954

Referenced by USBH_HubCompletePortWakeIrps().

◆ USBH_HubESDRecoverySetD3Completion()

VOID NTAPI USBH_HubESDRecoverySetD3Completion ( IN PDEVICE_OBJECT  DeviceObject,
IN UCHAR  MinorFunction,
IN POWER_STATE  PowerState,
IN PVOID  Context,
IN PIO_STATUS_BLOCK  IoStatus 
)

Definition at line 62 of file power.c.

67{
68 DPRINT("USBH_HubESDRecoverySetD3Completion ... \n");
69
72 FALSE);
73}

Referenced by USBH_HubSetD0().

◆ USBH_HubQueuePortWakeIrps()

VOID NTAPI USBH_HubQueuePortWakeIrps ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PLIST_ENTRY  ListIrps 
)

Definition at line 160 of file power.c.

162{
163 PDEVICE_OBJECT PortDevice;
164 PUSBHUB_PORT_PDO_EXTENSION PortExtension;
165 USHORT NumPorts;
166 USHORT Port;
167 PIRP WakeIrp;
169
170 DPRINT("USBH_HubQueuePortWakeIrps ... \n");
171
172 NumPorts = HubExtension->HubDescriptor->bNumberOfPorts;
173
174 InitializeListHead(ListIrps);
175
177
178 for (Port = 0; Port < NumPorts; ++Port)
179 {
180 PortDevice = HubExtension->PortData[Port].DeviceObject;
181
182 if (PortDevice)
183 {
184 PortExtension = PortDevice->DeviceExtension;
185
186 WakeIrp = PortExtension->PdoWaitWakeIrp;
187 PortExtension->PdoWaitWakeIrp = NULL;
188
189 if (WakeIrp)
190 {
191 DPRINT1("USBH_HubQueuePortWakeIrps: UNIMPLEMENTED. FIXME\n");
193 }
194 }
195 }
196
198}
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned short USHORT
Definition: pedump.c:61

Referenced by USBH_HubCompletePortWakeIrps().

◆ USBH_HubSetD0()

NTSTATUS NTAPI USBH_HubSetD0 ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 77 of file power.c.

78{
79 PUSBHUB_FDO_EXTENSION RootHubDevExt;
83
84 DPRINT("USBH_HubSetD0: HubExtension - %p\n", HubExtension);
85
86 RootHubDevExt = USBH_GetRootHubExtension(HubExtension);
87
89 {
91 return Status;
92 }
93
94 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST)
95 {
96 DPRINT("USBH_HubSetD0: HubFlags - %lX\n", HubExtension->HubFlags);
97
98 KeWaitForSingleObject(&HubExtension->IdleEvent,
101 FALSE,
102 NULL);
103 }
104
106
107 PowerState.DeviceState = PowerDeviceD0;
108
109 Status = PoRequestPowerIrp(HubExtension->LowerPDO,
113 &Event,
114 NULL);
115
116 if (Status == STATUS_PENDING)
117 {
119 Suspended,
121 FALSE,
122 NULL);
123 }
124
125 while (HubExtension->HubFlags & USBHUB_FDO_FLAG_WAKEUP_START)
126 {
127 USBH_Wait(10);
128 }
129
130 return Status;
131}
VOID NTAPI USBH_HubESDRecoverySetD3Completion(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
Definition: power.c:62
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
@ NotificationEvent
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
NTSTATUS NTAPI USBH_Wait(IN ULONG Milliseconds)
Definition: usbhub.c:23
#define USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST
Definition: usbhub.h:44
@ Suspended
Definition: ketypes.h:420

Referenced by USBH_DeviceControl(), USBH_FdoPnP(), USBH_IdleCancelPowerHubWorker(), USBH_IdleCompletePowerHubWorker(), and USBH_PdoRemoveDevice().

◆ USBH_IdleCancelPowerHubWorker()

VOID NTAPI USBH_IdleCancelPowerHubWorker ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PVOID  Context 
)

Definition at line 135 of file power.c.

137{
138 PUSBHUB_IDLE_PORT_CANCEL_CONTEXT WorkItemIdlePower;
139 PIRP Irp;
140
141 DPRINT("USBH_IdleCancelPowerHubWorker: ... \n");
142
143 WorkItemIdlePower = Context;
144
145 if (HubExtension &&
146 HubExtension->CurrentPowerState.DeviceState != PowerDeviceD0 &&
147 HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STARTED)
148 {
149 USBH_HubSetD0(HubExtension);
150 }
151
152 Irp = WorkItemIdlePower->Irp;
154
156}
NTSTATUS NTAPI USBH_HubSetD0(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: power.c:77
IO_STATUS_BLOCK IoStatus

Referenced by USBH_PortIdleNotificationCancelRoutine().

◆ USBH_PdoPower()

NTSTATUS NTAPI USBH_PdoPower ( IN PUSBHUB_PORT_PDO_EXTENSION  PortExtension,
IN PIRP  Irp,
IN UCHAR  Minor 
)

Definition at line 757 of file power.c.

760{
761 NTSTATUS Status = Irp->IoStatus.Status;
762
763 DPRINT_PWR("USBH_FdoPower: PortExtension - %p, Irp - %p, Minor - %X\n",
764 PortExtension,
765 Irp,
766 Minor);
767
768 switch (Minor)
769 {
770 case IRP_MN_WAIT_WAKE:
771 DPRINT_PWR("USBHUB_PdoPower: IRP_MN_WAIT_WAKE\n");
773 break;
774
776 DPRINT_PWR("USBHUB_PdoPower: IRP_MN_POWER_SEQUENCE\n");
778 break;
779
780 case IRP_MN_SET_POWER:
781 DPRINT_PWR("USBHUB_PdoPower: IRP_MN_SET_POWER\n");
783 break;
784
786 DPRINT_PWR("USBHUB_PdoPower: IRP_MN_QUERY_POWER\n");
788 break;
789
790 default:
791 DPRINT1("USBHUB_PdoPower: unknown IRP_MN_POWER!\n");
793 break;
794 }
795
796 Irp->IoStatus.Status = Status;
797 Irp->IoStatus.Information = 0;
799
800 return Status;
801}

Referenced by USBH_PdoDispatch().

◆ USBH_PowerIrpCompletion()

NTSTATUS NTAPI USBH_PowerIrpCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 349 of file power.c.

352{
353 PUSBHUB_FDO_EXTENSION HubExtension;
354 PIO_STACK_LOCATION IoStack;
355 DEVICE_POWER_STATE OldDeviceState;
358
359 DPRINT("USBH_PowerIrpCompletion: DeviceObject - %p, Irp - %p\n",
361 Irp);
362
363 HubExtension = Context;
364
366 PowerState = IoStack->Parameters.Power.State;
367
368 Status = Irp->IoStatus.Status;
369 DPRINT("USBH_PowerIrpCompletion: Status - %lX\n", Status);
370
371 if (!NT_SUCCESS(Status))
372 {
373 if (PowerState.DeviceState == PowerDeviceD0)
374 {
376 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_SET_D0_STATE;
377 }
378 }
379 else if (PowerState.DeviceState == PowerDeviceD0)
380 {
381 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_SET_D0_STATE;
382
383 OldDeviceState = HubExtension->CurrentPowerState.DeviceState;
385
386 DPRINT("USBH_PowerIrpCompletion: OldDeviceState - %x\n", OldDeviceState);
387
388 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_HIBERNATE_STATE)
389 {
390 DPRINT1("USBH_PowerIrpCompletion: USBHUB_FDO_FLAG_HIBERNATE_STATE. FIXME\n");
392 }
393
394 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_HIBERNATE_STATE;
395
396 if (OldDeviceState == PowerDeviceD3)
397 {
398 DPRINT1("USBH_PowerIrpCompletion: PowerDeviceD3. FIXME\n");
400 }
401
402 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED) &&
404 {
406 }
407
408 DPRINT("USBH_PowerIrpCompletion: Status - %lX\n", Status);
409
411 {
413 return Status;
414 }
415 }
416
417 return Status;
418}
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
POWER_STATE CurrentPowerState
Definition: usbhub.h:160
#define USBHUB_FDO_FLAG_DO_ENUMERATION
Definition: usbhub.h:52

Referenced by USBH_FdoPower().