Loading...
iokit/Kernel/IOInterruptController.cpp xnu-1504.3.12 xnu-792
--- xnu/xnu-1504.3.12/iokit/Kernel/IOInterruptController.cpp
+++ xnu/xnu-792/iokit/Kernel/IOInterruptController.cpp
@@ -1,29 +1,23 @@
 /*
- * Copyright (c) 1998-2008 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * @APPLE_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. 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.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License").  You may not use this file except in compliance with the
+ * License.  Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
  * 
- * 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
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
  * 
- * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ * @APPLE_LICENSE_HEADER_END@
  */
 /*
  * Copyright (c) 1999 Apple Computer, Inc.  All rights reserved. 
@@ -44,6 +38,7 @@
 #include <IOKit/IOInterrupts.h>
 #include <IOKit/IOInterruptController.h>
 
+
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 #define super IOService
@@ -65,21 +60,19 @@
 						  void *refCon)
 {
   IOInterruptSource *interruptSources;
-  IOInterruptVectorNumber vectorNumber;
-  IOInterruptVector *vector;
-  int               wasDisabledSoft;
+  long              vectorNumber;
+  IOInterruptVector *vector;
+  long              wasDisabledSoft;
   IOReturn          error;
   OSData            *vectorData;
+  IOService         *originalNub;
+  int               originalSource;
   IOOptionBits      options;
   bool              canBeShared, shouldBeShared, wasAlreadyRegisterd;
-
-  IOService         *originalNub = NULL; // Protected by wasAlreadyRegisterd
-  int               originalSource = 0; // Protected by wasAlreadyRegisterd
- 
-
-  interruptSources = nub->_interruptSources;
-  vectorData = interruptSources[source].vectorData;
-  vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy();
+  
+  interruptSources = nub->_interruptSources;
+  vectorData = interruptSources[source].vectorData;
+  vectorNumber = *(long *)vectorData->getBytesNoCopy();
   vector = &vectors[vectorNumber];
   
   // Get the lock for this vector.
@@ -88,15 +81,6 @@
   // Check if the interrupt source can/should be shared.
   canBeShared = vectorCanBeShared(vectorNumber, vector);
   IODTGetInterruptOptions(nub, source, &options);
-#if defined(__i386__) || defined(__x86_64__)
-  int   interruptType;
-  if (OSDynamicCast(IOPlatformDevice, getProvider()) &&
-      (getInterruptType(nub, source, &interruptType) == kIOReturnSuccess) &&
-      (kIOInterruptTypeLevel & interruptType))
-  {
-    options |= kIODTInterruptShared;
-  }
-#endif
   shouldBeShared = canBeShared && (options & kIODTInterruptShared);
   wasAlreadyRegisterd = vector->interruptRegistered;
   
@@ -193,7 +177,6 @@
       vector->interruptRegistered   = 1;
       
       // Enable the original consumer's interrupt if needed.
-      // originalNub is protected by wasAlreadyRegisterd here (see line 184).
       if (!wasDisabledSoft) originalNub->enableInterrupt(originalSource);
     }
     
@@ -225,13 +208,13 @@
 IOReturn IOInterruptController::unregisterInterrupt(IOService *nub, int source)
 {
   IOInterruptSource *interruptSources;
-  IOInterruptVectorNumber vectorNumber;
-  IOInterruptVector *vector;
-  OSData            *vectorData;
-  
-  interruptSources = nub->_interruptSources;
-  vectorData = interruptSources[source].vectorData;
-  vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy();
+  long              vectorNumber;
+  IOInterruptVector *vector;
+  OSData            *vectorData;
+  
+  interruptSources = nub->_interruptSources;
+  vectorData = interruptSources[source].vectorData;
+  vectorNumber = *(long *)vectorData->getBytesNoCopy();
   vector = &vectors[vectorNumber];
   
   // Get the lock for this vector.
@@ -268,7 +251,7 @@
 						 int *interruptType)
 {
   IOInterruptSource *interruptSources;
-  IOInterruptVectorNumber vectorNumber;
+  long              vectorNumber;
   IOInterruptVector *vector;
   OSData            *vectorData;
   
@@ -276,7 +259,7 @@
   
   interruptSources = nub->_interruptSources;
   vectorData = interruptSources[source].vectorData;
-  vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy();
+  vectorNumber = *(long *)vectorData->getBytesNoCopy();
   vector = &vectors[vectorNumber];
   
   *interruptType = getVectorType(vectorNumber, vector);
@@ -287,13 +270,13 @@
 IOReturn IOInterruptController::enableInterrupt(IOService *nub, int source)
 {
   IOInterruptSource *interruptSources;
-  IOInterruptVectorNumber vectorNumber;
-  IOInterruptVector *vector;
-  OSData            *vectorData;
-  
-  interruptSources = nub->_interruptSources;
-  vectorData = interruptSources[source].vectorData;
-  vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy();
+  long              vectorNumber;
+  IOInterruptVector *vector;
+  OSData            *vectorData;
+  
+  interruptSources = nub->_interruptSources;
+  vectorData = interruptSources[source].vectorData;
+  vectorNumber = *(long *)vectorData->getBytesNoCopy();
   vector = &vectors[vectorNumber];
   
   if (vector->interruptDisabledSoft) {
@@ -304,8 +287,7 @@
 #endif
     
     if (!getPlatform()->atInterruptLevel()) {
-      while (vector->interruptActive)
-	{}
+      while (vector->interruptActive);
 #if __ppc__
       isync();
 #endif
@@ -323,13 +305,13 @@
 IOReturn IOInterruptController::disableInterrupt(IOService *nub, int source)
 {
   IOInterruptSource *interruptSources;
-  IOInterruptVectorNumber vectorNumber;
-  IOInterruptVector *vector;
-  OSData            *vectorData;
-  
-  interruptSources = nub->_interruptSources;
-  vectorData = interruptSources[source].vectorData;
-  vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy();
+  long              vectorNumber;
+  IOInterruptVector *vector;
+  OSData            *vectorData;
+  
+  interruptSources = nub->_interruptSources;
+  vectorData = interruptSources[source].vectorData;
+  vectorNumber = *(long *)vectorData->getBytesNoCopy();
   vector = &vectors[vectorNumber];
   
   vector->interruptDisabledSoft = 1;
@@ -339,8 +321,7 @@
 #endif
   
   if (!getPlatform()->atInterruptLevel()) {
-    while (vector->interruptActive)
-	{}
+    while (vector->interruptActive);
 #if __ppc__
     isync();
 #endif
@@ -352,13 +333,13 @@
 IOReturn IOInterruptController::causeInterrupt(IOService *nub, int source)
 {
   IOInterruptSource *interruptSources;
-  IOInterruptVectorNumber vectorNumber;
-  IOInterruptVector *vector;
-  OSData            *vectorData;
-
-  interruptSources = nub->_interruptSources;
-  vectorData = interruptSources[source].vectorData;
-  vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy();
+  long              vectorNumber;
+  IOInterruptVector *vector;
+  OSData            *vectorData;
+
+  interruptSources = nub->_interruptSources;
+  vectorData = interruptSources[source].vectorData;
+  vectorNumber = *(long *)vectorData->getBytesNoCopy();
   vector = &vectors[vectorNumber];
   
   causeVector(vectorNumber, vector);
@@ -380,34 +361,34 @@
 
 // Methods to be overridden for simplifed interrupt controller subclasses.
 
-bool IOInterruptController::vectorCanBeShared(IOInterruptVectorNumber /*vectorNumber*/,
+bool IOInterruptController::vectorCanBeShared(long /*vectorNumber*/,
 					      IOInterruptVector */*vector*/)
 {
   return false;
 }
 
-void IOInterruptController::initVector(IOInterruptVectorNumber /*vectorNumber*/,
+void IOInterruptController::initVector(long /*vectorNumber*/,
 				       IOInterruptVector */*vector*/)
 {
 }
 
-int IOInterruptController::getVectorType(IOInterruptVectorNumber /*vectorNumber*/,
+int IOInterruptController::getVectorType(long /*vectorNumber*/,
 					  IOInterruptVector */*vector*/)
 {
   return kIOInterruptTypeEdge;
 }
 
-void IOInterruptController::disableVectorHard(IOInterruptVectorNumber /*vectorNumber*/,
+void IOInterruptController::disableVectorHard(long /*vectorNumber*/,
 					      IOInterruptVector */*vector*/)
 {
 }
 
-void IOInterruptController::enableVector(IOInterruptVectorNumber /*vectorNumber*/,
+void IOInterruptController::enableVector(long /*vectorNumber*/,
 					 IOInterruptVector */*vector*/)
 {
 }
 
-void IOInterruptController::causeVector(IOInterruptVectorNumber /*vectorNumber*/,
+void IOInterruptController::causeVector(long /*vectorNumber*/,
 					IOInterruptVector */*vector*/)
 {
 }
@@ -446,8 +427,6 @@
   _numInterruptSources = 1;
   
   // Set up the IOInterruptSource to point at this.
-  parentController->retain();
-  parentSource->retain();
   _interruptSources[0].interruptController = parentController;
   _interruptSources[0].vectorData = parentSource;
   
@@ -498,7 +477,7 @@
 							void *refCon)
 {
   IOInterruptSource *interruptSources;
-  IOInterruptVectorNumber vectorNumber;
+  long              vectorNumber;
   IOInterruptVector *vector = 0;
   OSData            *vectorData;
   IOInterruptState  interruptState;
@@ -562,51 +541,52 @@
 IOReturn IOSharedInterruptController::unregisterInterrupt(IOService *nub,
 							  int source)
 {
-  IOInterruptVectorNumber vectorNumber;
-  IOInterruptVector *vector;
+  IOInterruptSource *interruptSources;
+  long              vectorNumber;
+  IOInterruptVector *vector;
+  OSData            *vectorData;
   IOInterruptState  interruptState;
-
-  for (vectorNumber = 0; vectorNumber < kIOSharedInterruptControllerDefaultVectors; vectorNumber++) {
-    vector = &vectors[vectorNumber];
-
-    // Get the lock for this vector.
-    IOTakeLock(vector->interruptLock);
-
-    // Return success if it is not already registered
-    if (!vector->interruptRegistered
-     || (vector->nub != nub) || (vector->source != source)) {
-        IOUnlock(vector->interruptLock);
-        continue;
-    }
-
-    // Soft disable the source and the controller too.
-    disableInterrupt(nub, source);
-
-    // Clear all the storage for the vector except for interruptLock.
-    vector->interruptActive = 0;
-    vector->interruptDisabledSoft = 0;
-    vector->interruptDisabledHard = 0;
-    vector->interruptRegistered = 0;
-    vector->nub = 0;
-    vector->source = 0;
-    vector->handler = 0;
-    vector->target = 0;
-    vector->refCon = 0;
-
-    interruptState = IOSimpleLockLockDisableInterrupt(controllerLock);
-    vectorsRegistered--;
-    IOSimpleLockUnlockEnableInterrupt(controllerLock, interruptState);
-
-    // Move along to the next one.
+  
+  interruptSources = nub->_interruptSources;
+  vectorData = interruptSources[source].vectorData;
+  vectorNumber = *(long *)vectorData->getBytesNoCopy();
+  vector = &vectors[vectorNumber];
+  
+  // Get the lock for this vector.
+  IOTakeLock(vector->interruptLock);
+  
+  // Return success if it is not already registered
+  if (!vector->interruptRegistered) {
     IOUnlock(vector->interruptLock);
-  }
-
+    return kIOReturnSuccess;
+  }
+  
+  // Soft disable the source and the controller too.
+  disableInterrupt(nub, source);
+  
+  // Clear all the storage for the vector except for interruptLock.
+  vector->interruptActive = 0;
+  vector->interruptDisabledSoft = 0;
+  vector->interruptDisabledHard = 0;
+  vector->interruptRegistered = 0;
+  vector->nub = 0;
+  vector->source = 0;
+  vector->handler = 0;
+  vector->target = 0;
+  vector->refCon = 0;
+  
+  interruptState = IOSimpleLockLockDisableInterrupt(controllerLock);
+  vectorsRegistered--;
+  IOSimpleLockUnlockEnableInterrupt(controllerLock, interruptState);
+  
+  IOUnlock(vector->interruptLock);
+  
   // Re-enable the controller if all vectors are enabled.
   if (vectorsEnabled == vectorsRegistered) {
     controllerDisabled = 0;
     provider->enableInterrupt(0);
   }
-
+  
   return kIOReturnSuccess;
 }
 
@@ -621,14 +601,14 @@
 						      int source)
 {
   IOInterruptSource *interruptSources;
-  IOInterruptVectorNumber vectorNumber;
+  long              vectorNumber;
   IOInterruptVector *vector;
   OSData            *vectorData;
   IOInterruptState  interruptState;
   
   interruptSources = nub->_interruptSources;
   vectorData = interruptSources[source].vectorData;
-  vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy();
+  vectorNumber = *(long *)vectorData->getBytesNoCopy();
   vector = &vectors[vectorNumber];
   
   interruptState = IOSimpleLockLockDisableInterrupt(controllerLock);
@@ -653,14 +633,14 @@
 						       int source)
 {
   IOInterruptSource *interruptSources;
-  IOInterruptVectorNumber vectorNumber;
+  long              vectorNumber;
   IOInterruptVector *vector;
   OSData            *vectorData;
   IOInterruptState  interruptState;
   
   interruptSources = nub->_interruptSources;
   vectorData = interruptSources[source].vectorData;
-  vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy();
+  vectorNumber = *(long *)vectorData->getBytesNoCopy();
   vector = &vectors[vectorNumber];
   
   interruptState = IOSimpleLockLockDisableInterrupt(controllerLock); 
@@ -675,8 +655,7 @@
   IOSimpleLockUnlockEnableInterrupt(controllerLock, interruptState);
   
   if (!getPlatform()->atInterruptLevel()) {
-    while (vector->interruptActive)
-	{}
+    while (vector->interruptActive);
 #if __ppc__
     isync();
 #endif
@@ -687,15 +666,14 @@
 
 IOInterruptAction IOSharedInterruptController::getInterruptHandlerAddress(void)
 {
-    return OSMemberFunctionCast(IOInterruptAction,
-			this, &IOSharedInterruptController::handleInterrupt);
+    return (IOInterruptAction)&IOSharedInterruptController::handleInterrupt;
 }
 
 IOReturn IOSharedInterruptController::handleInterrupt(void * /*refCon*/,
 						      IOService * nub,
 						      int /*source*/)
 {
-  IOInterruptVectorNumber vectorNumber;
+  long              vectorNumber;
   IOInterruptVector *vector;
   
   for (vectorNumber = 0; vectorNumber < numVectors; vectorNumber++) {