* Implemented _InsertEndpointForPipe

* usual clean up


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22938 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Salvatore Benedetto
2007-11-17 15:12:31 +00:00
parent 91adcde60f
commit 4ff174438e
3 changed files with 88 additions and 74 deletions
+70 -58
View File
@@ -133,7 +133,7 @@ OHCI::OHCI(pci_info *info, Stack *stack)
return; return;
} }
memset((void*)fHcca, 0, sizeof(ohci_hcca)); memset((void *)fHcca, 0, sizeof(ohci_hcca));
// Set Up Host controller // Set Up Host controller
// Dummy endpoints // Dummy endpoints
@@ -172,7 +172,7 @@ OHCI::OHCI(pci_info *info, Stack *stack)
fInterruptEndpoints[i] = _AllocateEndpoint(); fInterruptEndpoints[i] = _AllocateEndpoint();
if (!fInterruptEndpoints[i]) { if (!fInterruptEndpoints[i]) {
TRACE_ERROR(("ohci_usb: cannot allocate memory for" TRACE_ERROR(("ohci_usb: cannot allocate memory for"
" fInterruptEndpoints[%d] endpoint\n", i)); " fInterruptEndpoints[%ld] endpoint\n", i));
while (--i >= 0) while (--i >= 0)
_FreeEndpoint(fInterruptEndpoints[i]); _FreeEndpoint(fInterruptEndpoints[i]);
_FreeEndpoint(fDummyBulk); _FreeEndpoint(fDummyBulk);
@@ -640,6 +640,7 @@ OHCI::_AllocateEndpoint()
TRACE_ERROR(("usb_ohci: failed to allocate endpoint descriptor\n")); TRACE_ERROR(("usb_ohci: failed to allocate endpoint descriptor\n"));
return NULL; return NULL;
} }
memset((void *)endpoint, 0, sizeof(ohci_endpoint_descriptor));
endpoint->physical_address = (addr_t)physicalAddress; endpoint->physical_address = (addr_t)physicalAddress;
@@ -698,89 +699,100 @@ OHCI::_FreeGeneralDescriptor(ohci_general_descriptor *descriptor)
status_t status_t
OHCI::_InsertEndpointForPipe(Pipe *pipe) OHCI::_InsertEndpointForPipe(Pipe *pipe)
{ {
#if 0 TRACE(("OHCI: Inserting Endpoint for device %u function %u\n",
TRACE(("OHCI: Inserting Endpoint for device %u function %u\n", p->DeviceAddress(), p->EndpointAddress())); pipe->DeviceAddress(), pipe->EndpointAddress()));
ohci_endpoint_descriptor *endpoint = _AllocateEndpoint(); ohci_endpoint_descriptor *endpoint = _AllocateEndpoint();
if (!endpoint) { if (!endpoint) {
TRACE_ERROR(("usb_ohci: cannot allocate memory for endpoint\n")); TRACE_ERROR(("usb_ohci: cannot allocate memory for endpoint\n"));
return B_NO_MEMORY; return B_NO_MEMORY;
} }
endpoint->flags |= OHCI_ENDPOINT_SKIP;
// Set up properties of the endpoint uint32 flags = 0;
endpoints->flags |= OHCI_ENDPOINT_SET_DEVICE_ADDRESS(pipe->DeviceAddress()) flags |= OHCI_ENDPOINT_SKIP;
// Set up flag field for the endpoint
flags |= OHCI_ENDPOINT_SET_DEVICE_ADDRESS(pipe->DeviceAddress())
| OHCI_ENDPOINT_SET_ENDPOINT_NUMBER(pipe->EndpointAddress()); | OHCI_ENDPOINT_SET_ENDPOINT_NUMBER(pipe->EndpointAddress());
//Set the direction // Set the direction
switch (pipe->Direction()) { switch (pipe->Direction()) {
case Pipe::In: case Pipe::In:
properties |= OHCI_ENDPOINT_DIRECTION_IN; flags |= OHCI_ENDPOINT_DIRECTION_IN;
break; break;
case Pipe::Out: case Pipe::Out:
properties |= OHCI_ENDPOINT_DIRECTION_OUT; flags |= OHCI_ENDPOINT_DIRECTION_OUT;
break; break;
case Pipe::Default: case Pipe::Default:
properties |= OHCI_ENDPOINT_DIRECTION_DESCRIPTOR; flags |= OHCI_ENDPOINT_DIRECTION_DESCRIPTOR;
break; break;
default: default:
//TODO: error TRACE_ERROR(("usb_ohci: direction unknown. Wrong value!\n"));
break; _FreeEndpoint(endpoint);
} return B_ERROR;
}
//Set the speed
switch (p->Speed()) { // Set up the speed
switch (pipe->Speed()) {
case USB_SPEED_LOWSPEED: case USB_SPEED_LOWSPEED:
//the bit is 0 flags |= OHCI_ENDPOINT_LOW_SPEED;
break; break;
case USB_SPEED_FULLSPEED: case USB_SPEED_FULLSPEED:
properties |= OHCI_ENDPOINT_SPEED; flags |= OHCI_ENDPOINT_FULL_SPEED;
break; break;
case USB_SPEED_HIGHSPEED: case USB_SPEED_HIGHSPEED:
default: default:
//TODO: error TRACE_ERROR(("usb_ohci: unaccetable speed. Wrong value!\n"));
break; _FreeEndpoint(endpoint);
} return B_ERROR;
//Assign the format. Isochronous endpoints require this switch
if (p->Type() & USB_OBJECT_ISO_PIPE)
properties |= OHCI_ENDPOINT_ISOCHRONOUS_FORMAT;
//Set the maximum packet size
properties |= OHCI_ENDPOINT_SET_MAX_PACKET_SIZE(p->MaxPacketSize());
endpoint->ed->flags = properties;
}
//Check which list we need to add the endpoint in
Endpoint *listhead;
if (p->Type() & USB_OBJECT_CONTROL_PIPE)
listhead = fDummyControl;
else if (p->Type() & USB_OBJECT_BULK_PIPE)
listhead = fDummyBulk;
else if (p->Type() & USB_OBJECT_ISO_PIPE)
listhead = fDummyIsochronous;
else {
_FreeEndpoint(endpoint);
return B_ERROR;
} }
//Add the endpoint to the queues // Set the maximum packet size
if ((p->Type() & USB_OBJECT_ISO_PIPE) == 0) { flags |= OHCI_ENDPOINT_SET_MAX_PACKET_SIZE(pipe->MaxPacketSize());
//Link the endpoint into the head of the list
endpoint->SetNext(listhead->next); endpoint->flags = flags;
listhead->SetNext(endpoint);
} else { // Add the endpoint to the appropriate list
//Link the endpoint into the tail of the list ohci_endpoint_descriptor *head = NULL;
Endpoint *tail = listhead; switch (pipe->Type()) {
while (tail->next != 0) case USB_OBJECT_CONTROL_PIPE:
tail = tail->next; head = fDummyControl;
tail->SetNext(endpoint); break;
case USB_OBJECT_BULK_PIPE:
head = fDummyBulk;
break;
case USB_OBJECT_ISO_PIPE:
// Set the isochronous bit format
endpoint->flags = OHCI_ENDPOINT_ISOCHRONOUS_FORMAT;
head = fDummyIsochronous;
break;
case USB_OBJECT_INTERRUPT_PIPE:
head = _FindInterruptEndpoint((static_cast<InterruptPipe*>(pipe))->Interval());
break;
default:
TRACE_ERROR(("usb_ohci: unknown type of pipe. Wrong value!\n"));
_FreeEndpoint(endpoint);
return B_ERROR;
} }
#endif
Lock();
endpoint->next_logical_endpoint = head->next_logical_endpoint;
endpoint->next_physical_endpoint = head->next_physical_endpoint;
head->next_logical_endpoint = (void *)endpoint;
head->next_physical_endpoint = (uint32)endpoint->physical_address;
Unlock();
return B_OK; return B_OK;
} }
ohci_endpoint_descriptor*
OHCI::_FindInterruptEndpoint(uint8 interval)
{
return NULL;
}
status_t status_t
OHCI::_RemoveEndpointForPipe(Pipe *pipe) OHCI::_RemoveEndpointForPipe(Pipe *pipe)
{ {
+1
View File
@@ -91,6 +91,7 @@ static int32 _FinishThread(void *data);
status_t _RemoveEndpointForPipe(Pipe *pipe); status_t _RemoveEndpointForPipe(Pipe *pipe);
status_t _CreateEndpoint(Pipe *pipe, status_t _CreateEndpoint(Pipe *pipe,
bool isIsochronous); bool isIsochronous);
ohci_endpoint_descriptor *_FindInterruptEndpoint(uint8 interval);
ohci_endpoint_descriptor *_AllocateEndpoint(); ohci_endpoint_descriptor *_AllocateEndpoint();
void _FreeEndpoint( void _FreeEndpoint(
ohci_endpoint_descriptor *endpoint); ohci_endpoint_descriptor *endpoint);
+17 -16
View File
@@ -307,25 +307,26 @@ typedef struct ohci_endpoint_descriptor
void *next_logical_endpoint; // Logical pointer to the next endpoint void *next_logical_endpoint; // Logical pointer to the next endpoint
}; };
#define OHCI_ENDPOINT_ADDRESS_MASK 0x0000007f #define OHCI_ENDPOINT_ADDRESS_MASK 0x0000007f
#define OHCI_ENDPOINT_GET_DEVICE_ADDRESS(s) ((s) & 0x7f) #define OHCI_ENDPOINT_GET_DEVICE_ADDRESS(s) ((s) & 0x7f)
#define OHCI_ENDPOINT_SET_DEVICE_ADDRESS(s) (s) #define OHCI_ENDPOINT_SET_DEVICE_ADDRESS(s) (s)
#define OHCI_ENDPOINT_GET_ENDPOINT_NUMBER(s) (((s) >> 7) & 0xf) #define OHCI_ENDPOINT_GET_ENDPOINT_NUMBER(s) (((s) >> 7) & 0xf)
#define OHCI_ENDPOINT_SET_ENDPOINT_NUMBER(s) ((s) << 7) #define OHCI_ENDPOINT_SET_ENDPOINT_NUMBER(s) ((s) << 7)
#define OHCI_ENDPOINT_DIRECTION_MASK 0x00001800 #define OHCI_ENDPOINT_DIRECTION_MASK 0x00001800
#define OHCI_ENDPOINT_DIRECTION_DESCRIPTOR 0x00000000 #define OHCI_ENDPOINT_DIRECTION_DESCRIPTOR 0x00000000
#define OHCI_ENDPOINT_DIRECTION_OUT 0x00000800 #define OHCI_ENDPOINT_DIRECTION_OUT 0x00000800
#define OHCI_ENDPOINT_DIRECTION_IN 0x00001000 #define OHCI_ENDPOINT_DIRECTION_IN 0x00001000
#define OHCI_ENDPOINT_SPEED 0x00002000 #define OHCI_ENDPOINT_LOW_SPEED 0x00002000
#define OHCI_ENDPOINT_SKIP 0x00004000 #define OHCI_ENDPOINT_FULL_SPEED 0x00000000
#define OHCI_ENDPOINT_GENERAL_FORMAT 0x00000000 #define OHCI_ENDPOINT_SKIP 0x00004000
#define OHCI_ENDPOINT_ISOCHRONOUS_FORMAT 0x00008000 #define OHCI_ENDPOINT_GENERAL_FORMAT 0x00000000
#define OHCI_ENDPOINT_MAX_PACKET_SIZE_MASK (0x7ff << 16) #define OHCI_ENDPOINT_ISOCHRONOUS_FORMAT 0x00008000
#define OHCI_ENDPOINT_GET_MAX_PACKET_SIZE(s) (((s) >> 16) & 0x07ff) #define OHCI_ENDPOINT_MAX_PACKET_SIZE_MASK (0x7ff << 16)
#define OHCI_ENDPOINT_SET_MAX_PACKET_SIZE(s) ((s) << 16) #define OHCI_ENDPOINT_GET_MAX_PACKET_SIZE(s) (((s) >> 16) & 0x07ff)
#define OHCI_ENDPOINT_HALTED 0x00000001 #define OHCI_ENDPOINT_SET_MAX_PACKET_SIZE(s) ((s) << 16)
#define OHCI_ENDPOINT_TOGGLE_CARRY 0x00000002 #define OHCI_ENDPOINT_HALTED 0x00000001
#define OHCI_ENDPOINT_HEAD_MASK 0xfffffffc #define OHCI_ENDPOINT_TOGGLE_CARRY 0x00000002
#define OHCI_ENDPOINT_HEAD_MASK 0xfffffffc
// -------------------------------- // --------------------------------