]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOInterruptEventSource.cpp
xnu-2422.100.13.tar.gz
[apple/xnu.git] / iokit / Kernel / IOInterruptEventSource.cpp
index 97d4c595761deb84c70f8a39341cc3b7e76d593b..6782ec9fe7152d173f7b2a1d0824a639728e2e61 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1998-2010 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * 
  * @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 <IOKit/IOInterruptEventSource.h>
 #include <IOKit/IOKitDebug.h>
 #include <IOKit/IOLib.h>
@@ -40,6 +34,31 @@ HISTORY
 #include <IOKit/IOTimeStamp.h>
 #include <IOKit/IOWorkLoop.h>
 
+#if IOKITSTATS
+
+#define IOStatisticsInitializeCounter() \
+do { \
+       IOStatistics::setCounterType(IOEventSource::reserved->counter, kIOStatisticsInterruptEventSourceCounter); \
+} while (0)
+
+#define IOStatisticsCheckForWork() \
+do { \
+       IOStatistics::countInterruptCheckForWork(IOEventSource::reserved->counter); \
+} while (0)
+
+#define IOStatisticsInterrupt() \
+do { \
+       IOStatistics::countInterrupt(IOEventSource::reserved->counter); \
+} while (0)
+
+#else
+
+#define IOStatisticsInitializeCounter()
+#define IOStatisticsCheckForWork()
+#define IOStatisticsInterrupt()
+
+#endif // IOKITSTATS
+
 #define super IOEventSource
 
 OSDefineMetaClassAndStructors(IOInterruptEventSource, IOEventSource)
@@ -74,6 +93,8 @@ bool IOInterruptEventSource::init(OSObject *inOwner,
            intIndex = inIntIndex;
     }
 
+    IOStatisticsInitializeCounter();
+
     return res;
 }
 
@@ -146,19 +167,20 @@ void IOInterruptEventSource::disable()
 
 void IOInterruptEventSource::setWorkLoop(IOWorkLoop *inWorkLoop)
 {
-    super::setWorkLoop(inWorkLoop);
-
-    if (!provider)
-       return;
-
-    if ( !inWorkLoop ) {
-       if (intIndex >= 0) {
-           provider->unregisterInterrupt(intIndex);
+    if (inWorkLoop) super::setWorkLoop(inWorkLoop);
+
+    if (provider) {
+       if (!inWorkLoop) {
+           if (intIndex >= 0) {
+               provider->unregisterInterrupt(intIndex);
+               intIndex = ~intIndex;
+           }
+       } else if ((intIndex < 0) && (kIOReturnSuccess == registerInterruptHandler(provider, ~intIndex))) {
            intIndex = ~intIndex;
        }
-    } else if ((intIndex < 0) && (kIOReturnSuccess == registerInterruptHandler(provider, ~intIndex))) {
-       intIndex = ~intIndex;
     }
+
+    if (!inWorkLoop) super::setWorkLoop(inWorkLoop);
 }
 
 const IOService *IOInterruptEventSource::getProvider() const
@@ -182,43 +204,45 @@ bool IOInterruptEventSource::checkForWork()
     int numInts = cacheProdCount - consumerCount;
     IOInterruptEventAction intAction = (IOInterruptEventAction) action;
        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);
-
+                                                VM_KERNEL_UNSLIDE(intAction), (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop);
+               
                // Call the handler
-        (*intAction)(owner, this,  numInts);
+               (*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();
-    }
+                                              VM_KERNEL_UNSLIDE(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);
+                                                VM_KERNEL_UNSLIDE(intAction), (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop);
                
                // Call the handler
-       (*intAction)(owner, this, -numInts);
+               (*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();
-    }
-
+                                              VM_KERNEL_UNSLIDE(intAction), (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop);
+               
+               consumerCount = cacheProdCount;
+               if (autoDisable && !explicitDisable)
+                       enable();
+       }
+       
     return false;
 }
 
@@ -226,14 +250,15 @@ void IOInterruptEventSource::normalInterruptOccurred
     (void */*refcon*/, IOService */*prov*/, int /*source*/)
 {
        bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false;
-
+       
+    IOStatisticsInterrupt();
     producerCount++;
-
+       
        if (trace)
            IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner);
        
     signalWorkAvailable();
-
+       
        if (trace)
            IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner);
 }
@@ -242,16 +267,17 @@ void IOInterruptEventSource::disableInterruptOccurred
     (void */*refcon*/, IOService *prov, int source)
 {
        bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false;
-
+       
     prov->disableInterrupt(source);    /* disable the interrupt */
-
+       
+    IOStatisticsInterrupt();
     producerCount++;
-
+       
        if (trace)
            IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner);
     
     signalWorkAvailable();
-
+       
        if (trace)
            IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner);
 }
@@ -264,3 +290,10 @@ void IOInterruptEventSource::interruptOccurred
     else
         normalInterruptOccurred(refcon, prov, source);
 }
+
+IOReturn IOInterruptEventSource::warmCPU
+    (uint64_t abstime)
+{
+
+       return ml_interrupt_prewarm(abstime);
+}