1/* 2 * Copyright (c) 1998-2002 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/* 23 * IOFireWireLibIsochPort.h 24 * IOFireWireFamily 25 * 26 * Created on Mon Mar 12 2001. 27 * Copyright (c) 2001-2002 Apple Computer, Inc. All rights reserved. 28 * 29 */ 30 31#import "IOFireWireLibIUnknown.h" 32#import "IOFireWireLibPriv.h" 33 34#import <IOKit/firewire/IOFireWireLibIsoch.h> 35 36#import <pthread.h> 37 38namespace IOFireWireLib { 39 40 class IsochChannel ; 41 class Device ; 42 class CoalesceTree ; 43 44#pragma mark - 45 class IsochPort: public IOFireWireIUnknown 46 { 47 friend class IsochChannel ; 48 49 public: 50 51 IsochPort( const IUnknownVTbl & interface, Device & userclient, 52 bool talking, bool allocateKernPort ) ; 53 virtual ~IsochPort() ; 54 55 public: 56 57 // --- methods from kernel isoch port ---------- 58 virtual IOReturn GetSupported( IOFWSpeed & maxSpeed, UInt64 & chanSupported ) ; 59 virtual IOReturn AllocatePort( IOFWSpeed speed, UInt32 chan ) ; 60 virtual IOReturn ReleasePort() ; 61 virtual IOReturn Start() ; 62 virtual IOReturn Stop() ; 63 64 void SetRefCon( void * refCon ) { mRefCon = refCon ; } 65 void* GetRefCon() const { return mRefCon ; } 66 Boolean GetTalking() const { return mTalking ; } 67 68 protected: 69 UserObjectHandle GetKernPortRef() { return mKernPortRef; } 70 71 protected: 72 73 Device & mDevice ; 74 UserObjectHandle mKernPortRef ; 75 void * mRefCon ; 76 Boolean mTalking ; 77 78 79 } ; 80 81#pragma mark - 82 class IsochPortCOM: public IsochPort 83 { 84 public: 85 86 IsochPortCOM( const IUnknownVTbl & interface, Device& inUserClient, bool talking, bool allocateKernPort = true ) ; 87 virtual ~IsochPortCOM() ; 88 89 public: 90 91 // --- static methods ------------------ 92 static IOReturn SGetSupported( 93 IOFireWireLibIsochPortRef self, 94 IOFWSpeed* maxSpeed, 95 UInt64* chanSupported ) ; 96 static IOReturn SAllocatePort( 97 IOFireWireLibIsochPortRef self, 98 IOFWSpeed speed, 99 UInt32 chan ) ; 100 static IOReturn SReleasePort( 101 IOFireWireLibIsochPortRef self) ; 102 static IOReturn SStart( 103 IOFireWireLibIsochPortRef self) ; 104 static IOReturn SStop( 105 IOFireWireLibIsochPortRef self) ; 106 static void SSetRefCon( 107 IOFireWireLibIsochPortRef self, 108 void* inRefCon) ; 109 static void* SGetRefCon( 110 IOFireWireLibIsochPortRef self) ; 111 static Boolean SGetTalking( 112 IOFireWireLibIsochPortRef self) ; 113 } ; 114 115#pragma mark - 116 class RemoteIsochPort: public IsochPortCOM 117 { 118 protected: 119 typedef ::IOFireWireRemoteIsochPortInterface Interface ; 120 typedef ::IOFireWireLibRemoteIsochPortRef PortRef ; 121 122 public: 123 124 RemoteIsochPort( const IUnknownVTbl & interface, Device& userclient, bool talking ) ; 125 virtual ~RemoteIsochPort() {} 126 127 // --- methods from kernel isoch port ---------- 128 virtual IOReturn GetSupported( 129 IOFWSpeed& maxSpeed, 130 UInt64& chanSupported) ; 131 virtual IOReturn AllocatePort( 132 IOFWSpeed speed, 133 UInt32 chan ) ; 134 virtual IOReturn ReleasePort() ; 135 virtual IOReturn Start() ; 136 virtual IOReturn Stop() ; 137 138 IOFireWireLibIsochPortGetSupportedCallback 139 SetGetSupportedHandler( 140 IOFireWireLibIsochPortGetSupportedCallback inHandler) ; 141 IOFireWireLibIsochPortAllocateCallback 142 SetAllocatePortHandler( 143 IOFireWireLibIsochPortAllocateCallback inHandler) ; 144 IOFireWireLibIsochPortCallback 145 SetReleasePortHandler( 146 IOFireWireLibIsochPortCallback inHandler) ; 147 IOFireWireLibIsochPortCallback 148 SetStartHandler( 149 IOFireWireLibIsochPortCallback inHandler) ; 150 IOFireWireLibIsochPortCallback 151 SetStopHandler( 152 IOFireWireLibIsochPortCallback inHandler) ; 153 154 protected: 155 IOFireWireLibIsochPortGetSupportedCallback mGetSupportedHandler ; 156 IOFireWireLibIsochPortAllocateCallback mAllocatePortHandler ; 157 IOFireWireLibIsochPortCallback mReleasePortHandler ; 158 IOFireWireLibIsochPortCallback mStartHandler ; 159 IOFireWireLibIsochPortCallback mStopHandler ; 160 161 IOFireWireLibIsochPortRef mRefInterface ; 162 } ; 163 164#pragma mark - 165 class RemoteIsochPortCOM: public RemoteIsochPort 166 { 167 public: 168 RemoteIsochPortCOM( Device& userclient, bool talking ) ; 169 virtual ~RemoteIsochPortCOM() ; 170 171 static Interface sInterface ; 172 173 // --- IUNKNOWN support ---------------- 174 static IUnknownVTbl** Alloc( Device& inUserClient, bool inTalking ) ; 175 virtual HRESULT QueryInterface( REFIID iid, void** ppv ) ; 176 177 // --- static methods ------------------ 178 static IOFireWireLibIsochPortGetSupportedCallback 179 SSetGetSupportedHandler( 180 PortRef self, 181 IOFireWireLibIsochPortGetSupportedCallback inHandler) ; 182 static IOFireWireLibIsochPortAllocateCallback 183 SSetAllocatePortHandler( 184 PortRef self, 185 IOFireWireLibIsochPortAllocateCallback inHandler) ; 186 static IOFireWireLibIsochPortCallback 187 SSetReleasePortHandler( 188 PortRef self, 189 IOFireWireLibIsochPortCallback inHandler) ; 190 static IOFireWireLibIsochPortCallback 191 SSetStartHandler( 192 PortRef self, 193 IOFireWireLibIsochPortCallback inHandler) ; 194 static IOFireWireLibIsochPortCallback 195 SSetStopHandler( 196 PortRef self, 197 IOFireWireLibIsochPortCallback inHandler) ; 198 } ; 199 200 // ============================================================ 201 // 202 // LocalIsochPort 203 // 204 // ============================================================ 205 206#pragma mark - 207 class LocalIsochPort: public IsochPortCOM 208 { 209 protected: 210 typedef ::IOFireWireLibLocalIsochPortRef PortRef ; 211 typedef ::IOFireWireLibIsochPortFinalizeCallback FinalizeCallback ; 212 213 protected: 214 215 DCLCommand * mDCLProgram ; 216 UInt32 mExpectedStopTokens ; 217 UInt32 mDeferredReleaseCount ; 218 FinalizeCallback mFinalizeCallback ; 219 IOVirtualRange * mBufferRanges ; 220 FWVirtualAddressRange * mBufferAddressRanges; 221 unsigned mBufferRangeCount ; 222 223 pthread_mutex_t mMutex ; 224 bool mStarted ; 225 226 public: 227 228 LocalIsochPort ( const IUnknownVTbl & interface, Device & userClient, bool talking, DCLCommand * dclProgram, 229 UInt32 startEvent, UInt32 startState, UInt32 startMask, 230 IOVirtualRange programRanges[], UInt32 programRangeCount, IOVirtualRange bufferRanges[], 231 UInt32 bufferRangeCount, IOFWIsochPortOptions options ) ; 232 virtual ~LocalIsochPort () ; 233 234 protected : 235 236 IOReturn ExportDCLs( 237 IOVirtualAddress * exportBuffer, 238 IOByteCount * exportBytes ) ; 239 240 public: 241 242 virtual ULONG Release() ; 243 244 // port overrides: 245 virtual IOReturn Start() ; 246 virtual IOReturn Stop() ; 247 248 // local port methods: 249 250 IOReturn ModifyJumpDCL ( DCLJump * jump, DCLLabel * label ) ; 251 IOReturn ModifyTransferPacketDCLSize ( DCLTransferPacket * dcl, IOByteCount newSize ) ; 252 static void s_DCLStopTokenCallProcHandler ( void * self, IOReturn) ; 253 void DCLStopTokenCallProcHandler ( IOReturn) ; 254#if 0 255 void S_DCLKernelCallout( DCLCallProc * dcl ) ; 256 void S_NuDCLKernelCallout ( NuDCL * dcl ) ; 257#endif 258 inline void Lock () ; 259 inline void Unlock () ; 260 261 // 262 // v5 (panther) 263 // 264 265 IOReturn SetResourceUsageFlags ( IOFWIsochResourceFlags flags ) ; 266 IOReturn Notify( 267 IOFWDCLNotificationType notificationType, 268 void ** inDCLList, 269 UInt32 numDCLs ) ; 270 } ; 271 272 // ============================================================ 273 // 274 // LocalIsochPortCOM 275 // 276 // ============================================================ 277 278#pragma mark - 279 class LocalIsochPortCOM: public LocalIsochPort 280 { 281 typedef ::IOFireWireLocalIsochPortInterface Interface ; 282 typedef ::IOFireWireLibLocalIsochPortRef PortRef ; 283 284 public: 285 LocalIsochPortCOM( Device& userclient, bool inTalking, DCLCommand* inDCLProgram, UInt32 inStartEvent, 286 UInt32 inStartState, UInt32 inStartMask, IOVirtualRange inDCLProgramRanges[], 287 UInt32 inDCLProgramRangeCount, IOVirtualRange inBufferRanges[], UInt32 inBufferRangeCount, 288 IOFWIsochPortOptions options ) ; 289 virtual ~LocalIsochPortCOM() ; 290 291 // --- IUNKNOWN support ---------------- 292 static IUnknownVTbl** Alloc( 293 Device& inUserClient, 294 Boolean inTalking, 295 DCLCommand* inDCLProgram, 296 UInt32 inStartEvent, 297 UInt32 inStartState, 298 UInt32 inStartMask, 299 IOVirtualRange inDCLProgramRanges[], // optional optimization parameters 300 UInt32 inDCLProgramRangeCount, 301 IOVirtualRange inBufferRanges[], 302 UInt32 inBufferRangeCount, 303 IOFWIsochPortOptions options ) ; 304 virtual HRESULT QueryInterface( 305 REFIID iid, 306 void** ppv ) ; 307 308 // --- static methods ------------------ 309 static IOReturn SModifyJumpDCL( 310 PortRef self, 311 DCLJump* inJump, 312 DCLLabel* inLabel) ; 313 static void SPrintDCLProgram( 314 PortRef self, 315 const DCLCommand* inProgram, 316 UInt32 inLength) ; 317 static IOReturn SModifyTransferPacketDCLSize( PortRef self, DCLTransferPacket* dcl, IOByteCount newSize ) ; 318 static IOReturn SModifyTransferPacketDCLBuffer( PortRef self, DCLTransferPacket* dcl, void* newBuffer ) ; 319 static IOReturn SModifyTransferPacketDCL( PortRef self, DCLTransferPacket* dcl, void* newBuffer, IOByteCount newSize ) ; 320 static IOReturn S_SetFinalizeCallback( 321 IOFireWireLibLocalIsochPortRef self, 322 FinalizeCallback finalizeCallback ) ; 323 static IOReturn S_SetResourceUsageFlags( 324 IOFireWireLibLocalIsochPortRef self, 325 IOFWIsochResourceFlags flags ) ; 326 static IOReturn S_Notify( 327 IOFireWireLibLocalIsochPortRef self, 328 IOFWDCLNotificationType notificationType, 329 void ** inDCLList, 330 UInt32 numDCLs ) ; 331 332 protected: 333 static Interface sInterface ; 334 } ; 335 336 inline void 337 LocalIsochPort::Lock () 338 { 339 pthread_mutex_lock( & mMutex ) ; 340 } 341 342 inline void 343 LocalIsochPort::Unlock () 344 { 345 pthread_mutex_unlock( & mMutex ) ; 346 } 347} 348