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