]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOFilterInterruptEventSource.cpp
xnu-6153.11.26.tar.gz
[apple/xnu.git] / iokit / Kernel / IOFilterInterruptEventSource.cpp
CommitLineData
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
1c79356b
A
29#include <IOKit/IOFilterInterruptEventSource.h>
30#include <IOKit/IOService.h>
060df5ea 31#include <IOKit/IOKitDebug.h>
1c79356b
A
32#include <IOKit/IOTimeStamp.h>
33#include <IOKit/IOWorkLoop.h>
fe8ab488 34#include <IOKit/IOInterruptAccountingPrivate.h>
d9a64523 35#include <libkern/Block.h>
1c79356b 36
6d2010ae
A
37#if IOKITSTATS
38
39#define IOStatisticsInitializeCounter() \
40do { \
41 IOStatistics::setCounterType(IOEventSource::reserved->counter, kIOStatisticsFilterInterruptEventSourceCounter); \
42} while (0)
43
44#define IOStatisticsInterrupt() \
45do { \
46 IOStatistics::countInterrupt(IOEventSource::reserved->counter); \
47} while (0)
48
49#else
50
51#define IOStatisticsInitializeCounter()
52#define IOStatisticsInterrupt()
53
54#endif /* IOKITSTATS */
55
1c79356b
A
56#define super IOInterruptEventSource
57
58OSDefineMetaClassAndStructors
0a7de745 59(IOFilterInterruptEventSource, IOInterruptEventSource)
1c79356b
A
60OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 0);
61OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 1);
62OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 2);
63OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 3);
64OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 4);
65OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 5);
66OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 6);
67OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 7);
68
69/*
70 * Implement the call throughs for the private protection conversion
71 */
0a7de745
A
72bool
73IOFilterInterruptEventSource::init(OSObject *inOwner,
74 Action inAction,
75 IOService *inProvider,
76 int inIntIndex)
1c79356b 77{
0a7de745 78 return false;
1c79356b
A
79}
80
81IOInterruptEventSource *
82IOFilterInterruptEventSource::interruptEventSource(OSObject *inOwner,
0a7de745
A
83 Action inAction,
84 IOService *inProvider,
85 int inIntIndex)
1c79356b 86{
cb323159 87 return NULL;
1c79356b
A
88}
89
90bool
91IOFilterInterruptEventSource::init(OSObject *inOwner,
0a7de745
A
92 Action inAction,
93 Filter inFilterAction,
94 IOService *inProvider,
95 int inIntIndex)
1c79356b 96{
0a7de745
A
97 if (!super::init(inOwner, inAction, inProvider, inIntIndex)) {
98 return false;
99 }
100
101 if (!inFilterAction) {
102 return false;
103 }
1c79356b 104
0a7de745 105 filterAction = inFilterAction;
1c79356b 106
0a7de745 107 IOStatisticsInitializeCounter();
6d2010ae 108
0a7de745 109 return true;
1c79356b
A
110}
111
0a7de745
A
112IOFilterInterruptEventSource *
113IOFilterInterruptEventSource
1c79356b 114::filterInterruptEventSource(OSObject *inOwner,
0a7de745
A
115 Action inAction,
116 Filter inFilterAction,
117 IOService *inProvider,
118 int inIntIndex)
1c79356b 119{
0a7de745 120 IOFilterInterruptEventSource *me = new IOFilterInterruptEventSource;
1c79356b 121
0a7de745
A
122 if (me
123 && !me->init(inOwner, inAction, inFilterAction, inProvider, inIntIndex)) {
124 me->release();
cb323159 125 return NULL;
0a7de745 126 }
1c79356b 127
0a7de745 128 return me;
1c79356b
A
129}
130
d9a64523 131
0a7de745
A
132IOFilterInterruptEventSource *
133IOFilterInterruptEventSource
d9a64523 134::filterInterruptEventSource(OSObject *inOwner,
0a7de745
A
135 IOService *inProvider,
136 int inIntIndex,
137 ActionBlock inAction,
138 FilterBlock inFilterAction)
d9a64523 139{
0a7de745
A
140 IOFilterInterruptEventSource *me = new IOFilterInterruptEventSource;
141
142 FilterBlock filter = Block_copy(inFilterAction);
143 if (!filter) {
cb323159
A
144 OSSafeReleaseNULL(me);
145 return NULL;
0a7de745
A
146 }
147
148 if (me
149 && !me->init(inOwner, (Action) NULL, (Filter) filter, inProvider, inIntIndex)) {
150 me->release();
151 Block_release(filter);
cb323159 152 return NULL;
0a7de745
A
153 }
154 me->flags |= kFilterBlock;
155 me->setActionBlock((IOEventSource::ActionBlock) inAction);
156
157 return me;
d9a64523
A
158}
159
160
0a7de745
A
161void
162IOFilterInterruptEventSource::free( void )
d9a64523 163{
0a7de745
A
164 if ((kFilterBlock & flags) && filterActionBlock) {
165 Block_release(filterActionBlock);
166 }
d9a64523 167
0a7de745 168 super::free();
d9a64523
A
169}
170
0a7de745
A
171void
172IOFilterInterruptEventSource::signalInterrupt()
1c79356b 173{
060df5ea 174 bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false;
0a7de745
A
175
176 IOStatisticsInterrupt();
177 producerCount++;
178
179 if (trace) {
180 IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner));
181 }
182
183 signalWorkAvailable();
184
185 if (trace) {
186 IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner));
187 }
1c79356b
A
188}
189
190
191IOFilterInterruptEventSource::Filter
192IOFilterInterruptEventSource::getFilterAction() const
193{
0a7de745
A
194 if (kFilterBlock & flags) {
195 return NULL;
196 }
197 return filterAction;
1c79356b
A
198}
199
d9a64523
A
200IOFilterInterruptEventSource::FilterBlock
201IOFilterInterruptEventSource::getFilterActionBlock() const
202{
0a7de745
A
203 if (kFilterBlock & flags) {
204 return filterActionBlock;
205 }
206 return NULL;
d9a64523 207}
1c79356b 208
0a7de745
A
209void
210IOFilterInterruptEventSource::normalInterruptOccurred
211(void */*refcon*/, IOService */*prov*/, int /*source*/)
1c79356b 212{
0a7de745
A
213 bool filterRes;
214 uint64_t startTime = 0;
215 uint64_t endTime = 0;
216 bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false;
217
218 if (trace) {
060df5ea 219 IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER),
0a7de745
A
220 VM_KERNEL_UNSLIDE(filterAction), VM_KERNEL_ADDRHIDE(owner), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop));
221 }
222
223 if (IOInterruptEventSource::reserved->statistics) {
cb323159
A
224 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex)
225 || IOInterruptEventSource::reserved->statistics->enablePrimaryTimestamp) {
0a7de745
A
226 startTime = mach_absolute_time();
227 }
cb323159
A
228 if (IOInterruptEventSource::reserved->statistics->enablePrimaryTimestamp) {
229 IOInterruptEventSource::reserved->statistics->primaryTimestamp = startTime;
230 }
0a7de745
A
231 }
232
233 // Call the filter.
234 if (kFilterBlock & flags) {
235 filterRes = (filterActionBlock)(this);
236 } else {
237 filterRes = (*filterAction)(owner, this);
238 }
239
240 if (IOInterruptEventSource::reserved->statistics) {
241 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex)) {
242 IA_ADD_VALUE(&IOInterruptEventSource::reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelCountIndex], 1);
243 }
244
245 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex)) {
246 endTime = mach_absolute_time();
247 IA_ADD_VALUE(&IOInterruptEventSource::reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelTimeIndex], endTime - startTime);
248 }
249 }
250
251 if (trace) {
060df5ea 252 IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER),
0a7de745
A
253 VM_KERNEL_ADDRHIDE(filterAction), VM_KERNEL_ADDRHIDE(owner),
254 VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop));
255 }
256
257 if (filterRes) {
258 signalInterrupt();
259 }
1c79356b
A
260}
261
0a7de745
A
262void
263IOFilterInterruptEventSource::disableInterruptOccurred
264(void */*refcon*/, IOService *prov, int source)
1c79356b 265{
0a7de745
A
266 bool filterRes;
267 uint64_t startTime = 0;
268 uint64_t endTime = 0;
269 bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false;
270
271 if (trace) {
060df5ea 272 IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER),
0a7de745
A
273 VM_KERNEL_UNSLIDE(filterAction), VM_KERNEL_ADDRHIDE(owner), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop));
274 }
275
276 if (IOInterruptEventSource::reserved->statistics) {
cb323159
A
277 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex)
278 || IOInterruptEventSource::reserved->statistics->enablePrimaryTimestamp) {
0a7de745
A
279 startTime = mach_absolute_time();
280 }
cb323159
A
281 if (IOInterruptEventSource::reserved->statistics->enablePrimaryTimestamp) {
282 IOInterruptEventSource::reserved->statistics->primaryTimestamp = startTime;
283 }
0a7de745
A
284 }
285
286 // Call the filter.
287 if (kFilterBlock & flags) {
288 filterRes = (filterActionBlock)(this);
289 } else {
290 filterRes = (*filterAction)(owner, this);
291 }
292
293 if (IOInterruptEventSource::reserved->statistics) {
294 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex)) {
295 IA_ADD_VALUE(&IOInterruptEventSource::reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelCountIndex], 1);
296 }
297
298 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex)) {
299 endTime = mach_absolute_time();
300 IA_ADD_VALUE(&IOInterruptEventSource::reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelTimeIndex], endTime - startTime);
301 }
302 }
303
304 if (trace) {
060df5ea 305 IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER),
0a7de745
A
306 VM_KERNEL_UNSLIDE(filterAction), VM_KERNEL_ADDRHIDE(owner), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop));
307 }
308
309 if (filterRes) {
310 prov->disableInterrupt(source); /* disable the interrupt */
311 signalInterrupt();
312 }
1c79356b 313}