]>
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> | |
34 | ||
6d2010ae A |
35 | #if IOKITSTATS |
36 | ||
37 | #define IOStatisticsInitializeCounter() \ | |
38 | do { \ | |
39 | IOStatistics::setCounterType(IOEventSource::reserved->counter, kIOStatisticsFilterInterruptEventSourceCounter); \ | |
40 | } while (0) | |
41 | ||
42 | #define IOStatisticsInterrupt() \ | |
43 | do { \ | |
44 | IOStatistics::countInterrupt(IOEventSource::reserved->counter); \ | |
45 | } while (0) | |
46 | ||
47 | #else | |
48 | ||
49 | #define IOStatisticsInitializeCounter() | |
50 | #define IOStatisticsInterrupt() | |
51 | ||
52 | #endif /* IOKITSTATS */ | |
53 | ||
1c79356b A |
54 | #define super IOInterruptEventSource |
55 | ||
56 | OSDefineMetaClassAndStructors | |
57 | (IOFilterInterruptEventSource, IOInterruptEventSource) | |
58 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 0); | |
59 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 1); | |
60 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 2); | |
61 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 3); | |
62 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 4); | |
63 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 5); | |
64 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 6); | |
65 | OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 7); | |
66 | ||
67 | /* | |
68 | * Implement the call throughs for the private protection conversion | |
69 | */ | |
70 | bool IOFilterInterruptEventSource::init(OSObject *inOwner, | |
55e303ae A |
71 | Action inAction, |
72 | IOService *inProvider, | |
73 | int inIntIndex) | |
1c79356b A |
74 | { |
75 | return false; | |
76 | } | |
77 | ||
78 | IOInterruptEventSource * | |
79 | IOFilterInterruptEventSource::interruptEventSource(OSObject *inOwner, | |
80 | Action inAction, | |
81 | IOService *inProvider, | |
82 | int inIntIndex) | |
83 | { | |
84 | return 0; | |
85 | } | |
86 | ||
87 | bool | |
88 | IOFilterInterruptEventSource::init(OSObject *inOwner, | |
89 | Action inAction, | |
90 | Filter inFilterAction, | |
91 | IOService *inProvider, | |
55e303ae | 92 | int inIntIndex) |
1c79356b A |
93 | { |
94 | if ( !super::init(inOwner, inAction, inProvider, inIntIndex) ) | |
95 | return false; | |
96 | ||
97 | if (!inFilterAction) | |
98 | return false; | |
99 | ||
100 | filterAction = inFilterAction; | |
6d2010ae A |
101 | |
102 | IOStatisticsInitializeCounter(); | |
103 | ||
1c79356b A |
104 | return true; |
105 | } | |
106 | ||
107 | IOFilterInterruptEventSource *IOFilterInterruptEventSource | |
108 | ::filterInterruptEventSource(OSObject *inOwner, | |
109 | Action inAction, | |
110 | Filter inFilterAction, | |
111 | IOService *inProvider, | |
55e303ae | 112 | int inIntIndex) |
1c79356b A |
113 | { |
114 | IOFilterInterruptEventSource *me = new IOFilterInterruptEventSource; | |
115 | ||
116 | if (me | |
117 | && !me->init(inOwner, inAction, inFilterAction, inProvider, inIntIndex)) { | |
55e303ae | 118 | me->release(); |
1c79356b A |
119 | return 0; |
120 | } | |
121 | ||
122 | return me; | |
123 | } | |
124 | ||
125 | void IOFilterInterruptEventSource::signalInterrupt() | |
126 | { | |
060df5ea | 127 | bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; |
6d2010ae A |
128 | |
129 | IOStatisticsInterrupt(); | |
1c79356b | 130 | producerCount++; |
6d2010ae | 131 | |
060df5ea A |
132 | if (trace) |
133 | IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner); | |
134 | ||
1c79356b | 135 | signalWorkAvailable(); |
060df5ea A |
136 | |
137 | if (trace) | |
138 | IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner); | |
139 | ||
1c79356b A |
140 | } |
141 | ||
142 | ||
143 | IOFilterInterruptEventSource::Filter | |
144 | IOFilterInterruptEventSource::getFilterAction() const | |
145 | { | |
146 | return filterAction; | |
147 | } | |
148 | ||
149 | ||
150 | ||
151 | ||
152 | void IOFilterInterruptEventSource::normalInterruptOccurred | |
153 | (void */*refcon*/, IOService */*prov*/, int /*source*/) | |
154 | { | |
6d2010ae | 155 | bool filterRes; |
060df5ea | 156 | bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; |
6d2010ae | 157 | |
060df5ea A |
158 | if (trace) |
159 | IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER), | |
316670eb | 160 | VM_KERNEL_UNSLIDE(filterAction), (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop); |
6d2010ae | 161 | |
060df5ea | 162 | // Call the filter. |
1c79356b | 163 | filterRes = (*filterAction)(owner, this); |
060df5ea A |
164 | |
165 | if (trace) | |
166 | IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER), | |
316670eb | 167 | VM_KERNEL_UNSLIDE(filterAction), (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop); |
6d2010ae | 168 | |
1c79356b A |
169 | if (filterRes) |
170 | signalInterrupt(); | |
1c79356b A |
171 | } |
172 | ||
173 | void IOFilterInterruptEventSource::disableInterruptOccurred | |
174 | (void */*refcon*/, IOService *prov, int source) | |
175 | { | |
6d2010ae | 176 | bool filterRes; |
060df5ea | 177 | bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; |
6d2010ae | 178 | |
060df5ea A |
179 | if (trace) |
180 | IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER), | |
316670eb | 181 | VM_KERNEL_UNSLIDE(filterAction), (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop); |
6d2010ae | 182 | |
060df5ea | 183 | // Call the filter. |
1c79356b | 184 | filterRes = (*filterAction)(owner, this); |
060df5ea A |
185 | |
186 | if (trace) | |
187 | IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER), | |
316670eb | 188 | VM_KERNEL_UNSLIDE(filterAction), (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop); |
6d2010ae | 189 | |
1c79356b A |
190 | if (filterRes) { |
191 | prov->disableInterrupt(source); /* disable the interrupt */ | |
1c79356b A |
192 | signalInterrupt(); |
193 | } | |
1c79356b | 194 | } |