]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
6d2010ae | 2 | * Copyright (c) 1998-2010 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 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 License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b | 27 | */ |
1c79356b | 28 | |
f427ee49 A |
29 | #define IOKIT_ENABLE_SHARED_PTR |
30 | ||
1c79356b A |
31 | #include <IOKit/IOFilterInterruptEventSource.h> |
32 | #include <IOKit/IOService.h> | |
060df5ea | 33 | #include <IOKit/IOKitDebug.h> |
1c79356b A |
34 | #include <IOKit/IOTimeStamp.h> |
35 | #include <IOKit/IOWorkLoop.h> | |
fe8ab488 | 36 | #include <IOKit/IOInterruptAccountingPrivate.h> |
d9a64523 | 37 | #include <libkern/Block.h> |
1c79356b | 38 | |
6d2010ae A |
39 | #if IOKITSTATS |
40 | ||
41 | #define IOStatisticsInitializeCounter() \ | |
42 | do { \ | |
43 | IOStatistics::setCounterType(IOEventSource::reserved->counter, kIOStatisticsFilterInterruptEventSourceCounter); \ | |
44 | } while (0) | |
45 | ||
46 | #define IOStatisticsInterrupt() \ | |
47 | do { \ | |
48 | IOStatistics::countInterrupt(IOEventSource::reserved->counter); \ | |
49 | } while (0) | |
50 | ||
51 | #else | |
52 | ||
53 | #define IOStatisticsInitializeCounter() | |
54 | #define IOStatisticsInterrupt() | |
55 | ||
56 | #endif /* IOKITSTATS */ | |
57 | ||
1c79356b A |
58 | #define super IOInterruptEventSource |
59 | ||
60 | OSDefineMetaClassAndStructors | |
0a7de745 | 61 | (IOFilterInterruptEventSource, IOInterruptEventSource) |
1c79356b A |
62 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 0); |
63 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 1); | |
64 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 2); | |
65 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 3); | |
66 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 4); | |
67 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 5); | |
68 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 6); | |
69 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 7); | |
70 | ||
71 | /* | |
72 | * Implement the call throughs for the private protection conversion | |
73 | */ | |
0a7de745 A |
74 | bool |
75 | IOFilterInterruptEventSource::init(OSObject *inOwner, | |
76 | Action inAction, | |
77 | IOService *inProvider, | |
78 | int inIntIndex) | |
1c79356b | 79 | { |
0a7de745 | 80 | return false; |
1c79356b A |
81 | } |
82 | ||
f427ee49 | 83 | OSSharedPtr<IOInterruptEventSource> |
1c79356b | 84 | IOFilterInterruptEventSource::interruptEventSource(OSObject *inOwner, |
0a7de745 A |
85 | Action inAction, |
86 | IOService *inProvider, | |
87 | int inIntIndex) | |
1c79356b | 88 | { |
cb323159 | 89 | return NULL; |
1c79356b A |
90 | } |
91 | ||
92 | bool | |
93 | IOFilterInterruptEventSource::init(OSObject *inOwner, | |
0a7de745 A |
94 | Action inAction, |
95 | Filter inFilterAction, | |
96 | IOService *inProvider, | |
97 | int inIntIndex) | |
1c79356b | 98 | { |
0a7de745 A |
99 | if (!super::init(inOwner, inAction, inProvider, inIntIndex)) { |
100 | return false; | |
101 | } | |
102 | ||
103 | if (!inFilterAction) { | |
104 | return false; | |
105 | } | |
1c79356b | 106 | |
0a7de745 | 107 | filterAction = inFilterAction; |
1c79356b | 108 | |
0a7de745 | 109 | IOStatisticsInitializeCounter(); |
6d2010ae | 110 | |
0a7de745 | 111 | return true; |
1c79356b A |
112 | } |
113 | ||
f427ee49 | 114 | OSSharedPtr<IOFilterInterruptEventSource> |
0a7de745 | 115 | IOFilterInterruptEventSource |
1c79356b | 116 | ::filterInterruptEventSource(OSObject *inOwner, |
0a7de745 A |
117 | Action inAction, |
118 | Filter inFilterAction, | |
119 | IOService *inProvider, | |
120 | int inIntIndex) | |
1c79356b | 121 | { |
f427ee49 | 122 | OSSharedPtr<IOFilterInterruptEventSource> me = OSMakeShared<IOFilterInterruptEventSource>(); |
1c79356b | 123 | |
0a7de745 A |
124 | if (me |
125 | && !me->init(inOwner, inAction, inFilterAction, inProvider, inIntIndex)) { | |
f427ee49 | 126 | return nullptr; |
0a7de745 | 127 | } |
1c79356b | 128 | |
0a7de745 | 129 | return me; |
1c79356b A |
130 | } |
131 | ||
d9a64523 | 132 | |
f427ee49 | 133 | OSSharedPtr<IOFilterInterruptEventSource> |
0a7de745 | 134 | IOFilterInterruptEventSource |
d9a64523 | 135 | ::filterInterruptEventSource(OSObject *inOwner, |
0a7de745 A |
136 | IOService *inProvider, |
137 | int inIntIndex, | |
138 | ActionBlock inAction, | |
139 | FilterBlock inFilterAction) | |
d9a64523 | 140 | { |
f427ee49 | 141 | OSSharedPtr<IOFilterInterruptEventSource> me = OSMakeShared<IOFilterInterruptEventSource>(); |
0a7de745 A |
142 | |
143 | FilterBlock filter = Block_copy(inFilterAction); | |
144 | if (!filter) { | |
f427ee49 | 145 | return nullptr; |
0a7de745 A |
146 | } |
147 | ||
148 | if (me | |
149 | && !me->init(inOwner, (Action) NULL, (Filter) filter, inProvider, inIntIndex)) { | |
0a7de745 | 150 | Block_release(filter); |
f427ee49 | 151 | return nullptr; |
0a7de745 A |
152 | } |
153 | me->flags |= kFilterBlock; | |
154 | me->setActionBlock((IOEventSource::ActionBlock) inAction); | |
155 | ||
156 | return me; | |
d9a64523 A |
157 | } |
158 | ||
159 | ||
0a7de745 A |
160 | void |
161 | IOFilterInterruptEventSource::free( void ) | |
d9a64523 | 162 | { |
0a7de745 A |
163 | if ((kFilterBlock & flags) && filterActionBlock) { |
164 | Block_release(filterActionBlock); | |
165 | } | |
d9a64523 | 166 | |
0a7de745 | 167 | super::free(); |
d9a64523 A |
168 | } |
169 | ||
0a7de745 A |
170 | void |
171 | IOFilterInterruptEventSource::signalInterrupt() | |
1c79356b | 172 | { |
060df5ea | 173 | bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; |
0a7de745 A |
174 | |
175 | IOStatisticsInterrupt(); | |
176 | producerCount++; | |
177 | ||
178 | if (trace) { | |
179 | IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner)); | |
180 | } | |
181 | ||
182 | signalWorkAvailable(); | |
183 | ||
184 | if (trace) { | |
185 | IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner)); | |
186 | } | |
1c79356b A |
187 | } |
188 | ||
189 | ||
190 | IOFilterInterruptEventSource::Filter | |
191 | IOFilterInterruptEventSource::getFilterAction() const | |
192 | { | |
0a7de745 A |
193 | if (kFilterBlock & flags) { |
194 | return NULL; | |
195 | } | |
196 | return filterAction; | |
1c79356b A |
197 | } |
198 | ||
d9a64523 A |
199 | IOFilterInterruptEventSource::FilterBlock |
200 | IOFilterInterruptEventSource::getFilterActionBlock() const | |
201 | { | |
0a7de745 A |
202 | if (kFilterBlock & flags) { |
203 | return filterActionBlock; | |
204 | } | |
205 | return NULL; | |
d9a64523 | 206 | } |
1c79356b | 207 | |
0a7de745 A |
208 | void |
209 | IOFilterInterruptEventSource::normalInterruptOccurred | |
210 | (void */*refcon*/, IOService */*prov*/, int /*source*/) | |
1c79356b | 211 | { |
0a7de745 A |
212 | bool filterRes; |
213 | uint64_t startTime = 0; | |
214 | uint64_t endTime = 0; | |
215 | bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; | |
216 | ||
217 | if (trace) { | |
060df5ea | 218 | IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER), |
0a7de745 A |
219 | VM_KERNEL_UNSLIDE(filterAction), VM_KERNEL_ADDRHIDE(owner), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop)); |
220 | } | |
221 | ||
222 | if (IOInterruptEventSource::reserved->statistics) { | |
cb323159 A |
223 | if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex) |
224 | || IOInterruptEventSource::reserved->statistics->enablePrimaryTimestamp) { | |
0a7de745 A |
225 | startTime = mach_absolute_time(); |
226 | } | |
cb323159 A |
227 | if (IOInterruptEventSource::reserved->statistics->enablePrimaryTimestamp) { |
228 | IOInterruptEventSource::reserved->statistics->primaryTimestamp = startTime; | |
229 | } | |
0a7de745 A |
230 | } |
231 | ||
232 | // Call the filter. | |
233 | if (kFilterBlock & flags) { | |
234 | filterRes = (filterActionBlock)(this); | |
235 | } else { | |
236 | filterRes = (*filterAction)(owner, this); | |
237 | } | |
238 | ||
239 | if (IOInterruptEventSource::reserved->statistics) { | |
240 | if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex)) { | |
241 | IA_ADD_VALUE(&IOInterruptEventSource::reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelCountIndex], 1); | |
242 | } | |
243 | ||
244 | if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex)) { | |
245 | endTime = mach_absolute_time(); | |
246 | IA_ADD_VALUE(&IOInterruptEventSource::reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelTimeIndex], endTime - startTime); | |
247 | } | |
248 | } | |
249 | ||
250 | if (trace) { | |
060df5ea | 251 | IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER), |
0a7de745 A |
252 | VM_KERNEL_ADDRHIDE(filterAction), VM_KERNEL_ADDRHIDE(owner), |
253 | VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop)); | |
254 | } | |
255 | ||
256 | if (filterRes) { | |
257 | signalInterrupt(); | |
258 | } | |
1c79356b A |
259 | } |
260 | ||
0a7de745 A |
261 | void |
262 | IOFilterInterruptEventSource::disableInterruptOccurred | |
263 | (void */*refcon*/, IOService *prov, int source) | |
1c79356b | 264 | { |
0a7de745 A |
265 | bool filterRes; |
266 | uint64_t startTime = 0; | |
267 | uint64_t endTime = 0; | |
268 | bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; | |
269 | ||
270 | if (trace) { | |
060df5ea | 271 | IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER), |
0a7de745 A |
272 | VM_KERNEL_UNSLIDE(filterAction), VM_KERNEL_ADDRHIDE(owner), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop)); |
273 | } | |
274 | ||
275 | if (IOInterruptEventSource::reserved->statistics) { | |
cb323159 A |
276 | if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex) |
277 | || IOInterruptEventSource::reserved->statistics->enablePrimaryTimestamp) { | |
0a7de745 A |
278 | startTime = mach_absolute_time(); |
279 | } | |
cb323159 A |
280 | if (IOInterruptEventSource::reserved->statistics->enablePrimaryTimestamp) { |
281 | IOInterruptEventSource::reserved->statistics->primaryTimestamp = startTime; | |
282 | } | |
0a7de745 A |
283 | } |
284 | ||
285 | // Call the filter. | |
286 | if (kFilterBlock & flags) { | |
287 | filterRes = (filterActionBlock)(this); | |
288 | } else { | |
289 | filterRes = (*filterAction)(owner, this); | |
290 | } | |
291 | ||
292 | if (IOInterruptEventSource::reserved->statistics) { | |
293 | if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex)) { | |
294 | IA_ADD_VALUE(&IOInterruptEventSource::reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelCountIndex], 1); | |
295 | } | |
296 | ||
297 | if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex)) { | |
298 | endTime = mach_absolute_time(); | |
299 | IA_ADD_VALUE(&IOInterruptEventSource::reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelTimeIndex], endTime - startTime); | |
300 | } | |
301 | } | |
302 | ||
303 | if (trace) { | |
060df5ea | 304 | IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER), |
0a7de745 A |
305 | VM_KERNEL_UNSLIDE(filterAction), VM_KERNEL_ADDRHIDE(owner), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop)); |
306 | } | |
307 | ||
308 | if (filterRes) { | |
309 | prov->disableInterrupt(source); /* disable the interrupt */ | |
310 | signalInterrupt(); | |
311 | } | |
1c79356b | 312 | } |