2012-02-21 15:49:08 +00:00
|
|
|
/*
|
2012-02-23 01:27:19 +00:00
|
|
|
* PROJECT: ReactOS Universal Serial Bus Host Controller Interface
|
2012-02-21 15:49:08 +00:00
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2012-02-23 01:27:19 +00:00
|
|
|
* FILE: drivers/usb/usbuhci/usb_queue.cpp
|
|
|
|
* PURPOSE: USB UHCI device driver.
|
2012-02-21 15:49:08 +00:00
|
|
|
* PROGRAMMERS:
|
|
|
|
* Michael Martin (michael.martin@reactos.org)
|
|
|
|
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "usbuhci.h"
|
2013-12-24 20:54:29 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
2012-02-21 15:49:08 +00:00
|
|
|
|
2012-02-28 22:09:57 +00:00
|
|
|
class CUSBQueue : public IUHCIQueue
|
2012-02-21 15:49:08 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// com
|
2012-02-28 22:09:57 +00:00
|
|
|
IMP_IUSBQUEUE
|
|
|
|
IMP_IUHCIQUEUE
|
2012-02-21 15:49:08 +00:00
|
|
|
|
2012-02-21 18:19:24 +00:00
|
|
|
// local
|
|
|
|
VOID LinkQueueHead(PUHCI_QUEUE_HEAD QueueHead, PUHCI_QUEUE_HEAD NextQueueHead);
|
2012-02-22 17:24:43 +00:00
|
|
|
VOID UnLinkQueueHead(PUHCI_QUEUE_HEAD PreviousQueueHead, PUHCI_QUEUE_HEAD NextQueueHead);
|
|
|
|
BOOLEAN IsQueueHeadComplete(PUHCI_QUEUE_HEAD QueueHead);
|
|
|
|
NTSTATUS AddQueueHead(PUHCI_QUEUE_HEAD NewQueueHead);
|
|
|
|
VOID QueueHeadCleanup(IN PUHCI_QUEUE_HEAD QueueHead, IN PUHCI_QUEUE_HEAD PreviousQueueHead, OUT PUHCI_QUEUE_HEAD *NextQueueHead);
|
|
|
|
|
2012-02-21 18:19:24 +00:00
|
|
|
|
2012-02-21 15:49:08 +00:00
|
|
|
// constructor / destructor
|
|
|
|
CUSBQueue(IUnknown *OuterUnknown){}
|
|
|
|
virtual ~CUSBQueue(){}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
LONG m_Ref; // reference count
|
|
|
|
KSPIN_LOCK m_Lock; // list lock
|
2012-02-28 22:09:57 +00:00
|
|
|
PUHCIHARDWAREDEVICE m_Hardware; // hardware
|
2012-02-22 17:24:43 +00:00
|
|
|
|
2012-02-21 15:49:08 +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
|
|
|
|
CUSBQueue::Initialize(
|
|
|
|
IN PUSBHARDWAREDEVICE Hardware,
|
|
|
|
IN PDMA_ADAPTER AdapterObject,
|
|
|
|
IN PDMAMEMORYMANAGER MemManager,
|
|
|
|
IN OPTIONAL PKSPIN_LOCK Lock)
|
|
|
|
{
|
|
|
|
|
|
|
|
//
|
|
|
|
// store hardware
|
|
|
|
//
|
2012-02-28 22:09:57 +00:00
|
|
|
m_Hardware = PUHCIHARDWAREDEVICE(Hardware);
|
2012-02-21 15:49:08 +00:00
|
|
|
|
|
|
|
//
|
2012-02-28 22:09:57 +00:00
|
|
|
// initialize spinlock
|
2012-02-21 15:49:08 +00:00
|
|
|
//
|
2012-02-28 22:09:57 +00:00
|
|
|
KeInitializeSpinLock(&m_Lock);
|
|
|
|
return STATUS_SUCCESS;
|
2012-02-21 15:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
2012-02-22 17:24:43 +00:00
|
|
|
CUSBQueue::AddQueueHead(
|
|
|
|
PUHCI_QUEUE_HEAD NewQueueHead)
|
2012-02-21 15:49:08 +00:00
|
|
|
{
|
2012-02-28 22:09:57 +00:00
|
|
|
PUHCIREQUEST Request;
|
2012-02-22 17:24:43 +00:00
|
|
|
PUHCI_QUEUE_HEAD QueueHead = NULL;
|
2012-02-21 18:19:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
2012-02-22 17:24:43 +00:00
|
|
|
// get request
|
2012-02-21 18:19:24 +00:00
|
|
|
//
|
2012-02-28 22:09:57 +00:00
|
|
|
Request = (PUHCIREQUEST)NewQueueHead->Request;
|
2012-02-22 17:24:43 +00:00
|
|
|
if (!Request)
|
2012-02-21 18:19:24 +00:00
|
|
|
{
|
|
|
|
//
|
2012-02-22 17:24:43 +00:00
|
|
|
// no request
|
2012-02-21 18:19:24 +00:00
|
|
|
//
|
2012-02-22 17:24:43 +00:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2012-02-21 18:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Request->GetTransferType() == USB_ENDPOINT_TYPE_CONTROL)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get device speed
|
|
|
|
//
|
|
|
|
if (Request->GetDeviceSpeed() == UsbLowSpeed)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// use low speed queue
|
|
|
|
//
|
|
|
|
m_Hardware->GetQueueHead(UHCI_LOW_SPEED_CONTROL_QUEUE, &QueueHead);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// use full speed queue
|
|
|
|
//
|
|
|
|
m_Hardware->GetQueueHead(UHCI_FULL_SPEED_CONTROL_QUEUE, &QueueHead);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Request->GetTransferType() == USB_ENDPOINT_TYPE_BULK)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// use full speed queue
|
|
|
|
//
|
|
|
|
m_Hardware->GetQueueHead(UHCI_BULK_QUEUE, &QueueHead);
|
|
|
|
}
|
|
|
|
else if (Request->GetTransferType() == USB_ENDPOINT_TYPE_INTERRUPT)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// use full speed queue
|
|
|
|
//
|
|
|
|
m_Hardware->GetQueueHead(UHCI_INTERRUPT_QUEUE, &QueueHead);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FIXME support isochronous
|
|
|
|
//
|
|
|
|
ASSERT(QueueHead);
|
|
|
|
|
|
|
|
//
|
|
|
|
// add reference
|
|
|
|
//
|
|
|
|
Request->AddRef();
|
|
|
|
|
|
|
|
//
|
|
|
|
// now link the new queue head
|
|
|
|
//
|
|
|
|
LinkQueueHead(QueueHead, NewQueueHead);
|
2012-02-21 15:49:08 +00:00
|
|
|
return STATUS_SUCCESS;
|
2012-02-22 17:24:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
CUSBQueue::AddUSBRequest(
|
2012-02-28 22:09:57 +00:00
|
|
|
IUSBRequest * Req)
|
2012-02-22 17:24:43 +00:00
|
|
|
{
|
|
|
|
PUHCI_QUEUE_HEAD NewQueueHead;
|
|
|
|
NTSTATUS Status;
|
2012-02-28 22:09:57 +00:00
|
|
|
PUHCIREQUEST Request;
|
|
|
|
|
|
|
|
// get request
|
|
|
|
Request = (PUHCIREQUEST)Req;
|
2012-02-22 17:24:43 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get queue head
|
|
|
|
//
|
|
|
|
Status = Request->GetEndpointDescriptor(&NewQueueHead);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed to create queue head
|
|
|
|
//
|
|
|
|
DPRINT1("[USBUHCI] Failed to create queue head %x\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(PVOID(Request) == NewQueueHead->Request);
|
|
|
|
|
|
|
|
//
|
|
|
|
// add queue head
|
|
|
|
//
|
2012-02-22 23:24:53 +00:00
|
|
|
DPRINT("AddUSBRequest Request %p\n", Request);
|
|
|
|
DPRINT("NewQueueHead %p\n", NewQueueHead);
|
2012-02-22 17:24:43 +00:00
|
|
|
return AddQueueHead(NewQueueHead);
|
2012-02-21 15:49:08 +00:00
|
|
|
}
|
|
|
|
|
2012-02-21 18:19:24 +00:00
|
|
|
VOID
|
|
|
|
CUSBQueue::LinkQueueHead(
|
|
|
|
IN PUHCI_QUEUE_HEAD QueueHead,
|
|
|
|
IN PUHCI_QUEUE_HEAD NextQueueHead)
|
|
|
|
{
|
|
|
|
NextQueueHead->LinkPhysical = QueueHead->LinkPhysical;
|
|
|
|
NextQueueHead->NextLogicalDescriptor = QueueHead->NextLogicalDescriptor;
|
|
|
|
|
|
|
|
QueueHead->LinkPhysical = NextQueueHead->PhysicalAddress | QH_NEXT_IS_QH;
|
|
|
|
QueueHead->NextLogicalDescriptor = (PVOID)NextQueueHead;
|
|
|
|
}
|
|
|
|
|
2012-02-22 17:24:43 +00:00
|
|
|
|
|
|
|
VOID
|
|
|
|
CUSBQueue::UnLinkQueueHead(
|
|
|
|
PUHCI_QUEUE_HEAD QueueHeadToRemove,
|
|
|
|
PUHCI_QUEUE_HEAD PreviousQueueHead)
|
|
|
|
{
|
|
|
|
PreviousQueueHead->LinkPhysical = QueueHeadToRemove->LinkPhysical;
|
|
|
|
PreviousQueueHead->NextLogicalDescriptor = QueueHeadToRemove->NextLogicalDescriptor;
|
|
|
|
}
|
|
|
|
|
2012-02-21 23:18:46 +00:00
|
|
|
NTSTATUS
|
|
|
|
CUSBQueue::AbortDevicePipe(
|
|
|
|
IN UCHAR DeviceAddress,
|
2012-02-28 22:09:57 +00:00
|
|
|
IN PUSB_ENDPOINT_DESCRIPTOR EndDescriptor)
|
2012-02-21 23:18:46 +00:00
|
|
|
{
|
2012-02-22 23:24:53 +00:00
|
|
|
KIRQL OldLevel;
|
|
|
|
PUHCI_TRANSFER_DESCRIPTOR Descriptor;
|
|
|
|
PUHCI_QUEUE_HEAD QueueHead, PreviousQueueHead = NULL;
|
|
|
|
UCHAR EndpointAddress, EndpointDeviceAddress;
|
2012-02-28 22:09:57 +00:00
|
|
|
PUSB_ENDPOINT EndpointDescriptor;
|
2012-02-22 23:24:53 +00:00
|
|
|
|
2012-02-28 22:09:57 +00:00
|
|
|
// get descriptor
|
|
|
|
EndpointDescriptor = (PUSB_ENDPOINT)EndDescriptor;
|
2012-02-22 23:24:53 +00:00
|
|
|
|
|
|
|
// acquire lock
|
|
|
|
KeAcquireSpinLock(&m_Lock, &OldLevel);
|
|
|
|
|
|
|
|
// get queue head
|
|
|
|
m_Hardware->GetQueueHead(UHCI_INTERRUPT_QUEUE, &QueueHead);
|
|
|
|
|
|
|
|
while(QueueHead)
|
|
|
|
{
|
|
|
|
// get descriptor
|
|
|
|
Descriptor = (PUHCI_TRANSFER_DESCRIPTOR)QueueHead->NextElementDescriptor;
|
|
|
|
|
|
|
|
if (Descriptor)
|
|
|
|
{
|
|
|
|
// extract endpoint address
|
|
|
|
EndpointAddress = (Descriptor->Token >> TD_TOKEN_ENDPTADDR_SHIFT) & 0x0F;
|
|
|
|
|
|
|
|
// extract device address
|
|
|
|
EndpointDeviceAddress = (Descriptor->Token >> TD_TOKEN_DEVADDR_SHIFT) & 0x7F;
|
|
|
|
|
|
|
|
// check if they match
|
|
|
|
if (EndpointAddress == (EndpointDescriptor->EndPointDescriptor.bEndpointAddress & 0x0F) &&
|
|
|
|
DeviceAddress == EndpointDeviceAddress)
|
|
|
|
{
|
|
|
|
// cleanup queue head
|
|
|
|
QueueHeadCleanup(QueueHead, PreviousQueueHead, &QueueHead);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// move to next queue head
|
|
|
|
PreviousQueueHead = QueueHead;
|
|
|
|
QueueHead = (PUHCI_QUEUE_HEAD)QueueHead->NextLogicalDescriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// release lock
|
|
|
|
KeReleaseSpinLock(&m_Lock, OldLevel);
|
|
|
|
return STATUS_SUCCESS;
|
2012-02-21 23:18:46 +00:00
|
|
|
}
|
|
|
|
|
2012-02-21 15:49:08 +00:00
|
|
|
NTSTATUS
|
|
|
|
CUSBQueue::CreateUSBRequest(
|
|
|
|
IUSBRequest **OutRequest)
|
|
|
|
{
|
|
|
|
PUSBREQUEST UsbRequest;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
*OutRequest = NULL;
|
|
|
|
Status = InternalCreateUSBRequest(&UsbRequest);
|
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
*OutRequest = UsbRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2012-02-22 17:24:43 +00:00
|
|
|
BOOLEAN
|
|
|
|
CUSBQueue::IsQueueHeadComplete(
|
|
|
|
IN PUHCI_QUEUE_HEAD QueueHead)
|
|
|
|
{
|
|
|
|
PUHCI_TRANSFER_DESCRIPTOR Descriptor;
|
|
|
|
ULONG ErrorCount;
|
|
|
|
|
|
|
|
if (QueueHead->NextElementDescriptor == NULL)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// empty queue head
|
|
|
|
//
|
2012-02-22 23:24:53 +00:00
|
|
|
DPRINT("QueueHead %p empty element physical\n", QueueHead);
|
2012-02-22 17:24:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// check all descriptors
|
|
|
|
//
|
|
|
|
Descriptor = (PUHCI_TRANSFER_DESCRIPTOR)QueueHead->NextElementDescriptor;
|
|
|
|
while(Descriptor)
|
|
|
|
{
|
|
|
|
if (Descriptor->Status & TD_STATUS_ACTIVE)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// descriptor is still active
|
|
|
|
//
|
2012-02-23 01:51:55 +00:00
|
|
|
DPRINT("Descriptor %p is active Status %x BufferSize %lu\n", Descriptor, Descriptor->Status, Descriptor->BufferSize);
|
2012-02-22 17:24:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Descriptor->Status & TD_ERROR_MASK)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// error happened
|
|
|
|
//
|
|
|
|
DPRINT1("[USBUHCI] Error detected at descriptor %p Physical %x\n", Descriptor, Descriptor->PhysicalAddress);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get error count
|
|
|
|
//
|
|
|
|
ErrorCount = (Descriptor->Status >> TD_ERROR_COUNT_SHIFT) & TD_ERROR_COUNT_MASK;
|
|
|
|
if (ErrorCount == 0)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// error retry count elapsed
|
|
|
|
//
|
|
|
|
DPRINT1("[USBUHCI] ErrorBuffer %x TimeOut %x Nak %x BitStuff %x\n",
|
|
|
|
Descriptor->Status & TD_STATUS_ERROR_BUFFER,
|
|
|
|
Descriptor->Status & TD_STATUS_ERROR_TIMEOUT,
|
|
|
|
Descriptor->Status & TD_STATUS_ERROR_NAK,
|
|
|
|
Descriptor->Status & TD_STATUS_ERROR_BITSTUFF);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (Descriptor->Status & TD_STATUS_ERROR_BABBLE)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// babble error
|
|
|
|
//
|
|
|
|
DPRINT1("[USBUHCI] Babble detected\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// stall detected
|
|
|
|
//
|
|
|
|
DPRINT1("[USBUHCI] Stall detected\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// move to next descriptor
|
|
|
|
//
|
|
|
|
Descriptor = (PUHCI_TRANSFER_DESCRIPTOR)Descriptor->NextLogicalDescriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// request is complete
|
|
|
|
//
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CUSBQueue::QueueHeadCleanup(
|
|
|
|
IN PUHCI_QUEUE_HEAD QueueHead,
|
|
|
|
IN PUHCI_QUEUE_HEAD PreviousQueueHead,
|
|
|
|
OUT PUHCI_QUEUE_HEAD *NextQueueHead)
|
|
|
|
{
|
2012-02-28 22:09:57 +00:00
|
|
|
PUHCIREQUEST Request;
|
2012-02-22 17:24:43 +00:00
|
|
|
PUHCI_QUEUE_HEAD NewQueueHead;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
//
|
|
|
|
// unlink queue head
|
|
|
|
//
|
|
|
|
UnLinkQueueHead(QueueHead, PreviousQueueHead);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get next queue head
|
|
|
|
//
|
|
|
|
*NextQueueHead = (PUHCI_QUEUE_HEAD)PreviousQueueHead->NextLogicalDescriptor;
|
|
|
|
ASSERT(*NextQueueHead != QueueHead);
|
|
|
|
|
|
|
|
//
|
|
|
|
// the queue head is complete, is the transfer now completed?
|
|
|
|
//
|
2012-02-28 22:09:57 +00:00
|
|
|
Request = (PUHCIREQUEST)QueueHead->Request;
|
2012-02-22 17:24:43 +00:00
|
|
|
ASSERT(Request);
|
|
|
|
|
|
|
|
//
|
|
|
|
// free queue head
|
|
|
|
//
|
2012-02-22 23:24:53 +00:00
|
|
|
DPRINT("Request %p\n", Request);
|
2012-02-22 17:24:43 +00:00
|
|
|
Request->FreeEndpointDescriptor(QueueHead);
|
|
|
|
|
|
|
|
//
|
|
|
|
// check if transfer is complete
|
|
|
|
//
|
|
|
|
if (Request->IsRequestComplete())
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// the transfer is complete
|
|
|
|
//
|
|
|
|
Request->CompletionCallback();
|
|
|
|
Request->Release();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// grab new queue head
|
|
|
|
//
|
|
|
|
Status = Request->GetEndpointDescriptor(&NewQueueHead);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed to get new queue head
|
|
|
|
//
|
|
|
|
DPRINT1("[USBUHCI] Failed to get new queue head with %x\n", Status);
|
|
|
|
Request->CompletionCallback();
|
|
|
|
Request->Release();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Link queue head
|
|
|
|
//
|
|
|
|
Status = AddQueueHead(NewQueueHead);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed to get new queue head
|
|
|
|
//
|
|
|
|
DPRINT1("[USBUHCI] Failed to add queue head with %x\n", Status);
|
|
|
|
Request->CompletionCallback();
|
|
|
|
Request->Release();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CUSBQueue::TransferInterrupt(
|
|
|
|
UCHAR ErrorInterrupt)
|
|
|
|
{
|
|
|
|
KIRQL OldLevel;
|
|
|
|
PUHCI_QUEUE_HEAD QueueHead, PreviousQueueHead = NULL;
|
|
|
|
BOOLEAN IsComplete;
|
|
|
|
|
|
|
|
//
|
|
|
|
// acquire lock
|
|
|
|
//
|
|
|
|
KeAcquireSpinLock(&m_Lock, &OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get queue head
|
|
|
|
//
|
|
|
|
m_Hardware->GetQueueHead(UHCI_INTERRUPT_QUEUE, &QueueHead);
|
|
|
|
|
|
|
|
while(QueueHead)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// is queue head complete
|
|
|
|
//
|
2012-02-22 23:24:53 +00:00
|
|
|
DPRINT("QueueHead %p\n", QueueHead);
|
2012-02-22 17:24:43 +00:00
|
|
|
IsComplete = IsQueueHeadComplete(QueueHead);
|
|
|
|
if (IsComplete)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// cleanup queue head
|
|
|
|
//
|
|
|
|
QueueHeadCleanup(QueueHead, PreviousQueueHead, &QueueHead);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// backup previous queue head
|
|
|
|
//
|
|
|
|
PreviousQueueHead = QueueHead;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get next queue head
|
|
|
|
//
|
|
|
|
QueueHead = (PUHCI_QUEUE_HEAD)QueueHead->NextLogicalDescriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// release lock
|
|
|
|
//
|
|
|
|
KeReleaseSpinLock(&m_Lock, OldLevel);
|
|
|
|
}
|
|
|
|
|
2012-02-21 15:49:08 +00:00
|
|
|
NTSTATUS
|
2012-02-29 16:15:05 +00:00
|
|
|
NTAPI
|
2012-02-21 15:49:08 +00:00
|
|
|
CreateUSBQueue(
|
|
|
|
PUSBQUEUE *OutUsbQueue)
|
|
|
|
{
|
|
|
|
PUSBQUEUE This;
|
|
|
|
|
|
|
|
//
|
|
|
|
// allocate controller
|
|
|
|
//
|
2012-02-23 01:27:19 +00:00
|
|
|
This = new(NonPagedPool, TAG_USBUHCI) CUSBQueue(0);
|
2012-02-21 15:49:08 +00:00
|
|
|
if (!This)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed to allocate
|
|
|
|
//
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// add reference count
|
|
|
|
//
|
|
|
|
This->AddRef();
|
|
|
|
|
|
|
|
//
|
|
|
|
// return result
|
|
|
|
//
|
|
|
|
*OutUsbQueue = (PUSBQUEUE)This;
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|