1/* 2 * Copyright (c) 1998-2000 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 * IOFireWireLibCommand.h 24 * IOFireWireLib 25 * 26 * Created by NWG on Tue Dec 12 2000. 27 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 28 * 29 */ 30 31#import <IOKit/firewire/IOFireWireFamilyCommon.h> 32 33//#import "IOFireWireLibDevice.h" 34#import "IOFireWireLibIUnknown.h" 35#import "IOFireWireLib.h" 36#import "IOFireWireLibPriv.h" 37 38namespace IOFireWireLib { 39 40 typedef ::IOFireWireLibCommandCallback CommandCallback ; 41 42 class Device ; 43 class Cmd: public IOFireWireIUnknown 44 { 45 public: 46 47 Cmd( const IUnknownVTbl & vtable, Device & userClient, io_object_t device, const FWAddress & inAddr, 48 CommandCallback callback, const bool failOnReset, const UInt32 generation, 49 void * refCon, CommandSubmitParams* params ) ; 50 virtual ~Cmd() ; 51 52 public: 53 54 virtual HRESULT QueryInterface( REFIID iid, LPVOID* ppv ) ; 55 virtual void SetTarget( const FWAddress& addr) ; 56 virtual void SetGeneration( UInt32 generation) ; 57 virtual void SetCallback( CommandCallback callback ) ; 58 virtual IOReturn Submit() = 0 ; 59 virtual IOReturn Submit( CommandSubmitParams* params, mach_msg_type_number_t paramsSize, 60 CommandSubmitResult* ioResult, mach_msg_type_number_t* ioResultSize ) ; 61 virtual IOReturn SubmitWithRefconAndCallback( void* refCon, CommandCallback inCallback ) ; 62 virtual IOReturn Cancel( IOReturn reason) ; 63 virtual void SetBuffer( UInt32 size, void* buf ) ; 64 virtual void GetBuffer( UInt32* outSize, void** outBuf ) ; 65 virtual IOReturn SetMaxPacket( IOByteCount maxBytes ) ; 66 virtual void SetFlags( UInt32 inFlags ) ; 67 virtual void SetTimeoutDuration( UInt32 duration ); 68 virtual void SetMaxRetryCount( UInt32 count ); 69 virtual UInt32 GetAckCode(); 70 virtual UInt32 GetResponseCode(); 71 virtual void SetMaxPacketSpeed( IOFWSpeed speed ); 72 73 virtual IOReturn PrepareForVectorSubmit( CommandSubmitParams * submit_params ); 74 virtual void VectorIsExecuting( void ); 75 76 static void CommandCompletionHandler( 77 void* refcon, 78 IOReturn result, 79 void* quads[], 80 UInt32 numQuads) ; 81 82 // --- getters ----------------------- 83 static IOReturn SGetStatus( IOFireWireLibCommandRef self) ; 84 static UInt32 SGetTransferredBytes( IOFireWireLibCommandRef self) ; 85 static void SGetTargetAddress( IOFireWireLibCommandRef self, FWAddress* outAddr ) ; 86 87 // --- setters ----------------------- 88 static void SSetTarget ( IOFireWireLibCommandRef self, const FWAddress * addr ) ; 89 static void SSetGeneration ( IOFireWireLibCommandRef self, UInt32 generation ) ; 90 static void SSetCallback ( IOFireWireLibCommandRef self, CommandCallback callback ) ; 91 static void SSetRefCon ( IOFireWireLibCommandRef self, void * refCon ) ; 92 93 static const Boolean SIsExecuting ( IOFireWireLibCommandRef self ) ; 94 static IOReturn SSubmit ( IOFireWireLibCommandRef self ) ; 95 static IOReturn SSubmitWithRefconAndCallback ( IOFireWireLibCommandRef self, void * refCon, 96 CommandCallback callback) ; 97 static IOReturn SCancel ( IOFireWireLibCommandRef self, IOReturn reason ) ; 98 static void SSetBuffer ( IOFireWireLibCommandRef self, UInt32 size, void * buf ) ; 99 static void SGetBuffer ( IOFireWireLibCommandRef self, UInt32 * outSize, void ** outBuf) ; 100 static IOReturn SSetMaxPacket ( IOFireWireLibCommandRef self, IOByteCount maxBytes ) ; 101 static void SSetFlags ( IOFireWireLibCommandRef self, UInt32 flags ) ; 102 103 static void SSetTimeoutDuration( IOFireWireLibCommandRef self, UInt32 duration ); 104 static void SSetMaxRetryCount( IOFireWireLibCommandRef self, UInt32 count ); 105 static UInt32 SGetAckCode( IOFireWireLibCommandRef self ); 106 static UInt32 SGetResponseCode( IOFireWireLibCommandRef self ); 107 static void SSetMaxPacketSpeed( IOFireWireLibCommandRef self, IOFWSpeed speed ); 108 static void * SGetRefCon ( IOFireWireLibCommandRef self ); 109 110 protected: 111 112 static IOFireWireCommandInterface sInterface ; 113 114 protected: 115 116 Device & mUserClient ; 117 io_object_t mDevice ; 118 IOByteCount mBytesTransferred ; 119 Boolean mIsExecuting ; 120 IOReturn mStatus ; 121 void* mRefCon ; 122 CommandCallback mCallback ; 123 124 UInt32 mAckCode; 125 UInt32 mResponseCode; 126 127 CommandSubmitParams* mParams ; 128 129 } ; 130 131#pragma mark - 132 class ReadCmd: public Cmd 133 { 134 protected: 135 typedef ::IOFireWireReadCommandInterface Interface ; 136 typedef ::IOFireWireLibReadCommandRef CmdRef ; 137 138 public: 139 ReadCmd( 140 Device& userclient, 141 io_object_t device, 142 const FWAddress& addr, 143 void* buf, 144 UInt32 size, 145 CommandCallback callback, 146 bool failOnReset, 147 UInt32 generation, 148 void* inRefCon ) ; 149 virtual ~ReadCmd() {} 150 virtual HRESULT QueryInterface(REFIID iid, LPVOID* ppv) ; 151 inline ReadCmd* GetThis(CmdRef self) { return IOFireWireIUnknown::InterfaceMap<ReadCmd>::GetThis(self) ; } 152 static IUnknownVTbl** Alloc( 153 Device& userclient, 154 io_object_t device, 155 const FWAddress& addr, 156 void* buf, 157 UInt32 size, 158 CommandCallback callback, 159 bool failOnReset, 160 UInt32 generation, 161 void* inRefCon) ; 162 163 virtual IOReturn Submit() ; 164 165 private: 166 static Interface sInterface ; 167 168 } ; 169 170#pragma mark - 171 class ReadQuadCmd: public Cmd 172 { 173 protected: 174 typedef ::IOFireWireReadQuadletCommandInterface Interface ; 175 typedef ::IOFireWireLibReadQuadletCommandRef CmdRef ; 176 177 public: 178 ReadQuadCmd( 179 Device& userclient, 180 io_object_t device, 181 const FWAddress & addr, 182 UInt32 quads[], 183 UInt32 numQuads, 184 CommandCallback callback, 185 Boolean failOnReset, 186 UInt32 generation, 187 void* refcon) ; 188 virtual ~ReadQuadCmd() {} 189 190 virtual HRESULT QueryInterface( REFIID iid, LPVOID* ppv ) ; 191 inline static ReadQuadCmd* GetThis( CmdRef self ) { return IOFireWireIUnknown::InterfaceMap<ReadQuadCmd>::GetThis(self) ; } 192 193 virtual void SetFlags( UInt32 inFlags ) ; 194 virtual void SetQuads( UInt32 quads[], UInt32 numQuads) ; 195 virtual IOReturn Submit() ; 196 197 // static 198 static IUnknownVTbl** Alloc( 199 Device& inUserClient, 200 io_object_t device, 201 const FWAddress & addr, 202 UInt32 quads[], 203 UInt32 numQuads, 204 CommandCallback callback, 205 Boolean failOnReset, 206 UInt32 generation, 207 void* inRefCon) ; 208 static void SSetQuads( 209 IOFireWireLibReadQuadletCommandRef self, 210 UInt32 inQuads[], 211 UInt32 inNumQuads) ; 212 static void CommandCompletionHandler( 213 void* refcon, 214 IOReturn result, 215 void* quads[], 216 UInt32 numQuads) ; 217 protected: 218 static Interface sInterface ; 219 unsigned int mNumQuads ; 220 221 } ; 222 223#pragma mark - 224 class WriteCmd: public Cmd 225 { 226 protected: 227 typedef ::IOFireWireWriteCommandInterface Interface ; 228 229 public: 230/* virtual Boolean Init( 231 const FWAddress& inAddr, 232 void* buf, 233 UInt32 size, 234 CommandCallback inCallback, 235 const Boolean inFailOnReset, 236 const UInt32 inGeneration, 237 void* inRefCon ) ;*/ 238 WriteCmd( 239 Device& userclient, 240 io_object_t device, 241 const FWAddress& addr, 242 void* buf, 243 UInt32 size, 244 CommandCallback callback, 245 bool failOnReset, 246 UInt32 generation, 247 void* inRefCon ) ; 248 virtual ~WriteCmd() {} 249 static IUnknownVTbl** Alloc( 250 Device& inUserClient, 251 io_object_t device, 252 const FWAddress & addr, 253 void* buf, 254 UInt32 size, 255 CommandCallback callback, 256 bool failOnReset, 257 UInt32 generation, 258 void* inRefCon) ; 259 virtual HRESULT QueryInterface(REFIID iid, LPVOID* ppv) ; 260 inline static WriteCmd* GetThis(IOFireWireLibWriteCommandRef self) { return IOFireWireIUnknown::InterfaceMap<WriteCmd>::GetThis(self) ; } 261 262 // required Submit() method 263 virtual IOReturn Submit() ; 264 265 protected: 266 static Interface sInterface ; 267 } ; 268 269#pragma mark - 270 class PHYCmd: public Cmd 271 { 272 protected: 273 typedef ::IOFireWirePHYCommandInterface Interface; 274 275 public: 276 PHYCmd( 277 Device& userclient, 278 UInt32 data1, 279 UInt32 data2, 280 CommandCallback callback, 281 bool failOnReset, 282 UInt32 generation, 283 void* inRefCon ); 284 virtual ~PHYCmd() {} 285 static IUnknownVTbl** Alloc( 286 Device& inUserClient, 287 UInt32 data1, 288 UInt32 data2, 289 CommandCallback callback, 290 bool failOnReset, 291 UInt32 generation, 292 void* inRefCon ); 293 294 virtual HRESULT QueryInterface( REFIID iid, LPVOID* ppv ); 295 inline static PHYCmd* GetThis( IOFireWireLibWriteCommandRef self ) { return IOFireWireIUnknown::InterfaceMap<PHYCmd>::GetThis(self); } 296 297 // required Submit() method 298 virtual IOReturn Submit() ; 299 300 static void S_SetDataQuads( IOFireWireLibPHYCommandRef self, 301 UInt32 data1, 302 UInt32 data2 ); 303 304 protected: 305 static Interface sInterface; 306 }; 307 308#pragma mark - 309 class WriteQuadCmd: public Cmd 310 { 311 protected: 312 typedef ::IOFireWireWriteQuadletCommandInterface Interface ; 313 typedef ::IOFireWireLibWriteQuadletCommandRef CmdRef ; 314 public: 315 WriteQuadCmd( 316 Device& userclient, 317 io_object_t device, 318 const FWAddress& addr, 319 UInt32 quads[], 320 UInt32 numQuads, 321 CommandCallback callback, 322 bool failOnReset, 323 UInt32 generation, 324 void* inRefCon ) ; 325 virtual ~WriteQuadCmd() ; 326 static IUnknownVTbl** Alloc( Device& userclient, io_object_t device, const FWAddress& addr, 327 UInt32 quads[], UInt32 numQuads, CommandCallback callback, 328 bool failOnReset, UInt32 generation, void* refcon) ; 329 330 331 virtual HRESULT QueryInterface(REFIID iid, LPVOID* ppv) ; 332 inline static WriteQuadCmd* GetThis(CmdRef self) { return IOFireWireIUnknown::InterfaceMap<WriteQuadCmd>::GetThis(self) ; } 333 334 virtual void SetFlags( UInt32 inFlags ) ; 335 virtual void SetQuads( UInt32 inQuads[], UInt32 inNumQuads) ; 336 virtual IOReturn Submit() ; 337 338 // static 339 static void SSetQuads( 340 CmdRef self, 341 UInt32 inQuads[], 342 UInt32 inNumQuads) ; 343 344 protected: 345 static Interface sInterface; 346 UInt8* mParamsExtra; 347 348 } ; 349 350#pragma mark - 351 class CompareSwapCmd: public Cmd 352 { 353 protected: 354 typedef ::IOFireWireLibCompareSwapCommandRef CmdRef; 355 typedef ::IOFireWireCompareSwapCommandInterface Interface; 356 typedef ::IOFireWireCompareSwapCommandInterface_v3 Interface_v3; 357 358 // --- ctor/dtor ---------------- 359 CompareSwapCmd( 360 Device& inUserClient, 361 io_object_t device, 362 const FWAddress & addr, 363 UInt64 cmpVal, 364 UInt64 newVal, 365 unsigned int quads, 366 CommandCallback callback, 367 bool failOnReset, 368 UInt32 generation, 369 void* inRefCon) ; 370 virtual ~CompareSwapCmd() ; 371 virtual HRESULT QueryInterface(REFIID iid, LPVOID* ppv) ; 372 inline static CompareSwapCmd* GetThis(IOFireWireLibCompareSwapCommandRef self) { return IOFireWireIUnknown::InterfaceMap<CompareSwapCmd>::GetThis(self) ; } 373 374 virtual void SetFlags( UInt32 inFlags ) ; 375 void SetValues( UInt32 cmpVal, UInt32 newVal) ; 376 virtual IOReturn SetMaxPacket( 377 IOByteCount inMaxBytes) ; 378 virtual IOReturn Submit() ; 379 380 // --- v2 --- 381 void SetValues( UInt64 cmpVal, UInt64 newVal) ; 382 Boolean DidLock() ; 383 IOReturn Locked( UInt32* oldValue) ; 384 IOReturn Locked64( UInt64* oldValue) ; 385 386 // 387 // static interface 388 // 389 public: 390 static IUnknownVTbl** Alloc( 391 Device& userclient, 392 io_object_t device, 393 const FWAddress & addr, 394 UInt64 cmpVal, 395 UInt64 newVal, 396 unsigned int quads, 397 CommandCallback callback, 398 bool failOnReset, 399 UInt32 generation, 400 void* inRefCon) ; 401 static void SSetValues( 402 IOFireWireLibCompareSwapCommandRef self, 403 UInt32 cmpVal, 404 UInt32 newVal) ; 405 static void SSetValues64( 406 CmdRef self, 407 UInt64 cmpVal, 408 UInt64 newVal) ; 409 static Boolean SDidLock( 410 CmdRef self) ; 411 static IOReturn SLocked( 412 CmdRef self, 413 UInt32* oldValue) ; 414 static IOReturn SLocked64( 415 CmdRef self, 416 UInt64* oldValue) ; 417 static void SSetFlags( CmdRef self, UInt32 inFlags) ; 418 static void CommandCompletionHandler( 419 void* refcon, 420 IOReturn result, 421 io_user_reference_t quads[], 422 UInt32 numQuads) ; 423 424 425 protected: 426 static Interface sInterface ; 427 static Interface_v3 sInterface_v3; 428 UInt8* mParamsExtra ; 429 CompareSwapSubmitResult mSubmitResult ; 430 431 private: 432 mutable InterfaceMap<IOFireWireIUnknown> mInterface_v3; 433 } ; 434 435#pragma mark - 436 class AsyncStreamCmd: public Cmd 437 { 438 protected: 439 typedef ::IOFireWireAsyncStreamCommandInterface Interface ; 440 441 public: 442 AsyncStreamCmd( 443 Device& userclient, 444 UInt32 channel, 445 UInt32 sync, 446 UInt32 tag, 447 void* buf, 448 UInt32 size, 449 CommandCallback callback, 450 Boolean failOnReset, 451 UInt32 generation, 452 void* inRefCon) ; 453 454 virtual ~AsyncStreamCmd() {} 455 456 static IUnknownVTbl** Alloc( 457 Device& userclient, 458 UInt32 channel, 459 UInt32 sync, 460 UInt32 tag, 461 void* buf, 462 UInt32 size, 463 CommandCallback callback, 464 Boolean failOnReset, 465 UInt32 generation, 466 void* inRefCon) ; 467 468 virtual HRESULT QueryInterface(REFIID iid, LPVOID* ppv) ; 469 470 inline static AsyncStreamCmd* GetThis(IOFireWireLibAsyncStreamCommandRef self) { return IOFireWireIUnknown::InterfaceMap<AsyncStreamCmd>::GetThis(self) ; }; 471 472 // required Submit() method 473 virtual IOReturn Submit() ; 474 475 static void S_SetChannel( IOFireWireLibAsyncStreamCommandRef self, 476 UInt32 channel ); 477 478 static void S_SetSyncBits( IOFireWireLibAsyncStreamCommandRef self, 479 UInt16 sync ); 480 481 static void S_SetTagBits( IOFireWireLibAsyncStreamCommandRef self, 482 UInt16 tag ); 483 484 protected: 485 static Interface sInterface ; 486 } ; 487 488} 489