]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOMemoryCursor.cpp
xnu-517.7.21.tar.gz
[apple/xnu.git] / iokit / Kernel / IOMemoryCursor.cpp
index b0da5f75ada455062576941394b161572416d540..bfd0833a0f1da0c6171a298bac2e8642ce7c51da 100644 (file)
@@ -61,6 +61,18 @@ IOMemoryCursor::initWithSpecification(SegmentFunction  inSegFunc,
                                       IOPhysicalLength inMaxTransferSize,
                                       IOPhysicalLength inAlignment)
 {
+// @@@ gvdl: Remove me
+#if 1
+static UInt sMaxDBDMASegment;
+if (!sMaxDBDMASegment) {
+    sMaxDBDMASegment = (UInt) -1;
+    if (PE_parse_boot_arg("mseg", &sMaxDBDMASegment))
+        IOLog("Setting MaxDBDMASegment to %d\n", sMaxDBDMASegment);
+}
+
+if (inMaxSegmentSize > sMaxDBDMASegment) inMaxSegmentSize = sMaxDBDMASegment;
+#endif
+
     if (!super::init())
         return false;
 
@@ -104,22 +116,66 @@ IOMemoryCursor::genPhysicalSegments(IOMemoryDescriptor *inDescriptor,
      * If we finished cleanly return number of segments found
      * and update the position in the descriptor.
      */
+    PhysicalSegment curSeg = { 0 };
     UInt curSegIndex = 0;
     UInt curTransferSize = 0;
-    PhysicalSegment seg;
+    IOByteCount inDescriptorLength = inDescriptor->getLength();
+    PhysicalSegment seg = { 0 };
 
-    while ((curSegIndex < inMaxSegments)
-    &&  (curTransferSize < inMaxTransferSize)
-    &&  (seg.location = inDescriptor->getPhysicalSegment(
-                            fromPosition + curTransferSize, &seg.length)))
+    while ((seg.location) || (fromPosition < inDescriptorLength)) 
     {
-        assert(seg.length);
-        seg.length = min(inMaxTransferSize-curTransferSize,
-                         (min(seg.length, maxSegmentSize)));
-        (*outSeg)(seg, inSegments, curSegIndex++);
-        curTransferSize += seg.length;
+        if (!seg.location)
+        {
+            seg.location = inDescriptor->getPhysicalSegment(
+                               fromPosition, &seg.length);
+            assert(seg.location);
+            assert(seg.length);
+            fromPosition += seg.length;
+        }
+
+        if (!curSeg.location)
+        {
+            curTransferSize += seg.length;
+            curSeg = seg;
+            seg.location = 0;
+        }
+        else if ((curSeg.location + curSeg.length == seg.location))
+        {
+            curTransferSize += seg.length;
+            curSeg.length += seg.length;
+            seg.location = 0;
+        }
+
+        if (!seg.location)
+        {
+            if ((curSeg.length > maxSegmentSize))
+            {
+                seg.location = curSeg.location + maxSegmentSize;
+                seg.length = curSeg.length - maxSegmentSize;
+                curTransferSize -= seg.length;
+                curSeg.length -= seg.length;
+            }
+
+            if ((curTransferSize >= inMaxTransferSize))
+            {
+                curSeg.length -= curTransferSize - inMaxTransferSize;
+                curTransferSize = inMaxTransferSize;
+                break;
+            }
+        }
+
+        if (seg.location)
+        {
+            if ((curSegIndex + 1 == inMaxSegments))
+                break;
+            (*outSeg)(curSeg, inSegments, curSegIndex++);
+            curSeg.location = 0;
+        }
     }
 
+    if (curSeg.location)
+        (*outSeg)(curSeg, inSegments, curSegIndex++);
+
     if (outTransferSize)
         *outTransferSize = curTransferSize;