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>
38 #define IOStatisticsInitializeCounter() \
40 IOStatistics::setCounterType(IOEventSource::reserved->counter, kIOStatisticsFilterInterruptEventSourceCounter); \
43 #define IOStatisticsInterrupt() \
45 IOStatistics::countInterrupt(IOEventSource::reserved->counter); \
50 #define IOStatisticsInitializeCounter()
51 #define IOStatisticsInterrupt()
53 #endif /* IOKITSTATS */
55 #define super IOInterruptEventSource
57 OSDefineMetaClassAndStructors
58 (IOFilterInterruptEventSource
, IOInterruptEventSource
)
59 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 0);
60 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 1);
61 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 2);
62 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 3);
63 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 4);
64 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 5);
65 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 6);
66 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource
, 7);
69 * Implement the call throughs for the private protection conversion
71 bool IOFilterInterruptEventSource::init(OSObject
*inOwner
,
73 IOService
*inProvider
,
79 IOInterruptEventSource
*
80 IOFilterInterruptEventSource::interruptEventSource(OSObject
*inOwner
,
82 IOService
*inProvider
,
89 IOFilterInterruptEventSource::init(OSObject
*inOwner
,
91 Filter inFilterAction
,
92 IOService
*inProvider
,
95 if ( !super::init(inOwner
, inAction
, inProvider
, inIntIndex
) )
101 filterAction
= inFilterAction
;
103 IOStatisticsInitializeCounter();
108 IOFilterInterruptEventSource
*IOFilterInterruptEventSource
109 ::filterInterruptEventSource(OSObject
*inOwner
,
111 Filter inFilterAction
,
112 IOService
*inProvider
,
115 IOFilterInterruptEventSource
*me
= new IOFilterInterruptEventSource
;
118 && !me
->init(inOwner
, inAction
, inFilterAction
, inProvider
, inIntIndex
)) {
126 void IOFilterInterruptEventSource::signalInterrupt()
128 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
130 IOStatisticsInterrupt();
134 IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner
));
136 signalWorkAvailable();
139 IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner
));
144 IOFilterInterruptEventSource::Filter
145 IOFilterInterruptEventSource::getFilterAction() const
153 void IOFilterInterruptEventSource::normalInterruptOccurred
154 (void */
*refcon*/
, IOService */
*prov*/
, int /*source*/)
157 uint64_t startTime
= 0;
158 uint64_t endTime
= 0;
159 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
162 IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER
),
163 VM_KERNEL_UNSLIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
165 if (IOInterruptEventSource::reserved
->statistics
) {
166 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
167 startTime
= mach_absolute_time();
172 filterRes
= (*filterAction
)(owner
, this);
174 if (IOInterruptEventSource::reserved
->statistics
) {
175 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex
)) {
176 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelCountIndex
], 1);
179 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
180 endTime
= mach_absolute_time();
181 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelTimeIndex
], endTime
- startTime
);
186 IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER
),
187 VM_KERNEL_ADDRHIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
),
188 VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
194 void IOFilterInterruptEventSource::disableInterruptOccurred
195 (void */
*refcon*/
, IOService
*prov
, int source
)
198 uint64_t startTime
= 0;
199 uint64_t endTime
= 0;
200 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
203 IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER
),
204 VM_KERNEL_UNSLIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
206 if (IOInterruptEventSource::reserved
->statistics
) {
207 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
208 startTime
= mach_absolute_time();
213 filterRes
= (*filterAction
)(owner
, this);
215 if (IOInterruptEventSource::reserved
->statistics
) {
216 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex
)) {
217 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelCountIndex
], 1);
220 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
221 endTime
= mach_absolute_time();
222 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelTimeIndex
], endTime
- startTime
);
227 IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER
),
228 VM_KERNEL_UNSLIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
231 prov
->disableInterrupt(source
); /* disable the interrupt */