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/common.c
5 * PURPOSE: Common operations in FDO/PDO.
7 * Michael Martin (michael.martin@reactos.org)
15 /* PUBLIC AND PRIVATE FUNCTIONS ***********************************************/
18 GetBusInterface(PDEVICE_OBJECT DeviceObject
, PBUS_INTERFACE_STANDARD busInterface
)
23 IO_STATUS_BLOCK IoStatus
;
24 PIO_STACK_LOCATION Stack
;
26 if ((!DeviceObject
) || (!busInterface
))
27 return STATUS_UNSUCCESSFUL
;
29 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
31 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_PNP
,
41 return STATUS_INSUFFICIENT_RESOURCES
;
44 Stack
=IoGetNextIrpStackLocation(Irp
);
45 Stack
->MajorFunction
= IRP_MJ_PNP
;
46 Stack
->MinorFunction
= IRP_MN_QUERY_INTERFACE
;
47 Stack
->Parameters
.QueryInterface
.Size
= sizeof(BUS_INTERFACE_STANDARD
);
48 Stack
->Parameters
.QueryInterface
.InterfaceType
= (LPGUID
)&GUID_BUS_INTERFACE_STANDARD
;
49 Stack
->Parameters
.QueryInterface
.Version
= 1;
50 Stack
->Parameters
.QueryInterface
.Interface
= (PINTERFACE
)busInterface
;
51 Stack
->Parameters
.QueryInterface
.InterfaceSpecificData
= NULL
;
52 Irp
->IoStatus
.Status
=STATUS_NOT_SUPPORTED
;
54 Status
=IoCallDriver(DeviceObject
, Irp
);
56 if (Status
== STATUS_PENDING
)
58 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
60 Status
=IoStatus
.Status
;
67 ForwardAndWaitCompletionRoutine(PDEVICE_OBJECT DeviceObject
, PIRP Irp
, PKEVENT Event
)
69 if (Irp
->PendingReturned
)
71 KeSetEvent(Event
, IO_NO_INCREMENT
, FALSE
);
73 return STATUS_MORE_PROCESSING_REQUIRED
;
77 ForwardAndWait(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
79 PFDO_DEVICE_EXTENSION DeviceExtensions
;
84 DeviceExtensions
= DeviceObject
->DeviceExtension
;
85 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
86 IoCopyCurrentIrpStackLocationToNext(Irp
);
87 IoSetCompletionRoutine(Irp
, (PIO_COMPLETION_ROUTINE
)ForwardAndWaitCompletionRoutine
, &Event
, TRUE
, TRUE
, TRUE
);
88 Status
= IoCallDriver(DeviceExtensions
->LowerDevice
, Irp
);
89 if (Status
== STATUS_PENDING
)
91 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
92 Status
= Irp
->IoStatus
.Status
;
99 ForwardIrpAndForget(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
101 PDEVICE_OBJECT LowerDevice
;
103 LowerDevice
= ((PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->LowerDevice
;
106 IoSkipCurrentIrpStackLocation(Irp
);
107 return IoCallDriver(LowerDevice
, Irp
);
110 /* Copied fom trunk PCI drivers */
112 DuplicateUnicodeString(ULONG Flags
, PCUNICODE_STRING SourceString
, PUNICODE_STRING DestinationString
)
114 if (SourceString
== NULL
|| DestinationString
== NULL
115 || SourceString
->Length
> SourceString
->MaximumLength
116 || (SourceString
->Length
== 0 && SourceString
->MaximumLength
> 0 && SourceString
->Buffer
== NULL
)
117 || Flags
== RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
|| Flags
>= 4)
119 return STATUS_INVALID_PARAMETER
;
123 if ((SourceString
->Length
== 0)
124 && (Flags
!= (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
|
125 RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
)))
127 DestinationString
->Length
= 0;
128 DestinationString
->MaximumLength
= 0;
129 DestinationString
->Buffer
= NULL
;
133 USHORT DestMaxLength
= SourceString
->Length
;
135 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
136 DestMaxLength
+= sizeof(UNICODE_NULL
);
138 DestinationString
->Buffer
= ExAllocatePoolWithTag(NonPagedPool
, DestMaxLength
, USB_POOL_TAG
);
139 if (DestinationString
->Buffer
== NULL
)
140 return STATUS_NO_MEMORY
;
142 RtlCopyMemory(DestinationString
->Buffer
, SourceString
->Buffer
, SourceString
->Length
);
143 DestinationString
->Length
= SourceString
->Length
;
144 DestinationString
->MaximumLength
= DestMaxLength
;
146 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
147 DestinationString
->Buffer
[DestinationString
->Length
/ sizeof(WCHAR
)] = 0;
150 return STATUS_SUCCESS
;