1/*
2 *  IOFireWireLibNuDCL.h
3 *  IOFireWireFamily
4 *
5 *  Created by Niels on Thu Feb 27 2003.
6 *  Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
7 *
8 *	$Log: IOFireWireLibNuDCL.h,v $
9 *	Revision 1.9  2007/03/14 01:01:14  collin
10 *	*** empty log message ***
11 *
12 *	Revision 1.8  2007/01/26 20:52:32  ayanowit
13 *	changes to user-space isoch stuff to support 64-bit apps.
14 *
15 *	Revision 1.7  2006/02/09 00:21:55  niels
16 *	merge chardonnay branch to tot
17 *
18 *	Revision 1.6.20.1  2006/01/17 00:35:00  niels
19 *	<rdar://problem/4399365> FireWire NuDCL APIs need Rosetta support
20 *
21 *	Revision 1.6  2003/08/25 08:39:17  niels
22 *	*** empty log message ***
23 *
24 *	Revision 1.5  2003/08/22 18:15:17  niels
25 *	*** empty log message ***
26 *
27 *	Revision 1.4  2003/08/20 18:48:45  niels
28 *	*** empty log message ***
29 *
30 *	Revision 1.3  2003/08/14 17:47:33  niels
31 *	*** empty log message ***
32 *
33 *	Revision 1.2  2003/07/21 06:53:11  niels
34 *	merge isoch to TOT
35 *
36 *	Revision 1.1.2.4  2003/07/18 00:17:48  niels
37 *	*** empty log message ***
38 *
39 *	Revision 1.1.2.3  2003/07/11 18:15:36  niels
40 *	*** empty log message ***
41 *
42 *	Revision 1.1.2.2  2003/07/09 21:24:07  niels
43 *	*** empty log message ***
44 *
45 *	Revision 1.1.2.1  2003/07/01 20:54:24  niels
46 *	isoch merge
47 *
48 */
49
50#import "IOFireWireFamilyCommon.h"
51//#import "IOFireWireLibDevice.h"
52
53#ifndef KERNEL
54#import <CoreFoundation/CoreFoundation.h>
55#endif
56
57#ifdef KERNEL
58// this file is both user and kernel, and in user space we use CFMutableSet...
59// In the kernel, we just make this the same as a void *
60
61typedef void * CFMutableSetRef ;
62#endif
63
64namespace IOFireWireLib {
65
66	enum NuDCLType {
67		kReserved = 0,
68		kSendNuDCLType,
69		kReceiveNuDCLType,
70		kSkipCycleNuDCLType
71	} ;
72
73	class NuDCL ;
74	class NuDCLSharedData
75	{
76		public :
77
78			enum Type
79			{
80				kSendType = 'send',
81				kReceiveType = ' rcv',
82				kSkipCycleType = 'skip'
83			} ;
84
85			Type				type ;
86			union
87			{
88				NuDCL *				dcl ;
89				unsigned			index ;
90			} branch ;
91
92			NuDCLCallback		callback ;
93			union
94			{
95				UInt32 *				ptr ;
96				IOByteCount				offset ;
97			} timeStamp ;
98
99			UInt32				rangeCount ;
100			IOVirtualRange		ranges[6] ;
101
102			union
103			{
104				CFMutableSetRef		set ;		// In user space contains update set
105				UInt32				count ;		// In kernel, contains number of DCLs in update list following this DCL
106												// in export data
107			} update ;
108
109			union
110			{
111				UInt32 *			ptr ;
112				IOByteCount			offset ;
113			} status ;
114
115			void*				refcon ;
116			UInt32				flags ;
117
118			inline NuDCLSharedData( Type type ) ;
119	} ;
120
121	typedef struct NuDCLExportDataStruct
122	{
123		UInt32 type;
124		uint64_t branchIndex;
125		mach_vm_address_t callback;
126		uint64_t timeStampOffset;
127		UInt32 rangeCount;
128		IOAddressRange ranges[6];
129		uint64_t updateCount;
130		uint64_t statusOffset;
131		mach_vm_address_t refcon;
132		UInt32 flags;
133	} __attribute__ ((packed)) NuDCLExportData;
134
135	class ReceiveNuDCLSharedData
136	{
137		public :
138
139			UInt8		headerBytes ;
140			UInt8		wait ;
141
142			inline ReceiveNuDCLSharedData() : headerBytes( 0 ), wait( false ) {}
143	} ;
144
145	typedef struct ReceiveNuDCLExportDataStruct
146	{
147		UInt8		headerBytes ;
148		UInt8		wait ;
149	} __attribute__ ((packed)) ReceiveNuDCLExportData;
150
151	class SendNuDCLSharedData
152	{
153		public :
154
155			union
156			{
157				UInt32 *			ptr ;
158				IOByteCount			offset ;
159			} userHeader ;
160
161			union
162			{
163				UInt32 *			ptr ;
164				IOByteCount			offset ;
165			} userHeaderMask ;
166
167			union
168			{
169				NuDCL *				dcl ;
170				unsigned			index ;
171			} skipBranch ;
172
173			NuDCLCallback		skipCallback ;
174			void *				skipRefcon ;
175			UInt8				syncBits ;
176			UInt8				tagBits ;
177
178			inline SendNuDCLSharedData()
179			: skipCallback( 0 )
180			, syncBits( 0 )
181			, tagBits( 0 )
182			{
183				userHeader.ptr = NULL ;
184				userHeaderMask.ptr = NULL ;
185				skipBranch.dcl = NULL ;
186			}
187	} ;
188
189	typedef struct SendNuDCLExportDataStruct
190	{
191		uint64_t userHeaderOffset;
192		uint64_t userHeaderMaskOffset;
193		uint64_t skipBranchIndex;
194		mach_vm_address_t skipCallback;
195		mach_vm_address_t skipRefcon ;
196		UInt8 syncBits ;
197		UInt8 tagBits ;
198	} __attribute__ ((packed)) SendNuDCLExportData;
199
200#ifndef KERNEL
201	class CoalesceTree ;
202	class NuDCLPool ;
203
204#pragma mark -
205	class NuDCL
206	{
207		protected:
208
209			NuDCLSharedData		fData ;
210			unsigned			fExportIndex ;		// index of this DCL in export chunk + 1
211			NuDCLPool &			fPool ;
212
213		public:
214
215			NuDCL( NuDCLPool & pool, UInt32 numRanges, IOVirtualRange ranges[], NuDCLSharedData::Type type ) ;
216			virtual ~NuDCL() ;
217
218		public:
219
220			void					SetBranch ( NuDCL* branch )						{ fData.branch.dcl = branch ; }
221			NuDCL*					GetBranch () const								{ return fData.branch.dcl ; }
222			void					SetTimeStampPtr ( UInt32* timeStampPtr )		{ fData.timeStamp.ptr = timeStampPtr ; }
223			UInt32*					GetTimeStampPtr () const						{ return fData.timeStamp.ptr ; }
224			void					SetCallback ( NuDCLCallback callback )			{ fData.callback = callback ; }
225			NuDCLCallback			GetCallback () const							{ return fData.callback ; }
226			void					SetStatusPtr ( UInt32* statusPtr )				{ fData.status.ptr = statusPtr ; }
227			UInt32*					GetStatusPtr () const							{ return fData.status.ptr ; }
228			void					SetRefcon ( void* refcon )						{ fData.refcon = refcon ; }
229			void*					GetRefcon ()									{ return fData.refcon ; }
230			CFSetRef				GetUpdateList ()								{ return fData.update.set ; }
231
232			virtual IOReturn		AppendRanges ( UInt32 numRanges, IOVirtualRange ranges[] ) ;
233			virtual IOReturn		SetRanges ( UInt32 numRanges, IOVirtualRange ranges[] ) ;
234			UInt32					GetRanges ( UInt32 maxRanges, IOVirtualRange ranges[] ) const ;
235			UInt32					CountRanges () const							{ return fData.rangeCount ; }
236			virtual IOReturn		GetSpan ( IOVirtualRange& result ) const ;
237			virtual IOByteCount		GetSize () const ;
238			IOReturn				AppendUpdateList ( NuDCL* updateDCL ) ;
239			IOReturn				SetUpdateList ( CFSetRef updateList ) ;
240			void					EmptyUpdateList () ;
241			void					SetFlags( UInt32 flags )						{ fData.flags = flags ; }
242			UInt32					GetFlags() const								{ return fData.flags ; }
243
244			virtual void		 	Print ( FILE* file ) const ;
245			void					CoalesceBuffers ( CoalesceTree & tree ) const ;
246			virtual IOByteCount		Export (
247													IOVirtualAddress * 		where,
248													IOVirtualRange			bufferRanges[],
249													unsigned				bufferRangesCount ) const ;
250			unsigned				GetExportIndex() const							{ return fExportIndex ; }
251			void					SetExportIndex( unsigned index )				{ fExportIndex = index ; }
252
253		protected :
254
255			static void				S_NuDCLKernelCallout( NuDCL * dcl, UserObjectHandle kernProgramRef ) ;
256	} ;
257
258#pragma mark -
259	class ReceiveNuDCL : public NuDCL
260	{
261		private:
262
263			ReceiveNuDCLSharedData	fReceiveData ;
264
265		public:
266
267			ReceiveNuDCL( NuDCLPool & pool, UInt8 headerBytes, UInt32 numRanges, IOVirtualRange ranges[] ) ;
268
269		public:
270
271			IOReturn				SetWaitControl ( bool wait ) ;
272
273			virtual void		 	Print ( FILE* file ) const ;
274//			virtual IOByteCount		GetExportSize ( void ) const								{ return NuDCL::GetExportSize() + sizeof ( fReceiveData ) ; }
275			virtual IOByteCount		Export (
276													IOVirtualAddress * 		where,
277													IOVirtualRange			bufferRanges[],
278													unsigned				bufferRangesCount ) const ;
279	} ;
280
281#pragma mark -
282	class SendNuDCL : public NuDCL
283	{
284		private:
285
286			SendNuDCLSharedData		fSendData ;
287
288		public:
289
290			SendNuDCL( NuDCLPool & pool, UInt32 numRanges, IOVirtualRange ranges[] ) ;
291
292		public:
293
294			void					SetUserHeaderPtr ( UInt32 * userHeaderPtr, UInt32 * mask )	{ fSendData.userHeader.ptr = userHeaderPtr ; fSendData.userHeaderMask.ptr = mask ;  }
295			UInt32 *				GetUserHeaderPtr ()	const									{ return fSendData.userHeader.ptr ; }
296			UInt32 *				GetUserHeaderMask () const									{ return fSendData.userHeaderMask.ptr ; }
297
298			void					SetSkipBranch( NuDCL * skipBranchDCL )						{ fSendData.skipBranch.dcl = skipBranchDCL ; }
299			NuDCL *					GetSkipBranch() const										{ return fSendData.skipBranch.dcl ; }
300			void					SetSkipCallback( NuDCLCallback callback )					{ fSendData.skipCallback = callback ; }
301			NuDCLCallback			GetSkipCallback() const										{ return fSendData.skipCallback ; }
302			void					SetSkipRefcon( void * refcon )								{ fSendData.skipRefcon = refcon ; }
303			void *					GetSkipRefcon() const										{ return fSendData.skipRefcon ; }
304			void					SetSync( UInt8 syncBits )									{ fSendData.syncBits = syncBits ; }
305			UInt8					GetSync() const												{ return fSendData.syncBits ; }
306			void					SetTag( UInt8 tagBits )										{ fSendData.tagBits = tagBits ; }
307			UInt8					GetTag() const												{ return fSendData.tagBits ; }
308
309			virtual void		 	Print ( FILE* file ) const ;
310			virtual IOByteCount		Export (
311													IOVirtualAddress * 		where,
312													IOVirtualRange			bufferRanges[],
313													unsigned				bufferRangesCount ) const ;
314	} ;
315
316#pragma mark -
317
318	class SkipCycleNuDCL : public NuDCL
319	{
320		public:
321
322			SkipCycleNuDCL( NuDCLPool & pool ): NuDCL( pool, 0, nil, NuDCLSharedData::kSkipCycleType ) {}
323
324		public:
325
326			virtual IOReturn		AddRange ( IOVirtualRange& range )							{ return kIOReturnUnsupported ; }
327			virtual IOReturn		SetRanges ( UInt32 numRanges, IOVirtualRange ranges[] )		{ return kIOReturnUnsupported ; }
328			UInt32					GetRanges ( UInt32 maxRanges, IOVirtualRange ranges[] ) const		{ return 0 ; }
329			virtual IOReturn		GetSpan ( IOVirtualRange& result ) const					{ return kIOReturnUnsupported ; }
330			virtual IOByteCount		GetSize () const											{ return 0 ; }
331
332			virtual void		 	Print ( FILE* file ) const ;
333	} ;
334#endif
335
336	NuDCLSharedData::NuDCLSharedData( Type type )
337	: type( type )
338	, callback( NULL )
339	, rangeCount( 0 )
340	, refcon( 0 )
341	{
342		timeStamp.ptr = NULL ;
343		branch.dcl = NULL ;
344		update.set = 0 ;
345		status.ptr = NULL ;
346	}
347
348} // namespace
349
350