* Getting familiar with the existing code

* Cleanup (whitespace, nameing, code style)
* Move around methods so they match the header order
* Fix some obvious stuff
* Initialize all members
* Sync roothub code (this will be reworked to a common roothub)
* Only minor functional changes (to the worse for now)

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25527 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2008-05-17 12:39:46 +00:00
parent 25d0a0841f
commit fd1e6f2b37
4 changed files with 857 additions and 845 deletions
File diff suppressed because it is too large Load Diff
+11 -11
View File
@@ -105,13 +105,13 @@ static int32 _InterruptHandler(void *data);
status_t _UnlinkTransfer(transfer_data *transfer); status_t _UnlinkTransfer(transfer_data *transfer);
static int32 _FinishThread(void *data); static int32 _FinishThread(void *data);
void _FinishTransfer(); void _FinishTransfers();
status_t _SubmitControlRequest(Transfer *transfer); status_t _SubmitControlTransfer(Transfer *transfer);
status_t _SubmitBulkTransfer(Transfer *transfer); status_t _SubmitBulkTransfer(Transfer *transfer);
status_t _SubmitPeriodicTransfer(Transfer *transfer); status_t _SubmitPeriodicTransfer(Transfer *transfer);
status_t _AppendChainDescriptorsToEndpoint( status_t _AppendDescriptorChainToEndpoint(
ohci_endpoint_descriptor *endpoint, ohci_endpoint_descriptor *endpoint,
ohci_general_td *first, ohci_general_td *first,
ohci_general_td *last); ohci_general_td *last);
@@ -129,17 +129,22 @@ static int32 _FinishThread(void *data);
// Transfer descriptor related methods // Transfer descriptor related methods
ohci_general_td *_CreateGeneralDescriptor( ohci_general_td *_CreateGeneralDescriptor(
size_t bufferSize); size_t bufferSize);
void _FreeGeneralDescriptor(
ohci_general_td *descriptor);
status_t _CreateDescriptorChain( status_t _CreateDescriptorChain(
ohci_general_td **firstDescriptor, ohci_general_td **firstDescriptor,
ohci_general_td **lastDescriptor, ohci_general_td **lastDescriptor,
uint8 direction, uint8 direction,
size_t bufferSize); size_t bufferSize);
void _FreeGeneralDescriptor(
ohci_general_td *descriptor);
void _FreeDescriptorChain( void _FreeDescriptorChain(
ohci_general_td *topDescriptor); ohci_general_td *topDescriptor);
size_t _WriteDescriptorChain(
ohci_general_td *topDescriptor,
iovec *vector,
size_t vectorCount);
void _LinkDescriptors(ohci_general_td *first, void _LinkDescriptors(ohci_general_td *first,
ohci_general_td *second); ohci_general_td *second);
@@ -147,11 +152,6 @@ static int32 _FinishThread(void *data);
void _FreeIsochronousDescriptor( void _FreeIsochronousDescriptor(
ohci_isochronous_td *descriptor); ohci_isochronous_td *descriptor);
size_t _WriteDescriptorChain(
ohci_general_td *topDescriptor,
iovec *vector,
size_t vectorCount);
// Hash tables related methods // Hash tables related methods
void _AddDescriptorToHash( void _AddDescriptorToHash(
ohci_general_td *descriptor); ohci_general_td *descriptor);
+27 -27
View File
@@ -3,15 +3,15 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Jan-Rixt Van Hoye * Jan-Rixt Van Hoye
* Salvatore Benedetto <[email protected]> * Salvatore Benedetto <[email protected]>
*/ */
#ifndef OHCI_HARD_H #ifndef OHCI_HARDWARE_H
#define OHCI_HARD_H #define OHCI_HARDWARE_H
// -------------------------------- // --------------------------------
// The OHCI registers // The OHCI registers
// -------------------------------- // --------------------------------
// -------------------------------- // --------------------------------
@@ -95,7 +95,7 @@
#define OHCI_HCCA 0x18 #define OHCI_HCCA 0x18
// -------------------------------- // --------------------------------
// Period current ED register (section 7.2.2) // Period current ED register (section 7.2.2)
// -------------------------------- // --------------------------------
#define OHCI_PERIOD_CURRENT_ED 0x1c #define OHCI_PERIOD_CURRENT_ED 0x1c
@@ -206,19 +206,19 @@
// Root Hub port status (n) register (section 7.4.4) // Root Hub port status (n) register (section 7.4.4)
// -------------------------------- // --------------------------------
#define OHCI_RH_PORT_STATUS(n) (0x50 + (n) * 4) // 1 based indexing #define OHCI_RH_PORT_STATUS(n) (0x50 + (n) * 4)// 1 based indexing
#define OHCI_RH_PORTSTATUS_CCS 0x00000001 // Current Connection Status #define OHCI_RH_PORTSTATUS_CCS 0x00000001 // Current Connection Status
#define OHCI_RH_PORTSTATUS_PES 0x00000002 // Port Enable Status #define OHCI_RH_PORTSTATUS_PES 0x00000002 // Port Enable Status
#define OHCI_RH_PORTSTATUS_PSS 0x00000004 // Port Suspend Status #define OHCI_RH_PORTSTATUS_PSS 0x00000004 // Port Suspend Status
#define OHCI_RH_PORTSTATUS_POCI 0x00000008 // Port Overcurrent Indicator #define OHCI_RH_PORTSTATUS_POCI 0x00000008 // Port Overcurrent Indicator
#define OHCI_RH_PORTSTATUS_PRS 0x00000010 // Port Reset Status #define OHCI_RH_PORTSTATUS_PRS 0x00000010 // Port Reset Status
#define OHCI_RH_PORTSTATUS_PPS 0x00000100 // Port Power Status #define OHCI_RH_PORTSTATUS_PPS 0x00000100 // Port Power Status
#define OHCI_RH_PORTSTATUS_LSDA 0x00000200 // Low Speed Device Attached #define OHCI_RH_PORTSTATUS_LSDA 0x00000200 // Low Speed Device Attached
#define OHCI_RH_PORTSTATUS_CSC 0x00010000 // Connection Status Change #define OHCI_RH_PORTSTATUS_CSC 0x00010000 // Connection Status Change
#define OHCI_RH_PORTSTATUS_PESC 0x00020000 // Port Enable Status Change #define OHCI_RH_PORTSTATUS_PESC 0x00020000 // Port Enable Status Change
#define OHCI_RH_PORTSTATUS_PSSC 0x00040000 // Port Suspend Status change #define OHCI_RH_PORTSTATUS_PSSC 0x00040000 // Port Suspend Status change
#define OHCI_RH_PORTSTATUS_OCIC 0x00080000 // Port Overcurrent Change #define OHCI_RH_PORTSTATUS_OCIC 0x00080000 // Port Overcurrent Change
#define OHCI_RH_PORTSTATUS_PRSC 0x00100000 // Port Reset Status Change #define OHCI_RH_PORTSTATUS_PRSC 0x00100000 // Port Reset Status Change
// -------------------------------- // --------------------------------
// Enable List // Enable List
@@ -244,8 +244,8 @@
// -------------------------------- // --------------------------------
// All normal interupts // All normal interupts
// -------------------------------- // --------------------------------
#define OHCI_NORMAL_INTERRUPTS (OHCI_SCHEDULING_OVERRUN \ #define OHCI_NORMAL_INTERRUPTS (OHCI_SCHEDULING_OVERRUN \
| OHCI_WRITEBACK_DONE_HEAD \ | OHCI_WRITEBACK_DONE_HEAD \
| OHCI_RESUME_DETECTED \ | OHCI_RESUME_DETECTED \
@@ -271,7 +271,7 @@
#define OHCI_NUMBER_OF_INTERRUPTS 32 #define OHCI_NUMBER_OF_INTERRUPTS 32
typedef struct ohci_hcca typedef struct ohci_hcca
{ {
uint32 interrupt_table[OHCI_NUMBER_OF_INTERRUPTS]; uint32 interrupt_table[OHCI_NUMBER_OF_INTERRUPTS];
uint32 current_frame_number; uint32 current_frame_number;
@@ -338,8 +338,8 @@ typedef struct ohci_general_td
// Hardware part 16 bytes // Hardware part 16 bytes
uint32 flags; // Flags field uint32 flags; // Flags field
uint32 buffer_physical; // Physical buffer pointer uint32 buffer_physical; // Physical buffer pointer
uint32 next_physical_descriptor; // Physical pointer next descriptor uint32 next_physical_descriptor; // Physical pointer next descriptor
uint32 last_physical_byte_address; // Physical pointer to buffer end uint32 last_physical_byte_address; // Physical pointer to buffer end
// Software part // Software part
addr_t physical_address; // Physical address of this descriptor addr_t physical_address; // Physical address of this descriptor
void *buffer_logical; // Logical pointer to the buffer void *buffer_logical; // Logical pointer to the buffer
@@ -403,7 +403,7 @@ typedef struct ohci_isochronous_td
#define OHCI_ITD_PAGE_SELECT 0x00001000 #define OHCI_ITD_PAGE_SELECT 0x00001000
#define OHCI_ITD_MK_OFFS(len) (0xe000 | ((len) & 0x1fff)) #define OHCI_ITD_MK_OFFS(len) (0xe000 | ((len) & 0x1fff))
#define OHCI_ITD_GET_BUFFER_LENGTH(x) ((x) & 0xfff) #define OHCI_ITD_GET_BUFFER_LENGTH(x) ((x) & 0xfff)
#define OHCI_ITD_GET_BUFFER_CONDITION_CODE(x) ((x) >> 12) #define OHCI_ITD_GET_BUFFER_CONDITION_CODE(x) ((x) >> 12)
#define OHCI_ISOCHRONOUS_TD_ALIGN 32 #define OHCI_ISOCHRONOUS_TD_ALIGN 32
@@ -426,11 +426,11 @@ typedef struct ohci_isochronous_td
#define OHCI_NOT_ACCESSED 15 #define OHCI_NOT_ACCESSED 15
// -------------------------------- // --------------------------------
// Some delay needed when changing // Some delay needed when changing
// certain registers. // certain registers.
// -------------------------------- // --------------------------------
#define OHCI_ENABLE_POWER_DELAY 5000 #define OHCI_ENABLE_POWER_DELAY 5000
#define OHCI_READ_DESC_DELAY 5000 #define OHCI_READ_DESC_DELAY 5000
#endif // OHCI_HARD_H #endif // OHCI_HARDWARE_H
+56 -53
View File
@@ -3,28 +3,29 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Jan-Rixt Van Hoye * Jan-Rixt Van Hoye
* Salvatore Benedetto <[email protected]> * Salvatore Benedetto <[email protected]>
* Michael Lotz <[email protected]>
*/ */
#include "ohci.h" #include "ohci.h"
static usb_device_descriptor sOHCIRootHubDevice = static usb_device_descriptor sOHCIRootHubDevice =
{ {
0x12, // Descriptor size 18, // Descriptor length
USB_DESCRIPTOR_DEVICE, // Type of descriptor USB_DESCRIPTOR_DEVICE, // Descriptor type
0x110, // USB 1.1 0x110, // USB 1.1
0x09, // Hub type 0x09, // Class (9 = Hub)
0, // Subclass 0, // Subclass
0, // Protocol 0, // Protocol
64, // Max packet size 64, // Max packet size on endpoint 0
0, // Vendor 0, // Vendor ID
0, // Product 0, // Product ID
0x110, // Version 0x110, // Version
1, // Index of manufacture string 1, // Index of manufacturer string
2, // Index of product string 2, // Index of product string
0, // Index of serial number string 0, // Index of serial number string
1 // Number of configurations 1 // Number of configurations
}; };
@@ -41,48 +42,50 @@ static ohci_root_hub_configuration_s sOHCIRootHubConfig =
{ // configuration descriptor { // configuration descriptor
9, // Descriptor length 9, // Descriptor length
USB_DESCRIPTOR_CONFIGURATION, // Descriptor type USB_DESCRIPTOR_CONFIGURATION, // Descriptor type
34, // Total size of the configuration 34, // Total length of configuration (including
1, // Number interfaces // interface, endpoint and hub descriptors)
1, // Value of configuration 1, // Number of interfaces
0, // Number of configuration 1, // Value of this configuration
0x40, // Self powered 0, // Index of configuration string
0 // Max power (0, because of self power) 0x40, // Attributes (0x40 = self powered)
0 // Max power (0, since self powered)
}, },
{ // interface descriptor { // interface descriptor
9, // Size 9, // Descriptor length
USB_DESCRIPTOR_INTERFACE, // Type USB_DESCRIPTOR_INTERFACE, // Descriptor type
0, // Interface number 0, // Interface number
0, // Alternate setting 0, // Alternate setting
1, // Num endpoints 1, // Number of endpoints
0x09, // Interface class 0x09, // Interface class (9 = Hub)
0, // Interface subclass 0, // Interface subclass
0, // Interface protocol 0, // Interface protocol
0 // Interface 0 // Index of interface string
}, },
{ // endpoint descriptor { // endpoint descriptor
7, // Size 7, // Descriptor length
USB_DESCRIPTOR_ENDPOINT, // Type USB_DESCRIPTOR_ENDPOINT, // Descriptor type
USB_REQTYPE_DEVICE_IN | 1, // Endpoint address (first in IN endpoint) USB_REQTYPE_DEVICE_IN | 1, // Endpoint address (first in IN endpoint)
0x03, // Attributes (0x03 = interrupt endpoint) 0x03, // Attributes (0x03 = interrupt endpoint)
8, // Max packet size 8, // Max packet size
0xFF // Interval 256 0xff // Interval 256
}, },
{ // hub descriptor { // hub descriptor
9, // Lenght (including deprecated power 9, // Descriptor length (including
// control mask) // deprecated power control mask)
USB_DESCRIPTOR_HUB, // Type USB_DESCRIPTOR_HUB, // Descriptor type
0, // Number of ports 2, // Number of ports
0x0000, // Hub characteristics 0x0000, // Hub characteristics
0, // Power on to power good 0, // Power on to power good (in 2ms units)
0, // Current 0, // Maximum current (in mA)
0x00, // Both ports are removable 0x00, // Both ports are removable
0xff // Depricated power control mask 0xff // Depricated power control mask
} }
}; };
struct ohci_root_hub_string_s { struct ohci_root_hub_string_s {
uint8 length; uint8 length;
uint8 descriptor_type; uint8 descriptor_type;
@@ -121,11 +124,12 @@ static ohci_root_hub_string_s sOHCIRootHubStrings[3] = {
OHCIRootHub::OHCIRootHub(Object *rootObject, int8 deviceAddress) OHCIRootHub::OHCIRootHub(Object *rootObject, int8 deviceAddress)
: Hub(rootObject, rootObject->GetStack()->IndexOfBusManager(rootObject->GetBusManager()), : Hub(rootObject, rootObject->GetStack()->IndexOfBusManager(rootObject->GetBusManager()),
sOHCIRootHubDevice, deviceAddress, USB_SPEED_FULLSPEED, true) sOHCIRootHubDevice, deviceAddress, USB_SPEED_FULLSPEED, true)
{ {
} }
status_t status_t
OHCIRootHub::ProcessTransfer(OHCI *ohci, Transfer *transfer) OHCIRootHub::ProcessTransfer(OHCI *ohci, Transfer *transfer)
{ {
@@ -133,8 +137,7 @@ OHCIRootHub::ProcessTransfer(OHCI *ohci, Transfer *transfer)
return B_ERROR; return B_ERROR;
usb_request_data *request = transfer->RequestData(); usb_request_data *request = transfer->RequestData();
TRACE(("usb_ohci_roothub: request: %d\n", request->Request));
TRACE(("usb_ohci_roothub(): request: %d\n", request->Request));
status_t status = B_TIMED_OUT; status_t status = B_TIMED_OUT;
size_t actualLength = 0; size_t actualLength = 0;
@@ -147,7 +150,6 @@ OHCIRootHub::ProcessTransfer(OHCI *ohci, Transfer *transfer)
// the hub reports whether the local power failed (bit 0) // the hub reports whether the local power failed (bit 0)
// and if there is a over-current condition (bit 1). // and if there is a over-current condition (bit 1).
// everything as 0 means all is ok. // everything as 0 means all is ok.
// TODO (?) actually check for the value
memset(transfer->Data(), 0, actualLength); memset(transfer->Data(), 0, actualLength);
status = B_OK; status = B_OK;
break; break;
@@ -159,6 +161,7 @@ OHCIRootHub::ProcessTransfer(OHCI *ohci, Transfer *transfer)
memcpy(transfer->Data(), (void *)&portStatus, actualLength); memcpy(transfer->Data(), (void *)&portStatus, actualLength);
status = B_OK; status = B_OK;
} }
break; break;
} }
@@ -168,12 +171,12 @@ OHCIRootHub::ProcessTransfer(OHCI *ohci, Transfer *transfer)
break; break;
} }
TRACE(("usb_ohci_roothub(): set address: %d\n", request->Value)); TRACE(("usb_ohci_roothub: set address: %d\n", request->Value));
status = B_OK; status = B_OK;
break; break;
case USB_REQUEST_GET_DESCRIPTOR: case USB_REQUEST_GET_DESCRIPTOR:
TRACE(("usb_ohci_roothub(): get descriptor: %d\n", request->Value >> 8)); TRACE(("usb_ohci_roothub: get descriptor: %d\n", request->Value >> 8));
switch (request->Value >> 8) { switch (request->Value >> 8) {
case USB_DESCRIPTOR_DEVICE: { case USB_DESCRIPTOR_DEVICE: {
@@ -227,11 +230,11 @@ OHCIRootHub::ProcessTransfer(OHCI *ohci, Transfer *transfer)
case USB_REQUEST_CLEAR_FEATURE: { case USB_REQUEST_CLEAR_FEATURE: {
if (request->Index == 0) { if (request->Index == 0) {
// we don't support any hub changes // we don't support any hub changes
TRACE_ERROR(("usb_ohci_roothub(): clear feature: no hub changes\n")); TRACE_ERROR(("usb_ohci_roothub: clear feature: no hub changes\n"));
break; break;
} }
TRACE(("usb_ohci_roothub(): clear feature: %d\n", request->Value)); TRACE(("usb_ohci_roothub: clear feature: %d\n", request->Value));
if (ohci->ClearPortFeature(request->Index - 1, request->Value) >= B_OK) if (ohci->ClearPortFeature(request->Index - 1, request->Value) >= B_OK)
status = B_OK; status = B_OK;
break; break;
@@ -240,11 +243,11 @@ OHCIRootHub::ProcessTransfer(OHCI *ohci, Transfer *transfer)
case USB_REQUEST_SET_FEATURE: { case USB_REQUEST_SET_FEATURE: {
if (request->Index == 0) { if (request->Index == 0) {
// we don't support any hub changes // we don't support any hub changes
TRACE_ERROR(("usb_ohci_roothub(): set feature: no hub changes\n")); TRACE_ERROR(("usb_ohci_roothub: set feature: no hub changes\n"));
break; break;
} }
TRACE(("usb_ohci_roothub(): set feature: %d\n", request->Value)); TRACE(("usb_ohci_roothub: set feature: %d\n", request->Value));
if (ohci->SetPortFeature(request->Index - 1, request->Value) >= B_OK) if (ohci->SetPortFeature(request->Index - 1, request->Value) >= B_OK)
status = B_OK; status = B_OK;
break; break;