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