Chameleon

Chameleon Svn Source Tree

Root/branches/Chimera/i386/include/IOKit/stream/IOStream.h

1/*
2 * Copyright 2006 Apple Computer, Inc. All rights reserved.
3 *
4 */
5
6#if !defined(__IOKIT_IOSTREAM_H)
7#define __IOKIT_IOSTREAM_H
8
9#include <IOKit/IOService.h>
10#include <IOKit/IOMemoryDescriptor.h>
11#include <IOKit/IOBufferMemoryDescriptor.h>
12#include <IOKit/IOUserClient.h>
13
14#include <IOKit/stream/IOStreamShared.h>
15
16/*!
17 @header IOStream.h
18 Definitions for IOStream family.
19 */
20
21class IOStreamBuffer;
22
23/*!
24 @class IOStream
25 @abstract
26 A class representing a stream of data buffers passed from kernel to
27 user space and back again.
28 @discussion
29 The IOStream class defines a mechanism for moving buffers of data from
30 kernel space to user space or vice-versa. The policy for which direction
31 the data flows and the nature of the data is left up the the implementer
32 of the driver which uses IOStream.
33
34 Although it is expected that the client of an IOStream will be in user space,
35 this is not required.
36
37 References to "output" mean "from the IOStream to the user client", and
38 "input" means "from the user client to the IOStream."
39
40 */
41
42class IOStream : public IOService
43{
44 OSDeclareDefaultStructors(IOStream);
45
46 protected:
47 OSArray * _buffers; // IOStreamBuffer objects in this stream
48
49 IOItemCount _queueCount; // Number of entries for the queues
50
51 IOMemoryDescriptor * _inputQueueDescriptor;
52 IOMemoryMap * _inputQueueMap;
53
54 IOMemoryDescriptor * _outputQueueDescriptor;
55 IOMemoryMap * _outputQueueMap;
56
57 IOStreamBufferQueue * _outputQueue; // Shared memory for buffers out to user space
58 IOStreamBufferQueue * _inputQueue; // Shared memory for buffers in from user space
59
60 mach_port_t _outputPort;
61 mach_port_t _inputPort;
62
63 OSArray * _memoryMaps; // Maps for data queues
64
65 IOStreamMode _streamMode;
66
67 public:
68
69 /*!
70 @functiongroup Creating IOStream objects
71 */
72
73 /*!
74 @function withBuffers
75 @param mode The initial mode of the stream, either output, input, or input/output.
76 @param queueLength The nuber of queue entries to reserve in the input and output queue.
77 Zero means to make the queues big enough to accommodate all the buffers at once.
78 @param properties
79 A dictionary of properties which will be set on the stream.
80 @param buffers
81 An array of IOStreamBuffer objects which will be the buffers for this stream.
82 */
83
84 static IOStream *withBuffers(OSArray *buffers, IOStreamMode mode = kIOStreamModeOutput, IOItemCount queueLength = 0, OSDictionary *properties = 0);
85
86 virtual bool init(OSDictionary *properties = 0);
87
88 /*!
89 @function initWithBuffers
90 @param mode The initial mode of the stream, either output, input, or input/output.
91 @param queueLength The nuber of queue entries to reserve in the input and output queue.
92 Zero means to make the queues big enough to accommodate all the buffers at once.
93 @param properties
94 A dictionary of properties which will be set on the stream.
95 @param buffers
96 An array of IOStreamBuffer objects which will be the buffers for this stream.
97 */
98 virtual bool initWithBuffers(OSArray *buffers, IOStreamMode mode = kIOStreamModeOutput, IOItemCount queueLength = 0, OSDictionary *properties = 0);
99
100 /*!
101 @function free
102 */
103 virtual void free(void);
104
105 /*!
106 @functiongroup Opening and closing streams
107 */
108
109 /*!
110 @function handleOpen
111 @abstract The handleOpen() method relies on the default IOService behavior
112 to ensure that
113 only one client has the stream open at a time.
114 The shared input and output queues are created at open time.
115 @param options
116 @param arg
117 */
118 virtual bool handleOpen( IOService * forClient,
119 IOOptionBits options,
120 void * arg );
121
122 /*!
123 @function handleClose
124 @abstract The handleClose method destroys the shared input and output
125 queues.
126 @param options
127 */
128 virtual void handleClose( IOService * forClient,
129 IOOptionBits options );
130
131 /*!
132 @functiongroup Managing shared queues
133 */
134
135 /*!
136 @function createQueues
137 @abstract Creates the shared input and output queues, without regard
138 to whether the stream is open or not.
139 Normally this is called by handleOpen().
140 @param queueLength
141 @param options
142 @result Returns kIOReturnSuccess if the queues were successfully created.
143 */
144 virtual IOReturn createQueues( IOItemCount queueLength = 0, IOOptionBits options = 0 );
145
146 /*!
147 @function destroyQueues
148 @abstract Releases the shared input and output queues.
149 @result Returns kIOReturnSuccess if the queues were successfully destroyed.
150 The queues cannot be destroyed while the stream is open by a client.
151 */
152 virtual IOReturn destroyQueues( void );
153
154 /*!
155 @function getOutputQueue
156 @result A pointer to the output IOStreamBufferQueue structure for the stream,
157 or NULL if the stream is not open and the queue has not been created yet.
158 */
159 virtual IOStreamBufferQueue *getOutputQueue(void); // get shared-memory output queue
160
161 /*!
162 @function getOutputQueueMemoryDescriptor
163 @result An IOMemoryDescriptor object repesenting the shared memory
164 output queue buffer.
165 */
166 virtual IOMemoryDescriptor *getOutputQueueMemoryDescriptor(void);
167
168 /*!
169 @function getInputQueue
170 @result A pointer to the input IOStreamBufferQueue structure for the stream,
171 or NULL if the stream is not open and the queue has not been created yet.
172 */
173 virtual IOStreamBufferQueue *getInputQueue(void); // get shared-memory input queue
174
175 /*!
176 @function getInputQueueMemoryDescriptor
177 @result An IOMemoryDescriptor object repesenting the shared memory
178 input queue buffer.
179 */
180 virtual IOMemoryDescriptor *getInputQueueMemoryDescriptor(void);
181
182
183 /*!
184 @functiongroup Managing buffers in an IOStream
185 */
186
187 /*!
188 @function addBuffer
189 @abstract Add a buffer to an IOStream.
190 @param buffer
191 @discussion
192 Adds an IOStreamBuffer to an IOStream. It will be added to the end
193 of the buffer array, so the buffer ID of existing buffers will not change.
194 */
195 virtual IOReturn addBuffer(IOStreamBuffer *buffer); // add a new buffer to the stream
196
197 /*!
198 @function addBuffers
199 @param buffers
200 @result
201 */
202 virtual IOReturn addBuffers(OSArray *buffers);
203
204 /*!
205 @function removeBuffer
206 @param buffer A pointer to an IOStreamBuffer object in the stream.
207 @result Returns kIOReturnSuccess if the buffer was removed, or kIOReturnNotFound
208 if the buffer was not in this stream.
209 @abstract
210 Removes a buffer from the stream. Buffers cannot be removed
211 while the stream is open, as this will change the buffer IDs of existing
212 buffers.
213 */
214 virtual IOReturn removeBuffer(IOStreamBuffer *buffer);
215
216 /*!
217 @function removeBuffer
218 @param bufferID The ID of the buffer to remove.
219 @result Returns kIOReturnSuccess if the buffer was removed.
220 @abstract
221 Removes a buffer from the stream. Buffers cannot be removed
222 while the stream is open, as this will change the buffer IDs of existing
223 buffers.
224 */
225
226 virtual IOReturn removeBuffer(IOStreamBufferID bufferID);
227
228 /*!
229 @function removeAllBuffers
230 @result
231 */
232 virtual IOReturn removeAllBuffers( void );
233
234 /*!
235 @function removeAllBuffers
236 @result Returns kIOReturnSuccess if all the buffers were successfully
237 removed. Buffers cannot be removed
238 while the stream is open, as this will change the buffer IDs of existing
239 buffers.
240
241 */
242 virtual IOItemCount getBufferCount( void );
243
244 /*!
245 @function getBuffers
246 @abstract Get an array containing all the buffers in the stream.
247 @discussion
248 Returns an OSArray containing all the buffers in the stream in order of their buffer ID.
249 */
250 virtual OSArray *getBuffers( void );
251
252
253 /*!
254 @function getBufferWithID
255 @param bufferID
256 The ID of the buffer to get.
257 @result
258 A pointer to an IOStreamBuffer object, or NULL if the
259 buffer ID was invalid for this stream.
260 */
261
262 virtual IOStreamBuffer *getBufferWithID(IOStreamBufferID bufferID);
263
264 /*!
265 @functiongroup Managing notification ports
266 */
267
268 /*!
269 @function getInputPort
270 @abstract Get the Mach port used to receive notifications
271 from user space that a buffer has been added to the input queue.
272 */
273 virtual mach_port_t getInputPort(void);
274
275 /*!
276 @function setInputPort
277 @abstract Set the Mach port used to receive notifications from
278 user space that a buffer has been added to the input queue.
279 @param port
280
281 */
282 virtual IOReturn setInputPort(mach_port_t port);
283
284 /*!
285 @function getOutputPort
286 @abstract Get the Mach port used to send notifications to user space
287 that a buffer has been added to the output queue.
288 */
289 virtual mach_port_t getOutputPort(void);
290
291 /*!
292 @function setOutputPort
293 @abstract Set the Mach port used to send notifications to user space
294 that a buffer has been added to the output queue.
295 @param port
296 */
297 virtual IOReturn setOutputPort(mach_port_t port);
298
299 /*!
300 @function sendOutputNotification
301 @abstract Send a notification to the user client that data is available
302 for reading on the output queue. This will result in the user's output
303 handler being called, if they registered one.
304 @result Returns kIOReturnSuccess if the notification was successfully sent.
305 */
306 virtual IOReturn sendOutputNotification(void);
307
308 /*!
309 @functiongroup Queueing and dequeueing buffers
310 */
311
312 /*!
313 @function enqueueOutputBuffer
314 @abstract A convenience method for enqueueing a buffer.
315 @param buffer
316 @param dataOffset
317 @param dataLength
318 @param controlOffset
319 @param controlLength
320 @result
321 */
322 virtual IOReturn enqueueOutputBuffer(IOStreamBuffer *buffer,
323 IOByteCount dataOffset = 0,
324 IOByteCount dataLength = 0,
325 IOByteCount controlOffset = 0,
326 IOByteCount controlLength = 0);
327
328
329 /*!
330 @function enqueueOutputEntry
331 @param entry
332 @result
333 */
334 virtual IOReturn enqueueOutputEntry( IOStreamBufferQueueEntry *entry );
335
336 /*!
337 @function dequeueInputEntry
338 @param entry
339 @result
340 */
341 virtual IOReturn dequeueInputEntry( IOStreamBufferQueueEntry *entry );
342
343 /*!
344 @functiongroup Managing notifications
345 */
346
347 /*!
348 @function inputCallback
349 @abstract Input callback function to be implemented by a subclass;
350 @param token
351 A 32-bit token value that can be used by convention to communicate
352 from user space to the stream. The semantics of this value are
353 defined by the IOStream subclass.
354 @discussion
355 The inputCallback() method is called as a result of a fast trap
356 from user space. It is called on the same thread as the user request,
357 but the subclass should implement this call as a notification sent
358 to a workloop so that the request is asynchronous.
359 */
360 virtual void inputCallback( UInt32 token );
361
362 /*!
363 @function inputSyncCallback
364 @abstract Input callback function to be implemented by a subclass.
365 @param token
366 A 32-bit token value that can be used by convention to communicate
367 from user space to the stream. The semantics of this value are
368 defined by the IOStream subclass.
369 @discussion
370 The inputSyncCallback() method is called as a result of a fast trap
371 from user space. It is called on the same thread as the user request,
372 so no context switch is necessary.
373 */
374 virtual void inputSyncCallback( UInt32 token );
375
376 /*!
377 @functiongroup Stream control
378 */
379
380 /*!
381 @function getStreamMode
382 @abstract Returns the mode of the stream, either input or output.
383 @result The mode of the stream, either kIOStreamModeInput
384 (from user space to kernel space) or the default
385 kIOStreamModeOutput (from kernel space to user space).
386 */
387 virtual IOStreamMode getStreamMode(void);
388
389 /*!
390 @function setStreamMode
391 @abstract Sets the mode of the stream, either input or output.
392 @discussion Subclasses may define whether it is possible
393 to change the mode of a stream.
394 */
395 virtual IOReturn setStreamMode(IOStreamMode mode);
396
397 /*!
398 @function startStream
399 @abstract Start sending data on a stream.
400 @result Returns kIOReturnSuccess if the stream was successfully started.
401 @discussion This must be implemented by a subclass.
402 */
403 virtual IOReturn startStream(void);
404
405 /*!
406 @function stopStream
407 @abstract Stop sending data on a stream.
408 @result Returns kIOReturnSuccess if the stream was successfully stopped.
409 @discussion This must be implemented by a subclass.
410 */
411 virtual IOReturn stopStream(void);
412
413 /*!
414 @function suspendStream
415 @abstract Temporarily suspend data flow on the stream.
416 @result Returns kIOReturnSuccess if the stream was successfully suspended.
417 @discussion This must be implemented by a subclass.
418 */
419 virtual IOReturn suspendStream(void);
420
421 /*!
422 @functiongroup Managing user clients
423 */
424
425 /*!
426 @function newUserClient
427 @abstract See the documentation for the IOService method newUserClient.
428 */
429 virtual IOReturn newUserClient( task_t owningTask, void * securityID,
430 UInt32 type, OSDictionary * properties,
431 IOUserClient ** handler );
432
433
434 /* Reserved slots */
435
436 OSMetaClassDeclareReservedUnused(IOStream, 0);
437 OSMetaClassDeclareReservedUnused(IOStream, 1);
438 OSMetaClassDeclareReservedUnused(IOStream, 2);
439 OSMetaClassDeclareReservedUnused(IOStream, 3);
440 OSMetaClassDeclareReservedUnused(IOStream, 4);
441 OSMetaClassDeclareReservedUnused(IOStream, 5);
442 OSMetaClassDeclareReservedUnused(IOStream, 6);
443 OSMetaClassDeclareReservedUnused(IOStream, 7);
444 OSMetaClassDeclareReservedUnused(IOStream, 8);
445 OSMetaClassDeclareReservedUnused(IOStream, 9);
446 OSMetaClassDeclareReservedUnused(IOStream, 10);
447 OSMetaClassDeclareReservedUnused(IOStream, 11);
448 OSMetaClassDeclareReservedUnused(IOStream, 12);
449 OSMetaClassDeclareReservedUnused(IOStream, 13);
450 OSMetaClassDeclareReservedUnused(IOStream, 14);
451 OSMetaClassDeclareReservedUnused(IOStream, 15);
452 OSMetaClassDeclareReservedUnused(IOStream, 16);
453 OSMetaClassDeclareReservedUnused(IOStream, 17);
454 OSMetaClassDeclareReservedUnused(IOStream, 18);
455 OSMetaClassDeclareReservedUnused(IOStream, 19);
456 OSMetaClassDeclareReservedUnused(IOStream, 20);
457 OSMetaClassDeclareReservedUnused(IOStream, 21);
458 OSMetaClassDeclareReservedUnused(IOStream, 22);
459 OSMetaClassDeclareReservedUnused(IOStream, 23);
460 OSMetaClassDeclareReservedUnused(IOStream, 24);
461 OSMetaClassDeclareReservedUnused(IOStream, 25);
462 OSMetaClassDeclareReservedUnused(IOStream, 26);
463 OSMetaClassDeclareReservedUnused(IOStream, 27);
464 OSMetaClassDeclareReservedUnused(IOStream, 28);
465 OSMetaClassDeclareReservedUnused(IOStream, 29);
466 OSMetaClassDeclareReservedUnused(IOStream, 30);
467 OSMetaClassDeclareReservedUnused(IOStream, 31);
468
469};
470
471
472/*!
473 @class IOStreamBuffer
474 A class representing a data buffer that is part of an IOStream.
475 */
476
477class IOStreamBuffer : public OSObject
478{
479 OSDeclareDefaultStructors(IOStreamBuffer);
480
481protected:
482 IOMemoryDescriptor * _dataBuffer; // The data buffer is expected to be filled by hardware.
483 IOMemoryDescriptor * _controlBuffer; // The control buffer is expected to be defined by the hardware driver.
484
485 IOStreamBufferID _bufferID; // Client handle for this buffer.
486
487 OSArray * _clientMemoryMaps; // Maps for clients who are sharing these buffers.
488
489 SInt32 _clientReferenceCount; // Count of client uses of this buffer. May be negative.
490
491public:
492 /*!
493 @function initWithMemoryDescriptors
494 */
495 virtual bool initWithMemoryDescriptors(IOMemoryDescriptor *dataBuffer,
496 IOMemoryDescriptor *controlBuffer,
497 IOStreamBufferID bufferID = 0);
498
499 /*!
500 @function withMemoryDescriptors
501 */
502 static IOStreamBuffer *withMemoryDescriptors(IOMemoryDescriptor *dataBuffer,
503 IOMemoryDescriptor *controlBuffer,
504 IOStreamBufferID bufferID = 0);
505
506 virtual void free(void);
507
508 /*!
509 @function getBufferID
510 @abstract Gets the buffer identifier for the IOStreamBuffer object.
511 @discussion The buffer identifier is unique across all buffers in a stream.
512 */
513 virtual IOStreamBufferID getBufferID(void);
514
515 /*!
516 @function setBufferID
517 @abstract Sets the buffer identifier for the IOStreamBuffer object.
518 */
519
520 virtual void setBufferID( IOStreamBufferID bufferID );
521
522 /*!
523 @function setDataBuffer
524 @abstract Sets the data buffer for the IOStreamBuffer object.
525 */
526 virtual void setDataBuffer(IOMemoryDescriptor *dataBuffer);
527
528 /*!
529 @function setControlBuffer
530 @abstract Sets the control buffer for the IOStreamBuffer object.
531 */
532 virtual void setControlBuffer(IOMemoryDescriptor *controlBuffer);
533
534 /*!
535 @function getDataBuffer
536 @result A pointer to the IOMemoryDescriptor for the data buffer.
537 */
538 virtual IOMemoryDescriptor *getDataBuffer(void);
539
540 /*!
541 @function getControlBuffer
542 @result A pointer to the IOMemoryDescriptor for the control buffer.
543 */
544 virtual IOMemoryDescriptor *getControlBuffer(void);
545
546 /*!
547 @function getClientReferenceCount
548 @result The count of client references to this buffer. It may be positive
549 or negative, depending on whether the client is sending data into the kernel,
550 or the kernel is sending data out to the client.
551 */
552 virtual SInt32 getClientReferenceCount( void );
553
554 /*!
555 @function sendClientReference
556 @param offset The offset in the buffer of the data sent to the client.
557 @param length The length of the data sent to the client.
558 @result The new client reference count.
559 @abstract
560 */
561 virtual SInt32 sendClientReference( IOByteCount offset = 0, IOByteCount length = 0 );
562
563 /*!
564 @function receiveClientReference
565 @param offset The offset in the buffer of the data from the client.
566 @param length The length of the data from the client.
567 @abstract
568 */
569 virtual SInt32 receiveClientReference( IOByteCount offset = 0, IOByteCount length = 0 );
570
571 /* Reserved slots */
572
573 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 0);
574 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 1);
575 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 2);
576 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 3);
577 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 4);
578 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 5);
579 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 6);
580 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 7);
581 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 8);
582 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 9);
583 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 10);
584 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 11);
585 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 12);
586 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 13);
587 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 14);
588 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 15);
589 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 16);
590 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 17);
591 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 18);
592 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 19);
593 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 20);
594 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 21);
595 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 22);
596 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 23);
597 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 24);
598 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 25);
599 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 26);
600 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 27);
601 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 28);
602 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 29);
603 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 30);
604 OSMetaClassDeclareReservedUnused(IOStreamBuffer, 31);
605
606};
607
608#endif /* ! __IOKIT_IOSTREAM_H */
609
610

Archive Download this file

Revision: 1340