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