XHCI: Reworking locking behavior and check for lock failures.
Should fix #14959.
This commit is contained in:
@@ -2294,10 +2294,19 @@ XHCI::HandleTransferComplete(xhci_trb* trb)
|
|||||||
xhci_device *device = &fDevices[slot];
|
xhci_device *device = &fDevices[slot];
|
||||||
xhci_endpoint *endpoint = &device->endpoints[endpointNumber - 1];
|
xhci_endpoint *endpoint = &device->endpoints[endpointNumber - 1];
|
||||||
|
|
||||||
|
if (endpoint->trbs == NULL) {
|
||||||
|
TRACE_ERROR("got TRB but endpoint is not allocated!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Use mutex_trylock first, in case we are in KDL.
|
// Use mutex_trylock first, in case we are in KDL.
|
||||||
if (mutex_trylock(&endpoint->lock) != B_OK)
|
MutexLocker endpointLocker(endpoint->lock,
|
||||||
mutex_lock(&endpoint->lock);
|
mutex_trylock(&endpoint->lock) == B_OK);
|
||||||
MutexLocker endpointLocker(endpoint->lock, true);
|
if (!endpointLocker.IsLocked()) {
|
||||||
|
// We failed to get the lock. Most likely it was destroyed
|
||||||
|
// while we were waiting for it.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
addr_t source = trb->qwtrb0;
|
addr_t source = trb->qwtrb0;
|
||||||
uint8 completionCode = TRB_2_COMP_CODE_GET(trb->dwtrb2);
|
uint8 completionCode = TRB_2_COMP_CODE_GET(trb->dwtrb2);
|
||||||
@@ -2581,8 +2590,12 @@ void
|
|||||||
XHCI::ProcessEvents()
|
XHCI::ProcessEvents()
|
||||||
{
|
{
|
||||||
// Use mutex_trylock first, in case we are in KDL.
|
// Use mutex_trylock first, in case we are in KDL.
|
||||||
if (mutex_trylock(&fEventLock) != B_OK)
|
MutexLocker locker(fEventLock, mutex_trylock(&fEventLock) == B_OK);
|
||||||
mutex_lock(&fEventLock);
|
if (!locker.IsLocked()) {
|
||||||
|
// We failed to get the lock. This really should not happen.
|
||||||
|
TRACE_ERROR("failed to acquire event lock!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uint16 i = fEventIdx;
|
uint16 i = fEventIdx;
|
||||||
uint8 j = fEventCcs;
|
uint8 j = fEventCcs;
|
||||||
@@ -2629,8 +2642,6 @@ XHCI::ProcessEvents()
|
|||||||
addr |= ERST_EHB;
|
addr |= ERST_EHB;
|
||||||
WriteRunReg32(XHCI_ERDP_LO(0), (uint32)addr);
|
WriteRunReg32(XHCI_ERDP_LO(0), (uint32)addr);
|
||||||
WriteRunReg32(XHCI_ERDP_HI(0), (uint32)(addr >> 32));
|
WriteRunReg32(XHCI_ERDP_HI(0), (uint32)(addr >> 32));
|
||||||
|
|
||||||
mutex_unlock(&fEventLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user