X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FUSB%2FCore%2Fusb_devinit.c;h=c9655cb398cad9591ecefc16e85f42e73eee7003;hb=5cab4c07bc13888dc7956194ef9595508072a4eb;hp=c5fd2ef320a7d88e0f5cab560ed6e1322362a43c;hpb=c3cdb7282e835c292abd295f4d154e912a7529d7;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/USB/Core/usb_devinit.c b/KernelLand/Modules/USB/Core/usb_devinit.c index c5fd2ef3..c9655cb3 100644 --- a/KernelLand/Modules/USB/Core/usb_devinit.c +++ b/KernelLand/Modules/USB/Core/usb_devinit.c @@ -5,7 +5,7 @@ * usb_devinit.c * - USB Device Initialisation */ -#define DEBUG 1 +#define DEBUG 0 #include #include #include @@ -29,7 +29,7 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) tUSBDevice tmpdev; tUSBDevice *dev = &tmpdev; if( Port >= Hub->nPorts ) return ; - if( Hub->Devices[Port] ) return ; + if( Hub->Ports[Port].Dev ) return ; ENTER("pHub iPort", Hub, Port); @@ -51,7 +51,7 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) USB_int_SendSetupSetAddress(dev->Host, dev->Address); LOG("Assigned address %i", dev->Address); - dev->EndpointHandles[0] = dev->Host->HostDef->InitControl(dev->Host->Ptr, dev->Address << 4); + dev->EndpointHandles[0] = dev->Host->HostDef->InitControl(dev->Host->Ptr, dev->Address << 4, 64); for( int i = 1; i < 16; i ++ ) dev->EndpointHandles[i] = 0; @@ -256,7 +256,14 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) LOG(" .MaxPacketSize = %i", LittleEndian16(endpt->MaxPacketSize)); LOG(" .PollingInterval = %i", endpt->PollingInterval); LOG("}"); - + + // Make sure things don't break + if( !((endpt->Address & 0x7F) < 15) ) { + Log_Error("USB", "Endpoint number %i>16", endpt->Address & 0x7F); + k --; + continue ; + } + dev_if->Endpoints[k].Next = NULL; dev_if->Endpoints[k].Interface = dev_if; dev_if->Endpoints[k].EndpointIdx = k; @@ -268,6 +275,31 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) dev_if->Endpoints[k].InputData = NULL; // TODO: Register endpoint early + int ep_num = endpt->Address & 15; + if( dev->EndpointHandles[ep_num] ) { + Log_Notice("USB", "Device %p:%i ep %i reused", dev->Host->Ptr, dev->Address, ep_num); + } + else { + int addr = dev->Address*16+ep_num; + int mps = dev_if->Endpoints[k].MaxPacketSize; + void *handle = NULL; + switch( endpt->Attributes & 3) + { + case 0: // Control + handle = dev->Host->HostDef->InitControl(dev->Host->Ptr, addr, mps); + break; + case 1: // Isochronous + // handle = dev->Host->HostDef->InitIsoch(dev->Host->Ptr, addr, mps); + break; + case 2: // Bulk + handle = dev->Host->HostDef->InitBulk(dev->Host->Ptr, addr, mps); + break; + case 3: // Interrupt + // handle = dev->Host->HostDef->InitInterrupt(dev->Host->Ptr, addr, ...); + break; + } + dev->EndpointHandles[ep_num] = handle; + } } // Initialise driver @@ -293,7 +325,7 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) free(full_buf); } - Hub->Devices[Port] = dev; + Hub->Ports[Port].Dev = dev; // Done. LEAVE('-'); @@ -302,11 +334,11 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) void USB_DeviceDisconnected(tUSBHub *Hub, int Port) { tUSBDevice *dev; - if( !Hub->Devices[Port] ) { + if( !Hub->Ports[Port].Dev ) { Log_Error("USB", "Non-registered device disconnected"); return; } - dev = Hub->Devices[Port]; + dev = Hub->Ports[Port].Dev; // TODO: Free related resources // - Endpoint registrations @@ -319,8 +351,9 @@ void USB_DeviceDisconnected(tUSBHub *Hub, int Port) // - Bus Address USB_int_DeallocateAddress(dev->Host, dev->Address); // - Inform handler - // - Allocate memory + // - Release memory free(dev); + Hub->Ports[Port].Dev = NULL; } void *USB_GetDeviceDataPtr(tUSBInterface *Dev) { return Dev->Data; } @@ -329,6 +362,7 @@ void USB_SetDeviceDataPtr(tUSBInterface *Dev, void *Ptr) { Dev->Data = Ptr; } int USB_int_AllocateAddress(tUSBHost *Host) { int i; + ASSERT(Host); for( i = 1; i < 128; i ++ ) { if(Host->AddressBitmap[i/8] & (1 << (i%8)))