2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
36 #include <IOKit/IOPlatformExpert.h>
38 #include "GenericInterruptController.h"
40 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 #define super IOInterruptController
45 IODefineMetaClassAndStructors(GenericInterruptController
,
46 IOInterruptController
);
48 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
51 bool GenericInterruptController::start(IOService
*provider
)
53 IOInterruptAction handler
;
54 IOSymbol
*interruptControllerName
;
56 // If needed call the parents start.
57 if (!super::start(provider
))
60 // Map the device's memory and initalize its state.
62 // For now you must allocate storage for the vectors.
63 // This will probably changed to something like: initVectors(numVectors).
64 // In the mean time something like this works well.
66 // Allocate the memory for the vectors.
67 vectors
= (IOInterruptVector
*)IOMalloc(numVectors
*
68 sizeof(IOInterruptVector
));
69 if (vectors
== NULL
) return false;
70 bzero(vectors
, numVectors
* sizeof(IOInterruptVector
));
72 // Allocate locks for the vectors.
73 for (cnt
= 0; cnt
< numVectors
; cnt
++) {
74 vectors
[cnt
].interruptLock
= IOLockAlloc();
75 if (vectors
[cnt
].interruptLock
== NULL
) {
76 for (cnt
= 0; cnt
< numVectors
; cnt
++) {
77 if (vectors
[cnt
].interruptLock
!= NULL
)
78 IOLockFree(vectors
[cnt
].interruptLock
);
84 // If you know that this interrupt controller is the primary
85 // interrupt controller, use this to set it nub properties properly.
86 // This may be done by the nub's creator.
87 getPlatform()->setCPUInterruptProperties(provider
);
89 // register the interrupt handler so it can receive interrupts.
90 handler
= getInterruptHandlerAddress();
91 provider
->registerInterrupt(0, this, handler
, 0);
93 // Just like any interrupt source, you must enable it to receive interrupts.
94 provider
->enableInterrupt(0);
96 // Set interruptControllerName to the proper symbol.
97 //interruptControllerName = xxx;
99 // Register this interrupt controller so clients can find it.
100 getPlatform()->registerInterruptController(interruptControllerName
, this);
102 // All done, so return true.
106 IOReturn
GenericInterruptController::getInterruptType(IOService
*nub
,
110 if (interruptType
== 0) return kIOReturnBadArgument
;
112 // Given the nub and source, set interruptType to level or edge.
114 return kIOReturnSuccess
;
117 // Sadly this just has to be replicated in every interrupt controller.
118 IOInterruptAction
GenericInterruptController::getInterruptHandlerAddress(void)
120 return (IOInterruptAction
)handleInterrupt
;
123 // Handle all current interrupts.
124 IOReturn
GenericInterruptController::handleInterrupt(void * refCon
,
128 IOInterruptVector
*vector
;
132 // Get vectorNumber from hardware some how and clear the event.
134 // Break if there are no more vectors to handle.
135 if (vectorNumber
== 0/*kNoVector*/) break;
137 // Get the vector's date from the controller's array.
138 vector
= &vectors
[vectorNumber
];
140 // Set the vector as active. This store must compleat before
141 // moving on to prevent the disableInterrupt fuction from
142 // geting out of sync.
143 vector
->interruptActive
= 1;
147 // If the vector is not disabled soft, handle it.
148 if (!vector
->interruptDisabledSoft
) {
149 // Prevent speculative exacution as needed on your processor.
152 // Call the handler if it exists.
153 if (vector
->interruptRegistered
) {
154 vector
->handler(vector
->target
, vector
->refCon
,
155 vector
->nub
, vector
->source
);
158 // Hard disable the vector if is was only soft disabled.
159 vector
->interruptDisabledHard
= 1;
160 disableVectorHard(vectorNumber
, vector
);
163 // Done with this vector so, set it back to inactive.
164 vector
->interruptActive
= 0;
167 return kIOReturnSuccess
;
170 bool GenericInterruptController::vectorCanBeShared(long vectorNumber
,
171 IOInterruptVector
*vector
)
173 // Given the vector number and the vector data, return if it can be shared.
177 void GenericInterruptController::initVector(long vectorNumber
,
178 IOInterruptVector
*vector
)
180 // Given the vector number and the vector data,
181 // get the hardware ready for the vector to generate interrupts.
182 // Make sure the vector is left disabled.
185 void GenericInterruptController::disableVectorHard(long vectorNumber
,
186 IOInterruptVector
*vector
)
188 // Given the vector number and the vector data,
189 // disable the vector at the hardware.
192 void GenericInterruptController::enableVector(long vectorNumber
,
193 IOInterruptVector
*vector
)
195 // Given the vector number and the vector data,
196 // enable the vector at the hardware.
199 void GenericInterruptController::causeVector(long vectorNumber
,
200 IOInterruptVector
*vector
)
202 // Given the vector number and the vector data,
203 // Set the vector pending and cause an interrupt at the parent controller.
205 // cause the interrupt at the parent controller. Source is usually zero,
206 // but it could be different for your controller.
207 getPlatform()->causeInterrupt(0);