2 * Copyright (c) 1998-2010 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <IOKit/IOFilterInterruptEventSource.h>
30 #include <IOKit/IOService.h>
31 #include <IOKit/IOKitDebug.h>
32 #include <IOKit/IOTimeStamp.h>
33 #include <IOKit/IOWorkLoop.h>
34 #include <IOKit/IOInterruptAccountingPrivate.h>
35 #include <libkern/Block.h>
39 #define IOStatisticsInitializeCounter() \
41 IOStatistics::setCounterType(IOEventSource::reserved->counter, kIOStatisticsFilterInterruptEventSourceCounter); \
44 #define IOStatisticsInterrupt() \
46 IOStatistics::countInterrupt(IOEventSource::reserved->counter); \
51 #define IOStatisticsInitializeCounter()
52 #define IOStatisticsInterrupt()
54 #endif /* IOKITSTATS */
56 #define super IOInterruptEventSource
58 OSDefineMetaClassAndStructors
59 (IOFilterInterruptEventSource
, IOInterruptEventSource
)
60 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 0);
61 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 1);
62 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 2);
63 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 3);
64 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 4);
65 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 5);
66 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 6);
67 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 7);
70 * Implement the call throughs for the private protection conversion
72 bool IOFilterInterruptEventSource::init(OSObject
*inOwner
,
74 IOService
*inProvider
,
80 IOInterruptEventSource
*
81 IOFilterInterruptEventSource::interruptEventSource(OSObject
*inOwner
,
83 IOService
*inProvider
,
90 IOFilterInterruptEventSource::init(OSObject
*inOwner
,
92 Filter inFilterAction
,
93 IOService
*inProvider
,
96 if ( !super::init(inOwner
, inAction
, inProvider
, inIntIndex
) )
102 filterAction
= inFilterAction
;
104 IOStatisticsInitializeCounter();
109 IOFilterInterruptEventSource
*IOFilterInterruptEventSource
110 ::filterInterruptEventSource(OSObject
*inOwner
,
112 Filter inFilterAction
,
113 IOService
*inProvider
,
116 IOFilterInterruptEventSource
*me
= new IOFilterInterruptEventSource
;
119 && !me
->init(inOwner
, inAction
, inFilterAction
, inProvider
, inIntIndex
)) {
128 IOFilterInterruptEventSource
*IOFilterInterruptEventSource
129 ::filterInterruptEventSource(OSObject
*inOwner
,
130 IOService
*inProvider
,
132 ActionBlock inAction
,
133 FilterBlock inFilterAction
)
135 IOFilterInterruptEventSource
*me
= new IOFilterInterruptEventSource
;
137 FilterBlock filter
= Block_copy(inFilterAction
);
138 if (!filter
) return 0;
141 && !me
->init(inOwner
, (Action
) NULL
, (Filter
) filter
, inProvider
, inIntIndex
)) {
143 Block_release(filter
);
146 me
->flags
|= kFilterBlock
;
147 me
->setActionBlock((IOEventSource::ActionBlock
) inAction
);
153 void IOFilterInterruptEventSource::free( void )
155 if ((kFilterBlock
& flags
) && filterActionBlock
) Block_release(filterActionBlock
);
160 void IOFilterInterruptEventSource::signalInterrupt()
162 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
164 IOStatisticsInterrupt();
168 IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner
));
170 signalWorkAvailable();
173 IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner
));
178 IOFilterInterruptEventSource::Filter
179 IOFilterInterruptEventSource::getFilterAction() const
181 if (kFilterBlock
& flags
) return NULL
;
185 IOFilterInterruptEventSource::FilterBlock
186 IOFilterInterruptEventSource::getFilterActionBlock() const
188 if (kFilterBlock
& flags
) return filterActionBlock
;
192 void IOFilterInterruptEventSource::normalInterruptOccurred
193 (void */
*refcon*/
, IOService */
*prov*/
, int /*source*/)
196 uint64_t startTime
= 0;
197 uint64_t endTime
= 0;
198 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
201 IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER
),
202 VM_KERNEL_UNSLIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
204 if (IOInterruptEventSource::reserved
->statistics
) {
205 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
206 startTime
= mach_absolute_time();
211 if (kFilterBlock
& flags
) filterRes
= (filterActionBlock
)(this);
212 else filterRes
= (*filterAction
)(owner
, this);
214 if (IOInterruptEventSource::reserved
->statistics
) {
215 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex
)) {
216 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelCountIndex
], 1);
219 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
220 endTime
= mach_absolute_time();
221 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelTimeIndex
], endTime
- startTime
);
226 IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER
),
227 VM_KERNEL_ADDRHIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
),
228 VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
234 void IOFilterInterruptEventSource::disableInterruptOccurred
235 (void */
*refcon*/
, IOService
*prov
, int source
)
238 uint64_t startTime
= 0;
239 uint64_t endTime
= 0;
240 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
243 IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER
),
244 VM_KERNEL_UNSLIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
246 if (IOInterruptEventSource::reserved
->statistics
) {
247 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
248 startTime
= mach_absolute_time();
253 if (kFilterBlock
& flags
) filterRes
= (filterActionBlock
)(this);
254 else filterRes
= (*filterAction
)(owner
, this);
256 if (IOInterruptEventSource::reserved
->statistics
) {
257 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex
)) {
258 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelCountIndex
], 1);
261 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
262 endTime
= mach_absolute_time();
263 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelTimeIndex
], endTime
- startTime
);
268 IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER
),
269 VM_KERNEL_UNSLIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
272 prov
->disableInterrupt(source
); /* disable the interrupt */