]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOFilterInterruptEventSource.cpp
f4f73e2b4c1b3a371ddf791b5915590af1d8916e
[apple/xnu.git] / iokit / Kernel / IOFilterInterruptEventSource.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
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
35 #define super IOInterruptEventSource
36
37 OSDefineMetaClassAndStructors
38 (IOFilterInterruptEventSource, IOInterruptEventSource)
39 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 0);
40 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 1);
41 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 2);
42 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 3);
43 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 4);
44 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 5);
45 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 6);
46 OSMetaClassDefineReservedUnused(IOFilterInterruptEventSource, 7);
47
48 /*
49 * Implement the call throughs for the private protection conversion
50 */
51 bool IOFilterInterruptEventSource::init(OSObject *inOwner,
52 Action inAction,
53 IOService *inProvider,
54 int inIntIndex)
55 {
56 return false;
57 }
58
59 IOInterruptEventSource *
60 IOFilterInterruptEventSource::interruptEventSource(OSObject *inOwner,
61 Action inAction,
62 IOService *inProvider,
63 int inIntIndex)
64 {
65 return 0;
66 }
67
68 bool
69 IOFilterInterruptEventSource::init(OSObject *inOwner,
70 Action inAction,
71 Filter inFilterAction,
72 IOService *inProvider,
73 int inIntIndex)
74 {
75 if ( !super::init(inOwner, inAction, inProvider, inIntIndex) )
76 return false;
77
78 if (!inFilterAction)
79 return false;
80
81 filterAction = inFilterAction;
82 return true;
83 }
84
85 IOFilterInterruptEventSource *IOFilterInterruptEventSource
86 ::filterInterruptEventSource(OSObject *inOwner,
87 Action inAction,
88 Filter inFilterAction,
89 IOService *inProvider,
90 int inIntIndex)
91 {
92 IOFilterInterruptEventSource *me = new IOFilterInterruptEventSource;
93
94 if (me
95 && !me->init(inOwner, inAction, inFilterAction, inProvider, inIntIndex)) {
96 me->release();
97 return 0;
98 }
99
100 return me;
101 }
102
103 void IOFilterInterruptEventSource::signalInterrupt()
104 {
105 bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false;
106
107 producerCount++;
108
109 if (trace)
110 IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner);
111
112 signalWorkAvailable();
113
114 if (trace)
115 IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), (uintptr_t) this, (uintptr_t) owner);
116
117 }
118
119
120 IOFilterInterruptEventSource::Filter
121 IOFilterInterruptEventSource::getFilterAction() const
122 {
123 return filterAction;
124 }
125
126
127
128
129 void IOFilterInterruptEventSource::normalInterruptOccurred
130 (void */*refcon*/, IOService */*prov*/, int /*source*/)
131 {
132 bool filterRes;
133 bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false;
134
135 if (trace)
136 IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER),
137 (uintptr_t) filterAction, (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop);
138
139 // Call the filter.
140 filterRes = (*filterAction)(owner, this);
141
142 if (trace)
143 IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER),
144 (uintptr_t) filterAction, (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop);
145
146 if (filterRes)
147 signalInterrupt();
148 }
149
150 void IOFilterInterruptEventSource::disableInterruptOccurred
151 (void */*refcon*/, IOService *prov, int source)
152 {
153 bool filterRes;
154 bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false;
155
156 if (trace)
157 IOTimeStampStartConstant(IODBG_INTES(IOINTES_FILTER),
158 (uintptr_t) filterAction, (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop);
159
160 // Call the filter.
161 filterRes = (*filterAction)(owner, this);
162
163 if (trace)
164 IOTimeStampEndConstant(IODBG_INTES(IOINTES_FILTER),
165 (uintptr_t) filterAction, (uintptr_t) owner, (uintptr_t) this, (uintptr_t) workLoop);
166
167 if (filterRes) {
168 prov->disableInterrupt(source); /* disable the interrupt */
169 signalInterrupt();
170 }
171 }