]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
1c79356b | 5 | * |
8ad349bb A |
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 | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
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. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
1c79356b A |
29 | */ |
30 | /* | |
31 | Copyright (c) 1998 Apple Computer, Inc. All rights reserved. | |
32 | ||
33 | HISTORY | |
34 | 1998-7-13 Godfrey van der Linden(gvdl) | |
35 | Created. | |
36 | */ | |
37 | #include <IOKit/IOInterruptEventSource.h> | |
38 | #include <IOKit/IOLib.h> | |
39 | #include <IOKit/IOService.h> | |
40 | #include <IOKit/IOInterrupts.h> | |
41 | #include <IOKit/IOTimeStamp.h> | |
42 | #include <IOKit/IOWorkLoop.h> | |
43 | ||
44 | #if KDEBUG | |
45 | ||
46 | #define IOTimeTypeStampS(t) \ | |
47 | do { \ | |
48 | IOTimeStampStart(IODBG_INTES(t), \ | |
49 | (unsigned int) this, (unsigned int) owner); \ | |
50 | } while(0) | |
51 | ||
52 | #define IOTimeTypeStampE(t) \ | |
53 | do { \ | |
54 | IOTimeStampEnd(IODBG_INTES(t), \ | |
55 | (unsigned int) this, (unsigned int) owner); \ | |
56 | } while(0) | |
57 | ||
58 | #define IOTimeStampLatency() \ | |
59 | do { \ | |
60 | IOTimeStampEnd(IODBG_INTES(IOINTES_LAT), \ | |
61 | (unsigned int) this, (unsigned int) owner); \ | |
62 | } while(0) | |
63 | ||
64 | #else /* !KDEBUG */ | |
65 | #define IOTimeTypeStampS(t) | |
66 | #define IOTimeTypeStampE(t) | |
67 | #define IOTimeStampLatency() | |
68 | #endif /* KDEBUG */ | |
69 | ||
70 | #define super IOEventSource | |
71 | ||
72 | OSDefineMetaClassAndStructors(IOInterruptEventSource, IOEventSource) | |
73 | OSMetaClassDefineReservedUnused(IOInterruptEventSource, 0); | |
74 | OSMetaClassDefineReservedUnused(IOInterruptEventSource, 1); | |
75 | OSMetaClassDefineReservedUnused(IOInterruptEventSource, 2); | |
76 | OSMetaClassDefineReservedUnused(IOInterruptEventSource, 3); | |
77 | OSMetaClassDefineReservedUnused(IOInterruptEventSource, 4); | |
78 | OSMetaClassDefineReservedUnused(IOInterruptEventSource, 5); | |
79 | OSMetaClassDefineReservedUnused(IOInterruptEventSource, 6); | |
80 | OSMetaClassDefineReservedUnused(IOInterruptEventSource, 7); | |
81 | ||
82 | bool IOInterruptEventSource::init(OSObject *inOwner, | |
55e303ae A |
83 | Action inAction, |
84 | IOService *inProvider, | |
85 | int inIntIndex) | |
1c79356b A |
86 | { |
87 | bool res = true; | |
88 | ||
89 | if ( !super::init(inOwner, (IOEventSourceAction) inAction) ) | |
90 | return false; | |
91 | ||
92 | provider = inProvider; | |
93 | producerCount = consumerCount = 0; | |
94 | autoDisable = explicitDisable = false; | |
95 | intIndex = -1; | |
96 | ||
97 | // Assumes inOwner holds a reference(retain) on the provider | |
98 | if (inProvider) { | |
99 | int intType; | |
100 | ||
101 | res = (kIOReturnSuccess | |
102 | == inProvider->getInterruptType(inIntIndex, &intType)); | |
103 | if (res) { | |
104 | IOInterruptAction intHandler; | |
105 | ||
106 | autoDisable = (intType == kIOInterruptTypeLevel); | |
107 | if (autoDisable) { | |
91447636 A |
108 | intHandler = OSMemberFunctionCast(IOInterruptAction, |
109 | this, &IOInterruptEventSource::disableInterruptOccurred); | |
1c79356b A |
110 | } |
111 | else | |
91447636 A |
112 | intHandler = OSMemberFunctionCast(IOInterruptAction, |
113 | this, &IOInterruptEventSource::normalInterruptOccurred); | |
1c79356b A |
114 | |
115 | res = (kIOReturnSuccess == inProvider->registerInterrupt | |
116 | (inIntIndex, this, intHandler)); | |
117 | if (res) | |
118 | intIndex = inIntIndex; | |
119 | } | |
120 | } | |
121 | ||
122 | return res; | |
123 | } | |
124 | ||
125 | IOInterruptEventSource * | |
126 | IOInterruptEventSource::interruptEventSource(OSObject *inOwner, | |
127 | Action inAction, | |
128 | IOService *inProvider, | |
129 | int inIntIndex) | |
130 | { | |
131 | IOInterruptEventSource *me = new IOInterruptEventSource; | |
132 | ||
133 | if (me && !me->init(inOwner, inAction, inProvider, inIntIndex)) { | |
55e303ae | 134 | me->release(); |
1c79356b A |
135 | return 0; |
136 | } | |
137 | ||
138 | return me; | |
139 | } | |
140 | ||
141 | void IOInterruptEventSource::free() | |
142 | { | |
143 | if (provider && intIndex != -1) | |
144 | provider->unregisterInterrupt(intIndex); | |
145 | ||
146 | super::free(); | |
147 | } | |
148 | ||
149 | void IOInterruptEventSource::enable() | |
150 | { | |
151 | if (provider && intIndex != -1) { | |
152 | provider->enableInterrupt(intIndex); | |
153 | explicitDisable = false; | |
154 | } | |
155 | } | |
156 | ||
157 | void IOInterruptEventSource::disable() | |
158 | { | |
159 | if (provider && intIndex != -1) { | |
160 | provider->disableInterrupt(intIndex); | |
161 | explicitDisable = true; | |
162 | } | |
163 | } | |
164 | ||
165 | const IOService *IOInterruptEventSource::getProvider() const | |
166 | { | |
167 | return provider; | |
168 | } | |
169 | ||
170 | int IOInterruptEventSource::getIntIndex() const | |
171 | { | |
172 | return intIndex; | |
173 | } | |
174 | ||
175 | bool IOInterruptEventSource::getAutoDisable() const | |
176 | { | |
177 | return autoDisable; | |
178 | } | |
179 | ||
180 | bool IOInterruptEventSource::checkForWork() | |
181 | { | |
182 | unsigned int cacheProdCount = producerCount; | |
183 | int numInts = cacheProdCount - consumerCount; | |
184 | IOInterruptEventAction intAction = (IOInterruptEventAction) action; | |
185 | ||
186 | if (numInts > 0) { | |
187 | ||
188 | IOTimeStampLatency(); | |
189 | IOTimeTypeStampS(IOINTES_CLIENT); | |
190 | IOTimeStampConstant(IODBG_INTES(IOINTES_ACTION), | |
191 | (unsigned int) intAction, (unsigned int) owner); | |
192 | (*intAction)(owner, this, numInts); | |
193 | IOTimeTypeStampE(IOINTES_CLIENT); | |
194 | ||
195 | consumerCount = cacheProdCount; | |
196 | if (autoDisable && !explicitDisable) | |
197 | enable(); | |
198 | } | |
199 | else if (numInts < 0) { | |
200 | IOTimeStampLatency(); | |
201 | IOTimeTypeStampS(IOINTES_CLIENT); | |
202 | IOTimeStampConstant(IODBG_INTES(IOINTES_ACTION), | |
203 | (unsigned int) intAction, (unsigned int) owner); | |
204 | (*intAction)(owner, this, -numInts); | |
205 | IOTimeTypeStampE(IOINTES_CLIENT); | |
206 | ||
207 | consumerCount = cacheProdCount; | |
208 | if (autoDisable && !explicitDisable) | |
209 | enable(); | |
210 | } | |
211 | ||
212 | return false; | |
213 | } | |
214 | ||
215 | void IOInterruptEventSource::normalInterruptOccurred | |
216 | (void */*refcon*/, IOService */*prov*/, int /*source*/) | |
217 | { | |
218 | IOTimeTypeStampS(IOINTES_INTCTXT); | |
219 | IOTimeStampLatency(); | |
220 | ||
221 | producerCount++; | |
222 | ||
223 | IOTimeTypeStampS(IOINTES_SEMA); | |
224 | signalWorkAvailable(); | |
225 | IOTimeTypeStampE(IOINTES_SEMA); | |
226 | ||
227 | IOTimeTypeStampE(IOINTES_INTCTXT); | |
228 | } | |
229 | ||
230 | void IOInterruptEventSource::disableInterruptOccurred | |
231 | (void */*refcon*/, IOService *prov, int source) | |
232 | { | |
233 | IOTimeTypeStampS(IOINTES_INTCTXT); | |
234 | IOTimeStampLatency(); | |
235 | ||
236 | prov->disableInterrupt(source); /* disable the interrupt */ | |
237 | ||
238 | producerCount++; | |
239 | ||
240 | IOTimeTypeStampS(IOINTES_SEMA); | |
241 | signalWorkAvailable(); | |
242 | IOTimeTypeStampE(IOINTES_SEMA); | |
243 | ||
244 | IOTimeTypeStampE(IOINTES_INTCTXT); | |
245 | } | |
246 | ||
247 | void IOInterruptEventSource::interruptOccurred | |
248 | (void *refcon, IOService *prov, int source) | |
249 | { | |
250 | if (autoDisable && prov) | |
251 | disableInterruptOccurred(refcon, prov, source); | |
252 | else | |
253 | normalInterruptOccurred(refcon, prov, source); | |
254 | } |