TODO
[tpg/acess2.git] / KernelLand / Modules / USB / UHCI / uhci.c
index dd07210..257171a 100644 (file)
@@ -191,7 +191,7 @@ int UHCI_int_InitHost(tUHCI_Controller *Host)
                1,17,9,25,5,21,13,29,3,19,11,27,7,23,15,31
                };
        for( int i = 0; i < 1024; i ++ ) {
-               Uint32  addr = MM_GetPhysAddr( (tVAddr)&Host->TDQHPage->ControlQH );
+               Uint32  addr = MM_GetPhysAddr( &Host->TDQHPage->ControlQH );
                Host->FrameList[i] = addr | 2;
        }
        for( int i = 0; i < 64; i ++ ) {
@@ -220,12 +220,12 @@ int UHCI_int_InitHost(tUHCI_Controller *Host)
                        dest += _count; destphys += _count * sizeof(tUHCI_QH);
                }
                // Skip padding, and move to control QH
-               dest->Next = MM_GetPhysAddr( (tVAddr)&Host->TDQHPage->BulkQH ) | 2;
+               dest->Next = MM_GetPhysAddr( &Host->TDQHPage->BulkQH ) | 2;
                dest->Child = 1;
        }
 
        // Set up control and bulk queues
-       Host->TDQHPage->ControlQH.Next = MM_GetPhysAddr( (tVAddr)&Host->TDQHPage->BulkQH ) | 2;
+       Host->TDQHPage->ControlQH.Next = MM_GetPhysAddr( &Host->TDQHPage->BulkQH ) | 2;
        Host->TDQHPage->ControlQH.Child = 1;
        Host->TDQHPage->BulkQH.Next = 1;
        Host->TDQHPage->BulkQH.Child = 1;
@@ -297,11 +297,11 @@ void UHCI_int_AppendTD(tUHCI_Controller *Cont, tUHCI_QH *QH, tUHCI_TD *TD)
        // Add
        TD->Link = 1;
        if( QH->Child & 1 ) {
-               QH->Child = MM_GetPhysAddr( (tVAddr)TD );
+               QH->Child = MM_GetPhysAddr( TD );
        }
        else {
                // Depth first
-               QH->_LastItem->Link = MM_GetPhysAddr( (tVAddr)TD ) | 4;
+               QH->_LastItem->Link = MM_GetPhysAddr( TD ) | 4;
        }
        QH->_LastItem = TD;
 
@@ -360,7 +360,7 @@ tUHCI_TD *UHCI_int_CreateTD(
        if(
                ((tVAddr)Data & (PAGE_SIZE-1)) + Length > PAGE_SIZE
        #if PHYS_BITS > 32
-               || MM_GetPhysAddr( (tVAddr)Data ) >> 32
+               || MM_GetPhysAddr( Data ) >> 32
        #endif
                )
        {
@@ -373,14 +373,14 @@ tUHCI_TD *UHCI_int_CreateTD(
                        LOG("Relocated IN");
                        info = calloc( sizeof(tUHCI_ExtraTDInfo), 1 );
                        info->Offset = ((tVAddr)Data & (PAGE_SIZE-1));
-                       info->FirstPage = MM_GetPhysAddr( (tVAddr)Data );
-                       info->SecondPage = MM_GetPhysAddr( (tVAddr)Data + Length - 1 );
+                       info->FirstPage = MM_GetPhysAddr( Data );
+                       info->SecondPage = MM_GetPhysAddr( (const char *)Data + Length - 1 );
                }
                else
                {
                        LOG("Relocated OUT/SETUP");
-                       tVAddr  ptr = MM_MapTemp(td->BufferPointer);
-                       memcpy( (void*)ptr, Data, Length );
+                       void *ptr = MM_MapTemp(td->BufferPointer);
+                       memcpy( ptr, Data, Length );
                        MM_FreeTemp(ptr);
                        td->Control |= TD_CTL_IOC;
                }
@@ -388,7 +388,7 @@ tUHCI_TD *UHCI_int_CreateTD(
        }
        else
        {
-               td->BufferPointer = MM_GetPhysAddr( (tVAddr)Data );
+               td->BufferPointer = MM_GetPhysAddr( Data );
                td->_info.bFreePointer = 0;
        }
 
@@ -578,19 +578,12 @@ void *UHCI_BulkOUT(void *Ptr, int Dest, int bToggle, tUSBHostCb Cb, void *CbData
 
        ENTER("pPtr xDest ibToggle pCb pCbData pData iLength", Ptr, Dest, bToggle, Cb, CbData, Buf, Length);
 
-       while( Length > MAX_PACKET_SIZE )
-       {
-               LOG("MaxPacket (rem = %i)", Length);
-               td = UHCI_int_CreateTD(Cont, Dest, PID_OUT, bToggle, NULL, NULL, src, MAX_PACKET_SIZE);
-               UHCI_int_AppendTD(Cont, qh, td);
-               
-               bToggle = !bToggle;
-               Length -= MAX_PACKET_SIZE;
-               src += MAX_PACKET_SIZE;
+       if( Length > MAX_PACKET_SIZE ) {
+               Log_Error("UHCI", "Passed an oversized packet by the USB code (%i > %i)", Length, MAX_PACKET_SIZE);
+               LEAVE('n');
        }
-
-       LOG("Final");
-       td = UHCI_int_CreateTD(Cont, Dest, PID_OUT, bToggle, NULL, NULL, src, Length);
+       
+       td = UHCI_int_CreateTD(Cont, Dest, PID_OUT, bToggle, Cb, CbData, src, Length);
        UHCI_int_AppendTD(Cont, qh, td);
 
        LEAVE('p', td);
@@ -604,19 +597,12 @@ void *UHCI_BulkIN(void *Ptr, int Dest, int bToggle, tUSBHostCb Cb, void *CbData,
        char    *dst = Buf;
 
        ENTER("pPtr xDest ibToggle pCb pCbData pData iLength", Ptr, Dest, bToggle, Cb, CbData, Buf, Length);
-       while( Length > MAX_PACKET_SIZE )
-       {
-               LOG("MaxPacket (rem = %i)", Length);
-               td = UHCI_int_CreateTD(Cont, Dest, PID_IN, bToggle, NULL, NULL, dst, MAX_PACKET_SIZE);
-               UHCI_int_AppendTD(Cont, qh, td);
-               
-               bToggle = !bToggle;
-               Length -= MAX_PACKET_SIZE;
-               dst += MAX_PACKET_SIZE;
+       if( Length > MAX_PACKET_SIZE ) {
+               Log_Error("UHCI", "Passed an oversized packet by the USB code (%i > %i)", Length, MAX_PACKET_SIZE);
+               LEAVE('n');
        }
 
-       LOG("Final");
-       td = UHCI_int_CreateTD(Cont, Dest, PID_IN, bToggle, NULL, NULL, dst, Length);
+       td = UHCI_int_CreateTD(Cont, Dest, PID_IN, bToggle, Cb, CbData, dst, Length);
        UHCI_int_AppendTD(Cont, qh, td);
 
        LEAVE('p', td);
@@ -675,7 +661,7 @@ tUHCI_TD *UHCI_int_GetTDFromPhys(tUHCI_Controller *Controller, Uint32 PAddr)
        }
 
        
-       tPAddr  global_pool = MM_GetPhysAddr( (tVAddr)gaUHCI_TDPool );
+       tPAddr  global_pool = MM_GetPhysAddr( gaUHCI_TDPool );
        
        if( PAddr < global_pool || PAddr >= global_pool + PAGE_SIZE )   return NULL;
        
@@ -742,8 +728,8 @@ void UHCI_int_HandleTDComplete(tUHCI_Controller *Cont, tUHCI_TD *TD)
        {
                char    *src, *dest;
                 int    src_ofs = TD->BufferPointer & (PAGE_SIZE-1);
-               src = (void *) MM_MapTemp(TD->BufferPointer);
-               dest = (void *) MM_MapTemp(info->FirstPage);
+               src = MM_MapTemp(TD->BufferPointer);
+               dest = MM_MapTemp(info->FirstPage);
                // Check for a single page transfer
                if( byte_count + info->Offset <= PAGE_SIZE )
                {
@@ -758,21 +744,21 @@ void UHCI_int_HandleTDComplete(tUHCI_Controller *Cont, tUHCI_TD *TD)
                                TD->BufferPointer, info->FirstPage, info->SecondPage, TD);
                         int    part_len = PAGE_SIZE - info->Offset;
                        memcpy(dest + info->Offset, src + src_ofs, part_len);
-                       MM_FreeTemp( (tVAddr)dest );
-                       dest = (void *) MM_MapTemp(info->SecondPage);
+                       MM_FreeTemp( dest );
+                       dest = MM_MapTemp(info->SecondPage);
                        memcpy(dest, src + src_ofs + part_len, byte_count - part_len);
                }
-               MM_FreeTemp( (tVAddr)src );
-               MM_FreeTemp( (tVAddr)dest );
+               MM_FreeTemp( src );
+               MM_FreeTemp( dest );
        }
 
        // Callback
        if( info->Callback != NULL )
        {
                LOG("Calling cb %p (%i bytes)", info->Callback, byte_count);
-               void    *ptr = (void *) MM_MapTemp( TD->BufferPointer );
+               void    *ptr = MM_MapTemp( TD->BufferPointer );
                info->Callback( info->CallbackPtr, ptr, byte_count );
-               MM_FreeTemp( (tVAddr)ptr );
+               MM_FreeTemp( ptr );
        }
        
        // Clean up info
@@ -870,6 +856,7 @@ void UHCI_InterruptHandler(int IRQ, void *Ptr)
        Uint16  status = _InWord(Host, USBSTS);
        
        LOG("%p: status = 0x%04x", Ptr, status);
+       
        // Interrupt-on-completion
        if( status & 1 )
        {
@@ -877,6 +864,31 @@ void UHCI_InterruptHandler(int IRQ, void *Ptr)
                Semaphore_Signal(&gUHCI_InterruptSempahore, 1);
        }
 
+       // USB Error Interrupt
+       if( status & 2 )
+       {
+               
+       }
+
+       // Resume Detect
+       // - Fired if in suspend state and a USB device sends the RESUME signal
+       if( status & 4 )
+       {
+               
+       }
+
+       // Host System Error
+       if( status & 8 )
+       {
+               
+       }
+
+       // Host Controller Process Error
+       if( status & 0x10 )
+       {
+               Log_Error("UHCI", "Host controller process error on controller %p", Ptr);
+       }
+
        _OutWord(Host, USBSTS, status);
 }
 

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