]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOInterruptEventSource.h
xnu-1228.9.59.tar.gz
[apple/xnu.git] / iokit / IOKit / IOInterruptEventSource.h
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 Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
30
31 HISTORY
32 1998-7-13 Godfrey van der Linden(gvdl)
33 Created.
34 1998-10-30 Godfrey van der Linden(gvdl)
35 Converted to C++
36 */
37
38 #ifndef _IOKIT_IOINTERRUPTEVENTSOURCE_H
39 #define _IOKIT_IOINTERRUPTEVENTSOURCE_H
40
41 #include <IOKit/IOEventSource.h>
42
43 class IOService;
44
45 /*! @class IOInterruptEventSource : public IOEventSource
46 @abstract Event source for interrupt delivery to work-loop based drivers.
47 @discussion The IOInterruptEventSource is a generic object that delivers calls interrupt routines in it's client in a guaranteed single-threaded manner. IOInterruptEventSource is part of the IOKit $link IOWorkLoop infrastructure where the semantic that one and only one action method is executing within a work-loops event chain.
48 <br><br>
49 When the action method is called in the client member function will receive 2 arguments, (IOEventSource *) sender and (int) count, See $link IOInterruptEventSource::Action. Where sender will be reference to the interrupt that occurred and the count will be computed by the difference between the $link producerCount and $link consumerCount. This number may not be reliable as no attempt is made to adjust for around the world type problems but is provided for general information and statistic gathering.
50 <br><br>
51 In general a client will use the factory member function to create and initialise the event source and then add it to their work-loop. It is the work loop's responsiblity to maintain the new event source in it's event chain. See $link IOWorkLoop.
52 <br><br>
53 An interrupt event source attaches itself to the given provider's interrupt source at initialisation time. At this time it determines if it is connected to a level or edge triggered interrupt. If the interrupt is an level triggered interrupt the event source automatically disables the interrupt source at primary interrupt time and after it call's the client it automatically reenables the interrupt. This action is fairly expensive but it is 100% safe and defaults sensibly so that the driver writer does not have to implement type dependant interrupt routines. So to repeat, the driver writer does not have to be concerned by the actual underlying interrupt mechanism as the event source hides the complexity.
54 <br><br>
55 Saying this if the hardware is a multi-device card, for instance a 4 port NIC, where all of the devices are sharing one level triggered interrupt AND it is possible to determine each port's interrupt state non-destructively then the $link IOFilterInterruptEventSource would be a better choice.
56 <br><br>
57 Warning: All IOInterruptEventSources are created in the disabled state. If you want to actually schedule interrupt delivery do not forget to enable the source.
58 */
59 class IOInterruptEventSource : public IOEventSource
60 {
61 OSDeclareDefaultStructors(IOInterruptEventSource)
62
63 public:
64 /*! @typedef Action
65 @discussion 'C' pointer prototype of functions that are called in a single threaded context when an interrupt occurs.
66 @param owner Pointer to client instance.
67 @param sender Pointer to generation interrupt event source.
68 @param count Number of interrupts seen before delivery. */
69 typedef void (*Action)(OSObject *, IOInterruptEventSource *, int count);
70
71 /*! @defined IOInterruptEventAction
72 @discussion Backward compatibilty define for the old non-class scoped type definition. See $link IOInterruptEventSource::Action */
73 #define IOInterruptEventAction IOInterruptEventSource::Action
74
75 protected:
76 /*! @var provider IOService that provides interrupts for delivery. */
77 IOService *provider;
78
79 /*! @var intIndex */
80 int intIndex;
81
82 /*! @var producerCount
83 Current count of produced interrupts that have been received. */
84 volatile unsigned int producerCount;
85
86 /*! @var consumerCount
87 Current count of produced interrupts that the owner has been informed of. */
88 unsigned int consumerCount;
89
90 /*! @var autoDisable Do we need to automatically disable the interrupt source when we take an interrupt, i.e. we are level triggered. */
91 bool autoDisable;
92
93 /*! @var explicitDisable Has the user expicitly disabled this event source, if so then do not overide their request when returning from the callout */
94 bool explicitDisable;
95
96 /*! @struct ExpansionData
97 @discussion This structure will be used to expand the capablilties of the IOWorkLoop in the future.
98 */
99 struct ExpansionData { };
100
101 /*! @var reserved
102 Reserved for future use. (Internal use only) */
103 ExpansionData *reserved;
104
105 /*! @function free
106 @abstract Sub-class implementation of free method, disconnects from the interrupt source. */
107 virtual void free();
108
109 /*! @function checkForWork
110 @abstract Pure Virtual member function used by IOWorkLoop for issueing a client calls.
111 @discussion This function called when the work-loop is ready to check for any work to do and then to call out the owner/action.
112 @result Return true if this function needs to be called again before all its outstanding events have been processed. */
113 virtual bool checkForWork();
114
115 public:
116
117 /*! @function interruptEventSource
118 @abstract Factory function for IOInterruptEventSources creation and initialisation.
119 @param owner Owning client of the new event source.
120 @param action 'C' Function to call when something happens.
121 @param provider IOService that represents the interrupt source. Defaults to 0. When no provider is defined the event source assumes that the client will in some manner call the interruptOccured method explicitly. This will start the ball rolling for safe delivery of asynchronous event's into the driver.
122 @param intIndex The index of the interrupt within the provider's interrupt sources. Defaults to 0, i.e. the first interrupt in the provider.
123 @result A new interrupt event source if successfully created and initialised, 0 otherwise. */
124 static IOInterruptEventSource *
125 interruptEventSource(OSObject *owner,
126 Action action,
127 IOService *provider = 0,
128 int intIndex = 0);
129
130 /*! @function init
131 @abstract Primary initialiser for the IOInterruptEventSource class.
132 @param owner Owning client of the new event source.
133 @param action 'C' Function to call when something happens.
134 @param provider IOService that represents the interrupt source. Defaults to 0. When no provider is defined the event source assumes that the client will in some manner call the interruptOccured method explicitly. This will start the ball rolling for safe delivery of asynchronous event's into the driver.
135 @param intIndex The index of the interrupt within the provider's interrupt sources. Defaults to 0, i.e. the first interrupt in the provider.
136 @result true if the inherited classes and this instance initialise
137 successfully. */
138 virtual bool init(OSObject *owner,
139 Action action,
140 IOService *provider = 0,
141 int intIndex = 0);
142
143 /*! @function enable
144 @abstract Enable event source.
145 @discussion A subclass implementation is expected to respect the enabled
146 state when checkForWork is called. Calling this function will cause the
147 work-loop to be signalled so that a checkForWork is performed. */
148 virtual void enable();
149
150 /*! @function disable
151 @abstract Disable event source.
152 @discussion A subclass implementation is expected to respect the enabled
153 state when checkForWork is called. */
154 virtual void disable();
155
156 /*! @function getProvider
157 @abstract Get'ter for $link provider variable.
158 @result value of provider. */
159 virtual const IOService *getProvider() const;
160
161 /*! @function getIntIndex
162 @abstract Get'ter for $link intIndex interrupt index variable.
163 @result value of intIndex. */
164 virtual int getIntIndex() const;
165
166 /*! @function getAutoDisable
167 @abstract Get'ter for $link autoDisable variable.
168 @result value of autoDisable. */
169 virtual bool getAutoDisable() const;
170
171 /*! @function interruptOccurred
172 @abstract Functions that get called by the interrupt controller. See $link IOService::registerInterrupt
173 @param nub Where did the interrupt originate from
174 @param ind What is this interrupts index within 'nub'. */
175 virtual void interruptOccurred(void *, IOService *nub, int ind);
176
177 /*! @function normalInterruptOccurred
178 @abstract Functions that get called by the interrupt controller.See $link IOService::registerInterrupt
179 @param nub Where did the interrupt originate from
180 @param ind What is this interrupts index within 'nub'. */
181 virtual void normalInterruptOccurred(void *, IOService *nub, int ind);
182
183 /*! @function disableInterruptOccurred
184 @abstract Functions that get called by the interrupt controller.See $link IOService::registerInterrupt
185 @param nub Where did the interrupt originate from
186 @param ind What is this interrupts index within 'nub'. */
187 virtual void disableInterruptOccurred(void *, IOService *nub, int ind);
188
189 private:
190 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 0);
191 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 1);
192 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 2);
193 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 3);
194 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 4);
195 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 5);
196 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 6);
197 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 7);
198 };
199
200 #endif /* !_IOKIT_IOINTERRUPTEVENTSOURCE_H */