-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-#undef super
-#define super IOMemoryDescriptor
-
-OSDefineMetaClassAndStructors(IOSubMemoryDescriptor, IOMemoryDescriptor)
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-bool IOSubMemoryDescriptor::initSubRange( IOMemoryDescriptor * parent,
- IOByteCount offset, IOByteCount length,
- IODirection direction )
-{
- if( !parent)
- return( false);
-
- if( (offset + length) > parent->getLength())
- return( false);
-
- /*
- * We can check the _parent instance variable before having ever set it
- * to an initial value because I/O Kit guarantees that all our instance
- * variables are zeroed on an object's allocation.
- */
-
- if( !_parent) {
- if( !super::init())
- return( false );
- } else {
- /*
- * An existing memory descriptor is being retargeted to
- * point to somewhere else. Clean up our present state.
- */
-
- _parent->release();
- _parent = 0;
- }
-
- parent->retain();
- _parent = parent;
- _start = offset;
- _length = length;
- _direction = direction;
- _tag = parent->getTag();
-
- return( true );
-}
-
-void IOSubMemoryDescriptor::free( void )
-{
- if( _parent)
- _parent->release();
-
- super::free();
-}
-
-
-IOReturn
-IOSubMemoryDescriptor::dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const
-{
- IOReturn rtn;
-
- if (kIOMDGetCharacteristics == op) {
-
- rtn = _parent->dmaCommandOperation(op, vData, dataSize);
- if (kIOReturnSuccess == rtn) {
- IOMDDMACharacteristics *data = (IOMDDMACharacteristics *) vData;
- data->fLength = _length;
- data->fSGCount = 0; // XXX gvdl: need to compute and pages
- data->fPages = 0;
- data->fPageAlign = 0;
- }
-
- return rtn;
- }
- else if (kIOMDWalkSegments & op) {
- if (dataSize < sizeof(IOMDDMAWalkSegmentArgs))
- return kIOReturnUnderrun;
-
- IOMDDMAWalkSegmentArgs *data =
- reinterpret_cast<IOMDDMAWalkSegmentArgs *>(vData);
- UInt offset = data->fOffset;
- UInt remain = _length - offset;
- if ((int) remain <= 0)
- return (!remain)? kIOReturnOverrun : kIOReturnInternalError;
-
- data->fOffset = offset + _start;
- rtn = _parent->dmaCommandOperation(op, vData, dataSize);
- if (data->fLength > remain)
- data->fLength = remain;
- data->fOffset = offset;
-
- return rtn;
- }
- else
- return kIOReturnBadArgument;
-}
-
-addr64_t
-IOSubMemoryDescriptor::getPhysicalSegment64(IOByteCount offset, IOByteCount * length)
-{
- addr64_t address;
- IOByteCount actualLength;
-
- assert(offset <= _length);
-
- if( length)
- *length = 0;
-
- if( offset >= _length)
- return( 0 );
-
- address = _parent->getPhysicalSegment64( offset + _start, &actualLength );
-
- if( address && length)
- *length = min( _length - offset, actualLength );
-
- return( address );
-}
-
-IOPhysicalAddress
-IOSubMemoryDescriptor::getPhysicalSegment( IOByteCount offset, IOByteCount * length )
-{
- IOPhysicalAddress address;
- IOByteCount actualLength;
-
- assert(offset <= _length);
-
- if( length)
- *length = 0;
-
- if( offset >= _length)
- return( 0 );
-
- address = _parent->getPhysicalSegment( offset + _start, &actualLength );
-
- if( address && length)
- *length = min( _length - offset, actualLength );
-
- return( address );
-}
-
-IOPhysicalAddress
-IOSubMemoryDescriptor::getSourceSegment( IOByteCount offset, IOByteCount * length )
-{
- IOPhysicalAddress address;
- IOByteCount actualLength;
-
- assert(offset <= _length);
-
- if( length)
- *length = 0;
-
- if( offset >= _length)
- return( 0 );
-
- address = _parent->getSourceSegment( offset + _start, &actualLength );
-
- if( address && length)
- *length = min( _length - offset, actualLength );
-
- return( address );
-}
-
-void * IOSubMemoryDescriptor::getVirtualSegment(IOByteCount offset,
- IOByteCount * lengthOfSegment)
-{
- return( 0 );
-}
-
-IOReturn IOSubMemoryDescriptor::doMap(
- vm_map_t addressMap,
- IOVirtualAddress * atAddress,
- IOOptionBits options,
- IOByteCount sourceOffset,
- IOByteCount length )
-{
- panic("IOSubMemoryDescriptor::doMap");
- return (IOMemoryDescriptor::doMap(addressMap, atAddress, options, sourceOffset, length));
-}
-
-IOByteCount IOSubMemoryDescriptor::readBytes(IOByteCount offset,
- void * bytes, IOByteCount length)
-{
- IOByteCount byteCount;
-
- assert(offset <= _length);
-
- if( offset >= _length)
- return( 0 );
-
- LOCK;
- byteCount = _parent->readBytes( _start + offset, bytes,
- min(length, _length - offset) );
- UNLOCK;
-
- return( byteCount );
-}
-
-IOByteCount IOSubMemoryDescriptor::writeBytes(IOByteCount offset,
- const void* bytes, IOByteCount length)
-{
- IOByteCount byteCount;
-
- assert(offset <= _length);
-
- if( offset >= _length)
- return( 0 );
-
- LOCK;
- byteCount = _parent->writeBytes( _start + offset, bytes,
- min(length, _length - offset) );
- UNLOCK;
-
- return( byteCount );
-}
-
-IOReturn IOSubMemoryDescriptor::setPurgeable( IOOptionBits newState,
- IOOptionBits * oldState )
-{
- IOReturn err;
-
- LOCK;
- err = _parent->setPurgeable( newState, oldState );
- UNLOCK;
-
- return( err );
-}
-
-IOReturn IOSubMemoryDescriptor::performOperation( IOOptionBits options,
- IOByteCount offset, IOByteCount length )
-{
- IOReturn err;
-
- assert(offset <= _length);
-
- if( offset >= _length)
- return( kIOReturnOverrun );
-
- LOCK;
- err = _parent->performOperation( options, _start + offset,
- min(length, _length - offset) );
- UNLOCK;
-
- return( err );
-}
-
-IOReturn IOSubMemoryDescriptor::prepare(
- IODirection forDirection)
-{
- IOReturn err;
-
- LOCK;
- err = _parent->prepare( forDirection);
- UNLOCK;
-
- return( err );
-}
-
-IOReturn IOSubMemoryDescriptor::complete(
- IODirection forDirection)
-{
- IOReturn err;
-
- LOCK;
- err = _parent->complete( forDirection);
- UNLOCK;
-
- return( err );
-}
-
-IOMemoryMap * IOSubMemoryDescriptor::makeMapping(
- IOMemoryDescriptor * owner,
- task_t intoTask,
- IOVirtualAddress address,
- IOOptionBits options,
- IOByteCount offset,
- IOByteCount length )
-{
- IOMemoryMap * mapping = 0;
-
- if (!(kIOMap64Bit & options))
- {
- panic("IOSubMemoryDescriptor::makeMapping !64bit");
- }
-
- mapping = (IOMemoryMap *) _parent->makeMapping(
- owner,
- intoTask,
- address,
- options, _start + offset, length );
-
- return( mapping );
-}
-
-/* ick */
-