xref: /xnu-10063.121.3/iokit/IOKit/IOFilterInterruptEventSource.h (revision 2c2f96dc2b9a4408a43d3150ae9c105355ca3daa)
1*2c2f96dcSApple OSS Distributions /*
2*2c2f96dcSApple OSS Distributions  * Copyright (c) 1998-2019 Apple Inc. All rights reserved.
3*2c2f96dcSApple OSS Distributions  *
4*2c2f96dcSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*2c2f96dcSApple OSS Distributions  *
6*2c2f96dcSApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*2c2f96dcSApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*2c2f96dcSApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*2c2f96dcSApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*2c2f96dcSApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*2c2f96dcSApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*2c2f96dcSApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*2c2f96dcSApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*2c2f96dcSApple OSS Distributions  *
15*2c2f96dcSApple OSS Distributions  * Please obtain a copy of the License at
16*2c2f96dcSApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*2c2f96dcSApple OSS Distributions  *
18*2c2f96dcSApple OSS Distributions  * The Original Code and all software distributed under the License are
19*2c2f96dcSApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*2c2f96dcSApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*2c2f96dcSApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*2c2f96dcSApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*2c2f96dcSApple OSS Distributions  * Please see the License for the specific language governing rights and
24*2c2f96dcSApple OSS Distributions  * limitations under the License.
25*2c2f96dcSApple OSS Distributions  *
26*2c2f96dcSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*2c2f96dcSApple OSS Distributions  */
28*2c2f96dcSApple OSS Distributions /*
29*2c2f96dcSApple OSS Distributions  *  Copyright (c) 1999 Apple Computer, Inc.	 All rights reserved.
30*2c2f96dcSApple OSS Distributions  *
31*2c2f96dcSApple OSS Distributions  *  HISTORY
32*2c2f96dcSApple OSS Distributions  *   1999-4-15	Godfrey van der Linden(gvdl)
33*2c2f96dcSApple OSS Distributions  *       Created.
34*2c2f96dcSApple OSS Distributions  */
35*2c2f96dcSApple OSS Distributions #ifndef _IOKIT_IOFILTERINTERRUPTEVENTSOURCE_H
36*2c2f96dcSApple OSS Distributions #define _IOKIT_IOFILTERINTERRUPTEVENTSOURCE_H
37*2c2f96dcSApple OSS Distributions 
38*2c2f96dcSApple OSS Distributions #include <libkern/c++/OSPtr.h>
39*2c2f96dcSApple OSS Distributions #include <IOKit/IOInterruptEventSource.h>
40*2c2f96dcSApple OSS Distributions #include <libkern/c++/OSPtr.h>
41*2c2f96dcSApple OSS Distributions 
42*2c2f96dcSApple OSS Distributions class IOService;
43*2c2f96dcSApple OSS Distributions 
44*2c2f96dcSApple OSS Distributions /*! @class IOFilterInterruptEventSource : public IOInterruptEventSource
45*2c2f96dcSApple OSS Distributions  *   @abstract Filtering varient of the $link IOInterruptEventSource.
46*2c2f96dcSApple OSS Distributions  *   @discussion An interrupt event source that calls the client to determine if a interrupt event needs to be scheduled on the work loop.  A filter interrupt event source call's the client in the primary interrupt context, the client can then interrogate its hardware and determine if the interrupt needs to be processed yet.
47*2c2f96dcSApple OSS Distributions  *  <br><br>
48*2c2f96dcSApple OSS Distributions  *   As the routine is called in the primary interrupt context great care must be taken in the writing of this routine.  In general none of the generic IOKit environment is safe to call in this context.  We intend this routine to be used by hardware that can interrogate its registers without destroying state.  Primarily this variant of event sources will be used by drivers that share interrupts.  The filter routine will determine if the interrupt is a real interrupt or a ghost and thus optimise the work thread context switch away.
49*2c2f96dcSApple OSS Distributions  *  <br><br>
50*2c2f96dcSApple OSS Distributions  *  If you are implementing 'SoftDMA' (or pseudo-DMA), you may not want the I/O Kit to automatically start your interrupt handler routine on your work loop when your filter routine returns true.  In this case, you may choose to have your filter routine schedule the work on the work loop itself and then return false.  If you do this, the interrupt will not be disabled in hardware and you could receive additional primary interrupts before your work loop–level service routine completes.  Because this scheme has implications for synchronization between your filter routine and your interrupt service routine, you should avoid doing this unless your driver requires SoftDMA.
51*2c2f96dcSApple OSS Distributions  *  <br><br>
52*2c2f96dcSApple OSS Distributions  *  CAUTION:  Called in primary interrupt context, if you need to disable interrupt to guard you registers against an unexpected call then it is better to use a straight IOInterruptEventSource and its secondary interrupt delivery mechanism.
53*2c2f96dcSApple OSS Distributions  */
54*2c2f96dcSApple OSS Distributions class IOFilterInterruptEventSource : public IOInterruptEventSource
55*2c2f96dcSApple OSS Distributions {
56*2c2f96dcSApple OSS Distributions 	OSDeclareDefaultStructors(IOFilterInterruptEventSource);
57*2c2f96dcSApple OSS Distributions 
58*2c2f96dcSApple OSS Distributions public:
59*2c2f96dcSApple OSS Distributions /*!
60*2c2f96dcSApple OSS Distributions  *   @typedef Filter
61*2c2f96dcSApple OSS Distributions  *   @discussion C Function pointer to a routine to call when an interrupt occurs.
62*2c2f96dcSApple OSS Distributions  *   @param owner Pointer to the owning/client instance.
63*2c2f96dcSApple OSS Distributions  *   @param sender Where is the interrupt comming from.
64*2c2f96dcSApple OSS Distributions  *   @result false if this interrupt can be ignored. */
65*2c2f96dcSApple OSS Distributions 	typedef bool (*Filter)(OSObject *owner, IOFilterInterruptEventSource *sender);
66*2c2f96dcSApple OSS Distributions 
67*2c2f96dcSApple OSS Distributions /*! @defined IOFilterInterruptAction
68*2c2f96dcSApple OSS Distributions  *   @discussion Backward compatibilty define for the old non-class scoped type definition.  See $link IOFilterInterruptSource::Filter */
69*2c2f96dcSApple OSS Distributions #define IOFilterInterruptAction IOFilterInterruptEventSource::Filter
70*2c2f96dcSApple OSS Distributions 
71*2c2f96dcSApple OSS Distributions #ifdef __BLOCKS__
72*2c2f96dcSApple OSS Distributions 	typedef bool (^FilterBlock)(IOFilterInterruptEventSource *sender);
73*2c2f96dcSApple OSS Distributions #endif /* __BLOCKS__ */
74*2c2f96dcSApple OSS Distributions 
75*2c2f96dcSApple OSS Distributions private:
76*2c2f96dcSApple OSS Distributions // Hide the superclass initializers
77*2c2f96dcSApple OSS Distributions 	virtual bool init(OSObject *inOwner,
78*2c2f96dcSApple OSS Distributions 	    IOInterruptEventSource::Action inAction = NULL,
79*2c2f96dcSApple OSS Distributions 	    IOService *inProvider = NULL,
80*2c2f96dcSApple OSS Distributions 	    int inIntIndex = 0) APPLE_KEXT_OVERRIDE;
81*2c2f96dcSApple OSS Distributions 
82*2c2f96dcSApple OSS Distributions 	static OSPtr<IOInterruptEventSource>
83*2c2f96dcSApple OSS Distributions 	interruptEventSource(OSObject *inOwner,
84*2c2f96dcSApple OSS Distributions 	    IOInterruptEventSource::Action inAction = NULL,
85*2c2f96dcSApple OSS Distributions 	    IOService *inProvider = NULL,
86*2c2f96dcSApple OSS Distributions 	    int inIntIndex = 0);
87*2c2f96dcSApple OSS Distributions 
88*2c2f96dcSApple OSS Distributions protected:
89*2c2f96dcSApple OSS Distributions /*! @var filterAction Filter callout */
90*2c2f96dcSApple OSS Distributions 
91*2c2f96dcSApple OSS Distributions #if XNU_KERNEL_PRIVATE
92*2c2f96dcSApple OSS Distributions 	union { Filter filterAction; FilterBlock filterActionBlock; };
93*2c2f96dcSApple OSS Distributions #else /* XNU_KERNEL_PRIVATE */
94*2c2f96dcSApple OSS Distributions 	Filter filterAction;
95*2c2f96dcSApple OSS Distributions #endif /* !XNU_KERNEL_PRIVATE */
96*2c2f96dcSApple OSS Distributions 
97*2c2f96dcSApple OSS Distributions /*! @struct ExpansionData
98*2c2f96dcSApple OSS Distributions  *   @discussion This structure will be used to expand the capablilties of the IOWorkLoop in the future.
99*2c2f96dcSApple OSS Distributions  */
100*2c2f96dcSApple OSS Distributions 	struct ExpansionData { };
101*2c2f96dcSApple OSS Distributions 
102*2c2f96dcSApple OSS Distributions /*! @var reserved
103*2c2f96dcSApple OSS Distributions  *   Reserved for future use.  (Internal use only)  */
104*2c2f96dcSApple OSS Distributions 	APPLE_KEXT_WSHADOW_PUSH;
105*2c2f96dcSApple OSS Distributions 	ExpansionData *reserved;
106*2c2f96dcSApple OSS Distributions 	APPLE_KEXT_WSHADOW_POP;
107*2c2f96dcSApple OSS Distributions 
108*2c2f96dcSApple OSS Distributions public:
109*2c2f96dcSApple OSS Distributions /*! @function filterInterruptEventSource
110*2c2f96dcSApple OSS Distributions  *   @abstract Factor method to create and initialise an IOFilterInterruptEventSource.  See $link init.
111*2c2f96dcSApple OSS Distributions  *   @param owner Owner/client of this event source.
112*2c2f96dcSApple OSS Distributions  *   @param action 'C' Function to call when something happens.
113*2c2f96dcSApple OSS Distributions  *   @param filter 'C' Function to call when interrupt occurs.
114*2c2f96dcSApple OSS Distributions  *   @param provider Service that provides interrupts.
115*2c2f96dcSApple OSS Distributions  *   @param intIndex Defaults to 0.
116*2c2f96dcSApple OSS Distributions  *   @result a new event source if succesful, 0 otherwise.  */
117*2c2f96dcSApple OSS Distributions 	static OSPtr<IOFilterInterruptEventSource>
118*2c2f96dcSApple OSS Distributions 	filterInterruptEventSource(OSObject *owner,
119*2c2f96dcSApple OSS Distributions 	    IOInterruptEventSource::Action action,
120*2c2f96dcSApple OSS Distributions 	    Filter filter,
121*2c2f96dcSApple OSS Distributions 	    IOService *provider,
122*2c2f96dcSApple OSS Distributions 	    int intIndex = 0);
123*2c2f96dcSApple OSS Distributions 
124*2c2f96dcSApple OSS Distributions #ifdef __BLOCKS__
125*2c2f96dcSApple OSS Distributions /*! @function filterInterruptEventSource
126*2c2f96dcSApple OSS Distributions  *   @abstract Factor method to create and initialise an IOFilterInterruptEventSource.  See $link init.
127*2c2f96dcSApple OSS Distributions  *   @param owner Owner/client of this event source.
128*2c2f96dcSApple OSS Distributions  *   @param provider Service that provides interrupts.
129*2c2f96dcSApple OSS Distributions  *   @param intIndex The index of the interrupt within the provider's interrupt sources.
130*2c2f96dcSApple OSS Distributions  *   @param action Block for the callout routine of this event source.
131*2c2f96dcSApple OSS Distributions  *   @param filter Block to invoke when HW interrupt occurs.
132*2c2f96dcSApple OSS Distributions  *   @result a new event source if succesful, 0 otherwise.  */
133*2c2f96dcSApple OSS Distributions 	static OSPtr<IOFilterInterruptEventSource>
134*2c2f96dcSApple OSS Distributions 	filterInterruptEventSource(OSObject *owner,
135*2c2f96dcSApple OSS Distributions 	    IOService *provider,
136*2c2f96dcSApple OSS Distributions 	    int intIndex,
137*2c2f96dcSApple OSS Distributions 	    IOInterruptEventSource::ActionBlock action,
138*2c2f96dcSApple OSS Distributions 	    FilterBlock filter);
139*2c2f96dcSApple OSS Distributions #endif /* __BLOCKS__ */
140*2c2f96dcSApple OSS Distributions 
141*2c2f96dcSApple OSS Distributions #if XNU_KERNEL_PRIVATE
142*2c2f96dcSApple OSS Distributions 	enum{
143*2c2f96dcSApple OSS Distributions 		kFilterBlock = kSubClass0,
144*2c2f96dcSApple OSS Distributions 	};
145*2c2f96dcSApple OSS Distributions #endif
146*2c2f96dcSApple OSS Distributions 
147*2c2f96dcSApple OSS Distributions /*! @function init
148*2c2f96dcSApple OSS Distributions  *   @abstract Primary initialiser for the IOFilterInterruptEventSource class.
149*2c2f96dcSApple OSS Distributions  *   @param owner Owner/client of this event source.
150*2c2f96dcSApple OSS Distributions  *   @param action 'C' Function to call when something happens.
151*2c2f96dcSApple OSS Distributions  *   @param filter 'C' Function to call in primary interrupt context.
152*2c2f96dcSApple OSS Distributions  *   @param provider Service that provides interrupts.
153*2c2f96dcSApple OSS Distributions  *   @param intIndex Interrupt source within provider.  Defaults to 0.
154*2c2f96dcSApple OSS Distributions  *   @result true if the inherited classes and this instance initialise
155*2c2f96dcSApple OSS Distributions  *  successfully.  */
156*2c2f96dcSApple OSS Distributions 	virtual bool init(OSObject *owner,
157*2c2f96dcSApple OSS Distributions 	    IOInterruptEventSource::Action action,
158*2c2f96dcSApple OSS Distributions 	    Filter filter,
159*2c2f96dcSApple OSS Distributions 	    IOService *provider,
160*2c2f96dcSApple OSS Distributions 	    int intIndex = 0);
161*2c2f96dcSApple OSS Distributions 
162*2c2f96dcSApple OSS Distributions 	virtual void free( void ) APPLE_KEXT_OVERRIDE;
163*2c2f96dcSApple OSS Distributions 
164*2c2f96dcSApple OSS Distributions /*! @function signalInterrupt
165*2c2f96dcSApple OSS Distributions  *   @abstract Cause the work loop to schedule the action.
166*2c2f96dcSApple OSS Distributions  *   @discussion Cause the work loop to schedule the interrupt action even if the filter routine returns 'false'. Note well the interrupting condition MUST be cleared from the hardware otherwise an infinite process interrupt loop will occur.  Use this function when SoftDMA is desired.  See $link IOFilterInterruptSource::Filter */
167*2c2f96dcSApple OSS Distributions 	virtual void signalInterrupt();
168*2c2f96dcSApple OSS Distributions 
169*2c2f96dcSApple OSS Distributions /*! @function getFilterAction
170*2c2f96dcSApple OSS Distributions  *   @abstract Get'ter for filterAction variable.
171*2c2f96dcSApple OSS Distributions  *   @result value of filterAction. */
172*2c2f96dcSApple OSS Distributions 	virtual Filter getFilterAction() const;
173*2c2f96dcSApple OSS Distributions 
174*2c2f96dcSApple OSS Distributions #ifdef __BLOCKS__
175*2c2f96dcSApple OSS Distributions /*! @function getFilterActionBlock
176*2c2f96dcSApple OSS Distributions  *   @abstract Get'ter for filterAction variable.
177*2c2f96dcSApple OSS Distributions  *   @result value of filterAction. */
178*2c2f96dcSApple OSS Distributions 	FilterBlock getFilterActionBlock() const;
179*2c2f96dcSApple OSS Distributions #endif /* __BLOCKS__ */
180*2c2f96dcSApple OSS Distributions 
181*2c2f96dcSApple OSS Distributions /*! @function normalInterruptOccurred
182*2c2f96dcSApple OSS Distributions  *   @abstract Override $link IOInterruptEventSource::normalInterruptOccured to make a filter callout. */
183*2c2f96dcSApple OSS Distributions 	virtual void normalInterruptOccurred(void *self, IOService *prov, int ind) APPLE_KEXT_OVERRIDE;
184*2c2f96dcSApple OSS Distributions 
185*2c2f96dcSApple OSS Distributions /*! @function disableInterruptOccurred
186*2c2f96dcSApple OSS Distributions  *   @abstract Override $link IOInterruptEventSource::disableInterruptOccurred to make a filter callout. */
187*2c2f96dcSApple OSS Distributions 	virtual void disableInterruptOccurred(void *self, IOService *prov, int ind) APPLE_KEXT_OVERRIDE;
188*2c2f96dcSApple OSS Distributions 
189*2c2f96dcSApple OSS Distributions private:
190*2c2f96dcSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOFilterInterruptEventSource, 0);
191*2c2f96dcSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOFilterInterruptEventSource, 1);
192*2c2f96dcSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOFilterInterruptEventSource, 2);
193*2c2f96dcSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOFilterInterruptEventSource, 3);
194*2c2f96dcSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOFilterInterruptEventSource, 4);
195*2c2f96dcSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOFilterInterruptEventSource, 5);
196*2c2f96dcSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOFilterInterruptEventSource, 6);
197*2c2f96dcSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOFilterInterruptEventSource, 7);
198*2c2f96dcSApple OSS Distributions };
199*2c2f96dcSApple OSS Distributions 
200*2c2f96dcSApple OSS Distributions #endif /* !_IOKIT_IOFILTERINTERRUPTEVENTSOURCE_H */
201