X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/43866e378188c25dd1e2208016ab3cbeb086ae6c..7ee9d059c4eecf68ae4f8b0fb99ae2471eda79af:/iokit/Kernel/IOInterruptEventSource.cpp diff --git a/iokit/Kernel/IOInterruptEventSource.cpp b/iokit/Kernel/IOInterruptEventSource.cpp index cbdd0aa6a..8b49024a1 100644 --- a/iokit/Kernel/IOInterruptEventSource.cpp +++ b/iokit/Kernel/IOInterruptEventSource.cpp @@ -1,16 +1,19 @@ /* - * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1998-2010 Apple Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER @@ -20,47 +23,41 @@ * Please see the License for the specific language governing rights and * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ -/* -Copyright (c) 1998 Apple Computer, Inc. All rights reserved. -HISTORY - 1998-7-13 Godfrey van der Linden(gvdl) - Created. -*/ #include +#include #include #include #include #include #include -#if KDEBUG +#if IOKITSTATS + +#define IOStatisticsInitializeCounter() \ +do { \ + IOStatistics::setCounterType(IOEventSource::reserved->counter, kIOStatisticsInterruptEventSourceCounter); \ +} while (0) + +#define IOStatisticsCheckForWork() \ +do { \ + IOStatistics::countInterruptCheckForWork(IOEventSource::reserved->counter); \ +} while (0) -#define IOTimeTypeStampS(t) \ -do { \ - IOTimeStampStart(IODBG_INTES(t), \ - (unsigned int) this, (unsigned int) owner); \ -} while(0) +#define IOStatisticsInterrupt() \ +do { \ + IOStatistics::countInterrupt(IOEventSource::reserved->counter); \ +} while (0) -#define IOTimeTypeStampE(t) \ -do { \ - IOTimeStampEnd(IODBG_INTES(t), \ - (unsigned int) this, (unsigned int) owner); \ -} while(0) +#else -#define IOTimeStampLatency() \ -do { \ - IOTimeStampEnd(IODBG_INTES(IOINTES_LAT), \ - (unsigned int) this, (unsigned int) owner); \ -} while(0) +#define IOStatisticsInitializeCounter() +#define IOStatisticsCheckForWork() +#define IOStatisticsInterrupt() -#else /* !KDEBUG */ -#define IOTimeTypeStampS(t) -#define IOTimeTypeStampE(t) -#define IOTimeStampLatency() -#endif /* KDEBUG */ +#endif // IOKITSTATS #define super IOEventSource @@ -75,9 +72,9 @@ OSMetaClassDefineReservedUnused(IOInterruptEventSource, 6); OSMetaClassDefineReservedUnused(IOInterruptEventSource, 7); bool IOInterruptEventSource::init(OSObject *inOwner, - Action inAction = 0, - IOService *inProvider = 0, - int inIntIndex = 0) + Action inAction, + IOService *inProvider, + int inIntIndex) { bool res = true; @@ -87,36 +84,45 @@ bool IOInterruptEventSource::init(OSObject *inOwner, provider = inProvider; producerCount = consumerCount = 0; autoDisable = explicitDisable = false; - intIndex = -1; + intIndex = ~inIntIndex; // Assumes inOwner holds a reference(retain) on the provider if (inProvider) { - int intType; - - res = (kIOReturnSuccess - == inProvider->getInterruptType(inIntIndex, &intType)); - if (res) { - IOInterruptAction intHandler; - - autoDisable = (intType == kIOInterruptTypeLevel); - if (autoDisable) { - intHandler = (IOInterruptAction) - &IOInterruptEventSource::disableInterruptOccurred; - } - else - intHandler = (IOInterruptAction) - &IOInterruptEventSource::normalInterruptOccurred; - - res = (kIOReturnSuccess == inProvider->registerInterrupt - (inIntIndex, this, intHandler)); - if (res) - intIndex = inIntIndex; - } + res = (kIOReturnSuccess == registerInterruptHandler(inProvider, inIntIndex)); + if (res) + intIndex = inIntIndex; } + IOStatisticsInitializeCounter(); + return res; } +IOReturn IOInterruptEventSource::registerInterruptHandler(IOService *inProvider, + int inIntIndex) +{ + IOReturn ret; + int intType; + IOInterruptAction intHandler; + + ret = inProvider->getInterruptType(inIntIndex, &intType); + if (kIOReturnSuccess != ret) + return (ret); + + autoDisable = (intType == kIOInterruptTypeLevel); + if (autoDisable) { + intHandler = OSMemberFunctionCast(IOInterruptAction, + this, &IOInterruptEventSource::disableInterruptOccurred); + } + else + intHandler = OSMemberFunctionCast(IOInterruptAction, + this, &IOInterruptEventSource::normalInterruptOccurred); + + ret = provider->registerInterrupt(inIntIndex, this, intHandler); + + return (ret); +} + IOInterruptEventSource * IOInterruptEventSource::interruptEventSource(OSObject *inOwner, Action inAction, @@ -126,7 +132,7 @@ IOInterruptEventSource::interruptEventSource(OSObject *inOwner, IOInterruptEventSource *me = new IOInterruptEventSource; if (me && !me->init(inOwner, inAction, inProvider, inIntIndex)) { - me->free(); + me->release(); return 0; } @@ -135,7 +141,7 @@ IOInterruptEventSource::interruptEventSource(OSObject *inOwner, void IOInterruptEventSource::free() { - if (provider && intIndex != -1) + if (provider && intIndex >= 0) provider->unregisterInterrupt(intIndex); super::free(); @@ -143,17 +149,36 @@ void IOInterruptEventSource::free() void IOInterruptEventSource::enable() { - if (provider && intIndex != -1) { + if (provider && intIndex >= 0) { provider->enableInterrupt(intIndex); explicitDisable = false; + enabled = true; } } void IOInterruptEventSource::disable() { - if (provider && intIndex != -1) { + if (provider && intIndex >= 0) { provider->disableInterrupt(intIndex); explicitDisable = true; + enabled = false; + } +} + +void IOInterruptEventSource::setWorkLoop(IOWorkLoop *inWorkLoop) +{ + super::setWorkLoop(inWorkLoop); + + if (!provider) + return; + + if ( !inWorkLoop ) { + if (intIndex >= 0) { + provider->unregisterInterrupt(intIndex); + intIndex = ~intIndex; + } + } else if ((intIndex < 0) && (kIOReturnSuccess == registerInterruptHandler(provider, ~intIndex))) { + intIndex = ~intIndex; } } @@ -177,66 +202,83 @@ bool IOInterruptEventSource::checkForWork() unsigned int cacheProdCount = producerCount; int numInts = cacheProdCount - consumerCount; IOInterruptEventAction intAction = (IOInterruptEventAction) action; - - if (numInts > 0) { - - IOTimeStampLatency(); - IOTimeTypeStampS(IOINTES_CLIENT); - IOTimeStampConstant(IODBG_INTES(IOINTES_ACTION), - (unsigned int) intAction, (unsigned int) owner); - (*intAction)(owner, this, numInts); - IOTimeTypeStampE(IOINTES_CLIENT); - - consumerCount = cacheProdCount; - if (autoDisable && !explicitDisable) - enable(); - } - else if (numInts < 0) { - IOTimeStampLatency(); - IOTimeTypeStampS(IOINTES_CLIENT); - IOTimeStampConstant(IODBG_INTES(IOINTES_ACTION), - (unsigned int) intAction, (unsigned int) owner); - (*intAction)(owner, this, -numInts); - IOTimeTypeStampE(IOINTES_CLIENT); - - consumerCount = cacheProdCount; - if (autoDisable && !explicitDisable) - enable(); - } - + bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; + + IOStatisticsCheckForWork(); + + if ( numInts > 0 ) + { + if (trace) + IOTimeStampStartConstant(IODBG_INTES(IOINTES_ACTION), + (uintptr_t) intAction, (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop); + + // Call the handler + (*intAction)(owner, this, numInts); + + if (trace) + IOTimeStampEndConstant(IODBG_INTES(IOINTES_ACTION), + (uintptr_t) intAction, (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop); + + consumerCount = cacheProdCount; + if (autoDisable && !explicitDisable) + enable(); + } + + else if ( numInts < 0 ) + { + if (trace) + IOTimeStampStartConstant(IODBG_INTES(IOINTES_ACTION), + (uintptr_t) intAction, (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop); + + // Call the handler + (*intAction)(owner, this, -numInts); + + if (trace) + IOTimeStampEndConstant(IODBG_INTES(IOINTES_ACTION), + (uintptr_t) intAction, (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop); + + consumerCount = cacheProdCount; + if (autoDisable && !explicitDisable) + enable(); + } + return false; } void IOInterruptEventSource::normalInterruptOccurred (void */*refcon*/, IOService */*prov*/, int /*source*/) { -IOTimeTypeStampS(IOINTES_INTCTXT); -IOTimeStampLatency(); - + bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; + + IOStatisticsInterrupt(); producerCount++; - -IOTimeTypeStampS(IOINTES_SEMA); + + if (trace) + IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner); + signalWorkAvailable(); -IOTimeTypeStampE(IOINTES_SEMA); - -IOTimeTypeStampE(IOINTES_INTCTXT); + + if (trace) + IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner); } void IOInterruptEventSource::disableInterruptOccurred (void */*refcon*/, IOService *prov, int source) { -IOTimeTypeStampS(IOINTES_INTCTXT); -IOTimeStampLatency(); - + bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; + prov->disableInterrupt(source); /* disable the interrupt */ - + + IOStatisticsInterrupt(); producerCount++; - -IOTimeTypeStampS(IOINTES_SEMA); + + if (trace) + IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner); + signalWorkAvailable(); -IOTimeTypeStampE(IOINTES_SEMA); - -IOTimeTypeStampE(IOINTES_INTCTXT); + + if (trace) + IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner); } void IOInterruptEventSource::interruptOccurred @@ -247,3 +289,10 @@ void IOInterruptEventSource::interruptOccurred else normalInterruptOccurred(refcon, prov, source); } + +IOReturn IOInterruptEventSource::warmCPU + (uint64_t abstime) +{ + + return ml_interrupt_prewarm(abstime); +}