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/IOKitDebug.h>
37 #include <IOKit/IOLib.h>
38 #include <IOKit/IOService.h>
39 #include <IOKit/IOInterrupts.h>
40 #include <IOKit/IOTimeStamp.h>
41 #include <IOKit/IOWorkLoop.h>
43 #define super IOEventSource
45 OSDefineMetaClassAndStructors(IOInterruptEventSource
, IOEventSource
)
46 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 0);
47 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 1);
48 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 2);
49 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 3);
50 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 4);
51 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 5);
52 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 6);
53 OSMetaClassDefineReservedUnused(IOInterruptEventSource
, 7);
55 bool IOInterruptEventSource::init(OSObject
*inOwner
,
57 IOService
*inProvider
,
62 if ( !super::init(inOwner
, (IOEventSourceAction
) inAction
) )
65 provider
= inProvider
;
66 producerCount
= consumerCount
= 0;
67 autoDisable
= explicitDisable
= false;
68 intIndex
= ~inIntIndex
;
70 // Assumes inOwner holds a reference(retain) on the provider
72 res
= (kIOReturnSuccess
== registerInterruptHandler(inProvider
, inIntIndex
));
74 intIndex
= inIntIndex
;
80 IOReturn
IOInterruptEventSource::registerInterruptHandler(IOService
*inProvider
,
85 IOInterruptAction intHandler
;
87 ret
= inProvider
->getInterruptType(inIntIndex
, &intType
);
88 if (kIOReturnSuccess
!= ret
)
91 autoDisable
= (intType
== kIOInterruptTypeLevel
);
93 intHandler
= OSMemberFunctionCast(IOInterruptAction
,
94 this, &IOInterruptEventSource::disableInterruptOccurred
);
97 intHandler
= OSMemberFunctionCast(IOInterruptAction
,
98 this, &IOInterruptEventSource::normalInterruptOccurred
);
100 ret
= provider
->registerInterrupt(inIntIndex
, this, intHandler
);
105 IOInterruptEventSource
*
106 IOInterruptEventSource::interruptEventSource(OSObject
*inOwner
,
108 IOService
*inProvider
,
111 IOInterruptEventSource
*me
= new IOInterruptEventSource
;
113 if (me
&& !me
->init(inOwner
, inAction
, inProvider
, inIntIndex
)) {
121 void IOInterruptEventSource::free()
123 if (provider
&& intIndex
>= 0)
124 provider
->unregisterInterrupt(intIndex
);
129 void IOInterruptEventSource::enable()
131 if (provider
&& intIndex
>= 0) {
132 provider
->enableInterrupt(intIndex
);
133 explicitDisable
= false;
138 void IOInterruptEventSource::disable()
140 if (provider
&& intIndex
>= 0) {
141 provider
->disableInterrupt(intIndex
);
142 explicitDisable
= true;
147 void IOInterruptEventSource::setWorkLoop(IOWorkLoop
*inWorkLoop
)
149 super::setWorkLoop(inWorkLoop
);
156 provider
->unregisterInterrupt(intIndex
);
157 intIndex
= ~intIndex
;
159 } else if ((intIndex
< 0) && (kIOReturnSuccess
== registerInterruptHandler(provider
, ~intIndex
))) {
160 intIndex
= ~intIndex
;
164 const IOService
*IOInterruptEventSource::getProvider() const
169 int IOInterruptEventSource::getIntIndex() const
174 bool IOInterruptEventSource::getAutoDisable() const
179 bool IOInterruptEventSource::checkForWork()
181 unsigned int cacheProdCount
= producerCount
;
182 int numInts
= cacheProdCount
- consumerCount
;
183 IOInterruptEventAction intAction
= (IOInterruptEventAction
) action
;
184 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
189 IOTimeStampStartConstant(IODBG_INTES(IOINTES_ACTION
),
190 (uintptr_t) intAction
, (uintptr_t) owner
, (uintptr_t) this, (uintptr_t) workLoop
);
193 (*intAction
)(owner
, this, numInts
);
196 IOTimeStampEndConstant(IODBG_INTES(IOINTES_ACTION
),
197 (uintptr_t) intAction
, (uintptr_t) owner
, (uintptr_t) this, (uintptr_t) workLoop
);
199 consumerCount
= cacheProdCount
;
200 if (autoDisable
&& !explicitDisable
)
204 else if ( numInts
< 0 )
207 IOTimeStampStartConstant(IODBG_INTES(IOINTES_ACTION
),
208 (uintptr_t) intAction
, (uintptr_t) owner
, (uintptr_t) this, (uintptr_t) workLoop
);
211 (*intAction
)(owner
, this, -numInts
);
214 IOTimeStampEndConstant(IODBG_INTES(IOINTES_ACTION
),
215 (uintptr_t) intAction
, (uintptr_t) owner
, (uintptr_t) this, (uintptr_t) workLoop
);
217 consumerCount
= cacheProdCount
;
218 if (autoDisable
&& !explicitDisable
)
225 void IOInterruptEventSource::normalInterruptOccurred
226 (void */
*refcon*/
, IOService */
*prov*/
, int /*source*/)
228 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
233 IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA
), (uintptr_t) this, (uintptr_t) owner
);
235 signalWorkAvailable();
238 IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA
), (uintptr_t) this, (uintptr_t) owner
);
241 void IOInterruptEventSource::disableInterruptOccurred
242 (void */
*refcon*/
, IOService
*prov
, int source
)
244 bool trace
= (gIOKitTrace
& kIOTraceIntEventSource
) ? true : false;
246 prov
->disableInterrupt(source
); /* disable the interrupt */
251 IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA
), (uintptr_t) this, (uintptr_t) owner
);
253 signalWorkAvailable();
256 IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA
), (uintptr_t) this, (uintptr_t) owner
);
259 void IOInterruptEventSource::interruptOccurred
260 (void *refcon
, IOService
*prov
, int source
)
262 if (autoDisable
&& prov
)
263 disableInterruptOccurred(refcon
, prov
, source
);
265 normalInterruptOccurred(refcon
, prov
, source
);