1/*
2 * Copyright (c) 1998-2001 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License").  You may not use this file except in compliance with the
9 * License.  Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22#ifndef _IOKIT_IOFWASYNCSTREAMRECEIVER_H
23#define _IOKIT_IOFWASYNCSTREAMRECEIVER_H
24
25#include <IOKit/firewire/IOFireWireLink.h>
26#include <IOKit/firewire/IOFWCommand.h>
27#include <IOKit/IOBufferMemoryDescriptor.h>
28#include <IOKit/firewire/IOFWDCLProgram.h>
29
30const int kMaxAsyncStreamReceiveBuffers		= 9;
31const int kMaxAsyncStreamReceiveBufferSize	= 4096; // zzz : should determine from maxrec
32
33class IOFWAsyncStreamReceiver;
34class IOFWAsyncStreamReceivePort;
35
36/*! @class IOFWAsyncStreamReceiver
37*/
38class IOFWAsyncStreamReceiver : public OSObject
39{
40    OSDeclareDefaultStructors(IOFWAsyncStreamReceiver)
41
42friend class IOFWAsyncStreamListener;
43
44public:
45
46/*!	function initAll
47	abstract Constructs a DCL program to receive Async Stream packets.
48	param control IOFireWireController
49	param channel Channel to use.
50	result true on success, else false.	*/
51	bool initAll( IOFireWireController *control, UInt32 channel );
52
53/*!	function activate
54	abstract Activates the DCL program to start receiving Async stream
55			  packets.
56	param broadcastSpeed Ideal broadcast speed to receive.
57	result returns an IOReturn errorcode.	*/
58	IOReturn activate( IOFWSpeed broadcastSpeed );
59
60/*!	function deactivate
61	abstract Stops receiving Async stream  packets.
62	result returns an IOReturn errorcode.	*/
63	IOReturn deactivate();
64
65/*!	function getOverrunCounter
66	abstract returns Isoch ovverrun counter.
67	result returns the counter.	*/
68	inline UInt16 getOverrunCounter() { return fIsoRxOverrun; };
69
70/*!	function listens
71	abstract Checks whether DCL program is listening on this channel.
72	param channel Channel to verify.
73	result returns true on success, else false.	*/
74	inline bool listens ( UInt32 channel ) { return ( fChannel == channel ); };
75
76/*!	function receiverActive
77	abstract Verify whether receiver is active.
78	result returns true if active,else false.	*/
79	inline bool receiverActive() { return fActive; };
80
81/*!	function receiverInitialized
82	abstract Verify whether receiver is initialized.
83	result returns true if initialized,else false.	*/
84	inline bool receiverInitialized() { return fInitialized; };
85
86/*!	function addListener
87	abstract Add a new IOFWAsyncStreamListener for notifications.
88	param listener enable notifications for this listener.
89	result returns true if success,else false.	*/
90	bool addListener ( IOFWAsyncStreamListener *listener );
91
92/*!	function removeListener
93	abstract Removes a IOFWAsyncStreamListener from receiving notifications.
94	param  listener disable notifications for this listener.
95	result none.	*/
96	void removeListener ( IOFWAsyncStreamListener *listener );
97
98/*!	function restart
99	abstract Callback for restarting the DCL program.
100	result none.	*/
101    void restart( );
102
103/*!	function receiveAsyncStream
104	abstract Callback for receiving Async Stream packets.
105	result none.	*/
106	static void receiveAsyncStream( DCLCommandStruct *dclProgram );
107
108/*!	function receiveAsyncStream
109	abstract Callback for receiving Async Stream packets.
110	result return kIOReturnSuccess after processing the packet.	*/
111	static IOReturn receiveAsyncStream(void *refcon, IOFireWireMultiIsochReceivePacket *pPacket);
112
113	UInt32	getClientsCount();
114
115protected:
116	typedef struct
117	{
118		void	*obj;
119		void	*thisObj;
120		UInt8	*buffer;
121		UInt16	index;
122	} FWAsyncStreamReceiveRefCon ;
123
124	// Structure variables for each segment
125	typedef struct FWAsyncStreamReceiveSegment
126	{
127		DCLLabelPtr pSegmentLabelDCL;
128		DCLJumpPtr pSegmentJumpDCL;
129	}FWAsyncStreamReceiveSegment, *FWAsyncStreamReceiveSegmentPtr;
130
131/*! @struct ExpansionData
132    @discussion This structure will be used to expand the capablilties of the class in the future.
133    */
134    struct ExpansionData { };
135
136/*! @var reserved
137    Reserved for future use.  (Internal use only)  */
138    ExpansionData *reserved;
139
140    virtual void		free();
141
142private :
143
144	IOBufferMemoryDescriptor	*fBufDesc;
145	DCLCommandStruct			*fdclProgram;
146	IOFWAsyncStreamReceivePort	*fAsynStreamPort;
147	IOFWIsochChannel			*fAsyncStreamChan;
148    IODCLProgram 				*fIODclProgram;
149    IOFireWireController		*fControl;
150	IOFireWireLink				*fFWIM;
151
152	bool						fActive;
153    bool						fInitialized;
154	UInt32						fChannel;
155    IOFWSpeed					fSpeed;
156
157    UInt32						fSegment;
158    FWAsyncStreamReceiveSegment	*fReceiveSegmentInfoPtr;
159	DCLLabel					*fDCLOverrunLabelPtr;
160	UInt16 						fIsoRxOverrun;
161	UInt16 						fIsoRxCallbacks;
162    IORecursiveLock				*rxCommandLock;
163	OSSet						*fAsyncStreamClients;
164	OSIterator					*fAsyncStreamClientIterator;
165
166	IOFireWireMultiIsochReceiveListener *fListener;
167
168	DCLCommandStruct *CreateAsyncStreamRxDCLProgram(	DCLCallCommandProc* proc,
169														void *callbackObject);
170
171	IOFWAsyncStreamReceivePort *CreateAsyncStreamPort(	bool talking,
172														DCLCommandStruct *opcodes,
173														void *info,
174														UInt32 startEvent,
175														UInt32 startState,
176														UInt32 startMask,
177														UInt32 channel);
178
179    static void overrunNotification( DCLCommandStruct *callProc );
180
181	static IOReturn forceStopNotification( void* refCon, IOFWIsochChannel* channel, UInt32 stopCondition );
182
183	void FreeAsyncStreamRxDCLProgram( DCLCommandStruct *dclProgram );
184
185    void fixDCLJumps( bool restart );
186
187	void removeAllListeners();
188
189	void indicateListeners ( UInt8 *buffer );
190
191    IOReturn modifyDCLJumps( DCLCommandStruct *callProc );
192
193    OSMetaClassDeclareReservedUnused(IOFWAsyncStreamReceiver, 0);
194    OSMetaClassDeclareReservedUnused(IOFWAsyncStreamReceiver, 1);
195};
196
197#endif // _IOKIT_IOFWASYNCSTREAMRECEIVER_H
198
199