[USB]
[reactos.git] / reactos / drivers / usb / usbehci / misc.cpp
1 /*
2 * PROJECT: ReactOS Universal Serial Bus Bulk Enhanced Host Controller Interface
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/usb/usbehci/misc.cpp
5 * PURPOSE: USB EHCI device driver.
6 * PROGRAMMERS:
7 * Michael Martin (michael.martin@reactos.org)
8 * Johannes Anderwald (johannes.anderwald@reactos.org)
9 */
10
11 #include "usbehci.h"
12
13 //
14 // driver verifier
15 //
16 IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine;
17
18 NTSTATUS
19 NTAPI
20 SyncForwardIrpCompletionRoutine(
21 PDEVICE_OBJECT DeviceObject,
22 PIRP Irp,
23 PVOID Context)
24 {
25 if (Irp->PendingReturned)
26 {
27 KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
28 }
29 return STATUS_MORE_PROCESSING_REQUIRED;
30 }
31
32 NTSTATUS
33 NTAPI
34 SyncForwardIrp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
35 {
36 KEVENT Event;
37 NTSTATUS Status;
38
39 //
40 // initialize event
41 //
42 KeInitializeEvent(&Event, NotificationEvent, FALSE);
43
44 //
45 // copy irp stack location
46 //
47 IoCopyCurrentIrpStackLocationToNext(Irp);
48
49 //
50 // set completion routine
51 //
52 IoSetCompletionRoutine(Irp, SyncForwardIrpCompletionRoutine, &Event, TRUE, TRUE, TRUE);
53
54
55 //
56 // call driver
57 //
58 Status = IoCallDriver(DeviceObject, Irp);
59
60
61 //
62 // check if pending
63 //
64 if (Status == STATUS_PENDING)
65 {
66 //
67 // wait for the request to finish
68 //
69 KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
70
71 //
72 // copy status code
73 //
74 Status = Irp->IoStatus.Status;
75 }
76
77 //
78 // done
79 //
80 return Status;
81 }
82
83 NTSTATUS
84 NTAPI
85 GetBusInterface(
86 PDEVICE_OBJECT DeviceObject,
87 PBUS_INTERFACE_STANDARD busInterface)
88 {
89 KEVENT Event;
90 NTSTATUS Status;
91 PIRP Irp;
92 IO_STATUS_BLOCK IoStatus;
93 PIO_STACK_LOCATION Stack;
94
95 if ((!DeviceObject) || (!busInterface))
96 return STATUS_UNSUCCESSFUL;
97
98 KeInitializeEvent(&Event, NotificationEvent, FALSE);
99
100 Irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP,
101 DeviceObject,
102 NULL,
103 0,
104 NULL,
105 &Event,
106 &IoStatus);
107
108 if (Irp == NULL)
109 {
110 return STATUS_INSUFFICIENT_RESOURCES;
111 }
112
113 Stack=IoGetNextIrpStackLocation(Irp);
114 Stack->MajorFunction = IRP_MJ_PNP;
115 Stack->MinorFunction = IRP_MN_QUERY_INTERFACE;
116 Stack->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD);
117 Stack->Parameters.QueryInterface.InterfaceType = (LPGUID)&GUID_BUS_INTERFACE_STANDARD;
118 Stack->Parameters.QueryInterface.Version = 1;
119 Stack->Parameters.QueryInterface.Interface = (PINTERFACE)busInterface;
120 Stack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
121 Irp->IoStatus.Status=STATUS_NOT_SUPPORTED ;
122
123 Status=IoCallDriver(DeviceObject, Irp);
124
125 if (Status == STATUS_PENDING)
126 {
127 KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
128
129 Status=IoStatus.Status;
130 }
131
132 return Status;
133 }
134