]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
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 | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
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. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | ||
26 | #ifndef _IOKIT_IODATAQUEUE_H | |
27 | #define _IOKIT_IODATAQUEUE_H | |
28 | ||
29 | #include <libkern/c++/OSObject.h> | |
30 | #include <libkern/OSTypes.h> | |
31 | #include <mach/port.h> | |
32 | #include <mach/message.h> | |
33 | ||
34 | typedef struct _IODataQueueMemory IODataQueueMemory; | |
35 | class IOMemoryDescriptor; | |
36 | ||
37 | struct _notifyMsg { | |
38 | mach_msg_header_t h; | |
39 | }; | |
40 | ||
41 | /*! | |
42 | * @class IODataQueue : public OSObject | |
43 | * @abstract A generic queue designed to pass data from the kernel to a user process. | |
44 | * @discussion The IODataQueue class is designed to allow kernel code to queue data to a user process. IODataQueue 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. | |
45 | * | |
46 | * <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. | |
47 | * | |
48 | * <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. | |
49 | * | |
50 | * <br>User client code exists in the IOKit framework that facilitates the creation of the receive notification port as well as the listen process for new data available notifications. | |
51 | * | |
52 | * <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. | |
53 | */ | |
54 | class IODataQueue : public OSObject | |
55 | { | |
56 | OSDeclareDefaultStructors(IODataQueue) | |
57 | ||
58 | protected: | |
59 | IODataQueueMemory * dataQueue; | |
60 | ||
61 | void * notifyMsg; | |
62 | ||
63 | virtual void free(); | |
64 | ||
65 | /*! | |
66 | * @function sendDataAvailableNotification | |
67 | * @abstract Sends a dataAvailableNotification message to the specified mach port. | |
68 | * @discussion This method sends a message to the mach port passed to setNotificationPort(). It is used to indicate that data is available in the queue. | |
69 | */ | |
70 | virtual void sendDataAvailableNotification(); | |
71 | ||
72 | public: | |
73 | /*! | |
74 | * @function withCapacity | |
75 | * @abstract Static method that creates a new IODataQueue instance with the capacity specified in the size parameter. | |
76 | * @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. | |
77 | * @param size The size of the data queue memory region. | |
78 | * @result Returns the newly allocated IODataQueue instance. Zero is returned on failure. | |
79 | */ | |
80 | static IODataQueue *withCapacity(UInt32 size); | |
81 | ||
82 | /*! | |
83 | * @function withEntries | |
84 | * @abstract Static method that creates a new IODataQueue instance with the specified number of entries of the given size. | |
85 | * @discussion This method will create a new IODataQueue 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. | |
86 | * @param numEntries Number of entries to allocate space for. | |
87 | * @param entrySize Size of each entry. | |
88 | * @result Reeturns the newly allocated IODataQueue instance. Zero is returned on failure. | |
89 | */ | |
90 | static IODataQueue *withEntries(UInt32 numEntries, UInt32 entrySize); | |
91 | ||
92 | /*! | |
93 | * @function initWithCapacity | |
94 | * @abstract Initializes an IODataQueue instance with the capacity specified in the size parameter. | |
95 | * @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>. | |
96 | * @param size The size of the data queue memory region. | |
97 | * @result Returns true on success and false on failure. | |
98 | */ | |
99 | virtual Boolean initWithCapacity(UInt32 size); | |
100 | ||
101 | /*! | |
102 | * @function initWithEntries | |
103 | * @abstract Initializes an IODataQueue instance with the specified number of entries of the given size. | |
104 | * @discussion This method will initialize an IODataQueue 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. | |
105 | * @param numEntries Number of entries to allocate space for. | |
106 | * @param entrySize Size of each entry. | |
107 | * @result Reeturns true on success and false on failure. | |
108 | */ | |
109 | virtual Boolean initWithEntries(UInt32 numEntries, UInt32 entrySize); | |
110 | ||
111 | /*! | |
112 | * @function enqueue | |
113 | * @abstract Enqueues a new entry on the queue. | |
114 | * @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. | |
115 | * @param data Pointer to the data to be added to the queue. | |
116 | * @param dataSize Size of the data pointed to by data. | |
117 | * @result Returns true on success and false on failure. Typically failure means that the queue is full. | |
118 | */ | |
119 | virtual Boolean enqueue(void *data, UInt32 dataSize); | |
120 | ||
121 | /*! | |
122 | * @function setNotificationPort | |
123 | * @abstract Creates a simple mach message targeting the mach port specified in port. | |
124 | * @discussion This message is sent when data is added to an empty queue. It is to notify a user process that new data has become available. | |
125 | * @param port The mach port to target with the notification message. | |
126 | */ | |
127 | virtual void setNotificationPort(mach_port_t port); | |
128 | ||
129 | /*! | |
130 | * @function getMemoryDescriptor | |
131 | * @abstract Returns a memory descriptor covering the IODataQueueMemory region. | |
132 | * @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. | |
133 | * @result Returns a newly allocated IOMemoryDescriptor for the IODataQueueMemory region. Returns zero on failure. | |
134 | */ | |
135 | virtual IOMemoryDescriptor *getMemoryDescriptor(); | |
136 | }; | |
137 | ||
138 | #endif /* _IOKIT_IODATAQUEUE_H */ |