1*27b03b36SApple OSS Distributions /*
2*27b03b36SApple OSS Distributions * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3*27b03b36SApple OSS Distributions *
4*27b03b36SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*27b03b36SApple OSS Distributions *
6*27b03b36SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*27b03b36SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*27b03b36SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*27b03b36SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*27b03b36SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*27b03b36SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*27b03b36SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*27b03b36SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*27b03b36SApple OSS Distributions *
15*27b03b36SApple OSS Distributions * Please obtain a copy of the License at
16*27b03b36SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*27b03b36SApple OSS Distributions *
18*27b03b36SApple OSS Distributions * The Original Code and all software distributed under the License are
19*27b03b36SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*27b03b36SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*27b03b36SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*27b03b36SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*27b03b36SApple OSS Distributions * Please see the License for the specific language governing rights and
24*27b03b36SApple OSS Distributions * limitations under the License.
25*27b03b36SApple OSS Distributions *
26*27b03b36SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*27b03b36SApple OSS Distributions */
28*27b03b36SApple OSS Distributions /*
29*27b03b36SApple OSS Distributions * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
30*27b03b36SApple OSS Distributions *
31*27b03b36SApple OSS Distributions * DRI: Josh de Cesare
32*27b03b36SApple OSS Distributions */
33*27b03b36SApple OSS Distributions
34*27b03b36SApple OSS Distributions #include <IOKit/IOPlatformExpert.h>
35*27b03b36SApple OSS Distributions
36*27b03b36SApple OSS Distributions #include "GenericInterruptController.h"
37*27b03b36SApple OSS Distributions
38*27b03b36SApple OSS Distributions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
39*27b03b36SApple OSS Distributions
40*27b03b36SApple OSS Distributions #undef super
41*27b03b36SApple OSS Distributions #define super IOInterruptController
42*27b03b36SApple OSS Distributions
43*27b03b36SApple OSS Distributions IODefineMetaClassAndStructors(GenericInterruptController,
44*27b03b36SApple OSS Distributions IOInterruptController);
45*27b03b36SApple OSS Distributions
46*27b03b36SApple OSS Distributions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
47*27b03b36SApple OSS Distributions
48*27b03b36SApple OSS Distributions
49*27b03b36SApple OSS Distributions bool
start(IOService * provider)50*27b03b36SApple OSS Distributions GenericInterruptController::start(IOService *provider)
51*27b03b36SApple OSS Distributions {
52*27b03b36SApple OSS Distributions IOInterruptAction handler;
53*27b03b36SApple OSS Distributions IOSymbol *interruptControllerName;
54*27b03b36SApple OSS Distributions
55*27b03b36SApple OSS Distributions // If needed call the parents start.
56*27b03b36SApple OSS Distributions if (!super::start(provider)) {
57*27b03b36SApple OSS Distributions return false;
58*27b03b36SApple OSS Distributions }
59*27b03b36SApple OSS Distributions
60*27b03b36SApple OSS Distributions // Map the device's memory and initalize its state.
61*27b03b36SApple OSS Distributions
62*27b03b36SApple OSS Distributions // For now you must allocate storage for the vectors.
63*27b03b36SApple OSS Distributions // This will probably changed to something like: initVectors(numVectors).
64*27b03b36SApple OSS Distributions // In the mean time something like this works well.
65*27b03b36SApple OSS Distributions #if 0
66*27b03b36SApple OSS Distributions // Allocate the memory for the vectors.
67*27b03b36SApple OSS Distributions vectors = (IOInterruptVector *)IOMalloc(numVectors *
68*27b03b36SApple OSS Distributions sizeof(IOInterruptVector));
69*27b03b36SApple OSS Distributions if (vectors == NULL) {
70*27b03b36SApple OSS Distributions return false;
71*27b03b36SApple OSS Distributions }
72*27b03b36SApple OSS Distributions bzero(vectors, numVectors * sizeof(IOInterruptVector));
73*27b03b36SApple OSS Distributions
74*27b03b36SApple OSS Distributions // Allocate locks for the vectors.
75*27b03b36SApple OSS Distributions for (cnt = 0; cnt < numVectors; cnt++) {
76*27b03b36SApple OSS Distributions vectors[cnt].interruptLock = IOLockAlloc();
77*27b03b36SApple OSS Distributions if (vectors[cnt].interruptLock == NULL) {
78*27b03b36SApple OSS Distributions for (cnt = 0; cnt < numVectors; cnt++) {
79*27b03b36SApple OSS Distributions if (vectors[cnt].interruptLock != NULL) {
80*27b03b36SApple OSS Distributions IOLockFree(vectors[cnt].interruptLock);
81*27b03b36SApple OSS Distributions }
82*27b03b36SApple OSS Distributions }
83*27b03b36SApple OSS Distributions }
84*27b03b36SApple OSS Distributions }
85*27b03b36SApple OSS Distributions #endif
86*27b03b36SApple OSS Distributions
87*27b03b36SApple OSS Distributions // If you know that this interrupt controller is the primary
88*27b03b36SApple OSS Distributions // interrupt controller, use this to set it nub properties properly.
89*27b03b36SApple OSS Distributions // This may be done by the nub's creator.
90*27b03b36SApple OSS Distributions getPlatform()->setCPUInterruptProperties(provider);
91*27b03b36SApple OSS Distributions
92*27b03b36SApple OSS Distributions // register the interrupt handler so it can receive interrupts.
93*27b03b36SApple OSS Distributions handler = getInterruptHandlerAddress();
94*27b03b36SApple OSS Distributions provider->registerInterrupt(0, this, handler, 0);
95*27b03b36SApple OSS Distributions
96*27b03b36SApple OSS Distributions // Just like any interrupt source, you must enable it to receive interrupts.
97*27b03b36SApple OSS Distributions provider->enableInterrupt(0);
98*27b03b36SApple OSS Distributions
99*27b03b36SApple OSS Distributions // Set interruptControllerName to the proper symbol.
100*27b03b36SApple OSS Distributions //interruptControllerName = xxx;
101*27b03b36SApple OSS Distributions
102*27b03b36SApple OSS Distributions // Register this interrupt controller so clients can find it.
103*27b03b36SApple OSS Distributions getPlatform()->registerInterruptController(interruptControllerName, this);
104*27b03b36SApple OSS Distributions
105*27b03b36SApple OSS Distributions // All done, so return true.
106*27b03b36SApple OSS Distributions return true;
107*27b03b36SApple OSS Distributions }
108*27b03b36SApple OSS Distributions
109*27b03b36SApple OSS Distributions IOReturn
getInterruptType(IOService * nub,int source,int * interruptType)110*27b03b36SApple OSS Distributions GenericInterruptController::getInterruptType(IOService *nub,
111*27b03b36SApple OSS Distributions int source,
112*27b03b36SApple OSS Distributions int *interruptType)
113*27b03b36SApple OSS Distributions {
114*27b03b36SApple OSS Distributions if (interruptType == 0) {
115*27b03b36SApple OSS Distributions return kIOReturnBadArgument;
116*27b03b36SApple OSS Distributions }
117*27b03b36SApple OSS Distributions
118*27b03b36SApple OSS Distributions // Given the nub and source, set interruptType to level or edge.
119*27b03b36SApple OSS Distributions
120*27b03b36SApple OSS Distributions return kIOReturnSuccess;
121*27b03b36SApple OSS Distributions }
122*27b03b36SApple OSS Distributions
123*27b03b36SApple OSS Distributions // Sadly this just has to be replicated in every interrupt controller.
124*27b03b36SApple OSS Distributions IOInterruptAction
getInterruptHandlerAddress(void)125*27b03b36SApple OSS Distributions GenericInterruptController::getInterruptHandlerAddress(void)
126*27b03b36SApple OSS Distributions {
127*27b03b36SApple OSS Distributions return (IOInterruptAction)handleInterrupt;
128*27b03b36SApple OSS Distributions }
129*27b03b36SApple OSS Distributions
130*27b03b36SApple OSS Distributions // Handle all current interrupts.
131*27b03b36SApple OSS Distributions IOReturn
handleInterrupt(void * refCon,IOService * nub,int source)132*27b03b36SApple OSS Distributions GenericInterruptController::handleInterrupt(void * refCon,
133*27b03b36SApple OSS Distributions IOService * nub,
134*27b03b36SApple OSS Distributions int source)
135*27b03b36SApple OSS Distributions {
136*27b03b36SApple OSS Distributions IOInterruptVector *vector;
137*27b03b36SApple OSS Distributions int vectorNumber;
138*27b03b36SApple OSS Distributions
139*27b03b36SApple OSS Distributions while (1) {
140*27b03b36SApple OSS Distributions // Get vectorNumber from hardware some how and clear the event.
141*27b03b36SApple OSS Distributions
142*27b03b36SApple OSS Distributions // Break if there are no more vectors to handle.
143*27b03b36SApple OSS Distributions if (vectorNumber == 0 /*kNoVector*/) {
144*27b03b36SApple OSS Distributions break;
145*27b03b36SApple OSS Distributions }
146*27b03b36SApple OSS Distributions
147*27b03b36SApple OSS Distributions // Get the vector's date from the controller's array.
148*27b03b36SApple OSS Distributions vector = &vectors[vectorNumber];
149*27b03b36SApple OSS Distributions
150*27b03b36SApple OSS Distributions // Set the vector as active. This store must compleat before
151*27b03b36SApple OSS Distributions // moving on to prevent the disableInterrupt fuction from
152*27b03b36SApple OSS Distributions // geting out of sync.
153*27b03b36SApple OSS Distributions vector->interruptActive = 1;
154*27b03b36SApple OSS Distributions //sync();
155*27b03b36SApple OSS Distributions //isync();
156*27b03b36SApple OSS Distributions
157*27b03b36SApple OSS Distributions // If the vector is not disabled soft, handle it.
158*27b03b36SApple OSS Distributions if (!vector->interruptDisabledSoft) {
159*27b03b36SApple OSS Distributions // Prevent speculative exacution as needed on your processor.
160*27b03b36SApple OSS Distributions //isync();
161*27b03b36SApple OSS Distributions
162*27b03b36SApple OSS Distributions // Call the handler if it exists.
163*27b03b36SApple OSS Distributions if (vector->interruptRegistered) {
164*27b03b36SApple OSS Distributions vector->handler(vector->target, vector->refCon,
165*27b03b36SApple OSS Distributions vector->nub, vector->source);
166*27b03b36SApple OSS Distributions }
167*27b03b36SApple OSS Distributions } else {
168*27b03b36SApple OSS Distributions // Hard disable the vector if is was only soft disabled.
169*27b03b36SApple OSS Distributions vector->interruptDisabledHard = 1;
170*27b03b36SApple OSS Distributions disableVectorHard(vectorNumber, vector);
171*27b03b36SApple OSS Distributions }
172*27b03b36SApple OSS Distributions
173*27b03b36SApple OSS Distributions // Done with this vector so, set it back to inactive.
174*27b03b36SApple OSS Distributions vector->interruptActive = 0;
175*27b03b36SApple OSS Distributions }
176*27b03b36SApple OSS Distributions
177*27b03b36SApple OSS Distributions return kIOReturnSuccess;
178*27b03b36SApple OSS Distributions }
179*27b03b36SApple OSS Distributions
180*27b03b36SApple OSS Distributions bool
vectorCanBeShared(long vectorNumber,IOInterruptVector * vector)181*27b03b36SApple OSS Distributions GenericInterruptController::vectorCanBeShared(long vectorNumber,
182*27b03b36SApple OSS Distributions IOInterruptVector *vector)
183*27b03b36SApple OSS Distributions {
184*27b03b36SApple OSS Distributions // Given the vector number and the vector data, return if it can be shared.
185*27b03b36SApple OSS Distributions return true;
186*27b03b36SApple OSS Distributions }
187*27b03b36SApple OSS Distributions
188*27b03b36SApple OSS Distributions void
initVector(long vectorNumber,IOInterruptVector * vector)189*27b03b36SApple OSS Distributions GenericInterruptController::initVector(long vectorNumber,
190*27b03b36SApple OSS Distributions IOInterruptVector *vector)
191*27b03b36SApple OSS Distributions {
192*27b03b36SApple OSS Distributions // Given the vector number and the vector data,
193*27b03b36SApple OSS Distributions // get the hardware ready for the vector to generate interrupts.
194*27b03b36SApple OSS Distributions // Make sure the vector is left disabled.
195*27b03b36SApple OSS Distributions }
196*27b03b36SApple OSS Distributions
197*27b03b36SApple OSS Distributions void
disableVectorHard(long vectorNumber,IOInterruptVector * vector)198*27b03b36SApple OSS Distributions GenericInterruptController::disableVectorHard(long vectorNumber,
199*27b03b36SApple OSS Distributions IOInterruptVector *vector)
200*27b03b36SApple OSS Distributions {
201*27b03b36SApple OSS Distributions // Given the vector number and the vector data,
202*27b03b36SApple OSS Distributions // disable the vector at the hardware.
203*27b03b36SApple OSS Distributions }
204*27b03b36SApple OSS Distributions
205*27b03b36SApple OSS Distributions void
enableVector(long vectorNumber,IOInterruptVector * vector)206*27b03b36SApple OSS Distributions GenericInterruptController::enableVector(long vectorNumber,
207*27b03b36SApple OSS Distributions IOInterruptVector *vector)
208*27b03b36SApple OSS Distributions {
209*27b03b36SApple OSS Distributions // Given the vector number and the vector data,
210*27b03b36SApple OSS Distributions // enable the vector at the hardware.
211*27b03b36SApple OSS Distributions }
212*27b03b36SApple OSS Distributions
213*27b03b36SApple OSS Distributions void
causeVector(long vectorNumber,IOInterruptVector * vector)214*27b03b36SApple OSS Distributions GenericInterruptController::causeVector(long vectorNumber,
215*27b03b36SApple OSS Distributions IOInterruptVector *vector)
216*27b03b36SApple OSS Distributions {
217*27b03b36SApple OSS Distributions // Given the vector number and the vector data,
218*27b03b36SApple OSS Distributions // Set the vector pending and cause an interrupt at the parent controller.
219*27b03b36SApple OSS Distributions
220*27b03b36SApple OSS Distributions // cause the interrupt at the parent controller. Source is usually zero,
221*27b03b36SApple OSS Distributions // but it could be different for your controller.
222*27b03b36SApple OSS Distributions getPlatform()->causeInterrupt(0);
223*27b03b36SApple OSS Distributions }
224