2 * Copyright (c) 1998-2016 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #ifndef _IOMEMORYDESCRIPTOR_H
29 #define _IOMEMORYDESCRIPTOR_H
31 #include <sys/cdefs.h>
33 #include <IOKit/IOTypes.h>
34 #include <IOKit/IOLocks.h>
35 #include <libkern/c++/OSContainers.h>
36 #ifdef XNU_KERNEL_PRIVATE
37 #include <IOKit/IOKitDebug.h>
40 #include <mach/memory_object_types.h>
48 * Direction of transfer, with respect to the described memory.
54 #endif /* !__LP64__ */
56 kIODirectionNone
= 0x0, // same as VM_PROT_NONE
57 kIODirectionIn
= 0x1, // User land 'read', same as VM_PROT_READ
58 kIODirectionOut
= 0x2, // User land 'write', same as VM_PROT_WRITE
59 kIODirectionOutIn
= kIODirectionOut
| kIODirectionIn
,
60 kIODirectionInOut
= kIODirectionIn
| kIODirectionOut
,
62 // these flags are valid for the prepare() method only
63 kIODirectionPrepareToPhys32
= 0x00000004,
64 kIODirectionPrepareNoFault
= 0x00000008,
65 kIODirectionPrepareReserved1
= 0x00000010,
66 #define IODIRECTIONPREPARENONCOHERENTDEFINED 1
67 kIODirectionPrepareNonCoherent
= 0x00000020,
69 // these flags are valid for the complete() method only
70 #define IODIRECTIONCOMPLETEWITHERRORDEFINED 1
71 kIODirectionCompleteWithError
= 0x00000040,
72 #define IODIRECTIONCOMPLETEWITHDATAVALIDDEFINED 1
73 kIODirectionCompleteWithDataValid
= 0x00000080,
77 typedef IOOptionBits IODirection
;
81 * IOOptionBits used in the withOptions variant
84 kIOMemoryDirectionMask
= 0x00000007,
85 #ifdef XNU_KERNEL_PRIVATE
86 kIOMemoryAutoPrepare
= 0x00000008, // Shared with Buffer MD
89 kIOMemoryTypeVirtual
= 0x00000010,
90 kIOMemoryTypePhysical
= 0x00000020,
91 kIOMemoryTypeUPL
= 0x00000030,
92 kIOMemoryTypePersistentMD
= 0x00000040, // Persistent Memory Descriptor
93 kIOMemoryTypeUIO
= 0x00000050,
95 kIOMemoryTypeVirtual64
= kIOMemoryTypeVirtual
,
96 kIOMemoryTypePhysical64
= kIOMemoryTypePhysical
,
98 kIOMemoryTypeVirtual64
= 0x00000060,
99 kIOMemoryTypePhysical64
= 0x00000070,
100 #endif /* !__LP64__ */
101 kIOMemoryTypeMask
= 0x000000f0,
103 kIOMemoryAsReference
= 0x00000100,
104 kIOMemoryBufferPageable
= 0x00000400,
105 kIOMemoryMapperNone
= 0x00000800, // Shared with Buffer MD
106 kIOMemoryHostOnly
= 0x00001000, // Never DMA accessible
107 #ifdef XNU_KERNEL_PRIVATE
108 kIOMemoryRedirected
= 0x00004000,
109 kIOMemoryPreparedReadOnly
= 0x00008000,
111 kIOMemoryPersistent
= 0x00010000,
112 #ifdef XNU_KERNEL_PRIVATE
113 kIOMemoryMapCopyOnWrite
= 0x00020000,
115 kIOMemoryRemote
= 0x00040000,
116 kIOMemoryThreadSafe
= 0x00100000, // Shared with Buffer MD
117 kIOMemoryClearEncrypt
= 0x00200000, // Shared with Buffer MD
118 kIOMemoryUseReserve
= 0x00800000, // Shared with Buffer MD
119 #define IOMEMORYUSERESERVEDEFINED 1
121 #ifdef XNU_KERNEL_PRIVATE
122 kIOMemoryBufferPurgeable
= 0x00400000,
123 kIOMemoryBufferCacheMask
= 0x70000000,
124 kIOMemoryBufferCacheShift
= 28,
128 #define kIOMapperSystem ((IOMapper *) 0)
132 kIOMemoryPurgeableKeepCurrent
= 1,
134 kIOMemoryPurgeableNonVolatile
= 2,
135 kIOMemoryPurgeableVolatile
= 3,
136 kIOMemoryPurgeableEmpty
= 4,
138 // modifiers for kIOMemoryPurgeableVolatile behavior
139 kIOMemoryPurgeableVolatileGroup0
= VM_VOLATILE_GROUP_0
,
140 kIOMemoryPurgeableVolatileGroup1
= VM_VOLATILE_GROUP_1
,
141 kIOMemoryPurgeableVolatileGroup2
= VM_VOLATILE_GROUP_2
,
142 kIOMemoryPurgeableVolatileGroup3
= VM_VOLATILE_GROUP_3
,
143 kIOMemoryPurgeableVolatileGroup4
= VM_VOLATILE_GROUP_4
,
144 kIOMemoryPurgeableVolatileGroup5
= VM_VOLATILE_GROUP_5
,
145 kIOMemoryPurgeableVolatileGroup6
= VM_VOLATILE_GROUP_6
,
146 kIOMemoryPurgeableVolatileGroup7
= VM_VOLATILE_GROUP_7
,
147 kIOMemoryPurgeableVolatileBehaviorFifo
= VM_PURGABLE_BEHAVIOR_FIFO
,
148 kIOMemoryPurgeableVolatileBehaviorLifo
= VM_PURGABLE_BEHAVIOR_LIFO
,
149 kIOMemoryPurgeableVolatileOrderingObsolete
= VM_PURGABLE_ORDERING_OBSOLETE
,
150 kIOMemoryPurgeableVolatileOrderingNormal
= VM_PURGABLE_ORDERING_NORMAL
,
151 kIOMemoryPurgeableFaultOnAccess
= VM_PURGABLE_DEBUG_FAULT
,
155 kIOMemoryIncoherentIOFlush
= 1,
156 kIOMemoryIncoherentIOStore
= 2,
158 kIOMemoryClearEncrypted
= 50,
159 kIOMemorySetEncrypted
= 51,
162 #define IOMEMORYDESCRIPTOR_SUPPORTS_DMACOMMAND 1
164 struct IODMAMapSpecification
169 uint8_t numAddressBits
;
174 struct IODMAMapPageList
177 uint32_t pageListCount
;
178 const upl_page_info_t
* pageList
;
181 // mapOptions for iovmMapMemory
184 kIODMAMapReadAccess
= 0x00000001,
185 kIODMAMapWriteAccess
= 0x00000002,
186 kIODMAMapPhysicallyContiguous
= 0x00000010,
187 kIODMAMapDeviceMemory
= 0x00000020,
188 kIODMAMapPagingPath
= 0x00000040,
189 kIODMAMapIdentityMap
= 0x00000080,
191 kIODMAMapPageListFullyOccupied
= 0x00000100,
192 kIODMAMapFixedAddress
= 0x00000200,
195 #ifdef KERNEL_PRIVATE
197 // Used for dmaCommandOperation communications for IODMACommand and mappers
200 kIOMDWalkSegments
= 0x01000000,
201 kIOMDFirstSegment
= 1 | kIOMDWalkSegments
,
202 kIOMDGetCharacteristics
= 0x02000000,
203 kIOMDGetCharacteristicsMapped
= 1 | kIOMDGetCharacteristics
,
204 kIOMDDMAActive
= 0x03000000,
205 kIOMDSetDMAActive
= 1 | kIOMDDMAActive
,
206 kIOMDSetDMAInactive
= kIOMDDMAActive
,
207 kIOMDAddDMAMapSpec
= 0x04000000,
208 kIOMDDMAMap
= 0x05000000,
209 kIOMDDMAUnmap
= 0x06000000,
210 kIOMDDMACommandOperationMask
= 0xFF000000,
212 struct IOMDDMACharacteristics
{
217 ppnum_t fHighestPage
;
218 IODirection fDirection
;
222 struct IOMDDMAMapArgs
{
224 IODMACommand
* fCommand
;
225 IODMAMapSpecification fMapSpec
;
229 uint64_t fAllocLength
;
233 struct IOMDDMAWalkSegmentArgs
{
234 UInt64 fOffset
; // Input/Output offset
235 UInt64 fIOVMAddr
, fLength
; // Output variables
236 UInt8 fMapped
; // Input Variable, Require mapped IOVMA
238 typedef UInt8 IOMDDMAWalkSegmentState
[128];
240 #endif /* KERNEL_PRIVATE */
244 kIOPreparationIDUnprepared
= 0,
245 kIOPreparationIDUnsupported
= 1,
246 kIOPreparationIDAlwaysPrepared
= 2,
249 #ifdef XNU_KERNEL_PRIVATE
250 struct IOMemoryReference
;
254 /*! @class IOMemoryDescriptor : public OSObject
255 @abstract An abstract base class defining common methods for describing physical or virtual memory.
256 @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. */
258 class IOMemoryDescriptor
: public OSObject
260 friend class IOMemoryMap
;
261 friend class IOMultiMemoryDescriptor
;
263 OSDeclareDefaultStructors(IOMemoryDescriptor
);
268 Reserved for future use. (Internal use only) */
269 struct IOMemoryDescriptorReserved
* reserved
;
276 #ifdef XNU_KERNEL_PRIVATE
278 struct IOMemoryReference
* _memRef
;
281 int16_t _dmaReferences
;
282 uint16_t _internalFlags
;
283 kern_allocation_name_t _mapName
;
285 #else /* XNU_KERNEL_PRIVATE */
286 void * __iomd_reserved5
;
287 uint16_t __iomd_reserved1
[4];
288 uintptr_t __iomd_reserved2
;
289 #endif /* XNU_KERNEL_PRIVATE */
291 uintptr_t __iomd_reserved3
;
292 uintptr_t __iomd_reserved4
;
295 IODirection _direction
; /* use _flags instead */
296 #endif /* !__LP64__ */
297 IOByteCount _length
; /* length of all ranges */
301 typedef IOOptionBits DMACommandOps
;
303 virtual IOPhysicalAddress
getSourceSegment( IOByteCount offset
,
304 IOByteCount
* length
) APPLE_KEXT_DEPRECATED
;
305 #endif /* !__LP64__ */
307 /*! @function initWithOptions
308 @abstract Master initialiser for all variants of memory descriptors. For a more complete description see IOMemoryDescriptor::withOptions.
309 @discussion Note this function can be used to re-init a previously created memory descriptor.
310 @result true on success, false on failure. */
311 virtual bool initWithOptions(void * buffers
,
315 IOOptionBits options
,
316 IOMapper
* mapper
= kIOMapperSystem
);
319 virtual addr64_t
getPhysicalSegment64( IOByteCount offset
,
320 IOByteCount
* length
) APPLE_KEXT_DEPRECATED
; /* use getPhysicalSegment() and kIOMemoryMapperNone instead */
321 #endif /* !__LP64__ */
323 /*! @function setPurgeable
324 @abstract Control the purgeable status of a memory descriptors memory.
325 @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.
326 @param newState - the desired new purgeable state of the memory:<br>
327 kIOMemoryPurgeableKeepCurrent - make no changes to the memory's purgeable state.<br>
328 kIOMemoryPurgeableVolatile - make the memory volatile - the memory may be reclaimed by the VM system without saving its contents to backing store.<br>
329 kIOMemoryPurgeableNonVolatile - make the memory nonvolatile - the memory is treated as with usual allocations and must be saved to backing store if paged.<br>
330 kIOMemoryPurgeableEmpty - make the memory volatile, and discard any pages allocated to it.
331 @param oldState - if non-NULL, the previous purgeable state of the memory is returned here:<br>
332 kIOMemoryPurgeableNonVolatile - the memory was nonvolatile.<br>
333 kIOMemoryPurgeableVolatile - the memory was volatile but its content has not been discarded by the VM system.<br>
334 kIOMemoryPurgeableEmpty - the memory was volatile and has been discarded by the VM system.<br>
335 @result An IOReturn code. */
337 virtual IOReturn
setPurgeable( IOOptionBits newState
,
338 IOOptionBits
* oldState
);
341 /*! @function getPageCounts
342 @abstract Retrieve the number of resident and/or dirty pages encompassed by an IOMemoryDescriptor.
343 @discussion This method returns the number of resident and/or dirty pages encompassed by an IOMemoryDescriptor.
344 @param residentPageCount - If non-null, a pointer to a byte count that will return the number of resident pages encompassed by this IOMemoryDescriptor.
345 @param dirtyPageCount - If non-null, a pointer to a byte count that will return the number of dirty pages encompassed by this IOMemoryDescriptor.
346 @result An IOReturn code. */
348 IOReturn
getPageCounts( IOByteCount
* residentPageCount
,
349 IOByteCount
* dirtyPageCount
);
351 /*! @function performOperation
352 @abstract Perform an operation on the memory descriptor's memory.
353 @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.
354 @param options The operation to perform on the memory:<br>
355 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>
356 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.
357 @param offset A byte offset into the memory descriptor's memory.
358 @param length The length of the data range.
359 @result An IOReturn code. */
361 virtual IOReturn
performOperation( IOOptionBits options
,
362 IOByteCount offset
, IOByteCount length
);
364 // Used for dedicated communications for IODMACommand
365 virtual IOReturn
dmaCommandOperation(DMACommandOps op
, void *vData
, UInt dataSize
) const;
367 /*! @function getPhysicalSegment
368 @abstract Break a memory descriptor into its physically contiguous segments.
369 @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.
370 @param offset A byte offset into the memory whose physical address to return.
371 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
372 @result A physical address, or zero if the offset is beyond the length of the memory. */
375 virtual addr64_t
getPhysicalSegment( IOByteCount offset
,
376 IOByteCount
* length
,
377 IOOptionBits options
= 0 ) = 0;
378 #else /* !__LP64__ */
379 virtual addr64_t
getPhysicalSegment( IOByteCount offset
,
380 IOByteCount
* length
,
381 IOOptionBits options
);
382 #endif /* !__LP64__ */
384 virtual uint64_t getPreparationID( void );
385 void setPreparationID( void );
387 #ifdef XNU_KERNEL_PRIVATE
388 IOMemoryDescriptorReserved
* getKernelReserved( void );
391 IODMACommand
* command
,
392 const IODMAMapSpecification
* mapSpec
,
395 uint64_t * mapAddress
,
396 uint64_t * mapLength
);
399 IODMACommand
* command
,
405 IODMACommand
* command
,
408 void setVMTags(vm_tag_t kernelTag
, vm_tag_t userTag
);
409 vm_tag_t
getVMTag(vm_map_t map
);
413 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 0);
415 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 1);
416 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 2);
417 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 3);
418 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 4);
419 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 5);
420 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 6);
421 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 7);
422 #else /* !__LP64__ */
423 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 1);
424 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 2);
425 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 3);
426 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 4);
427 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 5);
428 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 6);
429 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 7);
430 #endif /* !__LP64__ */
431 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 8);
432 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 9);
433 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 10);
434 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 11);
435 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 12);
436 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 13);
437 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 14);
438 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 15);
441 virtual void free() APPLE_KEXT_OVERRIDE
;
443 static void initialize( void );
446 /*! @function withAddress
447 @abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
448 @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.
449 @param address The virtual address of the first byte in the memory.
450 @param withLength The length of memory.
451 @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.
452 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
454 static IOMemoryDescriptor
* withAddress(void * address
,
455 IOByteCount withLength
,
456 IODirection withDirection
);
459 static IOMemoryDescriptor
* withAddress(IOVirtualAddress address
,
460 IOByteCount withLength
,
461 IODirection withDirection
,
462 task_t withTask
) APPLE_KEXT_DEPRECATED
; /* use withAddressRange() and prepare() instead */
463 #endif /* !__LP64__ */
465 /*! @function withPhysicalAddress
466 @abstract Create an IOMemoryDescriptor to describe one physical range.
467 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.
468 @param address The physical address of the first byte in the memory.
469 @param withLength The length of memory.
470 @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.
471 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
473 static IOMemoryDescriptor
* withPhysicalAddress(
474 IOPhysicalAddress address
,
475 IOByteCount withLength
,
476 IODirection withDirection
);
479 static IOMemoryDescriptor
* withRanges(IOVirtualRange
* ranges
,
481 IODirection withDirection
,
483 bool asReference
= false) APPLE_KEXT_DEPRECATED
; /* use withAddressRanges() instead */
484 #endif /* !__LP64__ */
486 /*! @function withAddressRange
487 @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
488 @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.
489 @param address The virtual address of the first byte in the memory.
490 @param length The length of memory.
492 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.
493 @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.
494 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
496 static IOMemoryDescriptor
* withAddressRange(
497 mach_vm_address_t address
,
498 mach_vm_size_t length
,
499 IOOptionBits options
,
502 /*! @function withAddressRanges
503 @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
504 @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.
505 @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.
506 @param rangeCount The member count of the ranges array.
508 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.
509 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.
510 @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.
511 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
513 static IOMemoryDescriptor
* withAddressRanges(
514 IOAddressRange
* ranges
,
516 IOOptionBits options
,
519 /*! @function withOptions
520 @abstract Master initialiser for all variants of memory descriptors.
521 @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.
524 @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.
526 @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.
528 @param offset Only used when options:type = UPL, in which case this field contains an offset for the memory within the buffers upl.
530 @param task Only used options:type = Virtual, The task each of the virtual ranges are mapped into.
533 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.
534 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.
535 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.
536 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.
538 @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.
540 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
542 static IOMemoryDescriptor
*withOptions(void * buffers
,
546 IOOptionBits options
,
547 IOMapper
* mapper
= kIOMapperSystem
);
550 static IOMemoryDescriptor
* withPhysicalRanges(
551 IOPhysicalRange
* ranges
,
553 IODirection withDirection
,
554 bool asReference
= false) APPLE_KEXT_DEPRECATED
; /* use withOptions() and kIOMemoryTypePhysical instead */
555 #endif /* !__LP64__ */
558 static IOMemoryDescriptor
* withSubRange(IOMemoryDescriptor
*of
,
561 IODirection withDirection
) APPLE_KEXT_DEPRECATED
; /* use IOSubMemoryDescriptor::withSubRange() and kIOMemoryThreadSafe instead */
562 #endif /* !__LP64__ */
564 /*! @function withPersistentMemoryDescriptor
565 @abstract Copy constructor that generates a new memory descriptor if the backing memory for the same task's virtual address and length has changed.
566 @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.
567 @param originalMD The memory descriptor to be duplicated.
568 @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. */
569 static IOMemoryDescriptor
*
570 withPersistentMemoryDescriptor(IOMemoryDescriptor
*originalMD
);
573 // obsolete initializers
574 // - initWithOptions is the designated initializer
575 virtual bool initWithAddress(void * address
,
576 IOByteCount withLength
,
577 IODirection withDirection
) APPLE_KEXT_DEPRECATED
; /* use initWithOptions() instead */
578 virtual bool initWithAddress(IOVirtualAddress address
,
579 IOByteCount withLength
,
580 IODirection withDirection
,
581 task_t withTask
) APPLE_KEXT_DEPRECATED
; /* use initWithOptions() instead */
582 virtual bool initWithPhysicalAddress(
583 IOPhysicalAddress address
,
584 IOByteCount withLength
,
585 IODirection withDirection
) APPLE_KEXT_DEPRECATED
; /* use initWithOptions() instead */
586 virtual bool initWithRanges(IOVirtualRange
* ranges
,
588 IODirection withDirection
,
590 bool asReference
= false) APPLE_KEXT_DEPRECATED
; /* use initWithOptions() instead */
591 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
593 IODirection withDirection
,
594 bool asReference
= false) APPLE_KEXT_DEPRECATED
; /* use initWithOptions() instead */
595 #endif /* __LP64__ */
597 /*! @function getDirection
598 @abstract Accessor to get the direction the memory descriptor was created with.
599 @discussion This method returns the direction the memory descriptor was created with.
600 @result The direction. */
602 virtual IODirection
getDirection() const;
604 /*! @function getLength
605 @abstract Accessor to get the length of the memory descriptor (over all its ranges).
606 @discussion This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.
607 @result The byte count. */
609 virtual IOByteCount
getLength() const;
612 @abstract Set the tag for the memory descriptor.
613 @discussion This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
614 @param tag The tag. */
616 virtual void setTag( IOOptionBits tag
);
619 @abstract Accessor to the retrieve the tag for the memory descriptor.
620 @discussion This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
623 virtual IOOptionBits
getTag( void );
625 /*! @function getFlags
626 @abstract Accessor to the retrieve the options the memory descriptor was created with.
627 @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.
628 @result The flags bitfield. */
630 uint64_t getFlags(void);
632 /*! @function readBytes
633 @abstract Copy data from the memory descriptor's buffer to the specified buffer.
634 @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.
635 @param offset A byte offset into the memory descriptor's memory.
636 @param bytes The caller supplied buffer to copy the data to.
637 @param withLength The length of the data to copy.
638 @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. */
640 virtual IOByteCount
readBytes(IOByteCount offset
,
641 void * bytes
, IOByteCount withLength
);
643 /*! @function writeBytes
644 @abstract Copy data to the memory descriptor's buffer from the specified buffer.
645 @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.
646 @param offset A byte offset into the memory descriptor's memory.
647 @param bytes The caller supplied buffer to copy the data from.
648 @param withLength The length of the data to copy.
649 @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. */
651 virtual IOByteCount
writeBytes(IOByteCount offset
,
652 const void * bytes
, IOByteCount withLength
);
655 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
656 IOByteCount
* length
);
657 #endif /* !__LP64__ */
659 /*! @function getPhysicalAddress
660 @abstract Return the physical address of the first byte in the memory.
661 @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.
662 @result A physical address. */
664 IOPhysicalAddress
getPhysicalAddress();
667 virtual void * getVirtualSegment(IOByteCount offset
,
668 IOByteCount
* length
) APPLE_KEXT_DEPRECATED
; /* use map() and getVirtualAddress() instead */
669 #endif /* !__LP64__ */
671 /*! @function prepare
672 @abstract Prepare the memory for an I/O transfer.
673 @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.
674 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
675 @result An IOReturn code. */
677 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
) = 0;
679 /*! @function complete
680 @abstract Complete processing of the memory after an I/O transfer finishes.
681 @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.
682 @param forDirection DEPRECATED The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
683 @result An IOReturn code. */
685 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
) = 0;
691 /*! @function createMappingInTask
692 @abstract Maps a IOMemoryDescriptor into a task.
693 @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.
694 @param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space.
695 @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
696 @param options Mapping options are defined in IOTypes.h,<br>
697 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>
698 kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br>
699 kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br>
700 kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br>
701 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>
702 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>
703 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>
704 @param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
705 @param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
706 @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. */
708 IOMemoryMap
* createMappingInTask(
710 mach_vm_address_t atAddress
,
711 IOOptionBits options
,
712 mach_vm_size_t offset
= 0,
713 mach_vm_size_t length
= 0 );
716 virtual IOMemoryMap
* map(
718 IOVirtualAddress atAddress
,
719 IOOptionBits options
,
720 IOByteCount offset
= 0,
721 IOByteCount length
= 0 ) APPLE_KEXT_DEPRECATED
; /* use createMappingInTask() instead */
722 #endif /* !__LP64__ */
725 @abstract Maps a IOMemoryDescriptor into the kernel map.
726 @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.
727 @param options Mapping options as in the full version of the createMappingInTask method, with kIOMapAnywhere assumed.
728 @result See the full version of the createMappingInTask method. */
730 virtual IOMemoryMap
* map(
731 IOOptionBits options
= 0 );
733 /*! @function setMapping
734 @abstract Establishes an already existing mapping.
735 @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.
736 @param task Address space in which the mapping exists.
737 @param mapAddress Virtual address of the mapping.
738 @param options Caching and read-only attributes of the mapping.
739 @result A IOMemoryMap object created to represent the mapping. */
741 virtual IOMemoryMap
* setMapping(
743 IOVirtualAddress mapAddress
,
744 IOOptionBits options
= 0 );
746 // Following methods are private implementation
750 #endif /* __LP64__ */
751 IOReturn
redirect( task_t safeTask
, bool redirect
);
753 IOReturn
handleFault(
755 mach_vm_size_t sourceOffset
,
756 mach_vm_size_t length
);
758 IOReturn
populateDevicePager(
761 mach_vm_address_t address
,
762 mach_vm_size_t sourceOffset
,
763 mach_vm_size_t length
,
764 IOOptionBits options
);
766 virtual IOMemoryMap
* makeMapping(
767 IOMemoryDescriptor
* owner
,
769 IOVirtualAddress atAddress
,
770 IOOptionBits options
,
772 IOByteCount length
);
775 virtual void addMapping(
776 IOMemoryMap
* mapping
);
778 virtual void removeMapping(
779 IOMemoryMap
* mapping
);
781 virtual IOReturn
doMap(
783 IOVirtualAddress
* atAddress
,
784 IOOptionBits options
,
785 IOByteCount sourceOffset
= 0,
786 IOByteCount length
= 0 );
788 virtual IOReturn
doUnmap(
790 IOVirtualAddress logical
,
791 IOByteCount length
);
794 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
796 /*! @class IOMemoryMap : public OSObject
797 @abstract A class defining common methods for describing a memory mapping.
798 @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. */
800 class IOMemoryMap
: public OSObject
802 OSDeclareDefaultStructors(IOMemoryMap
)
803 #ifdef XNU_KERNEL_PRIVATE
805 IOMemoryDescriptor
* fMemory
;
806 IOMemoryMap
* fSuperMap
;
807 mach_vm_size_t fOffset
;
808 mach_vm_address_t fAddress
;
809 mach_vm_size_t fLength
;
811 vm_map_t fAddressMap
;
812 IOOptionBits fOptions
;
814 ipc_port_t fRedirEntry
;
815 IOMemoryDescriptor
* fOwner
;
816 uint8_t fUserClientUnmap
;
818 IOTrackingUser fTracking
;
820 #endif /* XNU_KERNEL_PRIVATE */
823 virtual void taggedRelease(const void *tag
= 0) const APPLE_KEXT_OVERRIDE
;
824 virtual void free() APPLE_KEXT_OVERRIDE
;
827 /*! @function getVirtualAddress
828 @abstract Accessor to the virtual address of the first byte in the mapping.
829 @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.
830 @result A virtual address. */
832 virtual IOVirtualAddress
getVirtualAddress();
834 /*! @function getPhysicalSegment
835 @abstract Break a mapping into its physically contiguous segments.
836 @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.
837 @param offset A byte offset into the mapping whose physical address to return.
838 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
839 @result A physical address, or zero if the offset is beyond the length of the mapping. */
842 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
843 IOByteCount
* length
,
844 IOOptionBits options
= 0);
845 #else /* !__LP64__ */
846 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
847 IOByteCount
* length
);
848 #endif /* !__LP64__ */
850 /*! @function getPhysicalAddress
851 @abstract Return the physical address of the first byte in the mapping.
852 @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.
853 @result A physical address. */
855 IOPhysicalAddress
getPhysicalAddress();
857 /*! @function getLength
858 @abstract Accessor to the length of the mapping.
859 @discussion This method returns the length of the mapping.
860 @result A byte count. */
862 virtual IOByteCount
getLength();
864 /*! @function getAddressTask
865 @abstract Accessor to the task of the mapping.
866 @discussion This method returns the mach task the mapping exists in.
867 @result A mach task_t. */
869 virtual task_t
getAddressTask();
871 /*! @function getMemoryDescriptor
872 @abstract Accessor to the IOMemoryDescriptor the mapping was created from.
873 @discussion This method returns the IOMemoryDescriptor the mapping was created from.
874 @result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */
876 virtual IOMemoryDescriptor
* getMemoryDescriptor();
878 /*! @function getMapOptions
879 @abstract Accessor to the options the mapping was created with.
880 @discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with.
881 @result Options for the mapping, including cache settings. */
883 virtual IOOptionBits
getMapOptions();
886 @abstract Force the IOMemoryMap to unmap, without destroying the object.
887 @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.
888 @result An IOReturn code. */
890 virtual IOReturn
unmap();
892 virtual void taskDied();
894 /*! @function redirect
895 @abstract Replace the memory mapped in a process with new backing memory.
896 @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.
897 @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.
898 @param options Mapping options are defined in IOTypes.h, and are documented in IOMemoryDescriptor::map()
899 @param offset As with IOMemoryDescriptor::map(), a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default.
900 @result An IOReturn code. */
903 // For 32 bit XNU, there is a 32 bit (IOByteCount) and a 64 bit (mach_vm_size_t) interface;
904 // for 64 bit, these fall together on the 64 bit one.
905 virtual IOReturn
redirect(IOMemoryDescriptor
* newBackingMemory
,
906 IOOptionBits options
,
907 IOByteCount offset
= 0);
909 virtual IOReturn
redirect(IOMemoryDescriptor
* newBackingMemory
,
910 IOOptionBits options
,
911 mach_vm_size_t offset
= 0);
914 /*! @function getAddress
915 @abstract Accessor to the virtual address of the first byte in the mapping.
916 @discussion This method returns the virtual address of the first byte in the mapping.
917 @result A virtual address. */
918 inline mach_vm_address_t
getAddress() __attribute__((always_inline
));
919 /*! @function getSize
920 @abstract Accessor to the length of the mapping.
921 @discussion This method returns the length of the mapping.
922 @result A byte count. */
923 inline mach_vm_size_t
getSize() __attribute__((always_inline
));
924 #else /* !__LP64__ */
925 /*! @function getAddress
926 @abstract Accessor to the virtual address of the first byte in the mapping.
927 @discussion This method returns the virtual address of the first byte in the mapping.
928 @result A virtual address. */
929 virtual mach_vm_address_t
getAddress();
930 /*! @function getSize
931 @abstract Accessor to the length of the mapping.
932 @discussion This method returns the length of the mapping.
933 @result A byte count. */
934 virtual mach_vm_size_t
getSize();
935 #endif /* !__LP64__ */
937 #ifdef XNU_KERNEL_PRIVATE
938 // for IOMemoryDescriptor use
939 IOMemoryMap
* copyCompatible( IOMemoryMap
* newMapping
);
943 mach_vm_address_t toAddress
,
944 IOOptionBits options
,
945 mach_vm_size_t offset
,
946 mach_vm_size_t length
);
948 bool setMemoryDescriptor(IOMemoryDescriptor
* _memory
, mach_vm_size_t _offset
);
951 task_t intoTask
, bool redirect
);
953 IOReturn
userClientUnmap();
954 #endif /* XNU_KERNEL_PRIVATE */
958 mach_vm_size_t offset
,
959 mach_vm_size_t length
);
961 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 0);
962 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 1);
963 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 2);
964 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 3);
965 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 4);
966 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 5);
967 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 6);
968 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 7);
971 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
972 #ifdef XNU_KERNEL_PRIVATE
973 // Also these flags should not overlap with the options to
974 // IOMemoryDescriptor::initWithRanges(... IOOptionsBits options);
976 _kIOMemorySourceSegment
= 0x00002000
978 #endif /* XNU_KERNEL_PRIVATE */
980 // The following classes are private implementation of IOMemoryDescriptor - they
981 // should not be referenced directly, just through the public API's in the
982 // IOMemoryDescriptor class. For example, an IOGeneralMemoryDescriptor instance
983 // might be created by IOMemoryDescriptor::withAddressRange(), but there should be
984 // no need to reference as anything but a generic IOMemoryDescriptor *.
986 class IOGeneralMemoryDescriptor
: public IOMemoryDescriptor
988 OSDeclareDefaultStructors(IOGeneralMemoryDescriptor
);
999 unsigned _rangesCount
; /* number of address ranges in list */
1001 bool _rangesIsAllocated
; /* is list allocated by us? */
1002 #endif /* !__LP64__ */
1004 task_t _task
; /* task where all ranges are mapped to */
1009 } _singleRange
; /* storage space for a single range */
1011 unsigned _wireCount
; /* number of outstanding wires */
1014 uintptr_t _cachedVirtualAddress
;
1016 IOPhysicalAddress _cachedPhysicalAddress
;
1017 #endif /* !__LP64__ */
1019 bool _initialized
; /* has superclass been initialized? */
1022 virtual void free() APPLE_KEXT_OVERRIDE
;
1024 virtual IOReturn
dmaCommandOperation(DMACommandOps op
, void *vData
, UInt dataSize
) const APPLE_KEXT_OVERRIDE
;
1026 virtual uint64_t getPreparationID( void ) APPLE_KEXT_OVERRIDE
;
1028 #ifdef XNU_KERNEL_PRIVATE
1029 // Internal APIs may be made virtual at some time in the future.
1030 IOReturn
wireVirtual(IODirection forDirection
);
1033 IODMACommand
* command
,
1034 const IODMAMapSpecification
* mapSpec
,
1037 uint64_t * mapAddress
,
1038 uint64_t * mapLength
);
1039 bool initMemoryEntries(size_t size
, IOMapper
* mapper
);
1041 IOMemoryReference
* memoryReferenceAlloc(uint32_t capacity
,
1042 IOMemoryReference
* realloc
);
1043 void memoryReferenceFree(IOMemoryReference
* ref
);
1044 void memoryReferenceRelease(IOMemoryReference
* ref
);
1046 IOReturn
memoryReferenceCreate(
1047 IOOptionBits options
,
1048 IOMemoryReference
** reference
);
1050 IOReturn
memoryReferenceMap(IOMemoryReference
* ref
,
1052 mach_vm_size_t inoffset
,
1053 mach_vm_size_t size
,
1054 IOOptionBits options
,
1055 mach_vm_address_t
* inaddr
);
1057 static IOReturn
memoryReferenceSetPurgeable(
1058 IOMemoryReference
* ref
,
1059 IOOptionBits newState
,
1060 IOOptionBits
* oldState
);
1061 static IOReturn
memoryReferenceGetPageCounts(
1062 IOMemoryReference
* ref
,
1063 IOByteCount
* residentPageCount
,
1064 IOByteCount
* dirtyPageCount
);
1070 virtual void setPosition(IOByteCount position
);
1071 virtual void mapIntoKernel(unsigned rangeIndex
);
1072 virtual void unmapFromKernel();
1073 #endif /* !__LP64__ */
1076 OSData
* _memoryEntries
;
1077 unsigned int _pages
;
1078 ppnum_t _highestPage
;
1079 uint32_t __iomd_reservedA
;
1080 uint32_t __iomd_reservedB
;
1082 IOLock
* _prepareLock
;
1086 * IOMemoryDescriptor required methods
1089 // Master initaliser
1090 virtual bool initWithOptions(void * buffers
,
1094 IOOptionBits options
,
1095 IOMapper
* mapper
= kIOMapperSystem
) APPLE_KEXT_OVERRIDE
;
1098 // Secondary initialisers
1099 virtual bool initWithAddress(void * address
,
1100 IOByteCount withLength
,
1101 IODirection withDirection
) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1103 virtual bool initWithAddress(IOVirtualAddress address
,
1104 IOByteCount withLength
,
1105 IODirection withDirection
,
1106 task_t withTask
) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1108 virtual bool initWithPhysicalAddress(
1109 IOPhysicalAddress address
,
1110 IOByteCount withLength
,
1111 IODirection withDirection
) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1113 virtual bool initWithRanges( IOVirtualRange
* ranges
,
1115 IODirection withDirection
,
1117 bool asReference
= false) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1119 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
1121 IODirection withDirection
,
1122 bool asReference
= false) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1124 virtual addr64_t
getPhysicalSegment64( IOByteCount offset
,
1125 IOByteCount
* length
) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1127 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
1128 IOByteCount
* length
) APPLE_KEXT_OVERRIDE
;
1130 virtual IOPhysicalAddress
getSourceSegment(IOByteCount offset
,
1131 IOByteCount
* length
) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1133 virtual void * getVirtualSegment(IOByteCount offset
,
1134 IOByteCount
* length
) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1135 #endif /* !__LP64__ */
1137 virtual IOReturn
setPurgeable( IOOptionBits newState
,
1138 IOOptionBits
* oldState
) APPLE_KEXT_OVERRIDE
;
1140 virtual addr64_t
getPhysicalSegment( IOByteCount offset
,
1141 IOByteCount
* length
,
1143 IOOptionBits options
= 0 ) APPLE_KEXT_OVERRIDE
;
1144 #else /* !__LP64__ */
1145 IOOptionBits options
) APPLE_KEXT_OVERRIDE
;
1146 #endif /* !__LP64__ */
1148 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
) APPLE_KEXT_OVERRIDE
;
1150 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
) APPLE_KEXT_OVERRIDE
;
1152 virtual IOReturn
doMap(
1153 vm_map_t addressMap
,
1154 IOVirtualAddress
* atAddress
,
1155 IOOptionBits options
,
1156 IOByteCount sourceOffset
= 0,
1157 IOByteCount length
= 0 ) APPLE_KEXT_OVERRIDE
;
1159 virtual IOReturn
doUnmap(
1160 vm_map_t addressMap
,
1161 IOVirtualAddress logical
,
1162 IOByteCount length
) APPLE_KEXT_OVERRIDE
;
1164 virtual bool serialize(OSSerialize
*s
) const APPLE_KEXT_OVERRIDE
;
1166 // Factory method for cloning a persistent IOMD, see IOMemoryDescriptor
1167 static IOMemoryDescriptor
*
1168 withPersistentMemoryDescriptor(IOGeneralMemoryDescriptor
*originalMD
);
1172 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1175 mach_vm_address_t
IOMemoryMap::getAddress()
1177 return (getVirtualAddress());
1180 mach_vm_size_t
IOMemoryMap::getSize()
1182 return (getLength());
1184 #else /* !__LP64__ */
1185 #include <IOKit/IOSubMemoryDescriptor.h>
1186 #endif /* !__LP64__ */
1188 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1190 #endif /* !_IOMEMORYDESCRIPTOR_H */