* Rework the USB tracing mechanism. Cleaned it up and make it more convenient to

use. It will now print out the usb_ids of the objects that generate the trace
  messages. These IDs are unique compared to the device address used previously,
  because device addresses are per bus while usb_ids are global. This makes
  trace output from devices across multiple controllers distinguishable.
* Some cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29002 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2009-01-24 01:28:31 +00:00
parent b6b002b81e
commit f14fe767bf
22 changed files with 591 additions and 524 deletions
@@ -12,6 +12,7 @@
BusManager::BusManager(Stack *stack) BusManager::BusManager(Stack *stack)
: fInitOK(false), : fInitOK(false),
fStack(stack),
fRootHub(NULL) fRootHub(NULL)
{ {
mutex_init(&fLock, "usb busmanager lock"); mutex_init(&fLock, "usb busmanager lock");
@@ -86,7 +87,7 @@ BusManager::AllocateAddress()
address = (address + 1) % 127; address = (address + 1) % 127;
} }
TRACE_ERROR(("USB BusManager: the busmanager has run out of device addresses\n")); TRACE_ERROR("the busmanager has run out of device addresses\n");
Unlock(); Unlock();
return -1; return -1;
} }
@@ -103,7 +104,7 @@ BusManager::FreeAddress(int8 address)
return; return;
if (!fDeviceMap[address]) { if (!fDeviceMap[address]) {
TRACE_ERROR(("USB BusManager: freeing address %d which was not allocated\n", address)); TRACE_ERROR("freeing address %d which was not allocated\n", address);
} }
fDeviceMap[address] = false; fDeviceMap[address] = false;
@@ -118,15 +119,15 @@ BusManager::AllocateDevice(Hub *parent, int8 hubAddress, uint8 hubPort,
// Check if there is a free entry in the device map (for the device number) // Check if there is a free entry in the device map (for the device number)
int8 deviceAddress = AllocateAddress(); int8 deviceAddress = AllocateAddress();
if (deviceAddress < 0) { if (deviceAddress < 0) {
TRACE_ERROR(("USB BusManager: could not allocate an address\n")); TRACE_ERROR("could not allocate an address\n");
return NULL; return NULL;
} }
TRACE(("USB BusManager: setting device address to %d\n", deviceAddress)); TRACE("setting device address to %d\n", deviceAddress);
ControlPipe *defaultPipe = _GetDefaultPipe(speed); ControlPipe *defaultPipe = _GetDefaultPipe(speed);
if (!defaultPipe) { if (!defaultPipe) {
TRACE_ERROR(("USB BusManager: error getting the default pipe for speed %d\n", (int)speed)); TRACE_ERROR("error getting the default pipe for speed %d\n", speed);
FreeAddress(deviceAddress); FreeAddress(deviceAddress);
return NULL; return NULL;
} }
@@ -153,7 +154,7 @@ BusManager::AllocateDevice(Hub *parent, int8 hubAddress, uint8 hubPort,
} }
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("USB BusManager: error while setting device address\n")); TRACE_ERROR("error while setting device address\n");
FreeAddress(deviceAddress); FreeAddress(deviceAddress);
return NULL; return NULL;
} }
@@ -173,7 +174,7 @@ BusManager::AllocateDevice(Hub *parent, int8 hubAddress, uint8 hubPort,
size_t actualLength = 0; size_t actualLength = 0;
usb_device_descriptor deviceDescriptor; usb_device_descriptor deviceDescriptor;
TRACE(("USB BusManager: getting the device descriptor\n")); TRACE("getting the device descriptor\n");
pipe.SendRequest( pipe.SendRequest(
USB_REQTYPE_DEVICE_IN | USB_REQTYPE_STANDARD, // type USB_REQTYPE_DEVICE_IN | USB_REQTYPE_STANDARD, // type
USB_REQUEST_GET_DESCRIPTOR, // request USB_REQUEST_GET_DESCRIPTOR, // request
@@ -185,33 +186,33 @@ BusManager::AllocateDevice(Hub *parent, int8 hubAddress, uint8 hubPort,
&actualLength); // actual length &actualLength); // actual length
if (actualLength != 8) { if (actualLength != 8) {
TRACE_ERROR(("USB BusManager: error while getting the device descriptor\n")); TRACE_ERROR("error while getting the device descriptor\n");
FreeAddress(deviceAddress); FreeAddress(deviceAddress);
return NULL; return NULL;
} }
TRACE(("short device descriptor for device %d:\n", deviceAddress)); TRACE("short device descriptor for device %d:\n", deviceAddress);
TRACE(("\tlength:..............%d\n", deviceDescriptor.length)); TRACE("\tlength:..............%d\n", deviceDescriptor.length);
TRACE(("\tdescriptor_type:.....0x%04x\n", deviceDescriptor.descriptor_type)); TRACE("\tdescriptor_type:.....0x%04x\n", deviceDescriptor.descriptor_type);
TRACE(("\tusb_version:.........0x%04x\n", deviceDescriptor.usb_version)); TRACE("\tusb_version:.........0x%04x\n", deviceDescriptor.usb_version);
TRACE(("\tdevice_class:........0x%02x\n", deviceDescriptor.device_class)); TRACE("\tdevice_class:........0x%02x\n", deviceDescriptor.device_class);
TRACE(("\tdevice_subclass:.....0x%02x\n", deviceDescriptor.device_subclass)); TRACE("\tdevice_subclass:.....0x%02x\n", deviceDescriptor.device_subclass);
TRACE(("\tdevice_protocol:.....0x%02x\n", deviceDescriptor.device_protocol)); TRACE("\tdevice_protocol:.....0x%02x\n", deviceDescriptor.device_protocol);
TRACE(("\tmax_packet_size_0:...%d\n", deviceDescriptor.max_packet_size_0)); TRACE("\tmax_packet_size_0:...%d\n", deviceDescriptor.max_packet_size_0);
// Create a new instance based on the type (Hub or Device) // Create a new instance based on the type (Hub or Device)
if (deviceDescriptor.device_class == 0x09) { if (deviceDescriptor.device_class == 0x09) {
TRACE(("USB BusManager: creating new hub\n")); TRACE("creating new hub\n");
Hub *hub = new(std::nothrow) Hub(parent, hubAddress, hubPort, Hub *hub = new(std::nothrow) Hub(parent, hubAddress, hubPort,
deviceDescriptor, deviceAddress, speed, false); deviceDescriptor, deviceAddress, speed, false);
if (!hub) { if (!hub) {
TRACE_ERROR(("USB BusManager: no memory to allocate hub\n")); TRACE_ERROR("no memory to allocate hub\n");
FreeAddress(deviceAddress); FreeAddress(deviceAddress);
return NULL; return NULL;
} }
if (hub->InitCheck() < B_OK) { if (hub->InitCheck() < B_OK) {
TRACE_ERROR(("USB BusManager: hub failed init check\n")); TRACE_ERROR("hub failed init check\n");
FreeAddress(deviceAddress); FreeAddress(deviceAddress);
delete hub; delete hub;
return NULL; return NULL;
@@ -220,17 +221,17 @@ BusManager::AllocateDevice(Hub *parent, int8 hubAddress, uint8 hubPort,
return (Device *)hub; return (Device *)hub;
} }
TRACE(("USB BusManager: creating new device\n")); TRACE("creating new device\n");
Device *device = new(std::nothrow) Device(parent, hubAddress, hubPort, Device *device = new(std::nothrow) Device(parent, hubAddress, hubPort,
deviceDescriptor, deviceAddress, speed, false); deviceDescriptor, deviceAddress, speed, false);
if (!device) { if (!device) {
TRACE_ERROR(("USB BusManager: no memory to allocate device\n")); TRACE_ERROR("no memory to allocate device\n");
FreeAddress(deviceAddress); FreeAddress(deviceAddress);
return NULL; return NULL;
} }
if (device->InitCheck() < B_OK) { if (device->InitCheck() < B_OK) {
TRACE_ERROR(("USB BusManager: device failed init check\n")); TRACE_ERROR("device failed init check\n");
FreeAddress(deviceAddress); FreeAddress(deviceAddress);
delete device; delete device;
return NULL; return NULL;
@@ -298,7 +299,7 @@ BusManager::_GetDefaultPipe(usb_speed speed)
} }
if (!fDefaultPipes[speed]) { if (!fDefaultPipes[speed]) {
TRACE_ERROR(("USB BusManager: failed to allocate default pipe for speed %d\n", speed)); TRACE_ERROR("failed to allocate default pipe for speed %d\n", speed);
} }
Unlock(); Unlock();
+69 -72
View File
@@ -25,11 +25,11 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
fHubAddress(hubAddress), fHubAddress(hubAddress),
fHubPort(hubPort) fHubPort(hubPort)
{ {
TRACE(("USB Device %d: creating device\n", fDeviceAddress)); TRACE("creating device\n");
fDefaultPipe = new(std::nothrow) ControlPipe(this); fDefaultPipe = new(std::nothrow) ControlPipe(this);
if (!fDefaultPipe) { if (!fDefaultPipe) {
TRACE_ERROR(("USB Device %d: could not allocate default pipe\n", fDeviceAddress)); TRACE_ERROR("could not allocate default pipe\n");
return; return;
} }
@@ -43,32 +43,31 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
(void *)&fDeviceDescriptor, sizeof(fDeviceDescriptor), &actualLength); (void *)&fDeviceDescriptor, sizeof(fDeviceDescriptor), &actualLength);
if (status < B_OK || actualLength != sizeof(fDeviceDescriptor)) { if (status < B_OK || actualLength != sizeof(fDeviceDescriptor)) {
TRACE_ERROR(("USB Device %d: error while getting the device descriptor\n", fDeviceAddress)); TRACE_ERROR("error while getting the device descriptor\n");
return; return;
} }
TRACE(("full device descriptor for device %d:\n", fDeviceAddress)); TRACE("full device descriptor for device %d:\n", fDeviceAddress);
TRACE(("\tlength:..............%d\n", fDeviceDescriptor.length)); TRACE("\tlength:..............%d\n", fDeviceDescriptor.length);
TRACE(("\tdescriptor_type:.....0x%04x\n", fDeviceDescriptor.descriptor_type)); TRACE("\tdescriptor_type:.....0x%04x\n", fDeviceDescriptor.descriptor_type);
TRACE(("\tusb_version:.........0x%04x\n", fDeviceDescriptor.usb_version)); TRACE("\tusb_version:.........0x%04x\n", fDeviceDescriptor.usb_version);
TRACE(("\tdevice_class:........0x%02x\n", fDeviceDescriptor.device_class)); TRACE("\tdevice_class:........0x%02x\n", fDeviceDescriptor.device_class);
TRACE(("\tdevice_subclass:.....0x%02x\n", fDeviceDescriptor.device_subclass)); TRACE("\tdevice_subclass:.....0x%02x\n", fDeviceDescriptor.device_subclass);
TRACE(("\tdevice_protocol:.....0x%02x\n", fDeviceDescriptor.device_protocol)); TRACE("\tdevice_protocol:.....0x%02x\n", fDeviceDescriptor.device_protocol);
TRACE(("\tmax_packet_size_0:...%d\n", fDeviceDescriptor.max_packet_size_0)); TRACE("\tmax_packet_size_0:...%d\n", fDeviceDescriptor.max_packet_size_0);
TRACE(("\tvendor_id:...........0x%04x\n", fDeviceDescriptor.vendor_id)); TRACE("\tvendor_id:...........0x%04x\n", fDeviceDescriptor.vendor_id);
TRACE(("\tproduct_id:..........0x%04x\n", fDeviceDescriptor.product_id)); TRACE("\tproduct_id:..........0x%04x\n", fDeviceDescriptor.product_id);
TRACE(("\tdevice_version:......0x%04x\n", fDeviceDescriptor.device_version)); TRACE("\tdevice_version:......0x%04x\n", fDeviceDescriptor.device_version);
TRACE(("\tmanufacturer:........0x%02x\n", fDeviceDescriptor.manufacturer)); TRACE("\tmanufacturer:........0x%02x\n", fDeviceDescriptor.manufacturer);
TRACE(("\tproduct:.............0x%02x\n", fDeviceDescriptor.product)); TRACE("\tproduct:.............0x%02x\n", fDeviceDescriptor.product);
TRACE(("\tserial_number:.......0x%02x\n", fDeviceDescriptor.serial_number)); TRACE("\tserial_number:.......0x%02x\n", fDeviceDescriptor.serial_number);
TRACE(("\tnum_configurations:..%d\n", fDeviceDescriptor.num_configurations)); TRACE("\tnum_configurations:..%d\n", fDeviceDescriptor.num_configurations);
// Get the configurations // Get the configurations
fConfigurations = (usb_configuration_info *)malloc( fConfigurations = (usb_configuration_info *)malloc(
fDeviceDescriptor.num_configurations * sizeof(usb_configuration_info)); fDeviceDescriptor.num_configurations * sizeof(usb_configuration_info));
if (fConfigurations == NULL) { if (fConfigurations == NULL) {
TRACE_ERROR(("USB Device %d: out of memory during config creations!\n", TRACE_ERROR("out of memory during config creations!\n");
fDeviceAddress));
return; return;
} }
@@ -81,25 +80,23 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
&actualLength); &actualLength);
if (status < B_OK || actualLength != sizeof(usb_configuration_descriptor)) { if (status < B_OK || actualLength != sizeof(usb_configuration_descriptor)) {
TRACE_ERROR(("USB Device %d: error fetching configuration %ld\n", TRACE_ERROR("error fetching configuration %ld\n", i);
fDeviceAddress, i));
return; return;
} }
TRACE(("USB Device %d: configuration %ld\n", fDeviceAddress, i)); TRACE("configuration %ld\n", i);
TRACE(("\tlength:..............%d\n", configDescriptor.length)); TRACE("\tlength:..............%d\n", configDescriptor.length);
TRACE(("\tdescriptor_type:.....0x%02x\n", configDescriptor.descriptor_type)); TRACE("\tdescriptor_type:.....0x%02x\n", configDescriptor.descriptor_type);
TRACE(("\ttotal_length:........%d\n", configDescriptor.total_length)); TRACE("\ttotal_length:........%d\n", configDescriptor.total_length);
TRACE(("\tnumber_interfaces:...%d\n", configDescriptor.number_interfaces)); TRACE("\tnumber_interfaces:...%d\n", configDescriptor.number_interfaces);
TRACE(("\tconfiguration_value:.0x%02x\n", configDescriptor.configuration_value)); TRACE("\tconfiguration_value:.0x%02x\n", configDescriptor.configuration_value);
TRACE(("\tconfiguration:.......0x%02x\n", configDescriptor.configuration)); TRACE("\tconfiguration:.......0x%02x\n", configDescriptor.configuration);
TRACE(("\tattributes:..........0x%02x\n", configDescriptor.attributes)); TRACE("\tattributes:..........0x%02x\n", configDescriptor.attributes);
TRACE(("\tmax_power:...........%d\n", configDescriptor.max_power)); TRACE("\tmax_power:...........%d\n", configDescriptor.max_power);
uint8 *configData = (uint8 *)malloc(configDescriptor.total_length); uint8 *configData = (uint8 *)malloc(configDescriptor.total_length);
if (configData == NULL) { if (configData == NULL) {
TRACE_ERROR(("USB Device %d: out of memory when reading config\n", TRACE_ERROR("out of memory when reading config\n");
fDeviceAddress));
return; return;
} }
@@ -107,9 +104,9 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
(void *)configData, configDescriptor.total_length, &actualLength); (void *)configData, configDescriptor.total_length, &actualLength);
if (status < B_OK || actualLength != configDescriptor.total_length) { if (status < B_OK || actualLength != configDescriptor.total_length) {
TRACE_ERROR(("USB Device %d: error fetching full configuration" TRACE_ERROR("error fetching full configuration"
" descriptor %ld got %lu expected %u\n", fDeviceAddress, i, " descriptor %ld got %lu expected %u\n", i,
actualLength, configDescriptor.total_length)); actualLength, configDescriptor.total_length);
free(configData); free(configData);
return; return;
} }
@@ -121,8 +118,7 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
fConfigurations[i].interface = (usb_interface_list *)malloc( fConfigurations[i].interface = (usb_interface_list *)malloc(
configuration->number_interfaces * sizeof(usb_interface_list)); configuration->number_interfaces * sizeof(usb_interface_list));
if (fConfigurations[i].interface == NULL) { if (fConfigurations[i].interface == NULL) {
TRACE_ERROR(("USB Device %d: out of memory when creating interfaces\n", TRACE_ERROR("out of memory when creating interfaces\n");
fDeviceAddress));
return; return;
} }
@@ -134,18 +130,18 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
while (descriptorStart < actualLength) { while (descriptorStart < actualLength) {
switch (configData[descriptorStart + 1]) { switch (configData[descriptorStart + 1]) {
case USB_DESCRIPTOR_INTERFACE: { case USB_DESCRIPTOR_INTERFACE: {
TRACE(("USB Device %d: got interface descriptor\n", fDeviceAddress)); TRACE("got interface descriptor\n");
usb_interface_descriptor *interfaceDescriptor usb_interface_descriptor *interfaceDescriptor
= (usb_interface_descriptor *)&configData[descriptorStart]; = (usb_interface_descriptor *)&configData[descriptorStart];
TRACE(("\tlength:.............%d\n", interfaceDescriptor->length)); TRACE("\tlength:.............%d\n", interfaceDescriptor->length);
TRACE(("\tdescriptor_type:....0x%02x\n", interfaceDescriptor->descriptor_type)); TRACE("\tdescriptor_type:....0x%02x\n", interfaceDescriptor->descriptor_type);
TRACE(("\tinterface_number:...%d\n", interfaceDescriptor->interface_number)); TRACE("\tinterface_number:...%d\n", interfaceDescriptor->interface_number);
TRACE(("\talternate_setting:..%d\n", interfaceDescriptor->alternate_setting)); TRACE("\talternate_setting:..%d\n", interfaceDescriptor->alternate_setting);
TRACE(("\tnum_endpoints:......%d\n", interfaceDescriptor->num_endpoints)); TRACE("\tnum_endpoints:......%d\n", interfaceDescriptor->num_endpoints);
TRACE(("\tinterface_class:....0x%02x\n", interfaceDescriptor->interface_class)); TRACE("\tinterface_class:....0x%02x\n", interfaceDescriptor->interface_class);
TRACE(("\tinterface_subclass:.0x%02x\n", interfaceDescriptor->interface_subclass)); TRACE("\tinterface_subclass:.0x%02x\n", interfaceDescriptor->interface_subclass);
TRACE(("\tinterface_protocol:.0x%02x\n", interfaceDescriptor->interface_protocol)); TRACE("\tinterface_protocol:.0x%02x\n", interfaceDescriptor->interface_protocol);
TRACE(("\tinterface:..........%d\n", interfaceDescriptor->interface)); TRACE("\tinterface:..........%d\n", interfaceDescriptor->interface);
usb_interface_list *interfaceList usb_interface_list *interfaceList
= &fConfigurations[i].interface[interfaceDescriptor->interface_number]; = &fConfigurations[i].interface[interfaceDescriptor->interface_number];
@@ -156,8 +152,8 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
= (usb_interface_info *)realloc(interfaceList->alt, = (usb_interface_info *)realloc(interfaceList->alt,
interfaceList->alt_count * sizeof(usb_interface_info)); interfaceList->alt_count * sizeof(usb_interface_info));
if (newAlternates == NULL) { if (newAlternates == NULL) {
TRACE_ERROR(("USB Device %d: out of memory allocating" TRACE_ERROR("out of memory allocating"
" alternate interface\n", fDeviceAddress)); " alternate interface\n");
interfaceList->alt_count--; interfaceList->alt_count--;
return; return;
} }
@@ -179,8 +175,8 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
Interface *interface = new(std::nothrow) Interface(this, Interface *interface = new(std::nothrow) Interface(this,
interfaceDescriptor->interface_number); interfaceDescriptor->interface_number);
if (interface == NULL) { if (interface == NULL) {
TRACE_ERROR(("USB Device %d: failed to allocate" TRACE_ERROR("failed to allocate"
" interface object\n", fDeviceAddress)); " interface object\n");
return; return;
} }
@@ -190,15 +186,15 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
} }
case USB_DESCRIPTOR_ENDPOINT: { case USB_DESCRIPTOR_ENDPOINT: {
TRACE(("USB Device %d: got endpoint descriptor\n", fDeviceAddress)); TRACE("got endpoint descriptor\n");
usb_endpoint_descriptor *endpointDescriptor usb_endpoint_descriptor *endpointDescriptor
= (usb_endpoint_descriptor *)&configData[descriptorStart]; = (usb_endpoint_descriptor *)&configData[descriptorStart];
TRACE(("\tlength:.............%d\n", endpointDescriptor->length)); TRACE("\tlength:.............%d\n", endpointDescriptor->length);
TRACE(("\tdescriptor_type:....0x%02x\n", endpointDescriptor->descriptor_type)); TRACE("\tdescriptor_type:....0x%02x\n", endpointDescriptor->descriptor_type);
TRACE(("\tendpoint_address:...0x%02x\n", endpointDescriptor->endpoint_address)); TRACE("\tendpoint_address:...0x%02x\n", endpointDescriptor->endpoint_address);
TRACE(("\tattributes:.........0x%02x\n", endpointDescriptor->attributes)); TRACE("\tattributes:.........0x%02x\n", endpointDescriptor->attributes);
TRACE(("\tmax_packet_size:....%d\n", endpointDescriptor->max_packet_size)); TRACE("\tmax_packet_size:....%d\n", endpointDescriptor->max_packet_size);
TRACE(("\tinterval:...........%d\n", endpointDescriptor->interval)); TRACE("\tinterval:...........%d\n", endpointDescriptor->interval);
if (!currentInterface) if (!currentInterface)
break; break;
@@ -211,8 +207,8 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
currentInterface->endpoint_count currentInterface->endpoint_count
* sizeof(usb_endpoint_info)); * sizeof(usb_endpoint_info));
if (newEndpoints == NULL) { if (newEndpoints == NULL) {
TRACE_ERROR(("USB Device %d: out of memory allocating" TRACE_ERROR("out of memory allocating"
" new endpoint\n", fDeviceAddress)); " new endpoint\n");
currentInterface->endpoint_count--; currentInterface->endpoint_count--;
return; return;
} }
@@ -228,11 +224,11 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
} }
default: default:
TRACE(("USB Device %d: got generic descriptor\n", fDeviceAddress)); TRACE("got generic descriptor\n");
usb_generic_descriptor *genericDescriptor usb_generic_descriptor *genericDescriptor
= (usb_generic_descriptor *)&configData[descriptorStart]; = (usb_generic_descriptor *)&configData[descriptorStart];
TRACE(("\tlength:.............%d\n", genericDescriptor->length)); TRACE("\tlength:.............%d\n", genericDescriptor->length);
TRACE(("\tdescriptor_type:....0x%02x\n", genericDescriptor->descriptor_type)); TRACE("\tdescriptor_type:....0x%02x\n", genericDescriptor->descriptor_type);
if (!currentInterface) if (!currentInterface)
break; break;
@@ -244,8 +240,8 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
currentInterface->generic_count currentInterface->generic_count
* sizeof(usb_descriptor *)); * sizeof(usb_descriptor *));
if (newGenerics == NULL) { if (newGenerics == NULL) {
TRACE_ERROR(("USB Device %d: out of memory allocating" TRACE_ERROR("out of memory allocating"
" generic descriptor\n", fDeviceAddress)); " generic descriptor\n");
currentInterface->generic_count--; currentInterface->generic_count--;
return; return;
} }
@@ -263,10 +259,9 @@ Device::Device(Object *parent, int8 hubAddress, uint8 hubPort,
} }
// Set default configuration // Set default configuration
TRACE(("USB Device %d: setting default configuration\n", fDeviceAddress)); TRACE("setting default configuration\n");
if (SetConfigurationAt(0) < B_OK) { if (SetConfigurationAt(0) < B_OK) {
TRACE_ERROR(("USB Device %d: failed to set default configuration\n", TRACE_ERROR("failed to set default configuration\n");
fDeviceAddress));
return; return;
} }
@@ -468,8 +463,7 @@ Device::InitEndpoints(int32 interfaceIndex)
} }
if (pipe == NULL) { if (pipe == NULL) {
TRACE_ERROR(("USB Device %d: failed to allocate pipe\n", TRACE_ERROR("failed to allocate pipe\n");
fDeviceAddress));
endpoint->handle = 0; endpoint->handle = 0;
continue; continue;
} }
@@ -584,7 +578,7 @@ Device::ReportDevice(usb_support_descriptor *supportDescriptors,
uint32 supportDescriptorCount, const usb_notify_hooks *hooks, uint32 supportDescriptorCount, const usb_notify_hooks *hooks,
usb_driver_cookie **cookies, bool added, bool recursive) usb_driver_cookie **cookies, bool added, bool recursive)
{ {
TRACE(("USB Device %d: reporting device\n", fDeviceAddress)); TRACE("reporting device\n");
bool supported = false; bool supported = false;
if (supportDescriptorCount == 0 || supportDescriptors == NULL) if (supportDescriptorCount == 0 || supportDescriptors == NULL)
supported = true; supported = true;
@@ -685,6 +679,7 @@ Device::SetFeature(uint16 selector)
if (!fAvailable) if (!fAvailable)
return B_ERROR; return B_ERROR;
TRACE("set feature %u\n", selector);
return fDefaultPipe->SendRequest( return fDefaultPipe->SendRequest(
USB_REQTYPE_STANDARD | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_STANDARD | USB_REQTYPE_DEVICE_OUT,
USB_REQUEST_SET_FEATURE, USB_REQUEST_SET_FEATURE,
@@ -703,6 +698,7 @@ Device::ClearFeature(uint16 selector)
if (!fAvailable) if (!fAvailable)
return B_ERROR; return B_ERROR;
TRACE("clear feature %u\n", selector);
return fDefaultPipe->SendRequest( return fDefaultPipe->SendRequest(
USB_REQTYPE_STANDARD | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_STANDARD | USB_REQTYPE_DEVICE_OUT,
USB_REQUEST_CLEAR_FEATURE, USB_REQUEST_CLEAR_FEATURE,
@@ -721,6 +717,7 @@ Device::GetStatus(uint16 *status)
if (!fAvailable) if (!fAvailable)
return B_ERROR; return B_ERROR;
TRACE("get status\n");
return fDefaultPipe->SendRequest( return fDefaultPipe->SendRequest(
USB_REQTYPE_STANDARD | USB_REQTYPE_DEVICE_IN, USB_REQTYPE_STANDARD | USB_REQTYPE_DEVICE_IN,
USB_REQUEST_GET_STATUS, USB_REQUEST_GET_STATUS,
+40 -38
View File
@@ -18,14 +18,14 @@ Hub::Hub(Object *parent, int8 hubAddress, uint8 hubPort,
isRootHub), isRootHub),
fInterruptPipe(NULL) fInterruptPipe(NULL)
{ {
TRACE(("USB Hub %d: creating hub\n", DeviceAddress())); TRACE("creating hub\n");
memset(&fHubDescriptor, 0, sizeof(fHubDescriptor)); memset(&fHubDescriptor, 0, sizeof(fHubDescriptor));
for (int32 i = 0; i < USB_MAX_PORT_COUNT; i++) for (int32 i = 0; i < USB_MAX_PORT_COUNT; i++)
fChildren[i] = NULL; fChildren[i] = NULL;
if (!fInitOK) { if (!fInitOK) {
TRACE_ERROR(("USB Hub %d: device failed to initialize\n", DeviceAddress())); TRACE_ERROR("device failed to initialize\n");
return; return;
} }
@@ -33,33 +33,33 @@ Hub::Hub(Object *parent, int8 hubAddress, uint8 hubPort,
fInitOK = false; fInitOK = false;
if (fDeviceDescriptor.device_class != 9) { if (fDeviceDescriptor.device_class != 9) {
TRACE_ERROR(("USB Hub %d: wrong class! bailing out\n", DeviceAddress())); TRACE_ERROR("wrong class! bailing out\n");
return; return;
} }
TRACE(("USB Hub %d: Getting hub descriptor...\n", DeviceAddress())); TRACE("getting hub descriptor...\n");
size_t actualLength; size_t actualLength;
status_t status = GetDescriptor(USB_DESCRIPTOR_HUB, 0, 0, status_t status = GetDescriptor(USB_DESCRIPTOR_HUB, 0, 0,
(void *)&fHubDescriptor, sizeof(usb_hub_descriptor), &actualLength); (void *)&fHubDescriptor, sizeof(usb_hub_descriptor), &actualLength);
// we need at least 8 bytes // we need at least 8 bytes
if (status < B_OK || actualLength < 8) { if (status < B_OK || actualLength < 8) {
TRACE_ERROR(("USB Hub %d: Error getting hub descriptor\n", DeviceAddress())); TRACE_ERROR("error getting hub descriptor\n");
return; return;
} }
TRACE(("USB Hub %d: hub descriptor (%ld bytes):\n", DeviceAddress(), actualLength)); TRACE("hub descriptor (%ld bytes):\n", actualLength);
TRACE(("\tlength:..............%d\n", fHubDescriptor.length)); TRACE("\tlength:..............%d\n", fHubDescriptor.length);
TRACE(("\tdescriptor_type:.....0x%02x\n", fHubDescriptor.descriptor_type)); TRACE("\tdescriptor_type:.....0x%02x\n", fHubDescriptor.descriptor_type);
TRACE(("\tnum_ports:...........%d\n", fHubDescriptor.num_ports)); TRACE("\tnum_ports:...........%d\n", fHubDescriptor.num_ports);
TRACE(("\tcharacteristics:.....0x%04x\n", fHubDescriptor.characteristics)); TRACE("\tcharacteristics:.....0x%04x\n", fHubDescriptor.characteristics);
TRACE(("\tpower_on_to_power_g:.%d\n", fHubDescriptor.power_on_to_power_good)); TRACE("\tpower_on_to_power_g:.%d\n", fHubDescriptor.power_on_to_power_good);
TRACE(("\tdevice_removeable:...0x%02x\n", fHubDescriptor.device_removeable)); TRACE("\tdevice_removeable:...0x%02x\n", fHubDescriptor.device_removeable);
TRACE(("\tpower_control_mask:..0x%02x\n", fHubDescriptor.power_control_mask)); TRACE("\tpower_control_mask:..0x%02x\n", fHubDescriptor.power_control_mask);
if (fHubDescriptor.num_ports > USB_MAX_PORT_COUNT) { if (fHubDescriptor.num_ports > USB_MAX_PORT_COUNT) {
TRACE_ERROR(("USB Hub %d: hub supports more ports than we do (%d vs. %d)\n", TRACE_ALWAYS("hub supports more ports than we do (%d vs. %d)\n",
DeviceAddress(), fHubDescriptor.num_ports, USB_MAX_PORT_COUNT)); fHubDescriptor.num_ports, USB_MAX_PORT_COUNT);
fHubDescriptor.num_ports = USB_MAX_PORT_COUNT; fHubDescriptor.num_ports = USB_MAX_PORT_COUNT;
} }
@@ -70,7 +70,7 @@ Hub::Hub(Object *parent, int8 hubAddress, uint8 hubPort,
fInterruptPipe->QueueInterrupt(fInterruptStatus, fInterruptPipe->QueueInterrupt(fInterruptStatus,
sizeof(fInterruptStatus), InterruptCallback, this); sizeof(fInterruptStatus), InterruptCallback, this);
} else { } else {
TRACE_ERROR(("USB Hub %d: no interrupt pipe found\n", DeviceAddress())); TRACE_ALWAYS("no interrupt pipe found\n");
} }
// Wait some time before powering up the ports // Wait some time before powering up the ports
@@ -83,14 +83,14 @@ Hub::Hub(Object *parent, int8 hubAddress, uint8 hubPort,
USB_REQUEST_SET_FEATURE, PORT_POWER, i + 1, 0, NULL, 0, NULL); USB_REQUEST_SET_FEATURE, PORT_POWER, i + 1, 0, NULL, 0, NULL);
if (status < B_OK) if (status < B_OK)
TRACE_ERROR(("USB Hub %d: power up failed on port %ld\n", DeviceAddress(), i)); TRACE_ERROR("power up failed on port %ld\n", i);
} }
// Wait for power to stabilize // Wait for power to stabilize
snooze(fHubDescriptor.power_on_to_power_good * 2000); snooze(fHubDescriptor.power_on_to_power_good * 2000);
fInitOK = true; fInitOK = true;
TRACE(("USB Hub %d: initialised ok\n", DeviceAddress())); TRACE("initialised ok\n");
} }
@@ -129,7 +129,7 @@ Hub::UpdatePortStatus(uint8 index)
4, &actualLength); 4, &actualLength);
if (result < B_OK || actualLength < 4) { if (result < B_OK || actualLength < 4) {
TRACE_ERROR(("USB Hub %d: error updating port status\n", DeviceAddress())); TRACE_ERROR("error updating port status\n");
return B_ERROR; return B_ERROR;
} }
@@ -160,7 +160,7 @@ Hub::ResetPort(uint8 index)
} }
if ((fPortStatus[index].change & C_PORT_RESET) == 0) { if ((fPortStatus[index].change & C_PORT_RESET) == 0) {
TRACE_ERROR(("USB Hub %d: port %d won't reset\n", DeviceAddress(), index)); TRACE_ERROR("port %d won't reset\n", index);
return B_ERROR; return B_ERROR;
} }
@@ -172,7 +172,7 @@ Hub::ResetPort(uint8 index)
// wait for reset recovery // wait for reset recovery
snooze(USB_DELAY_PORT_RESET_RECOVERY); snooze(USB_DELAY_PORT_RESET_RECOVERY);
TRACE(("USB Hub %d: port %d was reset successfully\n", DeviceAddress(), index)); TRACE("port %d was reset successfully\n", index);
return B_OK; return B_OK;
} }
@@ -197,8 +197,10 @@ Hub::Explore(change_item **changeList)
#ifdef TRACE_USB #ifdef TRACE_USB
if (fPortStatus[i].change) { if (fPortStatus[i].change) {
TRACE(("USB Hub %d: port %ld: status: 0x%04x; change: 0x%04x\n", DeviceAddress(), i, fPortStatus[i].status, fPortStatus[i].change)); TRACE("port %ld: status: 0x%04x; change: 0x%04x\n", i,
TRACE(("USB Hub %d: device at port %ld: 0x%08lx\n", DeviceAddress(), i, fChildren[i])); fPortStatus[i].status, fPortStatus[i].change);
TRACE("device at port %ld: %p (%ld)\n", i, fChildren[i],
fChildren[i] != NULL ? fChildren[i]->USBID() : 0);
} }
#endif #endif
@@ -210,7 +212,7 @@ Hub::Explore(change_item **changeList)
if (fPortStatus[i].status & PORT_STATUS_CONNECTION) { if (fPortStatus[i].status & PORT_STATUS_CONNECTION) {
// new device attached! // new device attached!
TRACE(("USB Hub %d: new device connected\n", DeviceAddress())); TRACE_ALWAYS("port %ld: new device connected\n", i);
// wait some time for the device to power up // wait some time for the device to power up
snooze(USB_DELAY_DEVICE_POWER_UP); snooze(USB_DELAY_DEVICE_POWER_UP);
@@ -218,7 +220,7 @@ Hub::Explore(change_item **changeList)
// reset the port, this will also enable it // reset the port, this will also enable it
result = ResetPort(i); result = ResetPort(i);
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("USB Hub %d: resetting port %ld failed\n", DeviceAddress(), i)); TRACE_ERROR("resetting port %ld failed\n", i);
continue; continue;
} }
@@ -228,12 +230,12 @@ Hub::Explore(change_item **changeList)
if ((fPortStatus[i].status & PORT_STATUS_CONNECTION) == 0) { if ((fPortStatus[i].status & PORT_STATUS_CONNECTION) == 0) {
// device has vanished after reset, ignore // device has vanished after reset, ignore
TRACE(("USB Hub %d: device disappeared on reset\n", DeviceAddress())); TRACE("device disappeared on reset\n");
continue; continue;
} }
if (fChildren[i]) { if (fChildren[i] != NULL) {
TRACE_ERROR(("USB Hub %d: new device on a port that is already in use\n", DeviceAddress())); TRACE_ERROR("new device on a port that is already in use\n");
fChildren[i]->Changed(changeList, false); fChildren[i]->Changed(changeList, false);
fChildren[i] = NULL; fChildren[i] = NULL;
} }
@@ -251,7 +253,7 @@ Hub::Explore(change_item **changeList)
int8 hubAddress = HubAddress(); int8 hubAddress = HubAddress();
uint8 hubPort = HubPort(); uint8 hubPort = HubPort();
if (Speed() == USB_SPEED_HIGHSPEED) { if (Speed() == USB_SPEED_HIGHSPEED) {
hubAddress = DeviceAddress(); hubAddress = USBID();
hubPort = i + 1; hubPort = i + 1;
} }
@@ -269,9 +271,9 @@ Hub::Explore(change_item **changeList)
} }
} else { } else {
// Device removed... // Device removed...
TRACE(("USB Hub %d: device removed\n", DeviceAddress())); TRACE_ALWAYS("port %ld: device removed\n", i);
if (fChildren[i]) { if (fChildren[i] != NULL) {
TRACE(("USB Hub %d: removing device 0x%08lx\n", DeviceAddress(), fChildren[i])); TRACE("removing device %p\n", fChildren[i]);
fChildren[i]->Changed(changeList, false); fChildren[i]->Changed(changeList, false);
fChildren[i] = NULL; fChildren[i] = NULL;
} }
@@ -280,28 +282,28 @@ Hub::Explore(change_item **changeList)
// other port changes we do not really handle, report and clear them // other port changes we do not really handle, report and clear them
if (fPortStatus[i].change & PORT_STATUS_ENABLE) { if (fPortStatus[i].change & PORT_STATUS_ENABLE) {
TRACE_ERROR(("USB Hub %d: port %ld %sabled\n", DeviceAddress(), i, (fPortStatus[i].status & PORT_STATUS_ENABLE) ? "en" : "dis")); TRACE_ALWAYS("port %ld %sabled\n", i, (fPortStatus[i].status & PORT_STATUS_ENABLE) ? "en" : "dis");
DefaultPipe()->SendRequest(USB_REQTYPE_CLASS | USB_REQTYPE_OTHER_OUT, DefaultPipe()->SendRequest(USB_REQTYPE_CLASS | USB_REQTYPE_OTHER_OUT,
USB_REQUEST_CLEAR_FEATURE, C_PORT_ENABLE, i + 1, USB_REQUEST_CLEAR_FEATURE, C_PORT_ENABLE, i + 1,
0, NULL, 0, NULL); 0, NULL, 0, NULL);
} }
if (fPortStatus[i].change & PORT_STATUS_SUSPEND) { if (fPortStatus[i].change & PORT_STATUS_SUSPEND) {
TRACE_ERROR(("USB Hub %d: port %ld is %ssuspended\n", DeviceAddress(), i, (fPortStatus[i].status & PORT_STATUS_SUSPEND) ? "" : "not ")); TRACE_ALWAYS("port %ld is %ssuspended\n", i, (fPortStatus[i].status & PORT_STATUS_SUSPEND) ? "" : "not ");
DefaultPipe()->SendRequest(USB_REQTYPE_CLASS | USB_REQTYPE_OTHER_OUT, DefaultPipe()->SendRequest(USB_REQTYPE_CLASS | USB_REQTYPE_OTHER_OUT,
USB_REQUEST_CLEAR_FEATURE, C_PORT_SUSPEND, i + 1, USB_REQUEST_CLEAR_FEATURE, C_PORT_SUSPEND, i + 1,
0, NULL, 0, NULL); 0, NULL, 0, NULL);
} }
if (fPortStatus[i].change & PORT_STATUS_OVER_CURRENT) { if (fPortStatus[i].change & PORT_STATUS_OVER_CURRENT) {
TRACE_ERROR(("USB Hub %d: port %ld is %sin an over current state\n", DeviceAddress(), i, (fPortStatus[i].status & PORT_STATUS_OVER_CURRENT) ? "" : "not ")); TRACE_ALWAYS("port %ld is %sin an over current state\n", i, (fPortStatus[i].status & PORT_STATUS_OVER_CURRENT) ? "" : "not ");
DefaultPipe()->SendRequest(USB_REQTYPE_CLASS | USB_REQTYPE_OTHER_OUT, DefaultPipe()->SendRequest(USB_REQTYPE_CLASS | USB_REQTYPE_OTHER_OUT,
USB_REQUEST_CLEAR_FEATURE, C_PORT_OVER_CURRENT, i + 1, USB_REQUEST_CLEAR_FEATURE, C_PORT_OVER_CURRENT, i + 1,
0, NULL, 0, NULL); 0, NULL, 0, NULL);
} }
if (fPortStatus[i].change & PORT_RESET) { if (fPortStatus[i].change & PORT_RESET) {
TRACE_ERROR(("USB Hub %d: port %ld was reset\n", DeviceAddress(), i)); TRACE_ALWAYS("port %ld was reset\n", i);
DefaultPipe()->SendRequest(USB_REQTYPE_CLASS | USB_REQTYPE_OTHER_OUT, DefaultPipe()->SendRequest(USB_REQTYPE_CLASS | USB_REQTYPE_OTHER_OUT,
USB_REQUEST_CLEAR_FEATURE, C_PORT_RESET, i + 1, USB_REQUEST_CLEAR_FEATURE, C_PORT_RESET, i + 1,
0, NULL, 0, NULL); 0, NULL, 0, NULL);
@@ -322,7 +324,7 @@ void
Hub::InterruptCallback(void *cookie, status_t status, void *data, Hub::InterruptCallback(void *cookie, status_t status, void *data,
size_t actualLength) size_t actualLength)
{ {
TRACE(("USB Hub %d: interrupt callback!\n", ((Hub *)data)->DeviceAddress())); TRACE_STATIC((Hub *)cookie, "interrupt callback!\n");
} }
@@ -347,7 +349,7 @@ Hub::ReportDevice(usb_support_descriptor *supportDescriptors,
uint32 supportDescriptorCount, const usb_notify_hooks *hooks, uint32 supportDescriptorCount, const usb_notify_hooks *hooks,
usb_driver_cookie **cookies, bool added, bool recursive) usb_driver_cookie **cookies, bool added, bool recursive)
{ {
TRACE(("USB Hub %d: reporting hub\n", DeviceAddress())); TRACE("reporting hub\n");
// Report ourselfs first // Report ourselfs first
status_t result = Device::ReportDevice(supportDescriptors, status_t result = Device::ReportDevice(supportDescriptors,
@@ -13,12 +13,14 @@ Interface::Interface(Object *parent, uint8 interfaceIndex)
: Object(parent), : Object(parent),
fInterfaceIndex(interfaceIndex) fInterfaceIndex(interfaceIndex)
{ {
TRACE("creating interface\n");
} }
status_t status_t
Interface::SetFeature(uint16 selector) Interface::SetFeature(uint16 selector)
{ {
TRACE("set feature %u\n", selector);
return ((Device *)Parent())->DefaultPipe()->SendRequest( return ((Device *)Parent())->DefaultPipe()->SendRequest(
USB_REQTYPE_STANDARD | USB_REQTYPE_INTERFACE_OUT, USB_REQTYPE_STANDARD | USB_REQTYPE_INTERFACE_OUT,
USB_REQUEST_SET_FEATURE, USB_REQUEST_SET_FEATURE,
@@ -34,6 +36,7 @@ Interface::SetFeature(uint16 selector)
status_t status_t
Interface::ClearFeature(uint16 selector) Interface::ClearFeature(uint16 selector)
{ {
TRACE("clear feature %u\n", selector);
return ((Device *)Parent())->DefaultPipe()->SendRequest( return ((Device *)Parent())->DefaultPipe()->SendRequest(
USB_REQTYPE_STANDARD | USB_REQTYPE_INTERFACE_OUT, USB_REQTYPE_STANDARD | USB_REQTYPE_INTERFACE_OUT,
USB_REQUEST_CLEAR_FEATURE, USB_REQUEST_CLEAR_FEATURE,
@@ -49,6 +52,7 @@ Interface::ClearFeature(uint16 selector)
status_t status_t
Interface::GetStatus(uint16 *status) Interface::GetStatus(uint16 *status)
{ {
TRACE("get status\n");
return ((Device *)Parent())->DefaultPipe()->SendRequest( return ((Device *)Parent())->DefaultPipe()->SendRequest(
USB_REQTYPE_STANDARD | USB_REQTYPE_INTERFACE_IN, USB_REQTYPE_STANDARD | USB_REQTYPE_INTERFACE_IN,
USB_REQUEST_GET_STATUS, USB_REQUEST_GET_STATUS,
@@ -37,7 +37,7 @@ status_t
Object::SetFeature(uint16 selector) Object::SetFeature(uint16 selector)
{ {
// to be implemented in subclasses // to be implemented in subclasses
TRACE_ERROR(("USB Object: set feature called\n")); TRACE_ERROR("set feature called\n");
return B_ERROR; return B_ERROR;
} }
@@ -46,7 +46,7 @@ status_t
Object::ClearFeature(uint16 selector) Object::ClearFeature(uint16 selector)
{ {
// to be implemented in subclasses // to be implemented in subclasses
TRACE_ERROR(("USB Object: clear feature called\n")); TRACE_ERROR("clear feature called\n");
return B_ERROR; return B_ERROR;
} }
@@ -55,6 +55,6 @@ status_t
Object::GetStatus(uint16 *status) Object::GetStatus(uint16 *status)
{ {
// to be implemented in subclasses // to be implemented in subclasses
TRACE_ERROR(("USB Object: get status called\n")); TRACE_ERROR("get status called\n");
return B_ERROR; return B_ERROR;
} }
+4 -1
View File
@@ -69,6 +69,7 @@ Pipe::CancelQueuedTransfers(bool force)
status_t status_t
Pipe::SetFeature(uint16 selector) Pipe::SetFeature(uint16 selector)
{ {
TRACE("set feature %u\n", selector);
return ((Device *)Parent())->DefaultPipe()->SendRequest( return ((Device *)Parent())->DefaultPipe()->SendRequest(
USB_REQTYPE_STANDARD | USB_REQTYPE_ENDPOINT_OUT, USB_REQTYPE_STANDARD | USB_REQTYPE_ENDPOINT_OUT,
USB_REQUEST_SET_FEATURE, USB_REQUEST_SET_FEATURE,
@@ -89,6 +90,7 @@ Pipe::ClearFeature(uint16 selector)
if (selector == USB_FEATURE_ENDPOINT_HALT) if (selector == USB_FEATURE_ENDPOINT_HALT)
SetDataToggle(false); SetDataToggle(false);
TRACE("clear feature %u\n", selector);
return ((Device *)Parent())->DefaultPipe()->SendRequest( return ((Device *)Parent())->DefaultPipe()->SendRequest(
USB_REQTYPE_STANDARD | USB_REQTYPE_ENDPOINT_OUT, USB_REQTYPE_STANDARD | USB_REQTYPE_ENDPOINT_OUT,
USB_REQUEST_CLEAR_FEATURE, USB_REQUEST_CLEAR_FEATURE,
@@ -105,6 +107,7 @@ Pipe::ClearFeature(uint16 selector)
status_t status_t
Pipe::GetStatus(uint16 *status) Pipe::GetStatus(uint16 *status)
{ {
TRACE("get status\n");
return ((Device *)Parent())->DefaultPipe()->SendRequest( return ((Device *)Parent())->DefaultPipe()->SendRequest(
USB_REQTYPE_STANDARD | USB_REQTYPE_ENDPOINT_IN, USB_REQTYPE_STANDARD | USB_REQTYPE_ENDPOINT_IN,
USB_REQUEST_GET_STATUS, USB_REQUEST_GET_STATUS,
@@ -336,7 +339,7 @@ ControlPipe::SendRequest(uint8 requestType, uint8 request, uint16 value,
// The sem will be released unconditionally in the callback after the // The sem will be released unconditionally in the callback after the
// result data was filled in. Use a 1 second timeout for control transfers. // result data was filled in. Use a 1 second timeout for control transfers.
if (acquire_sem_etc(fNotifySem, 1, B_RELATIVE_TIMEOUT, 1000000) < B_OK) { if (acquire_sem_etc(fNotifySem, 1, B_RELATIVE_TIMEOUT, 1000000) < B_OK) {
TRACE_ERROR(("USB ControlPipe: timeout waiting for queued request to complete\n")); TRACE_ERROR("timeout waiting for queued request to complete\n");
CancelQueuedTransfers(false); CancelQueuedTransfers(false);
+20 -20
View File
@@ -26,7 +26,7 @@ Stack::Stack()
fObjectArray(NULL), fObjectArray(NULL),
fDriverList(NULL) fDriverList(NULL)
{ {
TRACE(("USB Stack: stack init\n")); TRACE("stack init\n");
mutex_init(&fStackLock, "usb stack lock"); mutex_init(&fStackLock, "usb stack lock");
mutex_init(&fExploreLock, "usb explore lock"); mutex_init(&fExploreLock, "usb explore lock");
@@ -34,7 +34,7 @@ Stack::Stack()
size_t objectArraySize = fObjectMaxCount * sizeof(Object *); size_t objectArraySize = fObjectMaxCount * sizeof(Object *);
fObjectArray = (Object **)malloc(objectArraySize); fObjectArray = (Object **)malloc(objectArraySize);
if (fObjectArray == NULL) { if (fObjectArray == NULL) {
TRACE_ERROR(("USB Stack: failed to allocate object array\n")); TRACE_ERROR("failed to allocate object array\n");
return; return;
} }
@@ -43,7 +43,7 @@ Stack::Stack()
fAllocator = new(std::nothrow) PhysicalMemoryAllocator("USB Stack Allocator", fAllocator = new(std::nothrow) PhysicalMemoryAllocator("USB Stack Allocator",
8, B_PAGE_SIZE * 4, 64); 8, B_PAGE_SIZE * 4, 64);
if (!fAllocator || fAllocator->InitCheck() < B_OK) { if (!fAllocator || fAllocator->InitCheck() < B_OK) {
TRACE_ERROR(("USB Stack: failed to allocate the allocator\n")); TRACE_ERROR("failed to allocate the allocator\n");
delete fAllocator; delete fAllocator;
fAllocator = NULL; fAllocator = NULL;
return; return;
@@ -66,25 +66,25 @@ Stack::Stack()
NULL NULL
}; };
TRACE(("USB Stack: looking for host controller modules\n")); TRACE("looking for host controller modules\n");
for (uint32 i = 0; moduleNames[i]; i++) { for (uint32 i = 0; moduleNames[i]; i++) {
TRACE(("USB Stack: looking for module %s\n", moduleNames[i])); TRACE("looking for module %s\n", moduleNames[i]);
usb_host_controller_info *module = NULL; usb_host_controller_info *module = NULL;
if (get_module(moduleNames[i], (module_info **)&module) != B_OK) if (get_module(moduleNames[i], (module_info **)&module) != B_OK)
continue; continue;
TRACE(("USB Stack: adding module %s\n", moduleNames[i])); TRACE("adding module %s\n", moduleNames[i]);
if (module->add_to(this) < B_OK) { if (module->add_to(this) < B_OK) {
put_module(moduleNames[i]); put_module(moduleNames[i]);
continue; continue;
} }
TRACE(("USB Stack: module %s successfully loaded\n", moduleNames[i])); TRACE("module %s successfully loaded\n", moduleNames[i]);
} }
if (fBusManagers.Count() == 0) { if (fBusManagers.Count() == 0) {
TRACE_ERROR(("USB Stack: no bus managers available\n")); TRACE_ERROR("no bus managers available\n");
return; return;
} }
@@ -164,7 +164,7 @@ Stack::GetUSBID(Object *object)
id = (id + 1) % fObjectMaxCount; id = (id + 1) % fObjectMaxCount;
} }
TRACE_ERROR(("USB Stack: the stack did run out of usb_ids\n")); TRACE_ERROR("the stack did run out of usb_ids\n");
Unlock(); Unlock();
return 0; return 0;
} }
@@ -177,7 +177,7 @@ Stack::PutUSBID(usb_id id)
return; return;
if (id >= fObjectMaxCount) { if (id >= fObjectMaxCount) {
TRACE_ERROR(("USB Stack: tried to put an invalid usb_id\n")); TRACE_ERROR("tried to put an invalid usb_id\n");
Unlock(); Unlock();
return; return;
} }
@@ -194,7 +194,7 @@ Stack::GetObject(usb_id id)
return NULL; return NULL;
if (id >= fObjectMaxCount) { if (id >= fObjectMaxCount) {
TRACE_ERROR(("USB Stack: tried to get object with invalid usb_id\n")); TRACE_ERROR("tried to get object with invalid usb_id\n");
Unlock(); Unlock();
return NULL; return NULL;
} }
@@ -285,7 +285,7 @@ area_id
Stack::AllocateArea(void **logicalAddress, void **physicalAddress, size_t size, Stack::AllocateArea(void **logicalAddress, void **physicalAddress, size_t size,
const char *name) const char *name)
{ {
TRACE(("USB Stack: allocating %ld bytes for %s\n", size, name)); TRACE("allocating %ld bytes for %s\n", size, name);
void *logAddress; void *logAddress;
size = (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); size = (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
@@ -293,7 +293,7 @@ Stack::AllocateArea(void **logicalAddress, void **physicalAddress, size_t size,
B_CONTIGUOUS, 0); B_CONTIGUOUS, 0);
if (area < B_OK) { if (area < B_OK) {
TRACE_ERROR(("USB Stack: couldn't allocate area %s\n", name)); TRACE_ERROR("couldn't allocate area %s\n", name);
return B_ERROR; return B_ERROR;
} }
@@ -301,7 +301,7 @@ Stack::AllocateArea(void **logicalAddress, void **physicalAddress, size_t size,
status_t result = get_memory_map(logAddress, size, &physicalEntry, 1); status_t result = get_memory_map(logAddress, size, &physicalEntry, 1);
if (result < B_OK) { if (result < B_OK) {
delete_area(area); delete_area(area);
TRACE_ERROR(("USB Stack: couldn't map area %s\n", name)); TRACE_ERROR("couldn't map area %s\n", name);
return B_ERROR; return B_ERROR;
} }
@@ -312,8 +312,8 @@ Stack::AllocateArea(void **logicalAddress, void **physicalAddress, size_t size,
if (physicalAddress) if (physicalAddress)
*physicalAddress = physicalEntry.address; *physicalAddress = physicalEntry.address;
TRACE(("USB Stack: area = 0x%08lx, size = %ld, log = 0x%08lx, phy = 0x%08lx\n", TRACE("area = %ld, size = %ld, log = %p, phy = %p\n",
area, size, logAddress, physicalEntry.address)); area, size, logAddress, physicalEntry.address);
return area; return area;
} }
@@ -321,7 +321,7 @@ Stack::AllocateArea(void **logicalAddress, void **physicalAddress, size_t size,
void void
Stack::NotifyDeviceChange(Device *device, rescan_item **rescanList, bool added) Stack::NotifyDeviceChange(Device *device, rescan_item **rescanList, bool added)
{ {
TRACE(("USB Stack: device %s\n", added ? "added" : "removed")); TRACE("device %s\n", added ? "added" : "removed");
usb_driver_info *element = fDriverList; usb_driver_info *element = fDriverList;
while (element) { while (element) {
@@ -393,7 +393,7 @@ Stack::RegisterDriver(const char *driverName,
const usb_support_descriptor *descriptors, const usb_support_descriptor *descriptors,
size_t descriptorCount, const char *republishDriverName) size_t descriptorCount, const char *republishDriverName)
{ {
TRACE(("USB Stack: register driver \"%s\"\n", driverName)); TRACE("register driver \"%s\"\n", driverName);
if (!driverName) if (!driverName)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -457,7 +457,7 @@ Stack::RegisterDriver(const char *driverName,
status_t status_t
Stack::InstallNotify(const char *driverName, const usb_notify_hooks *hooks) Stack::InstallNotify(const char *driverName, const usb_notify_hooks *hooks)
{ {
TRACE(("USB Stack: installing notify hooks for driver \"%s\"\n", driverName)); TRACE("installing notify hooks for driver \"%s\"\n", driverName);
usb_driver_info *element = fDriverList; usb_driver_info *element = fDriverList;
while (element) { while (element) {
@@ -492,7 +492,7 @@ Stack::InstallNotify(const char *driverName, const usb_notify_hooks *hooks)
status_t status_t
Stack::UninstallNotify(const char *driverName) Stack::UninstallNotify(const char *driverName)
{ {
TRACE(("USB Stack: uninstalling notify hooks for driver \"%s\"\n", driverName)); TRACE("uninstalling notify hooks for driver \"%s\"\n", driverName);
usb_driver_info *element = fDriverList; usb_driver_info *element = fDriverList;
while (element) { while (element) {
@@ -71,7 +71,7 @@ Transfer::SetData(uint8 *data, size_t dataLength)
// Calculate the bandwidth (only if it is not a bulk transfer) // Calculate the bandwidth (only if it is not a bulk transfer)
if (!(fPipe->Type() & USB_OBJECT_BULK_PIPE)) { if (!(fPipe->Type() & USB_OBJECT_BULK_PIPE)) {
if (_CalculateBandwidth() < B_OK) if (_CalculateBandwidth() < B_OK)
TRACE_ERROR(("USB Transfer: can't calculate bandwidth\n")); TRACE_ERROR("can't calculate bandwidth\n");
} }
} }
@@ -135,8 +135,7 @@ Transfer::InitKernelAccess()
if (IS_USER_ADDRESS(vector[i].iov_base)) { if (IS_USER_ADDRESS(vector[i].iov_base)) {
fUserArea = area_for(vector[i].iov_base); fUserArea = area_for(vector[i].iov_base);
if (fUserArea < B_OK) { if (fUserArea < B_OK) {
TRACE_ERROR(("USB Transfer: failed to find area for user" TRACE_ERROR("failed to find area for user space buffer!\n");
" space buffer!\n"));
return B_BAD_ADDRESS; return B_BAD_ADDRESS;
} }
break; break;
@@ -149,7 +148,7 @@ Transfer::InitKernelAccess()
area_info areaInfo; area_info areaInfo;
if (fUserArea < B_OK || get_area_info(fUserArea, &areaInfo) < B_OK) { if (fUserArea < B_OK || get_area_info(fUserArea, &areaInfo) < B_OK) {
TRACE_ERROR(("USB Transfer: couldn't get user area info\n")); TRACE_ERROR("couldn't get user area info\n");
return B_BAD_ADDRESS; return B_BAD_ADDRESS;
} }
@@ -158,7 +157,7 @@ Transfer::InitKernelAccess()
if ((size_t)vector[i].iov_base > areaInfo.size if ((size_t)vector[i].iov_base > areaInfo.size
|| (size_t)vector[i].iov_base + vector[i].iov_len > areaInfo.size) { || (size_t)vector[i].iov_base + vector[i].iov_len > areaInfo.size) {
TRACE_ERROR(("USB Transfer: data buffer spans across multiple areas!\n")); TRACE_ERROR("data buffer spans across multiple areas!\n");
return B_BAD_ADDRESS; return B_BAD_ADDRESS;
} }
} }
@@ -264,7 +263,7 @@ Transfer::_CalculateBandwidth()
default: default:
// We should never get here // We should never get here
TRACE(("USB Transfer: speed unknown")); TRACE("speed unknown");
return B_ERROR; return B_ERROR;
} }
+33 -22
View File
@@ -11,6 +11,7 @@
#include "usb_p.h" #include "usb_p.h"
#include <USB_rle.h> #include <USB_rle.h>
#define USB_MODULE_NAME "module"
Stack *gUSBStack = NULL; Stack *gUSBStack = NULL;
@@ -20,7 +21,7 @@ bus_std_ops(int32 op, ...)
{ {
switch (op) { switch (op) {
case B_MODULE_INIT: { case B_MODULE_INIT: {
TRACE(("usb_module: init\n")); TRACE_MODULE("init\n");
if (gUSBStack) if (gUSBStack)
return B_OK; return B_OK;
@@ -35,7 +36,7 @@ bus_std_ops(int32 op, ...)
if (shared >= B_OK && clone_area("usb stack clone", &address, if (shared >= B_OK && clone_area("usb stack clone", &address,
B_ANY_KERNEL_ADDRESS, B_KERNEL_READ_AREA, shared) >= B_OK) { B_ANY_KERNEL_ADDRESS, B_KERNEL_READ_AREA, shared) >= B_OK) {
gUSBStack = *((Stack **)address); gUSBStack = *((Stack **)address);
TRACE(("usb_module: found shared stack at %p\n", gUSBStack)); TRACE_MODULE("found shared stack at %p\n", gUSBStack);
return B_OK; return B_OK;
} }
#endif #endif
@@ -47,7 +48,7 @@ bus_std_ops(int32 op, ...)
#endif #endif
#endif #endif
Stack *stack = new(std::nothrow) Stack(); Stack *stack = new(std::nothrow) Stack();
TRACE(("usb_module: stack created %p\n", stack)); TRACE_MODULE("usb_module: stack created %p\n", stack);
if (!stack) if (!stack)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -69,7 +70,7 @@ bus_std_ops(int32 op, ...)
} }
case B_MODULE_UNINIT: case B_MODULE_UNINIT:
TRACE(("usb_module: uninit\n")); TRACE_MODULE("uninit\n");
delete gUSBStack; delete gUSBStack;
gUSBStack = NULL; gUSBStack = NULL;
break; break;
@@ -109,7 +110,7 @@ uninstall_notify(const char *driverName)
const usb_device_descriptor * const usb_device_descriptor *
get_device_descriptor(usb_device device) get_device_descriptor(usb_device device)
{ {
TRACE(("usb_module: get_device_descriptor(%ld)\n", device)); TRACE_MODULE("get_device_descriptor(%ld)\n", device);
Object *object = gUSBStack->GetObject(device); Object *object = gUSBStack->GetObject(device);
if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0) if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0)
return NULL; return NULL;
@@ -121,7 +122,7 @@ get_device_descriptor(usb_device device)
const usb_configuration_info * const usb_configuration_info *
get_nth_configuration(usb_device device, uint32 index) get_nth_configuration(usb_device device, uint32 index)
{ {
TRACE(("usb_module: get_nth_configuration(%ld, %d)\n", device, index)); TRACE_MODULE("get_nth_configuration(%ld, %lu)\n", device, index);
Object *object = gUSBStack->GetObject(device); Object *object = gUSBStack->GetObject(device);
if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0) if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0)
return NULL; return NULL;
@@ -133,7 +134,7 @@ get_nth_configuration(usb_device device, uint32 index)
const usb_configuration_info * const usb_configuration_info *
get_configuration(usb_device device) get_configuration(usb_device device)
{ {
TRACE(("usb_module: get_configuration(%ld)\n", device)); TRACE_MODULE("get_configuration(%ld)\n", device);
Object *object = gUSBStack->GetObject(device); Object *object = gUSBStack->GetObject(device);
if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0) if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0)
return NULL; return NULL;
@@ -146,7 +147,7 @@ status_t
set_configuration(usb_device device, set_configuration(usb_device device,
const usb_configuration_info *configuration) const usb_configuration_info *configuration)
{ {
TRACE(("usb_module: set_configuration(%ld, 0x%08lx)\n", device, configuration)); TRACE_MODULE("set_configuration(%ld, %p)\n", device, configuration);
Object *object = gUSBStack->GetObject(device); Object *object = gUSBStack->GetObject(device);
if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0) if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -158,7 +159,7 @@ set_configuration(usb_device device,
status_t status_t
set_alt_interface(usb_device device, const usb_interface_info *interface) set_alt_interface(usb_device device, const usb_interface_info *interface)
{ {
TRACE(("usb_module: set_alt_interface(%ld, 0x%08lx)\n", device, interface)); TRACE_MODULE("set_alt_interface(%ld, %p)\n", device, interface);
Object *object = gUSBStack->GetObject(device); Object *object = gUSBStack->GetObject(device);
if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0) if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -170,7 +171,7 @@ set_alt_interface(usb_device device, const usb_interface_info *interface)
status_t status_t
set_feature(usb_id handle, uint16 selector) set_feature(usb_id handle, uint16 selector)
{ {
TRACE(("usb_module: set_feature(%ld, %d)\n", handle, selector)); TRACE_MODULE("set_feature(%ld, %d)\n", handle, selector);
Object *object = gUSBStack->GetObject(handle); Object *object = gUSBStack->GetObject(handle);
if (!object) if (!object)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -182,7 +183,7 @@ set_feature(usb_id handle, uint16 selector)
status_t status_t
clear_feature(usb_id handle, uint16 selector) clear_feature(usb_id handle, uint16 selector)
{ {
TRACE(("usb_module: clear_feature(%ld, %d)\n", handle, selector)); TRACE_MODULE("clear_feature(%ld, %d)\n", handle, selector);
Object *object = gUSBStack->GetObject(handle); Object *object = gUSBStack->GetObject(handle);
if (!object) if (!object)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -194,7 +195,7 @@ clear_feature(usb_id handle, uint16 selector)
status_t status_t
get_status(usb_id handle, uint16 *status) get_status(usb_id handle, uint16 *status)
{ {
TRACE(("usb_module: get_status(%ld, 0x%08lx)\n", handle, status)); TRACE_MODULE("get_status(%ld, %p)\n", handle, status);
if (!status) if (!status)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -210,7 +211,8 @@ status_t
get_descriptor(usb_device device, uint8 type, uint8 index, uint16 languageID, get_descriptor(usb_device device, uint8 type, uint8 index, uint16 languageID,
void *data, size_t dataLength, size_t *actualLength) void *data, size_t dataLength, size_t *actualLength)
{ {
TRACE(("usb_module: get_descriptor(%ld, 0x%02x, 0x%02x, 0x%04x, 0x%08lx, %ld, 0x%08lx)\n", device, type, index, languageID, data, dataLength, actualLength)); TRACE_MODULE("get_descriptor(%ld, 0x%02x, 0x%02x, 0x%04x, %p, %ld, %p)\n",
device, type, index, languageID, data, dataLength, actualLength);
Object *object = gUSBStack->GetObject(device); Object *object = gUSBStack->GetObject(device);
if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0) if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -224,7 +226,8 @@ status_t
send_request(usb_device device, uint8 requestType, uint8 request, send_request(usb_device device, uint8 requestType, uint8 request,
uint16 value, uint16 index, uint16 length, void *data, size_t *actualLength) uint16 value, uint16 index, uint16 length, void *data, size_t *actualLength)
{ {
TRACE(("usb_module: send_request(%ld, 0x%02x, 0x%02x, 0x%04x, 0x%04x, %d, 0x%08lx, 0x%08lx)\n", device, requestType, request, value, index, length, data, actualLength)); TRACE_MODULE("send_request(%ld, 0x%02x, 0x%02x, 0x%04x, 0x%04x, %d, %p, %p)\n",
device, requestType, request, value, index, length, data, actualLength);
Object *object = gUSBStack->GetObject(device); Object *object = gUSBStack->GetObject(device);
if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0) if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -239,7 +242,9 @@ queue_request(usb_device device, uint8 requestType, uint8 request,
uint16 value, uint16 index, uint16 length, void *data, uint16 value, uint16 index, uint16 length, void *data,
usb_callback_func callback, void *callbackCookie) usb_callback_func callback, void *callbackCookie)
{ {
TRACE(("usb_module: queue_request(%ld, 0x%02x, 0x%02x, 0x%04x, 0x%04x, %ld, 0x%08lx, 0x%08lx, 0x%08lx)\n", device, requestType, request, value, index, length, data, callback, callbackCookie)); TRACE_MODULE("queue_request(%ld, 0x%02x, 0x%02x, 0x%04x, 0x%04x, %u, %p, %p, %p)\n",
device, requestType, request, value, index, length, data, callback,
callbackCookie);
Object *object = gUSBStack->GetObject(device); Object *object = gUSBStack->GetObject(device);
if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0) if (!object || (object->Type() & USB_OBJECT_DEVICE) == 0)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -253,7 +258,8 @@ status_t
queue_interrupt(usb_pipe pipe, void *data, size_t dataLength, queue_interrupt(usb_pipe pipe, void *data, size_t dataLength,
usb_callback_func callback, void *callbackCookie) usb_callback_func callback, void *callbackCookie)
{ {
TRACE(("usb_module: queue_interrupt(%ld, 0x%08lx, %ld, 0x%08lx, 0x%08lx)\n", pipe, data, dataLength, callback, callbackCookie)); TRACE_MODULE("queue_interrupt(%ld, %p, %ld, %p, %p)\n",
pipe, data, dataLength, callback, callbackCookie);
Object *object = gUSBStack->GetObject(pipe); Object *object = gUSBStack->GetObject(pipe);
if (!object || (object->Type() & USB_OBJECT_INTERRUPT_PIPE) == 0) if (!object || (object->Type() & USB_OBJECT_INTERRUPT_PIPE) == 0)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -267,7 +273,8 @@ status_t
queue_bulk(usb_pipe pipe, void *data, size_t dataLength, queue_bulk(usb_pipe pipe, void *data, size_t dataLength,
usb_callback_func callback, void *callbackCookie) usb_callback_func callback, void *callbackCookie)
{ {
TRACE(("usb_module: queue_bulk(%ld, 0x%08lx, %ld, 0x%08lx, 0x%08lx)\n", pipe, data, dataLength, callback, callbackCookie)); TRACE_MODULE("queue_bulk(%ld, %p, %ld, %p, %p)\n",
pipe, data, dataLength, callback, callbackCookie);
Object *object = gUSBStack->GetObject(pipe); Object *object = gUSBStack->GetObject(pipe);
if (!object || (object->Type() & USB_OBJECT_BULK_PIPE) == 0) if (!object || (object->Type() & USB_OBJECT_BULK_PIPE) == 0)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -281,7 +288,8 @@ status_t
queue_bulk_v(usb_pipe pipe, iovec *vector, size_t vectorCount, queue_bulk_v(usb_pipe pipe, iovec *vector, size_t vectorCount,
usb_callback_func callback, void *callbackCookie) usb_callback_func callback, void *callbackCookie)
{ {
TRACE(("usb_module: queue_bulk(%ld, 0x%08lx, %ld, 0x%08lx, 0x%08lx)\n", pipe, vector, vectorCount, callback, callbackCookie)); TRACE_MODULE("queue_bulk(%ld, %p, %ld, %p, %p)\n",
pipe, vector, vectorCount, callback, callbackCookie);
Object *object = gUSBStack->GetObject(pipe); Object *object = gUSBStack->GetObject(pipe);
if (!object || (object->Type() & USB_OBJECT_BULK_PIPE) == 0) if (!object || (object->Type() & USB_OBJECT_BULK_PIPE) == 0)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -297,7 +305,9 @@ queue_isochronous(usb_pipe pipe, void *data, size_t dataLength,
uint32 *startingFrameNumber, uint32 flags, usb_callback_func callback, uint32 *startingFrameNumber, uint32 flags, usb_callback_func callback,
void *callbackCookie) void *callbackCookie)
{ {
TRACE(("usb_module: queue_isochronous(%ld, 0x%08lx, %ld, 0x%08lx, %ld, 0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx)\n", pipe, data, dataLength, packetDesc, packetCount, startingFrameNumber, flags, callback, callbackCookie)); TRACE_MODULE("queue_isochronous(%ld, %p, %ld, %p, %ld, %p, 0x%08lx, %p, %p)\n",
pipe, data, dataLength, packetDesc, packetCount, startingFrameNumber,
flags, callback, callbackCookie);
Object *object = gUSBStack->GetObject(pipe); Object *object = gUSBStack->GetObject(pipe);
if (!object || (object->Type() & USB_OBJECT_ISO_PIPE) == 0) if (!object || (object->Type() & USB_OBJECT_ISO_PIPE) == 0)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -312,7 +322,8 @@ status_t
set_pipe_policy(usb_pipe pipe, uint8 maxQueuedPackets, set_pipe_policy(usb_pipe pipe, uint8 maxQueuedPackets,
uint16 maxBufferDurationMS, uint16 sampleSize) uint16 maxBufferDurationMS, uint16 sampleSize)
{ {
TRACE(("usb_module: set_pipe_policy(%ld, %d, %d, %d)\n", pipe, maxQueuedPackets, maxBufferDurationMS, sampleSize)); TRACE_MODULE("set_pipe_policy(%ld, %d, %d, %d)\n", pipe, maxQueuedPackets,
maxBufferDurationMS, sampleSize);
Object *object = gUSBStack->GetObject(pipe); Object *object = gUSBStack->GetObject(pipe);
if (!object || (object->Type() & USB_OBJECT_ISO_PIPE) == 0) if (!object || (object->Type() & USB_OBJECT_ISO_PIPE) == 0)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -325,7 +336,7 @@ set_pipe_policy(usb_pipe pipe, uint8 maxQueuedPackets,
status_t status_t
cancel_queued_transfers(usb_pipe pipe) cancel_queued_transfers(usb_pipe pipe)
{ {
TRACE(("usb_module: cancel_queued_transfers(%ld)\n", pipe)); TRACE_MODULE("cancel_queued_transfers(%ld)\n", pipe);
Object *object = gUSBStack->GetObject(pipe); Object *object = gUSBStack->GetObject(pipe);
if (!object || (object->Type() & USB_OBJECT_PIPE) == 0) if (!object || (object->Type() & USB_OBJECT_PIPE) == 0)
return B_DEV_INVALID_PIPE; return B_DEV_INVALID_PIPE;
@@ -337,7 +348,7 @@ cancel_queued_transfers(usb_pipe pipe)
status_t status_t
usb_ioctl(uint32 opcode, void *buffer, size_t bufferSize) usb_ioctl(uint32 opcode, void *buffer, size_t bufferSize)
{ {
TRACE(("usb_module: usb_ioctl(0x%08lx, 0x%08lx, %ld)\n", opcode, buffer, bufferSize)); TRACE_MODULE("usb_ioctl(%lu, %p, %ld)\n", opcode, buffer, bufferSize);
switch (opcode) { switch (opcode) {
case 'DNAM': { case 'DNAM': {
+36 -4
View File
@@ -14,15 +14,28 @@
#include "usbspec_p.h" #include "usbspec_p.h"
#include <lock.h> #include <lock.h>
#define TRACE_OUTPUT(x, y, z...) \
{ \
dprintf("usb %s%s %ld: ", y, (x)->TypeName(), (x)->USBID()); \
dprintf(z); \
}
//#define TRACE_USB //#define TRACE_USB
#ifdef TRACE_USB #ifdef TRACE_USB
#define TRACE(x) dprintf x #define TRACE(x...) TRACE_OUTPUT(this, "", x)
#define TRACE_ERROR(x) dprintf x #define TRACE_STATIC(x, y...) TRACE_OUTPUT(x, "", y)
#define TRACE_MODULE(x...) dprintf("usb "USB_MODULE_NAME": "x)
#else #else
#define TRACE(x) /* nothing */ #define TRACE(x...) /* nothing */
#define TRACE_ERROR(x) dprintf x #define TRACE_STATIC(x, y...) /* nothing */
#define TRACE_MODULE(x...) /* nothing */
#endif #endif
#define TRACE_ALWAYS(x...) TRACE_OUTPUT(this, "", x)
#define TRACE_ERROR(x...) TRACE_OUTPUT(this, "error ", x)
#define TRACE_MODULE_ALWAYS(x...) dprintf("usb "USB_MODULE_NAME": "x)
#define TRACE_MODULE_ERROR(x...) dprintf("usb "USB_MODULE_NAME": "x)
class Hub; class Hub;
class Stack; class Stack;
@@ -141,6 +154,9 @@ public:
const usb_notify_hooks *hooks); const usb_notify_hooks *hooks);
status_t UninstallNotify(const char *driverName); status_t UninstallNotify(const char *driverName);
usb_id USBID() { return 0; };
const char * TypeName() { return "stack"; };
private: private:
static int32 ExploreThread(void *data); static int32 ExploreThread(void *data);
@@ -199,6 +215,9 @@ virtual status_t NotifyPipeChange(Pipe *pipe,
Hub * GetRootHub() { return fRootHub; }; Hub * GetRootHub() { return fRootHub; };
void SetRootHub(Hub *hub) { fRootHub = hub; }; void SetRootHub(Hub *hub) { fRootHub = hub; };
usb_id USBID() { return fStack->IndexOfBusManager(this); };
virtual const char * TypeName() = 0;
protected: protected:
bool fInitOK; bool fInitOK;
@@ -210,6 +229,7 @@ private:
bool fDeviceMap[128]; bool fDeviceMap[128];
int8 fDeviceIndex; int8 fDeviceIndex;
Stack * fStack;
ControlPipe * fDefaultPipes[USB_SPEED_MAX + 1]; ControlPipe * fDefaultPipes[USB_SPEED_MAX + 1];
Hub * fRootHub; Hub * fRootHub;
Object * fRootObject; Object * fRootObject;
@@ -229,6 +249,7 @@ virtual ~Object();
usb_id USBID() { return fUSBID; }; usb_id USBID() { return fUSBID; };
virtual uint32 Type() { return USB_OBJECT_NONE; }; virtual uint32 Type() { return USB_OBJECT_NONE; };
virtual const char * TypeName() { return "object"; };
// Convenience functions for standard requests // Convenience functions for standard requests
virtual status_t SetFeature(uint16 selector); virtual status_t SetFeature(uint16 selector);
@@ -263,6 +284,7 @@ virtual ~Pipe();
int8 hubAddress, uint8 hubPort); int8 hubAddress, uint8 hubPort);
virtual uint32 Type() { return USB_OBJECT_PIPE; }; virtual uint32 Type() { return USB_OBJECT_PIPE; };
virtual const char * TypeName() { return "pipe"; };
int8 DeviceAddress() { return fDeviceAddress; }; int8 DeviceAddress() { return fDeviceAddress; };
usb_speed Speed() { return fSpeed; }; usb_speed Speed() { return fSpeed; };
@@ -310,6 +332,7 @@ public:
virtual ~ControlPipe(); virtual ~ControlPipe();
virtual uint32 Type() { return USB_OBJECT_PIPE | USB_OBJECT_CONTROL_PIPE; }; virtual uint32 Type() { return USB_OBJECT_PIPE | USB_OBJECT_CONTROL_PIPE; };
virtual const char * TypeName() { return "control pipe"; };
// The data toggle is not relevant // The data toggle is not relevant
// for control transfers, as they are // for control transfers, as they are
@@ -348,6 +371,7 @@ public:
InterruptPipe(Object *parent); InterruptPipe(Object *parent);
virtual uint32 Type() { return USB_OBJECT_PIPE | USB_OBJECT_INTERRUPT_PIPE; }; virtual uint32 Type() { return USB_OBJECT_PIPE | USB_OBJECT_INTERRUPT_PIPE; };
virtual const char * TypeName() { return "interrupt pipe"; };
status_t QueueInterrupt(void *data, status_t QueueInterrupt(void *data,
size_t dataLength, size_t dataLength,
@@ -361,6 +385,7 @@ public:
BulkPipe(Object *parent); BulkPipe(Object *parent);
virtual uint32 Type() { return USB_OBJECT_PIPE | USB_OBJECT_BULK_PIPE; }; virtual uint32 Type() { return USB_OBJECT_PIPE | USB_OBJECT_BULK_PIPE; };
virtual const char * TypeName() { return "bulk pipe"; };
status_t QueueBulk(void *data, status_t QueueBulk(void *data,
size_t dataLength, size_t dataLength,
@@ -378,6 +403,7 @@ public:
IsochronousPipe(Object *parent); IsochronousPipe(Object *parent);
virtual uint32 Type() { return USB_OBJECT_PIPE | USB_OBJECT_ISO_PIPE; }; virtual uint32 Type() { return USB_OBJECT_PIPE | USB_OBJECT_ISO_PIPE; };
virtual const char * TypeName() { return "iso pipe"; };
status_t QueueIsochronous(void *data, status_t QueueIsochronous(void *data,
size_t dataLength, size_t dataLength,
@@ -408,6 +434,7 @@ public:
uint8 interfaceIndex); uint8 interfaceIndex);
virtual uint32 Type() { return USB_OBJECT_INTERFACE; }; virtual uint32 Type() { return USB_OBJECT_INTERFACE; };
virtual const char * TypeName() { return "interface"; };
// Convenience functions for standard requests // Convenience functions for standard requests
virtual status_t SetFeature(uint16 selector); virtual status_t SetFeature(uint16 selector);
@@ -434,6 +461,7 @@ virtual status_t Changed(change_item **changeList,
bool added); bool added);
virtual uint32 Type() { return USB_OBJECT_DEVICE; }; virtual uint32 Type() { return USB_OBJECT_DEVICE; };
virtual const char * TypeName() { return "device"; };
ControlPipe * DefaultPipe() { return fDefaultPipe; }; ControlPipe * DefaultPipe() { return fDefaultPipe; };
@@ -505,6 +533,7 @@ virtual status_t Changed(change_item **changeList,
bool added); bool added);
virtual uint32 Type() { return USB_OBJECT_DEVICE | USB_OBJECT_HUB; }; virtual uint32 Type() { return USB_OBJECT_DEVICE | USB_OBJECT_HUB; };
virtual const char * TypeName() { return "hub"; };
virtual status_t GetDescriptor(uint8 descriptorType, virtual status_t GetDescriptor(uint8 descriptorType,
uint8 index, uint16 languageID, uint8 index, uint16 languageID,
@@ -589,6 +618,9 @@ public:
void Finished(uint32 status, size_t actualLength); void Finished(uint32 status, size_t actualLength);
usb_id USBID() { return 0; };
const char * TypeName() { return "transfer"; };
private: private:
status_t _CalculateBandwidth(); status_t _CalculateBandwidth();
+76 -71
View File
@@ -13,6 +13,8 @@
#include "ehci.h" #include "ehci.h"
#define USB_MODULE_NAME "ehci"
pci_module_info *EHCI::sPCIModule = NULL; pci_module_info *EHCI::sPCIModule = NULL;
@@ -21,10 +23,10 @@ ehci_std_ops(int32 op, ...)
{ {
switch (op) { switch (op) {
case B_MODULE_INIT: case B_MODULE_INIT:
TRACE(("usb_ehci_module: init module\n")); TRACE_MODULE("ehci init module\n");
return B_OK; return B_OK;
case B_MODULE_UNINIT: case B_MODULE_UNINIT:
TRACE(("usb_ehci_module: uninit module\n")); TRACE_MODULE("ehci uninit module\n");
return B_OK; return B_OK;
} }
@@ -124,11 +126,11 @@ EHCI::EHCI(pci_info *info, Stack *stack)
fPortSuspendChange(0) fPortSuspendChange(0)
{ {
if (BusManager::InitCheck() < B_OK) { if (BusManager::InitCheck() < B_OK) {
TRACE_ERROR(("usb_ehci: bus manager failed to init\n")); TRACE_ERROR("bus manager failed to init\n");
return; return;
} }
TRACE(("usb_ehci: constructing new EHCI Host Controller Driver\n")); TRACE("constructing new EHCI host controller driver\n");
fInitOK = false; fInitOK = false;
// enable busmaster and memory mapped access // enable busmaster and memory mapped access
@@ -146,23 +148,26 @@ EHCI::EHCI(pci_info *info, Stack *stack)
size_t mapSize = (fPCIInfo->u.h0.base_register_sizes[0] + offset size_t mapSize = (fPCIInfo->u.h0.base_register_sizes[0] + offset
+ B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
TRACE(("usb_ehci: map physical memory 0x%08lx (base: 0x%08lx; offset: %lx); size: %ld\n", fPCIInfo->u.h0.base_registers[0], physicalAddress, offset, fPCIInfo->u.h0.base_register_sizes[0])); TRACE("map physical memory 0x%08lx (base: 0x%08lx; offset: %lx); size: %ld\n",
fPCIInfo->u.h0.base_registers[0], physicalAddress, offset,
fPCIInfo->u.h0.base_register_sizes[0]);
fRegisterArea = map_physical_memory("EHCI memory mapped registers", fRegisterArea = map_physical_memory("EHCI memory mapped registers",
(void *)physicalAddress, mapSize, B_ANY_KERNEL_BLOCK_ADDRESS, (void *)physicalAddress, mapSize, B_ANY_KERNEL_BLOCK_ADDRESS,
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_READ_AREA | B_WRITE_AREA, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_READ_AREA | B_WRITE_AREA,
(void **)&fCapabilityRegisters); (void **)&fCapabilityRegisters);
if (fRegisterArea < B_OK) { if (fRegisterArea < B_OK) {
TRACE(("usb_ehci: failed to map register memory\n")); TRACE("failed to map register memory\n");
return; return;
} }
fCapabilityRegisters += offset; fCapabilityRegisters += offset;
fOperationalRegisters = fCapabilityRegisters + ReadCapReg8(EHCI_CAPLENGTH); fOperationalRegisters = fCapabilityRegisters + ReadCapReg8(EHCI_CAPLENGTH);
TRACE(("usb_ehci: mapped capability registers: 0x%08lx\n", (uint32)fCapabilityRegisters)); TRACE("mapped capability registers: 0x%08lx\n", (uint32)fCapabilityRegisters);
TRACE(("usb_ehci: mapped operational registers: 0x%08lx\n", (uint32)fOperationalRegisters)); TRACE("mapped operational registers: 0x%08lx\n", (uint32)fOperationalRegisters);
TRACE(("usb_ehci: structural parameters: 0x%08lx\n", ReadCapReg32(EHCI_HCSPARAMS))); TRACE("structural parameters: 0x%08lx\n", ReadCapReg32(EHCI_HCSPARAMS));
TRACE(("usb_ehci: capability parameters: 0x%08lx\n", ReadCapReg32(EHCI_HCCPARAMS))); TRACE("capability parameters: 0x%08lx\n", ReadCapReg32(EHCI_HCCPARAMS));
// read port count from capability register // read port count from capability register
fPortCount = ReadCapReg32(EHCI_HCSPARAMS) & 0x0f; fPortCount = ReadCapReg32(EHCI_HCSPARAMS) & 0x0f;
@@ -170,15 +175,15 @@ EHCI::EHCI(pci_info *info, Stack *stack)
uint32 extendedCapPointer = ReadCapReg32(EHCI_HCCPARAMS) >> EHCI_ECP_SHIFT; uint32 extendedCapPointer = ReadCapReg32(EHCI_HCCPARAMS) >> EHCI_ECP_SHIFT;
extendedCapPointer &= EHCI_ECP_MASK; extendedCapPointer &= EHCI_ECP_MASK;
if (extendedCapPointer > 0) { if (extendedCapPointer > 0) {
TRACE(("usb_ehci: extended capabilities register at %ld\n", extendedCapPointer)); TRACE("extended capabilities register at %ld\n", extendedCapPointer);
uint32 legacySupport = sPCIModule->read_pci_config(fPCIInfo->bus, uint32 legacySupport = sPCIModule->read_pci_config(fPCIInfo->bus,
fPCIInfo->device, fPCIInfo->function, extendedCapPointer, 4); fPCIInfo->device, fPCIInfo->function, extendedCapPointer, 4);
if ((legacySupport & EHCI_LEGSUP_CAPID_MASK) == EHCI_LEGSUP_CAPID) { if ((legacySupport & EHCI_LEGSUP_CAPID_MASK) == EHCI_LEGSUP_CAPID) {
if (legacySupport & EHCI_LEGSUP_BIOSOWNED) if (legacySupport & EHCI_LEGSUP_BIOSOWNED)
dprintf("usb_ehci: the host controller is bios owned\n"); TRACE_ALWAYS("the host controller is bios owned\n");
dprintf("usb_ehci: claiming ownership of the host controller\n"); TRACE_ALWAYS("claiming ownership of the host controller\n");
sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device, sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device,
fPCIInfo->function, extendedCapPointer + 3, 1, 1); fPCIInfo->function, extendedCapPointer + 3, 1, 1);
@@ -187,14 +192,14 @@ EHCI::EHCI(pci_info *info, Stack *stack)
fPCIInfo->device, fPCIInfo->function, extendedCapPointer, 4); fPCIInfo->device, fPCIInfo->function, extendedCapPointer, 4);
if (legacySupport & EHCI_LEGSUP_BIOSOWNED) { if (legacySupport & EHCI_LEGSUP_BIOSOWNED) {
dprintf("usb_ehci: controller is still bios owned, waiting\n"); TRACE_ALWAYS("controller is still bios owned, waiting\n");
snooze(50000); snooze(50000);
} else } else
break; break;
} }
if (legacySupport & EHCI_LEGSUP_BIOSOWNED) { if (legacySupport & EHCI_LEGSUP_BIOSOWNED) {
TRACE_ERROR(("usb_ehci: bios won't give up control over the host controller (ignoring)\n")); TRACE_ERROR("bios won't give up control over the host controller (ignoring)\n");
// turn off the BIOS owned flag, clear all SMIs and continue // turn off the BIOS owned flag, clear all SMIs and continue
sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device, sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device,
@@ -202,13 +207,13 @@ EHCI::EHCI(pci_info *info, Stack *stack)
sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device, sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device,
fPCIInfo->function, extendedCapPointer + 4, 4, 0); fPCIInfo->function, extendedCapPointer + 4, 4, 0);
} else if (legacySupport & EHCI_LEGSUP_OSOWNED) { } else if (legacySupport & EHCI_LEGSUP_OSOWNED) {
dprintf("usb_ehci: successfully took ownership of the host controller\n"); TRACE_ALWAYS("successfully took ownership of the host controller\n");
} }
} else { } else {
TRACE(("usb_ehci: extended capability is not a legacy support register\n")); TRACE("extended capability is not a legacy support register\n");
} }
} else { } else {
TRACE(("usb_ehci: no extended capabilities register\n")); TRACE("no extended capabilities register\n");
} }
// disable interrupts // disable interrupts
@@ -216,7 +221,7 @@ EHCI::EHCI(pci_info *info, Stack *stack)
// reset the host controller // reset the host controller
if (ControllerReset() < B_OK) { if (ControllerReset() < B_OK) {
TRACE_ERROR(("usb_ehci: host controller failed to reset\n")); TRACE_ERROR("host controller failed to reset\n");
return; return;
} }
@@ -229,7 +234,7 @@ EHCI::EHCI(pci_info *info, Stack *stack)
fCleanupSem = create_sem(0, "EHCI Cleanup"); fCleanupSem = create_sem(0, "EHCI Cleanup");
if (fFinishTransfersSem < B_OK || fAsyncAdvanceSem < B_OK if (fFinishTransfersSem < B_OK || fAsyncAdvanceSem < B_OK
|| fCleanupSem < B_OK) { || fCleanupSem < B_OK) {
TRACE_ERROR(("usb_ehci: failed to create semaphores\n")); TRACE_ERROR("failed to create semaphores\n");
return; return;
} }
@@ -254,7 +259,7 @@ EHCI::EHCI(pci_info *info, Stack *stack)
fPeriodicFrameListArea = fStack->AllocateArea((void **)&fPeriodicFrameList, fPeriodicFrameListArea = fStack->AllocateArea((void **)&fPeriodicFrameList,
(void **)&physicalAddress, B_PAGE_SIZE * 2, "USB EHCI Periodic Framelist"); (void **)&physicalAddress, B_PAGE_SIZE * 2, "USB EHCI Periodic Framelist");
if (fPeriodicFrameListArea < B_OK) { if (fPeriodicFrameListArea < B_OK) {
TRACE_ERROR(("usb_ehci: unable to allocate periodic framelist\n")); TRACE_ERROR("unable to allocate periodic framelist\n");
return; return;
} }
@@ -262,7 +267,7 @@ EHCI::EHCI(pci_info *info, Stack *stack)
WriteOpReg(EHCI_PERIODICLISTBASE, (uint32)physicalAddress); WriteOpReg(EHCI_PERIODICLISTBASE, (uint32)physicalAddress);
// create the interrupt entries to support different polling intervals // create the interrupt entries to support different polling intervals
TRACE(("usb_ehci: creating interrupt entries\n")); TRACE("creating interrupt entries\n");
addr_t physicalBase = physicalAddress + B_PAGE_SIZE; addr_t physicalBase = physicalAddress + B_PAGE_SIZE;
uint8 *logicalBase = (uint8 *)fPeriodicFrameList + B_PAGE_SIZE; uint8 *logicalBase = (uint8 *)fPeriodicFrameList + B_PAGE_SIZE;
memset(logicalBase, 0, B_PAGE_SIZE); memset(logicalBase, 0, B_PAGE_SIZE);
@@ -287,7 +292,7 @@ EHCI::EHCI(pci_info *info, Stack *stack)
} }
// build flat interrupt tree // build flat interrupt tree
TRACE(("usb_ehci: build up interrupt links\n")); TRACE("build up interrupt links\n");
uint32 interval = 1024; uint32 interval = 1024;
uint32 intervalIndex = 10; uint32 intervalIndex = 10;
while (interval > 1) { while (interval > 1) {
@@ -320,7 +325,7 @@ EHCI::EHCI(pci_info *info, Stack *stack)
// allocate a queue head that will always stay in the async frame list // allocate a queue head that will always stay in the async frame list
fAsyncQueueHead = CreateQueueHead(); fAsyncQueueHead = CreateQueueHead();
if (!fAsyncQueueHead) { if (!fAsyncQueueHead) {
TRACE_ERROR(("usb_ehci: unable to allocate stray async queue head\n")); TRACE_ERROR("unable to allocate stray async queue head\n");
return; return;
} }
@@ -334,16 +339,16 @@ EHCI::EHCI(pci_info *info, Stack *stack)
WriteOpReg(EHCI_ASYNCLISTADDR, (uint32)fAsyncQueueHead->this_phy WriteOpReg(EHCI_ASYNCLISTADDR, (uint32)fAsyncQueueHead->this_phy
| EHCI_QH_TYPE_QH); | EHCI_QH_TYPE_QH);
TRACE(("usb_ehci: set the async list addr to 0x%08lx\n", ReadOpReg(EHCI_ASYNCLISTADDR))); TRACE("set the async list addr to 0x%08lx\n", ReadOpReg(EHCI_ASYNCLISTADDR));
fInitOK = true; fInitOK = true;
TRACE(("usb_ehci: EHCI Host Controller Driver constructed\n")); TRACE("EHCI host controller driver constructed\n");
} }
EHCI::~EHCI() EHCI::~EHCI()
{ {
TRACE(("usb_ehci: tear down EHCI Host Controller Driver\n")); TRACE("tear down EHCI host controller driver\n");
WriteOpReg(EHCI_USBCMD, 0); WriteOpReg(EHCI_USBCMD, 0);
WriteOpReg(EHCI_CONFIGFLAG, 0); WriteOpReg(EHCI_CONFIGFLAG, 0);
@@ -366,8 +371,8 @@ EHCI::~EHCI()
status_t status_t
EHCI::Start() EHCI::Start()
{ {
TRACE(("usb_ehci: starting EHCI Host Controller\n")); TRACE("starting EHCI host controller\n");
TRACE(("usb_ehci: usbcmd: 0x%08lx; usbsts: 0x%08lx\n", ReadOpReg(EHCI_USBCMD), ReadOpReg(EHCI_USBSTS))); TRACE("usbcmd: 0x%08lx; usbsts: 0x%08lx\n", ReadOpReg(EHCI_USBCMD), ReadOpReg(EHCI_USBSTS));
uint32 frameListSize = (ReadOpReg(EHCI_USBCMD) >> EHCI_USBCMD_FLS_SHIFT) uint32 frameListSize = (ReadOpReg(EHCI_USBCMD) >> EHCI_USBCMD_FLS_SHIFT)
& EHCI_USBCMD_FLS_MASK; & EHCI_USBCMD_FLS_MASK;
@@ -379,7 +384,7 @@ EHCI::Start()
bool running = false; bool running = false;
for (int32 i = 0; i < 10; i++) { for (int32 i = 0; i < 10; i++) {
uint32 status = ReadOpReg(EHCI_USBSTS); uint32 status = ReadOpReg(EHCI_USBSTS);
TRACE(("usb_ehci: try %ld: status 0x%08lx\n", i, status)); TRACE("try %ld: status 0x%08lx\n", i, status);
if (status & EHCI_USBSTS_HCHALTED) { if (status & EHCI_USBSTS_HCHALTED) {
snooze(10000); snooze(10000);
@@ -390,7 +395,7 @@ EHCI::Start()
} }
if (!running) { if (!running) {
TRACE(("usb_ehci: Host Controller didn't start\n")); TRACE("host controller didn't start\n");
return B_ERROR; return B_ERROR;
} }
@@ -401,17 +406,17 @@ EHCI::Start()
fRootHubAddress = AllocateAddress(); fRootHubAddress = AllocateAddress();
fRootHub = new(std::nothrow) EHCIRootHub(RootObject(), fRootHubAddress); fRootHub = new(std::nothrow) EHCIRootHub(RootObject(), fRootHubAddress);
if (!fRootHub) { if (!fRootHub) {
TRACE_ERROR(("usb_ehci: no memory to allocate root hub\n")); TRACE_ERROR("no memory to allocate root hub\n");
return B_NO_MEMORY; return B_NO_MEMORY;
} }
if (fRootHub->InitCheck() < B_OK) { if (fRootHub->InitCheck() < B_OK) {
TRACE_ERROR(("usb_ehci: root hub failed init check\n")); TRACE_ERROR("root hub failed init check\n");
return fRootHub->InitCheck(); return fRootHub->InitCheck();
} }
SetRootHub(fRootHub); SetRootHub(fRootHub);
dprintf("usb_ehci: successfully started the controller\n"); TRACE_ALWAYS("successfully started the controller\n");
return BusManager::Start(); return BusManager::Start();
} }
@@ -431,13 +436,13 @@ EHCI::SubmitTransfer(Transfer *transfer)
ehci_qh *queueHead = CreateQueueHead(); ehci_qh *queueHead = CreateQueueHead();
if (!queueHead) { if (!queueHead) {
TRACE_ERROR(("usb_ehci: failed to allocate queue head\n")); TRACE_ERROR("failed to allocate queue head\n");
return B_NO_MEMORY; return B_NO_MEMORY;
} }
status_t result = InitQueueHead(queueHead, pipe); status_t result = InitQueueHead(queueHead, pipe);
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("usb_ehci: failed to init queue head\n")); TRACE_ERROR("failed to init queue head\n");
FreeQueueHead(queueHead); FreeQueueHead(queueHead);
return result; return result;
} }
@@ -453,20 +458,20 @@ EHCI::SubmitTransfer(Transfer *transfer)
} }
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("usb_ehci: failed to fill transfer queue with data\n")); TRACE_ERROR("failed to fill transfer queue with data\n");
FreeQueueHead(queueHead); FreeQueueHead(queueHead);
return result; return result;
} }
result = AddPendingTransfer(transfer, queueHead, dataDescriptor, directionIn); result = AddPendingTransfer(transfer, queueHead, dataDescriptor, directionIn);
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("usb_ehci: failed to add pending transfer\n")); TRACE_ERROR("failed to add pending transfer\n");
FreeQueueHead(queueHead); FreeQueueHead(queueHead);
return result; return result;
} }
#ifdef TRACE_USB #ifdef TRACE_USB
TRACE(("usb_ehci: linking queue\n")); TRACE("linking queue\n");
print_queue(queueHead); print_queue(queueHead);
#endif #endif
@@ -476,7 +481,7 @@ EHCI::SubmitTransfer(Transfer *transfer)
result = LinkQueueHead(queueHead); result = LinkQueueHead(queueHead);
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("usb_ehci: failed to link queue head\n")); TRACE_ERROR("failed to link queue head\n");
FreeQueueHead(queueHead); FreeQueueHead(queueHead);
return result; return result;
} }
@@ -488,7 +493,7 @@ EHCI::SubmitTransfer(Transfer *transfer)
status_t status_t
EHCI::NotifyPipeChange(Pipe *pipe, usb_change change) EHCI::NotifyPipeChange(Pipe *pipe, usb_change change)
{ {
TRACE(("usb_ehci: pipe change %d for pipe 0x%08lx\n", change, (uint32)pipe)); TRACE("pipe change %d for pipe %p\n", change, pipe);
switch (change) { switch (change) {
case USB_CHANGE_CREATED: case USB_CHANGE_CREATED:
case USB_CHANGE_DESTROYED: { case USB_CHANGE_DESTROYED: {
@@ -521,12 +526,12 @@ EHCI::AddTo(Stack *stack)
if (!sPCIModule) { if (!sPCIModule) {
status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule); status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule);
if (status < B_OK) { if (status < B_OK) {
TRACE_ERROR(("usb_ehci: getting pci module failed! 0x%08lx\n", status)); TRACE_MODULE_ERROR("getting pci module failed! 0x%08lx\n", status);
return status; return status;
} }
} }
TRACE(("usb_ehci: searching devices\n")); TRACE_MODULE("searching devices\n");
bool found = false; bool found = false;
pci_info *item = new(std::nothrow) pci_info; pci_info *item = new(std::nothrow) pci_info;
if (!item) { if (!item) {
@@ -540,11 +545,11 @@ EHCI::AddTo(Stack *stack)
&& item->class_api == PCI_usb_ehci) { && item->class_api == PCI_usb_ehci) {
if (item->u.h0.interrupt_line == 0 if (item->u.h0.interrupt_line == 0
|| item->u.h0.interrupt_line == 0xFF) { || item->u.h0.interrupt_line == 0xFF) {
TRACE_ERROR(("usb_ehci: found device with invalid IRQ - check IRQ assignement\n")); TRACE_MODULE_ERROR("found device with invalid IRQ - check IRQ assignement\n");
continue; continue;
} }
TRACE(("usb_ehci: found device at IRQ %u\n", item->u.h0.interrupt_line)); TRACE_MODULE("found device at IRQ %u\n", item->u.h0.interrupt_line);
EHCI *bus = new(std::nothrow) EHCI(item, stack); EHCI *bus = new(std::nothrow) EHCI(item, stack);
if (!bus) { if (!bus) {
delete item; delete item;
@@ -554,7 +559,7 @@ EHCI::AddTo(Stack *stack)
} }
if (bus->InitCheck() < B_OK) { if (bus->InitCheck() < B_OK) {
TRACE_ERROR(("usb_ehci: bus failed init check\n")); TRACE_MODULE_ERROR("bus failed init check\n");
delete bus; delete bus;
continue; continue;
} }
@@ -569,7 +574,7 @@ EHCI::AddTo(Stack *stack)
} }
if (!found) { if (!found) {
TRACE_ERROR(("usb_ehci: no devices found\n")); TRACE_MODULE_ERROR("no devices found\n");
delete item; delete item;
sPCIModule = NULL; sPCIModule = NULL;
put_module(B_PCI_MODULE_NAME); put_module(B_PCI_MODULE_NAME);
@@ -697,12 +702,12 @@ EHCI::ClearPortFeature(uint8 index, uint16 feature)
status_t status_t
EHCI::ResetPort(uint8 index) EHCI::ResetPort(uint8 index)
{ {
TRACE(("usb_ehci: reset port %d\n", index)); TRACE("reset port %d\n", index);
uint32 portRegister = EHCI_PORTSC + index * sizeof(uint32); uint32 portRegister = EHCI_PORTSC + index * sizeof(uint32);
uint32 portStatus = ReadOpReg(portRegister) & EHCI_PORTSC_DATAMASK; uint32 portStatus = ReadOpReg(portRegister) & EHCI_PORTSC_DATAMASK;
if (portStatus & EHCI_PORTSC_DMINUS) { if (portStatus & EHCI_PORTSC_DMINUS) {
dprintf("usb_ehci: lowspeed device connected, giving up port ownership\n"); TRACE_ALWAYS("lowspeed device connected, giving up port ownership\n");
// there is a lowspeed device connected. // there is a lowspeed device connected.
// we give the ownership to a companion controller. // we give the ownership to a companion controller.
WriteOpReg(portRegister, portStatus | EHCI_PORTSC_PORTOWNER); WriteOpReg(portRegister, portStatus | EHCI_PORTSC_PORTOWNER);
@@ -721,12 +726,12 @@ EHCI::ResetPort(uint8 index)
portStatus = ReadOpReg(portRegister) & EHCI_PORTSC_DATAMASK; portStatus = ReadOpReg(portRegister) & EHCI_PORTSC_DATAMASK;
if (portStatus & EHCI_PORTSC_PORTRESET) { if (portStatus & EHCI_PORTSC_PORTRESET) {
TRACE_ERROR(("usb_ehci: port reset won't complete\n")); TRACE_ERROR("port reset won't complete\n");
return B_ERROR; return B_ERROR;
} }
if ((portStatus & EHCI_PORTSC_ENABLE) == 0) { if ((portStatus & EHCI_PORTSC_ENABLE) == 0) {
dprintf("usb_ehci: fullspeed device connected, giving up port ownership\n"); TRACE_ALWAYS("fullspeed device connected, giving up port ownership\n");
// the port was not enabled, this means that no high speed device is // the port was not enabled, this means that no high speed device is
// attached to this port. we give up ownership to a companion controler // attached to this port. we give up ownership to a companion controler
WriteOpReg(portRegister, portStatus | EHCI_PORTSC_PORTOWNER); WriteOpReg(portRegister, portStatus | EHCI_PORTSC_PORTOWNER);
@@ -802,33 +807,33 @@ EHCI::Interrupt()
int32 result = B_HANDLED_INTERRUPT; int32 result = B_HANDLED_INTERRUPT;
if (status & EHCI_USBSTS_USBINT) { if (status & EHCI_USBSTS_USBINT) {
TRACE(("usb_ehci: transfer finished\n")); TRACE("transfer finished\n");
acknowledge |= EHCI_USBSTS_USBINT; acknowledge |= EHCI_USBSTS_USBINT;
result = B_INVOKE_SCHEDULER; result = B_INVOKE_SCHEDULER;
finishTransfers = true; finishTransfers = true;
} }
if (status & EHCI_USBSTS_USBERRINT) { if (status & EHCI_USBSTS_USBERRINT) {
TRACE(("usb_ehci: transfer error\n")); TRACE("transfer error\n");
acknowledge |= EHCI_USBSTS_USBERRINT; acknowledge |= EHCI_USBSTS_USBERRINT;
result = B_INVOKE_SCHEDULER; result = B_INVOKE_SCHEDULER;
finishTransfers = true; finishTransfers = true;
} }
if (status & EHCI_USBSTS_PORTCHANGE) { if (status & EHCI_USBSTS_PORTCHANGE) {
TRACE(("usb_ehci: port change detected\n")); TRACE("port change detected\n");
acknowledge |= EHCI_USBSTS_PORTCHANGE; acknowledge |= EHCI_USBSTS_PORTCHANGE;
} }
if (status & EHCI_USBSTS_INTONAA) { if (status & EHCI_USBSTS_INTONAA) {
TRACE(("usb_ehci: interrupt on async advance\n")); TRACE("interrupt on async advance\n");
acknowledge |= EHCI_USBSTS_INTONAA; acknowledge |= EHCI_USBSTS_INTONAA;
asyncAdvance = true; asyncAdvance = true;
result = B_INVOKE_SCHEDULER; result = B_INVOKE_SCHEDULER;
} }
if (status & EHCI_USBSTS_HOSTSYSERR) { if (status & EHCI_USBSTS_HOSTSYSERR) {
TRACE_ERROR(("usb_ehci: host system error!\n")); TRACE_ERROR("host system error!\n");
acknowledge |= EHCI_USBSTS_HOSTSYSERR; acknowledge |= EHCI_USBSTS_HOSTSYSERR;
} }
@@ -989,7 +994,7 @@ EHCI::FinishTransfers()
if (!Lock()) if (!Lock())
continue; continue;
TRACE(("usb_ehci: finishing transfers\n")); TRACE("finishing transfers\n");
transfer_data *lastTransfer = NULL; transfer_data *lastTransfer = NULL;
transfer_data *transfer = fFirstTransfer; transfer_data *transfer = fFirstTransfer;
Unlock(); Unlock();
@@ -1003,13 +1008,13 @@ EHCI::FinishTransfers()
uint32 status = descriptor->token; uint32 status = descriptor->token;
if (status & EHCI_QTD_STATUS_ACTIVE) { if (status & EHCI_QTD_STATUS_ACTIVE) {
// still in progress // still in progress
TRACE(("usb_ehci: qtd (0x%08lx) still active\n", descriptor->this_phy)); TRACE("qtd (0x%08lx) still active\n", descriptor->this_phy);
break; break;
} }
if (status & EHCI_QTD_STATUS_ERRMASK) { if (status & EHCI_QTD_STATUS_ERRMASK) {
// a transfer error occured // a transfer error occured
TRACE_ERROR(("usb_ehci: qtd (0x%08lx) error: 0x%08lx\n", descriptor->this_phy, status)); TRACE_ERROR("qtd (0x%08lx) error: 0x%08lx\n", descriptor->this_phy, status);
uint8 errorCount = status >> EHCI_QTD_ERRCOUNT_SHIFT; uint8 errorCount = status >> EHCI_QTD_ERRCOUNT_SHIFT;
errorCount &= EHCI_QTD_ERRCOUNT_MASK; errorCount &= EHCI_QTD_ERRCOUNT_MASK;
@@ -1043,7 +1048,7 @@ EHCI::FinishTransfers()
if (descriptor->next_phy & EHCI_QTD_TERMINATE) { if (descriptor->next_phy & EHCI_QTD_TERMINATE) {
// we arrived at the last (stray) descriptor, we're done // we arrived at the last (stray) descriptor, we're done
TRACE(("usb_ehci: qtd (0x%08lx) done\n", descriptor->this_phy)); TRACE("qtd (0x%08lx) done\n", descriptor->this_phy);
callbackStatus = B_OK; callbackStatus = B_OK;
transferDone = true; transferDone = true;
break; break;
@@ -1188,7 +1193,7 @@ EHCI::CreateQueueHead()
void *physicalAddress; void *physicalAddress;
if (fStack->AllocateChunk((void **)&result, &physicalAddress, if (fStack->AllocateChunk((void **)&result, &physicalAddress,
sizeof(ehci_qh)) < B_OK) { sizeof(ehci_qh)) < B_OK) {
TRACE_ERROR(("usb_ehci: failed to allocate queue head\n")); TRACE_ERROR("failed to allocate queue head\n");
return NULL; return NULL;
} }
@@ -1199,7 +1204,7 @@ EHCI::CreateQueueHead()
ehci_qtd *descriptor = CreateDescriptor(0, 0); ehci_qtd *descriptor = CreateDescriptor(0, 0);
if (!descriptor) { if (!descriptor) {
TRACE_ERROR(("usb_ehci: failed to allocate initial qtd for queue head\n")); TRACE_ERROR("failed to allocate initial qtd for queue head\n");
fStack->FreeChunk(result, (void *)result->this_phy, sizeof(ehci_qh)); fStack->FreeChunk(result, (void *)result->this_phy, sizeof(ehci_qh));
return NULL; return NULL;
} }
@@ -1234,7 +1239,7 @@ EHCI::InitQueueHead(ehci_qh *queueHead, Pipe *pipe)
queueHead->endpoint_chars = EHCI_QH_CHARS_EPS_HIGH; queueHead->endpoint_chars = EHCI_QH_CHARS_EPS_HIGH;
break; break;
default: default:
TRACE_ERROR(("usb_ehci: unknown pipe speed\n")); TRACE_ERROR("unknown pipe speed\n");
return B_ERROR; return B_ERROR;
} }
@@ -1377,7 +1382,7 @@ EHCI::FillQueueWithRequest(Transfer *transfer, ehci_qh *queueHead,
directionIn ? EHCI_QTD_PID_OUT : EHCI_QTD_PID_IN); directionIn ? EHCI_QTD_PID_OUT : EHCI_QTD_PID_IN);
if (!setupDescriptor || !statusDescriptor) { if (!setupDescriptor || !statusDescriptor) {
TRACE_ERROR(("usb_ehci: failed to allocate descriptors\n")); TRACE_ERROR("failed to allocate descriptors\n");
FreeDescriptor(setupDescriptor); FreeDescriptor(setupDescriptor);
FreeDescriptor(statusDescriptor); FreeDescriptor(statusDescriptor);
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -1467,7 +1472,7 @@ EHCI::CreateDescriptor(size_t bufferSize, uint8 pid)
void *physicalAddress; void *physicalAddress;
if (fStack->AllocateChunk((void **)&result, &physicalAddress, if (fStack->AllocateChunk((void **)&result, &physicalAddress,
sizeof(ehci_qtd)) < B_OK) { sizeof(ehci_qtd)) < B_OK) {
TRACE_ERROR(("usb_ehci: failed to allocate a qtd\n")); TRACE_ERROR("failed to allocate a qtd\n");
return NULL; return NULL;
} }
@@ -1493,7 +1498,7 @@ EHCI::CreateDescriptor(size_t bufferSize, uint8 pid)
if (fStack->AllocateChunk(&result->buffer_log, &physicalAddress, if (fStack->AllocateChunk(&result->buffer_log, &physicalAddress,
bufferSize) < B_OK) { bufferSize) < B_OK) {
TRACE_ERROR(("usb_ehci: unable to allocate qtd buffer\n")); TRACE_ERROR("unable to allocate qtd buffer\n");
fStack->FreeChunk(result, (void *)result->this_phy, sizeof(ehci_qtd)); fStack->FreeChunk(result, (void *)result->this_phy, sizeof(ehci_qtd));
return NULL; return NULL;
} }
@@ -1621,7 +1626,7 @@ EHCI::WriteDescriptorChain(ehci_qtd *topDescriptor, iovec *vector,
if (vectorOffset >= vector[vectorIndex].iov_len) { if (vectorOffset >= vector[vectorIndex].iov_len) {
if (++vectorIndex >= vectorCount) { if (++vectorIndex >= vectorCount) {
TRACE(("usb_ehci: wrote descriptor chain (%ld bytes, no more vectors)\n", actualLength)); TRACE("wrote descriptor chain (%ld bytes, no more vectors)\n", actualLength);
return actualLength; return actualLength;
} }
@@ -1640,7 +1645,7 @@ EHCI::WriteDescriptorChain(ehci_qtd *topDescriptor, iovec *vector,
current = (ehci_qtd *)current->next_log; current = (ehci_qtd *)current->next_log;
} }
TRACE(("usb_ehci: wrote descriptor chain (%ld bytes)\n", actualLength)); TRACE("wrote descriptor chain (%ld bytes)\n", actualLength);
return actualLength; return actualLength;
} }
@@ -1677,7 +1682,7 @@ EHCI::ReadDescriptorChain(ehci_qtd *topDescriptor, iovec *vector,
if (vectorOffset >= vector[vectorIndex].iov_len) { if (vectorOffset >= vector[vectorIndex].iov_len) {
if (++vectorIndex >= vectorCount) { if (++vectorIndex >= vectorCount) {
TRACE(("usb_ehci: read descriptor chain (%ld bytes, no more vectors)\n", actualLength)); TRACE("read descriptor chain (%ld bytes, no more vectors)\n", actualLength);
*nextDataToggle = dataToggle > 0 ? true : false; *nextDataToggle = dataToggle > 0 ? true : false;
return actualLength; return actualLength;
} }
@@ -1697,7 +1702,7 @@ EHCI::ReadDescriptorChain(ehci_qtd *topDescriptor, iovec *vector,
current = (ehci_qtd *)current->next_log; current = (ehci_qtd *)current->next_log;
} }
TRACE(("usb_ehci: read descriptor chain (%ld bytes)\n", actualLength)); TRACE("read descriptor chain (%ld bytes)\n", actualLength);
*nextDataToggle = dataToggle > 0 ? true : false; *nextDataToggle = dataToggle > 0 ? true : false;
return actualLength; return actualLength;
} }
@@ -1722,7 +1727,7 @@ EHCI::ReadActualLength(ehci_qtd *topDescriptor, bool *nextDataToggle)
current = (ehci_qtd *)current->next_log; current = (ehci_qtd *)current->next_log;
} }
TRACE(("usb_ehci: read actual length (%ld bytes)\n", actualLength)); TRACE("read actual length (%ld bytes)\n", actualLength);
*nextDataToggle = dataToggle > 0 ? true : false; *nextDataToggle = dataToggle > 0 ? true : false;
return actualLength; return actualLength;
} }
+2
View File
@@ -51,6 +51,8 @@ static status_t AddTo(Stack *stack);
status_t ResetPort(uint8 index); status_t ResetPort(uint8 index);
status_t SuspendPort(uint8 index); status_t SuspendPort(uint8 index);
virtual const char * TypeName() { return "ehci"; };
private: private:
// Controller resets // Controller resets
status_t ControllerReset(); status_t ControllerReset();
+1 -1
View File
@@ -11,5 +11,5 @@ resource app_version {
variety = 0, variety = 0,
internal = 0, internal = 0,
short_info = "EHCI host controller driver", short_info = "EHCI host controller driver",
long_info = "Haiku EHCI HCD - Copyright 2006-2008, Haiku Inc." long_info = "Haiku EHCI HCD - Copyright 2006-2009, Haiku Inc."
}; };
+9 -7
View File
@@ -8,6 +8,8 @@
#include "ehci.h" #include "ehci.h"
#define USB_MODULE_NAME "ehci roothub"
static usb_device_descriptor sEHCIRootHubDevice = static usb_device_descriptor sEHCIRootHubDevice =
{ {
18, // Descriptor length 18, // Descriptor length
@@ -135,7 +137,7 @@ EHCIRootHub::ProcessTransfer(EHCI *ehci, Transfer *transfer)
return B_ERROR; return B_ERROR;
usb_request_data *request = transfer->RequestData(); usb_request_data *request = transfer->RequestData();
TRACE(("usb_ehci_roothub: request: %d\n", request->Request)); TRACE_MODULE("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;
@@ -169,12 +171,12 @@ EHCIRootHub::ProcessTransfer(EHCI *ehci, Transfer *transfer)
break; break;
} }
TRACE(("usb_ehci_roothub: set address: %d\n", request->Value)); TRACE_MODULE("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_ehci_roothub: get descriptor: %d\n", request->Value >> 8)); TRACE_MODULE("get descriptor: %d\n", request->Value >> 8);
switch (request->Value >> 8) { switch (request->Value >> 8) {
case USB_DESCRIPTOR_DEVICE: { case USB_DESCRIPTOR_DEVICE: {
@@ -228,11 +230,11 @@ EHCIRootHub::ProcessTransfer(EHCI *ehci, 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_ehci_roothub: clear feature: no hub changes\n")); TRACE_MODULE_ERROR("clear feature: no hub changes\n");
break; break;
} }
TRACE(("usb_ehci_roothub: clear feature: %d\n", request->Value)); TRACE_MODULE("clear feature: %d\n", request->Value);
if (ehci->ClearPortFeature(request->Index - 1, request->Value) >= B_OK) if (ehci->ClearPortFeature(request->Index - 1, request->Value) >= B_OK)
status = B_OK; status = B_OK;
break; break;
@@ -241,11 +243,11 @@ EHCIRootHub::ProcessTransfer(EHCI *ehci, 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_ehci_roothub: set feature: no hub changes\n")); TRACE_MODULE_ERROR("set feature: no hub changes\n");
break; break;
} }
TRACE(("usb_ehci_roothub: set feature: %d\n", request->Value)); TRACE_MODULE("set feature: %d\n", request->Value);
if (ehci->SetPortFeature(request->Index - 1, request->Value) >= B_OK) if (ehci->SetPortFeature(request->Index - 1, request->Value) >= B_OK)
status = B_OK; status = B_OK;
break; break;
+96 -97
View File
@@ -15,6 +15,8 @@
#include "ohci.h" #include "ohci.h"
#define USB_MODULE_NAME "ohci"
pci_module_info *OHCI::sPCIModule = NULL; pci_module_info *OHCI::sPCIModule = NULL;
@@ -23,10 +25,10 @@ ohci_std_ops(int32 op, ...)
{ {
switch (op) { switch (op) {
case B_MODULE_INIT: case B_MODULE_INIT:
TRACE(("usb_ohci_module: init module\n")); TRACE_MODULE("init module\n");
return B_OK; return B_OK;
case B_MODULE_UNINIT: case B_MODULE_UNINIT:
TRACE(("usb_ohci_module: uninit module\n")); TRACE_MODULE("uninit module\n");
return B_OK; return B_OK;
} }
@@ -73,11 +75,11 @@ OHCI::OHCI(pci_info *info, Stack *stack)
fPortCount(0) fPortCount(0)
{ {
if (!fInitOK) { if (!fInitOK) {
TRACE_ERROR(("usb_ohci: bus manager failed to init\n")); TRACE_ERROR("bus manager failed to init\n");
return; return;
} }
TRACE(("usb_ohci: constructing new OHCI Host Controller Driver\n")); TRACE("constructing new OHCI host controller driver\n");
fInitOK = false; fInitOK = false;
mutex_init(&fEndpointLock, "ohci endpoint lock"); mutex_init(&fEndpointLock, "ohci endpoint lock");
@@ -95,26 +97,25 @@ OHCI::OHCI(pci_info *info, Stack *stack)
uint32 offset = sPCIModule->read_pci_config(fPCIInfo->bus, uint32 offset = sPCIModule->read_pci_config(fPCIInfo->bus,
fPCIInfo->device, fPCIInfo->function, PCI_base_registers, 4); fPCIInfo->device, fPCIInfo->function, PCI_base_registers, 4);
offset &= PCI_address_memory_32_mask; offset &= PCI_address_memory_32_mask;
TRACE(("usb_ohci: iospace offset: 0x%lx\n", offset)); TRACE_ALWAYS("iospace offset: 0x%lx\n", offset);
fRegisterArea = map_physical_memory("OHCI memory mapped registers", fRegisterArea = map_physical_memory("OHCI memory mapped registers",
(void *)offset, B_PAGE_SIZE, B_ANY_KERNEL_BLOCK_ADDRESS, (void *)offset, B_PAGE_SIZE, B_ANY_KERNEL_BLOCK_ADDRESS,
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_READ_AREA | B_WRITE_AREA, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_READ_AREA | B_WRITE_AREA,
(void **)&fOperationalRegisters); (void **)&fOperationalRegisters);
if (fRegisterArea < B_OK) { if (fRegisterArea < B_OK) {
TRACE_ERROR(("usb_ohci: failed to map register memory\n")); TRACE_ERROR("failed to map register memory\n");
return; return;
} }
TRACE(("usb_ohci: mapped operational registers: %p\n", TRACE("mapped operational registers: %p\n", fOperationalRegisters);
fOperationalRegisters));
// Check the revision of the controller, which should be 10h // Check the revision of the controller, which should be 10h
uint32 revision = _ReadReg(OHCI_REVISION) & 0xff; uint32 revision = _ReadReg(OHCI_REVISION) & 0xff;
TRACE(("usb_ohci: version %ld.%ld%s\n", OHCI_REVISION_HIGH(revision), TRACE("version %ld.%ld%s\n", OHCI_REVISION_HIGH(revision),
OHCI_REVISION_LOW(revision), OHCI_REVISION_LEGACY(revision) OHCI_REVISION_LOW(revision), OHCI_REVISION_LEGACY(revision)
? ", legacy support" : "")); ? ", legacy support" : "");
if (OHCI_REVISION_HIGH(revision) != 1 || OHCI_REVISION_LOW(revision) != 0) { if (OHCI_REVISION_HIGH(revision) != 1 || OHCI_REVISION_LOW(revision) != 0) {
TRACE_ERROR(("usb_ohci: unsupported OHCI revision\n")); TRACE_ERROR("unsupported OHCI revision\n");
return; return;
} }
@@ -123,7 +124,7 @@ OHCI::OHCI(pci_info *info, Stack *stack)
sizeof(ohci_hcca), "USB OHCI Host Controller Communication Area"); sizeof(ohci_hcca), "USB OHCI Host Controller Communication Area");
if (fHccaArea < B_OK) { if (fHccaArea < B_OK) {
TRACE_ERROR(("usb_ohci: unable to create the HCCA block area\n")); TRACE_ERROR("unable to create the HCCA block area\n");
return; return;
} }
@@ -152,7 +153,7 @@ OHCI::OHCI(pci_info *info, Stack *stack)
fInterruptEndpoints = new(std::nothrow) fInterruptEndpoints = new(std::nothrow)
ohci_endpoint_descriptor *[OHCI_STATIC_ENDPOINT_COUNT]; ohci_endpoint_descriptor *[OHCI_STATIC_ENDPOINT_COUNT];
if (!fInterruptEndpoints) { if (!fInterruptEndpoints) {
TRACE_ERROR(("ohci_usb: failed to allocate memory for interrupt endpoints\n")); TRACE_ERROR("failed to allocate memory for interrupt endpoints\n");
_FreeEndpoint(fDummyControl); _FreeEndpoint(fDummyControl);
_FreeEndpoint(fDummyBulk); _FreeEndpoint(fDummyBulk);
_FreeEndpoint(fDummyIsochronous); _FreeEndpoint(fDummyIsochronous);
@@ -162,7 +163,7 @@ OHCI::OHCI(pci_info *info, Stack *stack)
for (int32 i = 0; i < OHCI_STATIC_ENDPOINT_COUNT; i++) { for (int32 i = 0; i < OHCI_STATIC_ENDPOINT_COUNT; i++) {
fInterruptEndpoints[i] = _AllocateEndpoint(); fInterruptEndpoints[i] = _AllocateEndpoint();
if (!fInterruptEndpoints[i]) { if (!fInterruptEndpoints[i]) {
TRACE_ERROR(("ohci_usb: failed to allocate interrupt endpoint %ld", i)); TRACE_ERROR("failed to allocate interrupt endpoint %ld", i);
while (--i >= 0) while (--i >= 0)
_FreeEndpoint(fInterruptEndpoints[i]); _FreeEndpoint(fInterruptEndpoints[i]);
_FreeEndpoint(fDummyBulk); _FreeEndpoint(fDummyBulk);
@@ -204,7 +205,7 @@ OHCI::OHCI(pci_info *info, Stack *stack)
// Determine in what context we are running (Kindly copied from FreeBSD) // Determine in what context we are running (Kindly copied from FreeBSD)
uint32 control = _ReadReg(OHCI_CONTROL); uint32 control = _ReadReg(OHCI_CONTROL);
if (control & OHCI_INTERRUPT_ROUTING) { if (control & OHCI_INTERRUPT_ROUTING) {
TRACE(("usb_ohci: smm is in control of the host controller\n")); TRACE_ALWAYS("smm is in control of the host controller\n");
uint32 status = _ReadReg(OHCI_COMMAND_STATUS); uint32 status = _ReadReg(OHCI_COMMAND_STATUS);
_WriteReg(OHCI_COMMAND_STATUS, status | OHCI_OWNERSHIP_CHANGE_REQUEST); _WriteReg(OHCI_COMMAND_STATUS, status | OHCI_OWNERSHIP_CHANGE_REQUEST);
for (uint32 i = 0; i < 100 && (control & OHCI_INTERRUPT_ROUTING); i++) { for (uint32 i = 0; i < 100 && (control & OHCI_INTERRUPT_ROUTING); i++) {
@@ -213,13 +214,13 @@ OHCI::OHCI(pci_info *info, Stack *stack)
} }
if ((control & OHCI_INTERRUPT_ROUTING) != 0) { if ((control & OHCI_INTERRUPT_ROUTING) != 0) {
TRACE_ERROR(("usb_ohci: smm does not respond. resetting...\n")); TRACE_ERROR("smm does not respond. resetting...\n");
_WriteReg(OHCI_CONTROL, OHCI_HC_FUNCTIONAL_STATE_RESET); _WriteReg(OHCI_CONTROL, OHCI_HC_FUNCTIONAL_STATE_RESET);
snooze(USB_DELAY_BUS_RESET); snooze(USB_DELAY_BUS_RESET);
} else } else
TRACE(("usb_ohci: ownership change successful\n")); TRACE_ALWAYS("ownership change successful\n");
} else { } else {
TRACE(("usb_ohci: cold started\n")); TRACE("cold started\n");
snooze(USB_DELAY_BUS_RESET); snooze(USB_DELAY_BUS_RESET);
} }
@@ -244,7 +245,7 @@ OHCI::OHCI(pci_info *info, Stack *stack)
} }
if (reset) { if (reset) {
TRACE_ERROR(("usb_ohci: Error resetting the host controller (timeout)\n")); TRACE_ERROR("error resetting the host controller (timeout)\n");
return; return;
} }
@@ -293,12 +294,12 @@ OHCI::OHCI(pci_info *info, Stack *stack)
if (numberOfPorts > OHCI_MAX_PORT_COUNT) if (numberOfPorts > OHCI_MAX_PORT_COUNT)
numberOfPorts = OHCI_MAX_PORT_COUNT; numberOfPorts = OHCI_MAX_PORT_COUNT;
fPortCount = numberOfPorts; fPortCount = numberOfPorts;
TRACE(("usb_ohci: port count is %d\n", fPortCount)); TRACE("port count is %d\n", fPortCount);
// Create semaphore the finisher thread will wait for // Create semaphore the finisher thread will wait for
fFinishTransfersSem = create_sem(0, "OHCI Finish Transfers"); fFinishTransfersSem = create_sem(0, "OHCI Finish Transfers");
if (fFinishTransfersSem < B_OK) { if (fFinishTransfersSem < B_OK) {
TRACE_ERROR(("usb_ohci: failed to create semaphore\n")); TRACE_ERROR("failed to create semaphore\n");
return; return;
} }
@@ -308,7 +309,7 @@ OHCI::OHCI(pci_info *info, Stack *stack)
resume_thread(fFinishThread); resume_thread(fFinishThread);
// Install the interrupt handler // Install the interrupt handler
TRACE(("usb_ohci: installing interrupt handler\n")); TRACE("installing interrupt handler\n");
install_io_interrupt_handler(fPCIInfo->u.h0.interrupt_line, install_io_interrupt_handler(fPCIInfo->u.h0.interrupt_line,
_InterruptHandler, (void *)this, 0); _InterruptHandler, (void *)this, 0);
@@ -316,7 +317,7 @@ OHCI::OHCI(pci_info *info, Stack *stack)
_WriteReg(OHCI_INTERRUPT_ENABLE, OHCI_NORMAL_INTERRUPTS _WriteReg(OHCI_INTERRUPT_ENABLE, OHCI_NORMAL_INTERRUPTS
| OHCI_MASTER_INTERRUPT_ENABLE); | OHCI_MASTER_INTERRUPT_ENABLE);
TRACE(("usb_ohci: OHCI Host Controller Driver constructed\n")); TRACE("OHCI host controller driver constructed\n");
fInitOK = true; fInitOK = true;
} }
@@ -355,31 +356,30 @@ OHCI::~OHCI()
status_t status_t
OHCI::Start() OHCI::Start()
{ {
TRACE(("usb_ohci: starting OHCI Host Controller\n")); TRACE("starting OHCI host controller\n");
uint32 control = _ReadReg(OHCI_CONTROL); uint32 control = _ReadReg(OHCI_CONTROL);
if ((control & OHCI_HC_FUNCTIONAL_STATE_MASK) if ((control & OHCI_HC_FUNCTIONAL_STATE_MASK)
!= OHCI_HC_FUNCTIONAL_STATE_OPERATIONAL) { != OHCI_HC_FUNCTIONAL_STATE_OPERATIONAL) {
TRACE_ERROR(("usb_ohci: Controller not started (0x%08lx)!\n", TRACE_ERROR("controller not started (0x%08lx)!\n", control);
control));
return B_ERROR; return B_ERROR;
} else } else
TRACE(("usb_ohci: Controller is operational!\n")); TRACE("controller is operational!\n");
fRootHubAddress = AllocateAddress(); fRootHubAddress = AllocateAddress();
fRootHub = new(std::nothrow) OHCIRootHub(RootObject(), fRootHubAddress); fRootHub = new(std::nothrow) OHCIRootHub(RootObject(), fRootHubAddress);
if (!fRootHub) { if (!fRootHub) {
TRACE_ERROR(("usb_ohci: no memory to allocate root hub\n")); TRACE_ERROR("no memory to allocate root hub\n");
return B_NO_MEMORY; return B_NO_MEMORY;
} }
if (fRootHub->InitCheck() < B_OK) { if (fRootHub->InitCheck() < B_OK) {
TRACE_ERROR(("usb_ohci: root hub failed init check\n")); TRACE_ERROR("root hub failed init check\n");
return B_ERROR; return B_ERROR;
} }
SetRootHub(fRootHub); SetRootHub(fRootHub);
dprintf("usb_ohci: successfully started the controller\n"); TRACE_ALWAYS("successfully started the controller\n");
return BusManager::Start(); return BusManager::Start();
} }
@@ -393,23 +393,22 @@ OHCI::SubmitTransfer(Transfer *transfer)
uint32 type = transfer->TransferPipe()->Type(); uint32 type = transfer->TransferPipe()->Type();
if (type & USB_OBJECT_CONTROL_PIPE) { if (type & USB_OBJECT_CONTROL_PIPE) {
TRACE(("usb_ohci: submitting request\n")); TRACE("submitting request\n");
return _SubmitRequest(transfer); return _SubmitRequest(transfer);
} }
if ((type & USB_OBJECT_BULK_PIPE) || (type & USB_OBJECT_INTERRUPT_PIPE)) { if ((type & USB_OBJECT_BULK_PIPE) || (type & USB_OBJECT_INTERRUPT_PIPE)) {
TRACE(("usb_ohci: submitting %s transfer\n", TRACE("submitting %s transfer\n",
(type & USB_OBJECT_BULK_PIPE) ? "bulk" : "interrupt")); (type & USB_OBJECT_BULK_PIPE) ? "bulk" : "interrupt");
return _SubmitTransfer(transfer); return _SubmitTransfer(transfer);
} }
if (type & USB_OBJECT_ISO_PIPE) { if (type & USB_OBJECT_ISO_PIPE) {
TRACE(("usb_ohci: submitting isochronous transfer\n")); TRACE("submitting isochronous transfer\n");
return _SubmitIsochronousTransfer(transfer); return _SubmitIsochronousTransfer(transfer);
} }
TRACE_ERROR(("usb_ohci: tried to submit transfer for unknown pipe" TRACE_ERROR("tried to submit transfer for unknown pipe type %lu\n", type);
" type %lu\n", type));
return B_ERROR; return B_ERROR;
} }
@@ -481,7 +480,7 @@ OHCI::CancelQueuedTransfers(Pipe *pipe, bool force)
status_t status_t
OHCI::NotifyPipeChange(Pipe *pipe, usb_change change) OHCI::NotifyPipeChange(Pipe *pipe, usb_change change)
{ {
TRACE(("usb_ohci: pipe change %d for pipe 0x%08lx\n", change, (uint32)pipe)); TRACE("pipe change %d for pipe 0x%08lx\n", change, (uint32)pipe);
if (pipe->DeviceAddress() == fRootHubAddress) { if (pipe->DeviceAddress() == fRootHubAddress) {
// no need to insert/remove endpoint descriptors for the root hub // no need to insert/remove endpoint descriptors for the root hub
return B_OK; return B_OK;
@@ -495,11 +494,11 @@ OHCI::NotifyPipeChange(Pipe *pipe, usb_change change)
return _RemoveEndpointForPipe(pipe); return _RemoveEndpointForPipe(pipe);
case USB_CHANGE_PIPE_POLICY_CHANGED: case USB_CHANGE_PIPE_POLICY_CHANGED:
TRACE(("usb_ohci: pipe policy changing unhandled!\n")); TRACE("pipe policy changing unhandled!\n");
break; break;
default: default:
TRACE_ERROR(("usb_ohci: unknown pipe change!\n")); TRACE_ERROR("unknown pipe change!\n");
return B_ERROR; return B_ERROR;
} }
@@ -520,13 +519,12 @@ OHCI::AddTo(Stack *stack)
if (!sPCIModule) { if (!sPCIModule) {
status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule); status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule);
if (status < B_OK) { if (status < B_OK) {
TRACE_ERROR(("usb_ohci: getting pci module failed! 0x%08lx\n", TRACE_MODULE_ERROR("getting pci module failed! 0x%08lx\n", status);
status));
return status; return status;
} }
} }
TRACE(("usb_ohci: searching devices\n")); TRACE_MODULE("searching devices\n");
bool found = false; bool found = false;
pci_info *item = new(std::nothrow) pci_info; pci_info *item = new(std::nothrow) pci_info;
if (!item) { if (!item) {
@@ -540,13 +538,13 @@ OHCI::AddTo(Stack *stack)
&& item->class_api == PCI_usb_ohci) { && item->class_api == PCI_usb_ohci) {
if (item->u.h0.interrupt_line == 0 if (item->u.h0.interrupt_line == 0
|| item->u.h0.interrupt_line == 0xFF) { || item->u.h0.interrupt_line == 0xFF) {
TRACE_ERROR(("usb_ohci: found device with invalid IRQ -" TRACE_MODULE_ERROR("found device with invalid IRQ -"
" check IRQ assignement\n")); " check IRQ assignement\n");
continue; continue;
} }
TRACE(("usb_ohci: found device at IRQ %u\n", TRACE_MODULE("found device at IRQ %u\n",
item->u.h0.interrupt_line)); item->u.h0.interrupt_line);
OHCI *bus = new(std::nothrow) OHCI(item, stack); OHCI *bus = new(std::nothrow) OHCI(item, stack);
if (!bus) { if (!bus) {
delete item; delete item;
@@ -556,7 +554,7 @@ OHCI::AddTo(Stack *stack)
} }
if (bus->InitCheck() < B_OK) { if (bus->InitCheck() < B_OK) {
TRACE_ERROR(("usb_ohci: bus failed init check\n")); TRACE_MODULE_ERROR("bus failed init check\n");
delete bus; delete bus;
continue; continue;
} }
@@ -571,7 +569,7 @@ OHCI::AddTo(Stack *stack)
} }
if (!found) { if (!found) {
TRACE_ERROR(("usb_ohci: no devices found\n")); TRACE_MODULE_ERROR("no devices found\n");
delete item; delete item;
sPCIModule = NULL; sPCIModule = NULL;
put_module(B_PCI_MODULE_NAME); put_module(B_PCI_MODULE_NAME);
@@ -587,7 +585,7 @@ status_t
OHCI::GetPortStatus(uint8 index, usb_port_status *status) OHCI::GetPortStatus(uint8 index, usb_port_status *status)
{ {
if (index >= fPortCount) { if (index >= fPortCount) {
TRACE_ERROR(("usb_ohci: get port status for invalid port %u\n", index)); TRACE_ERROR("get port status for invalid port %u\n", index);
return B_BAD_INDEX; return B_BAD_INDEX;
} }
@@ -622,8 +620,8 @@ OHCI::GetPortStatus(uint8 index, usb_port_status *status)
if (portStatus & OHCI_RH_PORTSTATUS_PRSC) if (portStatus & OHCI_RH_PORTSTATUS_PRSC)
status->change |= PORT_STATUS_RESET; status->change |= PORT_STATUS_RESET;
TRACE(("usb_ohci: port %u status 0x%04x change 0x%04x\n", index, TRACE("port %u status 0x%04x change 0x%04x\n", index,
status->status, status->change)); status->status, status->change);
return B_OK; return B_OK;
} }
@@ -631,7 +629,7 @@ OHCI::GetPortStatus(uint8 index, usb_port_status *status)
status_t status_t
OHCI::SetPortFeature(uint8 index, uint16 feature) OHCI::SetPortFeature(uint8 index, uint16 feature)
{ {
TRACE(("usb_ohci: set port feature index %u feature %u\n", index, feature)); TRACE("set port feature index %u feature %u\n", index, feature);
if (index > fPortCount) if (index > fPortCount)
return B_BAD_INDEX; return B_BAD_INDEX;
@@ -660,7 +658,7 @@ OHCI::SetPortFeature(uint8 index, uint16 feature)
status_t status_t
OHCI::ClearPortFeature(uint8 index, uint16 feature) OHCI::ClearPortFeature(uint8 index, uint16 feature)
{ {
TRACE(("usb_ohci: clear port feature index %u feature %u\n", index, feature)); TRACE("clear port feature index %u feature %u\n", index, feature);
if (index > fPortCount) if (index > fPortCount)
return B_BAD_INDEX; return B_BAD_INDEX;
@@ -746,12 +744,12 @@ OHCI::_Interrupt()
} }
if (status & OHCI_SCHEDULING_OVERRUN) { if (status & OHCI_SCHEDULING_OVERRUN) {
TRACE(("usb_ohci: scheduling overrun occured\n")); TRACE_MODULE("scheduling overrun occured\n");
acknowledge |= OHCI_SCHEDULING_OVERRUN; acknowledge |= OHCI_SCHEDULING_OVERRUN;
} }
if (status & OHCI_WRITEBACK_DONE_HEAD) { if (status & OHCI_WRITEBACK_DONE_HEAD) {
TRACE(("usb_ohci: transfer descriptors processed\n")); TRACE_MODULE("transfer descriptors processed\n");
fHcca->done_head = 0; fHcca->done_head = 0;
acknowledge |= OHCI_WRITEBACK_DONE_HEAD; acknowledge |= OHCI_WRITEBACK_DONE_HEAD;
result = B_INVOKE_SCHEDULER; result = B_INVOKE_SCHEDULER;
@@ -759,18 +757,18 @@ OHCI::_Interrupt()
} }
if (status & OHCI_RESUME_DETECTED) { if (status & OHCI_RESUME_DETECTED) {
TRACE(("usb_ohci: resume detected\n")); TRACE_MODULE("resume detected\n");
acknowledge |= OHCI_RESUME_DETECTED; acknowledge |= OHCI_RESUME_DETECTED;
} }
if (status & OHCI_UNRECOVERABLE_ERROR) { if (status & OHCI_UNRECOVERABLE_ERROR) {
TRACE_ERROR(("usb_ohci: unrecoverable error - controller halted\n")); TRACE_MODULE_ERROR("unrecoverable error - controller halted\n");
_WriteReg(OHCI_CONTROL, OHCI_HC_FUNCTIONAL_STATE_RESET); _WriteReg(OHCI_CONTROL, OHCI_HC_FUNCTIONAL_STATE_RESET);
// TODO: clear all pending transfers, reset and resetup the controller // TODO: clear all pending transfers, reset and resetup the controller
} }
if (status & OHCI_ROOT_HUB_STATUS_CHANGE) { if (status & OHCI_ROOT_HUB_STATUS_CHANGE) {
TRACE(("usb_ohci: root hub status change\n")); TRACE_MODULE("root hub status change\n");
// Disable the interrupt as it will otherwise be retriggered until the // Disable the interrupt as it will otherwise be retriggered until the
// port has been reset and the change is cleared explicitly. // port has been reset and the change is cleared explicitly.
// TODO: renable it once we use status changes instead of polling // TODO: renable it once we use status changes instead of polling
@@ -879,8 +877,8 @@ OHCI::_FinishTransfers()
if (!Lock()) if (!Lock())
continue; continue;
TRACE(("usb_ohci: finishing transfers (first transfer: %p; last" TRACE("finishing transfers (first transfer: %p; last"
" transfer: %p)\n", fFirstTransfer, fLastTransfer)); " transfer: %p)\n", fFirstTransfer, fLastTransfer);
transfer_data *lastTransfer = NULL; transfer_data *lastTransfer = NULL;
transfer_data *transfer = fFirstTransfer; transfer_data *transfer = fFirstTransfer;
Unlock(); Unlock();
@@ -894,7 +892,7 @@ OHCI::_FinishTransfers()
uint32 status = OHCI_TD_GET_CONDITION_CODE(descriptor->flags); uint32 status = OHCI_TD_GET_CONDITION_CODE(descriptor->flags);
if (status == OHCI_TD_CONDITION_NOT_ACCESSED) { if (status == OHCI_TD_CONDITION_NOT_ACCESSED) {
// td is still active // td is still active
TRACE(("usb_ohci: td %p still active\n", descriptor)); TRACE("td %p still active\n", descriptor);
break; break;
} }
@@ -908,7 +906,7 @@ OHCI::_FinishTransfers()
// was halted because of this td, but we do not need // was halted because of this td, but we do not need
// to know, as when it was halted by another td this // to know, as when it was halted by another td this
// still ensures that this td was handled before). // still ensures that this td was handled before).
TRACE_ERROR(("usb_ohci: td error: 0x%08lx\n", status)); TRACE_ERROR("td error: 0x%08lx\n", status);
switch (status) { switch (status) {
case OHCI_TD_CONDITION_CRC_ERROR: case OHCI_TD_CONDITION_CRC_ERROR:
@@ -959,13 +957,13 @@ OHCI::_FinishTransfers()
} else { } else {
// an error occured but the endpoint is not halted so // an error occured but the endpoint is not halted so
// the td is in fact still active // the td is in fact still active
TRACE(("usb_ohci: td %p active with error\n", descriptor)); TRACE("td %p active with error\n", descriptor);
break; break;
} }
} }
// the td has complete without an error // the td has complete without an error
TRACE(("usb_ohci: td %p done\n", descriptor)); TRACE("td %p done\n", descriptor);
if (descriptor == transfer->last_descriptor if (descriptor == transfer->last_descriptor
|| descriptor->buffer_physical != 0) { || descriptor->buffer_physical != 0) {
@@ -1013,8 +1011,8 @@ OHCI::_FinishTransfers()
// break the descriptor chain on the last descriptor // break the descriptor chain on the last descriptor
transfer->last_descriptor->next_logical_descriptor = NULL; transfer->last_descriptor->next_logical_descriptor = NULL;
TRACE(("usb_ohci: transfer %p done with status 0x%08lx\n", TRACE("transfer %p done with status 0x%08lx\n",
transfer, callbackStatus)); transfer, callbackStatus);
// if canceled the callback has already been called // if canceled the callback has already been called
if (!transfer->canceled) { if (!transfer->canceled) {
@@ -1037,11 +1035,11 @@ OHCI::_FinishTransfers()
if (transfer->transfer->IsFragmented()) { if (transfer->transfer->IsFragmented()) {
// this transfer may still have data left // this transfer may still have data left
TRACE(("usb_ohci: advancing fragmented transfer\n")); TRACE("advancing fragmented transfer\n");
transfer->transfer->AdvanceByFragment(actualLength); transfer->transfer->AdvanceByFragment(actualLength);
if (transfer->transfer->VectorLength() > 0) { if (transfer->transfer->VectorLength() > 0) {
TRACE(("usb_ohci: still %ld bytes left on transfer\n", TRACE("still %ld bytes left on transfer\n",
transfer->transfer->VectorLength())); transfer->transfer->VectorLength());
// TODO actually resubmit the transfer // TODO actually resubmit the transfer
} }
@@ -1080,7 +1078,7 @@ OHCI::_SubmitRequest(Transfer *transfer)
ohci_general_td *setupDescriptor ohci_general_td *setupDescriptor
= _CreateGeneralDescriptor(sizeof(usb_request_data)); = _CreateGeneralDescriptor(sizeof(usb_request_data));
if (!setupDescriptor) { if (!setupDescriptor) {
TRACE_ERROR(("usb_ohci: failed to allocate setup descriptor\n")); TRACE_ERROR("failed to allocate setup descriptor\n");
return B_NO_MEMORY; return B_NO_MEMORY;
} }
@@ -1091,7 +1089,7 @@ OHCI::_SubmitRequest(Transfer *transfer)
ohci_general_td *statusDescriptor = _CreateGeneralDescriptor(0); ohci_general_td *statusDescriptor = _CreateGeneralDescriptor(0);
if (!statusDescriptor) { if (!statusDescriptor) {
TRACE_ERROR(("usb_ohci: failed to allocate status descriptor\n")); TRACE_ERROR("failed to allocate status descriptor\n");
_FreeGeneralDescriptor(setupDescriptor); _FreeGeneralDescriptor(setupDescriptor);
return B_NO_MEMORY; return B_NO_MEMORY;
} }
@@ -1137,7 +1135,7 @@ OHCI::_SubmitRequest(Transfer *transfer)
result = _AddPendingTransfer(transfer, endpoint, setupDescriptor, result = _AddPendingTransfer(transfer, endpoint, setupDescriptor,
dataDescriptor, statusDescriptor, directionIn); dataDescriptor, statusDescriptor, directionIn);
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("usb_ohci: failed to add pending transfer\n")); TRACE_ERROR("failed to add pending transfer\n");
_FreeDescriptorChain(setupDescriptor); _FreeDescriptorChain(setupDescriptor);
return result; return result;
} }
@@ -1183,7 +1181,7 @@ OHCI::_SubmitTransfer(Transfer *transfer)
result = _AddPendingTransfer(transfer, endpoint, firstDescriptor, result = _AddPendingTransfer(transfer, endpoint, firstDescriptor,
firstDescriptor, lastDescriptor, directionIn); firstDescriptor, lastDescriptor, directionIn);
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("usb_ohci: failed to add pending transfer\n")); TRACE_ERROR("failed to add pending transfer\n");
_FreeDescriptorChain(firstDescriptor); _FreeDescriptorChain(firstDescriptor);
return result; return result;
} }
@@ -1289,7 +1287,7 @@ OHCI::_AllocateEndpoint()
// Allocate memory chunk // Allocate memory chunk
if (fStack->AllocateChunk((void **)&endpoint, &physicalAddress, if (fStack->AllocateChunk((void **)&endpoint, &physicalAddress,
sizeof(ohci_endpoint_descriptor)) < B_OK) { sizeof(ohci_endpoint_descriptor)) < B_OK) {
TRACE_ERROR(("usb_ohci: failed to allocate endpoint descriptor\n")); TRACE_ERROR("failed to allocate endpoint descriptor\n");
return NULL; return NULL;
} }
@@ -1318,12 +1316,12 @@ OHCI::_FreeEndpoint(ohci_endpoint_descriptor *endpoint)
status_t status_t
OHCI::_InsertEndpointForPipe(Pipe *pipe) OHCI::_InsertEndpointForPipe(Pipe *pipe)
{ {
TRACE(("usb_ohci: inserting endpoint for device %u endpoint %u\n", TRACE("inserting endpoint for device %u endpoint %u\n",
pipe->DeviceAddress(), pipe->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("cannot allocate memory for endpoint\n");
return B_NO_MEMORY; return B_NO_MEMORY;
} }
@@ -1348,7 +1346,7 @@ OHCI::_InsertEndpointForPipe(Pipe *pipe)
break; break;
default: default:
TRACE_ERROR(("usb_ohci: direction unknown\n")); TRACE_ERROR("direction unknown\n");
_FreeEndpoint(endpoint); _FreeEndpoint(endpoint);
return B_ERROR; return B_ERROR;
} }
@@ -1364,7 +1362,7 @@ OHCI::_InsertEndpointForPipe(Pipe *pipe)
break; break;
default: default:
TRACE_ERROR(("usb_ohci: unaccetable speed\n")); TRACE_ERROR("unaccetable speed\n");
_FreeEndpoint(endpoint); _FreeEndpoint(endpoint);
return B_ERROR; return B_ERROR;
} }
@@ -1385,10 +1383,10 @@ OHCI::_InsertEndpointForPipe(Pipe *pipe)
else if (type & USB_OBJECT_ISO_PIPE) else if (type & USB_OBJECT_ISO_PIPE)
head = fDummyIsochronous; head = fDummyIsochronous;
else else
TRACE_ERROR(("usb_ohci: unknown pipe type\n")); TRACE_ERROR("unknown pipe type\n");
if (head == NULL) { if (head == NULL) {
TRACE_ERROR(("usb_ohci: no list found for endpoint\n")); TRACE_ERROR("no list found for endpoint\n");
_FreeEndpoint(endpoint); _FreeEndpoint(endpoint);
return B_ERROR; return B_ERROR;
} }
@@ -1431,8 +1429,8 @@ OHCI::_InsertEndpointForPipe(Pipe *pipe)
status_t status_t
OHCI::_RemoveEndpointForPipe(Pipe *pipe) OHCI::_RemoveEndpointForPipe(Pipe *pipe)
{ {
TRACE(("usb_ohci: removing endpoint for device %u endpoint %u\n", TRACE("removing endpoint for device %u endpoint %u\n",
pipe->DeviceAddress(), pipe->EndpointAddress())); pipe->DeviceAddress(), pipe->EndpointAddress());
ohci_endpoint_descriptor *endpoint ohci_endpoint_descriptor *endpoint
= (ohci_endpoint_descriptor *)pipe->ControllerCookie(); = (ohci_endpoint_descriptor *)pipe->ControllerCookie();
@@ -1470,7 +1468,7 @@ OHCI::_CreateGeneralDescriptor(size_t bufferSize)
if (fStack->AllocateChunk((void **)&descriptor, &physicalAddress, if (fStack->AllocateChunk((void **)&descriptor, &physicalAddress,
sizeof(ohci_general_td)) != B_OK) { sizeof(ohci_general_td)) != B_OK) {
TRACE_ERROR(("usb_ohci: failed to allocate general descriptor\n")); TRACE_ERROR("failed to allocate general descriptor\n");
return NULL; return NULL;
} }
@@ -1487,7 +1485,7 @@ OHCI::_CreateGeneralDescriptor(size_t bufferSize)
if (fStack->AllocateChunk(&descriptor->buffer_logical, if (fStack->AllocateChunk(&descriptor->buffer_logical,
(void **)&descriptor->buffer_physical, bufferSize) != B_OK) { (void **)&descriptor->buffer_physical, bufferSize) != B_OK) {
TRACE_ERROR(("usb_ohci: failed to allocate space for buffer\n")); TRACE_ERROR("failed to allocate space for buffer\n");
fStack->FreeChunk(descriptor, (void *)descriptor->physical_address, fStack->FreeChunk(descriptor, (void *)descriptor->physical_address,
sizeof(ohci_general_td)); sizeof(ohci_general_td));
return NULL; return NULL;
@@ -1589,9 +1587,9 @@ OHCI::_WriteDescriptorChain(ohci_general_td *topDescriptor, iovec *vector,
size_t length = min_c(current->buffer_size - bufferOffset, size_t length = min_c(current->buffer_size - bufferOffset,
vector[vectorIndex].iov_len - vectorOffset); vector[vectorIndex].iov_len - vectorOffset);
TRACE(("usb_ohci: copying %ld bytes to bufferOffset %ld from" TRACE("copying %ld bytes to bufferOffset %ld from"
" vectorOffset %ld at index %ld of %ld\n", length, bufferOffset, " vectorOffset %ld at index %ld of %ld\n", length, bufferOffset,
vectorOffset, vectorIndex, vectorCount)); vectorOffset, vectorIndex, vectorCount);
memcpy((uint8 *)current->buffer_logical + bufferOffset, memcpy((uint8 *)current->buffer_logical + bufferOffset,
(uint8 *)vector[vectorIndex].iov_base + vectorOffset, length); (uint8 *)vector[vectorIndex].iov_base + vectorOffset, length);
@@ -1601,8 +1599,8 @@ OHCI::_WriteDescriptorChain(ohci_general_td *topDescriptor, iovec *vector,
if (vectorOffset >= vector[vectorIndex].iov_len) { if (vectorOffset >= vector[vectorIndex].iov_len) {
if (++vectorIndex >= vectorCount) { if (++vectorIndex >= vectorCount) {
TRACE(("usb_ohci: wrote descriptor chain (%ld bytes, no" TRACE("wrote descriptor chain (%ld bytes, no"
" more vectors)\n", actualLength)); " more vectors)\n", actualLength);
return actualLength; return actualLength;
} }
@@ -1621,7 +1619,7 @@ OHCI::_WriteDescriptorChain(ohci_general_td *topDescriptor, iovec *vector,
current = (ohci_general_td *)current->next_logical_descriptor; current = (ohci_general_td *)current->next_logical_descriptor;
} }
TRACE(("usb_ohci: wrote descriptor chain (%ld bytes)\n", actualLength)); TRACE("wrote descriptor chain (%ld bytes)\n", actualLength);
return actualLength; return actualLength;
} }
@@ -1651,9 +1649,9 @@ OHCI::_ReadDescriptorChain(ohci_general_td *topDescriptor, iovec *vector,
size_t length = min_c(bufferSize - bufferOffset, size_t length = min_c(bufferSize - bufferOffset,
vector[vectorIndex].iov_len - vectorOffset); vector[vectorIndex].iov_len - vectorOffset);
TRACE(("usb_ohci: copying %ld bytes to vectorOffset %ld from" TRACE("copying %ld bytes to vectorOffset %ld from"
" bufferOffset %ld at index %ld of %ld\n", length, vectorOffset, " bufferOffset %ld at index %ld of %ld\n", length, vectorOffset,
bufferOffset, vectorIndex, vectorCount)); bufferOffset, vectorIndex, vectorCount);
memcpy((uint8 *)vector[vectorIndex].iov_base + vectorOffset, memcpy((uint8 *)vector[vectorIndex].iov_base + vectorOffset,
(uint8 *)current->buffer_logical + bufferOffset, length); (uint8 *)current->buffer_logical + bufferOffset, length);
@@ -1663,7 +1661,8 @@ OHCI::_ReadDescriptorChain(ohci_general_td *topDescriptor, iovec *vector,
if (vectorOffset >= vector[vectorIndex].iov_len) { if (vectorOffset >= vector[vectorIndex].iov_len) {
if (++vectorIndex >= vectorCount) { if (++vectorIndex >= vectorCount) {
TRACE(("usb_ohci: read descriptor chain (%ld bytes, no more vectors)\n", actualLength)); TRACE("read descriptor chain (%ld bytes, no more vectors)\n",
actualLength);
return actualLength; return actualLength;
} }
@@ -1679,7 +1678,7 @@ OHCI::_ReadDescriptorChain(ohci_general_td *topDescriptor, iovec *vector,
current = (ohci_general_td *)current->next_logical_descriptor; current = (ohci_general_td *)current->next_logical_descriptor;
} }
TRACE(("usb_ohci: read descriptor chain (%ld bytes)\n", actualLength)); TRACE("read descriptor chain (%ld bytes)\n", actualLength);
return actualLength; return actualLength;
} }
@@ -1702,7 +1701,7 @@ OHCI::_ReadActualLength(ohci_general_td *topDescriptor)
current = (ohci_general_td *)current->next_logical_descriptor; current = (ohci_general_td *)current->next_logical_descriptor;
} }
TRACE(("usb_ohci: read actual length (%ld bytes)\n", actualLength)); TRACE("read actual length (%ld bytes)\n", actualLength);
return actualLength; return actualLength;
} }
@@ -1761,7 +1760,7 @@ OHCI::_ReadReg(uint32 reg)
void void
OHCI::_PrintEndpoint(ohci_endpoint_descriptor *endpoint) OHCI::_PrintEndpoint(ohci_endpoint_descriptor *endpoint)
{ {
dprintf("usb_ohci: endpoint %p\n", endpoint); TRACE_ALWAYS("endpoint %p\n", endpoint);
dprintf("\tflags........... 0x%08lx\n", endpoint->flags); dprintf("\tflags........... 0x%08lx\n", endpoint->flags);
dprintf("\ttail_physical... 0x%08lx\n", endpoint->tail_physical_descriptor); dprintf("\ttail_physical... 0x%08lx\n", endpoint->tail_physical_descriptor);
dprintf("\thead_physical... 0x%08lx\n", endpoint->head_physical_descriptor); dprintf("\thead_physical... 0x%08lx\n", endpoint->head_physical_descriptor);
@@ -1776,7 +1775,7 @@ void
OHCI::_PrintDescriptorChain(ohci_general_td *topDescriptor) OHCI::_PrintDescriptorChain(ohci_general_td *topDescriptor)
{ {
while (topDescriptor) { while (topDescriptor) {
dprintf("usb_ohci: descriptor %p\n", topDescriptor); TRACE_ALWAYS("descriptor %p\n", topDescriptor);
dprintf("\tflags........... 0x%08lx\n", topDescriptor->flags); dprintf("\tflags........... 0x%08lx\n", topDescriptor->flags);
dprintf("\tbuffer_physical. 0x%08lx\n", topDescriptor->buffer_physical); dprintf("\tbuffer_physical. 0x%08lx\n", topDescriptor->buffer_physical);
dprintf("\tnext_physical... 0x%08lx\n", topDescriptor->next_physical_descriptor); dprintf("\tnext_physical... 0x%08lx\n", topDescriptor->next_physical_descriptor);
+1
View File
@@ -55,6 +55,7 @@ static status_t AddTo(Stack *stack);
status_t ResetPort(uint8 index); status_t ResetPort(uint8 index);
virtual const char * TypeName() { return "ohci"; };
private: private:
// Interrupt functions // Interrupt functions
+1 -1
View File
@@ -12,6 +12,6 @@ resource app_version {
variety = 0, variety = 0,
internal = 0, internal = 0,
short_info = "OHCI host controller driver", short_info = "OHCI host controller driver",
long_info = "Haiku OHCI HCD - Copyright 2005-2008, Haiku Inc." long_info = "Haiku OHCI HCD - Copyright 2005-2009, Haiku Inc."
}; };
+9 -7
View File
@@ -10,6 +10,8 @@
#include "ohci.h" #include "ohci.h"
#define USB_MODULE_NAME "ohci roothub"
static usb_device_descriptor sOHCIRootHubDevice = static usb_device_descriptor sOHCIRootHubDevice =
{ {
18, // Descriptor length 18, // Descriptor length
@@ -137,7 +139,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_MODULE("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;
@@ -171,12 +173,12 @@ OHCIRootHub::ProcessTransfer(OHCI *ohci, Transfer *transfer)
break; break;
} }
TRACE(("usb_ohci_roothub: set address: %d\n", request->Value)); TRACE_MODULE("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_MODULE("get descriptor: %d\n", request->Value >> 8);
switch (request->Value >> 8) { switch (request->Value >> 8) {
case USB_DESCRIPTOR_DEVICE: { case USB_DESCRIPTOR_DEVICE: {
@@ -230,11 +232,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_MODULE_ERROR("clear feature: no hub changes\n");
break; break;
} }
TRACE(("usb_ohci_roothub: clear feature: %d\n", request->Value)); TRACE_MODULE("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;
@@ -243,11 +245,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_MODULE_ERROR("set feature: no hub changes\n");
break; break;
} }
TRACE(("usb_ohci_roothub: set feature: %d\n", request->Value)); TRACE_MODULE("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;
+84 -84
View File
@@ -15,6 +15,8 @@
#include "uhci.h" #include "uhci.h"
#define USB_MODULE_NAME "uhci"
pci_module_info *UHCI::sPCIModule = NULL; pci_module_info *UHCI::sPCIModule = NULL;
@@ -23,10 +25,10 @@ uhci_std_ops(int32 op, ...)
{ {
switch (op) { switch (op) {
case B_MODULE_INIT: case B_MODULE_INIT:
TRACE(("usb_uhci_module: init module\n")); TRACE_MODULE("init module\n");
return B_OK; return B_OK;
case B_MODULE_UNINIT: case B_MODULE_UNINIT:
TRACE(("usb_uhci_module: uninit module\n")); TRACE_MODULE("uninit module\n");
break; break;
default: default:
return EINVAL; return EINVAL;
@@ -166,7 +168,7 @@ Queue::TerminateByStrayDescriptor()
status_t result = fStack->AllocateChunk((void **)&fStrayDescriptor, status_t result = fStack->AllocateChunk((void **)&fStrayDescriptor,
&physicalAddress, sizeof(uhci_td)); &physicalAddress, sizeof(uhci_td));
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("usb_uhci: failed to allocate a stray transfer descriptor\n")); TRACE_ERROR("failed to allocate a stray transfer descriptor\n");
return result; return result;
} }
@@ -271,7 +273,7 @@ void
Queue::PrintToStream() Queue::PrintToStream()
{ {
#ifdef TRACE_USB #ifdef TRACE_USB
dprintf("USB UHCI Queue:\n"); TRACE("queue:\n");
dprintf("link phy: 0x%08lx; link type: %s; terminate: %s\n", fQueueHead->link_phy & 0xfff0, fQueueHead->link_phy & 0x0002 ? "QH" : "TD", fQueueHead->link_phy & 0x0001 ? "yes" : "no"); dprintf("link phy: 0x%08lx; link type: %s; terminate: %s\n", fQueueHead->link_phy & 0xfff0, fQueueHead->link_phy & 0x0002 ? "QH" : "TD", fQueueHead->link_phy & 0x0001 ? "yes" : "no");
dprintf("elem phy: 0x%08lx; elem type: %s; terminate: %s\n", fQueueHead->element_phy & 0xfff0, fQueueHead->element_phy & 0x0002 ? "QH" : "TD", fQueueHead->element_phy & 0x0001 ? "yes" : "no"); dprintf("elem phy: 0x%08lx; elem type: %s; terminate: %s\n", fQueueHead->element_phy & 0xfff0, fQueueHead->element_phy & 0x0002 ? "QH" : "TD", fQueueHead->element_phy & 0x0001 ? "yes" : "no");
#endif #endif
@@ -310,21 +312,21 @@ UHCI::UHCI(pci_info *info, Stack *stack)
fPortResetChange(0) fPortResetChange(0)
{ {
if (!fInitOK) { if (!fInitOK) {
TRACE_ERROR(("usb_uhci: bus manager failed to init\n")); TRACE_ERROR("bus manager failed to init\n");
return; return;
} }
TRACE(("usb_uhci: constructing new UHCI Host Controller Driver\n")); TRACE("constructing new UHCI host controller driver\n");
fInitOK = false; fInitOK = false;
fRegisterBase = sPCIModule->read_pci_config(fPCIInfo->bus, fRegisterBase = sPCIModule->read_pci_config(fPCIInfo->bus,
fPCIInfo->device, fPCIInfo->function, PCI_memory_base, 4); fPCIInfo->device, fPCIInfo->function, PCI_memory_base, 4);
fRegisterBase &= PCI_address_io_mask; fRegisterBase &= PCI_address_io_mask;
TRACE(("usb_uhci: iospace offset: 0x%08lx\n", fRegisterBase)); TRACE("iospace offset: 0x%08lx\n", fRegisterBase);
if (fRegisterBase == 0) { if (fRegisterBase == 0) {
fRegisterBase = fPCIInfo->u.h0.base_registers[0]; fRegisterBase = fPCIInfo->u.h0.base_registers[0];
TRACE_ERROR(("usb_uhci: register base: 0x%08lx\n", fRegisterBase)); TRACE_ALWAYS("register base: 0x%08lx\n", fRegisterBase);
} }
// enable pci address access // enable pci address access
@@ -346,7 +348,7 @@ UHCI::UHCI(pci_info *info, Stack *stack)
// do a global and host reset // do a global and host reset
GlobalReset(); GlobalReset();
if (ControllerReset() < B_OK) { if (ControllerReset() < B_OK) {
TRACE_ERROR(("usb_uhci: host failed to reset\n")); TRACE_ERROR("host failed to reset\n");
return; return;
} }
@@ -356,7 +358,7 @@ UHCI::UHCI(pci_info *info, Stack *stack)
(void **)&physicalAddress, 4096, "USB UHCI framelist"); (void **)&physicalAddress, 4096, "USB UHCI framelist");
if (fFrameArea < B_OK) { if (fFrameArea < B_OK) {
TRACE_ERROR(("usb_uhci: unable to create an area for the frame pointer list\n")); TRACE_ERROR("unable to create an area for the frame pointer list\n");
return; return;
} }
@@ -383,7 +385,7 @@ UHCI::UHCI(pci_info *info, Stack *stack)
for (int32 i = 0; i < fQueueCount; i++) { for (int32 i = 0; i < fQueueCount; i++) {
fQueues[i] = new(std::nothrow) Queue(fStack); fQueues[i] = new(std::nothrow) Queue(fStack);
if (!fQueues[i] || fQueues[i]->InitCheck() < B_OK) { if (!fQueues[i] || fQueues[i]->InitCheck() < B_OK) {
TRACE_ERROR(("usb_uhci: cannot create queues\n")); TRACE_ERROR("cannot create queues\n");
delete_area(fFrameArea); delete_area(fFrameArea);
return; return;
} }
@@ -401,12 +403,13 @@ UHCI::UHCI(pci_info *info, Stack *stack)
// Create lists for managing isochronous transfer descriptors // Create lists for managing isochronous transfer descriptors
fFirstIsochronousDescriptor = new(std::nothrow) uhci_td *[NUMBER_OF_FRAMES]; fFirstIsochronousDescriptor = new(std::nothrow) uhci_td *[NUMBER_OF_FRAMES];
if (!fFirstIsochronousDescriptor) { if (!fFirstIsochronousDescriptor) {
TRACE_ERROR(("usb_uhci: cannot allocate memory\n")); TRACE_ERROR("faild to allocate memory for first isochronous descriptor\n");
return; return;
} }
fLastIsochronousDescriptor = new(std::nothrow) uhci_td *[NUMBER_OF_FRAMES]; fLastIsochronousDescriptor = new(std::nothrow) uhci_td *[NUMBER_OF_FRAMES];
if (!fLastIsochronousDescriptor) { if (!fLastIsochronousDescriptor) {
TRACE_ERROR(("usb_uhci: cannot allocate memory\n")); TRACE_ERROR("failed to allocate memory for last isochronous descriptor\n");
delete [] fFirstIsochronousDescriptor; delete [] fFirstIsochronousDescriptor;
return; return;
} }
@@ -422,7 +425,7 @@ UHCI::UHCI(pci_info *info, Stack *stack)
// Create semaphore the finisher thread will wait for // Create semaphore the finisher thread will wait for
fFinishTransfersSem = create_sem(0, "UHCI Finish Transfers"); fFinishTransfersSem = create_sem(0, "UHCI Finish Transfers");
if (fFinishTransfersSem < B_OK) { if (fFinishTransfersSem < B_OK) {
TRACE_ERROR(("usb_uhci: failed to create semaphore\n")); TRACE_ERROR("failed to create finisher semaphore\n");
return; return;
} }
@@ -438,7 +441,7 @@ UHCI::UHCI(pci_info *info, Stack *stack)
fFinishIsochronousTransfersSem = create_sem(0, fFinishIsochronousTransfersSem = create_sem(0,
"UHCI Isochronous Finish Transfers"); "UHCI Isochronous Finish Transfers");
if (fFinishIsochronousTransfersSem < B_OK) { if (fFinishIsochronousTransfersSem < B_OK) {
TRACE_ERROR(("usb_uhci: failed to create semaphore\n")); TRACE_ERROR("failed to create isochronous finisher semaphore\n");
return; return;
} }
@@ -449,7 +452,7 @@ UHCI::UHCI(pci_info *info, Stack *stack)
resume_thread(fFinishIsochronousThread); resume_thread(fFinishIsochronousThread);
// Install the interrupt handler // Install the interrupt handler
TRACE(("usb_uhci: installing interrupt handler\n")); TRACE("installing interrupt handler\n");
install_io_interrupt_handler(fPCIInfo->u.h0.interrupt_line, install_io_interrupt_handler(fPCIInfo->u.h0.interrupt_line,
InterruptHandler, (void *)this, 0); InterruptHandler, (void *)this, 0);
@@ -459,7 +462,7 @@ UHCI::UHCI(pci_info *info, Stack *stack)
WriteReg16(UHCI_USBINTR, UHCI_USBINTR_CRC | UHCI_USBINTR_IOC WriteReg16(UHCI_USBINTR, UHCI_USBINTR_CRC | UHCI_USBINTR_IOC
| UHCI_USBINTR_SHORT); | UHCI_USBINTR_SHORT);
TRACE(("usb_uhci: UHCI Host Controller Driver constructed\n")); TRACE("UHCI host controller driver constructed\n");
fInitOK = true; fInitOK = true;
} }
@@ -513,9 +516,9 @@ status_t
UHCI::Start() UHCI::Start()
{ {
// Start the host controller, then start the Busmanager // Start the host controller, then start the Busmanager
TRACE(("usb_uhci: starting UHCI BusManager\n")); TRACE("starting UHCI BusManager\n");
TRACE(("usb_uhci: usbcmd reg 0x%04x, usbsts reg 0x%04x\n", TRACE("usbcmd reg 0x%04x, usbsts reg 0x%04x\n",
ReadReg16(UHCI_USBCMD), ReadReg16(UHCI_USBSTS))); ReadReg16(UHCI_USBCMD), ReadReg16(UHCI_USBSTS));
// Set the run bit in the command register // Set the run bit in the command register
WriteReg16(UHCI_USBCMD, ReadReg16(UHCI_USBCMD) | UHCI_USBCMD_RS); WriteReg16(UHCI_USBCMD, ReadReg16(UHCI_USBCMD) | UHCI_USBCMD_RS);
@@ -523,7 +526,7 @@ UHCI::Start()
bool running = false; bool running = false;
for (int32 i = 0; i < 10; i++) { for (int32 i = 0; i < 10; i++) {
uint16 status = ReadReg16(UHCI_USBSTS); uint16 status = ReadReg16(UHCI_USBSTS);
TRACE(("usb_uhci: current loop %ld, status 0x%04x\n", i, status)); TRACE("current loop %ld, status 0x%04x\n", i, status);
if (status & UHCI_USBSTS_HCHALT) if (status & UHCI_USBSTS_HCHALT)
snooze(10000); snooze(10000);
@@ -534,28 +537,28 @@ UHCI::Start()
} }
if (!running) { if (!running) {
TRACE_ERROR(("usb_uhci: controller won't start running\n")); TRACE_ERROR("controller won't start running\n");
return B_ERROR; return B_ERROR;
} }
fRootHubAddress = AllocateAddress(); fRootHubAddress = AllocateAddress();
fRootHub = new(std::nothrow) UHCIRootHub(RootObject(), fRootHubAddress); fRootHub = new(std::nothrow) UHCIRootHub(RootObject(), fRootHubAddress);
if (!fRootHub) { if (!fRootHub) {
TRACE_ERROR(("usb_uhci: no memory to allocate root hub\n")); TRACE_ERROR("no memory to allocate root hub\n");
return B_NO_MEMORY; return B_NO_MEMORY;
} }
if (fRootHub->InitCheck() < B_OK) { if (fRootHub->InitCheck() < B_OK) {
TRACE_ERROR(("usb_uhci: root hub failed init check\n")); TRACE_ERROR("root hub failed init check\n");
delete fRootHub; delete fRootHub;
return B_ERROR; return B_ERROR;
} }
SetRootHub(fRootHub); SetRootHub(fRootHub);
TRACE(("usb_uhci: controller is started. status: %u curframe: %u\n", TRACE("controller is started. status: %u curframe: %u\n",
ReadReg16(UHCI_USBSTS), ReadReg16(UHCI_FRNUM))); ReadReg16(UHCI_USBSTS), ReadReg16(UHCI_FRNUM));
dprintf("usb_uhci: successfully started the controller\n"); TRACE_ALWAYS("successfully started the controller\n");
return BusManager::Start(); return BusManager::Start();
} }
@@ -568,8 +571,7 @@ UHCI::SubmitTransfer(Transfer *transfer)
if (pipe->DeviceAddress() == fRootHubAddress) if (pipe->DeviceAddress() == fRootHubAddress)
return fRootHub->ProcessTransfer(this, transfer); return fRootHub->ProcessTransfer(this, transfer);
TRACE(("usb_uhci: submit transfer called for device %d\n", TRACE("submit transfer called for device %d\n", pipe->DeviceAddress());
pipe->DeviceAddress()));
if (pipe->Type() & USB_OBJECT_CONTROL_PIPE) if (pipe->Type() & USB_OBJECT_CONTROL_PIPE)
return SubmitRequest(transfer); return SubmitRequest(transfer);
@@ -594,7 +596,7 @@ UHCI::SubmitTransfer(Transfer *transfer)
result = AddPendingTransfer(transfer, queue, transferQueue, result = AddPendingTransfer(transfer, queue, transferQueue,
firstDescriptor, firstDescriptor, directionIn); firstDescriptor, firstDescriptor, directionIn);
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("usb_uhci: failed to add pending transfer\n")); TRACE_ERROR("failed to add pending transfer\n");
FreeDescriptorChain(firstDescriptor); FreeDescriptorChain(firstDescriptor);
FreeTransferQueue(transferQueue); FreeTransferQueue(transferQueue);
return result; return result;
@@ -689,7 +691,7 @@ UHCI::CancelQueuedIsochronousTransfers(Pipe *pipe, bool force)
current = current->link; current = current->link;
} }
TRACE_ERROR(("usb_uhci: no isochronous transfer found!\n")); TRACE_ERROR("no isochronous transfer found!\n");
return B_ERROR; return B_ERROR;
} }
@@ -708,7 +710,7 @@ UHCI::SubmitRequest(Transfer *transfer)
directionIn ? TD_TOKEN_OUT : TD_TOKEN_IN, 0); directionIn ? TD_TOKEN_OUT : TD_TOKEN_IN, 0);
if (!setupDescriptor || !statusDescriptor) { if (!setupDescriptor || !statusDescriptor) {
TRACE_ERROR(("usb_uhci: failed to allocate descriptors\n")); TRACE_ERROR("failed to allocate descriptors\n");
FreeDescriptor(setupDescriptor); FreeDescriptor(setupDescriptor);
FreeDescriptor(statusDescriptor); FreeDescriptor(statusDescriptor);
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -759,7 +761,7 @@ UHCI::SubmitRequest(Transfer *transfer)
status_t result = AddPendingTransfer(transfer, queue, transferQueue, status_t result = AddPendingTransfer(transfer, queue, transferQueue,
setupDescriptor, dataDescriptor, directionIn); setupDescriptor, dataDescriptor, directionIn);
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("usb_uhci: failed to add pending transfer\n")); TRACE_ERROR("failed to add pending transfer\n");
FreeDescriptorChain(setupDescriptor); FreeDescriptorChain(setupDescriptor);
FreeTransferQueue(transferQueue); FreeTransferQueue(transferQueue);
return result; return result;
@@ -867,8 +869,7 @@ UHCI::SubmitIsochronous(Transfer *transfer)
uint16 currentFrame; uint16 currentFrame;
if (packetSize > pipe->MaxPacketSize()) { if (packetSize > pipe->MaxPacketSize()) {
TRACE_ERROR(("usb_uhci: isochronous packetSize is bigger" TRACE_ERROR("isochronous packetSize is bigger than pipe MaxPacketSize\n");
" than pipe MaxPacketSize\n"));
return B_BAD_VALUE; return B_BAD_VALUE;
} }
@@ -876,8 +877,7 @@ UHCI::SubmitIsochronous(Transfer *transfer)
// The overhead is not worthy. // The overhead is not worthy.
uint16 bandwidth = transfer->Bandwidth() / isochronousData->packet_count; uint16 bandwidth = transfer->Bandwidth() / isochronousData->packet_count;
TRACE(("usb_uhci: isochronous transfer descriptor bandwdith = %d\n", TRACE("isochronous transfer descriptor bandwdith %d\n", bandwidth);
bandwidth));
// The following holds the list of transfer descriptor of the // The following holds the list of transfer descriptor of the
// isochronous request. It is used to quickly remove all the isochronous // isochronous request. It is used to quickly remove all the isochronous
@@ -886,7 +886,7 @@ UHCI::SubmitIsochronous(Transfer *transfer)
uhci_td **isoRequest uhci_td **isoRequest
= new(std::nothrow) uhci_td *[isochronousData->packet_count]; = new(std::nothrow) uhci_td *[isochronousData->packet_count];
if (isoRequest == NULL) { if (isoRequest == NULL) {
TRACE(("usb_uhci: failed to create isoRequest array!\n")); TRACE("failed to create isoRequest array!\n");
return B_NO_MEMORY; return B_NO_MEMORY;
} }
@@ -932,9 +932,9 @@ UHCI::SubmitIsochronous(Transfer *transfer)
} }
} }
TRACE(("usb_uhci: isochronous submitted size=%ld bytes, TDs=%ld, " TRACE("isochronous submitted size=%ld bytes, TDs=%ld, "
"packetSize=%ld, restSize=%ld\n", transfer->DataLength(), "packetSize=%ld, restSize=%ld\n", transfer->DataLength(),
isochronousData->packet_count, packetSize, restSize)); isochronousData->packet_count, packetSize, restSize);
// Find the entry where to start inserting the first Isochronous descriptor // Find the entry where to start inserting the first Isochronous descriptor
if (isochronousData->flags & USB_ISO_ASAP || if (isochronousData->flags & USB_ISO_ASAP ||
@@ -963,8 +963,7 @@ UHCI::SubmitIsochronous(Transfer *transfer)
while (fFrameBandwidth[currentFrame] < bandwidth) { while (fFrameBandwidth[currentFrame] < bandwidth) {
currentFrame = (currentFrame + 1) % NUMBER_OF_FRAMES; currentFrame = (currentFrame + 1) % NUMBER_OF_FRAMES;
if (currentFrame == startSeekingFromFrame) { if (currentFrame == startSeekingFromFrame) {
TRACE_ERROR(("usb_uhci: Not enough bandwidth to queue the" TRACE_ERROR("not enough bandwidth to queue the isochronous request");
" isochronous request. Try again later!\n"));
for (uint32 i = 0; i < isochronousData->packet_count; i++) for (uint32 i = 0; i < isochronousData->packet_count; i++)
FreeDescriptor(isoRequest[i]); FreeDescriptor(isoRequest[i]);
delete [] isoRequest; delete [] isoRequest;
@@ -979,15 +978,15 @@ UHCI::SubmitIsochronous(Transfer *transfer)
status_t result = AddPendingIsochronousTransfer(transfer, isoRequest, status_t result = AddPendingIsochronousTransfer(transfer, isoRequest,
directionIn); directionIn);
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("usb_uhci: failed to add pending isochronous transfer\n")); TRACE_ERROR("failed to add pending isochronous transfer\n");
for (uint32 i = 0; i < isochronousData->packet_count; i++) for (uint32 i = 0; i < isochronousData->packet_count; i++)
FreeDescriptor(isoRequest[i]); FreeDescriptor(isoRequest[i]);
delete [] isoRequest; delete [] isoRequest;
return result; return result;
} }
TRACE(("usb_uhci: appended isochronous transfer by starting at frame" TRACE("appended isochronous transfer by starting at frame number %d\n",
" number %d\n", currentFrame)); currentFrame);
// Insert the Transfer Descriptor by starting at // Insert the Transfer Descriptor by starting at
// the starting_frame_number entry // the starting_frame_number entry
@@ -995,7 +994,7 @@ UHCI::SubmitIsochronous(Transfer *transfer)
for (uint32 i = 0; i < isochronousData->packet_count; i++) { for (uint32 i = 0; i < isochronousData->packet_count; i++) {
result = LinkIsochronousDescriptor(isoRequest[i], currentFrame); result = LinkIsochronousDescriptor(isoRequest[i], currentFrame);
if (result < B_OK) { if (result < B_OK) {
TRACE_ERROR(("usb_uhci: failed to add pending isochronous transfer\n")); TRACE_ERROR("failed to add pending isochronous transfer\n");
for (uint32 i = 0; i < isochronousData->packet_count; i++) for (uint32 i = 0; i < isochronousData->packet_count; i++)
FreeDescriptor(isoRequest[i]); FreeDescriptor(isoRequest[i]);
delete [] isoRequest; delete [] isoRequest;
@@ -1111,9 +1110,9 @@ UHCI::FinishTransfers()
if (!Lock()) if (!Lock())
continue; continue;
TRACE(("usb_uhci: finishing transfers (first transfer: 0x%08lx; last" TRACE("finishing transfers (first transfer: 0x%08lx; last"
" transfer: 0x%08lx)\n", (uint32)fFirstTransfer, " transfer: 0x%08lx)\n", (uint32)fFirstTransfer,
(uint32)fLastTransfer)); (uint32)fLastTransfer);
transfer_data *lastTransfer = NULL; transfer_data *lastTransfer = NULL;
transfer_data *transfer = fFirstTransfer; transfer_data *transfer = fFirstTransfer;
Unlock(); Unlock();
@@ -1127,15 +1126,15 @@ UHCI::FinishTransfers()
uint32 status = descriptor->status; uint32 status = descriptor->status;
if (status & TD_STATUS_ACTIVE) { if (status & TD_STATUS_ACTIVE) {
// still in progress // still in progress
TRACE(("usb_uhci: td (0x%08lx) still active\n", descriptor->this_phy)); TRACE("td (0x%08lx) still active\n", descriptor->this_phy);
break; break;
} }
if (status & TD_ERROR_MASK) { if (status & TD_ERROR_MASK) {
// an error occured // an error occured
TRACE_ERROR(("usb_uhci: td (0x%08lx) error: status: 0x%08lx;" TRACE_ERROR("td (0x%08lx) error: status: 0x%08lx;"
" token: 0x%08lx;\n", descriptor->this_phy, status, " token: 0x%08lx;\n", descriptor->this_phy, status,
descriptor->token)); descriptor->token);
uint8 errorCount = status >> TD_ERROR_COUNT_SHIFT; uint8 errorCount = status >> TD_ERROR_COUNT_SHIFT;
errorCount &= TD_ERROR_COUNT_MASK; errorCount &= TD_ERROR_COUNT_MASK;
@@ -1179,7 +1178,7 @@ UHCI::FinishTransfers()
|| (descriptor->status & TD_STATUS_ACTLEN_MASK) || (descriptor->status & TD_STATUS_ACTLEN_MASK)
< (descriptor->token >> TD_TOKEN_MAXLEN_SHIFT)) { < (descriptor->token >> TD_TOKEN_MAXLEN_SHIFT)) {
// all descriptors are done, or we have a short packet // all descriptors are done, or we have a short packet
TRACE(("usb_uhci: td (0x%08lx) ok\n", descriptor->this_phy)); TRACE("td (0x%08lx) ok\n", descriptor->this_phy);
callbackStatus = B_OK; callbackStatus = B_OK;
transferDone = true; transferDone = true;
break; break;
@@ -1235,11 +1234,11 @@ UHCI::FinishTransfers()
if (transfer->transfer->IsFragmented()) { if (transfer->transfer->IsFragmented()) {
// this transfer may still have data left // this transfer may still have data left
TRACE(("usb_uhci: advancing fragmented transfer\n")); TRACE("advancing fragmented transfer\n");
transfer->transfer->AdvanceByFragment(actualLength); transfer->transfer->AdvanceByFragment(actualLength);
if (transfer->transfer->VectorLength() > 0) { if (transfer->transfer->VectorLength() > 0) {
TRACE(("usb_uhci: still %ld bytes left on transfer\n", TRACE("still %ld bytes left on transfer\n",
transfer->transfer->VectorLength())); transfer->transfer->VectorLength());
// free the used descriptors // free the used descriptors
transfer->queue->RemoveTransfer(transfer->transfer_queue); transfer->queue->RemoveTransfer(transfer->transfer_queue);
@@ -1497,7 +1496,7 @@ UHCI::ResetPort(uint8 index)
if (index > 1) if (index > 1)
return B_BAD_INDEX; return B_BAD_INDEX;
TRACE(("usb_uhci: reset port %d\n", index)); TRACE("reset port %d\n", index);
uint32 port = UHCI_PORTSC1 + index * 2; uint32 port = UHCI_PORTSC1 + index * 2;
uint16 status = ReadReg16(port); uint16 status = ReadReg16(port);
@@ -1540,7 +1539,7 @@ UHCI::ResetPort(uint8 index)
} }
fPortResetChange |= (1 << index); fPortResetChange |= (1 << index);
TRACE(("usb_uhci: port was reset: 0x%04x\n", ReadReg16(port))); TRACE("port was reset: 0x%04x\n", ReadReg16(port));
return B_OK; return B_OK;
} }
@@ -1570,36 +1569,36 @@ UHCI::Interrupt()
int32 result = B_HANDLED_INTERRUPT; int32 result = B_HANDLED_INTERRUPT;
if (status & UHCI_USBSTS_USBINT) { if (status & UHCI_USBSTS_USBINT) {
TRACE(("usb_uhci: transfer finished\n")); TRACE_MODULE("transfer finished\n");
acknowledge |= UHCI_USBSTS_USBINT; acknowledge |= UHCI_USBSTS_USBINT;
result = B_INVOKE_SCHEDULER; result = B_INVOKE_SCHEDULER;
finishTransfers = true; finishTransfers = true;
} }
if (status & UHCI_USBSTS_ERRINT) { if (status & UHCI_USBSTS_ERRINT) {
TRACE(("usb_uhci: transfer error\n")); TRACE_MODULE("transfer error\n");
acknowledge |= UHCI_USBSTS_ERRINT; acknowledge |= UHCI_USBSTS_ERRINT;
result = B_INVOKE_SCHEDULER; result = B_INVOKE_SCHEDULER;
finishTransfers = true; finishTransfers = true;
} }
if (status & UHCI_USBSTS_RESDET) { if (status & UHCI_USBSTS_RESDET) {
TRACE(("usb_uhci: resume detected\n")); TRACE_MODULE("resume detected\n");
acknowledge |= UHCI_USBSTS_RESDET; acknowledge |= UHCI_USBSTS_RESDET;
} }
if (status & UHCI_USBSTS_HOSTERR) { if (status & UHCI_USBSTS_HOSTERR) {
TRACE(("usb_uhci: host system error\n")); TRACE_MODULE("host system error\n");
acknowledge |= UHCI_USBSTS_HOSTERR; acknowledge |= UHCI_USBSTS_HOSTERR;
} }
if (status & UHCI_USBSTS_HCPRERR) { if (status & UHCI_USBSTS_HCPRERR) {
TRACE(("usb_uhci: process error\n")); TRACE_MODULE("process error\n");
acknowledge |= UHCI_USBSTS_HCPRERR; acknowledge |= UHCI_USBSTS_HCPRERR;
} }
if (status & UHCI_USBSTS_HCHALT) { if (status & UHCI_USBSTS_HCHALT) {
TRACE_ERROR(("usb_uhci: host controller halted\n")); TRACE_MODULE_ERROR("host controller halted\n");
// at least disable interrupts so we do not flood the system // at least disable interrupts so we do not flood the system
WriteReg16(UHCI_USBINTR, 0); WriteReg16(UHCI_USBINTR, 0);
fEnabledInterrupts = 0; fEnabledInterrupts = 0;
@@ -1632,13 +1631,13 @@ UHCI::AddTo(Stack *stack)
if (!sPCIModule) { if (!sPCIModule) {
status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule); status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule);
if (status < B_OK) { if (status < B_OK) {
TRACE_ERROR(("usb_uhci: AddTo(): getting pci module failed! 0x%08lx\n", TRACE_MODULE_ERROR("AddTo(): getting pci module failed! 0x%08lx\n",
status)); status);
return status; return status;
} }
} }
TRACE(("usb_uhci: AddTo(): setting up hardware\n")); TRACE_MODULE("AddTo(): setting up hardware\n");
bool found = false; bool found = false;
pci_info *item = new(std::nothrow) pci_info; pci_info *item = new(std::nothrow) pci_info;
@@ -1654,12 +1653,12 @@ UHCI::AddTo(Stack *stack)
&& item->class_api == PCI_usb_uhci) { && item->class_api == PCI_usb_uhci) {
if (item->u.h0.interrupt_line == 0 if (item->u.h0.interrupt_line == 0
|| item->u.h0.interrupt_line == 0xFF) { || item->u.h0.interrupt_line == 0xFF) {
TRACE_ERROR(("usb_uhci: AddTo(): found with invalid IRQ - check IRQ assignement\n")); TRACE_MODULE_ERROR("AddTo(): found with invalid IRQ - check IRQ assignement\n");
continue; continue;
} }
TRACE(("usb_uhci: AddTo(): found at IRQ %u\n", TRACE_MODULE("AddTo(): found at IRQ %u\n",
item->u.h0.interrupt_line)); item->u.h0.interrupt_line);
UHCI *bus = new(std::nothrow) UHCI(item, stack); UHCI *bus = new(std::nothrow) UHCI(item, stack);
if (!bus) { if (!bus) {
delete item; delete item;
@@ -1669,8 +1668,8 @@ UHCI::AddTo(Stack *stack)
} }
if (bus->InitCheck() < B_OK) { if (bus->InitCheck() < B_OK) {
TRACE_ERROR(("usb_uhci: AddTo(): InitCheck() failed 0x%08lx\n", TRACE_MODULE_ERROR("AddTo(): InitCheck() failed 0x%08lx\n",
bus->InitCheck())); bus->InitCheck());
delete bus; delete bus;
continue; continue;
} }
@@ -1685,7 +1684,7 @@ UHCI::AddTo(Stack *stack)
} }
if (!found) { if (!found) {
TRACE_ERROR(("usb_uhci: no devices found\n")); TRACE_MODULE_ERROR("no devices found\n");
delete item; delete item;
sPCIModule = NULL; sPCIModule = NULL;
put_module(B_PCI_MODULE_NAME); put_module(B_PCI_MODULE_NAME);
@@ -1769,7 +1768,7 @@ UHCI::CreateDescriptor(Pipe *pipe, uint8 direction, size_t bufferSize)
if (fStack->AllocateChunk((void **)&result, &physicalAddress, if (fStack->AllocateChunk((void **)&result, &physicalAddress,
sizeof(uhci_td)) < B_OK) { sizeof(uhci_td)) < B_OK) {
TRACE_ERROR(("usb_uhci: failed to allocate a transfer descriptor\n")); TRACE_ERROR("failed to allocate a transfer descriptor\n");
return NULL; return NULL;
} }
@@ -1804,7 +1803,7 @@ UHCI::CreateDescriptor(Pipe *pipe, uint8 direction, size_t bufferSize)
if (fStack->AllocateChunk(&result->buffer_log, (void **)&result->buffer_phy, if (fStack->AllocateChunk(&result->buffer_log, (void **)&result->buffer_phy,
bufferSize) < B_OK) { bufferSize) < B_OK) {
TRACE_ERROR(("usb_uhci: unable to allocate space for the buffer\n")); TRACE_ERROR("unable to allocate space for the buffer\n");
fStack->FreeChunk(result, (void *)result->this_phy, sizeof(uhci_td)); fStack->FreeChunk(result, (void *)result->this_phy, sizeof(uhci_td));
return NULL; return NULL;
} }
@@ -1909,9 +1908,9 @@ UHCI::WriteDescriptorChain(uhci_td *topDescriptor, iovec *vector,
size_t length = min_c(current->buffer_size - bufferOffset, size_t length = min_c(current->buffer_size - bufferOffset,
vector[vectorIndex].iov_len - vectorOffset); vector[vectorIndex].iov_len - vectorOffset);
TRACE(("usb_uhci: copying %ld bytes to bufferOffset %ld from" TRACE("copying %ld bytes to bufferOffset %ld from"
" vectorOffset %ld at index %ld of %ld\n", length, bufferOffset, " vectorOffset %ld at index %ld of %ld\n", length, bufferOffset,
vectorOffset, vectorIndex, vectorCount)); vectorOffset, vectorIndex, vectorCount);
memcpy((uint8 *)current->buffer_log + bufferOffset, memcpy((uint8 *)current->buffer_log + bufferOffset,
(uint8 *)vector[vectorIndex].iov_base + vectorOffset, length); (uint8 *)vector[vectorIndex].iov_base + vectorOffset, length);
@@ -1921,8 +1920,8 @@ UHCI::WriteDescriptorChain(uhci_td *topDescriptor, iovec *vector,
if (vectorOffset >= vector[vectorIndex].iov_len) { if (vectorOffset >= vector[vectorIndex].iov_len) {
if (++vectorIndex >= vectorCount) { if (++vectorIndex >= vectorCount) {
TRACE(("usb_uhci: wrote descriptor chain (%ld bytes, no" TRACE("wrote descriptor chain (%ld bytes, no more vectors)\n",
" more vectors)\n", actualLength)); actualLength);
return actualLength; return actualLength;
} }
@@ -1941,7 +1940,7 @@ UHCI::WriteDescriptorChain(uhci_td *topDescriptor, iovec *vector,
current = (uhci_td *)current->link_log; current = (uhci_td *)current->link_log;
} }
TRACE(("usb_uhci: wrote descriptor chain (%ld bytes)\n", actualLength)); TRACE("wrote descriptor chain (%ld bytes)\n", actualLength);
return actualLength; return actualLength;
} }
@@ -1970,9 +1969,9 @@ UHCI::ReadDescriptorChain(uhci_td *topDescriptor, iovec *vector,
size_t length = min_c(bufferSize - bufferOffset, size_t length = min_c(bufferSize - bufferOffset,
vector[vectorIndex].iov_len - vectorOffset); vector[vectorIndex].iov_len - vectorOffset);
TRACE(("usb_uhci: copying %ld bytes to vectorOffset %ld from" TRACE("copying %ld bytes to vectorOffset %ld from"
" bufferOffset %ld at index %ld of %ld\n", length, vectorOffset, " bufferOffset %ld at index %ld of %ld\n", length, vectorOffset,
bufferOffset, vectorIndex, vectorCount)); bufferOffset, vectorIndex, vectorCount);
memcpy((uint8 *)vector[vectorIndex].iov_base + vectorOffset, memcpy((uint8 *)vector[vectorIndex].iov_base + vectorOffset,
(uint8 *)current->buffer_log + bufferOffset, length); (uint8 *)current->buffer_log + bufferOffset, length);
@@ -1982,7 +1981,8 @@ UHCI::ReadDescriptorChain(uhci_td *topDescriptor, iovec *vector,
if (vectorOffset >= vector[vectorIndex].iov_len) { if (vectorOffset >= vector[vectorIndex].iov_len) {
if (++vectorIndex >= vectorCount) { if (++vectorIndex >= vectorCount) {
TRACE(("usb_uhci: read descriptor chain (%ld bytes, no more vectors)\n", actualLength)); TRACE("read descriptor chain (%ld bytes, no more vectors)\n",
actualLength);
if (lastDataToggle) if (lastDataToggle)
*lastDataToggle = dataToggle; *lastDataToggle = dataToggle;
return actualLength; return actualLength;
@@ -2006,7 +2006,7 @@ UHCI::ReadDescriptorChain(uhci_td *topDescriptor, iovec *vector,
if (lastDataToggle) if (lastDataToggle)
*lastDataToggle = dataToggle; *lastDataToggle = dataToggle;
TRACE(("usb_uhci: read descriptor chain (%ld bytes)\n", actualLength)); TRACE("read descriptor chain (%ld bytes)\n", actualLength);
return actualLength; return actualLength;
} }
@@ -2035,7 +2035,7 @@ UHCI::ReadActualLength(uhci_td *topDescriptor, uint8 *lastDataToggle)
if (lastDataToggle) if (lastDataToggle)
*lastDataToggle = dataToggle; *lastDataToggle = dataToggle;
TRACE(("usb_uhci: read actual length (%ld bytes)\n", actualLength)); TRACE("read actual length (%ld bytes)\n", actualLength);
return actualLength; return actualLength;
} }
+5
View File
@@ -46,6 +46,9 @@ public:
void PrintToStream(); void PrintToStream();
usb_id USBID() { return 0; };
const char * TypeName() { return "uhci"; };
private: private:
status_t fStatus; status_t fStatus;
Stack *fStack; Stack *fStack;
@@ -105,6 +108,8 @@ static status_t AddTo(Stack *stack);
status_t ResetPort(uint8 index); status_t ResetPort(uint8 index);
virtual const char * TypeName() { return "uhci"; };
private: private:
// Controller resets // Controller resets
void GlobalReset(); void GlobalReset();
+1 -1
View File
@@ -11,5 +11,5 @@ resource app_version {
variety = 0, variety = 0,
internal = 0, internal = 0,
short_info = "UHCI host controller driver", short_info = "UHCI host controller driver",
long_info = "Haiku UHCI HCD - Copyright 2003-2008, Haiku Inc." long_info = "Haiku UHCI HCD - Copyright 2003-2009, Haiku Inc."
}; };
+9 -7
View File
@@ -9,6 +9,8 @@
#include "uhci.h" #include "uhci.h"
#define USB_MODULE_NAME "uhci roothub"
static usb_device_descriptor sUHCIRootHubDevice = static usb_device_descriptor sUHCIRootHubDevice =
{ {
18, // Descriptor length 18, // Descriptor length
@@ -136,7 +138,7 @@ UHCIRootHub::ProcessTransfer(UHCI *uhci, Transfer *transfer)
return B_ERROR; return B_ERROR;
usb_request_data *request = transfer->RequestData(); usb_request_data *request = transfer->RequestData();
TRACE(("usb_uhci_roothub: request: %d\n", request->Request)); TRACE_MODULE("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;
@@ -170,12 +172,12 @@ UHCIRootHub::ProcessTransfer(UHCI *uhci, Transfer *transfer)
break; break;
} }
TRACE(("usb_uhci_roothub: set address: %d\n", request->Value)); TRACE_MODULE("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_uhci_roothub: get descriptor: %d\n", request->Value >> 8)); TRACE_MODULE("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 +229,11 @@ UHCIRootHub::ProcessTransfer(UHCI *uhci, 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_uhci_roothub: clear feature: no hub changes\n")); TRACE_MODULE_ERROR("clear feature: no hub changes\n");
break; break;
} }
TRACE(("usb_uhci_roothub: clear feature: %d\n", request->Value)); TRACE_MODULE("clear feature: %d\n", request->Value);
if (uhci->ClearPortFeature(request->Index - 1, request->Value) >= B_OK) if (uhci->ClearPortFeature(request->Index - 1, request->Value) >= B_OK)
status = B_OK; status = B_OK;
break; break;
@@ -240,11 +242,11 @@ UHCIRootHub::ProcessTransfer(UHCI *uhci, 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_uhci_roothub: set feature: no hub changes\n")); TRACE_MODULE_ERROR("set feature: no hub changes\n");
break; break;
} }
TRACE(("usb_uhci_roothub: set feature: %d!\n", request->Value)); TRACE_MODULE("set feature: %d\n", request->Value);
if (uhci->SetPortFeature(request->Index - 1, request->Value) >= B_OK) if (uhci->SetPortFeature(request->Index - 1, request->Value) >= B_OK)
status = B_OK; status = B_OK;
break; break;