]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
6d2010ae | 2 | * Copyright (c) 1998-2010 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 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. | |
8f6c56a5 | 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. | |
17 | * | |
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. | |
8f6c56a5 | 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> |
1c79356b | 35 | |
6d2010ae A |
36 | #if IOKITSTATS |
37 | ||
38 | #define IOStatisticsInitializeCounter() \ | |
39 | do { \ | |
40 | IOStatistics::setCounterType(IOEventSource::reserved->counter, kIOStatisticsFilterInterruptEventSourceCounter); \ | |
41 | } while (0) | |
42 | ||
43 | #define IOStatisticsInterrupt() \ | |
44 | do { \ | |
45 | IOStatistics::countInterrupt(IOEventSource::reserved->counter); \ | |
46 | } while (0) | |
47 | ||
48 | #else | |
49 | ||
50 | #define IOStatisticsInitializeCounter() | |
51 | #define IOStatisticsInterrupt() | |
52 | ||
53 | #endif /* IOKITSTATS */ | |
54 | ||
1c79356b A |
55 | #define super IOInterruptEventSource |
56 | ||
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); | |
67 | ||
68 | /* | |
69 | * Implement the call throughs for the private protection conversion | |
70 | */ | |
71 | bool IOFilterInterruptEventSource::init(OSObject *inOwner, | |
55e303ae A |
72 | Action inAction, |
73 | IOService *inProvider, | |
74 | int inIntIndex) | |
1c79356b A |
75 | { |
76 | return false; | |
77 | } | |
78 | ||
79 | IOInterruptEventSource * | |
80 | IOFilterInterruptEventSource::interruptEventSource(OSObject *inOwner, | |
81 | Action inAction, | |
82 | IOService *inProvider, | |
83 | int inIntIndex) | |
84 | { | |
85 | return 0; | |
86 | } | |
87 | ||
88 | bool | |
89 | IOFilterInterruptEventSource::init(OSObject *inOwner, | |
90 | Action inAction, | |
91 | Filter inFilterAction, | |
92 | IOService *inProvider, | |
55e303ae | 93 | int inIntIndex) |
1c79356b A |
94 | { |
95 | if ( !super::init(inOwner, inAction, inProvider, inIntIndex) ) | |
96 | return false; | |
97 | ||
98 | if (!inFilterAction) | |
99 | return false; | |
100 | ||
101 | filterAction = inFilterAction; | |
6d2010ae A |
102 | |
103 | IOStatisticsInitializeCounter(); | |
104 | ||
1c79356b A |
105 | return true; |
106 | } | |
107 | ||
108 | IOFilterInterruptEventSource *IOFilterInterruptEventSource | |
109 | ::filterInterruptEventSource(OSObject *inOwner, | |
110 | Action inAction, | |
111 | Filter inFilterAction, | |
112 | IOService *inProvider, | |
55e303ae | 113 | int inIntIndex) |
1c79356b A |
114 | { |
115 | IOFilterInterruptEventSource *me = new IOFilterInterruptEventSource; | |
116 | ||
117 | if (me | |
118 | && !me->init(inOwner, inAction, inFilterAction, inProvider, inIntIndex)) { | |
55e303ae | 119 | me->release(); |
1c79356b A |
120 | return 0; |
121 | } | |
122 | ||
123 | return me; | |
124 | } | |
125 | ||
126 | void IOFilterInterruptEventSource::signalInterrupt() | |
127 | { | |
060df5ea | 128 | bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; |
6d2010ae A |
129 | |
130 | IOStatisticsInterrupt(); | |
1c79356b | 131 | producerCount++; |
6d2010ae | 132 | |
060df5ea A |
133 | if (trace) |
134 | IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner); | |
135 | ||
1c79356b | 136 | signalWorkAvailable(); |
060df5ea A |
137 | |
138 | if (trace) | |
139 | IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner); | |
140 | ||
1c79356b A |
141 | } |
142 | ||
143 | ||
144 | IOFilterInterruptEventSource::Filter | |
145 | IOFilterInterruptEventSource::getFilterAction() const | |
146 | { | |
147 | return filterAction; | |
148 | } | |
149 | ||
150 | ||
151 | ||
152 | ||
153 | void IOFilterInterruptEventSource::normalInterruptOccurred | |
154 | (void */*refcon*/, IOService */*prov*/, int /*source*/) | |
155 | { | |
6d2010ae | 156 | bool filterRes; |
fe8ab488 A |
157 | uint64_t startTime = 0; |
158 | uint64_t endTime = 0; | |
060df5ea | 159 | bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; |
6d2010ae | 160 | |
060df5ea A |
161 | if (trace) |
162 | IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER), | |
316670eb | 163 | VM_KERNEL_UNSLIDE(filterAction), (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop); |
fe8ab488 A |
164 | |
165 | if (IOInterruptEventSource::reserved->statistics) { | |
166 | if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex)) { | |
167 | startTime = mach_absolute_time(); | |
168 | } | |
169 | } | |
6d2010ae | 170 | |
060df5ea | 171 | // Call the filter. |
1c79356b | 172 | filterRes = (*filterAction)(owner, this); |
fe8ab488 A |
173 | |
174 | if (IOInterruptEventSource::reserved->statistics) { | |
175 | if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex)) { | |
176 | IA_ADD_VALUE(&IOInterruptEventSource::reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelCountIndex], 1); | |
177 | } | |
178 | ||
179 | if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex)) { | |
180 | endTime = mach_absolute_time(); | |
181 | IA_ADD_VALUE(&IOInterruptEventSource::reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelTimeIndex], endTime - startTime); | |
182 | } | |
183 | } | |
060df5ea A |
184 | |
185 | if (trace) | |
186 | IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER), | |
316670eb | 187 | VM_KERNEL_UNSLIDE(filterAction), (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop); |
6d2010ae | 188 | |
1c79356b A |
189 | if (filterRes) |
190 | signalInterrupt(); | |
1c79356b A |
191 | } |
192 | ||
193 | void IOFilterInterruptEventSource::disableInterruptOccurred | |
194 | (void */*refcon*/, IOService *prov, int source) | |
195 | { | |
6d2010ae | 196 | bool filterRes; |
fe8ab488 A |
197 | uint64_t startTime = 0; |
198 | uint64_t endTime = 0; | |
060df5ea | 199 | bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; |
6d2010ae | 200 | |
060df5ea A |
201 | if (trace) |
202 | IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER), | |
316670eb | 203 | VM_KERNEL_UNSLIDE(filterAction), (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop); |
fe8ab488 A |
204 | |
205 | if (IOInterruptEventSource::reserved->statistics) { | |
206 | if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex)) { | |
207 | startTime = mach_absolute_time(); | |
208 | } | |
209 | } | |
6d2010ae | 210 | |
060df5ea | 211 | // Call the filter. |
1c79356b | 212 | filterRes = (*filterAction)(owner, this); |
fe8ab488 A |
213 | |
214 | if (IOInterruptEventSource::reserved->statistics) { | |
215 | if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex)) { | |
216 | IA_ADD_VALUE(&IOInterruptEventSource::reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelCountIndex], 1); | |
217 | } | |
218 | ||
219 | if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelTimeIndex)) { | |
220 | endTime = mach_absolute_time(); | |
221 | IA_ADD_VALUE(&IOInterruptEventSource::reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelTimeIndex], endTime - startTime); | |
222 | } | |
223 | } | |
224 | ||
060df5ea A |
225 | if (trace) |
226 | IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER), | |
316670eb | 227 | VM_KERNEL_UNSLIDE(filterAction), (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop); |
6d2010ae | 228 | |
1c79356b A |
229 | if (filterRes) { |
230 | prov->disableInterrupt(source); /* disable the interrupt */ | |
1c79356b A |
231 | signalInterrupt(); |
232 | } | |
1c79356b | 233 | } |