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 #define IOKIT_ENABLE_SHARED_PTR
31 #include <IOKit/IOFilterInterruptEventSource.h>
32 #include <IOKit/IOService.h>
33 #include <IOKit/IOKitDebug.h>
34 #include <IOKit/IOTimeStamp.h>
35 #include <IOKit/IOWorkLoop.h>
36 #include <IOKit/IOInterruptAccountingPrivate.h>
37 #include <libkern/Block.h>
41 #define IOStatisticsInitializeCounter() \
43 IOStatistics::setCounterType(IOEventSource::reserved->counter, kIOStatisticsFilterInterruptEventSourceCounter); \
46 #define IOStatisticsInterrupt() \
48 IOStatistics::countInterrupt(IOEventSource::reserved->counter); \
53 #define IOStatisticsInitializeCounter()
54 #define IOStatisticsInterrupt()
56 #endif /* IOKITSTATS */
58 #define super IOInterruptEventSource
60 OSDefineMetaClassAndStructors
61 (IOFilterInterruptEventSource
, IOInterruptEventSource
)
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);
72 * Implement the call throughs for the private protection conversion
75 IOFilterInterruptEventSource::init(OSObject
*inOwner
,
77 IOService
*inProvider
,
83 OSSharedPtr
<IOInterruptEventSource
>
84 IOFilterInterruptEventSource::interruptEventSource(OSObject
*inOwner
,
86 IOService
*inProvider
,
93 IOFilterInterruptEventSource::init(OSObject
*inOwner
,
95 Filter inFilterAction
,
96 IOService
*inProvider
,
99 if (!super::init(inOwner
, inAction
, inProvider
, inIntIndex
)) {
103 if (!inFilterAction
) {
107 filterAction
= inFilterAction
;
109 IOStatisticsInitializeCounter();
114 OSSharedPtr
<IOFilterInterruptEventSource
>
115 IOFilterInterruptEventSource
116 ::filterInterruptEventSource(OSObject
*inOwner
,
118 Filter inFilterAction
,
119 IOService
*inProvider
,
122 OSSharedPtr
<IOFilterInterruptEventSource
> me
= OSMakeShared
<IOFilterInterruptEventSource
>();
125 && !me
->init(inOwner
, inAction
, inFilterAction
, inProvider
, inIntIndex
)) {
133 OSSharedPtr
<IOFilterInterruptEventSource
>
134 IOFilterInterruptEventSource
135 ::filterInterruptEventSource(OSObject
*inOwner
,
136 IOService
*inProvider
,
138 ActionBlock inAction
,
139 FilterBlock inFilterAction
)
141 OSSharedPtr
<IOFilterInterruptEventSource
> me
= OSMakeShared
<IOFilterInterruptEventSource
>();
143 FilterBlock filter
= Block_copy(inFilterAction
);
149 && !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 || IOInterruptEventSource::reserved
->statistics
->enablePrimaryTimestamp
) {
225 startTime
= mach_absolute_time();
227 if (IOInterruptEventSource::reserved
->statistics
->enablePrimaryTimestamp
) {
228 IOInterruptEventSource::reserved
->statistics
->primaryTimestamp
= startTime
;
233 if (kFilterBlock
& flags
) {
234 filterRes
= (filterActionBlock
)(this);
236 filterRes
= (*filterAction
)(owner
, this);
239 if (IOInterruptEventSource::reserved
->statistics
) {
240 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex
)) {
241 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelCountIndex
], 1);
244 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
245 endTime
= mach_absolute_time();
246 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelTimeIndex
], endTime
- startTime
);
251 IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER
),
252 VM_KERNEL_ADDRHIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
),
253 VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
262 IOFilterInterruptEventSource::disableInterruptOccurred
263 (void */
*refcon*/
, IOService
*prov
, int source
)
266 uint64_t startTime
= 0;
267 uint64_t endTime
= 0;
268 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
271 IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER
),
272 VM_KERNEL_UNSLIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
275 if (IOInterruptEventSource::reserved
->statistics
) {
276 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)
277 || IOInterruptEventSource::reserved
->statistics
->enablePrimaryTimestamp
) {
278 startTime
= mach_absolute_time();
280 if (IOInterruptEventSource::reserved
->statistics
->enablePrimaryTimestamp
) {
281 IOInterruptEventSource::reserved
->statistics
->primaryTimestamp
= startTime
;
286 if (kFilterBlock
& flags
) {
287 filterRes
= (filterActionBlock
)(this);
289 filterRes
= (*filterAction
)(owner
, this);
292 if (IOInterruptEventSource::reserved
->statistics
) {
293 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex
)) {
294 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelCountIndex
], 1);
297 if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex
)) {
298 endTime
= mach_absolute_time();
299 IA_ADD_VALUE(&IOInterruptEventSource::reserved
->statistics
->interruptStatistics
[kInterruptAccountingFirstLevelTimeIndex
], endTime
- startTime
);
304 IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER
),
305 VM_KERNEL_UNSLIDE(filterAction
), VM_KERNEL_ADDRHIDE(owner
), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop
));
309 prov
->disableInterrupt(source
); /* disable the interrupt */