2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 #ifndef _IOMEMORYCURSOR_H
26 #define _IOMEMORYCURSOR_H
28 #include <libkern/c++/OSObject.h>
29 #include <IOKit/IOTypes.h>
31 class IOMemoryDescriptor
;
33 /**************************** class IOMemoryCursor ***************************/
36 @class IOMemoryCursor : public OSObject
37 @abstract A mechanism to convert memory references to physical addresses.
38 @discussion The IOMemoryCursor declares the super class that all
39 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.
41 A driver is expected to create a memory cursor and configure it to the limitations of it's DMA hardware; for instance the memory cursor used by the firewire SBP2 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.
43 Below is the simplest example of a SegmentFunction:-
44 void IONaturalMemoryCursor::outputSegment(PhysicalSegment segment,
46 UInt32 outSegmentIndex)
48 ((PhysicalSegment *) outSegments)[outSegmentIndex] = segment;
52 class IOMemoryCursor
: public OSObject
54 OSDeclareDefaultStructors(IOMemoryCursor
)
58 @typedef PhysicalSegment
59 @discussion A physical address/length pair.
61 struct PhysicalSegment
63 IOPhysicalAddress location
;
64 IOPhysicalLength length
;
67 /*! @defined IOPhysicalSegment
68 @discussion Backward compatibilty define for the old non-class scoped type definition. See $link IOMemoryCursor::PhysicalSegment */
69 #define IOPhysicalSegment IOMemoryCursor::PhysicalSegment
72 @typedef SegmentFunction
73 @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.
74 @param segment The physical address and length that is next to be output.
75 @param segments Base of the output vector of DMA address length pairs.
76 @param segmentIndex Index to output 'segment' in the 'segments' array.
78 typedef void (*SegmentFunction
)(PhysicalSegment segment
,
82 /*! @defined OutputSegmentFunc
83 @discussion Backward compatibilty define for the old non-class scoped type definition. See $link IOMemoryCursor::SegmentFunction */
84 #define OutputSegmentFunc IOMemoryCursor::SegmentFunction
87 /*! @var outSeg The action method called when an event has been delivered */
88 SegmentFunction outSeg
;
90 /*! @var maxSegmentSize Maximum size of one segment in a scatter/gather list */
91 IOPhysicalLength maxSegmentSize
;
93 /*! @var maxTransferSize
94 Maximum size of a transfer that this memory cursor is allowed to generate */
95 IOPhysicalLength maxTransferSize
;
98 Currently unused. Reserved for automated aligment restriction code. */
99 IOPhysicalLength alignMask
;
102 /*! @function withSpecification
103 @abstract Factory function to create and initialise an IOMemoryCursor in one operation, see $link IOMemoryCursor::initWithSpecification.
104 @param outSegFunc SegmentFunction to call to output one physical segment.
105 @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0.
106 @param maxTransferSize Maximum size of an entire transfer. Default to 0 indicating no maximum.
107 @param alignment Alligment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment.
108 @result A new memory cursor if successfully created and initialised, 0 otherwise.
110 static IOMemoryCursor
*
111 withSpecification(SegmentFunction outSegFunc
,
112 IOPhysicalLength maxSegmentSize
= 0,
113 IOPhysicalLength maxTransferSize
= 0,
114 IOPhysicalLength alignment
= 1);
116 /*! @function initWithSpecification
117 @abstract Primary initialiser for the IOMemoryCursor class.
118 @param outSegFunc SegmentFunction to call to output one physical segment.
119 @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0.
120 @param maxTransferSize Maximum size of an entire transfer. Default to 0 indicating no maximum.
121 @param alignment Alligment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment.
122 @result true if the inherited classes and this instance initialise
125 virtual bool initWithSpecification(SegmentFunction outSegFunc
,
126 IOPhysicalLength maxSegmentSize
= 0,
127 IOPhysicalLength maxTransferSize
= 0,
128 IOPhysicalLength alignment
= 1);
130 /*! @function genPhysicalSegments
131 @abstract Generate a physical scatter/gather list given a memory descriptor.
132 @discussion Generates a list of physical segments from the given memory descriptor, relative to the current position of the descriptor.
133 @param descriptor IOMemoryDescriptor that describes the data associated with an I/O request.
134 @param fromPosition Starting location of the I/O within a memory descriptor.
135 @param segments Void pointer to base of output physical scatter/gather list. Always passed directly onto the SegmentFunction without interpretation by the cursor.
136 @param maxSegments Maximum number of segments that can be written to segments array.
137 @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.
138 @param transferSize Pointer to a IOByteCount variable that can contain the total size of the transfer being described. Default to 0 indicating that no transfer size need be returned.
139 @result If the descriptor is exhausted of memory, a zero is returned, otherwise the number of segments that were filled in is returned.
141 virtual UInt32
genPhysicalSegments(
142 IOMemoryDescriptor
*descriptor
,
143 IOByteCount fromPosition
,
146 UInt32 maxTransferSize
= 0,
147 IOByteCount
*transferSize
= 0);
150 /************************ class IONaturalMemoryCursor ************************/
154 @class IONaturalMemoryCursor : public IOMemoryCursor
155 @abstract A $link IOMemoryCursor subclass that outputs a vector of PhysicalSegments in the natural byte orientation for the cpu.
156 @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.
158 class IONaturalMemoryCursor
: public IOMemoryCursor
160 OSDeclareDefaultStructors(IONaturalMemoryCursor
)
163 /*! @funtion outputSegment
164 @abstract Output the given segment into the output segments array in natural byte order.
165 @param segment The physical address and length that is next to be output.
166 @param segments Base of the output vector of DMA address length pairs.
167 @param segmentIndex Index to output 'segment' in the 'segments' array.
169 static void outputSegment(PhysicalSegment segment
,
171 UInt32 segmentIndex
);
173 /*! @defined naturalOutputSegment
174 @discussion Backward compatibilty define for the old global function definition. See $link IONaturalMemoryCursor::outputSegment */
175 #define naturalOutputSegment IONaturalMemoryCursor::outputSegment
177 /*! @function withSpecification
178 @abstract Factory function to create and initialise an IONaturalMemoryCursor in one operation, see $link IONaturalMemoryCursor::initWithSpecification.
179 @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0.
180 @param maxTransferSize Maximum size of an entire transfer. Default to 0 indicating no maximum.
181 @param alignment Alligment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment.
182 @result A new memory cursor if successfully created and initialised, 0 otherwise.
184 static IONaturalMemoryCursor
*
185 withSpecification(IOPhysicalLength maxSegmentSize
,
186 IOPhysicalLength maxTransferSize
,
187 IOPhysicalLength alignment
= 1);
189 /*! @function initWithSpecification
190 @abstract Primary initialiser for the IONaturalMemoryCursor class.
191 @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0.
192 @param maxTransferSize Maximum size of an entire transfer. Default to 0 indicating no maximum.
193 @param alignment Alligment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment.
194 @result true if the inherited classes and this instance initialise
197 virtual bool initWithSpecification(IOPhysicalLength maxSegmentSize
,
198 IOPhysicalLength maxTransferSize
,
199 IOPhysicalLength alignment
= 1);
202 /*! @function getPhysicalSegments
203 @abstract Generate a cpu natural physical scatter/gather list given a memory descriptor.
204 @discussion Generates a list of physical segments from the given memory descriptor, relative to the current position of the descriptor. Wraps $link IOMemoryCursor::genPhysicalSegments.
205 @param descriptor IOMemoryDescriptor that describes the data associated with an I/O request.
206 @param fromPosition Starting location of the I/O within a memory descriptor.
207 @param segments Pointer to an array of $link IOMemoryCursor::PhysicalSegments for the output physical scatter/gather list.
208 @param maxSegments Maximum number of segments that can be written to segments array.
209 @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.
210 @param transferSize Pointer to a IOByteCount variable that can contain the total size of the transfer being described. Default to 0 indicating that no transfer size need be returned.
211 @result If the descriptor is exhausted of memory, a zero is returned, otherwise the number of segments that were filled in is returned.
213 virtual UInt32
getPhysicalSegments(IOMemoryDescriptor
*descriptor
,
214 IOByteCount fromPosition
,
215 PhysicalSegment
*segments
,
217 UInt32 maxTransferSize
= 0,
218 IOByteCount
*transferSize
= 0)
220 return genPhysicalSegments(descriptor
, fromPosition
, segments
,
221 maxSegments
, maxTransferSize
, transferSize
);
225 /************************** class IOBigMemoryCursor **************************/
228 @class IOBigMemoryCursor : public IOMemoryCursor
229 @abstract A $link IOMemoryCursor subclass that outputs a vector of PhysicalSegments in the big endian byte order.
230 @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.
232 class IOBigMemoryCursor
: public IOMemoryCursor
234 OSDeclareDefaultStructors(IOBigMemoryCursor
)
237 /*! @funtion outputSegment
238 @abstract Output the given segment into the output segments array in big endian byte order.
239 @param segment The physical address and length that is next to be output.
240 @param segments Base of the output vector of DMA address length pairs.
241 @param segmentIndex Index to output 'segment' in the 'segments' array.
243 static void outputSegment(PhysicalSegment segment
,
245 UInt32 segmentIndex
);
247 /*! @defined bigOutputSegment
248 @discussion Backward compatibilty define for the old global function definition. See $link IOBigMemoryCursor::outputSegment */
249 #define bigOutputSegment IOBigMemoryCursor::outputSegment
251 /*! @function withSpecification
252 @abstract Factory function to create and initialise an IOBigMemoryCursor in one operation, see $link IOBigMemoryCursor::initWithSpecification.
253 @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0.
254 @param maxTransferSize Maximum size of an entire transfer. Default to 0 indicating no maximum.
255 @param alignment Alligment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment.
256 @result A new memory cursor if successfully created and initialised, 0 otherwise.
258 static IOBigMemoryCursor
*
259 withSpecification(IOPhysicalLength maxSegmentSize
,
260 IOPhysicalLength maxTransferSize
,
261 IOPhysicalLength alignment
= 1);
263 /*! @function initWithSpecification
264 @abstract Primary initialiser for the IOBigMemoryCursor class.
265 @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0.
266 @param maxTransferSize Maximum size of an entire transfer. Default to 0 indicating no maximum.
267 @param alignment Alligment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment.
268 @result true if the inherited classes and this instance initialise
271 virtual bool initWithSpecification(IOPhysicalLength maxSegmentSize
,
272 IOPhysicalLength maxTransferSize
,
273 IOPhysicalLength alignment
= 1);
276 /*! @function getPhysicalSegments
277 @abstract Generate a big endian physical scatter/gather list given a memory descriptor.
278 @discussion Generates a list of physical segments from the given memory descriptor, relative to the current position of the descriptor. Wraps $link IOMemoryCursor::genPhysicalSegments.
279 @param descriptor IOMemoryDescriptor that describes the data associated with an I/O request.
280 @param fromPosition Starting location of the I/O within a memory descriptor.
281 @param segments Pointer to an array of $link IOMemoryCursor::PhysicalSegments for the output physical scatter/gather list.
282 @param maxSegments Maximum number of segments that can be written to segments array.
283 @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.
284 @param transferSize Pointer to a IOByteCount variable that can contain the total size of the transfer being described. Default to 0 indicating that no transfer size need be returned.
285 @result If the descriptor is exhausted of memory, a zero is returned, otherwise the number of segments that were filled in is returned.
287 virtual UInt32
getPhysicalSegments(IOMemoryDescriptor
* descriptor
,
288 IOByteCount fromPosition
,
289 PhysicalSegment
* segments
,
291 UInt32 maxTransferSize
= 0,
292 IOByteCount
* transferSize
= 0)
294 return genPhysicalSegments(descriptor
, fromPosition
, segments
,
295 maxSegments
, maxTransferSize
, transferSize
);
299 /************************* class IOLittleMemoryCursor ************************/
302 @class IOLittleMemoryCursor : public IOMemoryCursor
303 @abstract A $link IOMemoryCursor subclass that outputs a vector of PhysicalSegments in the little endian byte order.
304 @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.
306 class IOLittleMemoryCursor
: public IOMemoryCursor
308 OSDeclareDefaultStructors(IOLittleMemoryCursor
)
311 /*! @funtion outputSegment
312 @abstract Output the given segment into the output segments array in little endian byte order.
313 @param segment The physical address and length that is next to be output.
314 @param segments Base of the output vector of DMA address length pairs.
315 @param segmentIndex Index to output 'segment' in the 'segments' array.
317 static void outputSegment(PhysicalSegment segment
,
319 UInt32 segmentIndex
);
321 /*! @defined littleOutputSegment
322 @discussion Backward compatibilty define for the old global function definition. See $link IOLittleMemoryCursor::outputSegment */
323 #define littleOutputSegment IOLittleMemoryCursor::outputSegment
325 /*! @function withSpecification
326 @abstract Factory function to create and initialise an IOLittleMemoryCursor in one operation, see $link IOLittleMemoryCursor::initWithSpecification.
327 @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0.
328 @param maxTransferSize Maximum size of an entire transfer. Default to 0 indicating no maximum.
329 @param alignment Alligment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment.
330 @result A new memory cursor if successfully created and initialised, 0 otherwise.
332 static IOLittleMemoryCursor
*
333 withSpecification(IOPhysicalLength maxSegmentSize
,
334 IOPhysicalLength maxTransferSize
,
335 IOPhysicalLength alignment
= 1);
337 /*! @function initWithSpecification
338 @abstract Primary initialiser for the IOLittleMemoryCursor class.
339 @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0.
340 @param maxTransferSize Maximum size of an entire transfer. Default to 0 indicating no maximum.
341 @param alignment Alligment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment.
342 @result true if the inherited classes and this instance initialise
345 virtual bool initWithSpecification(IOPhysicalLength maxSegmentSize
,
346 IOPhysicalLength maxTransferSize
,
347 IOPhysicalLength alignment
= 1);
350 /*! @function getPhysicalSegments
351 @abstract Generate a little endian physical scatter/gather list given a memory descriptor.
352 @discussion Generates a list of physical segments from the given memory descriptor, relative to the current position of the descriptor. Wraps $link IOMemoryCursor::genPhysicalSegments.
353 @param descriptor IOMemoryDescriptor that describes the data associated with an I/O request.
354 @param fromPosition Starting location of the I/O within a memory descriptor.
355 @param segments Pointer to an array of $link IOMemoryCursor::PhysicalSegments for the output physical scatter/gather list.
356 @param maxSegments Maximum number of segments that can be written to segments array.
357 @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.
358 @param transferSize Pointer to a IOByteCount variable that can contain the total size of the transfer being described. Default to 0 indicating that no transfer size need be returned.
359 @result If the descriptor is exhausted of memory, a zero is returned, otherwise the number of segments that were filled in is returned.
361 virtual UInt32
getPhysicalSegments(IOMemoryDescriptor
* descriptor
,
362 IOByteCount fromPosition
,
363 PhysicalSegment
* segments
,
365 UInt32 maxTransferSize
= 0,
366 IOByteCount
* transferSize
= 0)
368 return genPhysicalSegments(descriptor
, fromPosition
, segments
,
369 maxSegments
, maxTransferSize
, transferSize
);
373 /************************* class IODBDMAMemoryCursor *************************/
377 struct IODBDMADescriptor
;
380 @class IODBDMAMemoryCursor : public IOMemoryCursor
381 @abstract A $link IOMemoryCursor subclass that outputs a vector of DBDMA descriptors where the address and length are filled in.
382 @discussion The IODBDMAMemoryCursor would be used when the DBDMA hardware is available for the device for that will use an instance of this cursor.
384 class IODBDMAMemoryCursor
: public IOMemoryCursor
386 OSDeclareDefaultStructors(IODBDMAMemoryCursor
)
389 /*! @funtion outputSegment
390 @abstract Output the given segment into the output segments array in address and length fields of an DBDMA descriptor.
391 @param segment The physical address and length that is next to be output.
392 @param segments Base of the output vector of DMA address length pairs.
393 @param segmentIndex Index to output 'segment' in the 'segments' array.
395 static void outputSegment(PhysicalSegment segment
,
397 UInt32 segmentIndex
);
399 /*! @defined dbdmaOutputSegment
400 @discussion Backward compatibilty define for the old global function definition. See $link IODBDMAMemoryCursor::outputSegment */
401 #define dbdmaOutputSegment IODBDMAMemoryCursor::outputSegment
403 /*! @function withSpecification
404 @abstract Factory function to create and initialise an IODBDMAMemoryCursor in one operation, see $link IODBDMAMemoryCursor::initWithSpecification.
405 @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0.
406 @param maxTransferSize Maximum size of an entire transfer. Default to 0 indicating no maximum.
407 @param alignment Alligment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment.
408 @result A new memory cursor if successfully created and initialised, 0 otherwise.
410 static IODBDMAMemoryCursor
*
411 withSpecification(IOPhysicalLength maxSegmentSize
,
412 IOPhysicalLength maxTransferSize
,
413 IOPhysicalLength alignment
= 1);
415 /*! @function initWithSpecification
416 @abstract Primary initialiser for the IODBDMAMemoryCursor class.
417 @param maxSegmentSize Maximum allowable size for one segment. Defaults to 0.
418 @param maxTransferSize Maximum size of an entire transfer. Default to 0 indicating no maximum.
419 @param alignment Alligment restrictions on output physical addresses. Not currently implemented. Defaults to single byte alignment.
420 @result true if the inherited classes and this instance initialise
423 virtual bool initWithSpecification(IOPhysicalLength maxSegmentSize
,
424 IOPhysicalLength maxTransferSize
,
425 IOPhysicalLength alignment
= 1);
428 /*! @function getPhysicalSegments
429 @abstract Generate a DBDMA physical scatter/gather list given a memory descriptor.
430 @discussion Generates a list of DBDMA descriptors where the address and length fields are filled in appropriately. But the client is expected to fill in the rest of teh DBDMA descriptor as is appropriate for their particular hardware. Wraps $link IOMemoryCursor::genPhysicalSegments.
431 @param descriptor IOMemoryDescriptor that describes the data associated with an I/O request.
432 @param fromPosition Starting location of the I/O within a memory descriptor.
433 @param segments Pointer to an array of DBDMA descriptors for the output physical scatter/gather list. Be warned no room is left for a preamble in the output array. 'segments' should point to the first memory description slot in a DBDMA command.
434 @param maxSegments Maximum number of segments that can be written to the dbdma descriptor table.
435 @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.
436 @param transferSize Pointer to a IOByteCount variable that can contain the total size of the transfer being described. Default to 0 indicating that no transfer size need be returned.
437 @result If the descriptor is exhausted of memory, a zero is returned, otherwise the number of segments that were filled in is returned.
439 virtual UInt32
getPhysicalSegments(IOMemoryDescriptor
* descriptor
,
440 IOByteCount fromPosition
,
441 IODBDMADescriptor
* segments
,
443 UInt32 maxTransferSize
= 0,
444 IOByteCount
* transferSize
= 0)
446 return genPhysicalSegments(descriptor
, fromPosition
, segments
,
447 maxSegments
, maxTransferSize
, transferSize
);
451 #endif /* defined(__ppc__) */
453 #endif /* !_IOMEMORYCURSOR_H */