2 * Copyright (c) 1998-2000 Apple Computer, 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 Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
32 1998-7-13 Godfrey van der Linden(gvdl)
35 #include <IOKit/IOInterruptEventSource.h>
36 #include <IOKit/IOLib.h>
37 #include <IOKit/IOService.h>
38 #include <IOKit/IOInterrupts.h>
39 #include <IOKit/IOTimeStamp.h>
40 #include <IOKit/IOWorkLoop.h>
44 #define IOTimeTypeStampS(t) \
46 IOTimeStampStart(IODBG_INTES(t), \
47 (unsigned int) this, (unsigned int) owner); \
50 #define IOTimeTypeStampE(t) \
52 IOTimeStampEnd(IODBG_INTES(t), \
53 (unsigned int) this, (unsigned int) owner); \
56 #define IOTimeStampLatency() \
58 IOTimeStampEnd(IODBG_INTES(IOINTES_LAT), \
59 (unsigned int) this, (unsigned int) owner); \
63 #define IOTimeTypeStampS(t)
64 #define IOTimeTypeStampE(t)
65 #define IOTimeStampLatency()
68 #define super IOEventSource
70 OSDefineMetaClassAndStructors(IOInterruptEventSource
, IOEventSource
)
71 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 0);
72 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 1);
73 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 2);
74 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 3);
75 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 4);
76 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 5);
77 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 6);
78 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 7);
80 bool IOInterruptEventSource::init(OSObject
*inOwner
,
82 IOService
*inProvider
,
87 if ( !super::init(inOwner
, (IOEventSourceAction
) inAction
) )
90 provider
= inProvider
;
91 producerCount
= consumerCount
= 0;
92 autoDisable
= explicitDisable
= false;
95 // Assumes inOwner holds a reference(retain) on the provider
99 res
= (kIOReturnSuccess
100 == inProvider
->getInterruptType(inIntIndex
, &intType
));
102 IOInterruptAction intHandler
;
104 autoDisable
= (intType
== kIOInterruptTypeLevel
);
106 intHandler
= OSMemberFunctionCast(IOInterruptAction
,
107 this, &IOInterruptEventSource::disableInterruptOccurred
);
110 intHandler
= OSMemberFunctionCast(IOInterruptAction
,
111 this, &IOInterruptEventSource::normalInterruptOccurred
);
113 res
= (kIOReturnSuccess
== inProvider
->registerInterrupt
114 (inIntIndex
, this, intHandler
));
116 intIndex
= inIntIndex
;
123 IOInterruptEventSource
*
124 IOInterruptEventSource::interruptEventSource(OSObject
*inOwner
,
126 IOService
*inProvider
,
129 IOInterruptEventSource
*me
= new IOInterruptEventSource
;
131 if (me
&& !me
->init(inOwner
, inAction
, inProvider
, inIntIndex
)) {
139 void IOInterruptEventSource::free()
141 if (provider
&& intIndex
!= -1)
142 provider
->unregisterInterrupt(intIndex
);
147 void IOInterruptEventSource::enable()
149 if (provider
&& intIndex
!= -1) {
150 provider
->enableInterrupt(intIndex
);
151 explicitDisable
= false;
155 void IOInterruptEventSource::disable()
157 if (provider
&& intIndex
!= -1) {
158 provider
->disableInterrupt(intIndex
);
159 explicitDisable
= true;
163 const IOService
*IOInterruptEventSource::getProvider() const
168 int IOInterruptEventSource::getIntIndex() const
173 bool IOInterruptEventSource::getAutoDisable() const
178 bool IOInterruptEventSource::checkForWork()
180 unsigned int cacheProdCount
= producerCount
;
181 int numInts
= cacheProdCount
- consumerCount
;
182 IOInterruptEventAction intAction
= (IOInterruptEventAction
) action
;
186 IOTimeStampLatency();
187 IOTimeTypeStampS(IOINTES_CLIENT
);
188 IOTimeStampConstant(IODBG_INTES(IOINTES_ACTION
),
189 (unsigned int) intAction
, (unsigned int) owner
);
190 (*intAction
)(owner
, this, numInts
);
191 IOTimeTypeStampE(IOINTES_CLIENT
);
193 consumerCount
= cacheProdCount
;
194 if (autoDisable
&& !explicitDisable
)
197 else if (numInts
< 0) {
198 IOTimeStampLatency();
199 IOTimeTypeStampS(IOINTES_CLIENT
);
200 IOTimeStampConstant(IODBG_INTES(IOINTES_ACTION
),
201 (unsigned int) intAction
, (unsigned int) owner
);
202 (*intAction
)(owner
, this, -numInts
);
203 IOTimeTypeStampE(IOINTES_CLIENT
);
205 consumerCount
= cacheProdCount
;
206 if (autoDisable
&& !explicitDisable
)
213 void IOInterruptEventSource::normalInterruptOccurred
214 (void */
*refcon*/
, IOService */
*prov*/
, int /*source*/)
216 IOTimeTypeStampS(IOINTES_INTCTXT
);
217 IOTimeStampLatency();
221 IOTimeTypeStampS(IOINTES_SEMA
);
222 signalWorkAvailable();
223 IOTimeTypeStampE(IOINTES_SEMA
);
225 IOTimeTypeStampE(IOINTES_INTCTXT
);
228 void IOInterruptEventSource::disableInterruptOccurred
229 (void */
*refcon*/
, IOService
*prov
, int source
)
231 IOTimeTypeStampS(IOINTES_INTCTXT
);
232 IOTimeStampLatency();
234 prov
->disableInterrupt(source
); /* disable the interrupt */
238 IOTimeTypeStampS(IOINTES_SEMA
);
239 signalWorkAvailable();
240 IOTimeTypeStampE(IOINTES_SEMA
);
242 IOTimeTypeStampE(IOINTES_INTCTXT
);
245 void IOInterruptEventSource::interruptOccurred
246 (void *refcon
, IOService
*prov
, int source
)
248 if (autoDisable
&& prov
)
249 disableInterruptOccurred(refcon
, prov
, source
);
251 normalInterruptOccurred(refcon
, prov
, source
);