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( IOService *provider, UInt32 line )
{
if (_irqSet) return true;
IOReturn ret = provider->callPlatformFunction( "SetDeviceInterrupts",
false,
this,
(void *) &line,
(void *) 1,
(void *) false );
if (ret == kIOReturnSuccess) {
_irqSet = true;
return true;
} else {
return false;
}
}
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;
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;
if ( !setupInterrupt( parent, _irq ) )
return false;
}
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;
}