3 * - By John Hodge (thePowersGang)
15 extern tUSBHost *gUSB_Hosts;
16 extern tUSBDriver gUSBHub_Driver;
21 tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts);
25 tUSBHost *gUSB_Hosts = NULL;
26 tMutex glUSB_InterfaceDrivers;
27 tUSBDriver *gpUSB_InterfaceDrivers = &gUSBHub_Driver;
30 tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts)
34 host = malloc(sizeof(tUSBHost) + nPorts*sizeof(void*));
39 host->HostDef = HostDef;
40 host->Ptr = ControllerPtr;
41 memset(host->AddressBitmap, 0, sizeof(host->AddressBitmap));
43 host->RootHubDev.ParentHub = NULL;
44 host->RootHubDev.Host = host;
45 host->RootHubDev.Address = 0;
47 // host->RootHubIf.Next = NULL;
48 host->RootHubIf.Dev = &host->RootHubDev;
49 host->RootHubIf.Driver = NULL;
50 host->RootHubIf.Data = NULL;
51 host->RootHubIf.nEndpoints = 0;
53 host->RootHub.Interface = &host->RootHubIf;
54 host->RootHub.nPorts = nPorts;
55 memset(host->RootHub.Devices, 0, sizeof(void*)*nPorts);
58 Mutex_Acquire( &glUSB_Hosts );
59 host->Next = gUSB_Hosts;
61 Mutex_Release( &glUSB_Hosts );
63 return &host->RootHub;
67 void USB_RegisterDriver(tUSBDriver *Driver)
69 Mutex_Acquire( &glUSB_InterfaceDrivers );
70 Driver->Next = gpUSB_InterfaceDrivers;
71 gpUSB_InterfaceDrivers = Driver;
72 Mutex_Release( &glUSB_InterfaceDrivers );
74 // TODO: Recheck devices that didn't have a driver
77 tUSBDriver *USB_int_FindDriverByClass(Uint32 ClassCode)
79 ENTER("xClassCode", ClassCode);
80 for( tUSBDriver *ret = gpUSB_InterfaceDrivers; ret; ret = ret->Next )
82 LOG(" 0x%x & 0x%x == 0x%x?", ClassCode, ret->Match.Class.ClassMask, ret->Match.Class.ClassCode);
83 if( (ClassCode & ret->Match.Class.ClassMask) == ret->Match.Class.ClassCode )
85 LOG("Found '%s'", ret->Name);
94 // --- Hub Registration ---
95 // NOTE: Doesn't do much nowdays
96 tUSBHub *USB_RegisterHub(tUSBInterface *Device, int PortCount)
100 ret = malloc(sizeof(tUSBHub) + sizeof(ret->Devices[0])*PortCount);
101 ret->Interface = Device;
102 ret->nPorts = PortCount;
103 memset(ret->Devices, 0, sizeof(ret->Devices[0])*PortCount);
107 void USB_RemoveHub(tUSBHub *Hub)
109 for( int i = 0; i < Hub->nPorts; i ++ )
111 if( Hub->Devices[i] )
113 USB_DeviceDisconnected( Hub, i );