Author: mjmartin Date: Tue Jul 6 12:02:33 2010 New Revision: 47958
URL: http://svn.reactos.org/svn/reactos?rev=47958&view=rev Log: - Implement DeviceHandleToUsbDevice and remove IsHandleValid. - Add call to DeviceHandleToUsbDevice for all Direct Call functions that pass DeviceHandle. - Stop the processing of Asynchronous List after the Control Request has been processed by controller. - Misc changes.
Modified: trunk/reactos/drivers/usb/usbehci/common.c trunk/reactos/drivers/usb/usbehci/misc.c trunk/reactos/drivers/usb/usbehci/pdo.c trunk/reactos/drivers/usb/usbehci/urbreq.c trunk/reactos/drivers/usb/usbehci/usbehci.h trunk/reactos/drivers/usb/usbehci/usbehci.rbuild trunk/reactos/drivers/usb/usbehci/usbiffn.c
Modified: trunk/reactos/drivers/usb/usbehci/common.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/common.... ============================================================================== --- trunk/reactos/drivers/usb/usbehci/common.c [iso-8859-1] (original) +++ trunk/reactos/drivers/usb/usbehci/common.c [iso-8859-1] Tue Jul 6 12:02:33 2010 @@ -4,7 +4,7 @@ * FILE: drivers/usb/usbehci/common.c * PURPOSE: Common operations in FDO/PDO. * PROGRAMMERS: - * Michael Martin + * Michael Martin (mjmartin@reactos.org) */
#define INITGUID @@ -135,7 +135,7 @@ if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE) DestMaxLength += sizeof(UNICODE_NULL);
- DestinationString->Buffer = ExAllocatePool(PagedPool, DestMaxLength); + DestinationString->Buffer = ExAllocatePoolWithTag(NonPagedPool, DestMaxLength, USB_POOL_TAG); if (DestinationString->Buffer == NULL) return STATUS_NO_MEMORY;
Modified: trunk/reactos/drivers/usb/usbehci/misc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/misc.c?... ============================================================================== --- trunk/reactos/drivers/usb/usbehci/misc.c [iso-8859-1] (original) +++ trunk/reactos/drivers/usb/usbehci/misc.c [iso-8859-1] Tue Jul 6 12:02:33 2010 @@ -8,6 +8,8 @@ */
#include "usbehci.h" +#include <hubbusif.h> +#include <usbbusif.h>
/* Get SymblicName from Parameters in Registry Key @@ -121,3 +123,14 @@ return ObjectName; }
+PUSB_DEVICE DeviceHandleToUsbDevice(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PUSB_DEVICE_HANDLE DeviceHandle) +{ + LONG i; + + for (i=0; i<127; i++) + { + if (PdoDeviceExtension->UsbDevices[i] == (PUSB_DEVICE)DeviceHandle) + return (PUSB_DEVICE)DeviceHandle; + } + return NULL; +}
Modified: trunk/reactos/drivers/usb/usbehci/pdo.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/pdo.c?r... ============================================================================== --- trunk/reactos/drivers/usb/usbehci/pdo.c [iso-8859-1] (original) +++ trunk/reactos/drivers/usb/usbehci/pdo.c [iso-8859-1] Tue Jul 6 12:02:33 2010 @@ -446,7 +446,6 @@ else { Status = IoSetDeviceInterfaceState(&InterfaceSymLinkName, TRUE); - DPRINT1("Set interface state %x\n", Status); if (!NT_SUCCESS(Status)) ASSERT(FALSE); }
Modified: trunk/reactos/drivers/usb/usbehci/urbreq.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/urbreq.... ============================================================================== --- trunk/reactos/drivers/usb/usbehci/urbreq.c [iso-8859-1] (original) +++ trunk/reactos/drivers/usb/usbehci/urbreq.c [iso-8859-1] Tue Jul 6 12:02:33 2010 @@ -82,7 +82,10 @@
(*CtrlTD2)->NextPointer = TERMINATE_POINTER; (*CtrlTD2)->AlternateNextPointer = TERMINATE_POINTER; - (*CtrlTD2)->BufferPointer[0] = (ULONG)MmGetPhysicalAddress((PVOID) (*CtrlData)).LowPart; + if (Size == 0) + (*CtrlTD2)->BufferPointer[0] = 0; + else + (*CtrlTD2)->BufferPointer[0] = (ULONG)MmGetPhysicalAddress((PVOID) (*CtrlData)).LowPart; (*CtrlTD2)->Token.Bits.DataToggle = TRUE; (*CtrlTD2)->Token.Bits.InterruptOnComplete = TRUE; (*CtrlTD2)->Token.Bits.TotalBytesToTransfer = Size; @@ -98,6 +101,7 @@ (*CtrlTD3)->Token.Bits.Active = TRUE; (*CtrlTD3)->Token.Bits.PIDCode = PID_CODE_OUT_TOKEN; (*CtrlTD3)->Token.Bits.InterruptOnComplete = TRUE; + (*CtrlTD3)->Token.Bits.TotalBytesToTransfer = 0; (*CtrlTD3)->Token.Bits.DataToggle = TRUE; (*CtrlTD3)->Token.Bits.ErrorCounter = 0x03; (*CtrlTD2)->NextPointer = (ULONG) MmGetPhysicalAddress((PVOID)(*CtrlTD3)).LowPart; @@ -185,11 +189,14 @@
for (;;) { - KeStallExecutionProcessor(10); + KeStallExecutionProcessor(100); DPRINT("Waiting for completion!\n"); if (DeviceExtension->AsyncComplete == TRUE) break; } + + UsbCmd->Run = FALSE; + WRITE_REGISTER_ULONG((PULONG)(Base + EHCI_USBCMD), tmp);
if (CtrlSetup->bmRequestType._BM.Dir == BMREQUEST_DEVICE_TO_HOST) {
Modified: trunk/reactos/drivers/usb/usbehci/usbehci.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/usbehci... ============================================================================== --- trunk/reactos/drivers/usb/usbehci/usbehci.h [iso-8859-1] (original) +++ trunk/reactos/drivers/usb/usbehci/usbehci.h [iso-8859-1] Tue Jul 6 12:02:33 2010 @@ -419,14 +419,6 @@ FAST_MUTEX ListLock; } PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
-typedef struct _WORKITEM_DATA -{ - PIO_WORKITEM IoWorkItem; - PPDO_DEVICE_EXTENSION PdoDeviceExtension; - PDEVICE_OBJECT PortDeviceObject; -} WORKITEM_DATA, *PWORKITEM_DATA; - - VOID NTAPI UrbWorkerThread(PVOID Context);
@@ -478,5 +470,5 @@ VOID URBRequestCancel (PDEVICE_OBJECT DeviceObject, PIRP Irp);
-VOID NTAPI -DeviceArrivalWorkItem(PDEVICE_OBJECT DeviceObject, PVOID Context); +PUSB_DEVICE +DeviceHandleToUsbDevice(PPDO_DEVICE_EXTENSION PdoDeviceExtension, PUSB_DEVICE_HANDLE DeviceHandle);
Modified: trunk/reactos/drivers/usb/usbehci/usbehci.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/usbehci... ============================================================================== --- trunk/reactos/drivers/usb/usbehci/usbehci.rbuild [iso-8859-1] (original) +++ trunk/reactos/drivers/usb/usbehci/usbehci.rbuild [iso-8859-1] Tue Jul 6 12:02:33 2010 @@ -11,4 +11,5 @@ <file>irp.c</file> <file>usbiffn.c</file> <file>urbreq.c</file> + <file>usbehci.rc</file> </module>
Modified: trunk/reactos/drivers/usb/usbehci/usbiffn.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/usbiffn... ============================================================================== --- trunk/reactos/drivers/usb/usbehci/usbiffn.c [iso-8859-1] (original) +++ trunk/reactos/drivers/usb/usbehci/usbiffn.c [iso-8859-1] Tue Jul 6 12:02:33 2010 @@ -38,27 +38,6 @@ return UsbDevicePointer; }
-BOOLEAN -IsHandleValid(PVOID BusContext, - PUSB_DEVICE_HANDLE DeviceHandle) -{ - PPDO_DEVICE_EXTENSION PdoDeviceExtension; - LONG i; - - PdoDeviceExtension = (PPDO_DEVICE_EXTENSION) BusContext; - - if (!DeviceHandle) - return FALSE; - - for (i = 0; i < 128; i++) - { - if (PdoDeviceExtension->UsbDevices[i] == DeviceHandle) - return TRUE; - } - - return FALSE; -} - VOID USB_BUSIFFN InterfaceReference(PVOID BusContext) @@ -86,9 +65,18 @@ PUSB_DEVICE UsbDevice; LONG i = 0; PdoDeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)BusContext)->DeviceExtension; - DPRINT1("CreateUsbDevice: HubDeviceHandle %x, PortStatus %x, PortNumber %x\n", HubDeviceHandle, PortStatus, PortNumber); + DPRINT("CreateUsbDevice: HubDeviceHandle %x, PortStatus %x, PortNumber %x\n", HubDeviceHandle, PortStatus, PortNumber); + + if (PdoDeviceExtension->UsbDevices[0] != HubDeviceHandle) + { + DPRINT1("Not a valid HubDeviceHandle\n"); + return STATUS_DEVICE_NOT_CONNECTED; + }
UsbDevice = InternalCreateUsbDevice(PdoDeviceExtension->ChildDeviceCount, PortNumber, HubDeviceHandle, FALSE); + + if (!UsbDevice) + return STATUS_INSUFFICIENT_RESOURCES;
/* Add it to the list */ while (TRUE) @@ -131,7 +119,14 @@ DPRINT1("InitializeUsbDevice called, device %x\n", DeviceHandle); PdoDeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)BusContext)->DeviceExtension; FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)PdoDeviceExtension->ControllerFdo->DeviceExtension; - UsbDevice = (PUSB_DEVICE) DeviceHandle; + + UsbDevice = DeviceHandleToUsbDevice(BusContext, DeviceHandle); + + if (!UsbDevice) + { + DPRINT1("Invalid DeviceHandle or device not connected\n"); + return STATUS_DEVICE_NOT_CONNECTED; + }
Buffer = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, USB_POOL_TAG);
@@ -153,7 +148,7 @@ CtrlSetup.wLength = 0;
DPRINT1("Setting Address to %x\n", UsbDevice->Address); - ResultOk = ExecuteControlRequest(FdoDeviceExtension, &CtrlSetup, 0, 0, NULL, 0); + ResultOk = ExecuteControlRequest(FdoDeviceExtension, &CtrlSetup, 0, UsbDevice->Port, NULL, 0);
/* Get the Device Descriptor */ CtrlSetup.bmRequestType._BM.Recipient = BMREQUEST_TO_DEVICE; @@ -177,7 +172,10 @@ DPRINT1("bNumDescriptors %x\n", UsbDevice->DeviceDescriptor.bNumConfigurations);
if (UsbDevice->DeviceDescriptor.bNumConfigurations == 0) + { + DPRINT1("No Configurations. That cant be good!\n"); return STATUS_DEVICE_DATA_ERROR; + }
UsbDevice->Configs = ExAllocatePoolWithTag(NonPagedPool, sizeof(PVOID) * UsbDevice->DeviceDescriptor.bNumConfigurations, @@ -256,8 +254,14 @@ PUSB_DEVICE UsbDevice; DPRINT1("GetUsbDescriptor %x, %x, %x, %x\n", DeviceDescriptorBuffer, *DeviceDescriptorBufferLength, ConfigDescriptorBuffer, *ConfigDescriptorBufferLength);
- UsbDevice = (PUSB_DEVICE) DeviceHandle; - DPRINT1("DeviceHandle %x\n", UsbDevice); + UsbDevice = DeviceHandleToUsbDevice(BusContext, DeviceHandle); + + if (!UsbDevice) + { + DPRINT1("Invalid DeviceHandle or device not connected\n"); + return STATUS_DEVICE_NOT_CONNECTED; + } + if ((DeviceDescriptorBuffer) && (DeviceDescriptorBufferLength)) { RtlCopyMemory(DeviceDescriptorBuffer, &UsbDevice->DeviceDescriptor, sizeof(USB_DEVICE_DESCRIPTOR)); @@ -284,13 +288,13 @@
PdoDeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)BusContext)->DeviceExtension;
- /* FIXME: Implement DeviceHandleToUsbDevice to validate handles */ - //UsbDevice = DeviceHandleToUsbDevice(PdoDeviceExtension, DeviceHandle); - - UsbDevice = (PUSB_DEVICE) DeviceHandle; - - if (!UsbDevice) + UsbDevice = DeviceHandleToUsbDevice(BusContext, DeviceHandle); + + if (!UsbDevice) + { + DPRINT1("Invalid DeviceHandle or device not connected\n"); return STATUS_DEVICE_NOT_CONNECTED; + }
switch (Flags) { @@ -320,11 +324,11 @@ /* DeConfig Device */ break; case USBD_KEEP_DEVICE_DATA: - DPRINT("USBD_KEEP_DEVICE_DATA Not implemented!\n"); + DPRINT1("USBD_KEEP_DEVICE_DATA Not implemented!\n"); break;
case USBD_MARK_DEVICE_BUSY: - DPRINT("USBD_MARK_DEVICE_BUSY Not implemented!\n"); + DPRINT1("USBD_MARK_DEVICE_BUSY Not implemented!\n"); break; default: DPRINT1("Unknown Remove Flags %x\n", Flags); @@ -357,17 +361,18 @@ PULONG LengthReturned) { PUSB_DEVICE_INFORMATION_0 DeviceInfo = DeviceInformationBuffer; - PUSB_DEVICE UsbDevice = (PUSB_DEVICE) DeviceHandle; + PUSB_DEVICE UsbDevice; ULONG SizeNeeded; LONG i;
DPRINT1("QueryDeviceInformation (%x, %x, %x, %d, %x\n", BusContext, DeviceHandle, DeviceInformationBuffer, DeviceInformationBufferLength, LengthReturned);
- /* Search for a valid usb device in this BusContext */ - if (!IsHandleValid(BusContext, DeviceHandle)) - { - DPRINT1("Not a valid DeviceHandle\n"); - return STATUS_INVALID_PARAMETER; + UsbDevice = DeviceHandleToUsbDevice(BusContext, DeviceHandle); + + if (!UsbDevice) + { + DPRINT1("Invalid DeviceHandle or device not connected\n"); + return STATUS_DEVICE_NOT_CONNECTED; }
SizeNeeded = FIELD_OFFSET(USB_DEVICE_INFORMATION_0, PipeList[UsbDevice->ActiveInterface->InterfaceDescriptor.bNumEndpoints]); @@ -505,7 +510,17 @@ USB_BUSIFFN GetDeviceBusContext(PVOID HubBusContext, PVOID DeviceHandle) { + PUSB_DEVICE UsbDevice; + DPRINT1("GetDeviceBusContext called\n"); + UsbDevice = DeviceHandleToUsbDevice(HubBusContext, DeviceHandle); + + if (!UsbDevice) + { + DPRINT1("Invalid DeviceHandle or device not connected\n"); + return NULL; + } + return NULL; }
@@ -549,6 +564,14 @@ USB_BUSIFFN FlushTransfers(PVOID BusContext, PVOID DeviceHandle) { + PUSB_DEVICE UsbDevice; + UsbDevice = DeviceHandleToUsbDevice(BusContext, DeviceHandle); + + if (!UsbDevice) + { + DPRINT1("Invalid DeviceHandle or device not connected\n"); + } + DPRINT1("FlushTransfers\n"); }
@@ -611,5 +634,5 @@ EnumLogEntry(PVOID BusContext, ULONG DriverTag, ULONG EnumTag, ULONG P1, ULONG P2) { DPRINT1("EnumLogEntry called\n"); - return STATUS_NOT_SUPPORTED; -} + return STATUS_SUCCESS; +}