IOFireWireUnit.cpp [plain text]
#define DEBUGGING_LEVEL 0 // 1 = low; 2 = high; 3 = extreme
#define DEBUGLOG kprintf
#include <IOKit/assert.h>
#include <IOKit/IOMessage.h>
#include <IOKit/firewire/IOFireWireUnit.h>
#include <IOKit/firewire/IOFireWireDevice.h>
#include <IOKit/firewire/IOFireWireController.h>
#include <IOKit/firewire/IOConfigDirectory.h>
OSDefineMetaClassAndStructors(IOFireWireUnitAux, IOFireWireNubAux);
OSMetaClassDefineReservedUnused(IOFireWireUnitAux, 0);
OSMetaClassDefineReservedUnused(IOFireWireUnitAux, 1);
OSMetaClassDefineReservedUnused(IOFireWireUnitAux, 2);
OSMetaClassDefineReservedUnused(IOFireWireUnitAux, 3);
#pragma mark -
bool IOFireWireUnitAux::init( IOFireWireUnit * primary )
{
bool success = true;
if( !IOFireWireNubAux::init( primary ) )
success = false;
if( success )
{
}
return success;
}
void IOFireWireUnitAux::free()
{
IOFireWireNubAux::free();
}
#pragma mark -
OSDefineMetaClassAndStructors(IOFireWireUnit, IOFireWireNub)
OSMetaClassDefineReservedUnused(IOFireWireUnit, 0);
OSMetaClassDefineReservedUnused(IOFireWireUnit, 1);
#pragma mark -
bool IOFireWireUnit::init( OSDictionary *propTable, IOConfigDirectory *directory )
{
if(!IOFireWireNub::init(propTable))
return false;
directory->retain();
fDirectory = directory;
return true;
}
IOFireWireNubAux * IOFireWireUnit::createAuxiliary( void )
{
IOFireWireUnitAux * auxiliary;
auxiliary = new IOFireWireUnitAux;
if( auxiliary != NULL && !auxiliary->init(this) )
{
auxiliary->release();
auxiliary = NULL;
}
return auxiliary;
}
bool IOFireWireUnit::attach( IOService *provider )
{
fDevice = OSDynamicCast(IOFireWireDevice, provider);
if(!fDevice)
return false;
fDevice->retain();
if( !IOFireWireNub::attach(provider))
return (false);
fControl = fDevice->getController();
fControl->retain();
fDevice->getNodeIDGeneration(fGeneration, fNodeID, fLocalNodeID);
return(true);
}
void IOFireWireUnit::free()
{
if( fDevice != NULL )
{
fDevice->release();
fDevice = NULL;
}
IOFireWireNub::free();
}
IOReturn IOFireWireUnit::message( UInt32 mess,
IOService * provider,
void * argument )
{
if(provider == fDevice &&
(kIOMessageServiceIsResumed == mess ||
kIOMessageServiceIsSuspended == mess ||
kIOMessageServiceIsRequestingClose == mess ||
kIOFWMessageServiceIsRequestingClose == mess))
{
fDevice->getNodeIDGeneration(fGeneration, fNodeID, fLocalNodeID);
messageClients( mess );
return kIOReturnSuccess;
}
if( kIOFWMessagePowerStateChanged == mess )
{
messageClients( mess );
return kIOReturnSuccess;
}
if( kIOFWMessageTopologyChanged == mess )
{
messageClients( mess );
return kIOReturnSuccess;
}
return IOService::message(mess, provider, argument );
}
bool IOFireWireUnit::matchPropertyTable( OSDictionary * table )
{
if (!IOFireWireNub::matchPropertyTable(table)) return false;
bool res = compareProperty(table, gFireWireUnit_Spec_ID) &&
compareProperty(table, gFireWireUnit_SW_Version) &&
compareProperty(table, gFireWireVendor_ID) &&
compareProperty(table, gFireWire_GUID);
return res;
}
#pragma mark -
bool IOFireWireUnit::handleOpen( IOService * forClient,
IOOptionBits options,
void * arg )
{
if ( isOpen() )
return false ;
bool ok;
ok = fDevice->open(this, options, arg);
if(ok)
ok = IOFireWireNub::handleOpen(forClient, options, arg);
return ok;
}
void IOFireWireUnit::handleClose( IOService * forClient,
IOOptionBits options )
{
IOFireWireNub::handleClose(forClient, options);
fDevice->close(this, options);
}
#pragma mark -
void IOFireWireUnit::setNodeFlags( UInt32 flags )
{
if( fDevice )
fDevice->setNodeFlags( flags );
}
void IOFireWireUnit::clearNodeFlags( UInt32 flags )
{
if( fDevice )
fDevice->clearNodeFlags( flags );
}
UInt32 IOFireWireUnit::getNodeFlags( void )
{
if( fDevice )
return fDevice->getNodeFlags();
else
return 0;
}
void IOFireWireUnit::setMaxSpeed( IOFWSpeed speed )
{
if( fDevice )
fDevice->setMaxSpeed( speed );
}
#pragma mark -
IOFWPhysicalAddressSpace * IOFireWireUnit::createPhysicalAddressSpace( IOMemoryDescriptor *mem )
{
IOFWPhysicalAddressSpace * space = fControl->createPhysicalAddressSpace(mem);
if( space != NULL )
{
space->addTrustedNode( fDevice );
}
return space;
}
IOFWPseudoAddressSpace * IOFireWireUnit::createPseudoAddressSpace( FWAddress * addr,
UInt32 len,
FWReadCallback reader,
FWWriteCallback writer,
void * refcon )
{
IOFWPseudoAddressSpace * space = fControl->createPseudoAddressSpace(addr, len, reader, writer, refcon);
if( space != NULL )
{
space->addTrustedNode( fDevice );
}
return space;
}