]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOInterruptEventSource.h
xnu-344.49.tar.gz
[apple/xnu.git] / iokit / IOKit / IOInterruptEventSource.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
27
28 HISTORY
29 1998-7-13 Godfrey van der Linden(gvdl)
30 Created.
31 1998-10-30 Godfrey van der Linden(gvdl)
32 Converted to C++
33 */
34
35 #ifndef _IOKIT_IOINTERRUPTEVENTSOURCE_H
36 #define _IOKIT_IOINTERRUPTEVENTSOURCE_H
37
38 #include <IOKit/IOEventSource.h>
39
40 class IOService;
41
42 /*! @class IOInterruptEventSource : public IOEventSource
43 @abstract Event source for interrupt delivery to work-loop based drivers.
44 @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.
45 <br><br>
46 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 occured 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.
47 <br><br>
48 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.
49 <br><br>
50 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.
51 <br><br>
52 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.
53 <br><br>
54 Warning: All IOInterruptEventSources are created in the disabled state. If you want to actually schedule interrupt delivery do not forget to enable the source.
55 */
56 class IOInterruptEventSource : public IOEventSource
57 {
58 OSDeclareDefaultStructors(IOInterruptEventSource)
59
60 public:
61 /*! @typedef Action
62 @discussion 'C' pointer prototype of functions that are called in a single threaded context when an interrupt occurs.
63 @param owner Pointer to client instance.
64 @param sender Pointer to generation interrupt event source.
65 @param count Number of interrupts seen before delivery. */
66 typedef void (*Action)(OSObject *, IOInterruptEventSource *, int count);
67
68 /*! @defined IOInterruptEventAction
69 @discussion Backward compatibilty define for the old non-class scoped type definition. See $link IOInterruptEventSource::Action */
70 #define IOInterruptEventAction IOInterruptEventSource::Action
71
72 protected:
73 /*! @var provider IOService that provides interrupts for delivery. */
74 IOService *provider;
75
76 /*! @var intIndex */
77 int intIndex;
78
79 /*! @var producerCount
80 Current count of produced interrupts that have been received. */
81 volatile unsigned int producerCount;
82
83 /*! @var consumerCount
84 Current count of produced interrupts that the owner has been informed of. */
85 unsigned int consumerCount;
86
87 /*! @var autoDisable Do we need to automatically disable the interrupt source when we take an interrupt, i.e. we are level triggered. */
88 bool autoDisable;
89
90 /*! @var explicitDisable Has the user expicitly disabled this event source, if so then do not overide their request when returning from the callout */
91 bool explicitDisable;
92
93 /*! @struct ExpansionData
94 @discussion This structure will be used to expand the capablilties of the IOWorkLoop in the future.
95 */
96 struct ExpansionData { };
97
98 /*! @var reserved
99 Reserved for future use. (Internal use only) */
100 ExpansionData *reserved;
101
102 /*! @function free
103 @abstract Sub-class implementation of free method, disconnects from the interrupt source. */
104 virtual void free();
105
106 /*! @function checkForWork
107 @abstract Pure Virtual member function used by IOWorkLoop for issueing a client calls.
108 @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.
109 @result Return true if this function needs to be called again before all its outstanding events have been processed. */
110 virtual bool checkForWork();
111
112 public:
113
114 /*! @function interruptEventSource
115 @abstract Factory function for IOInterruptEventSources creation and initialisation.
116 @param owner Owning client of the new event source.
117 @param action 'C' Function to call when something happens.
118 @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.
119 @param intIndex The index of the interrupt within the provider's interrupt sources. Defaults to 0, i.e. the first interrupt in the provider.
120 @result A new interrupt event source if successfully created and initialised, 0 otherwise. */
121 static IOInterruptEventSource *
122 interruptEventSource(OSObject *owner,
123 Action action,
124 IOService *provider = 0,
125 int intIndex = 0);
126
127 /*! @function init
128 @abstract Primary initialiser for the IOInterruptEventSource class.
129 @param owner Owning client of the new event source.
130 @param action 'C' Function to call when something happens.
131 @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.
132 @param intIndex The index of the interrupt within the provider's interrupt sources. Defaults to 0, i.e. the first interrupt in the provider.
133 @result true if the inherited classes and this instance initialise
134 successfully. */
135 virtual bool init(OSObject *owner,
136 Action action,
137 IOService *provider = 0,
138 int intIndex = 0);
139
140 /*! @function enable
141 @abstract Enable event source.
142 @discussion A subclass implementation is expected to respect the enabled
143 state when checkForWork is called. Calling this function will cause the
144 work-loop to be signalled so that a checkForWork is performed. */
145 virtual void enable();
146
147 /*! @function disable
148 @abstract Disable event source.
149 @discussion A subclass implementation is expected to respect the enabled
150 state when checkForWork is called. */
151 virtual void disable();
152
153 /*! @function getProvider
154 @abstract Get'ter for $link provider variable.
155 @result value of provider. */
156 virtual const IOService *getProvider() const;
157
158 /*! @function getIntIndex
159 @abstract Get'ter for $link intIndex interrupt index variable.
160 @result value of intIndex. */
161 virtual int getIntIndex() const;
162
163 /*! @function getAutoDisable
164 @abstract Get'ter for $link autoDisable variable.
165 @result value of autoDisable. */
166 virtual bool getAutoDisable() const;
167
168 /*! @function interruptOccurred
169 @abstract Functions that get called by the interrupt controller. See $link IOService::registerInterrupt
170 @param nub Where did the interrupt originate from
171 @param ind What is this interrupts index within 'nub'. */
172 virtual void interruptOccurred(void *, IOService *nub, int ind);
173
174 /*! @function normalInterruptOccurred
175 @abstract Functions that get called by the interrupt controller.See $link IOService::registerInterrupt
176 @param nub Where did the interrupt originate from
177 @param ind What is this interrupts index within 'nub'. */
178 virtual void normalInterruptOccurred(void *, IOService *nub, int ind);
179
180 /*! @function disableInterruptOccurred
181 @abstract Functions that get called by the interrupt controller.See $link IOService::registerInterrupt
182 @param nub Where did the interrupt originate from
183 @param ind What is this interrupts index within 'nub'. */
184 virtual void disableInterruptOccurred(void *, IOService *nub, int ind);
185
186 private:
187 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 0);
188 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 1);
189 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 2);
190 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 3);
191 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 4);
192 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 5);
193 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 6);
194 OSMetaClassDeclareReservedUnused(IOInterruptEventSource, 7);
195 };
196
197 #endif /* !_IOKIT_IOINTERRUPTEVENTSOURCE_H */