1/* iig(DriverKit-286) generated from IODataQueueDispatchSource.iig */
2
3/* IODataQueueDispatchSource.iig:1-37 */
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_UIODATAQUEUEDISPATCHSOURCE_H
33#define _IOKIT_UIODATAQUEUEDISPATCHSOURCE_H
34
35#include <DriverKit/IODispatchQueue.h> /* .iig include */
36#include <DriverKit/IOMemoryDescriptor.h> /* .iig include */
37
38typedef void (^IODataQueueClientEnqueueEntryBlock)(void *data, size_t dataSize);
39typedef void (^IODataQueueClientDequeueEntryBlock)(const void *data, size_t dataSize);
40
41/* source class IODataQueueDispatchSource IODataQueueDispatchSource.iig:38-236 */
42
43#if __DOCUMENTATION__
44#define KERNEL IIG_KERNEL
45
46class NATIVE KERNEL IODataQueueDispatchSource : public IODispatchSource
47{
48public:
49
50 /*!
51 * @brief Create an IODataQueueDispatchSource for a shared memory data queue.
52 * @param queueByteCount The size of the queue in bytes.
53 * @param queue IODispatchQueue the source is attached to. Note that the DataAvailable
54 * and DataServiced handlers are invoked on the queue set for the target method
55 * of the OSAction, not this queue.
56 * @param source Created source with +1 retain count to be released by the caller.
57 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
58 */
59 static kern_return_t
60 Create(
61 uint64_t queueByteCount,
62 IODispatchQueue * queue,
63 IODataQueueDispatchSource ** source);
64
65 /*!
66 * @brief Represents the size of the data queue entry header independent of the actual size of the data in the entry. This is the overhead of each entry in the queue.
67 * @param dataQueueEntryHeaderSize Out parameter for data queue entry header size
68 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
69 */
70 static size_t
71 GetDataQueueEntryHeaderSize() LOCALONLY;
72
73 virtual bool
74 init() override;
75
76 virtual void
77 free() override;
78
79 /*!
80 * @brief As a consumer, set the handler block to run when the queue becomes non-empty.
81 * @param action OSAction instance specifying the callback method. The OSAction object will be retained
82 * until SetHandler is called again or the event source is cancelled.
83 * The DataAvailable handler is invoked on the queue set for the target method of the OSAction.
84 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
85 */
86 virtual kern_return_t
87 SetDataAvailableHandler(
88 OSAction * action TYPE(DataAvailable));
89
90 /*!
91 * @brief As a producer, set the handler block to run when the queue becomes non-full, after an attempt
92 * to enqueue data failed.
93 * @param action OSAction instance specifying the callback method. The OSAction object will be retained
94 * until SetHandler is called again or the event source is cancelled.
95 * The DataServiced handler is invoked on the queue set for the target method of the OSAction.
96 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
97 */
98 virtual kern_return_t
99 SetDataServicedHandler(
100 OSAction * action TYPE(DataServiced));
101
102 /*!
103 * @brief Control the enable state of the interrupt source.
104 * @param enable Pass true to enable the source or false to disable.
105 * @param handler Optional block to be executed after the interrupt has been disabled and any pending
106 * interrupt handlers completed.
107 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
108 */
109 virtual kern_return_t
110 SetEnableWithCompletion(
111 bool enable,
112 IODispatchSourceCancelHandler handler) override LOCAL;
113
114 /*!
115 * @brief Cancel all callbacks from the event source.
116 * @discussion After cancellation, the source can only be freed. It cannot be reactivated.
117 * @param handler Handler block to be invoked after any callbacks have completed.
118 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
119 */
120 virtual kern_return_t
121 Cancel(IODispatchSourceCancelHandler handler) override LOCAL;
122
123
124 /*!
125 * @brief As a consumer, check if the data queue is non-empty.
126 * @return True if the queue is non-empty.
127 */
128 bool
129 IsDataAvailable(void) LOCALONLY;
130
131 /*!
132 * @brief As a consumer, get access to the next queue entry without dequeuing it.
133 * @param callback to invoked if the queue is non-empty with the next entry to be dequeued.
134 * @return kIOReturnSuccess if the callback was invoked.
135 * kIOReturnUnderrun if the queue was empty.
136 * kIOReturnError if the queue was corrupt.
137 */
138 kern_return_t
139 Peek(IODataQueueClientDequeueEntryBlock callback) LOCALONLY;
140
141 /*!
142 * @brief As a consumer, dequeue the next queue entry.
143 * @param callback invoked if the queue was non-empty with the entry that was dequeued.
144 * @return kIOReturnSuccess if the callback was invoked.
145 * kIOReturnUnderrun if the queue was empty.
146 * kIOReturnError if the queue was corrupt.
147 */
148 kern_return_t
149 Dequeue(IODataQueueClientDequeueEntryBlock callback) LOCALONLY;
150
151 /*!
152 * @brief As a producer, enqueue a queue entry.
153 * @param dataSize size of the data to enqueue.
154 * @param callback invoked if the queue has enough space to enqueue the data.
155 * @return kIOReturnSuccess if the callback was invoked.
156 * kIOReturnOverrun if the queue was full.
157 * kIOReturnError if the queue was corrupt.
158 */
159 kern_return_t
160 Enqueue(uint32_t dataSize, IODataQueueClientEnqueueEntryBlock callback) LOCALONLY;
161
162 /*!
163 * @brief As a consumer, dequeue the next queue entry, but don't send any DataServiced notification.
164 * @param sendDataServiced Flag that indicates a DataServiced notification would have sent.
165 * It should be initialized to false before a series of calls to this method,
166 * and if true after those calls, the notification sent with SendDataServiced().
167 * @param callback invoked if the queue was non-empty with the entry that was dequeued.
168 * @return kIOReturnSuccess if the callback was invoked.
169 * kIOReturnUnderrun if the queue was empty.
170 * kIOReturnError if the queue was corrupt.
171 */
172 kern_return_t
173 DequeueWithCoalesce(bool * sendDataServiced, IODataQueueClientDequeueEntryBlock callback) LOCALONLY;
174
175 /*!
176 * @brief As a producer, enqueue a queue entry, but don't send any DataAvailable notification.
177 * @param dataSize size of the data to enqueue
178 * @param sendDataAvailable Flag that indicates a DataAvailable notification would have been sent.
179 * It should be initialized to false before a series of calls to this method,
180 * and if true after those calls, the notification sent with SendDataAvailable().
181 * @param callback invoked if the queue has enough space to enqueue the data.
182 * @return kIOReturnSuccess if the callback was invoked.
183 * kIOReturnOverrun if the queue was full.
184 * kIOReturnError if the queue was corrupt.
185 */
186 kern_return_t
187 EnqueueWithCoalesce(uint32_t dataSize, bool * sendDataAvailable, IODataQueueClientEnqueueEntryBlock callback) LOCALONLY;
188
189 /*!
190 * @brief As a producer, check if the queue has sufficient free space for a queue entry with the specified size.
191 * @param dataSize size of the queue entry to check
192 * @return kIOReturnSuccess if the queue has enough free space
193 * kIOReturnOverrun if the queue is full
194 * kIOReturnError if the queue was corrupt
195 */
196 kern_return_t
197 CanEnqueueData(uint32_t dataSize) LOCALONLY;
198
199 /*!
200 * @brief As a producer, check if the queue has sufficient free space for queue entries with the specified size.
201 * @param dataSize size of the queue entry to check
202 * @param entryCount number of queue entries to check. Entries are assumed to be the same size.
203 * @return kIOReturnSuccess if the queue has enough free space
204 * kIOReturnOverrun if the queue is full
205 * kIOReturnError if the queue was corrupt
206 */
207 kern_return_t
208 CanEnqueueData(uint32_t dataSize, uint32_t entryCount) LOCALONLY;
209
210 /*!
211 * @brief As a consumer, send the DataServiced notification indicated by DequeueWithCoalesce.
212 */
213 void
214 SendDataServiced(void) LOCALONLY;
215
216 /*!
217 * @brief As a producer, send the DataAvailable notification indicated by EnqueueWithCoalesce.
218 */
219 void
220 SendDataAvailable(void) LOCALONLY;
221
222private:
223 virtual kern_return_t
224 CopyMemory(
225 IOMemoryDescriptor ** memory);
226
227 virtual kern_return_t
228 CopyDataAvailableHandler(
229 OSAction ** action);
230
231 virtual kern_return_t
232 CopyDataServicedHandler(
233 OSAction ** action);
234
235 virtual kern_return_t
236 CheckForWork(bool synchronous) override LOCAL;
237
238 virtual void
239 DataAvailable(
240 OSAction * action TARGET) LOCAL = 0;
241
242 virtual void
243 DataServiced(
244 OSAction * action TARGET) LOCAL = 0;
245};
246
247#undef KERNEL
248#else /* __DOCUMENTATION__ */
249
250/* generated class IODataQueueDispatchSource IODataQueueDispatchSource.iig:38-236 */
251
252#define IODataQueueDispatchSource_Create_ID 0xe8544306a54d09e0ULL
253#define IODataQueueDispatchSource_SetDataAvailableHandler_ID 0xd2c1d8cc6ec3a591ULL
254#define IODataQueueDispatchSource_SetDataServicedHandler_ID 0xd0aac29bba67b644ULL
255#define IODataQueueDispatchSource_CopyMemory_ID 0x9be617ec7d8cd728ULL
256#define IODataQueueDispatchSource_CopyDataAvailableHandler_ID 0xc856b17471f65d99ULL
257#define IODataQueueDispatchSource_CopyDataServicedHandler_ID 0xd8759c8da406b3fcULL
258#define IODataQueueDispatchSource_DataAvailable_ID 0xf799c876baf566f3ULL
259#define IODataQueueDispatchSource_DataServiced_ID 0x8daa79f78047d8d8ULL
260
261#define IODataQueueDispatchSource_Create_Args \
262 uint64_t queueByteCount, \
263 IODispatchQueue * queue, \
264 IODataQueueDispatchSource ** source
265
266#define IODataQueueDispatchSource_SetDataAvailableHandler_Args \
267 OSAction * action
268
269#define IODataQueueDispatchSource_SetDataServicedHandler_Args \
270 OSAction * action
271
272#define IODataQueueDispatchSource_SetEnableWithCompletion_Args \
273 bool enable, \
274 IODispatchSourceCancelHandler handler
275
276#define IODataQueueDispatchSource_Cancel_Args \
277 IODispatchSourceCancelHandler handler
278
279#define IODataQueueDispatchSource_CopyMemory_Args \
280 IOMemoryDescriptor ** memory
281
282#define IODataQueueDispatchSource_CopyDataAvailableHandler_Args \
283 OSAction ** action
284
285#define IODataQueueDispatchSource_CopyDataServicedHandler_Args \
286 OSAction ** action
287
288#define IODataQueueDispatchSource_CheckForWork_Args \
289 const IORPC rpc, \
290 bool synchronous
291
292#define IODataQueueDispatchSource_DataAvailable_Args \
293 OSAction * action
294
295#define IODataQueueDispatchSource_DataServiced_Args \
296 OSAction * action
297
298#define IODataQueueDispatchSource_Methods \
299\
300public:\
301\
302 virtual kern_return_t\
303 Dispatch(const IORPC rpc) APPLE_KEXT_OVERRIDE;\
304\
305 static kern_return_t\
306 _Dispatch(IODataQueueDispatchSource * self, const IORPC rpc);\
307\
308 static kern_return_t\
309 Create(\
310 uint64_t queueByteCount,\
311 IODispatchQueue * queue,\
312 IODataQueueDispatchSource ** source);\
313\
314 static size_t\
315 GetDataQueueEntryHeaderSize(\
316);\
317\
318 kern_return_t\
319 SetDataAvailableHandler(\
320 OSAction * action,\
321 OSDispatchMethod supermethod = NULL);\
322\
323 kern_return_t\
324 SetDataServicedHandler(\
325 OSAction * action,\
326 OSDispatchMethod supermethod = NULL);\
327\
328 bool\
329 IsDataAvailable(\
330);\
331\
332 kern_return_t\
333 Peek(\
334 IODataQueueClientDequeueEntryBlock callback);\
335\
336 kern_return_t\
337 Dequeue(\
338 IODataQueueClientDequeueEntryBlock callback);\
339\
340 kern_return_t\
341 Enqueue(\
342 uint32_t dataSize,\
343 IODataQueueClientEnqueueEntryBlock callback);\
344\
345 kern_return_t\
346 DequeueWithCoalesce(\
347 bool * sendDataServiced,\
348 IODataQueueClientDequeueEntryBlock callback);\
349\
350 kern_return_t\
351 EnqueueWithCoalesce(\
352 uint32_t dataSize,\
353 bool * sendDataAvailable,\
354 IODataQueueClientEnqueueEntryBlock callback);\
355\
356 kern_return_t\
357 CanEnqueueData(\
358 uint32_t dataSize);\
359\
360 kern_return_t\
361 CanEnqueueData(\
362 uint32_t dataSize,\
363 uint32_t entryCount);\
364\
365 void\
366 SendDataServiced(\
367);\
368\
369 void\
370 SendDataAvailable(\
371);\
372\
373 kern_return_t\
374 CopyMemory(\
375 IOMemoryDescriptor ** memory,\
376 OSDispatchMethod supermethod = NULL);\
377\
378 kern_return_t\
379 CopyDataAvailableHandler(\
380 OSAction ** action,\
381 OSDispatchMethod supermethod = NULL);\
382\
383 kern_return_t\
384 CopyDataServicedHandler(\
385 OSAction ** action,\
386 OSDispatchMethod supermethod = NULL);\
387\
388 void\
389 DataAvailable(\
390 OSAction * action,\
391 OSDispatchMethod supermethod = NULL);\
392\
393 void\
394 DataServiced(\
395 OSAction * action,\
396 OSDispatchMethod supermethod = NULL);\
397\
398\
399protected:\
400 /* _Impl methods */\
401\
402 kern_return_t\
403 SetEnableWithCompletion_Impl(IODispatchSource_SetEnableWithCompletion_Args);\
404\
405 kern_return_t\
406 Cancel_Impl(IODispatchSource_Cancel_Args);\
407\
408 kern_return_t\
409 CheckForWork_Impl(IODispatchSource_CheckForWork_Args);\
410\
411\
412public:\
413 /* _Invoke methods */\
414\
415 typedef kern_return_t (*Create_Handler)(IODataQueueDispatchSource_Create_Args);\
416 static kern_return_t\
417 Create_Invoke(const IORPC rpc,\
418 Create_Handler func);\
419\
420 typedef kern_return_t (*SetDataAvailableHandler_Handler)(OSMetaClassBase * target, IODataQueueDispatchSource_SetDataAvailableHandler_Args);\
421 static kern_return_t\
422 SetDataAvailableHandler_Invoke(const IORPC rpc,\
423 OSMetaClassBase * target,\
424 SetDataAvailableHandler_Handler func);\
425\
426 typedef kern_return_t (*SetDataServicedHandler_Handler)(OSMetaClassBase * target, IODataQueueDispatchSource_SetDataServicedHandler_Args);\
427 static kern_return_t\
428 SetDataServicedHandler_Invoke(const IORPC rpc,\
429 OSMetaClassBase * target,\
430 SetDataServicedHandler_Handler func);\
431\
432 typedef kern_return_t (*CopyMemory_Handler)(OSMetaClassBase * target, IODataQueueDispatchSource_CopyMemory_Args);\
433 static kern_return_t\
434 CopyMemory_Invoke(const IORPC rpc,\
435 OSMetaClassBase * target,\
436 CopyMemory_Handler func);\
437\
438 typedef kern_return_t (*CopyDataAvailableHandler_Handler)(OSMetaClassBase * target, IODataQueueDispatchSource_CopyDataAvailableHandler_Args);\
439 static kern_return_t\
440 CopyDataAvailableHandler_Invoke(const IORPC rpc,\
441 OSMetaClassBase * target,\
442 CopyDataAvailableHandler_Handler func);\
443\
444 typedef kern_return_t (*CopyDataServicedHandler_Handler)(OSMetaClassBase * target, IODataQueueDispatchSource_CopyDataServicedHandler_Args);\
445 static kern_return_t\
446 CopyDataServicedHandler_Invoke(const IORPC rpc,\
447 OSMetaClassBase * target,\
448 CopyDataServicedHandler_Handler func);\
449\
450 typedef void (*DataAvailable_Handler)(OSMetaClassBase * target, IODataQueueDispatchSource_DataAvailable_Args);\
451 static kern_return_t\
452 DataAvailable_Invoke(const IORPC rpc,\
453 OSMetaClassBase * target,\
454 DataAvailable_Handler func,\
455 const OSMetaClass * targetActionClass);\
456\
457 static kern_return_t\
458 DataAvailable_Invoke(const IORPC rpc,\
459 OSMetaClassBase * target,\
460 DataAvailable_Handler func);\
461\
462 typedef void (*DataServiced_Handler)(OSMetaClassBase * target, IODataQueueDispatchSource_DataServiced_Args);\
463 static kern_return_t\
464 DataServiced_Invoke(const IORPC rpc,\
465 OSMetaClassBase * target,\
466 DataServiced_Handler func,\
467 const OSMetaClass * targetActionClass);\
468\
469 static kern_return_t\
470 DataServiced_Invoke(const IORPC rpc,\
471 OSMetaClassBase * target,\
472 DataServiced_Handler func);\
473\
474
475
476#define IODataQueueDispatchSource_KernelMethods \
477\
478protected:\
479 /* _Impl methods */\
480\
481 static kern_return_t\
482 Create_Impl(IODataQueueDispatchSource_Create_Args);\
483\
484 kern_return_t\
485 SetDataAvailableHandler_Impl(IODataQueueDispatchSource_SetDataAvailableHandler_Args);\
486\
487 kern_return_t\
488 SetDataServicedHandler_Impl(IODataQueueDispatchSource_SetDataServicedHandler_Args);\
489\
490 kern_return_t\
491 CopyMemory_Impl(IODataQueueDispatchSource_CopyMemory_Args);\
492\
493 kern_return_t\
494 CopyDataAvailableHandler_Impl(IODataQueueDispatchSource_CopyDataAvailableHandler_Args);\
495\
496 kern_return_t\
497 CopyDataServicedHandler_Impl(IODataQueueDispatchSource_CopyDataServicedHandler_Args);\
498\
499
500
501#define IODataQueueDispatchSource_VirtualMethods \
502\
503public:\
504\
505 virtual bool\
506 init(\
507) APPLE_KEXT_OVERRIDE;\
508\
509 virtual void\
510 free(\
511) APPLE_KEXT_OVERRIDE;\
512\
513
514
515#if !KERNEL
516
517extern OSMetaClass * gIODataQueueDispatchSourceMetaClass;
518extern const OSClassLoadInformation IODataQueueDispatchSource_Class;
519
520class IODataQueueDispatchSourceMetaClass : public OSMetaClass
521{
522public:
523 virtual kern_return_t
524 New(OSObject * instance) override;
525 virtual kern_return_t
526 Dispatch(const IORPC rpc) override;
527};
528
529#endif /* !KERNEL */
530
531class IODataQueueDispatchSourceInterface : public OSInterface
532{
533public:
534};
535
536struct IODataQueueDispatchSource_IVars;
537struct IODataQueueDispatchSource_LocalIVars;
538
539class IODataQueueDispatchSource : public IODispatchSource, public IODataQueueDispatchSourceInterface
540{
541#if KERNEL
542 OSDeclareDefaultStructorsWithDispatch(IODataQueueDispatchSource);
543#endif /* KERNEL */
544
545#if !KERNEL
546 friend class IODataQueueDispatchSourceMetaClass;
547#endif /* !KERNEL */
548
549public:
550#ifdef IODataQueueDispatchSource_DECLARE_IVARS
551IODataQueueDispatchSource_DECLARE_IVARS
552#else /* IODataQueueDispatchSource_DECLARE_IVARS */
553 union
554 {
555 IODataQueueDispatchSource_IVars * ivars;
556 IODataQueueDispatchSource_LocalIVars * lvars;
557 };
558#endif /* IODataQueueDispatchSource_DECLARE_IVARS */
559#if !KERNEL
560 static OSMetaClass *
561 sGetMetaClass() { return gIODataQueueDispatchSourceMetaClass; };
562 virtual const OSMetaClass *
563 getMetaClass() const APPLE_KEXT_OVERRIDE { return gIODataQueueDispatchSourceMetaClass; };
564#endif /* KERNEL */
565
566 using super = IODispatchSource;
567
568#if !KERNEL
569 IODataQueueDispatchSource_Methods
570#endif /* !KERNEL */
571
572 IODataQueueDispatchSource_VirtualMethods
573};
574
575#endif /* !__DOCUMENTATION__ */
576
577/* IODataQueueDispatchSource.iig:238- */
578
579#endif /* ! _IOKIT_UIODATAQUEUEDISPATCHSOURCE_H */
580