From: John Hodge Date: Tue, 6 Mar 2012 03:53:43 +0000 (+0800) Subject: Modules/USB - Fixing lack of locking, some commenting updates X-Git-Tag: rel0.15~736^2~2 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=37416c25dfc4f0290b0e806aa7e6c2d3ae8e50e5;p=tpg%2Facess2.git Modules/USB - Fixing lack of locking, some commenting updates --- diff --git a/KernelLand/Modules/USB/Core/main.c b/KernelLand/Modules/USB/Core/main.c index df7f174f..6ef7a2bb 100644 --- a/KernelLand/Modules/USB/Core/main.c +++ b/KernelLand/Modules/USB/Core/main.c @@ -36,7 +36,6 @@ tDevFS_Driver gUSB_DrvInfo = { .Type = &gUSB_RootNodeType } }; -tUSBHost *gUSB_Hosts = NULL; // === CODE === /** diff --git a/KernelLand/Modules/USB/Core/usb.c b/KernelLand/Modules/USB/Core/usb.c index 3ebb0b34..e20f53cd 100644 --- a/KernelLand/Modules/USB/Core/usb.c +++ b/KernelLand/Modules/USB/Core/usb.c @@ -21,6 +21,9 @@ extern tUSBDriver gUSBHub_Driver; tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts); // === GLOBALS === +tMutex glUSB_Hosts; +tUSBHost *gUSB_Hosts = NULL; +tMutex glUSB_InterfaceDrivers; tUSBDriver *gpUSB_InterfaceDrivers = &gUSBHub_Driver; // === CODE === @@ -51,9 +54,11 @@ tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts) host->RootHub.nPorts = nPorts; memset(host->RootHub.Devices, 0, sizeof(void*)*nPorts); - // TODO: Lock + // Append to list + Mutex_Acquire( &glUSB_Hosts ); host->Next = gUSB_Hosts; gUSB_Hosts = host; + Mutex_Release( &glUSB_Hosts ); return &host->RootHub; } @@ -61,8 +66,12 @@ tUSBHub *USB_RegisterHost(tUSBHostDef *HostDef, void *ControllerPtr, int nPorts) // --- Drivers --- void USB_RegisterDriver(tUSBDriver *Driver) { + Mutex_Acquire( &glUSB_InterfaceDrivers ); Driver->Next = gpUSB_InterfaceDrivers; gpUSB_InterfaceDrivers = Driver; + Mutex_Release( &glUSB_InterfaceDrivers ); + + // TODO: Recheck devices that didn't have a driver } tUSBDriver *USB_int_FindDriverByClass(Uint32 ClassCode) diff --git a/KernelLand/Modules/USB/Core/usb_poll.c b/KernelLand/Modules/USB/Core/usb_poll.c index 12e14a9a..63596653 100644 --- a/KernelLand/Modules/USB/Core/usb_poll.c +++ b/KernelLand/Modules/USB/Core/usb_poll.c @@ -5,7 +5,7 @@ * usb_poll.c * - Endpoint polling */ -#define DEBUG 0 +#define DEBUG 1 #include #include "usb.h" #include @@ -32,6 +32,9 @@ void USB_int_PollCallback(void *Ptr, void *Data, size_t Length) op->Length = Length; op->Data = ep->InputData; + LOG("op %p, endpoint %p (0x%x)", op, ep, + ep->Interface->Dev->Address * 16 + ep->EndpointNum); + Workqueue_AddWork(&gUSB_AsyncQueue, op); } @@ -49,6 +52,7 @@ void USB_StartPollingEndpoint(tUSBInterface *Iface, int Endpoint) endpt = &Iface->Endpoints[Endpoint-1]; LOG("endpt(%p)->PollingPeriod = %i", endpt, endpt->PollingPeriod); if(endpt->PollingPeriod > 256 || endpt->PollingPeriod <= 0) { + LOG("Invalid polling period"); LEAVE('-'); return ; } @@ -56,7 +60,7 @@ void USB_StartPollingEndpoint(tUSBInterface *Iface, int Endpoint) // TODO: Check that this endpoint isn't already on the queue endpt->InputData = malloc(endpt->MaxPacketSize); - + LOG("Polling 0x%x at %i ms", Iface->Dev->Address * 16 + endpt->EndpointNum, endpt->PollingPeriod); Iface->Dev->Host->HostDef->InterruptIN( Iface->Dev->Host->Ptr, Iface->Dev->Address * 16 + endpt->EndpointNum,