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