IOFWSimpleContiguousPhysicalAddressSpace.cpp [plain text]
#import <IOKit/IOLib.h>
#include "IOFWSimpleContiguousPhysicalAddressSpace.h"
OSDefineMetaClassAndStructors( IOFWSimpleContiguousPhysicalAddressSpace, IOFWSimplePhysicalAddressSpace )
OSMetaClassDefineReservedUnused(IOFWSimpleContiguousPhysicalAddressSpace, 0);
OSMetaClassDefineReservedUnused(IOFWSimpleContiguousPhysicalAddressSpace, 1);
OSMetaClassDefineReservedUnused(IOFWSimpleContiguousPhysicalAddressSpace, 2);
OSMetaClassDefineReservedUnused(IOFWSimpleContiguousPhysicalAddressSpace, 3);
OSMetaClassDefineReservedUnused(IOFWSimpleContiguousPhysicalAddressSpace, 4);
OSMetaClassDefineReservedUnused(IOFWSimpleContiguousPhysicalAddressSpace, 5);
OSMetaClassDefineReservedUnused(IOFWSimpleContiguousPhysicalAddressSpace, 6);
OSMetaClassDefineReservedUnused(IOFWSimpleContiguousPhysicalAddressSpace, 7);
OSMetaClassDefineReservedUnused(IOFWSimpleContiguousPhysicalAddressSpace, 8);
OSMetaClassDefineReservedUnused(IOFWSimpleContiguousPhysicalAddressSpace, 9);
struct MemberVariables
{
FWAddress fFWPhysicalAddress;
};
#define _members ((MemberVariables*)fSimpleContigPhysSpaceMembers)
bool IOFWSimpleContiguousPhysicalAddressSpace::init( IOFireWireBus * control, vm_size_t size, IODirection direction )
{
fSimpleContigPhysSpaceMembers = NULL;
bool success = IOFWSimplePhysicalAddressSpace::init( control, size, direction, true );
if( success )
{
IOReturn status = cachePhysicalAddress();
if( status != kIOReturnSuccess )
success = false;
}
return success;
}
void IOFWSimpleContiguousPhysicalAddressSpace::free( void )
{
IOFWSimplePhysicalAddressSpace::free();
}
bool IOFWSimpleContiguousPhysicalAddressSpace::createMemberVariables( void )
{
bool success = true;
success = IOFWSimplePhysicalAddressSpace::createMemberVariables();
if( success && (fSimpleContigPhysSpaceMembers == NULL) )
{
if( success )
{
fSimpleContigPhysSpaceMembers = IOMalloc( sizeof(MemberVariables) );
if( fSimpleContigPhysSpaceMembers == NULL )
success = false;
}
if( success )
{
bzero( fSimpleContigPhysSpaceMembers, sizeof(MemberVariables) );
_members->fFWPhysicalAddress.nodeID = 0x0000;
_members->fFWPhysicalAddress.addressHi = 0x0000;
_members->fFWPhysicalAddress.addressLo = 0x00000000;
}
if( !success )
{
destroyMemberVariables();
}
}
return success;
}
void IOFWSimpleContiguousPhysicalAddressSpace::destroyMemberVariables( void )
{
IOFWSimplePhysicalAddressSpace::destroyMemberVariables();
if( fSimpleContigPhysSpaceMembers != NULL )
{
IOFree( fSimpleContigPhysSpaceMembers, sizeof(MemberVariables) );
fSimpleContigPhysSpaceMembers = NULL;
}
}
#pragma mark -
IOReturn IOFWSimpleContiguousPhysicalAddressSpace::cachePhysicalAddress( void )
{
IOReturn status = kIOReturnSuccess;
UInt32 segment_count = 0;
FWSegment segments[ 2 ];
if( status == kIOReturnSuccess )
{
UInt64 offset_64 = 0;
segment_count = 2;
status = getSegments( &offset_64, segments, &segment_count );
}
if( status == kIOReturnSuccess )
{
if( segment_count > 2 || segment_count == 0 )
{
status = kIOReturnNoResources;
}
}
if( status == kIOReturnSuccess )
{
if( segments[0].length < getLength() )
{
status = kIOReturnNoResources;
}
}
if( status == kIOReturnSuccess )
{
_members->fFWPhysicalAddress = segments[0].address;
}
return status;
}
FWAddress IOFWSimpleContiguousPhysicalAddressSpace::getFWAddress( void )
{
return _members->fFWPhysicalAddress;
}