]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOMemoryDescriptor.h
xnu-2422.1.72.tar.gz
[apple/xnu.git] / iokit / IOKit / IOMemoryDescriptor.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 #ifndef _IOMEMORYDESCRIPTOR_H
29 #define _IOMEMORYDESCRIPTOR_H
30
31 #include <sys/cdefs.h>
32
33 #include <IOKit/IOTypes.h>
34 #include <IOKit/IOLocks.h>
35 #include <libkern/c++/OSContainers.h>
36
37 #include <mach/memory_object_types.h>
38
39 class IOMemoryMap;
40 class IOMapper;
41 class IOService;
42
43 /*
44 * Direction of transfer, with respect to the described memory.
45 */
46 #ifdef __LP64__
47 enum
48 #else /* !__LP64__ */
49 enum IODirection
50 #endif /* !__LP64__ */
51 {
52 kIODirectionNone = 0x0, // same as VM_PROT_NONE
53 kIODirectionIn = 0x1, // User land 'read', same as VM_PROT_READ
54 kIODirectionOut = 0x2, // User land 'write', same as VM_PROT_WRITE
55 kIODirectionOutIn = kIODirectionOut | kIODirectionIn,
56 kIODirectionInOut = kIODirectionIn | kIODirectionOut,
57
58 // these flags are valid for the prepare() method only
59 kIODirectionPrepareToPhys32 = 0x00000004,
60 kIODirectionPrepareNoFault = 0x00000008,
61 kIODirectionPrepareReserved1 = 0x00000010,
62 };
63 #ifdef __LP64__
64 typedef IOOptionBits IODirection;
65 #endif /* __LP64__ */
66
67 /*
68 * IOOptionBits used in the withOptions variant
69 */
70 enum {
71 kIOMemoryDirectionMask = 0x00000007,
72 #ifdef XNU_KERNEL_PRIVATE
73 kIOMemoryAutoPrepare = 0x00000008, // Shared with Buffer MD
74 #endif
75
76 kIOMemoryTypeVirtual = 0x00000010,
77 kIOMemoryTypePhysical = 0x00000020,
78 kIOMemoryTypeUPL = 0x00000030,
79 kIOMemoryTypePersistentMD = 0x00000040, // Persistent Memory Descriptor
80 kIOMemoryTypeUIO = 0x00000050,
81 #ifdef __LP64__
82 kIOMemoryTypeVirtual64 = kIOMemoryTypeVirtual,
83 kIOMemoryTypePhysical64 = kIOMemoryTypePhysical,
84 #else /* !__LP64__ */
85 kIOMemoryTypeVirtual64 = 0x00000060,
86 kIOMemoryTypePhysical64 = 0x00000070,
87 #endif /* !__LP64__ */
88 kIOMemoryTypeMask = 0x000000f0,
89
90 kIOMemoryAsReference = 0x00000100,
91 kIOMemoryBufferPageable = 0x00000400,
92 kIOMemoryMapperNone = 0x00000800, // Shared with Buffer MD
93 kIOMemoryHostOnly = 0x00001000, // Never DMA accessible
94 #ifdef XNU_KERNEL_PRIVATE
95 kIOMemoryRedirected = 0x00004000,
96 kIOMemoryPreparedReadOnly = 0x00008000,
97 #endif
98 kIOMemoryPersistent = 0x00010000,
99 #ifdef XNU_KERNEL_PRIVATE
100 kIOMemoryReserved6156215 = 0x00020000,
101 #endif
102 kIOMemoryThreadSafe = 0x00100000, // Shared with Buffer MD
103 kIOMemoryClearEncrypt = 0x00200000, // Shared with Buffer MD
104 };
105
106 #define kIOMapperSystem ((IOMapper *) 0)
107
108 enum
109 {
110 kIOMemoryPurgeableKeepCurrent = 1,
111
112 kIOMemoryPurgeableNonVolatile = 2,
113 kIOMemoryPurgeableVolatile = 3,
114 kIOMemoryPurgeableEmpty = 4,
115
116 // modifiers for kIOMemoryPurgeableVolatile behavior
117 kIOMemoryPurgeableVolatileGroup0 = VM_VOLATILE_GROUP_0,
118 kIOMemoryPurgeableVolatileGroup1 = VM_VOLATILE_GROUP_1,
119 kIOMemoryPurgeableVolatileGroup2 = VM_VOLATILE_GROUP_2,
120 kIOMemoryPurgeableVolatileGroup3 = VM_VOLATILE_GROUP_3,
121 kIOMemoryPurgeableVolatileGroup4 = VM_VOLATILE_GROUP_4,
122 kIOMemoryPurgeableVolatileGroup5 = VM_VOLATILE_GROUP_5,
123 kIOMemoryPurgeableVolatileGroup6 = VM_VOLATILE_GROUP_6,
124 kIOMemoryPurgeableVolatileGroup7 = VM_VOLATILE_GROUP_7,
125 kIOMemoryPurgeableVolatileBehaviorFifo = VM_PURGABLE_BEHAVIOR_FIFO,
126 kIOMemoryPurgeableVolatileBehaviorLifo = VM_PURGABLE_BEHAVIOR_LIFO,
127 kIOMemoryPurgeableVolatileOrderingObsolete = VM_PURGABLE_ORDERING_OBSOLETE,
128 kIOMemoryPurgeableVolatileOrderingNormal = VM_PURGABLE_ORDERING_NORMAL,
129 };
130 enum
131 {
132 kIOMemoryIncoherentIOFlush = 1,
133 kIOMemoryIncoherentIOStore = 2,
134
135 kIOMemoryClearEncrypted = 50,
136 kIOMemorySetEncrypted = 51,
137 };
138
139 #define IOMEMORYDESCRIPTOR_SUPPORTS_DMACOMMAND 1
140
141 struct IODMAMapSpecification
142 {
143 uint64_t alignment;
144 IOService * device;
145 uint32_t options;
146 uint8_t numAddressBits;
147 uint8_t resvA[3];
148 uint32_t resvB[4];
149 };
150
151 enum
152 {
153 kIODMAMapWriteAccess = 0x00000002,
154 kIODMAMapPhysicallyContiguous = 0x00000010,
155 kIODMAMapDeviceMemory = 0x00000020,
156 kIODMAMapPagingPath = 0x00000040,
157 kIODMAMapIdentityMap = 0x00000080,
158 };
159
160
161 enum
162 {
163 kIOPreparationIDUnprepared = 0,
164 kIOPreparationIDUnsupported = 1,
165 kIOPreparationIDAlwaysPrepared = 2,
166 };
167
168 /*! @class IOMemoryDescriptor : public OSObject
169 @abstract An abstract base class defining common methods for describing physical or virtual memory.
170 @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. */
171
172 class IOMemoryDescriptor : public OSObject
173 {
174 friend class IOMemoryMap;
175
176 OSDeclareDefaultStructors(IOMemoryDescriptor);
177
178 protected:
179
180 /*! @var reserved
181 Reserved for future use. (Internal use only) */
182 struct IOMemoryDescriptorReserved * reserved;
183
184 protected:
185 OSSet * _mappings;
186 IOOptionBits _flags;
187 void * _memEntry;
188
189 #ifdef __LP64__
190 uint64_t __iomd_reserved1;
191 uint64_t __iomd_reserved2;
192 uint64_t __iomd_reserved3;
193 uint64_t __iomd_reserved4;
194 #else /* !__LP64__ */
195 IODirection _direction; /* use _flags instead */
196 #endif /* !__LP64__ */
197 IOByteCount _length; /* length of all ranges */
198 IOOptionBits _tag;
199
200 public:
201 typedef IOOptionBits DMACommandOps;
202 #ifndef __LP64__
203 virtual IOPhysicalAddress getSourceSegment( IOByteCount offset,
204 IOByteCount * length ) APPLE_KEXT_DEPRECATED;
205 #endif /* !__LP64__ */
206
207 /*! @function initWithOptions
208 @abstract Master initialiser for all variants of memory descriptors. For a more complete description see IOMemoryDescriptor::withOptions.
209 @discussion Note this function can be used to re-init a previously created memory descriptor.
210 @result true on success, false on failure. */
211 virtual bool initWithOptions(void * buffers,
212 UInt32 count,
213 UInt32 offset,
214 task_t task,
215 IOOptionBits options,
216 IOMapper * mapper = kIOMapperSystem);
217
218 #ifndef __LP64__
219 virtual addr64_t getPhysicalSegment64( IOByteCount offset,
220 IOByteCount * length ) APPLE_KEXT_DEPRECATED; /* use getPhysicalSegment() and kIOMemoryMapperNone instead */
221 #endif /* !__LP64__ */
222
223 /*! @function setPurgeable
224 @abstract Control the purgeable status of a memory descriptors memory.
225 @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.
226 @param newState - the desired new purgeable state of the memory:<br>
227 kIOMemoryPurgeableKeepCurrent - make no changes to the memory's purgeable state.<br>
228 kIOMemoryPurgeableVolatile - make the memory volatile - the memory may be reclaimed by the VM system without saving its contents to backing store.<br>
229 kIOMemoryPurgeableNonVolatile - make the memory nonvolatile - the memory is treated as with usual allocations and must be saved to backing store if paged.<br>
230 kIOMemoryPurgeableEmpty - make the memory volatile, and discard any pages allocated to it.
231 @param oldState - if non-NULL, the previous purgeable state of the memory is returned here:<br>
232 kIOMemoryPurgeableNonVolatile - the memory was nonvolatile.<br>
233 kIOMemoryPurgeableVolatile - the memory was volatile but its content has not been discarded by the VM system.<br>
234 kIOMemoryPurgeableEmpty - the memory was volatile and has been discarded by the VM system.<br>
235 @result An IOReturn code. */
236
237 virtual IOReturn setPurgeable( IOOptionBits newState,
238 IOOptionBits * oldState );
239
240
241 /*! @function getPageCounts
242 @abstract Retrieve the number of resident and/or dirty pages encompassed by an IOMemoryDescriptor.
243 @discussion This method returns the number of resident and/or dirty pages encompassed by an IOMemoryDescriptor.
244 @param residentPageCount - If non-null, a pointer to a byte count that will return the number of resident pages encompassed by this IOMemoryDescriptor.
245 @param dirtyPageCount - If non-null, a pointer to a byte count that will return the number of dirty pages encompassed by this IOMemoryDescriptor.
246 @result An IOReturn code. */
247
248 IOReturn getPageCounts( IOByteCount * residentPageCount,
249 IOByteCount * dirtyPageCount);
250
251 /*! @function performOperation
252 @abstract Perform an operation on the memory descriptor's memory.
253 @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.
254 @param options The operation to perform on the memory:<br>
255 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>
256 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.
257 @param offset A byte offset into the memory descriptor's memory.
258 @param length The length of the data range.
259 @result An IOReturn code. */
260
261 virtual IOReturn performOperation( IOOptionBits options,
262 IOByteCount offset, IOByteCount length );
263
264 // Used for dedicated communications for IODMACommand
265 virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
266
267 /*! @function getPhysicalSegment
268 @abstract Break a memory descriptor into its physically contiguous segments.
269 @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.
270 @param offset A byte offset into the memory whose physical address to return.
271 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
272 @result A physical address, or zero if the offset is beyond the length of the memory. */
273
274 #ifdef __LP64__
275 virtual addr64_t getPhysicalSegment( IOByteCount offset,
276 IOByteCount * length,
277 IOOptionBits options = 0 ) = 0;
278 #else /* !__LP64__ */
279 virtual addr64_t getPhysicalSegment( IOByteCount offset,
280 IOByteCount * length,
281 IOOptionBits options );
282 #endif /* !__LP64__ */
283
284 virtual uint64_t getPreparationID( void );
285 void setPreparationID( void );
286
287 #ifdef XNU_KERNEL_PRIVATE
288 IOMemoryDescriptorReserved * getKernelReserved( void );
289 IOReturn dmaMap(
290 IOMapper * mapper,
291 const IODMAMapSpecification * mapSpec,
292 uint64_t offset,
293 uint64_t length,
294 uint64_t * address,
295 ppnum_t * mapPages);
296 #endif
297
298 private:
299 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 0);
300 #ifdef __LP64__
301 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 1);
302 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 2);
303 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 3);
304 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 4);
305 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 5);
306 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 6);
307 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 7);
308 #else /* !__LP64__ */
309 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 1);
310 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 2);
311 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 3);
312 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 4);
313 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 5);
314 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 6);
315 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 7);
316 #endif /* !__LP64__ */
317 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 8);
318 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 9);
319 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 10);
320 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 11);
321 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 12);
322 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 13);
323 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 14);
324 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 15);
325
326 protected:
327 virtual void free();
328 public:
329 static void initialize( void );
330
331 public:
332 /*! @function withAddress
333 @abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
334 @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.
335 @param address The virtual address of the first byte in the memory.
336 @param withLength The length of memory.
337 @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.
338 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
339
340 static IOMemoryDescriptor * withAddress(void * address,
341 IOByteCount withLength,
342 IODirection withDirection);
343
344 #ifndef __LP64__
345 static IOMemoryDescriptor * withAddress(IOVirtualAddress address,
346 IOByteCount withLength,
347 IODirection withDirection,
348 task_t withTask) APPLE_KEXT_DEPRECATED; /* use withAddressRange() and prepare() instead */
349 #endif /* !__LP64__ */
350
351 /*! @function withPhysicalAddress
352 @abstract Create an IOMemoryDescriptor to describe one physical range.
353 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.
354 @param address The physical address of the first byte in the memory.
355 @param withLength The length of memory.
356 @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.
357 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
358
359 static IOMemoryDescriptor * withPhysicalAddress(
360 IOPhysicalAddress address,
361 IOByteCount withLength,
362 IODirection withDirection );
363
364 #ifndef __LP64__
365 static IOMemoryDescriptor * withRanges(IOVirtualRange * ranges,
366 UInt32 withCount,
367 IODirection withDirection,
368 task_t withTask,
369 bool asReference = false) APPLE_KEXT_DEPRECATED; /* use withAddressRanges() instead */
370 #endif /* !__LP64__ */
371
372 /*! @function withAddressRange
373 @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
374 @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.
375 @param address The virtual address of the first byte in the memory.
376 @param withLength The length of memory.
377 @param options
378 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.
379 @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.
380 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
381
382 static IOMemoryDescriptor * withAddressRange(
383 mach_vm_address_t address,
384 mach_vm_size_t length,
385 IOOptionBits options,
386 task_t task);
387
388 /*! @function withAddressRanges
389 @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
390 @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.
391 @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.
392 @param rangeCount The member count of the ranges array.
393 @param options
394 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.
395 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.
396 @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.
397 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
398
399 static IOMemoryDescriptor * withAddressRanges(
400 IOAddressRange * ranges,
401 UInt32 rangeCount,
402 IOOptionBits options,
403 task_t task);
404
405 /*! @function withOptions
406 @abstract Master initialiser for all variants of memory descriptors.
407 @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.
408
409
410 @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.
411
412 @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.
413
414 @param offset Only used when options:type = UPL, in which case this field contains an offset for the memory within the buffers upl.
415
416 @param task Only used options:type = Virtual, The task each of the virtual ranges are mapped into.
417
418 @param options
419 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.
420 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.
421 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.
422 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.
423
424 @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.
425
426 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
427
428 static IOMemoryDescriptor *withOptions(void * buffers,
429 UInt32 count,
430 UInt32 offset,
431 task_t task,
432 IOOptionBits options,
433 IOMapper * mapper = kIOMapperSystem);
434
435 #ifndef __LP64__
436 static IOMemoryDescriptor * withPhysicalRanges(
437 IOPhysicalRange * ranges,
438 UInt32 withCount,
439 IODirection withDirection,
440 bool asReference = false) APPLE_KEXT_DEPRECATED; /* use withOptions() and kIOMemoryTypePhysical instead */
441 #endif /* !__LP64__ */
442
443 #ifndef __LP64__
444 static IOMemoryDescriptor * withSubRange(IOMemoryDescriptor *of,
445 IOByteCount offset,
446 IOByteCount length,
447 IODirection withDirection) APPLE_KEXT_DEPRECATED; /* use IOSubMemoryDescriptor::withSubRange() and kIOMemoryThreadSafe instead */
448 #endif /* !__LP64__ */
449
450 /*! @function withPersistentMemoryDescriptor
451 @abstract Copy constructor that generates a new memory descriptor if the backing memory for the same task's virtual address and length has changed.
452 @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.
453 @param originalMD The memory descriptor to be duplicated.
454 @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. */
455 static IOMemoryDescriptor *
456 withPersistentMemoryDescriptor(IOMemoryDescriptor *originalMD);
457
458 #ifndef __LP64__
459 // obsolete initializers
460 // - initWithOptions is the designated initializer
461 virtual bool initWithAddress(void * address,
462 IOByteCount withLength,
463 IODirection withDirection) APPLE_KEXT_DEPRECATED; /* use initWithOptions() instead */
464 virtual bool initWithAddress(IOVirtualAddress address,
465 IOByteCount withLength,
466 IODirection withDirection,
467 task_t withTask) APPLE_KEXT_DEPRECATED; /* use initWithOptions() instead */
468 virtual bool initWithPhysicalAddress(
469 IOPhysicalAddress address,
470 IOByteCount withLength,
471 IODirection withDirection ) APPLE_KEXT_DEPRECATED; /* use initWithOptions() instead */
472 virtual bool initWithRanges(IOVirtualRange * ranges,
473 UInt32 withCount,
474 IODirection withDirection,
475 task_t withTask,
476 bool asReference = false) APPLE_KEXT_DEPRECATED; /* use initWithOptions() instead */
477 virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
478 UInt32 withCount,
479 IODirection withDirection,
480 bool asReference = false) APPLE_KEXT_DEPRECATED; /* use initWithOptions() instead */
481 #endif /* __LP64__ */
482
483 /*! @function getDirection
484 @abstract Accessor to get the direction the memory descriptor was created with.
485 @discussion This method returns the direction the memory descriptor was created with.
486 @result The direction. */
487
488 virtual IODirection getDirection() const;
489
490 /*! @function getLength
491 @abstract Accessor to get the length of the memory descriptor (over all its ranges).
492 @discussion This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.
493 @result The byte count. */
494
495 virtual IOByteCount getLength() const;
496
497 /*! @function setTag
498 @abstract Set the tag for the memory descriptor.
499 @discussion This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
500 @param tag The tag. */
501
502 virtual void setTag( IOOptionBits tag );
503
504 /*! @function getTag
505 @abstract Accessor to the retrieve the tag for the memory descriptor.
506 @discussion This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
507 @result The tag. */
508
509 virtual IOOptionBits getTag( void );
510
511 /*! @function readBytes
512 @abstract Copy data from the memory descriptor's buffer to the specified buffer.
513 @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.
514 @param offset A byte offset into the memory descriptor's memory.
515 @param bytes The caller supplied buffer to copy the data to.
516 @param withLength The length of the data to copy.
517 @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. */
518
519 virtual IOByteCount readBytes(IOByteCount offset,
520 void * bytes, IOByteCount withLength);
521
522 /*! @function writeBytes
523 @abstract Copy data to the memory descriptor's buffer from the specified buffer.
524 @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.
525 @param offset A byte offset into the memory descriptor's memory.
526 @param bytes The caller supplied buffer to copy the data from.
527 @param withLength The length of the data to copy.
528 @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. */
529
530 virtual IOByteCount writeBytes(IOByteCount offset,
531 const void * bytes, IOByteCount withLength);
532
533 #ifndef __LP64__
534 virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
535 IOByteCount * length);
536 #endif /* !__LP64__ */
537
538 /*! @function getPhysicalAddress
539 @abstract Return the physical address of the first byte in the memory.
540 @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.
541 @result A physical address. */
542
543 IOPhysicalAddress getPhysicalAddress();
544
545 #ifndef __LP64__
546 virtual void * getVirtualSegment(IOByteCount offset,
547 IOByteCount * length) APPLE_KEXT_DEPRECATED; /* use map() and getVirtualAddress() instead */
548 #endif /* !__LP64__ */
549
550 /*! @function prepare
551 @abstract Prepare the memory for an I/O transfer.
552 @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.
553 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
554 @result An IOReturn code. */
555
556 virtual IOReturn prepare(IODirection forDirection = kIODirectionNone) = 0;
557
558 /*! @function complete
559 @abstract Complete processing of the memory after an I/O transfer finishes.
560 @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.
561 @param forDirection DEPRECATED The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
562 @result An IOReturn code. */
563
564 virtual IOReturn complete(IODirection forDirection = kIODirectionNone) = 0;
565
566 /*
567 * Mapping functions.
568 */
569
570 /*! @function createMappingInTask
571 @abstract Maps a IOMemoryDescriptor into a task.
572 @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.
573 @param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space.
574 @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
575 @param options Mapping options are defined in IOTypes.h,<br>
576 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>
577 kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br>
578 kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br>
579 kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br>
580 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>
581 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>
582 @param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
583 @param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
584 @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. */
585
586 IOMemoryMap * createMappingInTask(
587 task_t intoTask,
588 mach_vm_address_t atAddress,
589 IOOptionBits options,
590 mach_vm_size_t offset = 0,
591 mach_vm_size_t length = 0 );
592
593 #ifndef __LP64__
594 virtual IOMemoryMap * map(
595 task_t intoTask,
596 IOVirtualAddress atAddress,
597 IOOptionBits options,
598 IOByteCount offset = 0,
599 IOByteCount length = 0 ) APPLE_KEXT_DEPRECATED; /* use createMappingInTask() instead */
600 #endif /* !__LP64__ */
601
602 /*! @function map
603 @abstract Maps a IOMemoryDescriptor into the kernel map.
604 @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.
605 @param options Mapping options as in the full version of the createMappingInTask method, with kIOMapAnywhere assumed.
606 @result See the full version of the createMappingInTask method. */
607
608 virtual IOMemoryMap * map(
609 IOOptionBits options = 0 );
610
611 /*! @function setMapping
612 @abstract Establishes an already existing mapping.
613 @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.
614 @param task Address space in which the mapping exists.
615 @param mapAddress Virtual address of the mapping.
616 @param options Caching and read-only attributes of the mapping.
617 @result A IOMemoryMap object created to represent the mapping. */
618
619 virtual IOMemoryMap * setMapping(
620 task_t task,
621 IOVirtualAddress mapAddress,
622 IOOptionBits options = 0 );
623
624 // Following methods are private implementation
625
626 #ifdef __LP64__
627 virtual
628 #endif /* __LP64__ */
629 IOReturn redirect( task_t safeTask, bool redirect );
630
631 IOReturn handleFault(
632 void * pager,
633 vm_map_t addressMap,
634 mach_vm_address_t address,
635 mach_vm_size_t sourceOffset,
636 mach_vm_size_t length,
637 IOOptionBits options );
638
639 virtual IOMemoryMap * makeMapping(
640 IOMemoryDescriptor * owner,
641 task_t intoTask,
642 IOVirtualAddress atAddress,
643 IOOptionBits options,
644 IOByteCount offset,
645 IOByteCount length );
646
647 protected:
648 virtual void addMapping(
649 IOMemoryMap * mapping );
650
651 virtual void removeMapping(
652 IOMemoryMap * mapping );
653
654 virtual IOReturn doMap(
655 vm_map_t addressMap,
656 IOVirtualAddress * atAddress,
657 IOOptionBits options,
658 IOByteCount sourceOffset = 0,
659 IOByteCount length = 0 );
660
661 virtual IOReturn doUnmap(
662 vm_map_t addressMap,
663 IOVirtualAddress logical,
664 IOByteCount length );
665 };
666
667 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
668
669 /*! @class IOMemoryMap : public OSObject
670 @abstract A class defining common methods for describing a memory mapping.
671 @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. */
672
673 class IOMemoryMap : public OSObject
674 {
675 OSDeclareDefaultStructors(IOMemoryMap)
676 #ifdef XNU_KERNEL_PRIVATE
677 public:
678 IOMemoryDescriptor * fMemory;
679 IOMemoryMap * fSuperMap;
680 mach_vm_size_t fOffset;
681 mach_vm_address_t fAddress;
682 mach_vm_size_t fLength;
683 task_t fAddressTask;
684 vm_map_t fAddressMap;
685 IOOptionBits fOptions;
686 upl_t fRedirUPL;
687 ipc_port_t fRedirEntry;
688 IOMemoryDescriptor * fOwner;
689 uint8_t fUserClientUnmap;
690 #endif /* XNU_KERNEL_PRIVATE */
691
692 protected:
693 virtual void taggedRelease(const void *tag = 0) const;
694 virtual void free();
695
696 public:
697 /*! @function getVirtualAddress
698 @abstract Accessor to the virtual address of the first byte in the mapping.
699 @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.
700 @result A virtual address. */
701
702 virtual IOVirtualAddress getVirtualAddress();
703
704 /*! @function getPhysicalSegment
705 @abstract Break a mapping into its physically contiguous segments.
706 @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.
707 @param offset A byte offset into the mapping whose physical address to return.
708 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
709 @result A physical address, or zero if the offset is beyond the length of the mapping. */
710
711 #ifdef __LP64__
712 virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
713 IOByteCount * length,
714 IOOptionBits options = 0);
715 #else /* !__LP64__ */
716 virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
717 IOByteCount * length);
718 #endif /* !__LP64__ */
719
720 /*! @function getPhysicalAddress
721 @abstract Return the physical address of the first byte in the mapping.
722 @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.
723 @result A physical address. */
724
725 IOPhysicalAddress getPhysicalAddress();
726
727 /*! @function getLength
728 @abstract Accessor to the length of the mapping.
729 @discussion This method returns the length of the mapping.
730 @result A byte count. */
731
732 virtual IOByteCount getLength();
733
734 /*! @function getAddressTask
735 @abstract Accessor to the task of the mapping.
736 @discussion This method returns the mach task the mapping exists in.
737 @result A mach task_t. */
738
739 virtual task_t getAddressTask();
740
741 /*! @function getMemoryDescriptor
742 @abstract Accessor to the IOMemoryDescriptor the mapping was created from.
743 @discussion This method returns the IOMemoryDescriptor the mapping was created from.
744 @result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */
745
746 virtual IOMemoryDescriptor * getMemoryDescriptor();
747
748 /*! @function getMapOptions
749 @abstract Accessor to the options the mapping was created with.
750 @discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with.
751 @result Options for the mapping, including cache settings. */
752
753 virtual IOOptionBits getMapOptions();
754
755 /*! @function unmap
756 @abstract Force the IOMemoryMap to unmap, without destroying the object.
757 @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.
758 @result An IOReturn code. */
759
760 virtual IOReturn unmap();
761
762 virtual void taskDied();
763
764 /*! @function redirect
765 @abstract Replace the memory mapped in a process with new backing memory.
766 @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.
767 @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.
768 @param options Mapping options are defined in IOTypes.h, and are documented in IOMemoryDescriptor::map()
769 @param offset As with IOMemoryDescriptor::map(), a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default.
770 @result An IOReturn code. */
771
772 #ifndef __LP64__
773 // For 32 bit XNU, there is a 32 bit (IOByteCount) and a 64 bit (mach_vm_size_t) interface;
774 // for 64 bit, these fall together on the 64 bit one.
775 virtual IOReturn redirect(IOMemoryDescriptor * newBackingMemory,
776 IOOptionBits options,
777 IOByteCount offset = 0);
778 #endif
779 virtual IOReturn redirect(IOMemoryDescriptor * newBackingMemory,
780 IOOptionBits options,
781 mach_vm_size_t offset = 0);
782
783 #ifdef __LP64__
784 /*! @function getAddress
785 @abstract Accessor to the virtual address of the first byte in the mapping.
786 @discussion This method returns the virtual address of the first byte in the mapping.
787 @result A virtual address. */
788 /*! @function getSize
789 @abstract Accessor to the length of the mapping.
790 @discussion This method returns the length of the mapping.
791 @result A byte count. */
792 inline mach_vm_address_t getAddress() __attribute__((always_inline));
793 inline mach_vm_size_t getSize() __attribute__((always_inline));
794 #else /* !__LP64__ */
795 /*! @function getAddress
796 @abstract Accessor to the virtual address of the first byte in the mapping.
797 @discussion This method returns the virtual address of the first byte in the mapping.
798 @result A virtual address. */
799 /*! @function getSize
800 @abstract Accessor to the length of the mapping.
801 @discussion This method returns the length of the mapping.
802 @result A byte count. */
803 virtual mach_vm_address_t getAddress();
804 virtual mach_vm_size_t getSize();
805 #endif /* !__LP64__ */
806
807 #ifdef XNU_KERNEL_PRIVATE
808 // for IOMemoryDescriptor use
809 IOMemoryMap * copyCompatible( IOMemoryMap * newMapping );
810
811 bool init(
812 task_t intoTask,
813 mach_vm_address_t toAddress,
814 IOOptionBits options,
815 mach_vm_size_t offset,
816 mach_vm_size_t length );
817
818 bool setMemoryDescriptor(IOMemoryDescriptor * _memory, mach_vm_size_t _offset);
819
820 IOReturn redirect(
821 task_t intoTask, bool redirect );
822
823 IOReturn userClientUnmap();
824 #endif /* XNU_KERNEL_PRIVATE */
825
826 IOReturn wireRange(
827 uint32_t options,
828 mach_vm_size_t offset,
829 mach_vm_size_t length);
830
831 OSMetaClassDeclareReservedUnused(IOMemoryMap, 0);
832 OSMetaClassDeclareReservedUnused(IOMemoryMap, 1);
833 OSMetaClassDeclareReservedUnused(IOMemoryMap, 2);
834 OSMetaClassDeclareReservedUnused(IOMemoryMap, 3);
835 OSMetaClassDeclareReservedUnused(IOMemoryMap, 4);
836 OSMetaClassDeclareReservedUnused(IOMemoryMap, 5);
837 OSMetaClassDeclareReservedUnused(IOMemoryMap, 6);
838 OSMetaClassDeclareReservedUnused(IOMemoryMap, 7);
839 };
840
841 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
842 #ifdef XNU_KERNEL_PRIVATE
843 // Also these flags should not overlap with the options to
844 // IOMemoryDescriptor::initWithRanges(... IOOptionsBits options);
845 enum {
846 _kIOMemorySourceSegment = 0x00002000
847 };
848 #endif /* XNU_KERNEL_PRIVATE */
849
850 // The following classes are private implementation of IOMemoryDescriptor - they
851 // should not be referenced directly, just through the public API's in the
852 // IOMemoryDescriptor class. For example, an IOGeneralMemoryDescriptor instance
853 // might be created by IOMemoryDescriptor::withAddressRange(), but there should be
854 // no need to reference as anything but a generic IOMemoryDescriptor *.
855
856 class IOGeneralMemoryDescriptor : public IOMemoryDescriptor
857 {
858 OSDeclareDefaultStructors(IOGeneralMemoryDescriptor);
859
860 public:
861 union Ranges {
862 IOVirtualRange *v;
863 IOAddressRange *v64;
864 IOPhysicalRange *p;
865 void *uio;
866 };
867 protected:
868 Ranges _ranges;
869 unsigned _rangesCount; /* number of address ranges in list */
870 #ifndef __LP64__
871 bool _rangesIsAllocated; /* is list allocated by us? */
872 #endif /* !__LP64__ */
873
874 task_t _task; /* task where all ranges are mapped to */
875
876 union {
877 IOVirtualRange v;
878 IOPhysicalRange p;
879 } _singleRange; /* storage space for a single range */
880
881 unsigned _wireCount; /* number of outstanding wires */
882
883 #ifndef __LP64__
884 uintptr_t _cachedVirtualAddress;
885
886 IOPhysicalAddress _cachedPhysicalAddress;
887 #endif /* !__LP64__ */
888
889 bool _initialized; /* has superclass been initialized? */
890
891 public:
892 virtual void free();
893
894 virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
895
896 virtual uint64_t getPreparationID( void );
897
898 #ifdef XNU_KERNEL_PRIVATE
899 // Internal APIs may be made virtual at some time in the future.
900 IOReturn wireVirtual(IODirection forDirection);
901 IOReturn dmaMap(
902 IOMapper * mapper,
903 const IODMAMapSpecification * mapSpec,
904 uint64_t offset,
905 uint64_t length,
906 uint64_t * address,
907 ppnum_t * mapPages);
908 bool initMemoryEntries(size_t size, IOMapper * mapper);
909 #endif
910
911 private:
912
913 #ifndef __LP64__
914 virtual void setPosition(IOByteCount position);
915 virtual void mapIntoKernel(unsigned rangeIndex);
916 virtual void unmapFromKernel();
917 #endif /* !__LP64__ */
918
919 void *createNamedEntry();
920
921 // Internal
922 OSData * _memoryEntries;
923 unsigned int _pages;
924 ppnum_t _highestPage;
925 uint32_t __iomd_reservedA;
926 uint32_t __iomd_reservedB;
927
928 IOLock * _prepareLock;
929
930 public:
931 /*
932 * IOMemoryDescriptor required methods
933 */
934
935 // Master initaliser
936 virtual bool initWithOptions(void * buffers,
937 UInt32 count,
938 UInt32 offset,
939 task_t task,
940 IOOptionBits options,
941 IOMapper * mapper = kIOMapperSystem);
942
943 #ifndef __LP64__
944 // Secondary initialisers
945 virtual bool initWithAddress(void * address,
946 IOByteCount withLength,
947 IODirection withDirection) APPLE_KEXT_DEPRECATED;
948
949 virtual bool initWithAddress(IOVirtualAddress address,
950 IOByteCount withLength,
951 IODirection withDirection,
952 task_t withTask) APPLE_KEXT_DEPRECATED;
953
954 virtual bool initWithPhysicalAddress(
955 IOPhysicalAddress address,
956 IOByteCount withLength,
957 IODirection withDirection ) APPLE_KEXT_DEPRECATED;
958
959 virtual bool initWithRanges( IOVirtualRange * ranges,
960 UInt32 withCount,
961 IODirection withDirection,
962 task_t withTask,
963 bool asReference = false) APPLE_KEXT_DEPRECATED;
964
965 virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
966 UInt32 withCount,
967 IODirection withDirection,
968 bool asReference = false) APPLE_KEXT_DEPRECATED;
969
970 virtual addr64_t getPhysicalSegment64( IOByteCount offset,
971 IOByteCount * length ) APPLE_KEXT_DEPRECATED;
972
973 virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
974 IOByteCount * length);
975
976 virtual IOPhysicalAddress getSourceSegment(IOByteCount offset,
977 IOByteCount * length) APPLE_KEXT_DEPRECATED;
978
979 virtual void * getVirtualSegment(IOByteCount offset,
980 IOByteCount * length) APPLE_KEXT_DEPRECATED;
981 #endif /* !__LP64__ */
982
983 virtual IOReturn setPurgeable( IOOptionBits newState,
984 IOOptionBits * oldState );
985
986 virtual addr64_t getPhysicalSegment( IOByteCount offset,
987 IOByteCount * length,
988 #ifdef __LP64__
989 IOOptionBits options = 0 );
990 #else /* !__LP64__ */
991 IOOptionBits options );
992 #endif /* !__LP64__ */
993
994 virtual IOReturn prepare(IODirection forDirection = kIODirectionNone);
995
996 virtual IOReturn complete(IODirection forDirection = kIODirectionNone);
997
998 virtual IOReturn doMap(
999 vm_map_t addressMap,
1000 IOVirtualAddress * atAddress,
1001 IOOptionBits options,
1002 IOByteCount sourceOffset = 0,
1003 IOByteCount length = 0 );
1004
1005 virtual IOReturn doUnmap(
1006 vm_map_t addressMap,
1007 IOVirtualAddress logical,
1008 IOByteCount length );
1009
1010 virtual bool serialize(OSSerialize *s) const;
1011
1012 // Factory method for cloning a persistent IOMD, see IOMemoryDescriptor
1013 static IOMemoryDescriptor *
1014 withPersistentMemoryDescriptor(IOGeneralMemoryDescriptor *originalMD);
1015
1016 };
1017
1018 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1019
1020 #ifdef __LP64__
1021 mach_vm_address_t IOMemoryMap::getAddress()
1022 {
1023 return (getVirtualAddress());
1024 }
1025
1026 mach_vm_size_t IOMemoryMap::getSize()
1027 {
1028 return (getLength());
1029 }
1030 #else /* !__LP64__ */
1031 #include <IOKit/IOSubMemoryDescriptor.h>
1032 #endif /* !__LP64__ */
1033
1034 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1035
1036 #endif /* !_IOMEMORYDESCRIPTOR_H */