]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOSharedDataQueue.h
xnu-3789.51.2.tar.gz
[apple/xnu.git] / iokit / IOKit / IOSharedDataQueue.h
CommitLineData
2d21ac55
A
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#ifndef _IOKIT_IOSHAREDDATAQUEUE_H
30#define _IOKIT_IOSHAREDDATAQUEUE_H
31
32#ifdef dequeue
33#undef dequeue
34#endif
35
fe8ab488
A
36#define DISABLE_DATAQUEUE_WARNING /* IODataQueue is deprecated, please use IOSharedDataQueue instead */
37
2d21ac55
A
38#include <IOKit/IODataQueue.h>
39
fe8ab488
A
40#undef DISABLE_DATAQUEUE_WARNING
41
2d21ac55
A
42typedef struct _IODataQueueEntry IODataQueueEntry;
43
44/*!
45 * @class IOSharedDataQueue : public IODataQueue
46 * @abstract A generic queue designed to pass data both from the kernel to a user process and from a user process to the kernel.
47 * @discussion The IOSharedDataQueue class is designed to also allow a user process to queue data to kernel code. IOSharedDataQueue objects are designed to be used in a single producer / single consumer situation. As such, there are no locks on the data itself. Because the kernel enqueue and user-space dequeue methods follow a strict set of guidelines, no locks are necessary to maintain the integrity of the data struct.
48 *
49 * <br>Each data entry can be variable sized, but the entire size of the queue data region (including overhead for each entry) must be specified up front.
50 *
51 * <br>In order for the IODataQueue instance to notify the user process that data is available, a notification mach port must be set. When the queue is empty and a new entry is added, a message is sent to the specified port.
52 *
53 * <br>In order to make the data queue memory available to a user process, the method getMemoryDescriptor() must be used to get an IOMemoryDescriptor instance that can be mapped into a user process. Typically, the clientMemoryForType() method on an IOUserClient instance will be used to request the IOMemoryDescriptor and then return it to be mapped into the user process.
54 */
55class IOSharedDataQueue : public IODataQueue
56{
57 OSDeclareDefaultStructors(IOSharedDataQueue)
58
59 struct ExpansionData {
143464d5 60 UInt32 queueSize;
2d21ac55
A
61 };
62 /*! @var reserved
63 Reserved for future use. (Internal use only) */
64 ExpansionData * _reserved;
65
66protected:
3e170ce0 67 virtual void free() APPLE_KEXT_OVERRIDE;
2d21ac55 68
fe8ab488
A
69 /*!
70 * @function getQueueSize
71 * @abstract Returns the size of the data queue.
72 * @discussion Use this method to access the size of the data queue. Do not access the value of size directly, as it can get modified from userspace and is not reliable.
73 * @result Returns the size of the data queue, or zero in case of failure.
74 */
143464d5 75 UInt32 getQueueSize();
fe8ab488
A
76
77 /*!
78 * @function setQueueSize
79 * @abstract Stores the value of the size of the data queue.
80 * @discussion Use this method to store the value of the size of the data queue. Do not access the value of size directly, as it can get modified from userspace and is not reliable.
81 * @param size The size of the data queue.
82 * @result Returns true in case of success, false otherwise.
83 */
143464d5
A
84 Boolean setQueueSize(UInt32 size);
85
2d21ac55
A
86public:
87 /*!
88 * @function withCapacity
89 * @abstract Static method that creates a new IOSharedDataQueue instance with the capacity specified in the size parameter.
90 * @discussion The actual size of the entire data queue memory region (to be shared into a user process) is equal to the capacity plus the IODataQueueMemory overhead. This overhead value can be determined from the DATA_QUEUE_MEMORY_HEADER_SIZE macro in <IOKit/IODataQueueShared.h>. The size of the data queue memory region must include space for the overhead of each IODataQueueEntry. This entry overhead can be determined from the DATA_QUEUE_ENTRY_HEADER_SIZE macro in <IOKit/IODataQueueShared.h>.<br> This method allocates a new IODataQueue instance and then calls initWithCapacity() with the given size parameter. If the initWithCapacity() fails, the new instance is released and zero is returned.
91 * @param size The size of the data queue memory region.
92 * @result Returns the newly allocated IOSharedDataQueue instance. Zero is returned on failure.
93 */
94 static IOSharedDataQueue *withCapacity(UInt32 size);
95
96 /*!
97 * @function withEntries
98 * @abstract Static method that creates a new IOSharedDataQueue instance with the specified number of entries of the given size.
99 * @discussion This method will create a new IOSharedDataQueue instance with enough capacity for numEntries of entrySize. It does account for the IODataQueueEntry overhead for each entry. Note that the numEntries and entrySize are simply used to determine the data region size. They do not actually restrict the size of number of entries that can be added to the queue.<br> This method allocates a new IODataQueue instance and then calls initWithEntries() with the given numEntries and entrySize parameters. If the initWithEntries() fails, the new instance is released and zero is returned.
100 * @param numEntries Number of entries to allocate space for.
101 * @param entrySize Size of each entry.
102 * @result Reeturns the newly allocated IOSharedDataQueue instance. Zero is returned on failure.
103 */
104 static IOSharedDataQueue *withEntries(UInt32 numEntries, UInt32 entrySize);
105
106 /*!
107 * @function initWithCapacity
108 * @abstract Initializes an IOSharedDataQueue instance with the capacity specified in the size parameter.
109 * @discussion The actual size of the entire data queue memory region (to be shared into a user process) is equal to the capacity plus the IODataQueueMemory overhead. This overhead value can be determined from the DATA_QUEUE_MEMORY_HEADER_SIZE and DATA_QUEUE_MEMORY_APPENDIX_SIZE macro in <IOKit/IODataQueueShared.h>. The size of the data queue memory region must include space for the overhead of each IODataQueueEntry. This entry overhead can be determined from the DATA_QUEUE_ENTRY_HEADER_SIZE macro in <IOKit/IODataQueueShared.h>.
110 * @param size The size of the data queue memory region.
111 * @result Returns true on success and false on failure.
112 */
3e170ce0 113 virtual Boolean initWithCapacity(UInt32 size) APPLE_KEXT_OVERRIDE;
2d21ac55
A
114
115 /*!
116 * @function getMemoryDescriptor
117 * @abstract Returns a memory descriptor covering the IODataQueueMemory region.
118 * @discussion The IOMemoryDescriptor instance returned by this method is intended to be mapped into a user process. This is the memory region that the IODataQueueClient code operates on.
119 * @result Returns a newly allocated IOMemoryDescriptor for the IODataQueueMemory region. Returns zero on failure.
120 */
3e170ce0 121 virtual IOMemoryDescriptor *getMemoryDescriptor() APPLE_KEXT_OVERRIDE;
2d21ac55
A
122
123 /*!
124 * @function peek
125 * @abstract Used to peek at the next entry on the queue.
126 * @discussion This function can be used to look at the next entry which allows the entry to be received without having to copy it with dequeue. In order to do this, call peek to get the entry. Then call dequeue with a NULL data pointer. That will cause the head to be moved to the next entry, but no memory to be copied.
127 * @result Returns a pointer to the next IODataQueueEntry if one is available. 0 (NULL) is returned if the queue is empty.
128 */
129 virtual IODataQueueEntry * peek();
130
131 /*!
132 * @function dequeue
133 * @abstract Dequeues the next available entry on the queue and copies it into the given data pointer.
134 * @discussion This function will dequeue the next available entry on the queue. If a data pointer is provided, it will copy the data into the memory region if there is enough space available as specified in the dataSize parameter. If no data pointer is provided, it will simply move the head value past the current entry.
135 * @param data A pointer to the data memory region in which to copy the next entry data on the queue. If this parameter is 0 (NULL), it will simply move to the next entry.
136 * @param dataSize A pointer to the size of the data parameter. On return, this contains the size of the actual entry data - even if the original size was not large enough.
137 * @result Returns true on success and false on failure. Typically failure means that the queue is empty.
138 */
139 virtual Boolean dequeue(void *data, UInt32 *dataSize);
140
143464d5
A
141 /*!
142 * @function enqueue
143 * @abstract Enqueues a new entry on the queue.
144 * @discussion This method adds a new data entry of dataSize to the queue. It sets the size parameter of the entry pointed to by the tail value and copies the memory pointed to by the data parameter in place in the queue. Once that is done, it moves the tail to the next available location. When attempting to add a new entry towards the end of the queue and there isn't enough space at the end, it wraps back to the beginning.<br> If the queue is empty when a new entry is added, sendDataAvailableNotification() is called to send a message to the user process that data is now available.
145 * @param data Pointer to the data to be added to the queue.
146 * @param dataSize Size of the data pointed to by data.
147 * @result Returns true on success and false on failure. Typically failure means that the queue is full.
148 */
3e170ce0 149 virtual Boolean enqueue(void *data, UInt32 dataSize) APPLE_KEXT_OVERRIDE;
143464d5 150
2d21ac55
A
151 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 0);
152 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 1);
153 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 2);
154 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 3);
155 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 4);
156 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 5);
157 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 6);
158 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 7);
159};
160
161#endif /* _IOKIT_IOSHAREDDATAQUEUE_H */