IOFireWireController.h [plain text]
#ifndef _IOKIT_IOFIREWIRECONTROLLER_H
#define _IOKIT_IOFIREWIRECONTROLLER_H
#include <IOKit/IOEventSource.h>
#include <IOKit/firewire/IOFWWorkLoop.h>
#include <IOKit/firewire/IOFireWireBus.h>
class OSData;
class IOWorkLoop;
class IOEventSource;
class IOFWQEventSource;
class IOTimerEventSource;
class IOMemoryDescriptor;
class IOFireWireController;
class IOFWAddressSpace;
class IOFireWireNub;
class IOFireWireDevice;
class IOFireWireUnit;
class IODCLProgram;
class IOLocalConfigDirectory;
class IOFireWireLink;
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;
};
class IOFWQEventSource : public IOEventSource
{
OSDeclareDefaultStructors(IOFWQEventSource)
protected:
IOFWCmdQ *fQueue;
virtual bool checkForWork();
public:
bool init(IOFireWireController *owner);
#if 0 // Cheetah4F8-
inline void signalWorkAvailable() {workLoop->signalWorkAvailable();};
inline void openGate() {workLoop->openGate();};
inline void closeGate() {workLoop->closeGate();};
#else // Cheetah4G+
inline void signalWorkAvailable() {IOEventSource::signalWorkAvailable();};
inline void openGate() {IOEventSource::openGate();};
inline void closeGate() {IOEventSource::closeGate();};
#endif
};
#define kMaxPendingTransfers kFWAsynchTTotal
class IOFireWireController : public IOFireWireBus
{
OSDeclareAbstractStructors(IOFireWireController)
protected:
enum busState {
kAsleep = 0, kWaitingSelfIDs, kWaitingScan, kScanning, kWaitingPrune, kPendingReset, kRunning };
struct timeoutQ: public IOFWCmdQ
{
IOTimerEventSource *fTimer;
virtual void headChanged(IOFWCommand *oldHead);
};
struct pendingQ: public IOFWCmdQ
{
IOFWQEventSource *fSource;
virtual void headChanged(IOFWCommand *oldHead);
};
friend class IOFireWireLink;
friend class IOFWAddressSpace;
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;
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);
public:
virtual bool init(IOFireWireLink *fwim);
virtual bool start(IOService *provider);
virtual void stop( IOService * provider );
virtual bool finalize( 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 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,
DCLCommandStruct *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() { return fTimeoutQ; };
IOFWCmdQ &getPendingQ() { return fPendingQ; };
IOFWCmdQ &getAfterResetHandledQ() { return fAfterResetHandledQ; };
IOFireWireLink * getLink() const { return fFWIM; };
IOLocalConfigDirectory *getRootDir() const { return fRootDir;};
bool checkGeneration(UInt32 gen) const {return gen == fBusGeneration;};
UInt32 getGeneration() const {return fBusGeneration;};
UInt16 getLocalNodeID() const {
return fLocalNodeID;
};
IOReturn getIRMNodeID(UInt32 &generation, UInt16 &id) const
{generation = fBusGeneration; id = fIRMNodeID; return kIOReturnSuccess;};
const AbsoluteTime * getResetTime() const {return &fResetTime;};
IOFWSpeed FWSpeed(UInt16 nodeAddress) const
{return (IOFWSpeed)fSpeedCodes[(kFWMaxNodesPerBus+1)*(nodeAddress & 63)+(fLocalNodeID & 63)];};
IOFWSpeed FWSpeed(UInt16 nodeA, UInt16 nodeB) const
{return (IOFWSpeed)fSpeedCodes[(kFWMaxNodesPerBus+1)*(nodeA & 63)+(nodeB & 63)];};
virtual int maxPackLog(bool forSend, UInt16 nodeAddress) const;
virtual int maxPackLog(UInt16 nodeA, UInt16 nodeB) const;
virtual IOReturn makeRoot(UInt32 generation, UInt16 nodeID) ;
bool scanningBus() const
{return fBusState == kWaitingSelfIDs || fBusState == kWaitingScan || fBusState == kScanning;};
inline void openGate() {fPendingQ.fSource->openGate();};
inline void closeGate() {fPendingQ.fSource->closeGate();};
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