IOFireWireController.h [plain text]
#ifndef _IOKIT_IOFIREWIRECONTROLLER_H
#define _IOKIT_IOFIREWIRECONTROLLER_H
#ifndef FIREWIREPRIVATE
#warning Please do not include this file. Include IOFireWireBus.h instead.
#endif
#include <IOKit/IOEventSource.h>
#include <IOKit/firewire/IOFireWireBus.h>
#include <IOKit/firewire/IOFireWireFamilyCommon.h>
class OSData;
class IOWorkLoop;
class IOEventSource;
class IOFWQEventSource;
class IOTimerEventSource;
class IOMemoryDescriptor;
class IOFireWireController;
class IOFWAddressSpace;
class IOFWPseudoAddressSpace;
class IOFireWireNub;
class IOFireWireDevice;
class IOFireWireUnit;
class IODCLProgram;
class IOLocalConfigDirectory;
class IOFireWireLink;
class IOFireWireSBP2ORB;
class IOFireWireSBP2Login;
class IOFireWireROMCache;
class IOFireWireLocalNode;
class IOFWWorkLoop;
class IOFireWireIRM;
class IOFireWirePowerManager;
#if FIRELOGCORE
class IOFireLog;
class IOFireLogPublisher;
#endif
enum
{
kFWPhyPacketID = FWBitRange (0, 1),
kFWPhyPacketIDPhase = FWBitRangePhase (0, 1),
kFWPhyPacketPhyID = FWBitRange (2, 7),
kFWPhyPacketPhyIDPhase = FWBitRangePhase (2, 7)
};
enum
{
kSelfIDPacketSize = 8,
kMaxSelfIDs = 4 };
enum
{
kFWConfigurationPacketID = 0,
kFWLinkOnPacketID = 1,
kFWSelfIDPacketID = 2
};
enum
{
kFWPhyConfigurationR = FW_BIT(8),
kFWPhyConfigurationT = FW_BIT(9),
kFWPhyConfigurationGapCnt = FWBitRange (10, 15),
kFWPhyConfigurationGapCntPhase = FWBitRangePhase (10, 15)
};
enum
{
kFWSelfIDPortStatusChild = 3,
kFWSelfIDPortStatusParent = 2,
kFWSelfIDPortStatusNotConnected = 1,
kFWSelfIDPortStatusNotPresent = 0,
kFWSelfIDNoPower = 0,
kFWSelfIDSelfPowered15W = 1,
kFWSelfIDSelfPowered30W = 2,
kFWSelfIDSelfPowered45W = 3,
kFWSelfIDBusPowered1W = 4,
kFWSelfIDBusPowered3W = 5,
kFWSelfIDBusPowered6W = 6,
kFWSelfIDBusPowered10W = 7,
kFWSelfIDPhyID = kFWPhyPacketPhyID, kFWSelfIDPhyIDPhase = kFWPhyPacketPhyIDPhase,
kFWSelfIDM = FW_BIT(31),
kFWSelfID0L = FW_BIT(9),
kFWSelfID0GapCnt = FWBitRange (10, 15),
kFWSelfID0GapCntPhase = FWBitRangePhase (10, 15),
kFWSelfID0SP = FWBitRange (16, 17),
kFWSelfID0SPPhase = FWBitRangePhase (16, 17),
kFWSelfID0Del = FWBitRange (18, 19),
kFWSelfID0DelPhase = FWBitRangePhase (18, 19),
kFWSelfID0C = FW_BIT(20),
kFWSelfID0Pwr = FWBitRange (21, 23),
kFWSelfID0PwrPhase = FWBitRangePhase (21, 23),
kFWSelfID0P0 = FWBitRange (24, 25),
kFWSelfID0P0Phase = FWBitRangePhase (24, 25),
kFWSelfID0P1 = FWBitRange (26, 27),
kFWSelfID0P1Phase = FWBitRangePhase (26, 27),
kFWSelfID0P2 = FWBitRange (28, 29),
kFWSelfID0P2Phase = FWBitRangePhase (28, 29),
kFWSelfID0I = FW_BIT(30),
kFWSelfIDPacketType = FW_BIT(8),
kFWSelfIDNN = FWBitRange (9, 11),
kFWSelfIDNNPhase = FWBitRangePhase (9, 11),
kFWSelfIDNPa = FWBitRange (14, 15),
kFWSelfIDNPaPhase = FWBitRangePhase (14, 15),
kFWSelfIDNPb = FWBitRange (16, 17),
kFWSelfIDNPbPhase = FWBitRangePhase (16, 17),
kFWSelfIDNPc = FWBitRange (18, 19),
kFWSelfIDNPcPhase = FWBitRangePhase (18, 19),
kFWSelfIDNPd = FWBitRange (20, 21),
kFWSelfIDNPdPhase = FWBitRangePhase (20, 21),
kFWSelfIDNPe = FWBitRange (22, 23),
kFWSelfIDNPePhase = FWBitRangePhase (22, 23),
kFWSelfIDNPf = FWBitRange (24, 25),
kFWSelfIDNPfPhase = FWBitRangePhase (24, 25),
kFWSelfIDNPg = FWBitRange (26, 27),
kFWSelfIDNPgPhase = FWBitRangePhase (26, 27),
kFWSelfIDNPh = FWBitRange (28, 29),
kFWSelfIDNPhPhase = FWBitRangePhase (28, 29),
kFWSelfIDMore = FW_BIT(31)
};
enum
{
kFWPacketTCode = FWBitRange (24, 27),
kFWPacketTCodePhase = FWBitRangePhase (24, 27)
};
enum
{
kFWAsynchSpd = FWBitRange (14, 15),
kFWAsynchSpdPhase = FWBitRangePhase (14, 15),
kFWAsynchTLabel = FWBitRange (16, 21),
kFWAsynchTLabelPhase = FWBitRangePhase (16, 21),
kFWAsynchTTotal = ((0xffffffff & kFWAsynchTLabel) >> kFWAsynchTLabelPhase)+1,
kFWAsynchRt = FWBitRange (22, 23),
kFWAsynchRtPhase = FWBitRangePhase (22, 23),
kFWAsynchNew = 0,
kFWAsynchRetryA = 2,
kTIAsycnhRetryB = 3,
kFWAsynchPriority = FWBitRange (28, 31),
kFWAsynchPriorityPhase = FWBitRangePhase (28, 31),
kFWAsynchDestinationID = FWBitRange (0, 15),
kFWAsynchDestinationIDPhase = FWBitRangePhase (0, 15),
kFWAsynchSourceID = FWBitRange (0, 15),
kFWAsynchSourceIDPhase = FWBitRangePhase (0, 15),
kFWAsynchDestinationOffsetHigh = FWBitRange (16, 31),
kFWAsynchDestinationOffsetHighPhase = FWBitRangePhase (16, 31),
kFWAsynchDestinationOffsetLow = FWBitRange (0, 31),
kFWAsynchDestinationOffsetLowPhase = FWBitRangePhase (0, 31),
kFWAsynchDataLength = FWBitRange (0, 15),
kFWAsynchDataLengthPhase = FWBitRangePhase (0, 15),
kFWAsynchExtendedTCode = FWBitRange (16, 31),
kFWAsynchExtendedTCodePhase = FWBitRangePhase (16, 31),
kFWAsynchAckSent = FWBitRange (28, 31),
kFWAsynchAckSentPhase = FWBitRangePhase (28, 31),
kFWAsynchRCode = FWBitRange (16, 19),
kFWAsynchRCodePhase = FWBitRangePhase (16, 19)
};
enum
{
kFWTCodeWriteQuadlet = 0,
kFWTCodeWriteBlock = 1,
kFWTCodeWriteResponse = 2,
kFWTCodeReadQuadlet = 4,
kFWTCodeReadBlock = 5,
kFWTCodeReadQuadletResponse = 6,
kFWTCodeReadBlockResponse = 7,
kFWTCodeCycleStart = 8,
kFWTCodeLock = 9,
kFWTCodeIsochronousBlock = 10,
kFWTCodeLockResponse = 11,
kFWTCodePHYPacket = 14
};
enum
{
kFWExtendedTCodeMaskSwap = 1,
kFWExtendedTCodeCompareSwap = 2,
kFWExtendedTCodeFetchAdd = 3,
kFWExtendedTCodeLittleAdd = 4,
kFWExtendedTCodeBoundedAdd = 5,
kFWExtendedTCodeWrapAdd = 6,
kFWExtendedTCodeVendorDependent = 7
};
struct AsyncPendingTrans {
IOFWAsyncCommand * fHandler;
int fTCode;
bool fInUse;
};
struct IOFWNodeScan {
IOFireWireController * fControl;
FWAddress fAddr;
UInt32 fBuf[5]; UInt32 * fSelfIDs;
int fNumSelfIDs;
int fROMSize;
int fRead;
IOFWReadQuadCommand * fCmd;
UInt32 generation;
bool speedChecking;
};
#define kMaxPendingTransfers kFWAsynchTTotal
class IOFireWireController;
#pragma mark -
class IOFireWireControllerAux : public IOFireWireBusAux
{
OSDeclareDefaultStructors(IOFireWireControllerAux)
friend class IOFireWireController;
protected:
IOFireWireController * fPrimary;
struct ExpansionData { };
ExpansionData * reserved;
virtual bool init (
IOFireWireController * primary );
virtual void free ();
virtual IOFWDCLPool * createDCLPool ( unsigned capacity ) const ;
private:
OSMetaClassDeclareReservedUnused(IOFireWireControllerAux, 0);
OSMetaClassDeclareReservedUnused(IOFireWireControllerAux, 1);
OSMetaClassDeclareReservedUnused(IOFireWireControllerAux, 2);
OSMetaClassDeclareReservedUnused(IOFireWireControllerAux, 3);
OSMetaClassDeclareReservedUnused(IOFireWireControllerAux, 4);
OSMetaClassDeclareReservedUnused(IOFireWireControllerAux, 5);
OSMetaClassDeclareReservedUnused(IOFireWireControllerAux, 6);
OSMetaClassDeclareReservedUnused(IOFireWireControllerAux, 7);
};
#pragma mark -
class IOFireWireController : public IOFireWireBus
{
OSDeclareAbstractStructors(IOFireWireController)
protected:
enum busState {
kStarting = 0,
kAsleep, kWaitingBusReset,
kWaitingSelfIDs, kWaitingScan, kScanning, kWaitingPrune, kRunning };
enum ResetState
{
kResetStateResetting,
kResetStateDisabled,
kResetStateArbitrated
};
enum
{
kDisablePhysicalAccess = (1 << 0)
};
struct timeoutQ: public IOFWCmdQ
{
IOTimerEventSource *fTimer;
virtual void headChanged(IOFWCommand *oldHead);
void busReset();
};
struct pendingQ: public IOFWCmdQ
{
IOFWQEventSource *fSource;
virtual void headChanged(IOFWCommand *oldHead);
};
friend class IOFireWireLink;
friend class IOFWAddressSpace;
friend class IOFWPseudoAddressSpace;
friend class IOFireWireSBP2ORB;
friend class IOFireWireSBP2Login;
friend class IOFWLocalIsochPort;
friend class IOFWCommand;
friend class IOFireWireDevice;
friend class IOFireWirePCRSpace;
friend class IOFireWireROMCache;
friend class IOFWAsyncStreamCommand;
friend class IOFWAddressSpaceAux;
friend class IOFireWireAVCLocalUnit;
friend class IOFireWireAVCUnit;
friend class IOFireWireAVCCommand;
friend class IOFireWirePowerManager;
friend class IOFWWriteQuadCommand;
friend class IOFWWriteCommand;
friend class IOFWCompareAndSwapCommand;
#if FIRELOGCORE
friend class IOFireLog;
#endif
IOFireWireLink * fFWIM;
IOFWWorkLoop * fWorkLoop;
IOTimerEventSource * fTimer;
OSSet * fLocalAddresses; OSIterator * fSpaceIterator;
OSSet * fAllocatedChannels; OSIterator * fAllocChannelIterator;
AbsoluteTime fResetTime; UInt32 fBusGeneration; UInt16 fLocalNodeID; UInt16 fRootNodeID; UInt16 fIRMNodeID; bool fBusMgr; IORegistryEntry * fNodes[kFWMaxNodesPerBus]; UInt32 * fNodeIDs[kFWMaxNodesPerBus+1]; UInt32 fGapCount; UInt8 fSpeedCodes[(kFWMaxNodesPerBus+1)*kFWMaxNodesPerBus];
busState fBusState; int fNumROMReads; int fNumSelfIDs; UInt32 fSelfIDs[kMaxSelfIDs*kFWMaxNodesPerBus];
UInt32 fROMHeader[5]; IOLocalConfigDirectory * fRootDir;
int fMaxSendLog;
int fMaxRecvLog;
IOFWAddressSpace * fROMAddrSpace;
IOMemoryDescriptor * fBadReadResponse;
AsyncPendingTrans fTrans[kMaxPendingTransfers];
int fLastTrans;
timeoutQ fTimeoutQ;
pendingQ fPendingQ;
IOFWCmdQ fAfterResetHandledQ;
IOFWDelayCommand * fDelayedStateChangeCmd;
bool fDelayedStateChangeCmdNeedAbort;
UInt32 fDelayedPhyPacket;
bool fBusResetScheduled;
ResetState fBusResetState;
IOFWDelayCommand * fBusResetStateChangeCmd;
UInt32 fBusResetDisabledCount;
#if FIRELOGCORE
IOFireLogPublisher * fFireLogPublisher;
#else
void * fFireLogPublisher;
#endif
OSData * fAllocatedAddresses;
UInt32 fDevicePruneDelay;
IOFWPhysicalAccessMode fPhysicalAccessMode;
IOFWSecurityMode fSecurityMode;
IONotifier * fKeyswitchNotifier;
IOFireWireIRM * fIRM;
IOFireWirePowerManager * fBusPowerManager;
bool fGapCountMismatch;
UInt8 fHopCounts[(kFWMaxNodesPerBus+1)*kFWMaxNodesPerBus];
struct ExpansionData { };
ExpansionData *reserved;
static void clockTick(OSObject *, IOTimerEventSource *);
static void readROMGlue(void *refcon, IOReturn status,
IOFireWireNub *device, IOFWCommand *fwCmd);
static void delayedStateChange(void *refcon, IOReturn status,
IOFireWireBus *bus, IOFWBusCommand *fwCmd);
virtual void processBusReset();
virtual void processSelfIDs(UInt32 *IDs, int numIDs, UInt32 *ownIDs, int numOwnIDs);
virtual void processTimeout(IOTimerEventSource *src);
virtual void processRcvPacket(UInt32 *data, int numQuads);
virtual void processWriteRequest(UInt16 sourceID, UInt32 tlabel,
UInt32 *hdr, void *buf, int len);
virtual void processLockRequest(UInt16 sourceID, UInt32 tlabel,
UInt32 *hdr, void *buf, int len);
virtual UInt32 doReadSpace(UInt16 nodeID, IOFWSpeed &speed, FWAddress addr, UInt32 len,
IOMemoryDescriptor **buf, IOByteCount * offset,
IOFWRequestRefCon refcon);
virtual UInt32 doWriteSpace(UInt16 nodeID, IOFWSpeed &speed, FWAddress addr, UInt32 len,
const void *buf, IOFWRequestRefCon refcon);
UInt32 doLockSpace(UInt16 nodeID, IOFWSpeed &speed, FWAddress addr, UInt32 inlen,
const UInt32 *newVal, UInt32 &outLen, UInt32 *oldVal,
UInt32 extType, IOFWRequestRefCon refcon);
virtual void updatePlane();
virtual void startBusScan();
virtual void finishedBusScan();
virtual void buildTopology(bool doFWPlane);
virtual void readDeviceROM(IOFWNodeScan *refCon, IOReturn status);
virtual IOReturn UpdateROM();
virtual IOReturn allocAddress(IOFWAddressSpace *space);
virtual void freeAddress(IOFWAddressSpace *space);
IOFireWireBusAux * createAuxiliary( void );
public:
virtual bool init(IOFireWireLink *fwim);
virtual void free();
virtual bool start(IOService *provider);
virtual void stop( IOService * provider );
virtual bool finalize( IOOptionBits options );
virtual bool requestTerminate( IOService * provider, IOOptionBits options );
virtual IOReturn setPowerState ( unsigned long powerStateOrdinal, IOService* whatDevice );
virtual IOWorkLoop *getWorkLoop() const;
virtual AsyncPendingTrans *allocTrans(IOFWAsyncCommand *cmd=NULL);
virtual void freeTrans(AsyncPendingTrans *trans);
virtual IOReturn getCycleTime(UInt32 &cycleTime);
virtual IOReturn getBusCycleTime(UInt32 &busTime, UInt32 &cycleTime);
virtual IOReturn AddUnitDirectory(IOLocalConfigDirectory *unitDir);
virtual IOReturn RemoveUnitDirectory(IOLocalConfigDirectory *unitDir);
virtual IOReturn resetBus();
virtual IOReturn asyncRead( UInt32 generation,
UInt16 nodeID,
UInt16 addrHi,
UInt32 addrLo,
int speed,
int label,
int size,
IOFWAsyncCommand * cmd );
virtual IOReturn asyncWrite( UInt32 generation,
UInt16 nodeID,
UInt16 addrHi,
UInt32 addrLo,
int speed,
int label,
IOMemoryDescriptor * buf,
IOByteCount offset,
int size,
IOFWAsyncCommand * cmd );
virtual IOReturn asyncWrite( UInt32 generation,
UInt16 nodeID,
UInt16 addrHi,
UInt32 addrLo,
int speed,
int label,
void * data,
int size,
IOFWAsyncCommand * cmd );
virtual IOReturn asyncLock( UInt32 generation,
UInt16 nodeID,
UInt16 addrHi,
UInt32 addrLo,
int speed,
int label,
int type,
void * data,
int size,
IOFWAsyncCommand * cmd);
virtual IOReturn asyncReadResponse( UInt32 generation,
UInt16 nodeID,
int speed,
IOMemoryDescriptor * buf,
IOByteCount offset,
int len,
IOFWRequestRefCon refcon );
virtual IOReturn asyncLockResponse( UInt32 generation,
UInt16 nodeID,
int speed,
IOMemoryDescriptor * buf,
IOByteCount offset,
int len,
IOFWRequestRefCon refcon );
virtual IOReturn handleAsyncTimeout(IOFWAsyncCommand *cmd);
virtual IOFireWireDevice * nodeIDtoDevice(UInt32 generation, UInt16 nodeID);
virtual void addAllocatedChannel(IOFWIsochChannel *channel);
virtual void removeAllocatedChannel(IOFWIsochChannel *channel);
virtual IOFWIsochChannel *createIsochChannel(
bool doIRM, UInt32 packetSize, IOFWSpeed prefSpeed,
FWIsochChannelForceStopNotificationProc stopProc=NULL,
void *stopRefCon=NULL);
virtual IOFWLocalIsochPort *createLocalIsochPort(bool talking,
DCLCommand* opcodes, DCLTaskInfo *info = 0,
UInt32 startEvent = 0, UInt32 startState = 0, UInt32 startMask = 0);
virtual IOFWDelayCommand * createDelayedCmd(UInt32 uSecDelay, FWBusCallback func, void *refcon);
virtual IOFWPhysicalAddressSpace *createPhysicalAddressSpace(IOMemoryDescriptor *mem);
virtual IOFWPseudoAddressSpace *createPseudoAddressSpace(FWAddress *addr, UInt32 len,
FWReadCallback reader, FWWriteCallback writer, void *refcon);
virtual bool isLockRequest(IOFWRequestRefCon refcon);
virtual bool isQuadRequest(IOFWRequestRefCon refcon);
virtual UInt32 getExtendedTCode(IOFWRequestRefCon refcon);
IOFWCmdQ &getTimeoutQ();
IOFWCmdQ &getPendingQ();
IOFWCmdQ &getAfterResetHandledQ();
IOFireWireLink * getLink() const;
IOLocalConfigDirectory *getRootDir() const;
bool checkGeneration(UInt32 gen) const;
UInt32 getGeneration() const;
UInt16 getLocalNodeID() const;
IOReturn getIRMNodeID(UInt32 &generation, UInt16 &id) const;
const AbsoluteTime * getResetTime() const;
IOFWSpeed FWSpeed(UInt16 nodeAddress) const;
IOFWSpeed FWSpeed(UInt16 nodeA, UInt16 nodeB) const;
virtual int maxPackLog(bool forSend, UInt16 nodeAddress) const;
virtual int maxPackLog(UInt16 nodeA, UInt16 nodeB) const;
virtual IOReturn makeRoot(UInt32 generation, UInt16 nodeID) ;
virtual IOFWPseudoAddressSpace *createInitialAddressSpace(UInt32 addressLo, UInt32 len,
FWReadCallback reader, FWWriteCallback writer, void *refcon);
virtual IOFWAddressSpace *getAddressSpace(FWAddress address);
virtual bool isCompleteRequest(IOFWRequestRefCon refcon);
bool scanningBus() const;
protected:
void openGate();
void closeGate();
protected:
virtual void doBusReset( void );
static void resetStateChange( void *refcon, IOReturn status,
IOFireWireBus *bus, IOFWBusCommand *fwCmd);
public:
virtual IOReturn disableSoftwareBusResets( void );
virtual void enableSoftwareBusResets( void );
virtual IOFWAsyncStreamCommand * createAsyncStreamCommand( UInt32 generation,
UInt32 channel, UInt32 sync, UInt32 tag, IOMemoryDescriptor *hostMem,
UInt32 size, int speed,FWAsyncStreamCallback completion, void *refcon);
virtual IOReturn asyncStreamWrite(UInt32 generation,
int speed, int tag, int sync, int channel,
IOMemoryDescriptor *buf, IOByteCount offset,
int size, IOFWAsyncStreamCommand *cmd);
protected:
bool inGate();
virtual IOReturn allocatePseudoAddress(FWAddress *addr, UInt32 lenDummy);
virtual void freePseudoAddress(FWAddress addr, UInt32 lenDummy);
virtual IORegistryEntry * createDummyRegistryEntry( IOFWNodeScan *scan );
static IOFireWireLocalNode * getLocalNode(IOFireWireController *control);
virtual void setPhysicalAccessMode( IOFWPhysicalAccessMode mode );
virtual IOFWPhysicalAccessMode getPhysicalAccessMode( void );
virtual void physicalAccessProcessBusReset( void );
virtual void setNodeIDPhysicalFilter( UInt16 nodeID, bool state );
virtual void initSecurity( void );
virtual void freeSecurity( void );
static bool serverKeyswitchCallback( void * target, void * refCon, IOService * service );
virtual void setSecurityMode( IOFWSecurityMode mode );
virtual IOFWSecurityMode getSecurityMode( void );
virtual IOReturn createTimeoutQ( void );
virtual void destroyTimeoutQ( void );
virtual IOReturn createPendingQ( void );
virtual void destroyPendingQ( void );
virtual UInt32 countNodeIDChildren( UInt16 nodeID );
public:
virtual UInt32 hopCount(UInt16 nodeAAddress, UInt16 nodeBAddress );
virtual UInt32 hopCount(UInt16 nodeAAddress );
virtual IOFireWirePowerManager * getBusPowerManager( void );
protected:
virtual void handleARxReqIntComplete();
virtual IOReturn asyncLock( UInt32 generation,
UInt16 nodeID,
UInt16 addrHi,
UInt32 addrLo,
int speed,
int label,
int type,
IOMemoryDescriptor * buf,
IOByteCount offset,
int size,
IOFWAsyncCommand * cmd );
virtual IOReturn asyncWrite( UInt32 generation,
UInt16 nodeID,
UInt16 addrHi,
UInt32 addrLo,
int speed,
int label,
IOMemoryDescriptor * buf,
IOByteCount offset,
int size,
IOFWAsyncCommand * cmd,
IOFWWriteFlags flags );
protected:
bool delayedStateCommandInUse() const;
void enterBusResetDisabledState( );
public:
IOReturn clipMaxRec2K(Boolean clipMaxRec );
private:
OSMetaClassDeclareReservedUnused(IOFireWireController, 0);
OSMetaClassDeclareReservedUnused(IOFireWireController, 1);
OSMetaClassDeclareReservedUnused(IOFireWireController, 2);
OSMetaClassDeclareReservedUnused(IOFireWireController, 3);
OSMetaClassDeclareReservedUnused(IOFireWireController, 4);
OSMetaClassDeclareReservedUnused(IOFireWireController, 5);
OSMetaClassDeclareReservedUnused(IOFireWireController, 6);
OSMetaClassDeclareReservedUnused(IOFireWireController, 7);
OSMetaClassDeclareReservedUnused(IOFireWireController, 8);
};
#endif