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