xref: /xnu-10002.41.9/iokit/IOKit/IOMemoryDescriptor.h (revision 699cd48037512bf4380799317ca44ca453c82f57)
1*699cd480SApple OSS Distributions /*
2*699cd480SApple OSS Distributions  * Copyright (c) 1998-2020 Apple Inc. All rights reserved.
3*699cd480SApple OSS Distributions  *
4*699cd480SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*699cd480SApple OSS Distributions  *
6*699cd480SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*699cd480SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*699cd480SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*699cd480SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*699cd480SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*699cd480SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*699cd480SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*699cd480SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*699cd480SApple OSS Distributions  *
15*699cd480SApple OSS Distributions  * Please obtain a copy of the License at
16*699cd480SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*699cd480SApple OSS Distributions  *
18*699cd480SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*699cd480SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*699cd480SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*699cd480SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*699cd480SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*699cd480SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*699cd480SApple OSS Distributions  * limitations under the License.
25*699cd480SApple OSS Distributions  *
26*699cd480SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*699cd480SApple OSS Distributions  */
28*699cd480SApple OSS Distributions #ifndef _IOMEMORYDESCRIPTOR_H
29*699cd480SApple OSS Distributions #define _IOMEMORYDESCRIPTOR_H
30*699cd480SApple OSS Distributions 
31*699cd480SApple OSS Distributions #include <sys/cdefs.h>
32*699cd480SApple OSS Distributions 
33*699cd480SApple OSS Distributions #include <IOKit/IOTypes.h>
34*699cd480SApple OSS Distributions #include <IOKit/IOLocks.h>
35*699cd480SApple OSS Distributions #include <libkern/c++/OSPtr.h>
36*699cd480SApple OSS Distributions #include <libkern/c++/OSContainers.h>
37*699cd480SApple OSS Distributions #include <DriverKit/IOMemoryDescriptor.h>
38*699cd480SApple OSS Distributions #include <DriverKit/IOMemoryMap.h>
39*699cd480SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
40*699cd480SApple OSS Distributions #include <IOKit/IOKitDebug.h>
41*699cd480SApple OSS Distributions #endif
42*699cd480SApple OSS Distributions 
43*699cd480SApple OSS Distributions #include <mach/memory_object_types.h>
44*699cd480SApple OSS Distributions 
45*699cd480SApple OSS Distributions class IOMemoryDescriptor;
46*699cd480SApple OSS Distributions class IOMemoryMap;
47*699cd480SApple OSS Distributions class IOMapper;
48*699cd480SApple OSS Distributions class IOService;
49*699cd480SApple OSS Distributions class IODMACommand;
50*699cd480SApple OSS Distributions class _IOMemoryDescriptorMixedData;
51*699cd480SApple OSS Distributions 
52*699cd480SApple OSS Distributions /*
53*699cd480SApple OSS Distributions  * Direction of transfer, with respect to the described memory.
54*699cd480SApple OSS Distributions  */
55*699cd480SApple OSS Distributions #ifdef __LP64__
56*699cd480SApple OSS Distributions enum
57*699cd480SApple OSS Distributions #else /* !__LP64__ */
58*699cd480SApple OSS Distributions enum IODirection
59*699cd480SApple OSS Distributions #endif /* !__LP64__ */
60*699cd480SApple OSS Distributions {
61*699cd480SApple OSS Distributions 	kIODirectionNone  = 0x0,//                    same as VM_PROT_NONE
62*699cd480SApple OSS Distributions 	kIODirectionIn    = 0x1,// User land 'read',  same as VM_PROT_READ
63*699cd480SApple OSS Distributions 	kIODirectionOut   = 0x2,// User land 'write', same as VM_PROT_WRITE
64*699cd480SApple OSS Distributions 	kIODirectionOutIn = kIODirectionOut | kIODirectionIn,
65*699cd480SApple OSS Distributions 	kIODirectionInOut = kIODirectionIn  | kIODirectionOut,
66*699cd480SApple OSS Distributions 
67*699cd480SApple OSS Distributions 	// these flags are valid for the prepare() method only
68*699cd480SApple OSS Distributions 	kIODirectionPrepareToPhys32   = 0x00000004,
69*699cd480SApple OSS Distributions 	kIODirectionPrepareNoFault    = 0x00000008,
70*699cd480SApple OSS Distributions 	kIODirectionPrepareReserved1  = 0x00000010,
71*699cd480SApple OSS Distributions #define IODIRECTIONPREPARENONCOHERENTDEFINED    1
72*699cd480SApple OSS Distributions 	kIODirectionPrepareNonCoherent = 0x00000020,
73*699cd480SApple OSS Distributions #if KERNEL_PRIVATE
74*699cd480SApple OSS Distributions #define IODIRECTIONPREPAREAVOIDTHROTTLING       1
75*699cd480SApple OSS Distributions 	kIODirectionPrepareAvoidThrottling = 0x00000100,
76*699cd480SApple OSS Distributions #endif
77*699cd480SApple OSS Distributions 
78*699cd480SApple OSS Distributions 	// these flags are valid for the complete() method only
79*699cd480SApple OSS Distributions #define IODIRECTIONCOMPLETEWITHERRORDEFINED             1
80*699cd480SApple OSS Distributions 	kIODirectionCompleteWithError = 0x00000040,
81*699cd480SApple OSS Distributions #define IODIRECTIONCOMPLETEWITHDATAVALIDDEFINED 1
82*699cd480SApple OSS Distributions 	kIODirectionCompleteWithDataValid = 0x00000080,
83*699cd480SApple OSS Distributions };
84*699cd480SApple OSS Distributions 
85*699cd480SApple OSS Distributions #ifdef __LP64__
86*699cd480SApple OSS Distributions typedef IOOptionBits IODirection;
87*699cd480SApple OSS Distributions #endif /* __LP64__ */
88*699cd480SApple OSS Distributions 
89*699cd480SApple OSS Distributions /*
90*699cd480SApple OSS Distributions  * IOOptionBits used in the withOptions variant
91*699cd480SApple OSS Distributions  */
92*699cd480SApple OSS Distributions enum {
93*699cd480SApple OSS Distributions 	kIOMemoryDirectionMask      = 0x00000007,
94*699cd480SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
95*699cd480SApple OSS Distributions 	kIOMemoryAutoPrepare        = 0x00000008,// Shared with Buffer MD
96*699cd480SApple OSS Distributions #endif
97*699cd480SApple OSS Distributions 
98*699cd480SApple OSS Distributions 	kIOMemoryTypeVirtual        = 0x00000010,
99*699cd480SApple OSS Distributions 	kIOMemoryTypePhysical       = 0x00000020,
100*699cd480SApple OSS Distributions 	kIOMemoryTypeUPL            = 0x00000030,
101*699cd480SApple OSS Distributions 	kIOMemoryTypePersistentMD   = 0x00000040,// Persistent Memory Descriptor
102*699cd480SApple OSS Distributions 	kIOMemoryTypeUIO            = 0x00000050,
103*699cd480SApple OSS Distributions #ifdef __LP64__
104*699cd480SApple OSS Distributions 	kIOMemoryTypeVirtual64      = kIOMemoryTypeVirtual,
105*699cd480SApple OSS Distributions 	kIOMemoryTypePhysical64     = kIOMemoryTypePhysical,
106*699cd480SApple OSS Distributions #else /* !__LP64__ */
107*699cd480SApple OSS Distributions 	kIOMemoryTypeVirtual64      = 0x00000060,
108*699cd480SApple OSS Distributions 	kIOMemoryTypePhysical64     = 0x00000070,
109*699cd480SApple OSS Distributions #endif /* !__LP64__ */
110*699cd480SApple OSS Distributions 	kIOMemoryTypeMask           = 0x000000f0,
111*699cd480SApple OSS Distributions 
112*699cd480SApple OSS Distributions 	kIOMemoryAsReference        = 0x00000100,
113*699cd480SApple OSS Distributions 	kIOMemoryBufferPageable     = 0x00000400,
114*699cd480SApple OSS Distributions 	kIOMemoryMapperNone         = 0x00000800,// Shared with Buffer MD
115*699cd480SApple OSS Distributions 	kIOMemoryHostOnly           = 0x00001000,// Never DMA accessible
116*699cd480SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
117*699cd480SApple OSS Distributions 	kIOMemoryRedirected         = 0x00004000,
118*699cd480SApple OSS Distributions 	kIOMemoryPreparedReadOnly   = 0x00008000,
119*699cd480SApple OSS Distributions #endif
120*699cd480SApple OSS Distributions 	kIOMemoryPersistent         = 0x00010000,
121*699cd480SApple OSS Distributions 	kIOMemoryMapCopyOnWrite     = 0x00020000,
122*699cd480SApple OSS Distributions 	kIOMemoryRemote             = 0x00040000,
123*699cd480SApple OSS Distributions 	kIOMemoryThreadSafe         = 0x00100000,// Shared with Buffer MD
124*699cd480SApple OSS Distributions 	kIOMemoryClearEncrypt       = 0x00200000,// Shared with Buffer MD
125*699cd480SApple OSS Distributions 	kIOMemoryUseReserve         = 0x00800000,// Shared with Buffer MD
126*699cd480SApple OSS Distributions #define IOMEMORYUSERESERVEDEFINED       1
127*699cd480SApple OSS Distributions 
128*699cd480SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
129*699cd480SApple OSS Distributions 	kIOMemoryBufferPurgeable    = 0x00400000,
130*699cd480SApple OSS Distributions 	kIOMemoryBufferCacheMask    = 0x70000000,
131*699cd480SApple OSS Distributions 	kIOMemoryBufferCacheShift   = 28,
132*699cd480SApple OSS Distributions #endif
133*699cd480SApple OSS Distributions };
134*699cd480SApple OSS Distributions 
135*699cd480SApple OSS Distributions #define kIOMapperSystem ((IOMapper *) NULL)
136*699cd480SApple OSS Distributions 
137*699cd480SApple OSS Distributions enum{
138*699cd480SApple OSS Distributions 	kIOMemoryLedgerTagDefault       = VM_LEDGER_TAG_DEFAULT,
139*699cd480SApple OSS Distributions 	kIOmemoryLedgerTagNetwork       = VM_LEDGER_TAG_NETWORK,
140*699cd480SApple OSS Distributions 	kIOMemoryLedgerTagMedia         = VM_LEDGER_TAG_MEDIA,
141*699cd480SApple OSS Distributions 	kIOMemoryLedgerTagGraphics      = VM_LEDGER_TAG_GRAPHICS,
142*699cd480SApple OSS Distributions 	kIOMemoryLedgerTagNeural        = VM_LEDGER_TAG_NEURAL,
143*699cd480SApple OSS Distributions };
144*699cd480SApple OSS Distributions enum{
145*699cd480SApple OSS Distributions 	kIOMemoryLedgerFlagNoFootprint  = VM_LEDGER_FLAG_NO_FOOTPRINT,
146*699cd480SApple OSS Distributions };
147*699cd480SApple OSS Distributions 
148*699cd480SApple OSS Distributions enum{
149*699cd480SApple OSS Distributions 	kIOMemoryPurgeableKeepCurrent = 1,
150*699cd480SApple OSS Distributions 
151*699cd480SApple OSS Distributions 	kIOMemoryPurgeableNonVolatile = 2,
152*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatile    = 3,
153*699cd480SApple OSS Distributions 	kIOMemoryPurgeableEmpty       = 4,
154*699cd480SApple OSS Distributions 
155*699cd480SApple OSS Distributions 	// modifiers for kIOMemoryPurgeableVolatile behavior
156*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatileGroup0           = VM_VOLATILE_GROUP_0,
157*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatileGroup1           = VM_VOLATILE_GROUP_1,
158*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatileGroup2           = VM_VOLATILE_GROUP_2,
159*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatileGroup3           = VM_VOLATILE_GROUP_3,
160*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatileGroup4           = VM_VOLATILE_GROUP_4,
161*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatileGroup5           = VM_VOLATILE_GROUP_5,
162*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatileGroup6           = VM_VOLATILE_GROUP_6,
163*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatileGroup7           = VM_VOLATILE_GROUP_7,
164*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatileBehaviorFifo     = VM_PURGABLE_BEHAVIOR_FIFO,
165*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatileBehaviorLifo     = VM_PURGABLE_BEHAVIOR_LIFO,
166*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatileOrderingObsolete = VM_PURGABLE_ORDERING_OBSOLETE,
167*699cd480SApple OSS Distributions 	kIOMemoryPurgeableVolatileOrderingNormal   = VM_PURGABLE_ORDERING_NORMAL,
168*699cd480SApple OSS Distributions 	kIOMemoryPurgeableFaultOnAccess            = VM_PURGABLE_DEBUG_FAULT,
169*699cd480SApple OSS Distributions };
170*699cd480SApple OSS Distributions enum{
171*699cd480SApple OSS Distributions 	kIOMemoryIncoherentIOFlush   = 1,
172*699cd480SApple OSS Distributions 	kIOMemoryIncoherentIOStore   = 2,
173*699cd480SApple OSS Distributions 
174*699cd480SApple OSS Distributions 	kIOMemoryClearEncrypted      = 50,
175*699cd480SApple OSS Distributions 	kIOMemorySetEncrypted        = 51,
176*699cd480SApple OSS Distributions };
177*699cd480SApple OSS Distributions 
178*699cd480SApple OSS Distributions #define IOMEMORYDESCRIPTOR_SUPPORTS_DMACOMMAND  1
179*699cd480SApple OSS Distributions 
180*699cd480SApple OSS Distributions struct IODMAMapSpecification {
181*699cd480SApple OSS Distributions 	uint64_t    alignment;
182*699cd480SApple OSS Distributions 	IOService * device;
183*699cd480SApple OSS Distributions 	uint32_t    options;
184*699cd480SApple OSS Distributions 	uint8_t     numAddressBits;
185*699cd480SApple OSS Distributions 	uint8_t     resvA[3];
186*699cd480SApple OSS Distributions 	uint32_t    resvB[4];
187*699cd480SApple OSS Distributions };
188*699cd480SApple OSS Distributions 
189*699cd480SApple OSS Distributions struct IODMAMapPageList {
190*699cd480SApple OSS Distributions 	uint32_t                pageOffset;
191*699cd480SApple OSS Distributions 	uint32_t                pageListCount;
192*699cd480SApple OSS Distributions 	const upl_page_info_t * pageList;
193*699cd480SApple OSS Distributions };
194*699cd480SApple OSS Distributions 
195*699cd480SApple OSS Distributions // mapOptions for iovmMapMemory
196*699cd480SApple OSS Distributions enum{
197*699cd480SApple OSS Distributions 	kIODMAMapReadAccess           = 0x00000001,
198*699cd480SApple OSS Distributions 	kIODMAMapWriteAccess          = 0x00000002,
199*699cd480SApple OSS Distributions 	kIODMAMapPhysicallyContiguous = 0x00000010,
200*699cd480SApple OSS Distributions 	kIODMAMapDeviceMemory         = 0x00000020,
201*699cd480SApple OSS Distributions 	kIODMAMapPagingPath           = 0x00000040,
202*699cd480SApple OSS Distributions 	kIODMAMapIdentityMap          = 0x00000080,
203*699cd480SApple OSS Distributions 
204*699cd480SApple OSS Distributions 	kIODMAMapPageListFullyOccupied = 0x00000100,
205*699cd480SApple OSS Distributions 	kIODMAMapFixedAddress          = 0x00000200,
206*699cd480SApple OSS Distributions };
207*699cd480SApple OSS Distributions 
208*699cd480SApple OSS Distributions // Options used by IOMapper. example IOMappers are DART and VT-d
209*699cd480SApple OSS Distributions enum {
210*699cd480SApple OSS Distributions 	kIOMapperUncached      = 0x0001,
211*699cd480SApple OSS Distributions };
212*699cd480SApple OSS Distributions 
213*699cd480SApple OSS Distributions #ifdef KERNEL_PRIVATE
214*699cd480SApple OSS Distributions 
215*699cd480SApple OSS Distributions // Used for dmaCommandOperation communications for IODMACommand and mappers
216*699cd480SApple OSS Distributions 
217*699cd480SApple OSS Distributions enum  {
218*699cd480SApple OSS Distributions 	kIOMDWalkSegments             = 0x01000000,
219*699cd480SApple OSS Distributions 	kIOMDFirstSegment             = 1 | kIOMDWalkSegments,
220*699cd480SApple OSS Distributions 	kIOMDGetCharacteristics       = 0x02000000,
221*699cd480SApple OSS Distributions 	kIOMDGetCharacteristicsMapped = 1 | kIOMDGetCharacteristics,
222*699cd480SApple OSS Distributions 	kIOMDDMAActive                = 0x03000000,
223*699cd480SApple OSS Distributions 	kIOMDSetDMAActive             = 1 | kIOMDDMAActive,
224*699cd480SApple OSS Distributions 	kIOMDSetDMAInactive           = kIOMDDMAActive,
225*699cd480SApple OSS Distributions 	kIOMDAddDMAMapSpec            = 0x04000000,
226*699cd480SApple OSS Distributions 	kIOMDDMAMap                   = 0x05000000,
227*699cd480SApple OSS Distributions 	kIOMDDMAUnmap                 = 0x06000000,
228*699cd480SApple OSS Distributions 	kIOMDDMACommandOperationMask  = 0xFF000000,
229*699cd480SApple OSS Distributions };
230*699cd480SApple OSS Distributions struct IOMDDMACharacteristics {
231*699cd480SApple OSS Distributions 	UInt64 fLength;
232*699cd480SApple OSS Distributions 	UInt32 fSGCount;
233*699cd480SApple OSS Distributions 	UInt32 fPages;
234*699cd480SApple OSS Distributions 	UInt32 fPageAlign;
235*699cd480SApple OSS Distributions 	ppnum_t fHighestPage;
236*699cd480SApple OSS Distributions 	IODirection fDirection;
237*699cd480SApple OSS Distributions 	UInt8 fIsPrepared;
238*699cd480SApple OSS Distributions };
239*699cd480SApple OSS Distributions 
240*699cd480SApple OSS Distributions struct IOMDDMAMapArgs {
241*699cd480SApple OSS Distributions 	IOMapper            * fMapper;
242*699cd480SApple OSS Distributions 	IODMACommand        * fCommand;
243*699cd480SApple OSS Distributions 	IODMAMapSpecification fMapSpec;
244*699cd480SApple OSS Distributions 	uint64_t              fOffset;
245*699cd480SApple OSS Distributions 	uint64_t              fLength;
246*699cd480SApple OSS Distributions 	uint64_t              fAlloc;
247*699cd480SApple OSS Distributions 	uint64_t              fAllocLength;
248*699cd480SApple OSS Distributions };
249*699cd480SApple OSS Distributions 
250*699cd480SApple OSS Distributions struct IOMDDMAWalkSegmentArgs {
251*699cd480SApple OSS Distributions 	UInt64 fOffset;                 // Input/Output offset
252*699cd480SApple OSS Distributions 	UInt64 fIOVMAddr, fLength;      // Output variables
253*699cd480SApple OSS Distributions 	UInt8 fMapped;                  // Input Variable, Require mapped IOVMA
254*699cd480SApple OSS Distributions 	UInt64 fMappedBase;             // Input base of mapping
255*699cd480SApple OSS Distributions };
256*699cd480SApple OSS Distributions typedef UInt8 IOMDDMAWalkSegmentState[128];
257*699cd480SApple OSS Distributions 
258*699cd480SApple OSS Distributions #endif /* KERNEL_PRIVATE */
259*699cd480SApple OSS Distributions 
260*699cd480SApple OSS Distributions enum{
261*699cd480SApple OSS Distributions 	kIOPreparationIDUnprepared = 0,
262*699cd480SApple OSS Distributions 	kIOPreparationIDUnsupported = 1,
263*699cd480SApple OSS Distributions 	kIOPreparationIDAlwaysPrepared = 2,
264*699cd480SApple OSS Distributions };
265*699cd480SApple OSS Distributions 
266*699cd480SApple OSS Distributions #ifdef KERNEL_PRIVATE
267*699cd480SApple OSS Distributions #define kIODescriptorIDInvalid (0)
268*699cd480SApple OSS Distributions #endif
269*699cd480SApple OSS Distributions 
270*699cd480SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
271*699cd480SApple OSS Distributions struct IOMemoryReference;
272*699cd480SApple OSS Distributions #endif
273*699cd480SApple OSS Distributions 
274*699cd480SApple OSS Distributions 
275*699cd480SApple OSS Distributions /*! @class IOMemoryDescriptor : public OSObject
276*699cd480SApple OSS Distributions  *   @abstract An abstract base class defining common methods for describing physical or virtual memory.
277*699cd480SApple OSS Distributions  *   @discussion The IOMemoryDescriptor object represents a buffer or range of memory, specified as one or more physical or virtual address ranges. It contains methods to return the memory's physically contiguous segments (fragments), for use with the IOMemoryCursor, and methods to map the memory into any address space with caching and placed mapping options. */
278*699cd480SApple OSS Distributions 
279*699cd480SApple OSS Distributions class IOMemoryDescriptor : public OSObject
280*699cd480SApple OSS Distributions {
281*699cd480SApple OSS Distributions 	friend class IOMemoryMap;
282*699cd480SApple OSS Distributions 	friend class IOMultiMemoryDescriptor;
283*699cd480SApple OSS Distributions 
284*699cd480SApple OSS Distributions 	OSDeclareDefaultStructorsWithDispatch(IOMemoryDescriptor);
285*699cd480SApple OSS Distributions 
286*699cd480SApple OSS Distributions protected:
287*699cd480SApple OSS Distributions 
288*699cd480SApple OSS Distributions /*! @var reserved
289*699cd480SApple OSS Distributions  *   Reserved for future use.  (Internal use only)  */
290*699cd480SApple OSS Distributions 	struct IOMemoryDescriptorReserved * reserved;
291*699cd480SApple OSS Distributions 
292*699cd480SApple OSS Distributions protected:
293*699cd480SApple OSS Distributions 	OSPtr<OSSet>        _mappings;
294*699cd480SApple OSS Distributions 	IOOptionBits        _flags;
295*699cd480SApple OSS Distributions 
296*699cd480SApple OSS Distributions 
297*699cd480SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
298*699cd480SApple OSS Distributions public:
299*699cd480SApple OSS Distributions 	struct IOMemoryReference *  _memRef;
300*699cd480SApple OSS Distributions 	vm_tag_t _kernelTag;
301*699cd480SApple OSS Distributions 	vm_tag_t _userTag;
302*699cd480SApple OSS Distributions 	int16_t _dmaReferences;
303*699cd480SApple OSS Distributions 	uint16_t _internalFlags;
304*699cd480SApple OSS Distributions 	kern_allocation_name_t _mapName;
305*699cd480SApple OSS Distributions protected:
306*699cd480SApple OSS Distributions #else /* XNU_KERNEL_PRIVATE */
307*699cd480SApple OSS Distributions 	void *              __iomd_reserved5;
308*699cd480SApple OSS Distributions 	uint16_t            __iomd_reserved1[4];
309*699cd480SApple OSS Distributions 	uintptr_t           __iomd_reserved2;
310*699cd480SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
311*699cd480SApple OSS Distributions 
312*699cd480SApple OSS Distributions 	uint16_t            _iomapperOptions;
313*699cd480SApple OSS Distributions #ifdef __LP64__
314*699cd480SApple OSS Distributions 	uint16_t            __iomd_reserved3[3];
315*699cd480SApple OSS Distributions #else
316*699cd480SApple OSS Distributions 	uint16_t            __iomd_reserved3;
317*699cd480SApple OSS Distributions #endif
318*699cd480SApple OSS Distributions 	uintptr_t           __iomd_reserved4;
319*699cd480SApple OSS Distributions 
320*699cd480SApple OSS Distributions #ifndef __LP64__
321*699cd480SApple OSS Distributions 	IODirection         _direction;    /* use _flags instead */
322*699cd480SApple OSS Distributions #endif /* !__LP64__ */
323*699cd480SApple OSS Distributions 	IOByteCount         _length;       /* length of all ranges */
324*699cd480SApple OSS Distributions 	IOOptionBits        _tag;
325*699cd480SApple OSS Distributions 
326*699cd480SApple OSS Distributions public:
327*699cd480SApple OSS Distributions 	typedef IOOptionBits DMACommandOps;
328*699cd480SApple OSS Distributions #ifndef __LP64__
329*699cd480SApple OSS Distributions 	virtual IOPhysicalAddress getSourceSegment( IOByteCount offset,
330*699cd480SApple OSS Distributions 	    IOByteCount * length ) APPLE_KEXT_DEPRECATED;
331*699cd480SApple OSS Distributions #endif /* !__LP64__ */
332*699cd480SApple OSS Distributions 
333*699cd480SApple OSS Distributions /*! @function initWithOptions
334*699cd480SApple OSS Distributions  *   @abstract Master initialiser for all variants of memory descriptors.  For a more complete description see IOMemoryDescriptor::withOptions.
335*699cd480SApple OSS Distributions  *   @discussion Note this function can be used to re-init a previously created memory descriptor.
336*699cd480SApple OSS Distributions  *   @result true on success, false on failure. */
337*699cd480SApple OSS Distributions 	virtual bool initWithOptions(void *         buffers,
338*699cd480SApple OSS Distributions 	    UInt32         count,
339*699cd480SApple OSS Distributions 	    UInt32         offset,
340*699cd480SApple OSS Distributions 	    task_t         task,
341*699cd480SApple OSS Distributions 	    IOOptionBits   options,
342*699cd480SApple OSS Distributions 	    IOMapper *     mapper = kIOMapperSystem);
343*699cd480SApple OSS Distributions 
344*699cd480SApple OSS Distributions #ifndef __LP64__
345*699cd480SApple OSS Distributions 	virtual addr64_t getPhysicalSegment64( IOByteCount offset,
346*699cd480SApple OSS Distributions 	    IOByteCount * length ) APPLE_KEXT_DEPRECATED;                                 /* use getPhysicalSegment() and kIOMemoryMapperNone instead */
347*699cd480SApple OSS Distributions #endif /* !__LP64__ */
348*699cd480SApple OSS Distributions 
349*699cd480SApple OSS Distributions /*! @function setPurgeable
350*699cd480SApple OSS Distributions  *   @abstract Control the purgeable status of a memory descriptors memory.
351*699cd480SApple OSS Distributions  *   @discussion Buffers may be allocated with the ability to have their purgeable status changed - IOBufferMemoryDescriptor with the kIOMemoryPurgeable option, VM_FLAGS_PURGEABLE may be passed to vm_allocate() in user space to allocate such buffers. The purgeable status of such a buffer may be controlled with setPurgeable(). The process of making a purgeable memory descriptor non-volatile and determining its previous state is atomic - if a purgeable memory descriptor is made nonvolatile and the old state is returned as kIOMemoryPurgeableVolatile, then the memory's previous contents are completely intact and will remain so until the memory is made volatile again.  If the old state is returned as kIOMemoryPurgeableEmpty then the memory was reclaimed while it was in a volatile state and its previous contents have been lost.
352*699cd480SApple OSS Distributions  *   @param newState - the desired new purgeable state of the memory:<br>
353*699cd480SApple OSS Distributions  *   kIOMemoryPurgeableKeepCurrent - make no changes to the memory's purgeable state.<br>
354*699cd480SApple OSS Distributions  *   kIOMemoryPurgeableVolatile    - make the memory volatile - the memory may be reclaimed by the VM system without saving its contents to backing store.<br>
355*699cd480SApple OSS Distributions  *   kIOMemoryPurgeableNonVolatile - make the memory nonvolatile - the memory is treated as with usual allocations and must be saved to backing store if paged.<br>
356*699cd480SApple OSS Distributions  *   kIOMemoryPurgeableEmpty       - make the memory volatile, and discard any pages allocated to it.
357*699cd480SApple OSS Distributions  *   @param oldState - if non-NULL, the previous purgeable state of the memory is returned here:<br>
358*699cd480SApple OSS Distributions  *   kIOMemoryPurgeableNonVolatile - the memory was nonvolatile.<br>
359*699cd480SApple OSS Distributions  *   kIOMemoryPurgeableVolatile    - the memory was volatile but its content has not been discarded by the VM system.<br>
360*699cd480SApple OSS Distributions  *   kIOMemoryPurgeableEmpty       - the memory was volatile and has been discarded by the VM system.<br>
361*699cd480SApple OSS Distributions  *   @result An IOReturn code. */
362*699cd480SApple OSS Distributions 
363*699cd480SApple OSS Distributions 	virtual IOReturn setPurgeable( IOOptionBits newState,
364*699cd480SApple OSS Distributions 	    IOOptionBits * oldState );
365*699cd480SApple OSS Distributions 
366*699cd480SApple OSS Distributions /*! @function setOwnership
367*699cd480SApple OSS Distributions  *   @abstract Control the ownership of a memory descriptors memory.
368*699cd480SApple OSS Distributions  *   @discussion IOBufferMemoryDescriptor are owned by a specific task. The ownership of such a buffer may be controlled with setOwnership().
369*699cd480SApple OSS Distributions  *   @param newOwner - the task to be the new owner of the memory.
370*699cd480SApple OSS Distributions  *   @param newLedgerTag - the ledger this memory should be accounted in.
371*699cd480SApple OSS Distributions  *   @param newLedgerOptions - accounting options
372*699cd480SApple OSS Distributions  *   @result An IOReturn code. */
373*699cd480SApple OSS Distributions 
374*699cd480SApple OSS Distributions 	IOReturn setOwnership( task_t newOwner,
375*699cd480SApple OSS Distributions 	    int newLedgerTag,
376*699cd480SApple OSS Distributions 	    IOOptionBits newLedgerOptions );
377*699cd480SApple OSS Distributions 
378*699cd480SApple OSS Distributions /*! @function getPageCounts
379*699cd480SApple OSS Distributions  *   @abstract Retrieve the number of resident and/or dirty pages encompassed by an IOMemoryDescriptor.
380*699cd480SApple OSS Distributions  *   @discussion This method returns the number of resident and/or dirty pages encompassed by an IOMemoryDescriptor.
381*699cd480SApple OSS Distributions  *   @param residentPageCount - If non-null, a pointer to a byte count that will return the number of resident pages encompassed by this IOMemoryDescriptor.
382*699cd480SApple OSS Distributions  *   @param dirtyPageCount - If non-null, a pointer to a byte count that will return the number of dirty pages encompassed by this IOMemoryDescriptor.
383*699cd480SApple OSS Distributions  *   @result An IOReturn code. */
384*699cd480SApple OSS Distributions 
385*699cd480SApple OSS Distributions 	IOReturn getPageCounts( IOByteCount * residentPageCount,
386*699cd480SApple OSS Distributions 	    IOByteCount * dirtyPageCount);
387*699cd480SApple OSS Distributions 
388*699cd480SApple OSS Distributions /*! @function performOperation
389*699cd480SApple OSS Distributions  *   @abstract Perform an operation on the memory descriptor's memory.
390*699cd480SApple OSS Distributions  *   @discussion This method performs some operation on a range of the memory descriptor's memory. When a memory descriptor's memory is not mapped, it should be more efficient to use this method than mapping the memory to perform the operation virtually.
391*699cd480SApple OSS Distributions  *   @param options The operation to perform on the memory:<br>
392*699cd480SApple OSS Distributions  *   kIOMemoryIncoherentIOFlush - pass this option to store to memory and flush any data in the processor cache for the memory range, with synchronization to ensure the data has passed through all levels of processor cache. It may not be supported on all architectures. This type of flush may be used for non-coherent I/O such as AGP - it is NOT required for PCI coherent operations. The memory descriptor must have been previously prepared.<br>
393*699cd480SApple OSS Distributions  *   kIOMemoryIncoherentIOStore - pass this option to store to memory any data in the processor cache for the memory range, with synchronization to ensure the data has passed through all levels of processor cache. It may not be supported on all architectures. This type of flush may be used for non-coherent I/O such as AGP - it is NOT required for PCI coherent operations. The memory descriptor must have been previously prepared.
394*699cd480SApple OSS Distributions  *   @param offset A byte offset into the memory descriptor's memory.
395*699cd480SApple OSS Distributions  *   @param length The length of the data range.
396*699cd480SApple OSS Distributions  *   @result An IOReturn code. */
397*699cd480SApple OSS Distributions 
398*699cd480SApple OSS Distributions 	virtual IOReturn performOperation( IOOptionBits options,
399*699cd480SApple OSS Distributions 	    IOByteCount offset, IOByteCount length );
400*699cd480SApple OSS Distributions 
401*699cd480SApple OSS Distributions // Used for dedicated communications for IODMACommand
402*699cd480SApple OSS Distributions 	virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
403*699cd480SApple OSS Distributions 
404*699cd480SApple OSS Distributions /*! @function getPhysicalSegment
405*699cd480SApple OSS Distributions  *   @abstract Break a memory descriptor into its physically contiguous segments.
406*699cd480SApple OSS Distributions  *   @discussion This method returns the physical address of the byte at the given offset into the memory, and optionally the length of the physically contiguous segment from that offset.
407*699cd480SApple OSS Distributions  *   @param offset A byte offset into the memory whose physical address to return.
408*699cd480SApple OSS Distributions  *   @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
409*699cd480SApple OSS Distributions  *   @result A physical address, or zero if the offset is beyond the length of the memory. */
410*699cd480SApple OSS Distributions 
411*699cd480SApple OSS Distributions #ifdef __LP64__
412*699cd480SApple OSS Distributions 	virtual addr64_t getPhysicalSegment( IOByteCount   offset,
413*699cd480SApple OSS Distributions 	    IOByteCount * length,
414*699cd480SApple OSS Distributions 	    IOOptionBits  options = 0 ) = 0;
415*699cd480SApple OSS Distributions #else /* !__LP64__ */
416*699cd480SApple OSS Distributions 	virtual addr64_t getPhysicalSegment( IOByteCount   offset,
417*699cd480SApple OSS Distributions 	    IOByteCount * length,
418*699cd480SApple OSS Distributions 	    IOOptionBits  options );
419*699cd480SApple OSS Distributions #endif /* !__LP64__ */
420*699cd480SApple OSS Distributions 
421*699cd480SApple OSS Distributions 	virtual uint64_t getPreparationID( void );
422*699cd480SApple OSS Distributions 	void             setPreparationID( void );
423*699cd480SApple OSS Distributions 
424*699cd480SApple OSS Distributions 	void     setVMTags(uint32_t kernelTag, uint32_t userTag);
425*699cd480SApple OSS Distributions 	uint32_t getVMTag(vm_map_t map);
426*699cd480SApple OSS Distributions 
427*699cd480SApple OSS Distributions #ifdef KERNEL_PRIVATE
428*699cd480SApple OSS Distributions 	uint64_t getDescriptorID( void );
429*699cd480SApple OSS Distributions 	void     setDescriptorID( void );
430*699cd480SApple OSS Distributions 
431*699cd480SApple OSS Distributions 	IOReturn ktraceEmitPhysicalSegments( void );
432*699cd480SApple OSS Distributions #endif
433*699cd480SApple OSS Distributions 
434*699cd480SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
435*699cd480SApple OSS Distributions 	IOMemoryDescriptorReserved * getKernelReserved( void );
436*699cd480SApple OSS Distributions 	void                         cleanKernelReserved(IOMemoryDescriptorReserved * reserved);
437*699cd480SApple OSS Distributions 	IOReturn dmaMap(
438*699cd480SApple OSS Distributions 		IOMapper                    * mapper,
439*699cd480SApple OSS Distributions 		IOMemoryDescriptor          * memory,
440*699cd480SApple OSS Distributions 		IODMACommand                * command,
441*699cd480SApple OSS Distributions 		const IODMAMapSpecification * mapSpec,
442*699cd480SApple OSS Distributions 		uint64_t                      offset,
443*699cd480SApple OSS Distributions 		uint64_t                      length,
444*699cd480SApple OSS Distributions 		uint64_t                    * mapAddress,
445*699cd480SApple OSS Distributions 		uint64_t                    * mapLength);
446*699cd480SApple OSS Distributions 	IOReturn dmaUnmap(
447*699cd480SApple OSS Distributions 		IOMapper                    * mapper,
448*699cd480SApple OSS Distributions 		IODMACommand                * command,
449*699cd480SApple OSS Distributions 		uint64_t                      offset,
450*699cd480SApple OSS Distributions 		uint64_t                      mapAddress,
451*699cd480SApple OSS Distributions 		uint64_t                      mapLength);
452*699cd480SApple OSS Distributions 	void dmaMapRecord(
453*699cd480SApple OSS Distributions 		IOMapper                    * mapper,
454*699cd480SApple OSS Distributions 		IODMACommand                * command,
455*699cd480SApple OSS Distributions 		uint64_t                      mapLength);
456*699cd480SApple OSS Distributions #endif
457*699cd480SApple OSS Distributions 
458*699cd480SApple OSS Distributions private:
459*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOMemoryDescriptor, 0);
460*699cd480SApple OSS Distributions #ifdef __LP64__
461*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 1);
462*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 2);
463*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 3);
464*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 4);
465*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 5);
466*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 6);
467*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 7);
468*699cd480SApple OSS Distributions #else /* !__LP64__ */
469*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOMemoryDescriptor, 1);
470*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOMemoryDescriptor, 2);
471*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOMemoryDescriptor, 3);
472*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOMemoryDescriptor, 4);
473*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOMemoryDescriptor, 5);
474*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOMemoryDescriptor, 6);
475*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOMemoryDescriptor, 7);
476*699cd480SApple OSS Distributions #endif /* !__LP64__ */
477*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 8);
478*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 9);
479*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 10);
480*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 11);
481*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 12);
482*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 13);
483*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 14);
484*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 15);
485*699cd480SApple OSS Distributions 
486*699cd480SApple OSS Distributions protected:
487*699cd480SApple OSS Distributions 	virtual void free(void) APPLE_KEXT_OVERRIDE;
488*699cd480SApple OSS Distributions public:
489*699cd480SApple OSS Distributions 	static void initialize( void );
490*699cd480SApple OSS Distributions 
491*699cd480SApple OSS Distributions public:
492*699cd480SApple OSS Distributions /*! @function withAddress
493*699cd480SApple OSS Distributions  *   @abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
494*699cd480SApple OSS Distributions  *   @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map.  This memory descriptor needs to be prepared before it can be used to extract data from the memory described.
495*699cd480SApple OSS Distributions  *   @param address The virtual address of the first byte in the memory.
496*699cd480SApple OSS Distributions  *   @param withLength The length of memory.
497*699cd480SApple OSS Distributions  *   @param withDirection An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.
498*699cd480SApple OSS Distributions  *   @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
499*699cd480SApple OSS Distributions 
500*699cd480SApple OSS Distributions 	static OSPtr<IOMemoryDescriptor>  withAddress(void *       address,
501*699cd480SApple OSS Distributions 	    IOByteCount  withLength,
502*699cd480SApple OSS Distributions 	    IODirection  withDirection);
503*699cd480SApple OSS Distributions 
504*699cd480SApple OSS Distributions #ifndef __LP64__
505*699cd480SApple OSS Distributions 	static OSPtr<IOMemoryDescriptor>  withAddress(IOVirtualAddress address,
506*699cd480SApple OSS Distributions 	    IOByteCount  withLength,
507*699cd480SApple OSS Distributions 	    IODirection  withDirection,
508*699cd480SApple OSS Distributions 	    task_t       withTask) APPLE_KEXT_DEPRECATED;                                 /* use withAddressRange() and prepare() instead */
509*699cd480SApple OSS Distributions #endif /* !__LP64__ */
510*699cd480SApple OSS Distributions 
511*699cd480SApple OSS Distributions /*! @function withPhysicalAddress
512*699cd480SApple OSS Distributions  *   @abstract Create an IOMemoryDescriptor to describe one physical range.
513*699cd480SApple OSS Distributions  *   @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.
514*699cd480SApple OSS Distributions  *   @param address The physical address of the first byte in the memory.
515*699cd480SApple OSS Distributions  *   @param withLength The length of memory.
516*699cd480SApple OSS Distributions  *   @param withDirection An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.
517*699cd480SApple OSS Distributions  *   @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
518*699cd480SApple OSS Distributions 
519*699cd480SApple OSS Distributions 	static OSPtr<IOMemoryDescriptor>  withPhysicalAddress(
520*699cd480SApple OSS Distributions 		IOPhysicalAddress       address,
521*699cd480SApple OSS Distributions 		IOByteCount             withLength,
522*699cd480SApple OSS Distributions 		IODirection             withDirection );
523*699cd480SApple OSS Distributions 
524*699cd480SApple OSS Distributions #ifndef __LP64__
525*699cd480SApple OSS Distributions 	static OSPtr<IOMemoryDescriptor>  withRanges(IOVirtualRange * ranges,
526*699cd480SApple OSS Distributions 	    UInt32           withCount,
527*699cd480SApple OSS Distributions 	    IODirection      withDirection,
528*699cd480SApple OSS Distributions 	    task_t           withTask,
529*699cd480SApple OSS Distributions 	    bool             asReference = false) APPLE_KEXT_DEPRECATED;                                 /* use withAddressRanges() instead */
530*699cd480SApple OSS Distributions #endif /* !__LP64__ */
531*699cd480SApple OSS Distributions 
532*699cd480SApple OSS Distributions /*! @function withAddressRange
533*699cd480SApple OSS Distributions  *   @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
534*699cd480SApple OSS Distributions  *   @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.  This memory descriptor needs to be prepared before it can be used to extract data from the memory described.
535*699cd480SApple OSS Distributions  *   @param address The virtual address of the first byte in the memory.
536*699cd480SApple OSS Distributions  *   @param length The length of memory.
537*699cd480SApple OSS Distributions  *   @param options
538*699cd480SApple OSS Distributions  *       kIOMemoryDirectionMask (options:direction)	This nibble indicates the I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.
539*699cd480SApple OSS Distributions  *   @param task The task the virtual ranges are mapped into. Note that unlike IOMemoryDescriptor::withAddress(), kernel_task memory must be explicitly prepared when passed to this api. The task argument may be NULL to specify memory by physical address.
540*699cd480SApple OSS Distributions  *   @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
541*699cd480SApple OSS Distributions 
542*699cd480SApple OSS Distributions 	static OSPtr<IOMemoryDescriptor>  withAddressRange(
543*699cd480SApple OSS Distributions 		mach_vm_address_t address,
544*699cd480SApple OSS Distributions 		mach_vm_size_t    length,
545*699cd480SApple OSS Distributions 		IOOptionBits      options,
546*699cd480SApple OSS Distributions 		task_t            task);
547*699cd480SApple OSS Distributions 
548*699cd480SApple OSS Distributions /*! @function withAddressRanges
549*699cd480SApple OSS Distributions  *   @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
550*699cd480SApple OSS Distributions  *   @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of virtual memory ranges each mapped into a specified source task.  This memory descriptor needs to be prepared before it can be used to extract data from the memory described.
551*699cd480SApple OSS Distributions  *   @param ranges An array of IOAddressRange structures which specify the virtual ranges in the specified map which make up the memory to be described. IOAddressRange is the 64bit version of IOVirtualRange.
552*699cd480SApple OSS Distributions  *   @param rangeCount The member count of the ranges array.
553*699cd480SApple OSS Distributions  *   @param options
554*699cd480SApple OSS Distributions  *       kIOMemoryDirectionMask (options:direction)	This nibble indicates the I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.
555*699cd480SApple OSS Distributions  *       kIOMemoryAsReference	For options:type = Virtual or Physical this indicate that the memory descriptor need not copy the ranges array into local memory.  This is an optimisation to try to minimise unnecessary allocations.
556*699cd480SApple OSS Distributions  *   @param task The task each of the virtual ranges are mapped into. Note that unlike IOMemoryDescriptor::withAddress(), kernel_task memory must be explicitly prepared when passed to this api. The task argument may be NULL to specify memory by physical address.
557*699cd480SApple OSS Distributions  *   @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
558*699cd480SApple OSS Distributions 
559*699cd480SApple OSS Distributions 	static OSPtr<IOMemoryDescriptor>  withAddressRanges(
560*699cd480SApple OSS Distributions 		IOAddressRange * ranges,
561*699cd480SApple OSS Distributions 		UInt32           rangeCount,
562*699cd480SApple OSS Distributions 		IOOptionBits     options,
563*699cd480SApple OSS Distributions 		task_t           task);
564*699cd480SApple OSS Distributions 
565*699cd480SApple OSS Distributions /*! @function withOptions
566*699cd480SApple OSS Distributions  *   @abstract Master initialiser for all variants of memory descriptors.
567*699cd480SApple OSS Distributions  *   @discussion This method creates and initializes an IOMemoryDescriptor for memory it has three main variants: Virtual, Physical & mach UPL.  These variants are selected with the options parameter, see below.  This memory descriptor needs to be prepared before it can be used to extract data from the memory described.
568*699cd480SApple OSS Distributions  *
569*699cd480SApple OSS Distributions  *
570*699cd480SApple OSS Distributions  *   @param buffers A pointer to an array of IOAddressRange when options:type is kIOMemoryTypeVirtual64 or kIOMemoryTypePhysical64 or a 64bit kernel. For type UPL it is a upl_t returned by the mach/memory_object_types.h apis, primarily used internally by the UBC. IOVirtualRanges or IOPhysicalRanges are 32 bit only types for use when options:type is kIOMemoryTypeVirtual or kIOMemoryTypePhysical on 32bit kernels.
571*699cd480SApple OSS Distributions  *
572*699cd480SApple OSS Distributions  *   @param count options:type = Virtual or Physical count contains a count of the number of entires in the buffers array.  For options:type = UPL this field contains a total length.
573*699cd480SApple OSS Distributions  *
574*699cd480SApple OSS Distributions  *   @param offset Only used when options:type = UPL, in which case this field contains an offset for the memory within the buffers upl.
575*699cd480SApple OSS Distributions  *
576*699cd480SApple OSS Distributions  *   @param task Only used options:type = Virtual, The task each of the virtual ranges are mapped into.
577*699cd480SApple OSS Distributions  *
578*699cd480SApple OSS Distributions  *   @param options
579*699cd480SApple OSS Distributions  *       kIOMemoryDirectionMask (options:direction)	This nibble indicates the I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.
580*699cd480SApple OSS Distributions  *       kIOMemoryTypeMask (options:type)	kIOMemoryTypeVirtual64, kIOMemoryTypeVirtual, kIOMemoryTypePhysical64, kIOMemoryTypePhysical, kIOMemoryTypeUPL Indicates that what type of memory basic memory descriptor to use.  This sub-field also controls the interpretation of the buffers, count, offset & task parameters.
581*699cd480SApple OSS Distributions  *       kIOMemoryAsReference	For options:type = Virtual or Physical this indicate that the memory descriptor need not copy the ranges array into local memory.  This is an optimisation to try to minimise unnecessary allocations.
582*699cd480SApple OSS Distributions  *       kIOMemoryBufferPageable	Only used by the IOBufferMemoryDescriptor as an indication that the kernel virtual memory is in fact pageable and we need to use the kernel pageable submap rather than the default map.
583*699cd480SApple OSS Distributions  *
584*699cd480SApple OSS Distributions  *   @param mapper Which IOMapper should be used to map the in-memory physical addresses into I/O space addresses.  Defaults to 0 which indicates that the system mapper is to be used, if present.
585*699cd480SApple OSS Distributions  *
586*699cd480SApple OSS Distributions  *   @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
587*699cd480SApple OSS Distributions 
588*699cd480SApple OSS Distributions 	static OSPtr<IOMemoryDescriptor> withOptions(void *       buffers,
589*699cd480SApple OSS Distributions 	    UInt32       count,
590*699cd480SApple OSS Distributions 	    UInt32       offset,
591*699cd480SApple OSS Distributions 	    task_t       task,
592*699cd480SApple OSS Distributions 	    IOOptionBits options,
593*699cd480SApple OSS Distributions 	    IOMapper *   mapper = kIOMapperSystem);
594*699cd480SApple OSS Distributions 
595*699cd480SApple OSS Distributions #ifndef __LP64__
596*699cd480SApple OSS Distributions 	static OSPtr<IOMemoryDescriptor>  withPhysicalRanges(
597*699cd480SApple OSS Distributions 		IOPhysicalRange *   ranges,
598*699cd480SApple OSS Distributions 		UInt32              withCount,
599*699cd480SApple OSS Distributions 		IODirection         withDirection,
600*699cd480SApple OSS Distributions 		bool                asReference = false) APPLE_KEXT_DEPRECATED;                             /* use withOptions() and kIOMemoryTypePhysical instead */
601*699cd480SApple OSS Distributions #endif /* !__LP64__ */
602*699cd480SApple OSS Distributions 
603*699cd480SApple OSS Distributions #ifndef __LP64__
604*699cd480SApple OSS Distributions 	static OSPtr<IOMemoryDescriptor>  withSubRange(IOMemoryDescriptor *of,
605*699cd480SApple OSS Distributions 	    IOByteCount offset,
606*699cd480SApple OSS Distributions 	    IOByteCount length,
607*699cd480SApple OSS Distributions 	    IODirection withDirection) APPLE_KEXT_DEPRECATED;                                  /* use IOSubMemoryDescriptor::withSubRange() and kIOMemoryThreadSafe instead */
608*699cd480SApple OSS Distributions #endif /* !__LP64__ */
609*699cd480SApple OSS Distributions 
610*699cd480SApple OSS Distributions /*! @function withPersistentMemoryDescriptor
611*699cd480SApple OSS Distributions  *   @abstract Copy constructor that generates a new memory descriptor if the backing memory for the same task's virtual address and length has changed.
612*699cd480SApple OSS Distributions  *   @discussion If the original memory descriptor's address and length is still backed by the same real memory, i.e. the user hasn't deallocated and the reallocated memory at the same address then the original memory descriptor is returned with a additional reference.  Otherwise we build a totally new memory descriptor with the same characteristics as the previous one but with a new view of the vm.  Note not legal to call this function with anything except an IOGeneralMemoryDescriptor that was created with the kIOMemoryPersistent option.
613*699cd480SApple OSS Distributions  *   @param originalMD The memory descriptor to be duplicated.
614*699cd480SApple OSS Distributions  *   @result Either the original memory descriptor with an additional retain or a new memory descriptor, 0 for a bad original memory descriptor or some other resource shortage. */
615*699cd480SApple OSS Distributions 	static OSPtr<IOMemoryDescriptor>
616*699cd480SApple OSS Distributions 	withPersistentMemoryDescriptor(IOMemoryDescriptor *originalMD);
617*699cd480SApple OSS Distributions 
618*699cd480SApple OSS Distributions #ifndef __LP64__
619*699cd480SApple OSS Distributions // obsolete initializers
620*699cd480SApple OSS Distributions // - initWithOptions is the designated initializer
621*699cd480SApple OSS Distributions 	virtual bool initWithAddress(void *       address,
622*699cd480SApple OSS Distributions 	    IOByteCount  withLength,
623*699cd480SApple OSS Distributions 	    IODirection  withDirection) APPLE_KEXT_DEPRECATED;                      /* use initWithOptions() instead */
624*699cd480SApple OSS Distributions 	virtual bool initWithAddress(IOVirtualAddress address,
625*699cd480SApple OSS Distributions 	    IOByteCount  withLength,
626*699cd480SApple OSS Distributions 	    IODirection  withDirection,
627*699cd480SApple OSS Distributions 	    task_t       withTask) APPLE_KEXT_DEPRECATED;                      /* use initWithOptions() instead */
628*699cd480SApple OSS Distributions 	virtual bool initWithPhysicalAddress(
629*699cd480SApple OSS Distributions 		IOPhysicalAddress      address,
630*699cd480SApple OSS Distributions 		IOByteCount            withLength,
631*699cd480SApple OSS Distributions 		IODirection            withDirection ) APPLE_KEXT_DEPRECATED;                  /* use initWithOptions() instead */
632*699cd480SApple OSS Distributions 	virtual bool initWithRanges(IOVirtualRange * ranges,
633*699cd480SApple OSS Distributions 	    UInt32           withCount,
634*699cd480SApple OSS Distributions 	    IODirection      withDirection,
635*699cd480SApple OSS Distributions 	    task_t           withTask,
636*699cd480SApple OSS Distributions 	    bool             asReference = false) APPLE_KEXT_DEPRECATED;                     /* use initWithOptions() instead */
637*699cd480SApple OSS Distributions 	virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
638*699cd480SApple OSS Distributions 	    UInt32           withCount,
639*699cd480SApple OSS Distributions 	    IODirection      withDirection,
640*699cd480SApple OSS Distributions 	    bool             asReference = false) APPLE_KEXT_DEPRECATED;                             /* use initWithOptions() instead */
641*699cd480SApple OSS Distributions #endif /* __LP64__ */
642*699cd480SApple OSS Distributions 
643*699cd480SApple OSS Distributions /*! @function getDirection
644*699cd480SApple OSS Distributions  *   @abstract Accessor to get the direction the memory descriptor was created with.
645*699cd480SApple OSS Distributions  *   @discussion This method returns the direction the memory descriptor was created with.
646*699cd480SApple OSS Distributions  *   @result The direction. */
647*699cd480SApple OSS Distributions 
648*699cd480SApple OSS Distributions 	virtual IODirection getDirection() const;
649*699cd480SApple OSS Distributions 
650*699cd480SApple OSS Distributions /*! @function getLength
651*699cd480SApple OSS Distributions  *   @abstract Accessor to get the length of the memory descriptor (over all its ranges).
652*699cd480SApple OSS Distributions  *   @discussion This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.
653*699cd480SApple OSS Distributions  *   @result The byte count. */
654*699cd480SApple OSS Distributions 
655*699cd480SApple OSS Distributions 	virtual IOByteCount getLength() const;
656*699cd480SApple OSS Distributions 
657*699cd480SApple OSS Distributions #define IOMEMORYDESCRIPTOR_SUPPORTS_GETDMAMAPLENGTH
658*699cd480SApple OSS Distributions 	uint64_t getDMAMapLength(uint64_t * offset = NULL);
659*699cd480SApple OSS Distributions 
660*699cd480SApple OSS Distributions /*! @function setTag
661*699cd480SApple OSS Distributions  *   @abstract Set the tag for the memory descriptor.
662*699cd480SApple OSS Distributions  *   @discussion This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
663*699cd480SApple OSS Distributions  *   @param tag The tag. */
664*699cd480SApple OSS Distributions 
665*699cd480SApple OSS Distributions 	virtual void setTag( IOOptionBits tag );
666*699cd480SApple OSS Distributions 
667*699cd480SApple OSS Distributions /*! @function getTag
668*699cd480SApple OSS Distributions  *   @abstract Accessor to the retrieve the tag for the memory descriptor.
669*699cd480SApple OSS Distributions  *   @discussion This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
670*699cd480SApple OSS Distributions  *   @result The tag. */
671*699cd480SApple OSS Distributions 
672*699cd480SApple OSS Distributions 	virtual IOOptionBits getTag( void );
673*699cd480SApple OSS Distributions 
674*699cd480SApple OSS Distributions /*! @function getFlags
675*699cd480SApple OSS Distributions  *   @abstract Accessor to the retrieve the options the memory descriptor was created with.
676*699cd480SApple OSS Distributions  *   @discussion Accessor to the retrieve the options the memory descriptor was created with, and flags with its state. These bits are defined by the kIOMemory* enum.
677*699cd480SApple OSS Distributions  *   @result The flags bitfield. */
678*699cd480SApple OSS Distributions 
679*699cd480SApple OSS Distributions 	uint64_t getFlags(void);
680*699cd480SApple OSS Distributions 
681*699cd480SApple OSS Distributions /*! @function readBytes
682*699cd480SApple OSS Distributions  *   @abstract Copy data from the memory descriptor's buffer to the specified buffer.
683*699cd480SApple OSS Distributions  *   @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.  The memory descriptor MUST have the kIODirectionOut direcction bit set  and be prepared.  kIODirectionOut means that this memory descriptor will be output to an external device, so readBytes is used to get memory into a local buffer for a PIO transfer to the device.
684*699cd480SApple OSS Distributions  *   @param offset A byte offset into the memory descriptor's memory.
685*699cd480SApple OSS Distributions  *   @param bytes The caller supplied buffer to copy the data to.
686*699cd480SApple OSS Distributions  *   @param withLength The length of the data to copy.
687*699cd480SApple OSS Distributions  *   @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. Development/debug kernel builds will assert if the offset is beyond the length of the descriptor. */
688*699cd480SApple OSS Distributions 
689*699cd480SApple OSS Distributions 	virtual IOByteCount readBytes(IOByteCount offset,
690*699cd480SApple OSS Distributions 	    void * bytes, IOByteCount withLength);
691*699cd480SApple OSS Distributions 
692*699cd480SApple OSS Distributions /*! @function writeBytes
693*699cd480SApple OSS Distributions  *   @abstract Copy data to the memory descriptor's buffer from the specified buffer.
694*699cd480SApple OSS Distributions  *   @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer.  The memory descriptor MUST have the kIODirectionIn direcction bit set  and be prepared.  kIODirectionIn means that this memory descriptor will be input from an external device, so writeBytes is used to write memory into the descriptor for PIO drivers.
695*699cd480SApple OSS Distributions  *   @param offset A byte offset into the memory descriptor's memory.
696*699cd480SApple OSS Distributions  *   @param bytes The caller supplied buffer to copy the data from.
697*699cd480SApple OSS Distributions  *   @param withLength The length of the data to copy.
698*699cd480SApple OSS Distributions  *   @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. Development/debug kernel builds will assert if the offset is beyond the length of the descriptor. */
699*699cd480SApple OSS Distributions 
700*699cd480SApple OSS Distributions 	virtual IOByteCount writeBytes(IOByteCount offset,
701*699cd480SApple OSS Distributions 	    const void * bytes, IOByteCount withLength);
702*699cd480SApple OSS Distributions 
703*699cd480SApple OSS Distributions #ifndef __LP64__
704*699cd480SApple OSS Distributions 	virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
705*699cd480SApple OSS Distributions 	    IOByteCount * length);
706*699cd480SApple OSS Distributions #endif /* !__LP64__ */
707*699cd480SApple OSS Distributions 
708*699cd480SApple OSS Distributions /*! @function getPhysicalAddress
709*699cd480SApple OSS Distributions  *   @abstract Return the physical address of the first byte in the memory.
710*699cd480SApple OSS Distributions  *   @discussion This method returns the physical address of the  first byte in the memory. It is most useful on memory known to be physically contiguous.
711*699cd480SApple OSS Distributions  *   @result A physical address. */
712*699cd480SApple OSS Distributions 
713*699cd480SApple OSS Distributions 	IOPhysicalAddress getPhysicalAddress();
714*699cd480SApple OSS Distributions 
715*699cd480SApple OSS Distributions #ifndef __LP64__
716*699cd480SApple OSS Distributions 	virtual void * getVirtualSegment(IOByteCount offset,
717*699cd480SApple OSS Distributions 	    IOByteCount * length) APPLE_KEXT_DEPRECATED;                             /* use map() and getVirtualAddress() instead */
718*699cd480SApple OSS Distributions #endif /* !__LP64__ */
719*699cd480SApple OSS Distributions 
720*699cd480SApple OSS Distributions /*! @function prepare
721*699cd480SApple OSS Distributions  *   @abstract Prepare the memory for an I/O transfer.
722*699cd480SApple OSS Distributions  *   @discussion This involves paging in the memory, if necessary, and wiring it down for the duration of the transfer.  The complete() method completes the processing of the memory after the I/O transfer finishes.  Note that the prepare call is not thread safe and it is expected that the client will more easily be able to guarantee single threading a particular memory descriptor.
723*699cd480SApple OSS Distributions  *   @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
724*699cd480SApple OSS Distributions  *   @result An IOReturn code. */
725*699cd480SApple OSS Distributions 
726*699cd480SApple OSS Distributions 	virtual IOReturn prepare(IODirection forDirection = kIODirectionNone) = 0;
727*699cd480SApple OSS Distributions 
728*699cd480SApple OSS Distributions /*! @function complete
729*699cd480SApple OSS Distributions  *   @abstract Complete processing of the memory after an I/O transfer finishes.
730*699cd480SApple OSS Distributions  *   @discussion This method should not be called unless a prepare was previously issued; the prepare() and complete() must occur in pairs, before and after an I/O transfer involving pageable memory.  In 10.3 or greater systems the direction argument to complete is not longer respected.  The direction is totally determined at prepare() time.
731*699cd480SApple OSS Distributions  *   @param forDirection DEPRECATED The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
732*699cd480SApple OSS Distributions  *   @result An IOReturn code. */
733*699cd480SApple OSS Distributions 
734*699cd480SApple OSS Distributions 	virtual IOReturn complete(IODirection forDirection = kIODirectionNone) = 0;
735*699cd480SApple OSS Distributions 
736*699cd480SApple OSS Distributions /*
737*699cd480SApple OSS Distributions  * Mapping functions.
738*699cd480SApple OSS Distributions  */
739*699cd480SApple OSS Distributions 
740*699cd480SApple OSS Distributions /*! @function createMappingInTask
741*699cd480SApple OSS Distributions  *   @abstract Maps a IOMemoryDescriptor into a task.
742*699cd480SApple OSS Distributions  *   @discussion This is the general purpose method to map all or part of the memory described by a memory descriptor into a task at any available address, or at a fixed address if possible. Caching & read-only options may be set for the mapping. The mapping is represented as a returned reference to a IOMemoryMap object, which may be shared if the mapping is compatible with an existing mapping of the IOMemoryDescriptor. The IOMemoryMap object returned should be released only when the caller has finished accessing the mapping, as freeing the object destroys the mapping.
743*699cd480SApple OSS Distributions  *   @param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space.
744*699cd480SApple OSS Distributions  *   @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
745*699cd480SApple OSS Distributions  *   @param options Mapping options are defined in IOTypes.h,<br>
746*699cd480SApple OSS Distributions  *       kIOMapAnywhere should be passed if the mapping can be created anywhere. If not set, the atAddress parameter sets the location of the mapping, if it is available in the target map.<br>
747*699cd480SApple OSS Distributions  *       kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br>
748*699cd480SApple OSS Distributions  *       kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br>
749*699cd480SApple OSS Distributions  *       kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br>
750*699cd480SApple OSS Distributions  *       kIOMapReference will only succeed if the mapping already exists, and the IOMemoryMap object is just an extra reference, ie. no new mapping will be created.<br>
751*699cd480SApple OSS Distributions  *       kIOMapUnique allows a special kind of mapping to be created that may be used with the IOMemoryMap::redirect() API. These mappings will not be shared as is the default - there will always be a unique mapping created for the caller, not an existing mapping with an extra reference.<br>
752*699cd480SApple OSS Distributions  *       kIOMapPrefault will try to prefault the pages corresponding to the mapping. This must not be done on the kernel task, and the memory must have been wired via prepare(). Otherwise, the function will fail.<br>
753*699cd480SApple OSS Distributions  *   @param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
754*699cd480SApple OSS Distributions  *   @param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
755*699cd480SApple OSS Distributions  *   @result A reference to an IOMemoryMap object representing the mapping, which can supply the virtual address of the mapping and other information. The mapping may be shared with multiple callers - multiple maps are avoided if a compatible one exists. The IOMemoryMap object returned should be released only when the caller has finished accessing the mapping, as freeing the object destroys the mapping. The IOMemoryMap instance also retains the IOMemoryDescriptor it maps while it exists. */
756*699cd480SApple OSS Distributions 
757*699cd480SApple OSS Distributions 	OSPtr<IOMemoryMap>        createMappingInTask(
758*699cd480SApple OSS Distributions 		task_t                  intoTask,
759*699cd480SApple OSS Distributions 		mach_vm_address_t       atAddress,
760*699cd480SApple OSS Distributions 		IOOptionBits            options,
761*699cd480SApple OSS Distributions 		mach_vm_size_t          offset = 0,
762*699cd480SApple OSS Distributions 		mach_vm_size_t          length = 0 );
763*699cd480SApple OSS Distributions 
764*699cd480SApple OSS Distributions #ifndef __LP64__
765*699cd480SApple OSS Distributions 	virtual OSPtr<IOMemoryMap>       map(
766*699cd480SApple OSS Distributions 		task_t          intoTask,
767*699cd480SApple OSS Distributions 		IOVirtualAddress        atAddress,
768*699cd480SApple OSS Distributions 		IOOptionBits            options,
769*699cd480SApple OSS Distributions 		IOByteCount             offset = 0,
770*699cd480SApple OSS Distributions 		IOByteCount             length = 0 ) APPLE_KEXT_DEPRECATED;/* use createMappingInTask() instead */
771*699cd480SApple OSS Distributions #endif /* !__LP64__ */
772*699cd480SApple OSS Distributions 
773*699cd480SApple OSS Distributions /*! @function map
774*699cd480SApple OSS Distributions  *   @abstract Maps a IOMemoryDescriptor into the kernel map.
775*699cd480SApple OSS Distributions  *   @discussion This is a shortcut method to map all the memory described by a memory descriptor into the kernel map at any available address. See the full version of the createMappingInTask method for further details.
776*699cd480SApple OSS Distributions  *   @param options Mapping options as in the full version of the createMappingInTask method, with kIOMapAnywhere assumed.
777*699cd480SApple OSS Distributions  *   @result See the full version of the createMappingInTask method. */
778*699cd480SApple OSS Distributions 
779*699cd480SApple OSS Distributions 	virtual OSPtr<IOMemoryMap>       map(
780*699cd480SApple OSS Distributions 		IOOptionBits            options = 0 );
781*699cd480SApple OSS Distributions 
782*699cd480SApple OSS Distributions /*! @function setMapping
783*699cd480SApple OSS Distributions  *   @abstract Establishes an already existing mapping.
784*699cd480SApple OSS Distributions  *   @discussion This method tells the IOMemoryDescriptor about a mapping that exists, but was created elsewhere. It allows later callers of the map method to share this externally created mapping. The IOMemoryMap object returned is created to represent it. This method is not commonly needed.
785*699cd480SApple OSS Distributions  *   @param task Address space in which the mapping exists.
786*699cd480SApple OSS Distributions  *   @param mapAddress Virtual address of the mapping.
787*699cd480SApple OSS Distributions  *   @param options Caching and read-only attributes of the mapping.
788*699cd480SApple OSS Distributions  *   @result A IOMemoryMap object created to represent the mapping. */
789*699cd480SApple OSS Distributions 
790*699cd480SApple OSS Distributions 	virtual OSPtr<IOMemoryMap>       setMapping(
791*699cd480SApple OSS Distributions 		task_t          task,
792*699cd480SApple OSS Distributions 		IOVirtualAddress        mapAddress,
793*699cd480SApple OSS Distributions 		IOOptionBits            options = 0 );
794*699cd480SApple OSS Distributions 
795*699cd480SApple OSS Distributions /*! @function setMapperOptions
796*699cd480SApple OSS Distributions  *   @abstract Set the IOMapper options
797*699cd480SApple OSS Distributions  *   @discussion This method sets the IOMapper options
798*699cd480SApple OSS Distributions  *   @param options  IOMapper options to be set. */
799*699cd480SApple OSS Distributions 
800*699cd480SApple OSS Distributions 	void setMapperOptions( uint16_t options );
801*699cd480SApple OSS Distributions 
802*699cd480SApple OSS Distributions /*! @function getMapperOptions
803*699cd480SApple OSS Distributions  *   @abstract return IOMapper Options
804*699cd480SApple OSS Distributions  *   @discussion This method returns IOMapper Options set earlier using setMapperOptions
805*699cd480SApple OSS Distributions  *   @result IOMapper options set. */
806*699cd480SApple OSS Distributions 
807*699cd480SApple OSS Distributions 	uint16_t getMapperOptions( void );
808*699cd480SApple OSS Distributions 
809*699cd480SApple OSS Distributions // Following methods are private implementation
810*699cd480SApple OSS Distributions 
811*699cd480SApple OSS Distributions #ifdef __LP64__
812*699cd480SApple OSS Distributions 	virtual
813*699cd480SApple OSS Distributions #endif /* __LP64__ */
814*699cd480SApple OSS Distributions 	IOReturn redirect( task_t safeTask, bool redirect );
815*699cd480SApple OSS Distributions 
816*699cd480SApple OSS Distributions 	IOReturn handleFault(
817*699cd480SApple OSS Distributions 		void *                  _pager,
818*699cd480SApple OSS Distributions 		mach_vm_size_t          sourceOffset,
819*699cd480SApple OSS Distributions 		mach_vm_size_t          length);
820*699cd480SApple OSS Distributions 
821*699cd480SApple OSS Distributions 	IOReturn populateDevicePager(
822*699cd480SApple OSS Distributions 		void *                  pager,
823*699cd480SApple OSS Distributions 		vm_map_t                addressMap,
824*699cd480SApple OSS Distributions 		mach_vm_address_t       address,
825*699cd480SApple OSS Distributions 		mach_vm_size_t          sourceOffset,
826*699cd480SApple OSS Distributions 		mach_vm_size_t          length,
827*699cd480SApple OSS Distributions 		IOOptionBits            options );
828*699cd480SApple OSS Distributions 
829*699cd480SApple OSS Distributions 	virtual LIBKERN_RETURNS_NOT_RETAINED IOMemoryMap *      makeMapping(
830*699cd480SApple OSS Distributions 		IOMemoryDescriptor *    owner,
831*699cd480SApple OSS Distributions 		task_t                  intoTask,
832*699cd480SApple OSS Distributions 		IOVirtualAddress        atAddress,
833*699cd480SApple OSS Distributions 		IOOptionBits            options,
834*699cd480SApple OSS Distributions 		IOByteCount             offset,
835*699cd480SApple OSS Distributions 		IOByteCount             length );
836*699cd480SApple OSS Distributions 
837*699cd480SApple OSS Distributions #if KERNEL_PRIVATE
838*699cd480SApple OSS Distributions /*! @function copyContext
839*699cd480SApple OSS Distributions  *   @abstract Accessor to the retrieve the context previously set for the memory descriptor.
840*699cd480SApple OSS Distributions  *   @discussion This method returns the context for the memory descriptor. The context is not interpreted by IOMemoryDescriptor.
841*699cd480SApple OSS Distributions  *   @result The context, returned with an additional retain to be released by the caller. */
842*699cd480SApple OSS Distributions 	OSObject * copyContext(void) const;
843*699cd480SApple OSS Distributions 
844*699cd480SApple OSS Distributions /*! @function setContext
845*699cd480SApple OSS Distributions  *   @abstract Set a context object for the memory descriptor. The context is not interpreted by IOMemoryDescriptor.
846*699cd480SApple OSS Distributions  *   @discussion The context is retained, and will be released when the memory descriptor is freed or when a new context object is set.
847*699cd480SApple OSS Distributions  */
848*699cd480SApple OSS Distributions 	void setContext(OSObject * context);
849*699cd480SApple OSS Distributions #endif
850*699cd480SApple OSS Distributions 
851*699cd480SApple OSS Distributions protected:
852*699cd480SApple OSS Distributions 	virtual void                addMapping(
853*699cd480SApple OSS Distributions 		IOMemoryMap *           mapping );
854*699cd480SApple OSS Distributions 
855*699cd480SApple OSS Distributions 	virtual void                removeMapping(
856*699cd480SApple OSS Distributions 		IOMemoryMap *           mapping );
857*699cd480SApple OSS Distributions 
858*699cd480SApple OSS Distributions 	virtual IOReturn doMap(
859*699cd480SApple OSS Distributions 		vm_map_t                addressMap,
860*699cd480SApple OSS Distributions 		IOVirtualAddress *      atAddress,
861*699cd480SApple OSS Distributions 		IOOptionBits            options,
862*699cd480SApple OSS Distributions 		IOByteCount             sourceOffset = 0,
863*699cd480SApple OSS Distributions 		IOByteCount             length = 0 );
864*699cd480SApple OSS Distributions 
865*699cd480SApple OSS Distributions 	virtual IOReturn doUnmap(
866*699cd480SApple OSS Distributions 		vm_map_t                addressMap,
867*699cd480SApple OSS Distributions 		IOVirtualAddress        logical,
868*699cd480SApple OSS Distributions 		IOByteCount             length );
869*699cd480SApple OSS Distributions };
870*699cd480SApple OSS Distributions 
871*699cd480SApple OSS Distributions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
872*699cd480SApple OSS Distributions 
873*699cd480SApple OSS Distributions /*! @class IOMemoryMap : public OSObject
874*699cd480SApple OSS Distributions  *   @abstract A class defining common methods for describing a memory mapping.
875*699cd480SApple OSS Distributions  *   @discussion The IOMemoryMap object represents a mapped range of memory, described by a IOMemoryDescriptor. The mapping may be in the kernel or a non-kernel task and has processor cache mode attributes. IOMemoryMap instances are created by IOMemoryDescriptor when it creates mappings in its map method, and returned to the caller. */
876*699cd480SApple OSS Distributions 
877*699cd480SApple OSS Distributions class IOMemoryMap : public OSObject
878*699cd480SApple OSS Distributions {
879*699cd480SApple OSS Distributions 	OSDeclareDefaultStructorsWithDispatch(IOMemoryMap);
880*699cd480SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
881*699cd480SApple OSS Distributions public:
882*699cd480SApple OSS Distributions 	IOOptionBits         fOptions;
883*699cd480SApple OSS Distributions 	OSPtr<IOMemoryDescriptor>  fMemory;
884*699cd480SApple OSS Distributions 	OSPtr<IOMemoryMap>         fSuperMap;
885*699cd480SApple OSS Distributions 	mach_vm_size_t       fOffset;
886*699cd480SApple OSS Distributions 	mach_vm_address_t    fAddress;
887*699cd480SApple OSS Distributions 	mach_vm_size_t       fLength;
888*699cd480SApple OSS Distributions 	task_t               fAddressTask;
889*699cd480SApple OSS Distributions 	vm_map_t             fAddressMap;
890*699cd480SApple OSS Distributions 	upl_t                fRedirUPL;
891*699cd480SApple OSS Distributions 	uint8_t              fUserClientUnmap;
892*699cd480SApple OSS Distributions #if IOTRACKING
893*699cd480SApple OSS Distributions 	IOTrackingUser       fTracking;
894*699cd480SApple OSS Distributions #endif
895*699cd480SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
896*699cd480SApple OSS Distributions 
897*699cd480SApple OSS Distributions protected:
898*699cd480SApple OSS Distributions 	virtual void taggedRelease(const void *tag = NULL) const APPLE_KEXT_OVERRIDE;
899*699cd480SApple OSS Distributions 	virtual void free(void) APPLE_KEXT_OVERRIDE;
900*699cd480SApple OSS Distributions 
901*699cd480SApple OSS Distributions public:
902*699cd480SApple OSS Distributions /*! @function getVirtualAddress
903*699cd480SApple OSS Distributions  *   @abstract Accessor to the virtual address of the first byte in the mapping.
904*699cd480SApple OSS Distributions  *   @discussion This method returns the virtual address of the first byte in the mapping. Since the IOVirtualAddress is only 32bit in 32bit kernels, the getAddress() method should be used for compatibility with 64bit task mappings.
905*699cd480SApple OSS Distributions  *   @result A virtual address. */
906*699cd480SApple OSS Distributions 
907*699cd480SApple OSS Distributions 	virtual IOVirtualAddress    getVirtualAddress(void);
908*699cd480SApple OSS Distributions 
909*699cd480SApple OSS Distributions /*! @function getPhysicalSegment
910*699cd480SApple OSS Distributions  *   @abstract Break a mapping into its physically contiguous segments.
911*699cd480SApple OSS Distributions  *   @discussion This method returns the physical address of the byte at the given offset into the mapping, and optionally the length of the physically contiguous segment from that offset. It functions similarly to IOMemoryDescriptor::getPhysicalSegment.
912*699cd480SApple OSS Distributions  *   @param offset A byte offset into the mapping whose physical address to return.
913*699cd480SApple OSS Distributions  *   @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
914*699cd480SApple OSS Distributions  *   @result A physical address, or zero if the offset is beyond the length of the mapping. */
915*699cd480SApple OSS Distributions 
916*699cd480SApple OSS Distributions #ifdef __LP64__
917*699cd480SApple OSS Distributions 	virtual IOPhysicalAddress   getPhysicalSegment(IOByteCount offset,
918*699cd480SApple OSS Distributions 	    IOByteCount * length,
919*699cd480SApple OSS Distributions 	    IOOptionBits  options = 0);
920*699cd480SApple OSS Distributions #else /* !__LP64__ */
921*699cd480SApple OSS Distributions 	virtual IOPhysicalAddress   getPhysicalSegment(IOByteCount offset,
922*699cd480SApple OSS Distributions 	    IOByteCount * length);
923*699cd480SApple OSS Distributions #endif /* !__LP64__ */
924*699cd480SApple OSS Distributions 
925*699cd480SApple OSS Distributions /*! @function getPhysicalAddress
926*699cd480SApple OSS Distributions  *   @abstract Return the physical address of the first byte in the mapping.
927*699cd480SApple OSS Distributions  *   @discussion This method returns the physical address of the  first byte in the mapping. It is most useful on mappings known to be physically contiguous.
928*699cd480SApple OSS Distributions  *   @result A physical address. */
929*699cd480SApple OSS Distributions 
930*699cd480SApple OSS Distributions 	IOPhysicalAddress getPhysicalAddress(void);
931*699cd480SApple OSS Distributions 
932*699cd480SApple OSS Distributions /*! @function getLength
933*699cd480SApple OSS Distributions  *   @abstract Accessor to the length of the mapping.
934*699cd480SApple OSS Distributions  *   @discussion This method returns the length of the mapping.
935*699cd480SApple OSS Distributions  *   @result A byte count. */
936*699cd480SApple OSS Distributions 
937*699cd480SApple OSS Distributions 	virtual IOByteCount         getLength(void);
938*699cd480SApple OSS Distributions 
939*699cd480SApple OSS Distributions /*! @function getAddressTask
940*699cd480SApple OSS Distributions  *   @abstract Accessor to the task of the mapping.
941*699cd480SApple OSS Distributions  *   @discussion This method returns the mach task the mapping exists in.
942*699cd480SApple OSS Distributions  *   @result A mach task_t. */
943*699cd480SApple OSS Distributions 
944*699cd480SApple OSS Distributions 	virtual task_t              getAddressTask();
945*699cd480SApple OSS Distributions 
946*699cd480SApple OSS Distributions /*! @function getMemoryDescriptor
947*699cd480SApple OSS Distributions  *   @abstract Accessor to the IOMemoryDescriptor the mapping was created from.
948*699cd480SApple OSS Distributions  *   @discussion This method returns the IOMemoryDescriptor the mapping was created from.
949*699cd480SApple OSS Distributions  *   @result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */
950*699cd480SApple OSS Distributions 
951*699cd480SApple OSS Distributions 	virtual IOMemoryDescriptor * getMemoryDescriptor();
952*699cd480SApple OSS Distributions 
953*699cd480SApple OSS Distributions /*! @function getMapOptions
954*699cd480SApple OSS Distributions  *   @abstract Accessor to the options the mapping was created with.
955*699cd480SApple OSS Distributions  *   @discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with.
956*699cd480SApple OSS Distributions  *   @result Options for the mapping, including cache settings. */
957*699cd480SApple OSS Distributions 
958*699cd480SApple OSS Distributions 	virtual IOOptionBits        getMapOptions();
959*699cd480SApple OSS Distributions 
960*699cd480SApple OSS Distributions /*! @function unmap
961*699cd480SApple OSS Distributions  *   @abstract Force the IOMemoryMap to unmap, without destroying the object.
962*699cd480SApple OSS Distributions  *   @discussion IOMemoryMap instances will unmap themselves upon free, ie. when the last client with a reference calls release. This method forces the IOMemoryMap to destroy the mapping it represents, regardless of the number of clients. It is not generally used.
963*699cd480SApple OSS Distributions  *   @result An IOReturn code. */
964*699cd480SApple OSS Distributions 
965*699cd480SApple OSS Distributions 	virtual IOReturn            unmap();
966*699cd480SApple OSS Distributions 
967*699cd480SApple OSS Distributions 	virtual void                taskDied();
968*699cd480SApple OSS Distributions 
969*699cd480SApple OSS Distributions /*! @function redirect
970*699cd480SApple OSS Distributions  *   @abstract Replace the memory mapped in a process with new backing memory.
971*699cd480SApple OSS Distributions  *   @discussion An IOMemoryMap created with the kIOMapUnique option to IOMemoryDescriptor::map() can remapped to a new IOMemoryDescriptor backing object. If the new IOMemoryDescriptor is specified as NULL, client access to the memory map is blocked until a new backing object has been set. By blocking access and copying data, the caller can create atomic copies of the memory while the client is potentially reading or writing the memory.
972*699cd480SApple OSS Distributions  *   @param newBackingMemory The IOMemoryDescriptor that represents the physical memory that is to be now mapped in the virtual range the IOMemoryMap represents. If newBackingMemory is NULL, any access to the mapping will hang (in vm_fault()) until access has been restored by a new call to redirect() with non-NULL newBackingMemory argument.
973*699cd480SApple OSS Distributions  *   @param options Mapping options are defined in IOTypes.h, and are documented in IOMemoryDescriptor::map()
974*699cd480SApple OSS Distributions  *   @param offset As with IOMemoryDescriptor::map(), a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default.
975*699cd480SApple OSS Distributions  *   @result An IOReturn code. */
976*699cd480SApple OSS Distributions 
977*699cd480SApple OSS Distributions #ifndef __LP64__
978*699cd480SApple OSS Distributions // For 32 bit XNU, there is a 32 bit (IOByteCount) and a 64 bit (mach_vm_size_t) interface;
979*699cd480SApple OSS Distributions // for 64 bit, these fall together on the 64 bit one.
980*699cd480SApple OSS Distributions 	virtual IOReturn            redirect(IOMemoryDescriptor * newBackingMemory,
981*699cd480SApple OSS Distributions 	    IOOptionBits         options,
982*699cd480SApple OSS Distributions 	    IOByteCount          offset = 0);
983*699cd480SApple OSS Distributions #endif
984*699cd480SApple OSS Distributions 	virtual IOReturn            redirect(IOMemoryDescriptor * newBackingMemory,
985*699cd480SApple OSS Distributions 	    IOOptionBits         options,
986*699cd480SApple OSS Distributions 	    mach_vm_size_t       offset = 0);
987*699cd480SApple OSS Distributions 
988*699cd480SApple OSS Distributions #ifdef __LP64__
989*699cd480SApple OSS Distributions /*! @function getAddress
990*699cd480SApple OSS Distributions  *   @abstract Accessor to the virtual address of the first byte in the mapping.
991*699cd480SApple OSS Distributions  *   @discussion This method returns the virtual address of the first byte in the mapping.
992*699cd480SApple OSS Distributions  *   @result A virtual address. */
993*699cd480SApple OSS Distributions 	inline mach_vm_address_t    getAddress() __attribute__((always_inline));
994*699cd480SApple OSS Distributions /*! @function getSize
995*699cd480SApple OSS Distributions  *   @abstract Accessor to the length of the mapping.
996*699cd480SApple OSS Distributions  *   @discussion This method returns the length of the mapping.
997*699cd480SApple OSS Distributions  *   @result A byte count. */
998*699cd480SApple OSS Distributions 	inline mach_vm_size_t       getSize() __attribute__((always_inline));
999*699cd480SApple OSS Distributions #else /* !__LP64__ */
1000*699cd480SApple OSS Distributions /*! @function getAddress
1001*699cd480SApple OSS Distributions  *   @abstract Accessor to the virtual address of the first byte in the mapping.
1002*699cd480SApple OSS Distributions  *   @discussion This method returns the virtual address of the first byte in the mapping.
1003*699cd480SApple OSS Distributions  *   @result A virtual address. */
1004*699cd480SApple OSS Distributions 	virtual mach_vm_address_t   getAddress();
1005*699cd480SApple OSS Distributions /*! @function getSize
1006*699cd480SApple OSS Distributions  *   @abstract Accessor to the length of the mapping.
1007*699cd480SApple OSS Distributions  *   @discussion This method returns the length of the mapping.
1008*699cd480SApple OSS Distributions  *   @result A byte count. */
1009*699cd480SApple OSS Distributions 	virtual mach_vm_size_t      getSize();
1010*699cd480SApple OSS Distributions #endif /* !__LP64__ */
1011*699cd480SApple OSS Distributions 
1012*699cd480SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
1013*699cd480SApple OSS Distributions // for IOMemoryDescriptor use
1014*699cd480SApple OSS Distributions 	IOMemoryMap *  copyCompatible( IOMemoryMap * newMapping );
1015*699cd480SApple OSS Distributions 
1016*699cd480SApple OSS Distributions 	bool init(
1017*699cd480SApple OSS Distributions 		task_t                  intoTask,
1018*699cd480SApple OSS Distributions 		mach_vm_address_t       toAddress,
1019*699cd480SApple OSS Distributions 		IOOptionBits            options,
1020*699cd480SApple OSS Distributions 		mach_vm_size_t          offset,
1021*699cd480SApple OSS Distributions 		mach_vm_size_t          length );
1022*699cd480SApple OSS Distributions 
1023*699cd480SApple OSS Distributions 	bool    setMemoryDescriptor(IOMemoryDescriptor * _memory, mach_vm_size_t _offset);
1024*699cd480SApple OSS Distributions 
1025*699cd480SApple OSS Distributions 	IOReturn redirect(
1026*699cd480SApple OSS Distributions 		task_t                  intoTask, bool redirect );
1027*699cd480SApple OSS Distributions 
1028*699cd480SApple OSS Distributions 	IOReturn userClientUnmap();
1029*699cd480SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
1030*699cd480SApple OSS Distributions 
1031*699cd480SApple OSS Distributions 	IOReturn wireRange(
1032*699cd480SApple OSS Distributions 		uint32_t                options,
1033*699cd480SApple OSS Distributions 		mach_vm_size_t          offset,
1034*699cd480SApple OSS Distributions 		mach_vm_size_t          length);
1035*699cd480SApple OSS Distributions 
1036*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryMap, 0);
1037*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryMap, 1);
1038*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryMap, 2);
1039*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryMap, 3);
1040*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryMap, 4);
1041*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryMap, 5);
1042*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryMap, 6);
1043*699cd480SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOMemoryMap, 7);
1044*699cd480SApple OSS Distributions };
1045*699cd480SApple OSS Distributions 
1046*699cd480SApple OSS Distributions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1047*699cd480SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
1048*699cd480SApple OSS Distributions // Also these flags should not overlap with the options to
1049*699cd480SApple OSS Distributions //	IOMemoryDescriptor::initWithRanges(... IOOptionsBits options);
1050*699cd480SApple OSS Distributions enum {
1051*699cd480SApple OSS Distributions 	_kIOMemorySourceSegment     = 0x00002000
1052*699cd480SApple OSS Distributions };
1053*699cd480SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
1054*699cd480SApple OSS Distributions 
1055*699cd480SApple OSS Distributions // The following classes are private implementation of IOMemoryDescriptor - they
1056*699cd480SApple OSS Distributions // should not be referenced directly, just through the public API's in the
1057*699cd480SApple OSS Distributions // IOMemoryDescriptor class. For example, an IOGeneralMemoryDescriptor instance
1058*699cd480SApple OSS Distributions // might be created by IOMemoryDescriptor::withAddressRange(), but there should be
1059*699cd480SApple OSS Distributions // no need to reference as anything but a generic IOMemoryDescriptor *.
1060*699cd480SApple OSS Distributions 
1061*699cd480SApple OSS Distributions class IOGeneralMemoryDescriptor : public IOMemoryDescriptor
1062*699cd480SApple OSS Distributions {
1063*699cd480SApple OSS Distributions 	OSDeclareDefaultStructors(IOGeneralMemoryDescriptor);
1064*699cd480SApple OSS Distributions 
1065*699cd480SApple OSS Distributions public:
1066*699cd480SApple OSS Distributions 	union Ranges {
1067*699cd480SApple OSS Distributions 		IOVirtualRange   *v;
1068*699cd480SApple OSS Distributions 		IOAddressRange   *v64;
1069*699cd480SApple OSS Distributions 		IOPhysicalRange  *p;
1070*699cd480SApple OSS Distributions 		void             *uio;
1071*699cd480SApple OSS Distributions 	};
1072*699cd480SApple OSS Distributions protected:
1073*699cd480SApple OSS Distributions 	Ranges              _ranges;
1074*699cd480SApple OSS Distributions 	unsigned            _rangesCount;   /* number of address ranges in list */
1075*699cd480SApple OSS Distributions #ifndef __LP64__
1076*699cd480SApple OSS Distributions 	bool                _rangesIsAllocated;/* is list allocated by us? */
1077*699cd480SApple OSS Distributions #endif /* !__LP64__ */
1078*699cd480SApple OSS Distributions 
1079*699cd480SApple OSS Distributions 	task_t              _task;           /* task where all ranges are mapped to */
1080*699cd480SApple OSS Distributions 
1081*699cd480SApple OSS Distributions 	union {
1082*699cd480SApple OSS Distributions 		IOVirtualRange  v;
1083*699cd480SApple OSS Distributions 		IOPhysicalRange p;
1084*699cd480SApple OSS Distributions 	}                   _singleRange;  /* storage space for a single range */
1085*699cd480SApple OSS Distributions 
1086*699cd480SApple OSS Distributions 	unsigned            _wireCount;    /* number of outstanding wires */
1087*699cd480SApple OSS Distributions 
1088*699cd480SApple OSS Distributions #ifndef __LP64__
1089*699cd480SApple OSS Distributions 	uintptr_t _cachedVirtualAddress;
1090*699cd480SApple OSS Distributions 
1091*699cd480SApple OSS Distributions 	IOPhysicalAddress   _cachedPhysicalAddress;
1092*699cd480SApple OSS Distributions #endif /* !__LP64__ */
1093*699cd480SApple OSS Distributions 
1094*699cd480SApple OSS Distributions 	bool                _initialized;  /* has superclass been initialized? */
1095*699cd480SApple OSS Distributions 
1096*699cd480SApple OSS Distributions public:
1097*699cd480SApple OSS Distributions 	virtual void free() APPLE_KEXT_OVERRIDE;
1098*699cd480SApple OSS Distributions 
1099*699cd480SApple OSS Distributions 	virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const APPLE_KEXT_OVERRIDE;
1100*699cd480SApple OSS Distributions 
1101*699cd480SApple OSS Distributions 	virtual uint64_t getPreparationID( void ) APPLE_KEXT_OVERRIDE;
1102*699cd480SApple OSS Distributions 
1103*699cd480SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
1104*699cd480SApple OSS Distributions // Internal APIs may be made virtual at some time in the future.
1105*699cd480SApple OSS Distributions 	IOReturn wireVirtual(IODirection forDirection);
1106*699cd480SApple OSS Distributions 	IOReturn dmaMap(
1107*699cd480SApple OSS Distributions 		IOMapper                    * mapper,
1108*699cd480SApple OSS Distributions 		IOMemoryDescriptor          * memory,
1109*699cd480SApple OSS Distributions 		IODMACommand                * command,
1110*699cd480SApple OSS Distributions 		const IODMAMapSpecification * mapSpec,
1111*699cd480SApple OSS Distributions 		uint64_t                      offset,
1112*699cd480SApple OSS Distributions 		uint64_t                      length,
1113*699cd480SApple OSS Distributions 		uint64_t                    * mapAddress,
1114*699cd480SApple OSS Distributions 		uint64_t                    * mapLength);
1115*699cd480SApple OSS Distributions 	bool initMemoryEntries(size_t size, IOMapper * mapper);
1116*699cd480SApple OSS Distributions 
1117*699cd480SApple OSS Distributions 	IOMemoryReference * memoryReferenceAlloc(uint32_t capacity,
1118*699cd480SApple OSS Distributions 	    IOMemoryReference * realloc);
1119*699cd480SApple OSS Distributions 	void memoryReferenceFree(IOMemoryReference * ref);
1120*699cd480SApple OSS Distributions 	void memoryReferenceRelease(IOMemoryReference * ref);
1121*699cd480SApple OSS Distributions 
1122*699cd480SApple OSS Distributions 	IOReturn memoryReferenceCreate(
1123*699cd480SApple OSS Distributions 		IOOptionBits         options,
1124*699cd480SApple OSS Distributions 		IOMemoryReference ** reference);
1125*699cd480SApple OSS Distributions 
1126*699cd480SApple OSS Distributions 	IOReturn memoryReferenceMap(IOMemoryReference * ref,
1127*699cd480SApple OSS Distributions 	    vm_map_t            map,
1128*699cd480SApple OSS Distributions 	    mach_vm_size_t      inoffset,
1129*699cd480SApple OSS Distributions 	    mach_vm_size_t      size,
1130*699cd480SApple OSS Distributions 	    IOOptionBits        options,
1131*699cd480SApple OSS Distributions 	    mach_vm_address_t * inaddr);
1132*699cd480SApple OSS Distributions 
1133*699cd480SApple OSS Distributions 	IOReturn memoryReferenceMapNew(IOMemoryReference * ref,
1134*699cd480SApple OSS Distributions 	    vm_map_t            map,
1135*699cd480SApple OSS Distributions 	    mach_vm_size_t      inoffset,
1136*699cd480SApple OSS Distributions 	    mach_vm_size_t      size,
1137*699cd480SApple OSS Distributions 	    IOOptionBits        options,
1138*699cd480SApple OSS Distributions 	    mach_vm_address_t * inaddr);
1139*699cd480SApple OSS Distributions 
1140*699cd480SApple OSS Distributions 	static IOReturn memoryReferenceSetPurgeable(
1141*699cd480SApple OSS Distributions 		IOMemoryReference * ref,
1142*699cd480SApple OSS Distributions 		IOOptionBits newState,
1143*699cd480SApple OSS Distributions 		IOOptionBits * oldState);
1144*699cd480SApple OSS Distributions 	static IOReturn memoryReferenceSetOwnership(
1145*699cd480SApple OSS Distributions 		IOMemoryReference * ref,
1146*699cd480SApple OSS Distributions 		task_t newOwner,
1147*699cd480SApple OSS Distributions 		int newLedgerTag,
1148*699cd480SApple OSS Distributions 		IOOptionBits newLedgerOptions);
1149*699cd480SApple OSS Distributions 	static IOReturn memoryReferenceGetPageCounts(
1150*699cd480SApple OSS Distributions 		IOMemoryReference * ref,
1151*699cd480SApple OSS Distributions 		IOByteCount       * residentPageCount,
1152*699cd480SApple OSS Distributions 		IOByteCount       * dirtyPageCount);
1153*699cd480SApple OSS Distributions 
1154*699cd480SApple OSS Distributions 	static uint64_t memoryReferenceGetDMAMapLength(
1155*699cd480SApple OSS Distributions 		IOMemoryReference * ref,
1156*699cd480SApple OSS Distributions 		uint64_t * offset);
1157*699cd480SApple OSS Distributions 
1158*699cd480SApple OSS Distributions #endif
1159*699cd480SApple OSS Distributions 
1160*699cd480SApple OSS Distributions private:
1161*699cd480SApple OSS Distributions 
1162*699cd480SApple OSS Distributions #ifndef __LP64__
1163*699cd480SApple OSS Distributions 	virtual void setPosition(IOByteCount position);
1164*699cd480SApple OSS Distributions 	virtual void mapIntoKernel(unsigned rangeIndex);
1165*699cd480SApple OSS Distributions 	virtual void unmapFromKernel();
1166*699cd480SApple OSS Distributions #endif /* !__LP64__ */
1167*699cd480SApple OSS Distributions 
1168*699cd480SApple OSS Distributions // Internal
1169*699cd480SApple OSS Distributions 	OSPtr<_IOMemoryDescriptorMixedData> _memoryEntries;
1170*699cd480SApple OSS Distributions 	unsigned int    _pages;
1171*699cd480SApple OSS Distributions 	ppnum_t         _highestPage;
1172*699cd480SApple OSS Distributions 	uint32_t        __iomd_reservedA;
1173*699cd480SApple OSS Distributions 	uint32_t        __iomd_reservedB;
1174*699cd480SApple OSS Distributions 
1175*699cd480SApple OSS Distributions 	IOLock *        _prepareLock;
1176*699cd480SApple OSS Distributions 
1177*699cd480SApple OSS Distributions public:
1178*699cd480SApple OSS Distributions /*
1179*699cd480SApple OSS Distributions  * IOMemoryDescriptor required methods
1180*699cd480SApple OSS Distributions  */
1181*699cd480SApple OSS Distributions 
1182*699cd480SApple OSS Distributions // Master initaliser
1183*699cd480SApple OSS Distributions 	virtual bool initWithOptions(void *         buffers,
1184*699cd480SApple OSS Distributions 	    UInt32         count,
1185*699cd480SApple OSS Distributions 	    UInt32         offset,
1186*699cd480SApple OSS Distributions 	    task_t         task,
1187*699cd480SApple OSS Distributions 	    IOOptionBits   options,
1188*699cd480SApple OSS Distributions 	    IOMapper *     mapper = kIOMapperSystem) APPLE_KEXT_OVERRIDE;
1189*699cd480SApple OSS Distributions 
1190*699cd480SApple OSS Distributions #ifndef __LP64__
1191*699cd480SApple OSS Distributions // Secondary initialisers
1192*699cd480SApple OSS Distributions 	virtual bool initWithAddress(void *         address,
1193*699cd480SApple OSS Distributions 	    IOByteCount    withLength,
1194*699cd480SApple OSS Distributions 	    IODirection    withDirection) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
1195*699cd480SApple OSS Distributions 
1196*699cd480SApple OSS Distributions 	virtual bool initWithAddress(IOVirtualAddress address,
1197*699cd480SApple OSS Distributions 	    IOByteCount    withLength,
1198*699cd480SApple OSS Distributions 	    IODirection    withDirection,
1199*699cd480SApple OSS Distributions 	    task_t         withTask) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
1200*699cd480SApple OSS Distributions 
1201*699cd480SApple OSS Distributions 	virtual bool initWithPhysicalAddress(
1202*699cd480SApple OSS Distributions 		IOPhysicalAddress      address,
1203*699cd480SApple OSS Distributions 		IOByteCount            withLength,
1204*699cd480SApple OSS Distributions 		IODirection            withDirection ) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
1205*699cd480SApple OSS Distributions 
1206*699cd480SApple OSS Distributions 	virtual bool initWithRanges(        IOVirtualRange * ranges,
1207*699cd480SApple OSS Distributions 	    UInt32           withCount,
1208*699cd480SApple OSS Distributions 	    IODirection      withDirection,
1209*699cd480SApple OSS Distributions 	    task_t           withTask,
1210*699cd480SApple OSS Distributions 	    bool             asReference = false) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
1211*699cd480SApple OSS Distributions 
1212*699cd480SApple OSS Distributions 	virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
1213*699cd480SApple OSS Distributions 	    UInt32           withCount,
1214*699cd480SApple OSS Distributions 	    IODirection      withDirection,
1215*699cd480SApple OSS Distributions 	    bool             asReference = false) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
1216*699cd480SApple OSS Distributions 
1217*699cd480SApple OSS Distributions 	virtual addr64_t getPhysicalSegment64( IOByteCount offset,
1218*699cd480SApple OSS Distributions 	    IOByteCount * length ) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
1219*699cd480SApple OSS Distributions 
1220*699cd480SApple OSS Distributions 	virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
1221*699cd480SApple OSS Distributions 	    IOByteCount * length) APPLE_KEXT_OVERRIDE;
1222*699cd480SApple OSS Distributions 
1223*699cd480SApple OSS Distributions 	virtual IOPhysicalAddress getSourceSegment(IOByteCount offset,
1224*699cd480SApple OSS Distributions 	    IOByteCount * length) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
1225*699cd480SApple OSS Distributions 
1226*699cd480SApple OSS Distributions 	virtual void * getVirtualSegment(IOByteCount offset,
1227*699cd480SApple OSS Distributions 	    IOByteCount * length) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
1228*699cd480SApple OSS Distributions #endif /* !__LP64__ */
1229*699cd480SApple OSS Distributions 
1230*699cd480SApple OSS Distributions 	virtual IOReturn setPurgeable( IOOptionBits newState,
1231*699cd480SApple OSS Distributions 	    IOOptionBits * oldState ) APPLE_KEXT_OVERRIDE;
1232*699cd480SApple OSS Distributions 
1233*699cd480SApple OSS Distributions 	IOReturn setOwnership( task_t newOwner,
1234*699cd480SApple OSS Distributions 	    int newLedgerTag,
1235*699cd480SApple OSS Distributions 	    IOOptionBits newLedgerOptions );
1236*699cd480SApple OSS Distributions 
1237*699cd480SApple OSS Distributions 	virtual addr64_t getPhysicalSegment( IOByteCount   offset,
1238*699cd480SApple OSS Distributions 	    IOByteCount * length,
1239*699cd480SApple OSS Distributions #ifdef __LP64__
1240*699cd480SApple OSS Distributions 	    IOOptionBits  options = 0 ) APPLE_KEXT_OVERRIDE;
1241*699cd480SApple OSS Distributions #else /* !__LP64__ */
1242*699cd480SApple OSS Distributions 	    IOOptionBits  options)APPLE_KEXT_OVERRIDE;
1243*699cd480SApple OSS Distributions #endif /* !__LP64__ */
1244*699cd480SApple OSS Distributions 
1245*699cd480SApple OSS Distributions 	virtual IOReturn prepare(IODirection forDirection = kIODirectionNone) APPLE_KEXT_OVERRIDE;
1246*699cd480SApple OSS Distributions 
1247*699cd480SApple OSS Distributions 	virtual IOReturn complete(IODirection forDirection = kIODirectionNone) APPLE_KEXT_OVERRIDE;
1248*699cd480SApple OSS Distributions 
1249*699cd480SApple OSS Distributions 	virtual IOReturn doMap(
1250*699cd480SApple OSS Distributions 		vm_map_t                addressMap,
1251*699cd480SApple OSS Distributions 		IOVirtualAddress *      atAddress,
1252*699cd480SApple OSS Distributions 		IOOptionBits            options,
1253*699cd480SApple OSS Distributions 		IOByteCount             sourceOffset = 0,
1254*699cd480SApple OSS Distributions 		IOByteCount             length = 0 ) APPLE_KEXT_OVERRIDE;
1255*699cd480SApple OSS Distributions 
1256*699cd480SApple OSS Distributions 	virtual IOReturn doUnmap(
1257*699cd480SApple OSS Distributions 		vm_map_t                addressMap,
1258*699cd480SApple OSS Distributions 		IOVirtualAddress        logical,
1259*699cd480SApple OSS Distributions 		IOByteCount             length ) APPLE_KEXT_OVERRIDE;
1260*699cd480SApple OSS Distributions 
1261*699cd480SApple OSS Distributions 	virtual bool serialize(OSSerialize *s) const APPLE_KEXT_OVERRIDE;
1262*699cd480SApple OSS Distributions 
1263*699cd480SApple OSS Distributions // Factory method for cloning a persistent IOMD, see IOMemoryDescriptor
1264*699cd480SApple OSS Distributions 	static OSPtr<IOMemoryDescriptor>
1265*699cd480SApple OSS Distributions 	withPersistentMemoryDescriptor(IOGeneralMemoryDescriptor *originalMD);
1266*699cd480SApple OSS Distributions };
1267*699cd480SApple OSS Distributions 
1268*699cd480SApple OSS Distributions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1269*699cd480SApple OSS Distributions 
1270*699cd480SApple OSS Distributions #ifdef __LP64__
1271*699cd480SApple OSS Distributions mach_vm_address_t
getAddress()1272*699cd480SApple OSS Distributions IOMemoryMap::getAddress()
1273*699cd480SApple OSS Distributions {
1274*699cd480SApple OSS Distributions 	return getVirtualAddress();
1275*699cd480SApple OSS Distributions }
1276*699cd480SApple OSS Distributions 
1277*699cd480SApple OSS Distributions mach_vm_size_t
getSize()1278*699cd480SApple OSS Distributions IOMemoryMap::getSize()
1279*699cd480SApple OSS Distributions {
1280*699cd480SApple OSS Distributions 	return getLength();
1281*699cd480SApple OSS Distributions }
1282*699cd480SApple OSS Distributions #else /* !__LP64__ */
1283*699cd480SApple OSS Distributions #include <IOKit/IOSubMemoryDescriptor.h>
1284*699cd480SApple OSS Distributions #endif /* !__LP64__ */
1285*699cd480SApple OSS Distributions 
1286*699cd480SApple OSS Distributions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1287*699cd480SApple OSS Distributions 
1288*699cd480SApple OSS Distributions extern bool iokit_iomd_setownership_enabled;
1289*699cd480SApple OSS Distributions 
1290*699cd480SApple OSS Distributions #endif /* !_IOMEMORYDESCRIPTOR_H */
1291