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