Modules/USB - Debugging polling and async
[tpg/acess2.git] / Modules / USB / Core / usb.c
index 60bf3f2..b319580 100644 (file)
@@ -1,6 +1,9 @@
 /*
- * Acess 2 USB Stack
- * USB Packet Control
+ * Acess2 USB Stack
+ * - By John Hodge (thePowersGang)
+ *
+ * usb.c
+ * - USB Structure
  */
 #define DEBUG  1
 #include <acess.h>
 #include <drv_pci.h>
 #include "usb.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 ===
-void USB_MakeToken(void *Buf, int PID, int Addr, int EndP)
+tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts)
 {
-       Uint8   *tok = Buf;
-        int    crc = 0;
+       tUSBHost        *host;
        
-       tok[0] = PID & 0xFF;
-       tok[1] = (Addr & 0x7F) | ((EndP&1)<<7);
-       tok[2] = ((EndP >> 1) & 0x7) | crc;
+       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));
+
+       host->RootHubDev.ParentHub = NULL;
+       host->RootHubDev.Host = host;
+       host->RootHubDev.Address = 0;
+
+//     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;
 }
 
-#if 0
-void USB_SendData(int Controller, int Dev, int Endpoint, void *Data, int Length)
+// --- Drivers ---
+void USB_RegisterDriver(tUSBDriver *Driver)
 {
-       Uint8   buf[Length+3+2/*?*/];
-       
-       USB_MakeToken(buf, PID_DATA0, Dev, Endpoint);
+       Log_Warning("USB", "TODO: Implement USB_RegisterDriver");
+}
+
+tUSBDriver *USB_int_FindDriverByClass(Uint32 ClassCode)
+{
+       ENTER("xClassCode", ClassCode);
+       for( tUSBDriver *ret = gpUSB_InterfaceDrivers; ret; ret = ret->Next )
+       {
+               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;
+               }
+       }
+       LEAVE('n');
+       return NULL;
+}
+
+// --- Hub Registration ---
+// NOTE: Doesn't do much nowdays
+tUSBHub *USB_RegisterHub(tUSBInterface *Device, int PortCount)
+{
+       tUSBHub *ret;
        
-       switch(Controller & 0xF00)
+       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 ++ )
        {
-       case 1: // UHCI
-               UHCI_SendPacket(Controller & 0xFF);
-               break;
+               if( Hub->Devices[i] )
+               {
+                       USB_DeviceDisconnected( Hub, i );
+               }
        }
+       free(Hub);
 }
-#endif
+

UCC git Repository :: git.ucc.asn.au