]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOMultiMemoryDescriptor.cpp
xnu-1504.3.12.tar.gz
[apple/xnu.git] / iokit / Kernel / IOMultiMemoryDescriptor.cpp
index 3e31f16b8560d8d83cec5b7004d078a40dcede7d..262680dc8a4bd21055fd967d2f2f30a388af1521 100644 (file)
@@ -1,16 +1,19 @@
 /*
  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * This file contains Original Code and/or Modifications of Original Code
  * as defined in and that are subject to the Apple Public Source License
  * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ * 
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
  * 
  * The Original Code and all software distributed under the License are
  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
@@ -20,7 +23,7 @@
  * Please see the License for the specific language governing rights and
  * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 
 #include <IOKit/IOLib.h>
 #define super IOMemoryDescriptor
 OSDefineMetaClassAndStructors(IOMultiMemoryDescriptor, IOMemoryDescriptor)
 
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-bool IOMultiMemoryDescriptor::initWithAddress(
-                                  void *      /* address       */ ,
-                                  IOByteCount /* withLength    */ ,
-                                  IODirection /* withDirection */ )
-{
-    return false;
-}
-
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-bool IOMultiMemoryDescriptor::initWithAddress(
-                                  vm_address_t /* address       */ ,
-                                  IOByteCount  /* withLength    */ ,
-                                  IODirection  /* withDirection */ ,
-                                  task_t       /* withTask      */ )
-{
-    return false;
-}
-
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-bool IOMultiMemoryDescriptor::initWithPhysicalAddress(
-                                  IOPhysicalAddress /* address       */ ,
-                                  IOByteCount       /* withLength    */ ,
-                                  IODirection       /* withDirection */ )
-{
-    return false;
-}
-
-
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-bool IOMultiMemoryDescriptor::initWithPhysicalRanges(
-                                  IOPhysicalRange * /* ranges        */ ,
-                                  UInt32            /* withCount     */ ,
-                                  IODirection       /* withDirection */ ,
-                                  bool              /* asReference   */ )
-{
-    return false;
-}
-
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-bool IOMultiMemoryDescriptor::initWithRanges(
-                                  IOVirtualRange * /* ranges        */ ,
-                                  UInt32           /* withCount     */ ,
-                                  IODirection      /* withDirection */ ,
-                                  task_t           /* withTask      */ ,
-                                  bool             /* asReference   */ )
-{
-    return false;
-}
-
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
 IOMultiMemoryDescriptor * IOMultiMemoryDescriptor::withDescriptors(
                                   IOMemoryDescriptor ** descriptors,
                                   UInt32                withCount,
                                   IODirection           withDirection,
-                                  bool                  asReference = false )
+                                  bool                  asReference )
 {
     //
     // Create a new IOMultiMemoryDescriptor.  The "buffer" is made up of several
@@ -115,13 +61,11 @@ IOMultiMemoryDescriptor * IOMultiMemoryDescriptor::withDescriptors(
     return me;
 }
 
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
 bool IOMultiMemoryDescriptor::initWithDescriptors(
                                   IOMemoryDescriptor ** descriptors,
                                   UInt32                withCount,
                                   IODirection           withDirection,
-                                  bool                  asReference = false )
+                                  bool                  asReference )
 {
     //
     // Initialize an IOMultiMemoryDescriptor. The "buffer" is made up of several
@@ -134,16 +78,28 @@ bool IOMultiMemoryDescriptor::initWithDescriptors(
     assert(descriptors);
     assert(withCount);
 
-    // Ask our superclass' opinion.
-
-    if ( super::init() == false )  return false;
+    // Release existing descriptors, if any
+    if ( _descriptors )
+    {
+        for ( unsigned index = 0; index < _descriptorsCount; index++ ) 
+            _descriptors[index]->release();
 
+        if ( _descriptorsIsAllocated )
+            IODelete(_descriptors, IOMemoryDescriptor *, _descriptorsCount);
+    } else {
+        // Ask our superclass' opinion.
+        if ( super::init() == false )  return false;
+    }
+    
     // Initialize our minimal state.
 
     _descriptors            = 0;
     _descriptorsCount       = withCount;
     _descriptorsIsAllocated = asReference ? false : true;
-    _direction              = withDirection;
+    _flags                  = withDirection;
+#ifndef __LP64__
+    _direction              = (IODirection) (_flags & kIOMemoryDirectionMask);
+#endif /* !__LP64__ */
     _length                 = 0;
     _mappings               = 0;
     _tag                    = 0;
@@ -173,8 +129,6 @@ bool IOMultiMemoryDescriptor::initWithDescriptors(
     return true;
 }
 
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
 void IOMultiMemoryDescriptor::free()
 {
     //
@@ -193,8 +147,6 @@ void IOMultiMemoryDescriptor::free()
     super::free();
 }
 
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
 IOReturn IOMultiMemoryDescriptor::prepare(IODirection forDirection)
 {
     //
@@ -211,7 +163,7 @@ IOReturn IOMultiMemoryDescriptor::prepare(IODirection forDirection)
 
     if ( forDirection == kIODirectionNone )
     {
-        forDirection = _direction;
+        forDirection = getDirection();
     }
 
     for ( index = 0; index < _descriptorsCount; index++ ) 
@@ -232,8 +184,6 @@ IOReturn IOMultiMemoryDescriptor::prepare(IODirection forDirection)
     return status;
 }
 
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
 IOReturn IOMultiMemoryDescriptor::complete(IODirection forDirection)
 {
     //
@@ -249,7 +199,7 @@ IOReturn IOMultiMemoryDescriptor::complete(IODirection forDirection)
 
     if ( forDirection == kIODirectionNone )
     {
-        forDirection = _direction;
+        forDirection = getDirection();
     }
 
     for ( unsigned index = 0; index < _descriptorsCount; index++ ) 
@@ -262,11 +212,10 @@ IOReturn IOMultiMemoryDescriptor::complete(IODirection forDirection)
     return statusFinal;
 }
 
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-IOPhysicalAddress IOMultiMemoryDescriptor::getPhysicalSegment(
+addr64_t IOMultiMemoryDescriptor::getPhysicalSegment(
                                                        IOByteCount   offset,
-                                                       IOByteCount * length )
+                                                       IOByteCount * length,
+                                                       IOOptionBits  options )
 {
     //
     // This method returns the physical address of the byte at the given offset
@@ -280,7 +229,7 @@ IOPhysicalAddress IOMultiMemoryDescriptor::getPhysicalSegment(
     {
         if ( offset < _descriptors[index]->getLength() )
         {
-            return _descriptors[index]->getPhysicalSegment(offset, length);
+            return _descriptors[index]->getPhysicalSegment(offset, length, options);
         }
         offset -= _descriptors[index]->getLength();
     }
@@ -289,111 +238,3 @@ IOPhysicalAddress IOMultiMemoryDescriptor::getPhysicalSegment(
 
     return 0;
 }
-
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-IOPhysicalAddress IOMultiMemoryDescriptor::getSourceSegment(
-                                                       IOByteCount   offset,
-                                                       IOByteCount * length )
-{
-    //
-    // This method returns the physical address of the byte at the given offset
-    // into the memory,  and optionally the length of the physically contiguous
-    // segment from that offset.
-    //
-
-    assert(offset <= _length);
-
-    for ( unsigned index = 0; index < _descriptorsCount; index++ ) 
-    {
-        if ( offset < _descriptors[index]->getLength() )
-        {
-            return _descriptors[index]->getSourceSegment(offset, length);
-        }
-        offset -= _descriptors[index]->getLength();
-    }
-
-    if ( length )  *length = 0;
-
-    return 0;
-}
-
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-void * IOMultiMemoryDescriptor::getVirtualSegment( IOByteCount   /* offset */ ,
-                                                   IOByteCount * /* length */ )
-{
-    return 0;
-}
-
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-IOByteCount IOMultiMemoryDescriptor::readBytes( IOByteCount offset,
-                                                void *      bytes,
-                                                IOByteCount withLength )
-{
-    //
-    // Copies data from the memory descriptor's buffer at the given offset, to
-    // the specified buffer.  Returns the number of bytes copied.
-    //
-
-    IOByteCount bytesCopied = 0;
-    unsigned    index;
-
-    for ( index = 0; index < _descriptorsCount; index++ ) 
-    {
-        if ( offset < _descriptors[index]->getLength() )  break;
-        offset -= _descriptors[index]->getLength();
-    }
-
-    for ( ; index < _descriptorsCount && withLength; index++)
-    {
-        IOByteCount copy   = min(_descriptors[index]->getLength(), withLength);
-        IOByteCount copied = _descriptors[index]->readBytes(offset,bytes,copy);
-
-        bytesCopied += copied;
-        if ( copied != copy )  break;
-
-        bytes = ((UInt8 *) bytes) + copied;
-        withLength -= copied;
-        offset = 0;
-    }
-
-    return bytesCopied;
-}
-
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-IOByteCount IOMultiMemoryDescriptor::writeBytes( IOByteCount  offset,
-                                                 const void * bytes,
-                                                 IOByteCount  withLength )
-{
-    //
-    // Copies data to the memory descriptor's buffer at the given offset, from
-    // the specified buffer.  Returns the number of bytes copied.
-    //
-
-    IOByteCount bytesCopied = 0;
-    unsigned    index;
-
-    for ( index = 0; index < _descriptorsCount; index++ ) 
-    {
-        if ( offset < _descriptors[index]->getLength() )  break;
-        offset -= _descriptors[index]->getLength();
-    }
-
-    for ( ; index < _descriptorsCount && withLength; index++)
-    {
-        IOByteCount copy   = min(_descriptors[index]->getLength(), withLength);
-        IOByteCount copied = _descriptors[index]->writeBytes(offset,bytes,copy);
-
-        bytesCopied += copied;
-        if ( copied != copy )  break;
-
-        bytes = ((UInt8 *) bytes) + copied;
-        withLength -= copied;
-        offset = 0;
-    }
-
-    return bytesCopied;
-}