2011-05-22 19:36:13 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Universal Serial Bus Bulk Enhanced Host Controller Interface
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: drivers/usb/usbohci/usb_queue.cpp
|
|
|
|
* PURPOSE: USB OHCI device driver.
|
|
|
|
* PROGRAMMERS:
|
|
|
|
* Michael Martin (michael.martin@reactos.org)
|
|
|
|
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "usbohci.h"
|
2013-12-24 20:42:53 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
2011-05-22 19:36:13 +00:00
|
|
|
|
2012-02-29 09:15:42 +00:00
|
|
|
class CUSBQueue : public IOHCIQueue
|
2011-05-22 19:36:13 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) AddRef()
|
|
|
|
{
|
|
|
|
InterlockedIncrement(&m_Ref);
|
|
|
|
return m_Ref;
|
|
|
|
}
|
|
|
|
STDMETHODIMP_(ULONG) Release()
|
|
|
|
{
|
|
|
|
InterlockedDecrement(&m_Ref);
|
|
|
|
|
|
|
|
if (!m_Ref)
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return m_Ref;
|
|
|
|
}
|
|
|
|
|
2011-05-24 17:57:00 +00:00
|
|
|
// com
|
2012-02-28 18:54:30 +00:00
|
|
|
IMP_IUSBQUEUE
|
|
|
|
IMP_IUSBOHCIQUEUE
|
2011-05-24 17:57:00 +00:00
|
|
|
|
|
|
|
// local functions
|
|
|
|
BOOLEAN IsTransferDescriptorInEndpoint(IN POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor, IN ULONG TransferDescriptorLogicalAddress);
|
2011-05-29 19:54:55 +00:00
|
|
|
BOOLEAN IsTransferDescriptorInIsoEndpoint(IN POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor, IN ULONG TransferDescriptorLogicalAddress);
|
2011-05-24 17:57:00 +00:00
|
|
|
NTSTATUS FindTransferDescriptorInEndpoint(IN POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor, IN ULONG TransferDescriptorLogicalAddress, OUT POHCI_ENDPOINT_DESCRIPTOR *OutEndpointDescriptor, OUT POHCI_ENDPOINT_DESCRIPTOR *OutPreviousEndpointDescriptor);
|
2011-05-26 12:37:18 +00:00
|
|
|
NTSTATUS FindTransferDescriptorInInterruptHeadEndpoints(IN ULONG TransferDescriptorLogicalAddress, OUT POHCI_ENDPOINT_DESCRIPTOR *OutEndpointDescriptor, OUT POHCI_ENDPOINT_DESCRIPTOR *OutPreviousEndpointDescriptor);
|
2011-05-29 19:54:55 +00:00
|
|
|
NTSTATUS FindTransferDescriptorInIsochronousHeadEndpoints(IN ULONG TransferDescriptorLogicalAddress, OUT POHCI_ENDPOINT_DESCRIPTOR *OutEndpointDescriptor, OUT POHCI_ENDPOINT_DESCRIPTOR *OutPreviousEndpointDescriptor);
|
2011-05-26 12:37:18 +00:00
|
|
|
|
2011-05-26 02:15:11 +00:00
|
|
|
VOID CleanupEndpointDescriptor(POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor, POHCI_ENDPOINT_DESCRIPTOR PreviousEndpointDescriptor);
|
2011-05-26 12:37:18 +00:00
|
|
|
POHCI_ENDPOINT_DESCRIPTOR FindInterruptEndpointDescriptor(UCHAR InterruptInterval);
|
|
|
|
VOID PrintEndpointList(POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor);
|
|
|
|
VOID LinkEndpoint(POHCI_ENDPOINT_DESCRIPTOR HeadEndpointDescriptor, POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor);
|
2012-02-18 23:23:13 +00:00
|
|
|
VOID AddEndpointDescriptor(IN POHCI_ENDPOINT_DESCRIPTOR Descriptor);
|
|
|
|
|
2011-05-22 19:36:13 +00:00
|
|
|
|
|
|
|
// constructor / destructor
|
|
|
|
CUSBQueue(IUnknown *OuterUnknown){}
|
|
|
|
virtual ~CUSBQueue(){}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
LONG m_Ref; // reference count
|
|
|
|
KSPIN_LOCK m_Lock; // list lock
|
2012-02-28 18:54:30 +00:00
|
|
|
POHCIHARDWAREDEVICE m_Hardware; // hardware
|
2011-05-23 17:42:52 +00:00
|
|
|
POHCI_ENDPOINT_DESCRIPTOR m_BulkHeadEndpointDescriptor; // bulk head descriptor
|
|
|
|
POHCI_ENDPOINT_DESCRIPTOR m_ControlHeadEndpointDescriptor; // control head descriptor
|
2011-05-27 13:04:55 +00:00
|
|
|
POHCI_ENDPOINT_DESCRIPTOR m_IsoHeadEndpointDescriptor; // isochronous head descriptor
|
2011-05-26 12:37:18 +00:00
|
|
|
POHCI_ENDPOINT_DESCRIPTOR * m_InterruptEndpoints;
|
2012-02-18 23:23:13 +00:00
|
|
|
LIST_ENTRY m_PendingRequestList; // pending request list
|
2011-05-22 19:36:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//=================================================================================================
|
|
|
|
// COM
|
|
|
|
//
|
|
|
|
NTSTATUS
|
|
|
|
STDMETHODCALLTYPE
|
|
|
|
CUSBQueue::QueryInterface(
|
|
|
|
IN REFIID refiid,
|
|
|
|
OUT PVOID* Output)
|
|
|
|
{
|
|
|
|
if (IsEqualGUIDAligned(refiid, IID_IUnknown))
|
|
|
|
{
|
|
|
|
*Output = PVOID(PUNKNOWN(this));
|
|
|
|
PUNKNOWN(*Output)->AddRef();
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
2012-02-29 09:15:42 +00:00
|
|
|
STDMETHODCALLTYPE
|
2011-05-22 19:36:13 +00:00
|
|
|
CUSBQueue::Initialize(
|
|
|
|
IN PUSBHARDWAREDEVICE Hardware,
|
|
|
|
IN PDMA_ADAPTER AdapterObject,
|
|
|
|
IN PDMAMEMORYMANAGER MemManager,
|
|
|
|
IN OPTIONAL PKSPIN_LOCK Lock)
|
|
|
|
{
|
2012-02-29 09:15:42 +00:00
|
|
|
if (!Hardware)
|
|
|
|
{
|
|
|
|
// WTF
|
|
|
|
DPRINT1("[USBOHCI] Failed to initialize queue\n");
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2012-02-28 18:54:30 +00:00
|
|
|
//
|
|
|
|
// store hardware
|
|
|
|
//
|
|
|
|
m_Hardware = POHCIHARDWAREDEVICE(Hardware);
|
2012-02-29 09:15:42 +00:00
|
|
|
ASSERT(m_Hardware);
|
2012-02-28 18:54:30 +00:00
|
|
|
|
2011-05-23 17:42:52 +00:00
|
|
|
//
|
|
|
|
// get bulk endpoint descriptor
|
|
|
|
//
|
2012-02-28 18:54:30 +00:00
|
|
|
m_Hardware->GetBulkHeadEndpointDescriptor(&m_BulkHeadEndpointDescriptor);
|
2011-05-23 17:42:52 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get control endpoint descriptor
|
|
|
|
//
|
2012-02-28 18:54:30 +00:00
|
|
|
m_Hardware->GetControlHeadEndpointDescriptor(&m_ControlHeadEndpointDescriptor);
|
2011-05-23 17:42:52 +00:00
|
|
|
|
2011-05-29 19:54:55 +00:00
|
|
|
//
|
|
|
|
// get isochronous endpoint
|
2011-05-27 13:04:55 +00:00
|
|
|
//
|
2012-02-28 18:54:30 +00:00
|
|
|
m_Hardware->GetIsochronousHeadEndpointDescriptor(&m_IsoHeadEndpointDescriptor);
|
2011-05-27 13:04:55 +00:00
|
|
|
|
2011-05-26 12:37:18 +00:00
|
|
|
//
|
|
|
|
// get interrupt endpoints
|
|
|
|
//
|
2012-02-28 18:54:30 +00:00
|
|
|
m_Hardware->GetInterruptEndpointDescriptors(&m_InterruptEndpoints);
|
2011-05-26 12:37:18 +00:00
|
|
|
|
2011-05-23 17:42:52 +00:00
|
|
|
//
|
|
|
|
// initialize spinlock
|
|
|
|
//
|
|
|
|
KeInitializeSpinLock(&m_Lock);
|
|
|
|
|
2012-02-18 23:23:13 +00:00
|
|
|
//
|
|
|
|
// init list
|
|
|
|
//
|
|
|
|
InitializeListHead(&m_PendingRequestList);
|
|
|
|
|
2011-05-22 19:36:13 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:37:18 +00:00
|
|
|
VOID
|
|
|
|
CUSBQueue::LinkEndpoint(
|
|
|
|
POHCI_ENDPOINT_DESCRIPTOR HeadEndpointDescriptor,
|
|
|
|
POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor)
|
|
|
|
{
|
|
|
|
POHCI_ENDPOINT_DESCRIPTOR CurrentEndpointDescriptor = HeadEndpointDescriptor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get last descriptor in queue
|
|
|
|
//
|
|
|
|
while(CurrentEndpointDescriptor->NextDescriptor)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// move to last descriptor
|
|
|
|
//
|
|
|
|
CurrentEndpointDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)CurrentEndpointDescriptor->NextDescriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// link endpoints
|
|
|
|
//
|
|
|
|
CurrentEndpointDescriptor->NextPhysicalEndpoint = EndpointDescriptor->PhysicalAddress.LowPart;
|
|
|
|
CurrentEndpointDescriptor->NextDescriptor = EndpointDescriptor;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-02-18 23:23:13 +00:00
|
|
|
VOID
|
|
|
|
CUSBQueue::AddEndpointDescriptor(
|
|
|
|
IN POHCI_ENDPOINT_DESCRIPTOR Descriptor)
|
2011-05-22 19:36:13 +00:00
|
|
|
{
|
2012-02-28 18:54:30 +00:00
|
|
|
IOHCIRequest *Request;
|
2011-05-22 19:36:13 +00:00
|
|
|
ULONG Type;
|
2011-05-23 17:42:52 +00:00
|
|
|
POHCI_ENDPOINT_DESCRIPTOR HeadDescriptor;
|
2011-05-27 13:04:55 +00:00
|
|
|
POHCI_ISO_TD CurrentDescriptor;
|
|
|
|
ULONG FrameNumber;
|
2011-05-29 19:54:55 +00:00
|
|
|
USHORT Frame;
|
2011-05-23 17:42:52 +00:00
|
|
|
|
2011-05-22 19:36:13 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
2012-02-18 23:23:13 +00:00
|
|
|
ASSERT(Descriptor->Request);
|
2012-02-28 18:54:30 +00:00
|
|
|
Request = (IOHCIRequest*)Descriptor->Request;
|
2011-05-22 19:36:13 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get request type
|
|
|
|
//
|
|
|
|
Type = Request->GetTransferType();
|
|
|
|
|
2011-05-23 17:42:52 +00:00
|
|
|
//
|
|
|
|
// check type
|
|
|
|
//
|
|
|
|
if (Type == USB_ENDPOINT_TYPE_BULK)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get head descriptor
|
|
|
|
//
|
|
|
|
HeadDescriptor = m_BulkHeadEndpointDescriptor;
|
|
|
|
}
|
|
|
|
else if (Type == USB_ENDPOINT_TYPE_CONTROL)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get head descriptor
|
|
|
|
//
|
|
|
|
HeadDescriptor = m_ControlHeadEndpointDescriptor;
|
|
|
|
}
|
2011-05-26 12:37:18 +00:00
|
|
|
else if (Type == USB_ENDPOINT_TYPE_INTERRUPT)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get head descriptor
|
|
|
|
//
|
|
|
|
HeadDescriptor = FindInterruptEndpointDescriptor(Request->GetInterval());
|
|
|
|
ASSERT(HeadDescriptor);
|
|
|
|
}
|
2011-05-27 13:04:55 +00:00
|
|
|
else if (Type == USB_ENDPOINT_TYPE_ISOCHRONOUS)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get head descriptor
|
|
|
|
//
|
|
|
|
HeadDescriptor = m_IsoHeadEndpointDescriptor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get current frame number
|
|
|
|
//
|
|
|
|
m_Hardware->GetCurrentFrameNumber(&FrameNumber);
|
|
|
|
|
|
|
|
//
|
2011-05-29 19:54:55 +00:00
|
|
|
// FIXME: increment frame number
|
2011-05-27 13:04:55 +00:00
|
|
|
//
|
2011-05-29 19:54:55 +00:00
|
|
|
FrameNumber += 300;
|
2011-05-27 13:04:55 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// apply frame number to iso transfer descriptors
|
|
|
|
//
|
|
|
|
CurrentDescriptor = (POHCI_ISO_TD)Descriptor->HeadLogicalDescriptor;
|
|
|
|
|
2012-02-12 02:53:34 +00:00
|
|
|
DPRINT("ISO: NextFrameNumber %x\n", FrameNumber);
|
2011-05-29 19:54:55 +00:00
|
|
|
Frame = (FrameNumber & 0xFFFF);
|
2011-05-27 13:04:55 +00:00
|
|
|
|
|
|
|
while(CurrentDescriptor)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// set current frame number
|
|
|
|
//
|
2011-05-29 19:54:55 +00:00
|
|
|
CurrentDescriptor->Flags |= OHCI_ITD_SET_STARTING_FRAME(Frame);
|
2011-05-27 13:04:55 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// move to next frame number
|
|
|
|
//
|
2011-05-29 19:54:55 +00:00
|
|
|
Frame += OHCI_ITD_GET_FRAME_COUNT(CurrentDescriptor->Flags);
|
2011-05-27 13:04:55 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// move to next descriptor
|
|
|
|
//
|
|
|
|
CurrentDescriptor = CurrentDescriptor->NextLogicalDescriptor;
|
|
|
|
}
|
2011-05-30 06:55:32 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get current frame number
|
|
|
|
//
|
|
|
|
m_Hardware->GetCurrentFrameNumber(&FrameNumber);
|
|
|
|
|
2012-02-12 02:53:34 +00:00
|
|
|
DPRINT("Hardware 1ms %p Iso %p\n",m_InterruptEndpoints[0], m_IsoHeadEndpointDescriptor);
|
2012-02-13 13:39:20 +00:00
|
|
|
ASSERT(m_InterruptEndpoints[0]->NextPhysicalEndpoint == m_IsoHeadEndpointDescriptor->PhysicalAddress.LowPart);
|
2011-05-30 06:55:32 +00:00
|
|
|
|
|
|
|
PrintEndpointList(m_IsoHeadEndpointDescriptor);
|
2011-05-27 13:04:55 +00:00
|
|
|
}
|
2012-01-20 23:19:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// bad request type
|
|
|
|
//
|
2012-02-18 23:23:13 +00:00
|
|
|
ASSERT(FALSE);
|
|
|
|
return;
|
2012-01-20 23:19:18 +00:00
|
|
|
}
|
2011-05-23 17:42:52 +00:00
|
|
|
|
|
|
|
//
|
2011-05-29 19:54:55 +00:00
|
|
|
// set descriptor active
|
2011-05-23 17:42:52 +00:00
|
|
|
//
|
2011-05-29 19:54:55 +00:00
|
|
|
Descriptor->Flags &= ~OHCI_ENDPOINT_SKIP;
|
2011-05-23 17:42:52 +00:00
|
|
|
|
|
|
|
//
|
2011-05-29 19:54:55 +00:00
|
|
|
// insert endpoint at end
|
2011-05-23 17:42:52 +00:00
|
|
|
//
|
2011-05-29 19:54:55 +00:00
|
|
|
LinkEndpoint(HeadDescriptor, Descriptor);
|
2011-05-23 17:42:52 +00:00
|
|
|
|
2011-05-26 12:37:18 +00:00
|
|
|
if (Type == USB_ENDPOINT_TYPE_CONTROL || Type == USB_ENDPOINT_TYPE_BULK)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// notify hardware of our request
|
|
|
|
//
|
|
|
|
m_Hardware->HeadEndpointDescriptorModified(Type);
|
|
|
|
}
|
2012-02-18 23:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
2012-02-29 09:15:42 +00:00
|
|
|
STDMETHODCALLTYPE
|
2012-02-18 23:23:13 +00:00
|
|
|
CUSBQueue::AddUSBRequest(
|
2012-02-28 18:54:30 +00:00
|
|
|
IUSBRequest * Req)
|
2012-02-18 23:23:13 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
IN POHCI_ENDPOINT_DESCRIPTOR Descriptor;
|
2012-02-28 18:54:30 +00:00
|
|
|
POHCIREQUEST Request;
|
2012-02-18 23:23:13 +00:00
|
|
|
|
|
|
|
DPRINT("CUSBQueue::AddUSBRequest\n");
|
|
|
|
|
2012-02-28 18:54:30 +00:00
|
|
|
// get request
|
|
|
|
Request = POHCIREQUEST(Req);
|
|
|
|
|
|
|
|
|
2012-02-18 23:23:13 +00:00
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(Request != NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// add extra reference which is released when the request is completed
|
|
|
|
//
|
|
|
|
Request->AddRef();
|
|
|
|
|
|
|
|
//
|
|
|
|
// get transfer descriptors
|
|
|
|
//
|
|
|
|
Status = Request->GetEndpointDescriptor(&Descriptor);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed to get transfer descriptor
|
|
|
|
//
|
|
|
|
DPRINT1("CUSBQueue::AddUSBRequest GetEndpointDescriptor failed with %x\n", Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// release reference
|
|
|
|
//
|
|
|
|
Request->Release();
|
|
|
|
return Status;
|
|
|
|
}
|
2011-05-22 19:36:13 +00:00
|
|
|
|
2012-02-18 23:23:13 +00:00
|
|
|
//
|
|
|
|
// add the request
|
|
|
|
//
|
|
|
|
AddEndpointDescriptor(Descriptor);
|
2011-05-22 19:36:13 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
2012-02-29 09:15:42 +00:00
|
|
|
STDMETHODCALLTYPE
|
2011-05-22 19:36:13 +00:00
|
|
|
CUSBQueue::CreateUSBRequest(
|
|
|
|
IUSBRequest **OutRequest)
|
|
|
|
{
|
|
|
|
PUSBREQUEST UsbRequest;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
*OutRequest = NULL;
|
|
|
|
Status = InternalCreateUSBRequest(&UsbRequest);
|
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
*OutRequest = UsbRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2011-05-24 17:57:00 +00:00
|
|
|
NTSTATUS
|
|
|
|
CUSBQueue::FindTransferDescriptorInEndpoint(
|
|
|
|
IN POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor,
|
|
|
|
IN ULONG TransferDescriptorLogicalAddress,
|
|
|
|
OUT POHCI_ENDPOINT_DESCRIPTOR *OutEndpointDescriptor,
|
|
|
|
OUT POHCI_ENDPOINT_DESCRIPTOR *OutPreviousEndpointDescriptor)
|
|
|
|
{
|
|
|
|
POHCI_ENDPOINT_DESCRIPTOR LastDescriptor = EndpointDescriptor;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// skip first endpoint head
|
|
|
|
//
|
|
|
|
EndpointDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)EndpointDescriptor->NextDescriptor;
|
|
|
|
|
|
|
|
while(EndpointDescriptor)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// check if the transfer descriptor is inside the list
|
|
|
|
//
|
2012-02-03 09:52:29 +00:00
|
|
|
if ((EndpointDescriptor->HeadPhysicalDescriptor & OHCI_ENDPOINT_HEAD_MASK) == EndpointDescriptor->TailPhysicalDescriptor || (EndpointDescriptor->HeadPhysicalDescriptor & OHCI_ENDPOINT_HALTED))
|
2011-05-24 17:57:00 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// found endpoint
|
|
|
|
//
|
|
|
|
*OutEndpointDescriptor = EndpointDescriptor;
|
|
|
|
*OutPreviousEndpointDescriptor = LastDescriptor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// store last endpoint
|
|
|
|
//
|
|
|
|
LastDescriptor = EndpointDescriptor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// move to next
|
|
|
|
//
|
|
|
|
EndpointDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)EndpointDescriptor->NextDescriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// failed to endpoint
|
|
|
|
//
|
|
|
|
return STATUS_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:37:18 +00:00
|
|
|
NTSTATUS
|
|
|
|
CUSBQueue::FindTransferDescriptorInInterruptHeadEndpoints(IN ULONG TransferDescriptorLogicalAddress, OUT POHCI_ENDPOINT_DESCRIPTOR *OutEndpointDescriptor, OUT POHCI_ENDPOINT_DESCRIPTOR *OutPreviousEndpointDescriptor)
|
|
|
|
{
|
|
|
|
ULONG Index;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
//
|
|
|
|
// search descriptor in endpoint list
|
|
|
|
//
|
|
|
|
for(Index = 0; Index < OHCI_STATIC_ENDPOINT_COUNT; Index++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// is it in current endpoint
|
|
|
|
//
|
|
|
|
Status = FindTransferDescriptorInEndpoint(m_InterruptEndpoints[Index], TransferDescriptorLogicalAddress, OutEndpointDescriptor, OutPreviousEndpointDescriptor);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// found transfer descriptor
|
|
|
|
//
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// not found
|
|
|
|
//
|
|
|
|
return STATUS_NOT_FOUND;
|
|
|
|
}
|
2011-05-24 17:57:00 +00:00
|
|
|
|
2011-05-29 19:54:55 +00:00
|
|
|
NTSTATUS
|
|
|
|
CUSBQueue::FindTransferDescriptorInIsochronousHeadEndpoints(
|
|
|
|
IN ULONG TransferDescriptorLogicalAddress,
|
|
|
|
OUT POHCI_ENDPOINT_DESCRIPTOR *OutEndpointDescriptor,
|
|
|
|
OUT POHCI_ENDPOINT_DESCRIPTOR *OutPreviousEndpointDescriptor)
|
|
|
|
{
|
|
|
|
POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor;
|
|
|
|
POHCI_ENDPOINT_DESCRIPTOR LastDescriptor = m_IsoHeadEndpointDescriptor;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// skip first endpoint head
|
|
|
|
//
|
|
|
|
EndpointDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)m_IsoHeadEndpointDescriptor->NextDescriptor;
|
|
|
|
|
|
|
|
while(EndpointDescriptor)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// check if the transfer descriptor is inside the list
|
|
|
|
//
|
|
|
|
if (IsTransferDescriptorInIsoEndpoint(EndpointDescriptor, TransferDescriptorLogicalAddress))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// found endpoint
|
|
|
|
//
|
|
|
|
*OutEndpointDescriptor = EndpointDescriptor;
|
|
|
|
*OutPreviousEndpointDescriptor = LastDescriptor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// store last endpoint
|
|
|
|
//
|
|
|
|
LastDescriptor = EndpointDescriptor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// move to next
|
|
|
|
//
|
|
|
|
EndpointDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)EndpointDescriptor->NextDescriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// failed to endpoint
|
|
|
|
//
|
|
|
|
return STATUS_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
CUSBQueue::IsTransferDescriptorInIsoEndpoint(
|
|
|
|
IN POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor,
|
|
|
|
IN ULONG TransferDescriptorLogicalAddress)
|
|
|
|
{
|
|
|
|
POHCI_ISO_TD Descriptor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get first general transfer descriptor
|
|
|
|
//
|
|
|
|
Descriptor = (POHCI_ISO_TD)EndpointDescriptor->HeadLogicalDescriptor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(Descriptor);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (Descriptor->PhysicalAddress.LowPart == TransferDescriptorLogicalAddress)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// found descriptor
|
|
|
|
//
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// move to next
|
|
|
|
//
|
|
|
|
Descriptor = (POHCI_ISO_TD)Descriptor->NextLogicalDescriptor;
|
|
|
|
}while(Descriptor);
|
|
|
|
|
|
|
|
//
|
|
|
|
// no descriptor found
|
|
|
|
//
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 17:57:00 +00:00
|
|
|
BOOLEAN
|
|
|
|
CUSBQueue::IsTransferDescriptorInEndpoint(
|
|
|
|
IN POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor,
|
|
|
|
IN ULONG TransferDescriptorLogicalAddress)
|
|
|
|
{
|
|
|
|
POHCI_GENERAL_TD Descriptor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get first general transfer descriptor
|
|
|
|
//
|
|
|
|
Descriptor = (POHCI_GENERAL_TD)EndpointDescriptor->HeadLogicalDescriptor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(Descriptor);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (Descriptor->PhysicalAddress.LowPart == TransferDescriptorLogicalAddress)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// found descriptor
|
|
|
|
//
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// move to next
|
|
|
|
//
|
|
|
|
Descriptor = (POHCI_GENERAL_TD)Descriptor->NextLogicalDescriptor;
|
|
|
|
}while(Descriptor);
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// no descriptor found
|
|
|
|
//
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-05-26 02:15:11 +00:00
|
|
|
VOID
|
|
|
|
CUSBQueue::CleanupEndpointDescriptor(
|
|
|
|
POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor,
|
|
|
|
POHCI_ENDPOINT_DESCRIPTOR PreviousEndpointDescriptor)
|
|
|
|
{
|
2012-02-28 18:54:30 +00:00
|
|
|
POHCIREQUEST Request;
|
2012-02-18 23:23:13 +00:00
|
|
|
POHCI_ENDPOINT_DESCRIPTOR NewEndpointDescriptor;
|
|
|
|
USBD_STATUS UrbStatus;
|
|
|
|
KIRQL OldLevel;
|
2011-05-26 02:15:11 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// FIXME: verify unlinking process
|
|
|
|
//
|
|
|
|
PreviousEndpointDescriptor->NextDescriptor = EndpointDescriptor->NextDescriptor;
|
|
|
|
PreviousEndpointDescriptor->NextPhysicalEndpoint = EndpointDescriptor->NextPhysicalEndpoint;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get corresponding request
|
|
|
|
//
|
2012-02-28 18:54:30 +00:00
|
|
|
Request = POHCIREQUEST(EndpointDescriptor->Request);
|
2011-05-26 02:15:11 +00:00
|
|
|
ASSERT(Request);
|
|
|
|
|
|
|
|
//
|
2012-02-18 23:23:13 +00:00
|
|
|
// check for errors
|
|
|
|
//
|
|
|
|
if (EndpointDescriptor->HeadPhysicalDescriptor & OHCI_ENDPOINT_HALTED)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// the real error will processed by IUSBRequest
|
|
|
|
//
|
|
|
|
UrbStatus = USBD_STATUS_STALL_PID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// well done ;)
|
|
|
|
//
|
|
|
|
UrbStatus = USBD_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check if the transfer was completed and if UrbStatus is ok
|
2011-05-26 02:15:11 +00:00
|
|
|
//
|
2012-02-18 23:23:13 +00:00
|
|
|
if ((Request->IsRequestComplete() == FALSE) && (UrbStatus == USBD_STATUS_SUCCESS))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// request is incomplete, get new queue head
|
|
|
|
//
|
|
|
|
if (Request->GetEndpointDescriptor(&NewEndpointDescriptor) == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// notify of completion
|
|
|
|
//
|
|
|
|
Request->FreeEndpointDescriptor(EndpointDescriptor);
|
|
|
|
|
|
|
|
//
|
|
|
|
// first acquire request lock
|
|
|
|
//
|
|
|
|
KeAcquireSpinLock(&m_Lock, &OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// add to pending list
|
|
|
|
//
|
|
|
|
InsertTailList(&m_PendingRequestList, &NewEndpointDescriptor->DescriptorListEntry);
|
|
|
|
|
|
|
|
//
|
|
|
|
// release queue head
|
|
|
|
//
|
|
|
|
KeReleaseSpinLock(&m_Lock, OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Done for now
|
|
|
|
//
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DPRINT1("Unable to create a new QueueHead\n");
|
|
|
|
//ASSERT(FALSE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Else there was a problem
|
|
|
|
// FIXME: Find better return
|
|
|
|
UrbStatus = USBD_STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UrbStatus != USBD_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
DPRINT1("URB failed with status 0x%x\n", UrbStatus);
|
|
|
|
//PC_ASSERT(FALSE);
|
|
|
|
}
|
2011-05-26 02:15:11 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// free endpoint descriptor
|
|
|
|
//
|
|
|
|
Request->FreeEndpointDescriptor(EndpointDescriptor);
|
|
|
|
|
2012-02-18 23:23:13 +00:00
|
|
|
//
|
|
|
|
// notify of completion
|
|
|
|
//
|
|
|
|
Request->CompletionCallback();
|
|
|
|
|
|
|
|
|
2011-05-26 02:15:11 +00:00
|
|
|
//
|
|
|
|
// release request
|
|
|
|
//
|
|
|
|
Request->Release();
|
|
|
|
}
|
2012-02-18 23:23:13 +00:00
|
|
|
|
2011-05-26 12:37:18 +00:00
|
|
|
VOID
|
|
|
|
CUSBQueue::PrintEndpointList(
|
|
|
|
POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor)
|
|
|
|
{
|
|
|
|
DPRINT1("CUSBQueue::PrintEndpointList HeadEndpoint %p Logical %x\n", EndpointDescriptor, EndpointDescriptor->PhysicalAddress.LowPart);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get first general transfer descriptor
|
|
|
|
//
|
|
|
|
EndpointDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)EndpointDescriptor->NextDescriptor;
|
2011-05-26 02:15:11 +00:00
|
|
|
|
2011-05-26 12:37:18 +00:00
|
|
|
while(EndpointDescriptor)
|
|
|
|
{
|
|
|
|
DPRINT1(" CUSBQueue::PrintEndpointList Endpoint %p Logical %x\n", EndpointDescriptor, EndpointDescriptor->PhysicalAddress.LowPart);
|
|
|
|
|
|
|
|
//
|
|
|
|
// move to next
|
|
|
|
//
|
|
|
|
EndpointDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)EndpointDescriptor->NextDescriptor;
|
|
|
|
}
|
|
|
|
}
|
2011-05-24 17:57:00 +00:00
|
|
|
|
|
|
|
VOID
|
2012-02-29 09:15:42 +00:00
|
|
|
STDMETHODCALLTYPE
|
2011-05-24 17:57:00 +00:00
|
|
|
CUSBQueue::TransferDescriptorCompletionCallback(
|
|
|
|
ULONG TransferDescriptorLogicalAddress)
|
|
|
|
{
|
|
|
|
POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor, PreviousEndpointDescriptor;
|
2012-02-18 23:23:13 +00:00
|
|
|
PLIST_ENTRY Entry;
|
2011-05-24 17:57:00 +00:00
|
|
|
NTSTATUS Status;
|
2011-05-26 02:15:11 +00:00
|
|
|
|
2011-12-29 10:13:36 +00:00
|
|
|
DPRINT("CUSBQueue::TransferDescriptorCompletionCallback transfer descriptor %x\n", TransferDescriptorLogicalAddress);
|
2011-05-24 17:57:00 +00:00
|
|
|
|
2012-02-05 15:36:00 +00:00
|
|
|
do
|
2011-05-24 17:57:00 +00:00
|
|
|
{
|
|
|
|
//
|
2012-02-05 15:36:00 +00:00
|
|
|
// find transfer descriptor in control list
|
2011-05-24 17:57:00 +00:00
|
|
|
//
|
2012-02-05 15:36:00 +00:00
|
|
|
Status = FindTransferDescriptorInEndpoint(m_ControlHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// cleanup endpoint
|
|
|
|
//
|
|
|
|
CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor);
|
2011-05-24 17:57:00 +00:00
|
|
|
|
2012-02-05 15:36:00 +00:00
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
continue;
|
|
|
|
}
|
2011-05-24 17:57:00 +00:00
|
|
|
|
|
|
|
//
|
2012-02-05 15:36:00 +00:00
|
|
|
// find transfer descriptor in bulk list
|
2011-05-24 17:57:00 +00:00
|
|
|
//
|
2012-02-05 15:36:00 +00:00
|
|
|
Status = FindTransferDescriptorInEndpoint(m_BulkHeadEndpointDescriptor, TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// cleanup endpoint
|
|
|
|
//
|
|
|
|
CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor);
|
2011-05-24 17:57:00 +00:00
|
|
|
|
2012-02-05 15:36:00 +00:00
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
continue;
|
|
|
|
}
|
2011-05-24 17:57:00 +00:00
|
|
|
|
2011-05-26 12:37:18 +00:00
|
|
|
//
|
2012-02-05 15:36:00 +00:00
|
|
|
// find transfer descriptor in interrupt list
|
2011-05-26 12:37:18 +00:00
|
|
|
//
|
2012-02-05 15:36:00 +00:00
|
|
|
Status = FindTransferDescriptorInInterruptHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// cleanup endpoint
|
|
|
|
//
|
|
|
|
CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor);
|
2011-05-26 12:37:18 +00:00
|
|
|
|
2012-02-05 15:36:00 +00:00
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
continue;
|
|
|
|
}
|
2011-05-26 12:37:18 +00:00
|
|
|
|
2011-05-29 19:54:55 +00:00
|
|
|
//
|
2012-02-05 15:36:00 +00:00
|
|
|
// last try: find the descriptor in isochronous list
|
2011-05-29 19:54:55 +00:00
|
|
|
//
|
2012-02-05 15:36:00 +00:00
|
|
|
Status = FindTransferDescriptorInIsochronousHeadEndpoints(TransferDescriptorLogicalAddress, &EndpointDescriptor, &PreviousEndpointDescriptor);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// cleanup endpoint
|
|
|
|
//
|
2012-02-12 02:53:34 +00:00
|
|
|
DPRINT("ISO endpoint complete\n");
|
|
|
|
//ASSERT(FALSE);
|
2012-02-05 15:36:00 +00:00
|
|
|
CleanupEndpointDescriptor(EndpointDescriptor, PreviousEndpointDescriptor);
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
continue;
|
|
|
|
}
|
2011-05-29 19:54:55 +00:00
|
|
|
|
|
|
|
//
|
2012-02-05 15:36:00 +00:00
|
|
|
// no more completed descriptors found
|
2011-05-29 19:54:55 +00:00
|
|
|
//
|
2012-02-18 23:23:13 +00:00
|
|
|
break;
|
2012-02-05 15:36:00 +00:00
|
|
|
|
|
|
|
}while(TRUE);
|
2011-05-26 12:37:18 +00:00
|
|
|
|
2012-02-18 23:23:13 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// acquire spin lock
|
|
|
|
//
|
|
|
|
KeAcquireSpinLockAtDpcLevel(&m_Lock);
|
|
|
|
|
|
|
|
//
|
|
|
|
// is there a pending list item
|
|
|
|
//
|
|
|
|
if (!IsListEmpty(&m_PendingRequestList))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get list entry
|
|
|
|
//
|
|
|
|
Entry = RemoveHeadList(&m_PendingRequestList);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get entry
|
|
|
|
//
|
|
|
|
EndpointDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)CONTAINING_RECORD(Entry, OHCI_ENDPOINT_DESCRIPTOR, DescriptorListEntry);
|
|
|
|
|
|
|
|
//
|
|
|
|
// add entry
|
|
|
|
//
|
|
|
|
AddEndpointDescriptor(EndpointDescriptor);
|
|
|
|
}
|
|
|
|
|
2011-05-26 02:15:11 +00:00
|
|
|
//
|
2012-02-18 23:23:13 +00:00
|
|
|
// release lock
|
2011-05-26 02:15:11 +00:00
|
|
|
//
|
2012-02-18 23:23:13 +00:00
|
|
|
KeReleaseSpinLockFromDpcLevel(&m_Lock);
|
2011-05-24 17:57:00 +00:00
|
|
|
}
|
|
|
|
|
2011-05-26 12:37:18 +00:00
|
|
|
POHCI_ENDPOINT_DESCRIPTOR
|
|
|
|
CUSBQueue::FindInterruptEndpointDescriptor(
|
|
|
|
UCHAR InterruptInterval)
|
|
|
|
{
|
|
|
|
ULONG Index = 0;
|
|
|
|
ULONG Power = 1;
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
2011-05-30 06:55:32 +00:00
|
|
|
ASSERT(InterruptInterval <= OHCI_BIGGEST_INTERVAL);
|
2011-05-26 12:37:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// find interrupt index
|
|
|
|
//
|
|
|
|
while (Power <= OHCI_BIGGEST_INTERVAL / 2)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// is current interval greater
|
|
|
|
//
|
|
|
|
if (Power * 2 > InterruptInterval)
|
|
|
|
break;
|
|
|
|
|
|
|
|
//
|
|
|
|
// increment power
|
|
|
|
//
|
|
|
|
Power *= 2;
|
|
|
|
|
|
|
|
//
|
|
|
|
// move to next interrupt
|
|
|
|
//
|
|
|
|
Index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("InterruptInterval %lu Selected InterruptIndex %lu Choosen Interval %lu\n", InterruptInterval, Index, Power);
|
|
|
|
|
|
|
|
//
|
|
|
|
// return endpoint
|
|
|
|
//
|
|
|
|
return m_InterruptEndpoints[Index];
|
|
|
|
}
|
2011-05-22 19:36:13 +00:00
|
|
|
|
2012-02-03 14:47:18 +00:00
|
|
|
NTSTATUS
|
2012-02-29 09:15:42 +00:00
|
|
|
STDMETHODCALLTYPE
|
2012-02-03 14:47:18 +00:00
|
|
|
CUSBQueue::AbortDevicePipe(
|
|
|
|
IN UCHAR DeviceAddress,
|
|
|
|
IN PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor)
|
|
|
|
{
|
|
|
|
POHCI_ENDPOINT_DESCRIPTOR HeadDescriptor, CurrentDescriptor, PreviousDescriptor, TempDescriptor;
|
|
|
|
ULONG Type;
|
|
|
|
POHCI_GENERAL_TD TransferDescriptor;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get type
|
|
|
|
//
|
|
|
|
Type = (EndpointDescriptor->bmAttributes & USB_ENDPOINT_TYPE_MASK);
|
|
|
|
|
|
|
|
//
|
|
|
|
// check type
|
|
|
|
//
|
|
|
|
if (Type == USB_ENDPOINT_TYPE_BULK)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get head descriptor
|
|
|
|
//
|
|
|
|
HeadDescriptor = m_BulkHeadEndpointDescriptor;
|
|
|
|
}
|
|
|
|
else if (Type == USB_ENDPOINT_TYPE_CONTROL)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get head descriptor
|
|
|
|
//
|
|
|
|
HeadDescriptor = m_ControlHeadEndpointDescriptor;
|
|
|
|
}
|
|
|
|
else if (Type == USB_ENDPOINT_TYPE_INTERRUPT)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get head descriptor
|
|
|
|
//
|
|
|
|
HeadDescriptor = FindInterruptEndpointDescriptor(EndpointDescriptor->bInterval);
|
|
|
|
ASSERT(HeadDescriptor);
|
|
|
|
}
|
2012-02-18 23:23:13 +00:00
|
|
|
else
|
2012-02-03 14:47:18 +00:00
|
|
|
{
|
2012-02-18 23:23:13 +00:00
|
|
|
//
|
|
|
|
// IMPLEMENT me
|
|
|
|
//
|
|
|
|
ASSERT(Type == USB_ENDPOINT_TYPE_ISOCHRONOUS);
|
2012-02-03 14:47:18 +00:00
|
|
|
UNIMPLEMENTED
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FIXME should disable list processing
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// now remove all endpoints
|
|
|
|
//
|
|
|
|
ASSERT(HeadDescriptor);
|
|
|
|
CurrentDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)HeadDescriptor->NextDescriptor;
|
|
|
|
PreviousDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)HeadDescriptor;
|
|
|
|
|
|
|
|
while(CurrentDescriptor)
|
|
|
|
{
|
|
|
|
if ((CurrentDescriptor->HeadPhysicalDescriptor & OHCI_ENDPOINT_HEAD_MASK) == CurrentDescriptor->TailPhysicalDescriptor || (CurrentDescriptor->HeadPhysicalDescriptor & OHCI_ENDPOINT_HALTED))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// cleanup endpoint
|
|
|
|
//
|
|
|
|
TempDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)CurrentDescriptor->NextDescriptor;
|
|
|
|
CleanupEndpointDescriptor(CurrentDescriptor, PreviousDescriptor);
|
|
|
|
|
|
|
|
//
|
|
|
|
// use next descriptor
|
|
|
|
//
|
|
|
|
CurrentDescriptor = TempDescriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CurrentDescriptor)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (CurrentDescriptor->HeadPhysicalDescriptor)
|
|
|
|
{
|
|
|
|
TransferDescriptor = (POHCI_GENERAL_TD)CurrentDescriptor->HeadLogicalDescriptor;
|
|
|
|
ASSERT(TransferDescriptor);
|
|
|
|
|
|
|
|
if ((OHCI_ENDPOINT_GET_ENDPOINT_NUMBER(TransferDescriptor->Flags) == (EndpointDescriptor->bEndpointAddress & 0xF)) &&
|
|
|
|
(OHCI_ENDPOINT_GET_DEVICE_ADDRESS(TransferDescriptor->Flags) == DeviceAddress))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// cleanup endpoint
|
|
|
|
//
|
|
|
|
TempDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)CurrentDescriptor->NextDescriptor;
|
|
|
|
CleanupEndpointDescriptor(CurrentDescriptor, PreviousDescriptor);
|
|
|
|
//
|
|
|
|
// use next descriptor
|
|
|
|
//
|
|
|
|
CurrentDescriptor = TempDescriptor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CurrentDescriptor)
|
|
|
|
break;
|
|
|
|
|
|
|
|
PreviousDescriptor = CurrentDescriptor;
|
|
|
|
CurrentDescriptor = (POHCI_ENDPOINT_DESCRIPTOR)CurrentDescriptor->NextDescriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-22 19:36:13 +00:00
|
|
|
NTSTATUS
|
2012-02-29 09:15:42 +00:00
|
|
|
NTAPI
|
2011-05-22 19:36:13 +00:00
|
|
|
CreateUSBQueue(
|
|
|
|
PUSBQUEUE *OutUsbQueue)
|
|
|
|
{
|
|
|
|
PUSBQUEUE This;
|
|
|
|
|
|
|
|
//
|
|
|
|
// allocate controller
|
|
|
|
//
|
|
|
|
This = new(NonPagedPool, TAG_USBOHCI) CUSBQueue(0);
|
|
|
|
if (!This)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed to allocate
|
|
|
|
//
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// add reference count
|
|
|
|
//
|
|
|
|
This->AddRef();
|
|
|
|
|
|
|
|
//
|
|
|
|
// return result
|
|
|
|
//
|
|
|
|
*OutUsbQueue = (PUSBQUEUE)This;
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|