From 0387e49399279e685d2a2657392f3bccbf624184 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 8 Feb 2012 16:38:04 +0800 Subject: [PATCH] USB - Slight host API change --- KernelLand/Modules/USB/Core/include/usb_host.h | 2 +- KernelLand/Modules/USB/Core/usb.c | 8 ++------ KernelLand/Modules/USB/Core/usb_io.c | 2 +- KernelLand/Modules/USB/Core/usb_lowlevel.c | 18 ++++++++++-------- KernelLand/Modules/USB/UHCI/uhci.c | 18 +++++++++--------- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/KernelLand/Modules/USB/Core/include/usb_host.h b/KernelLand/Modules/USB/Core/include/usb_host.h index c5f3e39d..e2748da9 100644 --- a/KernelLand/Modules/USB/Core/include/usb_host.h +++ b/KernelLand/Modules/USB/Core/include/usb_host.h @@ -15,7 +15,7 @@ typedef struct sUSBHostDef tUSBHostDef; typedef void (*tUSBHostCb)(void *DataPtr, void *Data, int Length); -typedef void *(*tUSBHostOp)(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb CB, void *CbData, void *Data, size_t Length); +typedef void *(*tUSBHostOp)(void *Ptr, int Dest, int DataTgl, tUSBHostCb CB, void *CbData, void *Data, size_t Length); /** * \brief Defines a USB Host Controller type diff --git a/KernelLand/Modules/USB/Core/usb.c b/KernelLand/Modules/USB/Core/usb.c index 405a5081..a265be93 100644 --- a/KernelLand/Modules/USB/Core/usb.c +++ b/KernelLand/Modules/USB/Core/usb.c @@ -24,12 +24,6 @@ tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts) tUSBDriver *gpUSB_InterfaceDrivers = &gUSBHub_Driver; // === CODE === -void USB_RegisterDriver(tUSBDriver *Driver) -{ - Driver->Next = gpUSB_InterfaceDrivers; - gpUSB_InterfaceDrivers = Driver; -} - tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts) { tUSBHost *host; @@ -68,6 +62,8 @@ tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts) void USB_RegisterDriver(tUSBDriver *Driver) { Log_Warning("USB", "TODO: Implement USB_RegisterDriver"); + Driver->Next = gpUSB_InterfaceDrivers; + gpUSB_InterfaceDrivers = Driver; } tUSBDriver *USB_int_FindDriverByClass(Uint32 ClassCode) diff --git a/KernelLand/Modules/USB/Core/usb_io.c b/KernelLand/Modules/USB/Core/usb_io.c index 25ff59d2..38509d34 100644 --- a/KernelLand/Modules/USB/Core/usb_io.c +++ b/KernelLand/Modules/USB/Core/usb_io.c @@ -83,7 +83,7 @@ void USB_RecvDataA(tUSBInterface *Dev, int Endpoint, int Length, void *DataBuf, host = Dev->Dev->Host; LOG("IN from %p %i:%i", host->Ptr, Dev->Dev->Address, op->Endpt->EndpointNum); host->HostDef->SendIN( - host->Ptr, Dev->Dev->Address, op->Endpt->EndpointNum, + host->Ptr, Dev->Dev->Address*16 + op->Endpt->EndpointNum, 0, USB_AsyncCallback, op, DataBuf, Length ); diff --git a/KernelLand/Modules/USB/Core/usb_lowlevel.c b/KernelLand/Modules/USB/Core/usb_lowlevel.c index d8e1485a..3450bd80 100644 --- a/KernelLand/Modules/USB/Core/usb_lowlevel.c +++ b/KernelLand/Modules/USB/Core/usb_lowlevel.c @@ -25,13 +25,14 @@ void *USB_int_Request(tUSBHost *Host, int Addr, int EndPt, int Type, int Req, in void *hdl; // TODO: Sanity check (and check that Type is valid) struct sDeviceRequest req; + int dest = Addr * 16 + EndPt; // TODO: Validate req.ReqType = Type; req.Request = Req; req.Value = LittleEndian16( Val ); req.Index = LittleEndian16( Indx ); req.Length = LittleEndian16( Len ); - hdl = Host->HostDef->SendSETUP(Host->Ptr, Addr, EndPt, 0, NULL, NULL, &req, sizeof(req)); + hdl = Host->HostDef->SendSETUP(Host->Ptr, dest, 0, NULL, NULL, &req, sizeof(req)); // TODO: Data toggle? // TODO: Multi-packet transfers @@ -39,9 +40,9 @@ void *USB_int_Request(tUSBHost *Host, int Addr, int EndPt, int Type, int Req, in { void *hdl2; - hdl = Host->HostDef->SendIN(Host->Ptr, Addr, EndPt, 0, NULL, NULL, Data, Len); + hdl = Host->HostDef->SendIN(Host->Ptr, dest, 0, NULL, NULL, Data, Len); - hdl2 = Host->HostDef->SendOUT(Host->Ptr, Addr, EndPt, 0, NULL, NULL, NULL, 0); + hdl2 = Host->HostDef->SendOUT(Host->Ptr, dest, 0, NULL, NULL, NULL, 0); while( Host->HostDef->IsOpComplete(Host->Ptr, hdl2) == 0 ) Time_Delay(1); } @@ -50,12 +51,12 @@ void *USB_int_Request(tUSBHost *Host, int Addr, int EndPt, int Type, int Req, in void *hdl2; if( Len > 0 ) - hdl = Host->HostDef->SendOUT(Host->Ptr, Addr, EndPt, 0, NULL, NULL, Data, Len); + hdl = Host->HostDef->SendOUT(Host->Ptr, dest, 0, NULL, NULL, Data, Len); else hdl = NULL; // Status phase (DataToggle=1) - hdl2 = Host->HostDef->SendIN(Host->Ptr, Addr, EndPt, 1, NULL, NULL, NULL, 0); + hdl2 = Host->HostDef->SendIN(Host->Ptr, dest, 1, NULL, NULL, NULL, 0); while( Host->HostDef->IsOpComplete(Host->Ptr, hdl2) == 0 ) Time_Delay(1); } @@ -74,6 +75,7 @@ int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, i struct sDeviceRequest req; int bToggle = 0; void *final; + int dest = Dev->Address*16 + Endpoint; req.ReqType = 0x80; switch( Type & 0xF00 ) @@ -89,7 +91,7 @@ int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, i req.Length = LittleEndian16( Length ); Dev->Host->HostDef->SendSETUP( - Dev->Host->Ptr, Dev->Address, Endpoint, + Dev->Host->Ptr, dest, 0, NULL, NULL, &req, sizeof(req) ); @@ -98,7 +100,7 @@ int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, i while( Length > ciMaxPacketSize ) { Dev->Host->HostDef->SendIN( - Dev->Host->Ptr, Dev->Address, Endpoint, + Dev->Host->Ptr, dest, bToggle, NULL, NULL, Dest, ciMaxPacketSize ); @@ -107,7 +109,7 @@ int USB_int_ReadDescriptor(tUSBDevice *Dev, int Endpoint, int Type, int Index, i } final = Dev->Host->HostDef->SendIN( - Dev->Host->Ptr, Dev->Address, Endpoint, + Dev->Host->Ptr, dest, bToggle, INVLPTR, NULL, Dest, Length ); diff --git a/KernelLand/Modules/USB/UHCI/uhci.c b/KernelLand/Modules/USB/UHCI/uhci.c index 7b40b143..61755ca0 100644 --- a/KernelLand/Modules/USB/UHCI/uhci.c +++ b/KernelLand/Modules/USB/UHCI/uhci.c @@ -23,9 +23,9 @@ void UHCI_Cleanup(); tUHCI_TD *UHCI_int_AllocateTD(tUHCI_Controller *Cont); void UHCI_int_AppendTD(tUHCI_Controller *Cont, tUHCI_TD *TD); void *UHCI_int_SendTransaction(tUHCI_Controller *Cont, int Addr, Uint8 Type, int bTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length); -void *UHCI_DataIN(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length); -void *UHCI_DataOUT(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length); -void *UHCI_SendSetup(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length); +void *UHCI_DataIN(void *Ptr, int Dest, int DataTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length); +void *UHCI_DataOUT(void *Ptr, int Dest, int DataTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length); +void *UHCI_SendSetup(void *Ptr, int Dest, int DataTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length); int UHCI_IsTransferComplete(void *Ptr, void *Handle); int UHCI_Int_InitHost(tUHCI_Controller *Host); void UHCI_CheckPortUpdate(void *Ptr); @@ -255,19 +255,19 @@ void *UHCI_int_SendTransaction( return td; } -void *UHCI_DataIN(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length) +void *UHCI_DataIN(void *Ptr, int Dest, int DataTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length) { - return UHCI_int_SendTransaction(Ptr, Fcn*16+Endpt, 0x69, DataTgl, Cb, CbData, Buf, Length); + return UHCI_int_SendTransaction(Ptr, Dest, 0x69, DataTgl, Cb, CbData, Buf, Length); } -void *UHCI_DataOUT(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length) +void *UHCI_DataOUT(void *Ptr, int Dest, int DataTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length) { - return UHCI_int_SendTransaction(Ptr, Fcn*16+Endpt, 0xE1, DataTgl, Cb, CbData, Buf, Length); + return UHCI_int_SendTransaction(Ptr, Dest, 0xE1, DataTgl, Cb, CbData, Buf, Length); } -void *UHCI_SendSetup(void *Ptr, int Fcn, int Endpt, int DataTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length) +void *UHCI_SendSetup(void *Ptr, int Dest, int DataTgl, tUSBHostCb Cb, void *CbData, void *Buf, size_t Length) { - return UHCI_int_SendTransaction(Ptr, Fcn*16+Endpt, 0x2D, DataTgl, Cb, CbData, Buf, Length); + return UHCI_int_SendTransaction(Ptr, Dest, 0x2D, DataTgl, Cb, CbData, Buf, Length); } int UHCI_IsTransferComplete(void *Ptr, void *Handle) -- 2.20.1