X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FUSB%2FCore%2Fusb.c;h=b3195804c129892969048d4ea29e7c87e1ce11f2;hb=0e361ff8d9472885f770a370c0d477c229041572;hp=de884e48dba97aa331d98b49e7270d40689bb148;hpb=dfe55553735a8cfa2b7207e5096caddded32c992;p=tpg%2Facess2.git diff --git a/Modules/USB/Core/usb.c b/Modules/USB/Core/usb.c index de884e48..b3195804 100644 --- a/Modules/USB/Core/usb.c +++ b/Modules/USB/Core/usb.c @@ -1,63 +1,108 @@ /* - * Acess 2 USB Stack - * USB Packet Control + * Acess2 USB Stack + * - By John Hodge (thePowersGang) + * + * usb.c + * - USB Structure */ #define DEBUG 1 #include #include #include #include "usb.h" -#include "usb_proto.h" + +// === IMPORTS === +extern tUSBHost *gUSB_Hosts; +extern tUSBDriver gUSBHub_Driver; // === STRUCTURES === +// === PROTOTYPES === +tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts); + +// === GLOBALS === +tUSBDriver *gpUSB_InterfaceDrivers = &gUSBHub_Driver; + // === CODE === tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts) { - // TODO: - return NULL; -} + tUSBHost *host; + + host = malloc(sizeof(tUSBHost) + nPorts*sizeof(void*)); + if(!host) { + // Oh, bugger. + return NULL; + } + host->HostDef = HostDef; + host->Ptr = ControllerPtr; + memset(host->AddressBitmap, 0, sizeof(host->AddressBitmap)); -void USB_DeviceConnected(tUSBHub *Hub, int Port) -{ - if( Port >= Hub->nPorts ) return ; - if( Hub->Devices[Port] ) return ; + host->RootHubDev.ParentHub = NULL; + host->RootHubDev.Host = host; + host->RootHubDev.Address = 0; - // 0. Perform port init? (done in hub?) - // 1. Assign an address - - // 2. Get device information +// host->RootHubIf.Next = NULL; + host->RootHubIf.Dev = &host->RootHubDev; + host->RootHubIf.Driver = NULL; + host->RootHubIf.Data = NULL; + host->RootHubIf.nEndpoints = 0; + + host->RootHub.Interface = &host->RootHubIf; + host->RootHub.nPorts = nPorts; + memset(host->RootHub.Devices, 0, sizeof(void*)*nPorts); + + // TODO: Lock + host->Next = gUSB_Hosts; + gUSB_Hosts = host; + + return &host->RootHub; } -void USB_DeviceDisconnected(tUSBHub *Hub, int Port) +// --- Drivers --- +void USB_RegisterDriver(tUSBDriver *Driver) { - + Log_Warning("USB", "TODO: Implement USB_RegisterDriver"); } -void *USB_GetDeviceDataPtr(tUSBDevice *Dev) { return Dev->Data; } -void USB_SetDeviceDataPtr(tUSBDevice *Dev, void *Ptr) { Dev->Data = Ptr; } - -int USB_int_AllocateAddress(tUSBHost *Host) +tUSBDriver *USB_int_FindDriverByClass(Uint32 ClassCode) { - int i; - for( i = 1; i < 128; i ++ ) + ENTER("xClassCode", ClassCode); + for( tUSBDriver *ret = gpUSB_InterfaceDrivers; ret; ret = ret->Next ) { - if(Host->AddressBitmap[i/8] & (1 << i)) - continue ; - return i; + LOG(" 0x%x & 0x%x == 0x%x?", ClassCode, ret->Match.Class.ClassMask, ret->Match.Class.ClassCode); + if( (ClassCode & ret->Match.Class.ClassMask) == ret->Match.Class.ClassCode ) + { + LOG("Found '%s'", ret->Name); + LEAVE('p', ret); + return ret; + } } - return 0; + LEAVE('n'); + return NULL; } -int USB_int_SendSetupSetAddress(tUSBHost *Host, void *Ptr, int Address) +// --- Hub Registration --- +// NOTE: Doesn't do much nowdays +tUSBHub *USB_RegisterHub(tUSBInterface *Device, int PortCount) { - struct sDeviceRequest req; - req.ReqType = 0; // bmRequestType - req.Request = 5; // SET_ADDRESS - req.Value = Address & 0x7F; // wValue - req.Index = 0; // wIndex - req.Length = 0; // wLength + tUSBHub *ret; - // Addr 0:0, Data Toggle = 0, no interrupt - return Host->HostDef->SendSETUP(Ptr, 0, 0, 0, FALSE, &req, sizeof(req)) == NULL; + ret = malloc(sizeof(tUSBHub) + sizeof(ret->Devices[0])*PortCount); + ret->Interface = Device; + ret->nPorts = PortCount; + memset(ret->Devices, 0, sizeof(ret->Devices[0])*PortCount); + return ret; +} + +void USB_RemoveHub(tUSBHub *Hub) +{ + for( int i = 0; i < Hub->nPorts; i ++ ) + { + if( Hub->Devices[i] ) + { + USB_DeviceDisconnected( Hub, i ); + } + } + free(Hub); } +