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