1*4f1223e8SApple OSS Distributions /* 2*4f1223e8SApple OSS Distributions * Copyright (c) 1998-2019 Apple Inc. All rights reserved. 3*4f1223e8SApple OSS Distributions * 4*4f1223e8SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*4f1223e8SApple OSS Distributions * 6*4f1223e8SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*4f1223e8SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*4f1223e8SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*4f1223e8SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*4f1223e8SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*4f1223e8SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*4f1223e8SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*4f1223e8SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*4f1223e8SApple OSS Distributions * 15*4f1223e8SApple OSS Distributions * Please obtain a copy of the License at 16*4f1223e8SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*4f1223e8SApple OSS Distributions * 18*4f1223e8SApple OSS Distributions * The Original Code and all software distributed under the License are 19*4f1223e8SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*4f1223e8SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*4f1223e8SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*4f1223e8SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*4f1223e8SApple OSS Distributions * Please see the License for the specific language governing rights and 24*4f1223e8SApple OSS Distributions * limitations under the License. 25*4f1223e8SApple OSS Distributions * 26*4f1223e8SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*4f1223e8SApple OSS Distributions */ 28*4f1223e8SApple OSS Distributions #ifndef _IOMEMORYCURSOR_H 29*4f1223e8SApple OSS Distributions #define _IOMEMORYCURSOR_H 30*4f1223e8SApple OSS Distributions 31*4f1223e8SApple OSS Distributions #include <libkern/c++/OSObject.h> 32*4f1223e8SApple OSS Distributions #include <libkern/c++/OSPtr.h> 33*4f1223e8SApple OSS Distributions #include <IOKit/IOTypes.h> 34*4f1223e8SApple OSS Distributions 35*4f1223e8SApple OSS Distributions class IOMemoryDescriptor; 36*4f1223e8SApple OSS Distributions 37*4f1223e8SApple OSS Distributions /**************************** class IOMemoryCursor ***************************/ 38*4f1223e8SApple OSS Distributions 39*4f1223e8SApple OSS Distributions /*! 40*4f1223e8SApple OSS Distributions * @class IOMemoryCursor 41*4f1223e8SApple OSS Distributions * @abstract A mechanism to convert memory references to physical addresses. 42*4f1223e8SApple OSS Distributions * @discussion The IOMemoryCursor declares the super class that all 43*4f1223e8SApple OSS Distributions * specific memory cursors must inherit from, but a memory cursor can be created without a specific format subclass by just providing a segment function to the initializers. This class does the difficult stuff of dividing a memory descriptor into a physical scatter/gather list appropriate for the target hardware. 44*4f1223e8SApple OSS Distributions * <br><br> 45*4f1223e8SApple OSS Distributions * A driver is expected to create a memory cursor and configure it to the limitations of its DMA hardware; for instance the memory cursor used by the FireWire SBP-2 protocol has a maximum physical segment size of 2^16 - 1 but the actual transfer size is unlimited. Thus it would create a cursor with a maxSegmentSize of 65535 and a maxTransfer size of UINT_MAX. It would also provide a SegmentFunction that can output a pagelist entry. 46*4f1223e8SApple OSS Distributions * <br><br> 47*4f1223e8SApple OSS Distributions * Below is the simplest example of a SegmentFunction:<br> 48*4f1223e8SApple OSS Distributions * void IONaturalMemoryCursor::outputSegment(PhysicalSegment segment,<br> 49*4f1223e8SApple OSS Distributions * void * outSegments,<br> 50*4f1223e8SApple OSS Distributions * UInt32 outSegmentIndex)<br> 51*4f1223e8SApple OSS Distributions * {<br> 52*4f1223e8SApple OSS Distributions * ((PhysicalSegment *) outSegments)[outSegmentIndex] = segment;<br> 53*4f1223e8SApple OSS Distributions * } 54*4f1223e8SApple OSS Distributions * 55*4f1223e8SApple OSS Distributions */ 56*4f1223e8SApple OSS Distributions class IOMemoryCursor : public OSObject 57*4f1223e8SApple OSS Distributions { 58*4f1223e8SApple OSS Distributions OSDeclareDefaultStructors(IOMemoryCursor); 59*4f1223e8SApple OSS Distributions 60*4f1223e8SApple OSS Distributions public: 61*4f1223e8SApple OSS Distributions /*! 62*4f1223e8SApple OSS Distributions * @typedef PhysicalSegment 63*4f1223e8SApple OSS Distributions * @discussion A physical address/length pair. 64*4f1223e8SApple OSS Distributions */ 65*4f1223e8SApple OSS Distributions struct PhysicalSegment { 66*4f1223e8SApple OSS Distributions IOPhysicalAddress location; 67*4f1223e8SApple OSS Distributions IOPhysicalLength length; 68*4f1223e8SApple OSS Distributions }; 69*4f1223e8SApple OSS Distributions 70*4f1223e8SApple OSS Distributions /*! @defined IOPhysicalSegment 71*4f1223e8SApple OSS Distributions * @discussion Backward compatibility define for the old non-class scoped type definition. See IOMemoryCursor::PhysicalSegment 72*4f1223e8SApple OSS Distributions */ 73*4f1223e8SApple OSS Distributions #define IOPhysicalSegment IOMemoryCursor::PhysicalSegment 74*4f1223e8SApple OSS Distributions 75*4f1223e8SApple OSS Distributions /*! 76*4f1223e8SApple OSS Distributions * @typedef SegmentFunction 77*4f1223e8SApple OSS Distributions * @discussion Pointer to a C function that outputs a single physical segment to an element in the array as defined by the segments and segmentIndex parameters. 78*4f1223e8SApple OSS Distributions * @param segment The physical address and length that is next to be output. 79*4f1223e8SApple OSS Distributions * @param segments Base of the output vector of DMA address length pairs. 80*4f1223e8SApple OSS Distributions * @param segmentIndex Index to output 'segment' in the 'segments' array. 81*4f1223e8SApple OSS Distributions */ 82*4f1223e8SApple OSS Distributions typedef void (*SegmentFunction)(PhysicalSegment segment, 83*4f1223e8SApple OSS Distributions void * segments, 84*4f1223e8SApple OSS Distributions UInt32 segmentIndex); 85*4f1223e8SApple OSS Distributions 86*4f1223e8SApple OSS Distributions /*! @defined OutputSegmentFunc 87*4f1223e8SApple OSS Distributions * @discussion Backward compatibility define for the old non-class scoped type definition. See IOMemoryCursor::SegmentFunction */ 88*4f1223e8SApple OSS Distributions #define OutputSegmentFunc IOMemoryCursor::SegmentFunction 89*4f1223e8SApple OSS Distributions 90*4f1223e8SApple OSS Distributions protected: 91*4f1223e8SApple OSS Distributions /*! @var outSeg The action method called when an event has been delivered */ 92*4f1223e8SApple OSS Distributions SegmentFunction outSeg; 93*4f1223e8SApple OSS Distributions 94*4f1223e8SApple OSS Distributions /*! @var maxSegmentSize Maximum size of one segment in a scatter/gather list */ 95*4f1223e8SApple OSS Distributions IOPhysicalLength maxSegmentSize; 96*4f1223e8SApple OSS Distributions 97*4f1223e8SApple OSS Distributions /*! @var maxTransferSize 98*4f1223e8SApple OSS Distributions * Maximum size of a transfer that this memory cursor is allowed to generate */ 99*4f1223e8SApple OSS Distributions IOPhysicalLength maxTransferSize; 100*4f1223e8SApple OSS Distributions 101*4f1223e8SApple OSS Distributions /*! @var alignMask 102*4f1223e8SApple OSS Distributions * Currently unused. Reserved for automated aligment restriction code. */ 103*4f1223e8SApple OSS Distributions IOPhysicalLength alignMask; 104*4f1223e8SApple OSS Distributions 105*4f1223e8SApple OSS Distributions public: 106*4f1223e8SApple OSS Distributions /*! @function withSpecification 107*4f1223e8SApple OSS Distributions * @abstract Creates and initializes an IOMemoryCursor in one operation. 108*4f1223e8SApple OSS Distributions * @discussion Factory function to create and initialize an IOMemoryCursor in one operation. For more information, see IOMemoryCursor::initWithSpecification. 109*4f1223e8SApple OSS Distributions * @param outSegFunc SegmentFunction to call to output one physical segment. 110*4f1223e8SApple OSS Distributions * @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0. 111*4f1223e8SApple OSS Distributions * @param maxTransferSize Maximum size of an entire transfer. Defaults to 0 indicating no maximum. 112*4f1223e8SApple OSS Distributions * @param alignment Alignment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment. 113*4f1223e8SApple OSS Distributions * @result Returns a new memory cursor if successfully created and initialized, 0 otherwise. 114*4f1223e8SApple OSS Distributions */ 115*4f1223e8SApple OSS Distributions static OSPtr<IOMemoryCursor> 116*4f1223e8SApple OSS Distributions withSpecification(SegmentFunction outSegFunc, 117*4f1223e8SApple OSS Distributions IOPhysicalLength maxSegmentSize = 0, 118*4f1223e8SApple OSS Distributions IOPhysicalLength maxTransferSize = 0, 119*4f1223e8SApple OSS Distributions IOPhysicalLength alignment = 1); 120*4f1223e8SApple OSS Distributions 121*4f1223e8SApple OSS Distributions /*! @function initWithSpecification 122*4f1223e8SApple OSS Distributions * @abstract Primary initializer for the IOMemoryCursor class. 123*4f1223e8SApple OSS Distributions * @param outSegFunc SegmentFunction to call to output one physical segment. 124*4f1223e8SApple OSS Distributions * @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0. 125*4f1223e8SApple OSS Distributions * @param maxTransferSize Maximum size of an entire transfer. Defaults to 0 indicating no maximum. 126*4f1223e8SApple OSS Distributions * @param alignment Alignment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment. 127*4f1223e8SApple OSS Distributions * @result Returns true if the inherited classes and this instance initialize 128*4f1223e8SApple OSS Distributions * successfully. 129*4f1223e8SApple OSS Distributions */ 130*4f1223e8SApple OSS Distributions virtual bool initWithSpecification(SegmentFunction outSegFunc, 131*4f1223e8SApple OSS Distributions IOPhysicalLength maxSegmentSize = 0, 132*4f1223e8SApple OSS Distributions IOPhysicalLength maxTransferSize = 0, 133*4f1223e8SApple OSS Distributions IOPhysicalLength alignment = 1); 134*4f1223e8SApple OSS Distributions 135*4f1223e8SApple OSS Distributions /*! @function genPhysicalSegments 136*4f1223e8SApple OSS Distributions * @abstract Generates a physical scatter/gather list given a memory descriptor. 137*4f1223e8SApple OSS Distributions * @discussion Generates a list of physical segments from the given memory descriptor, relative to the current position of the descriptor. 138*4f1223e8SApple OSS Distributions * @param descriptor IOMemoryDescriptor that describes the data associated with an I/O request. 139*4f1223e8SApple OSS Distributions * @param fromPosition Starting location of the I/O within a memory descriptor. 140*4f1223e8SApple OSS Distributions * @param segments Void pointer to base of output physical scatter/gather list. Always passed directly onto the SegmentFunction without interpretation by the cursor. 141*4f1223e8SApple OSS Distributions * @param maxSegments Maximum number of segments that can be written to segments array. 142*4f1223e8SApple OSS Distributions * @param maxTransferSize Maximum transfer size is limited to that many bytes, otherwise it defaults to the maximum transfer size specified when the memory cursor was initialized. 143*4f1223e8SApple OSS Distributions * @param transferSize Pointer to an IOByteCount variable that can contain the total size of the transfer being described. Defaults to 0 indicating that no transfer size need be returned. 144*4f1223e8SApple OSS Distributions * @result If the descriptor is exhausted of memory, a zero is returned, otherwise the number of segments that were filled in is returned. 145*4f1223e8SApple OSS Distributions */ 146*4f1223e8SApple OSS Distributions virtual UInt32 genPhysicalSegments( 147*4f1223e8SApple OSS Distributions IOMemoryDescriptor *descriptor, 148*4f1223e8SApple OSS Distributions IOByteCount fromPosition, 149*4f1223e8SApple OSS Distributions void * segments, 150*4f1223e8SApple OSS Distributions UInt32 maxSegments, 151*4f1223e8SApple OSS Distributions UInt32 maxTransferSize = 0, 152*4f1223e8SApple OSS Distributions IOByteCount *transferSize = NULL); 153*4f1223e8SApple OSS Distributions }; 154*4f1223e8SApple OSS Distributions 155*4f1223e8SApple OSS Distributions /************************ class IONaturalMemoryCursor ************************/ 156*4f1223e8SApple OSS Distributions 157*4f1223e8SApple OSS Distributions 158*4f1223e8SApple OSS Distributions /*! 159*4f1223e8SApple OSS Distributions * @class IONaturalMemoryCursor 160*4f1223e8SApple OSS Distributions * @abstract An IOMemoryCursor subclass that outputs a vector of PhysicalSegments in the natural byte orientation for the CPU. 161*4f1223e8SApple OSS Distributions * @discussion The IONaturalMemoryCursor would be used when it is too difficult to safely describe a SegmentFunction that is more appropriate for your hardware. This cursor just outputs an array of PhysicalSegments. 162*4f1223e8SApple OSS Distributions */ 163*4f1223e8SApple OSS Distributions class IONaturalMemoryCursor : public IOMemoryCursor 164*4f1223e8SApple OSS Distributions { 165*4f1223e8SApple OSS Distributions OSDeclareDefaultStructors(IONaturalMemoryCursor); 166*4f1223e8SApple OSS Distributions 167*4f1223e8SApple OSS Distributions public: 168*4f1223e8SApple OSS Distributions /*! @function outputSegment 169*4f1223e8SApple OSS Distributions * @abstract Outputs the given segment into the output segments array in natural byte order. 170*4f1223e8SApple OSS Distributions * @param segment The physical address and length that is next to be output. 171*4f1223e8SApple OSS Distributions * @param segments Base of the output vector of DMA address length pairs. 172*4f1223e8SApple OSS Distributions * @param segmentIndex Index to output 'segment' in the 'segments' array. 173*4f1223e8SApple OSS Distributions */ 174*4f1223e8SApple OSS Distributions static void outputSegment(PhysicalSegment segment, 175*4f1223e8SApple OSS Distributions void * segments, 176*4f1223e8SApple OSS Distributions UInt32 segmentIndex); 177*4f1223e8SApple OSS Distributions 178*4f1223e8SApple OSS Distributions /*! @defined naturalOutputSegment 179*4f1223e8SApple OSS Distributions * @discussion Backward compatibility define for the old global function definition. See IONaturalMemoryCursor::outputSegment. 180*4f1223e8SApple OSS Distributions */ 181*4f1223e8SApple OSS Distributions #define naturalOutputSegment IONaturalMemoryCursor::outputSegment 182*4f1223e8SApple OSS Distributions 183*4f1223e8SApple OSS Distributions /*! @function withSpecification 184*4f1223e8SApple OSS Distributions * @abstract Creates and initializes an IONaturalMemoryCursor in one operation. 185*4f1223e8SApple OSS Distributions * @discussion Factory function to create and initialize an IONaturalMemoryCursor in one operation. For more information, see IONaturalMemoryCursor::initWithSpecification. 186*4f1223e8SApple OSS Distributions * @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0. 187*4f1223e8SApple OSS Distributions * @param maxTransferSize Maximum size of an entire transfer. Defaults to 0 indicating no maximum. 188*4f1223e8SApple OSS Distributions * @param alignment Alignment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment. 189*4f1223e8SApple OSS Distributions * @result Returns a new memory cursor if successfully created and initialized, 0 otherwise. 190*4f1223e8SApple OSS Distributions */ 191*4f1223e8SApple OSS Distributions static OSPtr<IONaturalMemoryCursor> 192*4f1223e8SApple OSS Distributions withSpecification(IOPhysicalLength maxSegmentSize, 193*4f1223e8SApple OSS Distributions IOPhysicalLength maxTransferSize, 194*4f1223e8SApple OSS Distributions IOPhysicalLength alignment = 1); 195*4f1223e8SApple OSS Distributions 196*4f1223e8SApple OSS Distributions /*! @function initWithSpecification 197*4f1223e8SApple OSS Distributions * @abstract Primary initializer for the IONaturalMemoryCursor class. 198*4f1223e8SApple OSS Distributions * @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0. 199*4f1223e8SApple OSS Distributions * @param maxTransferSize Maximum size of an entire transfer. Defaults to 0 indicating no maximum. 200*4f1223e8SApple OSS Distributions * @param alignment Alignment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment. 201*4f1223e8SApple OSS Distributions * @result Returns true if the inherited classes and this instance initialize successfully. 202*4f1223e8SApple OSS Distributions */ 203*4f1223e8SApple OSS Distributions virtual bool initWithSpecification(IOPhysicalLength maxSegmentSize, 204*4f1223e8SApple OSS Distributions IOPhysicalLength maxTransferSize, 205*4f1223e8SApple OSS Distributions IOPhysicalLength alignment = 1); 206*4f1223e8SApple OSS Distributions 207*4f1223e8SApple OSS Distributions 208*4f1223e8SApple OSS Distributions /*! @function getPhysicalSegments 209*4f1223e8SApple OSS Distributions * @abstract Generates a CPU natural physical scatter/gather list given a memory descriptor. 210*4f1223e8SApple OSS Distributions * @discussion Generates a list of physical segments from the given memory descriptor, relative to the current position of the descriptor. Wraps IOMemoryCursor::genPhysicalSegments. 211*4f1223e8SApple OSS Distributions * @param descriptor IOMemoryDescriptor that describes the data associated with an I/O request. 212*4f1223e8SApple OSS Distributions * @param fromPosition Starting location of the I/O within a memory descriptor. 213*4f1223e8SApple OSS Distributions * @param segments Pointer to an array of IOMemoryCursor::PhysicalSegments for the output physical scatter/gather list. 214*4f1223e8SApple OSS Distributions * @param maxSegments Maximum number of segments that can be written to segments array. 215*4f1223e8SApple OSS Distributions * @param inMaxTransferSize Maximum transfer size is limited to that many bytes, otherwise it defaults to the maximum transfer size specified when the memory cursor was initialized. 216*4f1223e8SApple OSS Distributions * @param transferSize Pointer to an IOByteCount variable that can contain the total size of the transfer being described. Defaults to 0 indicating that no transfer size need be returned. 217*4f1223e8SApple OSS Distributions * @result If the descriptor is exhausted of memory, a zero is returned, otherwise the number of segments that were filled in is returned. 218*4f1223e8SApple OSS Distributions */ 219*4f1223e8SApple OSS Distributions virtual UInt32 220*4f1223e8SApple OSS Distributions getPhysicalSegments(IOMemoryDescriptor *descriptor, 221*4f1223e8SApple OSS Distributions IOByteCount fromPosition, 222*4f1223e8SApple OSS Distributions PhysicalSegment *segments, 223*4f1223e8SApple OSS Distributions UInt32 maxSegments, 224*4f1223e8SApple OSS Distributions UInt32 inMaxTransferSize = 0, 225*4f1223e8SApple OSS Distributions IOByteCount *transferSize = NULL) 226*4f1223e8SApple OSS Distributions { 227*4f1223e8SApple OSS Distributions return genPhysicalSegments(descriptor, fromPosition, segments, 228*4f1223e8SApple OSS Distributions maxSegments, inMaxTransferSize, transferSize); 229*4f1223e8SApple OSS Distributions } 230*4f1223e8SApple OSS Distributions }; 231*4f1223e8SApple OSS Distributions 232*4f1223e8SApple OSS Distributions /************************** class IOBigMemoryCursor **************************/ 233*4f1223e8SApple OSS Distributions 234*4f1223e8SApple OSS Distributions /*! 235*4f1223e8SApple OSS Distributions * @class IOBigMemoryCursor 236*4f1223e8SApple OSS Distributions * @abstract An IOMemoryCursor subclass that outputs a vector of PhysicalSegments in the big endian byte order. 237*4f1223e8SApple OSS Distributions * @discussion The IOBigMemoryCursor would be used when the DMA hardware requires a big endian address and length pair. This cursor outputs an array of PhysicalSegments that are encoded in big-endian format. 238*4f1223e8SApple OSS Distributions */ 239*4f1223e8SApple OSS Distributions class IOBigMemoryCursor : public IOMemoryCursor 240*4f1223e8SApple OSS Distributions { 241*4f1223e8SApple OSS Distributions OSDeclareDefaultStructors(IOBigMemoryCursor); 242*4f1223e8SApple OSS Distributions 243*4f1223e8SApple OSS Distributions public: 244*4f1223e8SApple OSS Distributions /*! @function outputSegment 245*4f1223e8SApple OSS Distributions * @abstract Outputs the given segment into the output segments array in big endian byte order. 246*4f1223e8SApple OSS Distributions * @param segment The physical address and length that is next to be output. 247*4f1223e8SApple OSS Distributions * @param segments Base of the output vector of DMA address length pairs. 248*4f1223e8SApple OSS Distributions * @param segmentIndex Index to output 'segment' in the 'segments' array. 249*4f1223e8SApple OSS Distributions */ 250*4f1223e8SApple OSS Distributions static void outputSegment(PhysicalSegment segment, 251*4f1223e8SApple OSS Distributions void * segments, 252*4f1223e8SApple OSS Distributions UInt32 segmentIndex); 253*4f1223e8SApple OSS Distributions 254*4f1223e8SApple OSS Distributions /*! @defined bigOutputSegment 255*4f1223e8SApple OSS Distributions * @discussion Backward compatibility define for the old global function definition. See IOBigMemoryCursor::outputSegment 256*4f1223e8SApple OSS Distributions */ 257*4f1223e8SApple OSS Distributions #define bigOutputSegment IOBigMemoryCursor::outputSegment 258*4f1223e8SApple OSS Distributions 259*4f1223e8SApple OSS Distributions /*! @function withSpecification 260*4f1223e8SApple OSS Distributions * @abstract Creates and initializes an IOBigMemoryCursor in one operation. 261*4f1223e8SApple OSS Distributions * @discussion Factory function to create and initialize an IOBigMemoryCursor in one operation. See also IOBigMemoryCursor::initWithSpecification. 262*4f1223e8SApple OSS Distributions * @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0. 263*4f1223e8SApple OSS Distributions * @param maxTransferSize Maximum size of an entire transfer. Defaults to 0 indicating no maximum. 264*4f1223e8SApple OSS Distributions * @param alignment Alignment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment. 265*4f1223e8SApple OSS Distributions * @result Returns a new memory cursor if successfully created and initialized, 0 otherwise. 266*4f1223e8SApple OSS Distributions */ 267*4f1223e8SApple OSS Distributions static OSPtr<IOBigMemoryCursor> 268*4f1223e8SApple OSS Distributions withSpecification(IOPhysicalLength maxSegmentSize, 269*4f1223e8SApple OSS Distributions IOPhysicalLength maxTransferSize, 270*4f1223e8SApple OSS Distributions IOPhysicalLength alignment = 1); 271*4f1223e8SApple OSS Distributions 272*4f1223e8SApple OSS Distributions /*! @function initWithSpecification 273*4f1223e8SApple OSS Distributions * @abstract Primary initializer for the IOBigMemoryCursor class. 274*4f1223e8SApple OSS Distributions * @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0. 275*4f1223e8SApple OSS Distributions * @param maxTransferSize Maximum size of an entire transfer. Defaults to 0 indicating no maximum. 276*4f1223e8SApple OSS Distributions * @param alignment Alignment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment. 277*4f1223e8SApple OSS Distributions * @result Returns true if the inherited classes and this instance initialize 278*4f1223e8SApple OSS Distributions * successfully. 279*4f1223e8SApple OSS Distributions */ 280*4f1223e8SApple OSS Distributions virtual bool initWithSpecification(IOPhysicalLength maxSegmentSize, 281*4f1223e8SApple OSS Distributions IOPhysicalLength maxTransferSize, 282*4f1223e8SApple OSS Distributions IOPhysicalLength alignment = 1); 283*4f1223e8SApple OSS Distributions 284*4f1223e8SApple OSS Distributions 285*4f1223e8SApple OSS Distributions /*! @function getPhysicalSegments 286*4f1223e8SApple OSS Distributions * @abstract Generates a big endian physical scatter/gather list given a memory descriptor. 287*4f1223e8SApple OSS Distributions * @discussion Generates a list of physical segments from the given memory descriptor, relative to the current position of the descriptor. Wraps IOMemoryCursor::genPhysicalSegments. 288*4f1223e8SApple OSS Distributions * @param descriptor IOMemoryDescriptor that describes the data associated with an I/O request. 289*4f1223e8SApple OSS Distributions * @param fromPosition Starting location of the I/O within a memory descriptor. 290*4f1223e8SApple OSS Distributions * @param segments Pointer to an array of IOMemoryCursor::PhysicalSegments for the output physical scatter/gather list. 291*4f1223e8SApple OSS Distributions * @param maxSegments Maximum number of segments that can be written to segments array. 292*4f1223e8SApple OSS Distributions * @param inMaxTransferSize Maximum transfer size is limited to that many bytes, otherwise it defaults to the maximum transfer size specified when the memory cursor was initialized. 293*4f1223e8SApple OSS Distributions * @param transferSize Pointer to an IOByteCount variable that can contain the total size of the transfer being described. Defaults to 0 indicating that no transfer size need be returned. 294*4f1223e8SApple OSS Distributions * @result If the descriptor is exhausted of memory, a zero is returned, otherwise the number of segments that were filled in is returned. 295*4f1223e8SApple OSS Distributions */ 296*4f1223e8SApple OSS Distributions virtual UInt32 297*4f1223e8SApple OSS Distributions getPhysicalSegments(IOMemoryDescriptor * descriptor, 298*4f1223e8SApple OSS Distributions IOByteCount fromPosition, 299*4f1223e8SApple OSS Distributions PhysicalSegment * segments, 300*4f1223e8SApple OSS Distributions UInt32 maxSegments, 301*4f1223e8SApple OSS Distributions UInt32 inMaxTransferSize = 0, 302*4f1223e8SApple OSS Distributions IOByteCount * transferSize = NULL) 303*4f1223e8SApple OSS Distributions { 304*4f1223e8SApple OSS Distributions return genPhysicalSegments(descriptor, fromPosition, segments, 305*4f1223e8SApple OSS Distributions maxSegments, inMaxTransferSize, transferSize); 306*4f1223e8SApple OSS Distributions } 307*4f1223e8SApple OSS Distributions }; 308*4f1223e8SApple OSS Distributions 309*4f1223e8SApple OSS Distributions /************************* class IOLittleMemoryCursor ************************/ 310*4f1223e8SApple OSS Distributions 311*4f1223e8SApple OSS Distributions /*! 312*4f1223e8SApple OSS Distributions * @class IOLittleMemoryCursor 313*4f1223e8SApple OSS Distributions * @abstract An IOMemoryCursor subclass that outputs a vector of PhysicalSegments in the little endian byte order. 314*4f1223e8SApple OSS Distributions * @discussion The IOLittleMemoryCursor would be used when the DMA hardware requires a little endian address and length pair. This cursor outputs an array of PhysicalSegments that are encoded in little endian format. 315*4f1223e8SApple OSS Distributions */ 316*4f1223e8SApple OSS Distributions class IOLittleMemoryCursor : public IOMemoryCursor 317*4f1223e8SApple OSS Distributions { 318*4f1223e8SApple OSS Distributions OSDeclareDefaultStructors(IOLittleMemoryCursor); 319*4f1223e8SApple OSS Distributions 320*4f1223e8SApple OSS Distributions public: 321*4f1223e8SApple OSS Distributions /*! @function outputSegment 322*4f1223e8SApple OSS Distributions * @abstract Outputs the given segment into the output segments array in little endian byte order. 323*4f1223e8SApple OSS Distributions * @param segment The physical address and length that is next to be output. 324*4f1223e8SApple OSS Distributions * @param segments Base of the output vector of DMA address length pairs. 325*4f1223e8SApple OSS Distributions * @param segmentIndex Index to output 'segment' in the 'segments' array. 326*4f1223e8SApple OSS Distributions */ 327*4f1223e8SApple OSS Distributions static void outputSegment(PhysicalSegment segment, 328*4f1223e8SApple OSS Distributions void * segments, 329*4f1223e8SApple OSS Distributions UInt32 segmentIndex); 330*4f1223e8SApple OSS Distributions 331*4f1223e8SApple OSS Distributions /*! @defined littleOutputSegment 332*4f1223e8SApple OSS Distributions * @discussion Backward compatibility define for the old global function definition. See also IOLittleMemoryCursor::outputSegment. */ 333*4f1223e8SApple OSS Distributions #define littleOutputSegment IOLittleMemoryCursor::outputSegment 334*4f1223e8SApple OSS Distributions 335*4f1223e8SApple OSS Distributions /*! @function withSpecification 336*4f1223e8SApple OSS Distributions * @abstract Creates and initializes an IOLittleMemoryCursor in one operation. 337*4f1223e8SApple OSS Distributions * @discussion Factory function to create and initialize an IOLittleMemoryCursor in one operation. See also IOLittleMemoryCursor::initWithSpecification. 338*4f1223e8SApple OSS Distributions * @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0. 339*4f1223e8SApple OSS Distributions * @param maxTransferSize Maximum size of an entire transfer. Defaults to 0 indicating no maximum. 340*4f1223e8SApple OSS Distributions * @param alignment Alignment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment. 341*4f1223e8SApple OSS Distributions * @result Returns a new memory cursor if successfully created and initialized, 0 otherwise. 342*4f1223e8SApple OSS Distributions */ 343*4f1223e8SApple OSS Distributions static OSPtr<IOLittleMemoryCursor> 344*4f1223e8SApple OSS Distributions withSpecification(IOPhysicalLength maxSegmentSize, 345*4f1223e8SApple OSS Distributions IOPhysicalLength maxTransferSize, 346*4f1223e8SApple OSS Distributions IOPhysicalLength alignment = 1); 347*4f1223e8SApple OSS Distributions 348*4f1223e8SApple OSS Distributions /*! @function initWithSpecification 349*4f1223e8SApple OSS Distributions * @abstract Primary initializer for the IOLittleMemoryCursor class. 350*4f1223e8SApple OSS Distributions * @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0. 351*4f1223e8SApple OSS Distributions * @param maxTransferSize Maximum size of an entire transfer. Defaults to 0 indicating no maximum. 352*4f1223e8SApple OSS Distributions * @param alignment Alignment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment. 353*4f1223e8SApple OSS Distributions * @result Returns true if the inherited classes and this instance initialize successfully. 354*4f1223e8SApple OSS Distributions */ 355*4f1223e8SApple OSS Distributions virtual bool initWithSpecification(IOPhysicalLength maxSegmentSize, 356*4f1223e8SApple OSS Distributions IOPhysicalLength maxTransferSize, 357*4f1223e8SApple OSS Distributions IOPhysicalLength alignment = 1); 358*4f1223e8SApple OSS Distributions 359*4f1223e8SApple OSS Distributions 360*4f1223e8SApple OSS Distributions /*! @function getPhysicalSegments 361*4f1223e8SApple OSS Distributions * @abstract Generates a little endian physical scatter/gather list given a memory descriptor. 362*4f1223e8SApple OSS Distributions * @discussion Generates a list of physical segments from the given memory descriptor, relative to the current position of the descriptor. Wraps IOMemoryCursor::genPhysicalSegments. 363*4f1223e8SApple OSS Distributions * @param descriptor IOMemoryDescriptor that describes the data associated with an I/O request. 364*4f1223e8SApple OSS Distributions * @param fromPosition Starting location of the I/O within a memory descriptor. 365*4f1223e8SApple OSS Distributions * @param segments Pointer to an array of IOMemoryCursor::PhysicalSegments for the output physical scatter/gather list. 366*4f1223e8SApple OSS Distributions * @param maxSegments Maximum number of segments that can be written to segments array. 367*4f1223e8SApple OSS Distributions * @param inMaxTransferSize Maximum transfer size is limited to that many bytes, otherwise it defaults to the maximum transfer size specified when the memory cursor was initialized. 368*4f1223e8SApple OSS Distributions * @param transferSize Pointer to an IOByteCount variable that can contain the total size of the transfer being described. Defaults to 0 indicating that no transfer size need be returned. 369*4f1223e8SApple OSS Distributions * @result If the descriptor is exhausted of memory, a zero is returned, otherwise the number of segments that were filled in is returned. 370*4f1223e8SApple OSS Distributions */ 371*4f1223e8SApple OSS Distributions virtual UInt32 372*4f1223e8SApple OSS Distributions getPhysicalSegments(IOMemoryDescriptor * descriptor, 373*4f1223e8SApple OSS Distributions IOByteCount fromPosition, 374*4f1223e8SApple OSS Distributions PhysicalSegment * segments, 375*4f1223e8SApple OSS Distributions UInt32 maxSegments, 376*4f1223e8SApple OSS Distributions UInt32 inMaxTransferSize = 0, 377*4f1223e8SApple OSS Distributions IOByteCount * transferSize = NULL) 378*4f1223e8SApple OSS Distributions { 379*4f1223e8SApple OSS Distributions return genPhysicalSegments(descriptor, fromPosition, segments, 380*4f1223e8SApple OSS Distributions maxSegments, inMaxTransferSize, transferSize); 381*4f1223e8SApple OSS Distributions } 382*4f1223e8SApple OSS Distributions }; 383*4f1223e8SApple OSS Distributions 384*4f1223e8SApple OSS Distributions #endif /* !_IOMEMORYCURSOR_H */ 385