ReactOS 0.4.16-dev-91-g764881a
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
#define FALSE
Definition: types.h:117
@ PdoExtension
Definition: precomp.h:49
@ FdoExtension
Definition: precomp.h:48
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
@ PowerSystemUnspecified
Definition: ntpoapi.h:35
@ PowerSystemSleeping1
Definition: ntpoapi.h:37
@ PowerSystemSleeping2
Definition: ntpoapi.h:38
@ PowerSystemSleeping3
Definition: ntpoapi.h:39
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerSystemHibernate
Definition: ntpoapi.h:40
@ PowerDeviceD2
Definition: ntpoapi.h:51
@ PowerDeviceD3
Definition: ntpoapi.h:52
#define DPRINT
Definition: sndvol32.h:73
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
DEVICE_CAPABILITIES
Definition: iotypes.h:965
* PDEVICE_CAPABILITIES
Definition: iotypes.h:965

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{
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
#define NULL
Definition: types.h:112
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define IO_NO_INCREMENT
Definition: iotypes.h:598
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

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;
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
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}
IoSetCancelRoutine(Irp, CancelRoutine)
#define STATUS_SUCCESS
Definition: shellext.h:65
PVOID DeviceExtension
Definition: env_spec_w32.h:418

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}
#define InterlockedDecrement
Definition: armddk.h:52
NTKERNELAPI PIRP NTAPI IoCsqRemoveNextIrp(_Inout_ PIO_CSQ Csq, _In_opt_ PVOID PeekContext)
IoCsqRemoveNextIrp - Removes the next IRP from the queue.
Definition: csq.c:398

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

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;
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
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);
604 FdoExtension->TimerFlags &= ~USBPORT_TMFLAG_IDLE_QUEUEITEM_ON;
605 KeReleaseSpinLock(&FdoExtension->TimerFlagsSpinLock, OldIrql);
606
607 ExFreePoolWithTag(IdleQueueItem, USB_PORT_TAG);
608}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
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 KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
@ PowerDeviceD0
Definition: ntpoapi.h:49
struct _IO_STACK_LOCATION::@1575::@1576 DeviceIoControl
union _IO_STACK_LOCATION::@1575 Parameters
IO_STATUS_BLOCK IoStatus
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:445
LONGLONG QuadPart
Definition: typedefs.h:114
#define USB_PORT_TAG
Definition: usbport.h:44

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}

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
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}
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI USBPORT_SystemPowerState(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: power.c:480
NTSTATUS NTAPI USBPORT_DevicePowerState(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: power.c:471
NTSTATUS NTAPI USBPORT_HcWake(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: power.c:462
Status
Definition: gdiplustypes.h:25
#define IoCopyCurrentIrpStackLocationToNext(Irp)
Definition: ntifs_ex.h:413
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
@ DevicePowerState
Definition: ntpoapi.h:63
#define STATUS_PENDING
Definition: ntstatus.h:82
struct _IO_STACK_LOCATION::@3974::@4010 Power
#define IRP_MN_WAIT_WAKE
#define IRP_MN_POWER_SEQUENCE
#define IRP_MN_SET_POWER
#define IRP_MN_QUERY_POWER

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;
71}
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725

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}

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
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:687

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
660
661 IoCsqInsertIrp(&FdoExtension->IdleIoCsq, Irp, 0);
662
663 return Status;
664}
#define InterlockedIncrement
Definition: armddk.h:53
IoMarkIrpPending(Irp)
long LONG
Definition: pedump.c:60
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129

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
269 }
270 else
271 {
272 DPRINT1("USBPORT_PdoDevicePowerState: FdoExtension->Flags - %lx\n",
273 FdoExtension->Flags);
274
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_CompletePendingIdleIrp(IN PDEVICE_OBJECT PdoDevice)
Definition: power.c:75
VOID NTAPI USBPORT_SuspendController(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:112
NTSTATUS NTAPI USBPORT_ResumeController(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:146
NTSYSAPI void WINAPI DbgBreakPoint(void)
@ PowerDeviceD1
Definition: ntpoapi.h:50
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
#define USBPORT_TMFLAG_WAKE
Definition: usbport.h:98

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;
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
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");
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
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}
NTSTATUS NTAPI USBPORT_PdoDevicePowerState(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: power.c:232
VOID NTAPI USBPORT_CancelPendingWakeIrp(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: power.c:293
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#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{
152 MPSTATUS MpStatus;
153
154 DPRINT1("USBPORT_ResumeController: ... \n");
155
156 FdoExtension = FdoDevice->DeviceExtension;
157 Packet = &FdoExtension->MiniPortInterface->Packet;
158
160 {
161 return Status;
162 }
163
164 KeAcquireSpinLock(&FdoExtension->TimerFlagsSpinLock, &OldIrql);
165
168
169 KeReleaseSpinLock(&FdoExtension->TimerFlagsSpinLock, OldIrql);
170
171 if (!(FdoExtension->MiniPortFlags & USBPORT_MPFLAG_SUSPENDED))
172 {
173 FdoExtension->Flags &= ~USBPORT_FLAG_HC_SUSPEND;
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
183 FdoExtension->Flags &= ~USBPORT_FLAG_HC_SUSPEND;
184 return Status;
185 }
186
187 KeAcquireSpinLock(&FdoExtension->TimerFlagsSpinLock, &OldIrql);
190 KeReleaseSpinLock(&FdoExtension->TimerFlagsSpinLock, OldIrql);
191
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 {
213 }
214
215 KeAcquireSpinLock(&FdoExtension->TimerFlagsSpinLock, &OldIrql);
216
220
221 KeReleaseSpinLock(&FdoExtension->TimerFlagsSpinLock, OldIrql);
222
223 Status = USBPORT_Wait(FdoDevice, 100);
224
225 FdoExtension->Flags &= ~USBPORT_FLAG_HC_SUSPEND;
226
227 return Status;
228}
VOID NTAPI USBPORT_NukeAllEndpoints(IN PDEVICE_OBJECT FdoDevice)
Definition: endpoint.c:300
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
ULONG MPSTATUS
Definition: usbmport.h:131
VOID NTAPI USBPORT_MiniportInterrupts(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsEnable)
Definition: usbport.c:555
#define USBPORT_TMFLAG_HC_SUSPENDED
Definition: usbport.h:94
#define USBPORT_FLAG_HC_SUSPEND
Definition: usbport.h:71
#define USBPORT_TMFLAG_RH_SUSPENDED
Definition: usbport.h:96
#define USBPORT_MPFLAG_SUSPENDED
Definition: usbport.h:103
#define USBPORT_TMFLAG_HC_RESUME
Definition: usbport.h:95

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
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
#define USBPORT_MPFLAG_INTERRUPTS_ENABLED
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}

Referenced by USBPORT_FdoPower().