1 | /* iig(DriverKit-286) generated from IOInterruptDispatchSource.iig */ |
2 | |
3 | /* IOInterruptDispatchSource.iig:1-50 */ |
4 | /* |
5 | * Copyright (c) 2019-2019 Apple Inc. All rights reserved. |
6 | * |
7 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
8 | * |
9 | * This file contains Original Code and/or Modifications of Original Code |
10 | * as defined in and that are subject to the Apple Public Source License |
11 | * Version 2.0 (the 'License'). You may not use this file except in |
12 | * compliance with the License. The rights granted to you under the License |
13 | * may not be used to create, or enable the creation or redistribution of, |
14 | * unlawful or unlicensed copies of an Apple operating system, or to |
15 | * circumvent, violate, or enable the circumvention or violation of, any |
16 | * terms of an Apple operating system software license agreement. |
17 | * |
18 | * Please obtain a copy of the License at |
19 | * http://www.opensource.apple.com/apsl/ and read it before using this file. |
20 | * |
21 | * The Original Code and all software distributed under the License are |
22 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
23 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
24 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
25 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
26 | * Please see the License for the specific language governing rights and |
27 | * limitations under the License. |
28 | * |
29 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
30 | */ |
31 | |
32 | #ifndef _IOKIT_UIOINTERRUPTDISPATCHSOURCE_H |
33 | #define _IOKIT_UIOINTERRUPTDISPATCHSOURCE_H |
34 | |
35 | #include <DriverKit/IODispatchQueue.h> /* .iig include */ |
36 | #include <DriverKit/IOService.h> /* .iig include */ |
37 | |
38 | struct IOInterruptDispatchSourcePayload { |
39 | uint64_t time; |
40 | uint64_t count; |
41 | }; |
42 | |
43 | enum { |
44 | kIOInterruptDispatchSourceTypeEdge = 0x00000000, |
45 | kIOInterruptDispatchSourceTypeLevel = 0x00000001 |
46 | }; |
47 | |
48 | enum { |
49 | kIOInterruptSourceIndexMask = 0x0000FFFF, |
50 | kIOInterruptSourceAbsoluteTime = 0x00000000, |
51 | kIOInterruptSourceContinuousTime = 0x00010000 |
52 | }; |
53 | |
54 | /* source class IOInterruptDispatchSource IOInterruptDispatchSource.iig:51-155 */ |
55 | |
56 | #if __DOCUMENTATION__ |
57 | #define KERNEL IIG_KERNEL |
58 | |
59 | /*! |
60 | * @class IOInterruptDispatchSource |
61 | * |
62 | * @abstract |
63 | * IOInterruptDispatchSource delivers interrupts to a handler block on a dispatch queue. |
64 | * |
65 | * @discussion |
66 | * A driver can run code in response to an interrupt from a device, specified as an IOService |
67 | * and index. The code runs at normal thread level, but is notified with the mach_absolute_time |
68 | * the primary interrupt fired. For IOPCIDevices, only MSI interrupt sources are supported. |
69 | */ |
70 | |
71 | class NATIVE KERNEL IOInterruptDispatchSource : public IODispatchSource |
72 | { |
73 | public: |
74 | |
75 | /*! |
76 | * @brief Create an IOInterruptDispatchSource for an interrupt by index from an IOService provider. |
77 | * @param provider The IOService object representing the HW device producing the interrupt. |
78 | * @param index Index for the interrupt, optionally or'ed with one of the following constants: |
79 | kIOInterruptSourceContinuousTime time values sent to the InterruptOccurred() method will be in mach_continuous_time() units. |
80 | * @param queue Target queue to run the handler block. |
81 | * @param source Created source with +1 retain count to be released by the caller. |
82 | * @return kIOReturnSuccess on success. See IOReturn.h for error codes. |
83 | */ |
84 | static kern_return_t |
85 | Create(IOService * provider, |
86 | uint32_t index, |
87 | IODispatchQueue * queue, |
88 | IOInterruptDispatchSource ** source) LOCAL; |
89 | |
90 | /*! |
91 | * @brief Returns the type of interrupt used for a device supplying hardware interrupts, by index from an IOService provider. |
92 | * @param provider The IOService object representing the HW device producing the interrupt. |
93 | * @param index Index for the interrupt. |
94 | * @param interruptType The interrupt type for the interrupt source will be stored here. |
95 | * kIOInterruptTypeEdge will be returned for edge-trigggered sources. |
96 | * kIOInterruptTypeLevel will be returned for level-trigggered sources. |
97 | * Other flags may be returned depending on the provider, for example PCI flags for messaged interrupts. |
98 | * @return kIOReturnSuccess on success. See IOReturn.h for error codes. |
99 | */ |
100 | |
101 | static kern_return_t |
102 | GetInterruptType(IOService * provider, |
103 | uint32_t index, |
104 | uint64_t * interruptType); |
105 | |
106 | virtual bool |
107 | init() override; |
108 | |
109 | virtual void |
110 | free() override; |
111 | |
112 | /*! |
113 | * @brief Set the handler block to run when the interupt fires. |
114 | * @param action OSAction instance specifying the callback method. The OSAction object will be retained |
115 | * until SetHandler is called again or the event source is cancelled. |
116 | * @return kIOReturnSuccess on success. See IOReturn.h for error codes. |
117 | */ |
118 | virtual kern_return_t |
119 | SetHandler( |
120 | OSAction * action TYPE(InterruptOccurred)) LOCAL; |
121 | |
122 | /*! |
123 | * @brief Control the enable state of the interrupt source. |
124 | * @param enable Pass true to enable the source or false to disable. |
125 | * @param handler Optional block to be executed after the interrupt has been disabled and any pending |
126 | * interrupt handlers completed. |
127 | * @return kIOReturnSuccess on success. See IOReturn.h for error codes. |
128 | */ |
129 | virtual kern_return_t |
130 | SetEnableWithCompletion( |
131 | bool enable, |
132 | IODispatchSourceCancelHandler handler) override LOCAL; |
133 | |
134 | /*! |
135 | * @brief Cancel all callbacks from the event source. |
136 | * @discussion After cancellation, the source can only be freed. It cannot be reactivated. |
137 | * @param handler Handler block to be invoked after any callbacks have completed. |
138 | * @return kIOReturnSuccess on success. See IOReturn.h for error codes. |
139 | */ |
140 | virtual kern_return_t |
141 | Cancel(IODispatchSourceCancelHandler handler) override LOCAL; |
142 | |
143 | /*! |
144 | * @brief Get the count and time of the last interrupt received by the kernel |
145 | primary interrupt handler. |
146 | * @param count Interrupt count. |
147 | * @param time Interrupt time. |
148 | * @return kIOReturnSuccess on success. See IOReturn.h for error codes. |
149 | */ |
150 | virtual kern_return_t |
151 | GetLastInterrupt( |
152 | uint64_t * count, |
153 | uint64_t * time); |
154 | |
155 | private: |
156 | virtual kern_return_t |
157 | CheckForWork(bool synchronous) override LOCAL; |
158 | |
159 | virtual void |
160 | InterruptOccurred( |
161 | OSAction * action TARGET, |
162 | uint64_t count, |
163 | uint64_t time) REPLY LOCAL; |
164 | }; |
165 | |
166 | #undef KERNEL |
167 | #else /* __DOCUMENTATION__ */ |
168 | |
169 | /* generated class IOInterruptDispatchSource IOInterruptDispatchSource.iig:51-155 */ |
170 | |
171 | #define IOInterruptDispatchSource_Create_ID 0xb6a948b1585fc259ULL |
172 | #define IOInterruptDispatchSource_GetInterruptType_ID 0x846d2df6b6bef33bULL |
173 | #define IOInterruptDispatchSource_SetHandler_ID 0xfcc79b0928501bb1ULL |
174 | #define IOInterruptDispatchSource_GetLastInterrupt_ID 0x9b89e0dea24a143bULL |
175 | #define IOInterruptDispatchSource_InterruptOccurred_ID 0xce0513291cfa1ee1ULL |
176 | |
177 | #define IOInterruptDispatchSource_Create_Args \ |
178 | IOService * provider, \ |
179 | uint32_t index, \ |
180 | IODispatchQueue * queue, \ |
181 | IOInterruptDispatchSource ** source |
182 | |
183 | #define IOInterruptDispatchSource_GetInterruptType_Args \ |
184 | IOService * provider, \ |
185 | uint32_t index, \ |
186 | uint64_t * interruptType |
187 | |
188 | #define IOInterruptDispatchSource_SetHandler_Args \ |
189 | OSAction * action |
190 | |
191 | #define IOInterruptDispatchSource_SetEnableWithCompletion_Args \ |
192 | bool enable, \ |
193 | IODispatchSourceCancelHandler handler |
194 | |
195 | #define IOInterruptDispatchSource_Cancel_Args \ |
196 | IODispatchSourceCancelHandler handler |
197 | |
198 | #define IOInterruptDispatchSource_GetLastInterrupt_Args \ |
199 | uint64_t * count, \ |
200 | uint64_t * time |
201 | |
202 | #define IOInterruptDispatchSource_CheckForWork_Args \ |
203 | const IORPC rpc, \ |
204 | bool synchronous |
205 | |
206 | #define IOInterruptDispatchSource_InterruptOccurred_Args \ |
207 | OSAction * action, \ |
208 | uint64_t count, \ |
209 | uint64_t time |
210 | |
211 | #define IOInterruptDispatchSource_Methods \ |
212 | \ |
213 | public:\ |
214 | \ |
215 | virtual kern_return_t\ |
216 | Dispatch(const IORPC rpc) APPLE_KEXT_OVERRIDE;\ |
217 | \ |
218 | static kern_return_t\ |
219 | _Dispatch(IOInterruptDispatchSource * self, const IORPC rpc);\ |
220 | \ |
221 | static kern_return_t\ |
222 | Create(\ |
223 | IOService * provider,\ |
224 | uint32_t index,\ |
225 | IODispatchQueue * queue,\ |
226 | IOInterruptDispatchSource ** source);\ |
227 | \ |
228 | static kern_return_t\ |
229 | GetInterruptType(\ |
230 | IOService * provider,\ |
231 | uint32_t index,\ |
232 | uint64_t * interruptType);\ |
233 | \ |
234 | kern_return_t\ |
235 | SetHandler(\ |
236 | OSAction * action,\ |
237 | OSDispatchMethod supermethod = NULL);\ |
238 | \ |
239 | kern_return_t\ |
240 | GetLastInterrupt(\ |
241 | uint64_t * count,\ |
242 | uint64_t * time,\ |
243 | OSDispatchMethod supermethod = NULL);\ |
244 | \ |
245 | kern_return_t\ |
246 | InterruptOccurred(\ |
247 | IORPC rpc,\ |
248 | OSAction * action,\ |
249 | uint64_t count,\ |
250 | uint64_t time,\ |
251 | OSDispatchMethod supermethod = NULL);\ |
252 | \ |
253 | \ |
254 | protected:\ |
255 | /* _Impl methods */\ |
256 | \ |
257 | static kern_return_t\ |
258 | Create_Call(IOInterruptDispatchSource_Create_Args);\ |
259 | \ |
260 | kern_return_t\ |
261 | SetHandler_Impl(IOInterruptDispatchSource_SetHandler_Args);\ |
262 | \ |
263 | kern_return_t\ |
264 | SetEnableWithCompletion_Impl(IODispatchSource_SetEnableWithCompletion_Args);\ |
265 | \ |
266 | kern_return_t\ |
267 | Cancel_Impl(IODispatchSource_Cancel_Args);\ |
268 | \ |
269 | kern_return_t\ |
270 | CheckForWork_Impl(IODispatchSource_CheckForWork_Args);\ |
271 | \ |
272 | void\ |
273 | InterruptOccurred_Impl(IOInterruptDispatchSource_InterruptOccurred_Args);\ |
274 | \ |
275 | \ |
276 | public:\ |
277 | /* _Invoke methods */\ |
278 | \ |
279 | typedef kern_return_t (*Create_Handler)(IOInterruptDispatchSource_Create_Args);\ |
280 | static kern_return_t\ |
281 | Create_Invoke(const IORPC rpc,\ |
282 | Create_Handler func);\ |
283 | \ |
284 | typedef kern_return_t (*GetInterruptType_Handler)(IOInterruptDispatchSource_GetInterruptType_Args);\ |
285 | static kern_return_t\ |
286 | GetInterruptType_Invoke(const IORPC rpc,\ |
287 | GetInterruptType_Handler func);\ |
288 | \ |
289 | typedef kern_return_t (*SetHandler_Handler)(OSMetaClassBase * target, IOInterruptDispatchSource_SetHandler_Args);\ |
290 | static kern_return_t\ |
291 | SetHandler_Invoke(const IORPC rpc,\ |
292 | OSMetaClassBase * target,\ |
293 | SetHandler_Handler func);\ |
294 | \ |
295 | typedef kern_return_t (*GetLastInterrupt_Handler)(OSMetaClassBase * target, IOInterruptDispatchSource_GetLastInterrupt_Args);\ |
296 | static kern_return_t\ |
297 | GetLastInterrupt_Invoke(const IORPC rpc,\ |
298 | OSMetaClassBase * target,\ |
299 | GetLastInterrupt_Handler func);\ |
300 | \ |
301 | typedef void (*InterruptOccurred_Handler)(OSMetaClassBase * target, IOInterruptDispatchSource_InterruptOccurred_Args);\ |
302 | static kern_return_t\ |
303 | InterruptOccurred_Invoke(const IORPC rpc,\ |
304 | OSMetaClassBase * target,\ |
305 | InterruptOccurred_Handler func,\ |
306 | const OSMetaClass * targetActionClass);\ |
307 | \ |
308 | static kern_return_t\ |
309 | InterruptOccurred_Invoke(const IORPC rpc,\ |
310 | OSMetaClassBase * target,\ |
311 | InterruptOccurred_Handler func);\ |
312 | \ |
313 | |
314 | |
315 | #define IOInterruptDispatchSource_KernelMethods \ |
316 | \ |
317 | protected:\ |
318 | /* _Impl methods */\ |
319 | \ |
320 | static kern_return_t\ |
321 | Create_Impl(IOInterruptDispatchSource_Create_Args);\ |
322 | \ |
323 | static kern_return_t\ |
324 | GetInterruptType_Impl(IOInterruptDispatchSource_GetInterruptType_Args);\ |
325 | \ |
326 | kern_return_t\ |
327 | GetLastInterrupt_Impl(IOInterruptDispatchSource_GetLastInterrupt_Args);\ |
328 | \ |
329 | |
330 | |
331 | #define IOInterruptDispatchSource_VirtualMethods \ |
332 | \ |
333 | public:\ |
334 | \ |
335 | virtual bool\ |
336 | init(\ |
337 | ) APPLE_KEXT_OVERRIDE;\ |
338 | \ |
339 | virtual void\ |
340 | free(\ |
341 | ) APPLE_KEXT_OVERRIDE;\ |
342 | \ |
343 | |
344 | |
345 | #if !KERNEL |
346 | |
347 | extern OSMetaClass * gIOInterruptDispatchSourceMetaClass; |
348 | extern const OSClassLoadInformation IOInterruptDispatchSource_Class; |
349 | |
350 | class IOInterruptDispatchSourceMetaClass : public OSMetaClass |
351 | { |
352 | public: |
353 | virtual kern_return_t |
354 | New(OSObject * instance) override; |
355 | virtual kern_return_t |
356 | Dispatch(const IORPC rpc) override; |
357 | }; |
358 | |
359 | #endif /* !KERNEL */ |
360 | |
361 | class IOInterruptDispatchSourceInterface : public OSInterface |
362 | { |
363 | public: |
364 | }; |
365 | |
366 | struct IOInterruptDispatchSource_IVars; |
367 | struct IOInterruptDispatchSource_LocalIVars; |
368 | |
369 | class IOInterruptDispatchSource : public IODispatchSource, public IOInterruptDispatchSourceInterface |
370 | { |
371 | #if KERNEL |
372 | OSDeclareDefaultStructorsWithDispatch(IOInterruptDispatchSource); |
373 | #endif /* KERNEL */ |
374 | |
375 | #if !KERNEL |
376 | friend class IOInterruptDispatchSourceMetaClass; |
377 | #endif /* !KERNEL */ |
378 | |
379 | public: |
380 | #ifdef IOInterruptDispatchSource_DECLARE_IVARS |
381 | IOInterruptDispatchSource_DECLARE_IVARS |
382 | #else /* IOInterruptDispatchSource_DECLARE_IVARS */ |
383 | union |
384 | { |
385 | IOInterruptDispatchSource_IVars * ivars; |
386 | IOInterruptDispatchSource_LocalIVars * lvars; |
387 | }; |
388 | #endif /* IOInterruptDispatchSource_DECLARE_IVARS */ |
389 | #if !KERNEL |
390 | static OSMetaClass * |
391 | sGetMetaClass() { return gIOInterruptDispatchSourceMetaClass; }; |
392 | virtual const OSMetaClass * |
393 | getMetaClass() const APPLE_KEXT_OVERRIDE { return gIOInterruptDispatchSourceMetaClass; }; |
394 | #endif /* KERNEL */ |
395 | |
396 | using super = IODispatchSource; |
397 | |
398 | #if !KERNEL |
399 | IOInterruptDispatchSource_Methods |
400 | #endif /* !KERNEL */ |
401 | |
402 | IOInterruptDispatchSource_VirtualMethods |
403 | }; |
404 | |
405 | #endif /* !__DOCUMENTATION__ */ |
406 | |
407 | /* IOInterruptDispatchSource.iig:157- */ |
408 | |
409 | #endif /* ! _IOKIT_UIOINTERRUPTDISPATCHSOURCE_H */ |
410 | |