📄 appleusbohci.cpp
字号:
IOSync(); IOSleep(1); // the spec says 10 microseconds } _pFreeITD = NULL; _pLastFreeITD = NULL; if (_itdMBHead) { AppleUSBOHCIitdMemoryBlock *curBlock = _itdMBHead; AppleUSBOHCIitdMemoryBlock *nextBlock; _itdMBHead = NULL; while (curBlock) { nextBlock = curBlock->GetNextBlock(); curBlock->release(); curBlock = nextBlock; } } _pFreeTD = NULL; _pLastFreeTD = NULL; if (_gtdMBHead) { AppleUSBOHCIgtdMemoryBlock *curBlock = _gtdMBHead; AppleUSBOHCIgtdMemoryBlock *nextBlock; _gtdMBHead = NULL; while (curBlock) { nextBlock = curBlock->GetNextBlock(); curBlock->release(); curBlock = nextBlock; } } _pFreeED = NULL; _pLastFreeED = NULL; if (_edMBHead) { AppleUSBOHCIedMemoryBlock *curBlock = _edMBHead; AppleUSBOHCIedMemoryBlock *nextBlock; _edMBHead = NULL; while (curBlock) { nextBlock = curBlock->GetNextBlock(); curBlock->release(); curBlock = nextBlock; } } // Free the HCCA memory // IOFree ( _pHCCA, kHCCAsize ); // Remove the interruptEventSource we created // if ( _filterInterruptSource ) { _workLoop->removeEventSource(_filterInterruptSource); _filterInterruptSource->release(); _filterInterruptSource = NULL; } // Release the memory cursors // if ( _genCursor ) { _genCursor->release(); _genCursor = NULL; } if ( _isoCursor ) { _isoCursor->release(); _isoCursor = NULL; } _uimInitialized = false; return(kIOReturnSuccess);}/* * got an error on a TD with no completion routine. * Search for a later TD on the same end point which does have one, * so we can tell upper layes of the error. */void AppleUSBOHCI::doCallback(AppleOHCIGeneralTransferDescriptorPtr nextTD, UInt32 transferStatus, UInt32 bufferSizeRemaining){ AppleOHCIGeneralTransferDescriptorPtr pCurrentTD, pTempTD; AppleOHCIEndpointDescriptorPtr pED; IOPhysicalAddress PhysAddr; pED = nextTD->pEndpoint; pED->pShared->flags |= HostToUSBWord(kOHCIEDControl_K); // mark endpoint as skipped PhysAddr = (IOPhysicalAddress) USBToHostLong(pED->pShared->tdQueueHeadPtr) & kOHCIHeadPMask; nextTD = AppleUSBOHCIgtdMemoryBlock::GetGTDFromPhysical(PhysAddr); pCurrentTD = nextTD; if(pCurrentTD == NULL) { USBLog(3, "%s[%p]::doCallback No transfer descriptors!", getName(), this); return; } USBLog(5, "AppleUSBOHCI::doCallback: pCurrentTD = %p, pED->pLogicalTailP = %p", pCurrentTD, pED->pLogicalTailP); while (pCurrentTD != pED->pLogicalTailP) { // UnlinkTD! But don't lose the data toggle or halt bit // pED->pShared->tdQueueHeadPtr = pCurrentTD->pShared->nextTD | (pED->pShared->tdQueueHeadPtr & HostToUSBLong(~kOHCIHeadPointer_headP)); USBLog(5, "AppleUSBOHCI::doCallback- queueheadptr is now %p", pED->pShared->tdQueueHeadPtr); bufferSizeRemaining += findBufferRemaining (pCurrentTD); // make sure this TD won't be added to any future buffer // remaining calculations pCurrentTD->pShared->currentBufferPtr = NULL; if (pCurrentTD->uimFlags & kUIMFlagsCallbackTD) { IOUSBCompletion completion; if (transferStatus == kOHCIGTDConditionDataUnderrun) { USBLog(5, "AppleUSBOHCI::doCallback- found callback TD, setting queuehead to %p", pED->pShared->tdQueueHeadPtr & HostToUSBLong(~kOHCIHeadPointer_H)); pED->pShared->tdQueueHeadPtr = pED->pShared->tdQueueHeadPtr & HostToUSBLong(~kOHCIHeadPointer_H); transferStatus = 0; } // zero out callback first then call it completion = pCurrentTD->command->GetUSLCompletion(); pCurrentTD->uimFlags &= ~kUIMFlagsCallbackTD; DeallocateTD(pCurrentTD); pED->pShared->flags &= ~HostToUSBWord(kOHCIEDControl_K); // mark endpoint as not skipped Complete(completion, TranslateStatusToUSBError(transferStatus), bufferSizeRemaining); bufferSizeRemaining = 0; return; } pTempTD = pCurrentTD->pLogicalNext; DeallocateTD(pCurrentTD); pCurrentTD = pTempTD; }}// FIXME add page size to param listUInt32 AppleUSBOHCI::findBufferRemaining (AppleOHCIGeneralTransferDescriptorPtr pCurrentTD){ UInt32 pageMask; UInt32 bufferSizeRemaining; pageMask = ~(_pageSize - 1); if (pCurrentTD->pShared->currentBufferPtr == 0) { bufferSizeRemaining = 0; } else if ((USBToHostLong(pCurrentTD->pShared->bufferEnd) & (pageMask)) == (USBToHostLong(pCurrentTD->pShared->currentBufferPtr)& (pageMask))) { // we're on the same page bufferSizeRemaining = (USBToHostLong (pCurrentTD->pShared->bufferEnd) & ~pageMask) - (USBToHostLong (pCurrentTD->pShared->currentBufferPtr) & ~pageMask) + 1; } else { bufferSizeRemaining = ((USBToHostLong(pCurrentTD->pShared->bufferEnd) & ~pageMask) + 1) + (_pageSize - (USBToHostLong(pCurrentTD->pShared->currentBufferPtr) & ~pageMask)); } return (bufferSizeRemaining);}IOReturn AppleUSBOHCI::ControlInitialize(void){ AppleOHCIEndpointDescriptorPtr pED, pED2; // Create ED, mark it skipped and assign it to Control tail // pED = AllocateED(); if ( pED == NULL ) return kIOReturnNoMemory; pED->pShared->flags = HostToUSBLong (kOHCIEDControl_K); pED->pShared->nextED = 0; // End of list _pControlTail = pED; // Create ED, mark it skipped and assign it to Control head // pED2 = AllocateED(); if ( pED2 == NULL ) return kIOReturnNoMemory; pED2->pShared->flags = HostToUSBLong (kOHCIEDControl_K); _pControlHead = pED2; _pOHCIRegisters->hcControlHeadED = HostToUSBLong ((UInt32) pED2->pPhysical); // Have Control head ED point to Control tail ED // pED2->pShared->nextED = HostToUSBLong ((UInt32) pED->pPhysical); pED2->pLogicalNext = pED; return kIOReturnSuccess;}IOReturn AppleUSBOHCI::BulkInitialize (void){ AppleOHCIEndpointDescriptorPtr pED, pED2; // Create ED, mark it skipped and assign it to Bulk tail // pED = AllocateED(); if ( pED == NULL ) return kIOReturnNoMemory; pED->pShared->flags = HostToUSBLong (kOHCIEDControl_K); pED->pShared->nextED = NULL; // End of list _pBulkTail = pED; // Create ED, mark it skipped and assign it to Bulk head // pED2 = AllocateED(); if ( pED2 == NULL ) return kIOReturnNoMemory; pED2->pShared->flags = HostToUSBLong (kOHCIEDControl_K); _pBulkHead = pED2; _pOHCIRegisters->hcBulkHeadED = HostToUSBLong ((UInt32) pED2->pPhysical); // Have Bulk head ED point to Bulk tail ED // pED2->pShared->nextED = HostToUSBLong ((UInt32) pED->pPhysical); pED2->pLogicalNext = pED; return kIOReturnSuccess;}IOReturn AppleUSBOHCI::IsochronousInitialize(void){ AppleOHCIEndpointDescriptorPtr pED, pED2; // Create ED mark it skipped and assign it to Isoch tail // pED = AllocateED(); if ( pED == NULL ) return kIOReturnNoMemory; pED->pShared->flags = HostToUSBLong (kOHCIEDControl_K); pED->pShared->nextED = NULL; // End of list _pIsochTail = pED; // Create ED mark it skipped and assign it to Isoch head // pED2 = AllocateED(); if ( pED2 == NULL ) return kIOReturnNoMemory; pED2->pShared->flags = HostToUSBLong (kOHCIEDControl_K); _pIsochHead = pED2; // have Isoch head ED point to Isoch tail ED // pED2->pShared->nextED = HostToUSBLong ((UInt32) pED->pPhysical); pED2->pLogicalNext = pED; _isochBandwidthAvail = kUSBMaxIsocFrameReqCount; return kIOReturnSuccess;}//Initializes the HCCA Interrupt list with statically//disabled ED's to form the Interrupt polling queuesIOReturn AppleUSBOHCI::InterruptInitialize (void){ UInt32 dummyControl; int i, p, q, z; AppleOHCIEndpointDescriptorPtr pED, pIsochHead; // create UInt32 with same dword0 for use with searching and // tracking, skip should be set, and open area should be marked dummyControl = kOHCIEDControl_K; dummyControl |= 0; //should be kOHCIFakeED dummyControl = HostToUSBLong (dummyControl); pIsochHead = (AppleOHCIEndpointDescriptorPtr) _pIsochHead; // do 31 times // change to 65 and make isoch head the last one.????? for (i = 0; i < 63; i++) { // allocate Endpoint descriptor pED = AllocateED(); if (pED == NULL) { return (kIOReturnNoMemory); } // mark skipped,some how mark as a False endpoint zzzzz else { pED->pShared->flags = dummyControl; pED->pShared->nextED = NULL; // End of list _pInterruptHead[i].pHead = pED; _pInterruptHead[i].pHeadPhysical = pED->pPhysical; _pInterruptHead[i].nodeBandwidth = 0; } if (i < 32) ((UInt32 *)_pHCCA)[i] = (UInt32) HostToUSBLong((UInt32) _pInterruptHead[i].pHeadPhysical); } p = 0; q = 32; // FIXME? ERIC for (i = 0; i < (32 +16 + 8 + 4 + 2); i++) { if (i < q/2+p) z = i + q; else z = i + q/2; if (i == p+q-1) { p = p + q; q = q/2; } // point endpoint descriptor to corresponding 8ms descriptor pED = _pInterruptHead[i].pHead; pED->pShared->nextED = HostToUSBLong (_pInterruptHead[z].pHeadPhysical); pED->pLogicalNext = _pInterruptHead[z].pHead; _pInterruptHead[i].pTail = (AppleOHCIEndpointDescriptorPtr) pED->pLogicalNext; } i = 62; pED = _pInterruptHead[i].pHead; pED->pShared->nextED = HostToUSBLong (pIsochHead->pPhysical); pED->pLogicalNext = _pIsochHead; _pInterruptHead[i].pTail = (AppleOHCIEndpointDescriptorPtr) pED->pLogicalNext; // point Isochronous head to last endpoint return kIOReturnSuccess;}AppleOHCIIsochTransferDescriptorPtr AppleUSBOHCI::AllocateITD(void){ AppleOHCIIsochTransferDescriptorPtr freeITD; // pop a TD off of FreeITD list // freeITD = _pFreeITD; if (freeITD == NULL) { // i need to allocate another page of EDs AppleUSBOHCIitdMemoryBlock *memBlock; UInt32 numTDs, i; memBlock = AppleUSBOHCIitdMemoryBlock::NewMemoryBlock(); if (!memBlock) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -