* Calmed down debug output a bit

* Removed all friends in the USB stack classes (as they are not needed)
* Added max packet size to the pipe and respect it on transfers
* Use pipes with the same speed as the device

Device descriptors can now also be retrieved from full speed devices and devices with a packet size of more than 8 bytes. The devices are also correctly initialized to their default configuration.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17639 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz 2006-05-29 22:09:21 +00:00
parent f4ccbdaa3a
commit b7a062b5ad
6 changed files with 57 additions and 31 deletions

View File

@ -34,9 +34,10 @@ BusManager::BusManager()
fDeviceMap[i] = false;
// Set up the default pipes
fDefaultPipe = new ControlPipe(this, 0, Pipe::Default, Pipe::NormalSpeed, 0);
fDefaultPipe = new ControlPipe(this, 0, Pipe::Default, Pipe::NormalSpeed,
0, 8);
fDefaultPipeLowSpeed = new ControlPipe(this, 0, Pipe::Default,
Pipe::LowSpeed, 0);
Pipe::LowSpeed, 0, 8);
fExploreThread = -1;
fInitOK = true;
@ -69,8 +70,8 @@ BusManager::ExploreThread(void *data)
if (!rootHub)
return B_ERROR;
snooze(3000000);
while (true) {
//snooze(5000000);
rootHub->Explore();
snooze(1000000);
}
@ -91,8 +92,10 @@ BusManager::AllocateNewDevice(Device *parent, bool lowSpeed)
TRACE(("usb BusManager::AllocateNewDevice(): setting device address to %d\n", deviceNum));
ControlPipe *defaultPipe = (lowSpeed ? fDefaultPipeLowSpeed : fDefaultPipe);
// Set the address of the device USB 1.1 spec p202
status_t result = fDefaultPipeLowSpeed->SendRequest(
status_t result = defaultPipe->SendRequest(
USB_REQTYPE_DEVICE_OUT | USB_REQTYPE_STANDARD, // type
USB_REQUEST_SET_ADDRESS, // request
deviceNum, // value
@ -111,7 +114,8 @@ BusManager::AllocateNewDevice(Device *parent, bool lowSpeed)
snooze(10000);
// Create a temporary pipe with the new address
ControlPipe pipe(this, deviceNum, Pipe::Default, Pipe::LowSpeed, 0);
ControlPipe pipe(this, deviceNum, Pipe::Default,
lowSpeed ? Pipe::LowSpeed : Pipe::NormalSpeed, 0, 8);
// Get the device descriptor
// Just retrieve the first 8 bytes of the descriptor -> minimum supported
@ -136,6 +140,15 @@ BusManager::AllocateNewDevice(Device *parent, bool lowSpeed)
return NULL;
}
TRACE(("short device descriptor for device %d:\n", deviceDescriptor));
TRACE(("\tlength:..............%d\n", deviceDescriptor.length));
TRACE(("\tdescriptor_type:.....0x%04x\n", deviceDescriptor.descriptor_type));
TRACE(("\tusb_version:.........0x%04x\n", deviceDescriptor.usb_version));
TRACE(("\tdevice_class:........0x%02x\n", deviceDescriptor.device_class));
TRACE(("\tdevice_subclass:.....0x%02x\n", deviceDescriptor.device_subclass));
TRACE(("\tdevice_protocol:.....0x%02x\n", deviceDescriptor.device_protocol));
TRACE(("\tmax_packet_size_0:...%d\n", deviceDescriptor.max_packet_size_0));
// Create a new instance based on the type (Hub or Device)
if (deviceDescriptor.device_class == 0x09) {
TRACE(("usb BusManager::AllocateNewDevice(): creating new hub\n"));

View File

@ -40,7 +40,7 @@ Device::Device(BusManager *bus, Device *parent, usb_device_descriptor &desc,
fDeviceDescriptor = desc;
fMaxPacketIn[0] = fMaxPacketOut[0] = fDeviceDescriptor.max_packet_size_0;
fDefaultPipe = new ControlPipe(this, Pipe::Default,
lowSpeed ? Pipe::LowSpeed : Pipe::NormalSpeed, 0);
lowSpeed ? Pipe::LowSpeed : Pipe::NormalSpeed, 0, fMaxPacketIn[0]);
// Get the device descriptor
// We already have a part of it, but we want it all
@ -52,9 +52,21 @@ Device::Device(BusManager *bus, Device *parent, usb_device_descriptor &desc,
return;
}
TRACE(("USB Device %d: Vendor id: 0x%04x, Product id: 0x%04x, Device version: 0x%04x\n",
fDeviceAddress, fDeviceDescriptor.vendor_id,
fDeviceDescriptor.product_id, fDeviceDescriptor.device_version));
TRACE(("full device descriptor for device %d:\n", fDeviceAddress));
TRACE(("\tlength:..............%d\n", fDeviceDescriptor.length));
TRACE(("\tdescriptor_type:.....0x%04x\n", fDeviceDescriptor.descriptor_type));
TRACE(("\tusb_version:.........0x%04x\n", fDeviceDescriptor.usb_version));
TRACE(("\tdevice_class:........0x%02x\n", fDeviceDescriptor.device_class));
TRACE(("\tdevice_subclass:.....0x%02x\n", fDeviceDescriptor.device_subclass));
TRACE(("\tdevice_protocol:.....0x%02x\n", fDeviceDescriptor.device_protocol));
TRACE(("\tmax_packet_size_0:...%d\n", fDeviceDescriptor.max_packet_size_0));
TRACE(("\tvendor_id:...........0x%04x\n", fDeviceDescriptor.vendor_id));
TRACE(("\tproduct_id:..........0x%04x\n", fDeviceDescriptor.product_id));
TRACE(("\tdevice_version:......0x%04x\n", fDeviceDescriptor.device_version));
TRACE(("\tmanufacturer:........0x%04x\n", fDeviceDescriptor.manufacturer));
TRACE(("\tproduct:.............0x%02x\n", fDeviceDescriptor.product));
TRACE(("\tserial_number:.......0x%02x\n", fDeviceDescriptor.serial_number));
TRACE(("\tnum_configurations:..%d\n", fDeviceDescriptor.num_configurations));
// Get the configurations
fConfigurations = (usb_configuration_descriptor *)malloc(fDeviceDescriptor.num_configurations

View File

@ -9,11 +9,13 @@
#include "usb_p.h"
Pipe::Pipe(Device *device, pipeDirection &direction, uint8 &endpointAddress)
Pipe::Pipe(Device *device, pipeDirection direction, uint8 endpointAddress,
uint32 maxPacketSize)
{
fDirection = direction;
fDevice = device;
fEndpoint = endpointAddress;
fMaxPacketSize = maxPacketSize;
fBus = NULL;
if (fDevice)
@ -42,16 +44,17 @@ Pipe::DeviceAddress()
ControlPipe::ControlPipe(Device *device, pipeDirection direction,
pipeSpeed speed, uint8 endpointAddress)
: Pipe(device, direction, endpointAddress)
pipeSpeed speed, uint8 endpointAddress, uint32 maxPacketSize)
: Pipe(device, direction, endpointAddress, maxPacketSize)
{
fSpeed = speed;
}
ControlPipe::ControlPipe(BusManager *bus, int8 deviceAddress,
pipeDirection direction, pipeSpeed speed, uint8 endpointAddress)
: Pipe(NULL, direction, endpointAddress)
pipeDirection direction, pipeSpeed speed, uint8 endpointAddress,
uint32 maxPacketSize)
: Pipe(NULL, direction, endpointAddress, maxPacketSize)
{
fBus = bus;
fDeviceAddress = deviceAddress;

View File

@ -84,8 +84,6 @@ virtual bool IsHub() { return false; };
status_t SetConfiguration(uint8 value);
protected:
friend class Pipe;
usb_device_descriptor fDeviceDescriptor;
usb_configuration_descriptor *fConfigurations;
usb_configuration_descriptor *fCurrentConfiguration;
@ -95,8 +93,8 @@ friend class Pipe;
BusManager *fBus;
Device *fParent;
int8 fDeviceAddress;
uint8 fMaxPacketIn[16];
uint8 fMaxPacketOut[16];
uint32 fMaxPacketIn[16];
uint32 fMaxPacketOut[16];
sem_id fLock;
};
@ -151,9 +149,6 @@ protected:
bool fInitOK;
private:
friend class Device;
friend class ControlPipe;
static int32 ExploreThread(void *data);
sem_id fLock;
@ -176,8 +171,9 @@ enum pipeSpeed { LowSpeed, NormalSpeed };
enum pipeType { Control, Bulk, Isochronous, Interrupt, Invalid };
Pipe(Device *device,
pipeDirection &direction,
uint8 &endpointAddress);
pipeDirection direction,
uint8 endpointAddress,
uint32 maxPacketSize);
virtual ~Pipe();
virtual int8 DeviceAddress();
@ -185,14 +181,14 @@ virtual pipeType Type() { return Invalid; };
virtual pipeSpeed Speed() { return LowSpeed; };
//Provide a default: should never be called
virtual int8 EndpointAddress() { return fEndpoint; };
virtual uint32 MaxPacketSize() { return fMaxPacketSize; };
protected:
friend class Transfer;
Device *fDevice;
BusManager *fBus;
pipeDirection fDirection;
uint8 fEndpoint;
uint32 fMaxPacketSize;
};
@ -201,14 +197,16 @@ public:
ControlPipe(Device *device,
pipeDirection direction,
pipeSpeed speed,
uint8 endpointAddress);
uint8 endpointAddress,
uint32 maxPacketSize);
// Constructor for default control pipe
ControlPipe(BusManager *bus,
int8 deviceAddress,
pipeDirection direction,
pipeSpeed speed,
uint8 endpointAddress);
uint8 endpointAddress,
uint32 maxPacketSize);
virtual int8 DeviceAddress();
virtual pipeType Type() { return Control; };

View File

@ -346,7 +346,7 @@ Queue::AddRequest(Transfer *transfer, bigtime_t timeout)
statusDescriptor->link_log = 0;
if (transfer->Buffer() && transfer->BufferLength() > 0) {
int32 packetSize = 8;
int32 packetSize = pipe->MaxPacketSize();
int32 bufferLength = transfer->BufferLength();
int32 descriptorCount = (bufferLength + packetSize - 1) / packetSize;
@ -617,7 +617,7 @@ UHCI::Start()
status_t
UHCI::SubmitTransfer(Transfer *transfer, bigtime_t timeout)
{
TRACE(("usb_uhci: submit packet called\n"));
//TRACE(("usb_uhci: submit packet called\n"));
// Short circuit the root hub
if (transfer->TransferPipe()->DeviceAddress() == fRootHubAddress)
@ -662,7 +662,7 @@ UHCI::PortStatus(int32 index)
if (index > 1)
return B_BAD_VALUE;
TRACE(("usb_uhci: read port status of port: %d\n", index));
//TRACE(("usb_uhci: read port status of port: %d\n", index));
return ReadReg16(UHCI_PORTSC1 + index * 2);
}

View File

@ -10,7 +10,7 @@
#include <PCI.h>
#define TRACE_UHCI_ROOT_HUB
//#define TRACE_UHCI_ROOT_HUB
#ifdef TRACE_UHCI_ROOT_HUB
#define TRACE(x) dprintf x
#else