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