AppleGenericPCATAController.cpp [plain text]
#include "AppleGenericPCATAController.h"
#include "AppleGenericPCATAKeys.h"
#define super IOService
OSDefineMetaClassAndStructors( AppleGenericPCATAController, IOService )
static bool
getOSNumberValue( const OSDictionary * dict,
const char * key,
UInt32 * outValue )
{
OSNumber * num = OSDynamicCast( OSNumber, dict->getObject( key ) );
if ( num )
{
*outValue = num->unsigned32BitValue();
return true;
}
return false;
}
bool
AppleGenericPCATAController::setupInterrupt( UInt32 line )
{
OSArray * controller = 0;
OSArray * specifier = 0;
OSData * tmpData = 0;
bool ret = false;
extern OSSymbol * gIntelPICName;
do {
specifier = OSArray::withCapacity(1);
if ( !specifier ) break;
tmpData = OSData::withBytes( &line, sizeof(line) );
if ( !tmpData ) break;
specifier->setObject( tmpData );
controller = OSArray::withCapacity(1);
if ( !controller ) break;
controller->setObject( gIntelPICName );
ret = setProperty( gIOInterruptControllersKey, controller )
&& setProperty( gIOInterruptSpecifiersKey, specifier );
}
while( false );
if ( controller ) controller->release();
if ( specifier ) specifier->release();
if ( tmpData ) tmpData->release();
return ret;
}
bool
AppleGenericPCATAController::init( OSDictionary * dictionary )
{
if ( super::init(dictionary) == false )
return false;
if ( !getOSNumberValue( dictionary, kPortAddressKey, &_ioPorts )
|| !getOSNumberValue( dictionary, kInterruptLineKey, &_irq )
|| !getOSNumberValue( dictionary, kPIOModeKey, &_pioMode )
) return false;
if ( !setupInterrupt( _irq ) )
return false;
return true;
}
bool
AppleGenericPCATAController::handleOpen( IOService * client,
IOOptionBits options,
void * arg )
{
bool ret = false;
if ( _provider && _provider->open( this, 0, arg ) )
{
ret = super::handleOpen( client, options, arg );
if ( ret == false )
_provider->close( this );
}
return ret;
}
void
AppleGenericPCATAController::handleClose( IOService * client,
IOOptionBits options )
{
super::handleClose( client, options );
if ( _provider ) _provider->close( this );
}
bool
AppleGenericPCATAController::attachToParent( IORegistryEntry * parent,
const IORegistryPlane * plane )
{
bool ret = super::attachToParent( parent, plane );
if ( ret && (plane == gIOServicePlane) )
_provider = (IOService *) parent;
return ret;
}
void
AppleGenericPCATAController::detachFromParent( IORegistryEntry * parent,
const IORegistryPlane * plane )
{
if ( plane == gIOServicePlane ) _provider = 0;
return super::detachFromParent( parent, plane );
}
UInt32
AppleGenericPCATAController::getIOPorts() const
{
return _ioPorts;
}
UInt32
AppleGenericPCATAController::getInterruptLine() const
{
return _irq;
}
UInt32
AppleGenericPCATAController::getPIOMode() const
{
return _pioMode;
}