xref: /xnu-12377.41.6/iokit/Kernel/IOMemoryCursor.cpp (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1*bbb1b6f9SApple OSS Distributions /*
2*bbb1b6f9SApple OSS Distributions  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3*bbb1b6f9SApple OSS Distributions  *
4*bbb1b6f9SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*bbb1b6f9SApple OSS Distributions  *
6*bbb1b6f9SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*bbb1b6f9SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*bbb1b6f9SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*bbb1b6f9SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*bbb1b6f9SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*bbb1b6f9SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*bbb1b6f9SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*bbb1b6f9SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*bbb1b6f9SApple OSS Distributions  *
15*bbb1b6f9SApple OSS Distributions  * Please obtain a copy of the License at
16*bbb1b6f9SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*bbb1b6f9SApple OSS Distributions  *
18*bbb1b6f9SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*bbb1b6f9SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*bbb1b6f9SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*bbb1b6f9SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*bbb1b6f9SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*bbb1b6f9SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*bbb1b6f9SApple OSS Distributions  * limitations under the License.
25*bbb1b6f9SApple OSS Distributions  *
26*bbb1b6f9SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*bbb1b6f9SApple OSS Distributions  */
28*bbb1b6f9SApple OSS Distributions /* IOMemoryCursor.cpp created by wgulland on 1999-3-02 */
29*bbb1b6f9SApple OSS Distributions 
30*bbb1b6f9SApple OSS Distributions #define IOKIT_ENABLE_SHARED_PTR
31*bbb1b6f9SApple OSS Distributions 
32*bbb1b6f9SApple OSS Distributions #include <IOKit/assert.h>
33*bbb1b6f9SApple OSS Distributions #include <IOKit/IOLib.h>
34*bbb1b6f9SApple OSS Distributions #include <IOKit/IOMemoryCursor.h>
35*bbb1b6f9SApple OSS Distributions #include <IOKit/IOMemoryDescriptor.h>
36*bbb1b6f9SApple OSS Distributions #include <libkern/OSByteOrder.h>
37*bbb1b6f9SApple OSS Distributions 
38*bbb1b6f9SApple OSS Distributions /**************************** class IOMemoryCursor ***************************/
39*bbb1b6f9SApple OSS Distributions 
40*bbb1b6f9SApple OSS Distributions #undef super
41*bbb1b6f9SApple OSS Distributions #define super OSObject
OSDefineMetaClassAndStructors(IOMemoryCursor,OSObject)42*bbb1b6f9SApple OSS Distributions OSDefineMetaClassAndStructors(IOMemoryCursor, OSObject)
43*bbb1b6f9SApple OSS Distributions 
44*bbb1b6f9SApple OSS Distributions OSSharedPtr<IOMemoryCursor>
45*bbb1b6f9SApple OSS Distributions IOMemoryCursor::withSpecification(SegmentFunction  inSegFunc,
46*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inMaxSegmentSize,
47*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inMaxTransferSize,
48*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inAlignment)
49*bbb1b6f9SApple OSS Distributions {
50*bbb1b6f9SApple OSS Distributions 	OSSharedPtr<IOMemoryCursor> me = OSMakeShared<IOMemoryCursor>();
51*bbb1b6f9SApple OSS Distributions 
52*bbb1b6f9SApple OSS Distributions 	if (me && !me->initWithSpecification(inSegFunc,
53*bbb1b6f9SApple OSS Distributions 	    inMaxSegmentSize,
54*bbb1b6f9SApple OSS Distributions 	    inMaxTransferSize,
55*bbb1b6f9SApple OSS Distributions 	    inAlignment)) {
56*bbb1b6f9SApple OSS Distributions 		return nullptr;
57*bbb1b6f9SApple OSS Distributions 	}
58*bbb1b6f9SApple OSS Distributions 
59*bbb1b6f9SApple OSS Distributions 	return me;
60*bbb1b6f9SApple OSS Distributions }
61*bbb1b6f9SApple OSS Distributions 
62*bbb1b6f9SApple OSS Distributions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
63*bbb1b6f9SApple OSS Distributions 
64*bbb1b6f9SApple OSS Distributions bool
initWithSpecification(SegmentFunction inSegFunc,IOPhysicalLength inMaxSegmentSize,IOPhysicalLength inMaxTransferSize,IOPhysicalLength inAlignment)65*bbb1b6f9SApple OSS Distributions IOMemoryCursor::initWithSpecification(SegmentFunction  inSegFunc,
66*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inMaxSegmentSize,
67*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inMaxTransferSize,
68*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inAlignment)
69*bbb1b6f9SApple OSS Distributions {
70*bbb1b6f9SApple OSS Distributions // @@@ gvdl: Remove me
71*bbb1b6f9SApple OSS Distributions #if 1
72*bbb1b6f9SApple OSS Distributions 	static UInt sMaxDBDMASegment;
73*bbb1b6f9SApple OSS Distributions 	if (!sMaxDBDMASegment) {
74*bbb1b6f9SApple OSS Distributions 		sMaxDBDMASegment = (UInt) - 1;
75*bbb1b6f9SApple OSS Distributions 		if (PE_parse_boot_argn("mseg", &sMaxDBDMASegment, sizeof(sMaxDBDMASegment))) {
76*bbb1b6f9SApple OSS Distributions 			IOLog("Setting MaxDBDMASegment to %d\n", sMaxDBDMASegment);
77*bbb1b6f9SApple OSS Distributions 		}
78*bbb1b6f9SApple OSS Distributions 	}
79*bbb1b6f9SApple OSS Distributions 
80*bbb1b6f9SApple OSS Distributions 	if (inMaxSegmentSize > sMaxDBDMASegment) {
81*bbb1b6f9SApple OSS Distributions 		inMaxSegmentSize = sMaxDBDMASegment;
82*bbb1b6f9SApple OSS Distributions 	}
83*bbb1b6f9SApple OSS Distributions #endif
84*bbb1b6f9SApple OSS Distributions 
85*bbb1b6f9SApple OSS Distributions 	if (!super::init()) {
86*bbb1b6f9SApple OSS Distributions 		return false;
87*bbb1b6f9SApple OSS Distributions 	}
88*bbb1b6f9SApple OSS Distributions 
89*bbb1b6f9SApple OSS Distributions 	if (!inSegFunc) {
90*bbb1b6f9SApple OSS Distributions 		return false;
91*bbb1b6f9SApple OSS Distributions 	}
92*bbb1b6f9SApple OSS Distributions 	if (inMaxTransferSize > UINT_MAX) {
93*bbb1b6f9SApple OSS Distributions 		return false;
94*bbb1b6f9SApple OSS Distributions 	}
95*bbb1b6f9SApple OSS Distributions 
96*bbb1b6f9SApple OSS Distributions 	outSeg              = inSegFunc;
97*bbb1b6f9SApple OSS Distributions 	maxSegmentSize      = inMaxSegmentSize;
98*bbb1b6f9SApple OSS Distributions 	if (inMaxTransferSize) {
99*bbb1b6f9SApple OSS Distributions 		maxTransferSize = inMaxTransferSize;
100*bbb1b6f9SApple OSS Distributions 	} else {
101*bbb1b6f9SApple OSS Distributions 		maxTransferSize = (IOPhysicalLength) - 1;
102*bbb1b6f9SApple OSS Distributions 	}
103*bbb1b6f9SApple OSS Distributions 	alignMask           = inAlignment - 1;
104*bbb1b6f9SApple OSS Distributions 	assert(alignMask == 0);         // No alignment code yet!
105*bbb1b6f9SApple OSS Distributions 
106*bbb1b6f9SApple OSS Distributions 	return true;
107*bbb1b6f9SApple OSS Distributions }
108*bbb1b6f9SApple OSS Distributions 
109*bbb1b6f9SApple OSS Distributions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
110*bbb1b6f9SApple OSS Distributions 
111*bbb1b6f9SApple OSS Distributions UInt32
genPhysicalSegments(IOMemoryDescriptor * inDescriptor,IOByteCount fromPosition,void * inSegments,UInt32 inMaxSegments,UInt32 inMaxTransferSize,IOByteCount * outTransferSize)112*bbb1b6f9SApple OSS Distributions IOMemoryCursor::genPhysicalSegments(IOMemoryDescriptor *inDescriptor,
113*bbb1b6f9SApple OSS Distributions     IOByteCount         fromPosition,
114*bbb1b6f9SApple OSS Distributions     void *              inSegments,
115*bbb1b6f9SApple OSS Distributions     UInt32              inMaxSegments,
116*bbb1b6f9SApple OSS Distributions     UInt32              inMaxTransferSize,
117*bbb1b6f9SApple OSS Distributions     IOByteCount         *outTransferSize)
118*bbb1b6f9SApple OSS Distributions {
119*bbb1b6f9SApple OSS Distributions 	if (!inDescriptor) {
120*bbb1b6f9SApple OSS Distributions 		return 0;
121*bbb1b6f9SApple OSS Distributions 	}
122*bbb1b6f9SApple OSS Distributions 
123*bbb1b6f9SApple OSS Distributions 	if (!inMaxSegments) {
124*bbb1b6f9SApple OSS Distributions 		return 0;
125*bbb1b6f9SApple OSS Distributions 	}
126*bbb1b6f9SApple OSS Distributions 
127*bbb1b6f9SApple OSS Distributions 	if (!inMaxTransferSize) {
128*bbb1b6f9SApple OSS Distributions 		inMaxTransferSize = (typeof(inMaxTransferSize))maxTransferSize;
129*bbb1b6f9SApple OSS Distributions 	}
130*bbb1b6f9SApple OSS Distributions 
131*bbb1b6f9SApple OSS Distributions 	/*
132*bbb1b6f9SApple OSS Distributions 	 * Iterate over the packet, translating segments where allowed
133*bbb1b6f9SApple OSS Distributions 	 *
134*bbb1b6f9SApple OSS Distributions 	 * If we finished cleanly return number of segments found
135*bbb1b6f9SApple OSS Distributions 	 * and update the position in the descriptor.
136*bbb1b6f9SApple OSS Distributions 	 */
137*bbb1b6f9SApple OSS Distributions 	PhysicalSegment curSeg = { 0, 0 };
138*bbb1b6f9SApple OSS Distributions 	UInt curSegIndex = 0;
139*bbb1b6f9SApple OSS Distributions 	UInt curTransferSize = 0;
140*bbb1b6f9SApple OSS Distributions 	IOByteCount inDescriptorLength = inDescriptor->getLength();
141*bbb1b6f9SApple OSS Distributions 	PhysicalSegment seg = { 0, 0 };
142*bbb1b6f9SApple OSS Distributions 
143*bbb1b6f9SApple OSS Distributions 	while ((seg.location) || (fromPosition < inDescriptorLength)) {
144*bbb1b6f9SApple OSS Distributions 		if (!seg.location) {
145*bbb1b6f9SApple OSS Distributions 			seg.location = inDescriptor->getPhysicalSegment(
146*bbb1b6f9SApple OSS Distributions 				fromPosition, (IOByteCount*)&seg.length);
147*bbb1b6f9SApple OSS Distributions 			assert(seg.location);
148*bbb1b6f9SApple OSS Distributions 			assert(seg.length);
149*bbb1b6f9SApple OSS Distributions 			fromPosition += seg.length;
150*bbb1b6f9SApple OSS Distributions 		}
151*bbb1b6f9SApple OSS Distributions 
152*bbb1b6f9SApple OSS Distributions 		if (!curSeg.location) {
153*bbb1b6f9SApple OSS Distributions 			curTransferSize += seg.length;
154*bbb1b6f9SApple OSS Distributions 			curSeg = seg;
155*bbb1b6f9SApple OSS Distributions 			seg.location = 0;
156*bbb1b6f9SApple OSS Distributions 		} else if ((curSeg.location + curSeg.length == seg.location)) {
157*bbb1b6f9SApple OSS Distributions 			curTransferSize += seg.length;
158*bbb1b6f9SApple OSS Distributions 			curSeg.length += seg.length;
159*bbb1b6f9SApple OSS Distributions 			seg.location = 0;
160*bbb1b6f9SApple OSS Distributions 		}
161*bbb1b6f9SApple OSS Distributions 
162*bbb1b6f9SApple OSS Distributions 		if (!seg.location) {
163*bbb1b6f9SApple OSS Distributions 			if ((curSeg.length > maxSegmentSize)) {
164*bbb1b6f9SApple OSS Distributions 				seg.location = curSeg.location + maxSegmentSize;
165*bbb1b6f9SApple OSS Distributions 				seg.length = curSeg.length - maxSegmentSize;
166*bbb1b6f9SApple OSS Distributions 				curTransferSize -= seg.length;
167*bbb1b6f9SApple OSS Distributions 				curSeg.length -= seg.length;
168*bbb1b6f9SApple OSS Distributions 			}
169*bbb1b6f9SApple OSS Distributions 
170*bbb1b6f9SApple OSS Distributions 			if ((curTransferSize >= inMaxTransferSize)) {
171*bbb1b6f9SApple OSS Distributions 				curSeg.length -= curTransferSize - inMaxTransferSize;
172*bbb1b6f9SApple OSS Distributions 				curTransferSize = inMaxTransferSize;
173*bbb1b6f9SApple OSS Distributions 				break;
174*bbb1b6f9SApple OSS Distributions 			}
175*bbb1b6f9SApple OSS Distributions 		}
176*bbb1b6f9SApple OSS Distributions 
177*bbb1b6f9SApple OSS Distributions 		if (seg.location) {
178*bbb1b6f9SApple OSS Distributions 			if ((curSegIndex + 1 == inMaxSegments)) {
179*bbb1b6f9SApple OSS Distributions 				break;
180*bbb1b6f9SApple OSS Distributions 			}
181*bbb1b6f9SApple OSS Distributions 			(*outSeg)(curSeg, inSegments, curSegIndex++);
182*bbb1b6f9SApple OSS Distributions 			curSeg.location = 0;
183*bbb1b6f9SApple OSS Distributions 		}
184*bbb1b6f9SApple OSS Distributions 	}
185*bbb1b6f9SApple OSS Distributions 
186*bbb1b6f9SApple OSS Distributions 	if (curSeg.location) {
187*bbb1b6f9SApple OSS Distributions 		(*outSeg)(curSeg, inSegments, curSegIndex++);
188*bbb1b6f9SApple OSS Distributions 	}
189*bbb1b6f9SApple OSS Distributions 
190*bbb1b6f9SApple OSS Distributions 	if (outTransferSize) {
191*bbb1b6f9SApple OSS Distributions 		*outTransferSize = curTransferSize;
192*bbb1b6f9SApple OSS Distributions 	}
193*bbb1b6f9SApple OSS Distributions 
194*bbb1b6f9SApple OSS Distributions 	return curSegIndex;
195*bbb1b6f9SApple OSS Distributions }
196*bbb1b6f9SApple OSS Distributions 
197*bbb1b6f9SApple OSS Distributions /************************ class IONaturalMemoryCursor ************************/
198*bbb1b6f9SApple OSS Distributions 
199*bbb1b6f9SApple OSS Distributions #undef super
200*bbb1b6f9SApple OSS Distributions #define super IOMemoryCursor
OSDefineMetaClassAndStructors(IONaturalMemoryCursor,IOMemoryCursor)201*bbb1b6f9SApple OSS Distributions OSDefineMetaClassAndStructors(IONaturalMemoryCursor, IOMemoryCursor)
202*bbb1b6f9SApple OSS Distributions 
203*bbb1b6f9SApple OSS Distributions void
204*bbb1b6f9SApple OSS Distributions IONaturalMemoryCursor::outputSegment(PhysicalSegment segment,
205*bbb1b6f9SApple OSS Distributions     void *          outSegments,
206*bbb1b6f9SApple OSS Distributions     UInt32          outSegmentIndex)
207*bbb1b6f9SApple OSS Distributions {
208*bbb1b6f9SApple OSS Distributions 	((PhysicalSegment *) outSegments)[outSegmentIndex] = segment;
209*bbb1b6f9SApple OSS Distributions }
210*bbb1b6f9SApple OSS Distributions 
211*bbb1b6f9SApple OSS Distributions OSSharedPtr<IONaturalMemoryCursor>
withSpecification(IOPhysicalLength inMaxSegmentSize,IOPhysicalLength inMaxTransferSize,IOPhysicalLength inAlignment)212*bbb1b6f9SApple OSS Distributions IONaturalMemoryCursor::withSpecification(IOPhysicalLength inMaxSegmentSize,
213*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inMaxTransferSize,
214*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inAlignment)
215*bbb1b6f9SApple OSS Distributions {
216*bbb1b6f9SApple OSS Distributions 	OSSharedPtr<IONaturalMemoryCursor> me = OSMakeShared<IONaturalMemoryCursor>();
217*bbb1b6f9SApple OSS Distributions 
218*bbb1b6f9SApple OSS Distributions 	if (me && !me->initWithSpecification(inMaxSegmentSize,
219*bbb1b6f9SApple OSS Distributions 	    inMaxTransferSize,
220*bbb1b6f9SApple OSS Distributions 	    inAlignment)) {
221*bbb1b6f9SApple OSS Distributions 		return nullptr;
222*bbb1b6f9SApple OSS Distributions 	}
223*bbb1b6f9SApple OSS Distributions 
224*bbb1b6f9SApple OSS Distributions 	return me;
225*bbb1b6f9SApple OSS Distributions }
226*bbb1b6f9SApple OSS Distributions 
227*bbb1b6f9SApple OSS Distributions bool
initWithSpecification(IOPhysicalLength inMaxSegmentSize,IOPhysicalLength inMaxTransferSize,IOPhysicalLength inAlignment)228*bbb1b6f9SApple OSS Distributions IONaturalMemoryCursor::initWithSpecification(IOPhysicalLength inMaxSegmentSize,
229*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inMaxTransferSize,
230*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inAlignment)
231*bbb1b6f9SApple OSS Distributions {
232*bbb1b6f9SApple OSS Distributions 	return super::initWithSpecification(&IONaturalMemoryCursor::outputSegment,
233*bbb1b6f9SApple OSS Distributions 	           inMaxSegmentSize,
234*bbb1b6f9SApple OSS Distributions 	           inMaxTransferSize,
235*bbb1b6f9SApple OSS Distributions 	           inAlignment);
236*bbb1b6f9SApple OSS Distributions }
237*bbb1b6f9SApple OSS Distributions 
238*bbb1b6f9SApple OSS Distributions /************************** class IOBigMemoryCursor **************************/
239*bbb1b6f9SApple OSS Distributions 
240*bbb1b6f9SApple OSS Distributions #undef super
241*bbb1b6f9SApple OSS Distributions #define super IOMemoryCursor
OSDefineMetaClassAndStructors(IOBigMemoryCursor,IOMemoryCursor)242*bbb1b6f9SApple OSS Distributions OSDefineMetaClassAndStructors(IOBigMemoryCursor, IOMemoryCursor)
243*bbb1b6f9SApple OSS Distributions 
244*bbb1b6f9SApple OSS Distributions void
245*bbb1b6f9SApple OSS Distributions IOBigMemoryCursor::outputSegment(PhysicalSegment inSegment,
246*bbb1b6f9SApple OSS Distributions     void *          inSegments,
247*bbb1b6f9SApple OSS Distributions     UInt32          inSegmentIndex)
248*bbb1b6f9SApple OSS Distributions {
249*bbb1b6f9SApple OSS Distributions 	IOPhysicalAddress * segment;
250*bbb1b6f9SApple OSS Distributions 
251*bbb1b6f9SApple OSS Distributions 	segment = &((PhysicalSegment *) inSegments)[inSegmentIndex].location;
252*bbb1b6f9SApple OSS Distributions #if IOPhysSize == 64
253*bbb1b6f9SApple OSS Distributions 	OSWriteBigInt64(segment, 0, inSegment.location);
254*bbb1b6f9SApple OSS Distributions 	OSWriteBigInt64(segment, sizeof(IOPhysicalAddress), inSegment.length);
255*bbb1b6f9SApple OSS Distributions #else
256*bbb1b6f9SApple OSS Distributions 	OSWriteBigInt(segment, 0, inSegment.location);
257*bbb1b6f9SApple OSS Distributions 	OSWriteBigInt(segment, sizeof(IOPhysicalAddress), inSegment.length);
258*bbb1b6f9SApple OSS Distributions #endif
259*bbb1b6f9SApple OSS Distributions }
260*bbb1b6f9SApple OSS Distributions 
261*bbb1b6f9SApple OSS Distributions OSSharedPtr<IOBigMemoryCursor>
withSpecification(IOPhysicalLength inMaxSegmentSize,IOPhysicalLength inMaxTransferSize,IOPhysicalLength inAlignment)262*bbb1b6f9SApple OSS Distributions IOBigMemoryCursor::withSpecification(IOPhysicalLength inMaxSegmentSize,
263*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inMaxTransferSize,
264*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inAlignment)
265*bbb1b6f9SApple OSS Distributions {
266*bbb1b6f9SApple OSS Distributions 	OSSharedPtr<IOBigMemoryCursor> me = OSMakeShared<IOBigMemoryCursor>();
267*bbb1b6f9SApple OSS Distributions 
268*bbb1b6f9SApple OSS Distributions 	if (me && !me->initWithSpecification(inMaxSegmentSize,
269*bbb1b6f9SApple OSS Distributions 	    inMaxTransferSize,
270*bbb1b6f9SApple OSS Distributions 	    inAlignment)) {
271*bbb1b6f9SApple OSS Distributions 		return nullptr;
272*bbb1b6f9SApple OSS Distributions 	}
273*bbb1b6f9SApple OSS Distributions 
274*bbb1b6f9SApple OSS Distributions 	return me;
275*bbb1b6f9SApple OSS Distributions }
276*bbb1b6f9SApple OSS Distributions 
277*bbb1b6f9SApple OSS Distributions bool
initWithSpecification(IOPhysicalLength inMaxSegmentSize,IOPhysicalLength inMaxTransferSize,IOPhysicalLength inAlignment)278*bbb1b6f9SApple OSS Distributions IOBigMemoryCursor::initWithSpecification(IOPhysicalLength inMaxSegmentSize,
279*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inMaxTransferSize,
280*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inAlignment)
281*bbb1b6f9SApple OSS Distributions {
282*bbb1b6f9SApple OSS Distributions 	return super::initWithSpecification(&IOBigMemoryCursor::outputSegment,
283*bbb1b6f9SApple OSS Distributions 	           inMaxSegmentSize,
284*bbb1b6f9SApple OSS Distributions 	           inMaxTransferSize,
285*bbb1b6f9SApple OSS Distributions 	           inAlignment);
286*bbb1b6f9SApple OSS Distributions }
287*bbb1b6f9SApple OSS Distributions 
288*bbb1b6f9SApple OSS Distributions /************************* class IOLittleMemoryCursor ************************/
289*bbb1b6f9SApple OSS Distributions 
290*bbb1b6f9SApple OSS Distributions #undef super
291*bbb1b6f9SApple OSS Distributions #define super IOMemoryCursor
OSDefineMetaClassAndStructors(IOLittleMemoryCursor,IOMemoryCursor)292*bbb1b6f9SApple OSS Distributions OSDefineMetaClassAndStructors(IOLittleMemoryCursor, IOMemoryCursor)
293*bbb1b6f9SApple OSS Distributions 
294*bbb1b6f9SApple OSS Distributions void
295*bbb1b6f9SApple OSS Distributions IOLittleMemoryCursor::outputSegment(PhysicalSegment inSegment,
296*bbb1b6f9SApple OSS Distributions     void *          inSegments,
297*bbb1b6f9SApple OSS Distributions     UInt32          inSegmentIndex)
298*bbb1b6f9SApple OSS Distributions {
299*bbb1b6f9SApple OSS Distributions 	IOPhysicalAddress * segment;
300*bbb1b6f9SApple OSS Distributions 
301*bbb1b6f9SApple OSS Distributions 	segment = &((PhysicalSegment *) inSegments)[inSegmentIndex].location;
302*bbb1b6f9SApple OSS Distributions #if IOPhysSize == 64
303*bbb1b6f9SApple OSS Distributions 	OSWriteLittleInt64(segment, 0, inSegment.location);
304*bbb1b6f9SApple OSS Distributions 	OSWriteLittleInt64(segment, sizeof(IOPhysicalAddress), inSegment.length);
305*bbb1b6f9SApple OSS Distributions #else
306*bbb1b6f9SApple OSS Distributions 	OSWriteLittleInt(segment, 0, inSegment.location);
307*bbb1b6f9SApple OSS Distributions 	OSWriteLittleInt(segment, sizeof(IOPhysicalAddress), inSegment.length);
308*bbb1b6f9SApple OSS Distributions #endif
309*bbb1b6f9SApple OSS Distributions }
310*bbb1b6f9SApple OSS Distributions 
311*bbb1b6f9SApple OSS Distributions OSSharedPtr<IOLittleMemoryCursor>
withSpecification(IOPhysicalLength inMaxSegmentSize,IOPhysicalLength inMaxTransferSize,IOPhysicalLength inAlignment)312*bbb1b6f9SApple OSS Distributions IOLittleMemoryCursor::withSpecification(IOPhysicalLength inMaxSegmentSize,
313*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inMaxTransferSize,
314*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inAlignment)
315*bbb1b6f9SApple OSS Distributions {
316*bbb1b6f9SApple OSS Distributions 	OSSharedPtr<IOLittleMemoryCursor> me = OSMakeShared<IOLittleMemoryCursor>();
317*bbb1b6f9SApple OSS Distributions 
318*bbb1b6f9SApple OSS Distributions 	if (me && !me->initWithSpecification(inMaxSegmentSize,
319*bbb1b6f9SApple OSS Distributions 	    inMaxTransferSize,
320*bbb1b6f9SApple OSS Distributions 	    inAlignment)) {
321*bbb1b6f9SApple OSS Distributions 		return nullptr;
322*bbb1b6f9SApple OSS Distributions 	}
323*bbb1b6f9SApple OSS Distributions 
324*bbb1b6f9SApple OSS Distributions 	return me;
325*bbb1b6f9SApple OSS Distributions }
326*bbb1b6f9SApple OSS Distributions 
327*bbb1b6f9SApple OSS Distributions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
328*bbb1b6f9SApple OSS Distributions 
329*bbb1b6f9SApple OSS Distributions bool
initWithSpecification(IOPhysicalLength inMaxSegmentSize,IOPhysicalLength inMaxTransferSize,IOPhysicalLength inAlignment)330*bbb1b6f9SApple OSS Distributions IOLittleMemoryCursor::initWithSpecification(IOPhysicalLength inMaxSegmentSize,
331*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inMaxTransferSize,
332*bbb1b6f9SApple OSS Distributions     IOPhysicalLength inAlignment)
333*bbb1b6f9SApple OSS Distributions {
334*bbb1b6f9SApple OSS Distributions 	return super::initWithSpecification(&IOLittleMemoryCursor::outputSegment,
335*bbb1b6f9SApple OSS Distributions 	           inMaxSegmentSize,
336*bbb1b6f9SApple OSS Distributions 	           inMaxTransferSize,
337*bbb1b6f9SApple OSS Distributions 	           inAlignment);
338*bbb1b6f9SApple OSS Distributions }
339