#ifndef _IOKIT_IOFWCOMMAND_H
#define _IOKIT_IOFWCOMMAND_H
#include <IOKit/IOCommand.h>
#include <IOKit/IOLib.h>
#include <IOKit/firewire/IOFireWireFamilyCommon.h>
class IOMemoryDescriptor;
class IOSyncer;
class IOFireWireBus;
class IOFireWireController;
class IOFireWireNub;
class IOFWAddressSpace; class IOFWCommand;
class IOFWBusCommand;
class IOFWAsyncStreamCommand;
class IOCommandGate;
struct AsyncPendingTrans;
struct IOFWCmdQ
{
IOFWCommand *fHead;
IOFWCommand *fTail;
bool executeQueue(bool all);
virtual void headChanged(IOFWCommand *oldHead);
};
typedef void (*FWDeviceCallback)(void *refcon, IOReturn status, IOFireWireNub *device, IOFWCommand *fwCmd);
typedef void (*FWBusCallback)(void *refcon, IOReturn status, IOFireWireBus *bus, IOFWBusCommand *fwCmd);
typedef void (*FWAsyncStreamCallback)(void *refcon, IOReturn status, IOFireWireBus *bus, IOFWAsyncStreamCommand *fwCmd);
#pragma mark -
class IOFWCommand : public IOCommand
{
OSDeclareAbstractStructors(IOFWCommand)
protected:
IOReturn fStatus;
IOFireWireController *fControl;
IOFWCommand * fQueuePrev;
IOFWCommand * fQueueNext;
IOFWCmdQ * fQueue;
UInt32 fTimeout; AbsoluteTime fDeadline; IOSyncer * fSyncWakeup;
UInt8 fSync;
UInt8 fCancelOnReset;
UInt8 spare[2];
struct ExpansionData { };
ExpansionData *reserved;
virtual IOReturn complete(IOReturn status);
virtual void updateTimer();
virtual IOReturn startExecution();
virtual IOReturn execute() = 0;
public:
virtual bool initWithController(IOFireWireController *control);
IOReturn getStatus() const { return fStatus; };
virtual IOReturn submit(bool queue = false);
virtual IOReturn cancel(IOReturn reason);
virtual void setHead(IOFWCmdQ &queue);
virtual void insertAfter(IOFWCommand &prev);
virtual void removeFromQ();
IOFWCommand *getPrevious() const
{ return fQueuePrev; };
IOFWCommand *getNext() const
{ return fQueueNext; };
const AbsoluteTime &getDeadline() const
{ return fDeadline; };
bool cancelOnReset() const
{ return fCancelOnReset; };
bool Busy() const
{ return fStatus == kIOReturnBusy || fStatus == kIOFireWirePending;};
void setTimeout( UInt32 timeout )
{ fTimeout = timeout; };
friend class IOFWCmdQ;
private:
OSMetaClassDeclareReservedUnused(IOFWCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWCommand, 1);
};
#pragma mark -
class IOFWBusCommand : public IOFWCommand
{
OSDeclareAbstractStructors(IOFWBusCommand)
protected:
FWBusCallback fComplete;
void * fRefCon;
struct ExpansionData { };
ExpansionData *reserved;
virtual IOReturn complete(IOReturn status);
virtual bool initWithController(IOFireWireController *control,
FWBusCallback completion=NULL, void *refcon=NULL);
virtual IOReturn reinit(FWBusCallback completion, void *refcon);
private:
OSMetaClassDeclareReservedUnused(IOFWBusCommand, 0);
};
#pragma mark -
class IOFWDelayCommand : public IOFWBusCommand
{
OSDeclareDefaultStructors(IOFWDelayCommand)
struct ExpansionData { };
ExpansionData *reserved;
protected:
virtual IOReturn execute();
public:
virtual bool initWithDelay(IOFireWireController *control, UInt32 uSecs,
FWBusCallback completion, void *refcon);
virtual IOReturn reinit(UInt32 uSecs, FWBusCallback completion, void *refcon);
private:
OSMetaClassDeclareReservedUnused(IOFWDelayCommand, 0);
};
class IOFWUserReadQuadletCommand ;
class IOFWUserWriteCommand ;
#pragma mark -
class IOFWAsyncCommand : public IOFWCommand
{
OSDeclareAbstractStructors(IOFWAsyncCommand)
protected:
IOFireWireNub * fDevice;
FWDeviceCallback fComplete;
void * fRefCon;
IOMemoryDescriptor *fMemDesc;
AsyncPendingTrans * fTrans;
UInt32 fAddressHi;
UInt32 fAddressLo;
IOByteCount fBytesTransferred;
int fSize;
int fSpeed;
int fMaxPack;
int fCurRetries;
int fMaxRetries;
UInt32 fGeneration; UInt16 fNodeID;
bool fFailOnReset;
bool fWrite;
typedef struct
{
void * fSubclassMembers;
int fMaxSpeed;
}
MemberVariables;
MemberVariables * fMembers;
virtual IOReturn complete(IOReturn status);
virtual bool initWithController(IOFireWireController *control);
virtual bool initAll(IOFireWireNub *device, FWAddress devAddress,
IOMemoryDescriptor *hostMem,
FWDeviceCallback completion, void *refcon, bool failOnReset);
virtual bool initAll(IOFireWireController *control,
UInt32 generation, FWAddress devAddress,
IOMemoryDescriptor *hostMem,
FWDeviceCallback completion, void *refcon);
virtual void free( void );
virtual IOReturn reinit(FWAddress devAddress, IOMemoryDescriptor *hostMem,
FWDeviceCallback completion, void *refcon, bool failOnReset);
virtual IOReturn reinit(UInt32 generation, FWAddress devAddress, IOMemoryDescriptor *hostMem,
FWDeviceCallback completion, void *refcon);
bool createMemberVariables( void );
void destroyMemberVariables( void );
public:
virtual void setGeneration(UInt32 generation)
{ fGeneration = generation; }
virtual void gotPacket(int rcode, const void* data, int size) = 0;
virtual void gotAck(int ackCode);
IOReturn updateGeneration();
IOReturn updateNodeID(UInt32 generation, UInt16 nodeID);
IOByteCount getBytesTransferred() const
{ return fBytesTransferred; };
FWAddress getAddress() const
{ return FWAddress(fAddressHi, fAddressLo, fNodeID); }
bool failOnReset() const
{ return fFailOnReset; }
IOFireWireNub * getDevice() const
{ return fDevice; }
IOReturn setMaxPacket(UInt32 maxBytes)
{
if(fStatus == kIOReturnBusy || fStatus == kIOFireWirePending)
return fStatus;
fMaxPack = maxBytes;
return kIOReturnSuccess;
}
void setMaxSpeed( int speed );
private:
OSMetaClassDeclareReservedUnused(IOFWAsyncCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWAsyncCommand, 1);
OSMetaClassDeclareReservedUnused(IOFWAsyncCommand, 2);
OSMetaClassDeclareReservedUnused(IOFWAsyncCommand, 3);
};
#pragma mark -
class IOFWReadCommand : public IOFWAsyncCommand
{
OSDeclareDefaultStructors(IOFWReadCommand)
protected:
virtual void gotPacket(int rcode, const void* data, int size);
virtual IOReturn execute();
public:
virtual bool initAll(IOFireWireNub *device, FWAddress devAddress,
IOMemoryDescriptor *hostMem,
FWDeviceCallback completion, void *refcon, bool failOnReset);
virtual bool initAll(IOFireWireController *control,
UInt32 generation, FWAddress devAddress,
IOMemoryDescriptor *hostMem,
FWDeviceCallback completion, void *refcon);
virtual IOReturn reinit(FWAddress devAddress, IOMemoryDescriptor *hostMem,
FWDeviceCallback completion=NULL, void *refcon=NULL,
bool failOnReset=false);
virtual IOReturn reinit(UInt32 generation, FWAddress devAddress, IOMemoryDescriptor *hostMem,
FWDeviceCallback completion=NULL, void *refcon=NULL);
private:
OSMetaClassDeclareReservedUnused(IOFWReadCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWReadCommand, 1);
};
#pragma mark -
class IOFWReadQuadCommand : public IOFWAsyncCommand
{
OSDeclareDefaultStructors(IOFWReadQuadCommand)
protected:
UInt32 * fQuads;
virtual void gotPacket(int rcode, const void* data, int size);
virtual IOReturn execute();
public:
virtual bool initAll(IOFireWireNub *device, FWAddress devAddress,
UInt32 *quads, int numQuads,
FWDeviceCallback completion, void *refcon, bool failOnReset);
virtual bool initAll(IOFireWireController *control,
UInt32 generation, FWAddress devAddress,
UInt32 *quads, int numQuads,
FWDeviceCallback completion, void *refcon);
virtual IOReturn reinit(FWAddress devAddress, UInt32 *quads, int numQuads,
FWDeviceCallback completion=NULL, void *refcon=NULL,
bool failOnReset=false);
virtual IOReturn reinit(UInt32 generation, FWAddress devAddress, UInt32 *quads, int numQuads,
FWDeviceCallback completion=NULL, void *refcon=NULL);
private:
OSMetaClassDeclareReservedUnused(IOFWReadQuadCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWReadQuadCommand, 1);
};
#pragma mark -
class IOFWWriteCommand : public IOFWAsyncCommand
{
OSDeclareDefaultStructors(IOFWWriteCommand)
protected:
int fPackSize;
typedef struct
{
bool fDeferredNotify;
}
MemberVariables;
virtual IOReturn execute();
virtual void gotPacket( int rcode, const void* data, int size );
bool createMemberVariables( void );
void destroyMemberVariables( void );
public:
virtual bool initWithController(IOFireWireController *control);
virtual bool initAll( IOFireWireNub * device,
FWAddress devAddress,
IOMemoryDescriptor * hostMem,
FWDeviceCallback completion,
void * refcon,
bool failOnReset );
virtual bool initAll( IOFireWireController * control,
UInt32 generation,
FWAddress devAddress,
IOMemoryDescriptor * hostMem,
FWDeviceCallback completion,
void * refcon );
virtual void free( void );
virtual IOReturn reinit( FWAddress devAddress,
IOMemoryDescriptor * hostMem,
FWDeviceCallback completion = NULL,
void * refcon = NULL,
bool failOnReset = false );
virtual IOReturn reinit( UInt32 generation,
FWAddress devAddress,
IOMemoryDescriptor * hostMem,
FWDeviceCallback completion = NULL,
void * refcon = NULL );
void setDeferredNotify( bool state )
{ ((MemberVariables*)fMembers->fSubclassMembers)->fDeferredNotify = state; };
private:
OSMetaClassDeclareReservedUnused(IOFWWriteCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWWriteCommand, 1);
};
#pragma mark -
class IOFWWriteQuadCommand : public IOFWAsyncCommand
{
OSDeclareDefaultStructors(IOFWWriteQuadCommand)
public:
enum
{
kMaxWriteQuads = 8
};
protected:
UInt32 fQuads[kMaxWriteQuads];
UInt32 * fQPtr;
int fPackSize;
typedef struct
{
bool fDeferredNotify;
IOMemoryDescriptor * fMemory;
}
MemberVariables;
virtual void gotPacket( int rcode, const void* data, int size );
virtual IOReturn execute();
bool createMemberVariables( void );
void destroyMemberVariables( void );
public:
virtual bool initWithController(IOFireWireController *control);
virtual bool initAll( IOFireWireNub * device,
FWAddress devAddress,
UInt32 * quads,
int numQuads,
FWDeviceCallback completion,
void * refcon,
bool failOnReset );
virtual bool initAll( IOFireWireController * control,
UInt32 generation,
FWAddress devAddress,
UInt32 * quads,
int numQuads,
FWDeviceCallback completion,
void * refcon );
virtual void free( void );
virtual IOReturn reinit( FWAddress devAddress,
UInt32 * quads,
int numQuads,
FWDeviceCallback completion = NULL,
void * refcon = NULL,
bool failOnReset = false );
virtual IOReturn reinit( UInt32 generation,
FWAddress devAddress,
UInt32 * quads,
int numQuads,
FWDeviceCallback completion = NULL,
void * refcon = NULL );
protected:
void setQuads( UInt32 * quads, int numQuads );
bool createMemoryDescriptor( void );
void destroyMemoryDescriptor( void );
public:
void setDeferredNotify( bool state )
{ ((MemberVariables*)fMembers->fSubclassMembers)->fDeferredNotify = state; };
private:
OSMetaClassDeclareReservedUnused(IOFWWriteQuadCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWWriteQuadCommand, 1);
};
#pragma mark -
class IOFWCompareAndSwapCommand : public IOFWAsyncCommand
{
OSDeclareDefaultStructors(IOFWCompareAndSwapCommand)
protected:
UInt32 fInputVals[4];
UInt32 fOldVal[2];
typedef struct
{
IOMemoryDescriptor * fMemory;
}
MemberVariables;
MemberVariables * fMembers;
virtual void gotPacket(int rcode, const void* data, int size);
virtual IOReturn execute();
public:
virtual bool initWithController(IOFireWireController *control);
virtual bool initAll(IOFireWireNub *device, FWAddress devAddress,
const UInt32 *cmpVal, const UInt32 *newVal, int size,
FWDeviceCallback completion, void *refcon, bool failOnReset);
virtual bool initAll(IOFireWireController *control,
UInt32 generation, FWAddress devAddress,
const UInt32 *cmpVal, const UInt32 *newVal, int size,
FWDeviceCallback completion, void *refcon);
virtual IOReturn reinit(FWAddress devAddress, const UInt32 *cmpVal, const UInt32 *newVal, int size,
FWDeviceCallback completion=NULL, void *refcon=NULL, bool failOnReset=false);
virtual IOReturn reinit(UInt32 generation, FWAddress devAddress,
const UInt32 *cmpVal, const UInt32 *newVal, int size,
FWDeviceCallback completion=NULL, void *refcon=NULL);
virtual bool locked(UInt32 *oldVal);
virtual void free( void );
protected:
bool createMemberVariables( void );
void destroyMemberVariables( void );
void setInputVals( const UInt32 * cmpVal, const UInt32 * newVal, int size );
bool createMemoryDescriptor( void );
void destroyMemoryDescriptor( void );
private:
OSMetaClassDeclareReservedUnused(IOFWCompareAndSwapCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWCompareAndSwapCommand, 1);
OSMetaClassDeclareReservedUnused(IOFWCompareAndSwapCommand, 2);
OSMetaClassDeclareReservedUnused(IOFWCompareAndSwapCommand, 3);
};
#pragma mark -
class IOFWAsyncStreamCommand : public IOFWCommand
{
friend class IOFireWireUserClient ;
OSDeclareDefaultStructors(IOFWAsyncStreamCommand)
protected:
FWAsyncStreamCallback fComplete;
void * fRefCon;
IOMemoryDescriptor * fMemDesc;
int fSpeed;
int fSize;
int fCurRetries;
int fMaxRetries;
int fChannel;
int fSyncBits;
int fTag;
UInt32 fGeneration; bool fFailOnReset;
struct ExpansionData { };
ExpansionData *reserved;
virtual IOReturn complete(
IOReturn status);
virtual IOReturn execute();
public:
virtual bool initAll(
IOFireWireController * control,
UInt32 generation,
UInt32 channel,
UInt32 sync,
UInt32 tag,
IOMemoryDescriptor * hostMem,
UInt32 size,
int speed,
FWAsyncStreamCallback completion,
void * refcon);
virtual IOReturn reinit( UInt32 generation,
UInt32 channel,
UInt32 sync,
UInt32 tag,
IOMemoryDescriptor * hostMem,
UInt32 size,
int speed,
FWAsyncStreamCallback completion,
void * refcon);
virtual void gotAck(
int ackCode);
virtual void setGeneration(
UInt32 generation)
{ fGeneration = generation; }
IOReturn updateGeneration();
bool failOnReset() const
{ return fFailOnReset; }
private:
OSMetaClassDeclareReservedUnused(IOFWAsyncStreamCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWAsyncStreamCommand, 1);
OSMetaClassDeclareReservedUnused(IOFWAsyncStreamCommand, 2);
OSMetaClassDeclareReservedUnused(IOFWAsyncStreamCommand, 3);
};
#endif