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
73 IOFilterInterruptEventSource::init(OSObject
*inOwner
,
75 IOService
*inProvider
,
81 IOInterruptEventSource
*
82 IOFilterInterruptEventSource::interruptEventSource(OSObject
*inOwner
,
84 IOService
*inProvider
,
91 IOFilterInterruptEventSource::init(OSObject
*inOwner
,
93 Filter inFilterAction
,
94 IOService
*inProvider
,
97 if (!super::init(inOwner
, inAction
, inProvider
, inIntIndex
)) {
101 if (!inFilterAction
) {
105 filterAction
= inFilterAction
;
107 IOStatisticsInitializeCounter();
112 IOFilterInterruptEventSource
*
113 IOFilterInterruptEventSource
114 ::filterInterruptEventSource(OSObject
*inOwner
,
116 Filter inFilterAction
,
117 IOService
*inProvider
,
120 IOFilterInterruptEventSource
*me
= new IOFilterInterruptEventSource
;
123 && !me
->init(inOwner
, inAction
, inFilterAction
, inProvider
, inIntIndex
)) {
132 IOFilterInterruptEventSource
*
133 IOFilterInterruptEventSource
134 ::filterInterruptEventSource(OSObject
*inOwner
,
135 IOService
*inProvider
,
137 ActionBlock inAction
,
138 FilterBlock inFilterAction
)
140 IOFilterInterruptEventSource
*me
= new IOFilterInterruptEventSource
;
142 FilterBlock filter
= Block_copy(inFilterAction
);
148 && !me
->init(inOwner
, (Action
) NULL
, (Filter
) filter
, inProvider
, inIntIndex
)) {
150 Block_release(filter
);
153 me
->flags
|= kFilterBlock
;
154 me
->setActionBlock((IOEventSource::ActionBlock
) inAction
);
161 IOFilterInterruptEventSource::free( void )
163 if ((kFilterBlock
& flags
) && filterActionBlock
) {
164 Block_release(filterActionBlock
);
171 IOFilterInterruptEventSource::signalInterrupt()
173 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
175 IOStatisticsInterrupt();
179 IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner
));
182 signalWorkAvailable();
185 IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner
));
190 IOFilterInterruptEventSource::Filter
191 IOFilterInterruptEventSource::getFilterAction() const
193 if (kFilterBlock
& flags
) {
199 IOFilterInterruptEventSource::FilterBlock
200 IOFilterInterruptEventSource::getFilterActionBlock() const
202 if (kFilterBlock
& flags
) {
203 return filterActionBlock
;
209 IOFilterInterruptEventSource::normalInterruptOccurred
210 (void */
*refcon*/
, IOService */
*prov*/
, int /*source*/)
213 uint64_t startTime
= 0;
214 uint64_t endTime
= 0;
215 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
218 IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER
),
219 VM_KERNEL_UNSLIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
222 if (IOInterruptEventSource::reserved
->statistics
) {
223 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
224 startTime
= mach_absolute_time();
229 if (kFilterBlock
& flags
) {
230 filterRes
= (filterActionBlock
)(this);
232 filterRes
= (*filterAction
)(owner
, this);
235 if (IOInterruptEventSource::reserved
->statistics
) {
236 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex
)) {
237 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelCountIndex
], 1);
240 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
241 endTime
= mach_absolute_time();
242 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelTimeIndex
], endTime
- startTime
);
247 IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER
),
248 VM_KERNEL_ADDRHIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
),
249 VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
258 IOFilterInterruptEventSource::disableInterruptOccurred
259 (void */
*refcon*/
, IOService
*prov
, int source
)
262 uint64_t startTime
= 0;
263 uint64_t endTime
= 0;
264 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
267 IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER
),
268 VM_KERNEL_UNSLIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
271 if (IOInterruptEventSource::reserved
->statistics
) {
272 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
273 startTime
= mach_absolute_time();
278 if (kFilterBlock
& flags
) {
279 filterRes
= (filterActionBlock
)(this);
281 filterRes
= (*filterAction
)(owner
, this);
284 if (IOInterruptEventSource::reserved
->statistics
) {
285 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex
)) {
286 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelCountIndex
], 1);
289 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
290 endTime
= mach_absolute_time();
291 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelTimeIndex
], endTime
- startTime
);
296 IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER
),
297 VM_KERNEL_UNSLIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
301 prov
->disableInterrupt(source
); /* disable the interrupt */