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
237 UInt64 fMappedBase
; // Input base of mapping
239 typedef UInt8 IOMDDMAWalkSegmentState
[128];
243 kIOMDDMAWalkMappedLocal
= 2
246 #endif /* KERNEL_PRIVATE */
250 kIOPreparationIDUnprepared
= 0,
251 kIOPreparationIDUnsupported
= 1,
252 kIOPreparationIDAlwaysPrepared
= 2,
255 #ifdef XNU_KERNEL_PRIVATE
256 struct IOMemoryReference
;
260 /*! @class IOMemoryDescriptor : public OSObject
261 @abstract An abstract base class defining common methods for describing physical or virtual memory.
262 @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. */
264 class IOMemoryDescriptor
: public OSObject
266 friend class IOMemoryMap
;
267 friend class IOMultiMemoryDescriptor
;
269 OSDeclareDefaultStructors(IOMemoryDescriptor
);
274 Reserved for future use. (Internal use only) */
275 struct IOMemoryDescriptorReserved
* reserved
;
282 #ifdef XNU_KERNEL_PRIVATE
284 struct IOMemoryReference
* _memRef
;
287 int16_t _dmaReferences
;
288 uint16_t _internalFlags
;
289 kern_allocation_name_t _mapName
;
291 #else /* XNU_KERNEL_PRIVATE */
292 void * __iomd_reserved5
;
293 uint16_t __iomd_reserved1
[4];
294 uintptr_t __iomd_reserved2
;
295 #endif /* XNU_KERNEL_PRIVATE */
297 uintptr_t __iomd_reserved3
;
298 uintptr_t __iomd_reserved4
;
301 IODirection _direction
; /* use _flags instead */
302 #endif /* !__LP64__ */
303 IOByteCount _length
; /* length of all ranges */
307 typedef IOOptionBits DMACommandOps
;
309 virtual IOPhysicalAddress
getSourceSegment( IOByteCount offset
,
310 IOByteCount
* length
) APPLE_KEXT_DEPRECATED
;
311 #endif /* !__LP64__ */
313 /*! @function initWithOptions
314 @abstract Master initialiser for all variants of memory descriptors. For a more complete description see IOMemoryDescriptor::withOptions.
315 @discussion Note this function can be used to re-init a previously created memory descriptor.
316 @result true on success, false on failure. */
317 virtual bool initWithOptions(void * buffers
,
321 IOOptionBits options
,
322 IOMapper
* mapper
= kIOMapperSystem
);
325 virtual addr64_t
getPhysicalSegment64( IOByteCount offset
,
326 IOByteCount
* length
) APPLE_KEXT_DEPRECATED
; /* use getPhysicalSegment() and kIOMemoryMapperNone instead */
327 #endif /* !__LP64__ */
329 /*! @function setPurgeable
330 @abstract Control the purgeable status of a memory descriptors memory.
331 @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.
332 @param newState - the desired new purgeable state of the memory:<br>
333 kIOMemoryPurgeableKeepCurrent - make no changes to the memory's purgeable state.<br>
334 kIOMemoryPurgeableVolatile - make the memory volatile - the memory may be reclaimed by the VM system without saving its contents to backing store.<br>
335 kIOMemoryPurgeableNonVolatile - make the memory nonvolatile - the memory is treated as with usual allocations and must be saved to backing store if paged.<br>
336 kIOMemoryPurgeableEmpty - make the memory volatile, and discard any pages allocated to it.
337 @param oldState - if non-NULL, the previous purgeable state of the memory is returned here:<br>
338 kIOMemoryPurgeableNonVolatile - the memory was nonvolatile.<br>
339 kIOMemoryPurgeableVolatile - the memory was volatile but its content has not been discarded by the VM system.<br>
340 kIOMemoryPurgeableEmpty - the memory was volatile and has been discarded by the VM system.<br>
341 @result An IOReturn code. */
343 virtual IOReturn
setPurgeable( IOOptionBits newState
,
344 IOOptionBits
* oldState
);
347 /*! @function getPageCounts
348 @abstract Retrieve the number of resident and/or dirty pages encompassed by an IOMemoryDescriptor.
349 @discussion This method returns the number of resident and/or dirty pages encompassed by an IOMemoryDescriptor.
350 @param residentPageCount - If non-null, a pointer to a byte count that will return the number of resident pages encompassed by this IOMemoryDescriptor.
351 @param dirtyPageCount - If non-null, a pointer to a byte count that will return the number of dirty pages encompassed by this IOMemoryDescriptor.
352 @result An IOReturn code. */
354 IOReturn
getPageCounts( IOByteCount
* residentPageCount
,
355 IOByteCount
* dirtyPageCount
);
357 /*! @function performOperation
358 @abstract Perform an operation on the memory descriptor's memory.
359 @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.
360 @param options The operation to perform on the memory:<br>
361 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>
362 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.
363 @param offset A byte offset into the memory descriptor's memory.
364 @param length The length of the data range.
365 @result An IOReturn code. */
367 virtual IOReturn
performOperation( IOOptionBits options
,
368 IOByteCount offset
, IOByteCount length
);
370 // Used for dedicated communications for IODMACommand
371 virtual IOReturn
dmaCommandOperation(DMACommandOps op
, void *vData
, UInt dataSize
) const;
373 /*! @function getPhysicalSegment
374 @abstract Break a memory descriptor into its physically contiguous segments.
375 @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.
376 @param offset A byte offset into the memory whose physical address to return.
377 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
378 @result A physical address, or zero if the offset is beyond the length of the memory. */
381 virtual addr64_t
getPhysicalSegment( IOByteCount offset
,
382 IOByteCount
* length
,
383 IOOptionBits options
= 0 ) = 0;
384 #else /* !__LP64__ */
385 virtual addr64_t
getPhysicalSegment( IOByteCount offset
,
386 IOByteCount
* length
,
387 IOOptionBits options
);
388 #endif /* !__LP64__ */
390 virtual uint64_t getPreparationID( void );
391 void setPreparationID( void );
393 #ifdef XNU_KERNEL_PRIVATE
394 IOMemoryDescriptorReserved
* getKernelReserved( void );
397 IODMACommand
* command
,
398 const IODMAMapSpecification
* mapSpec
,
401 uint64_t * mapAddress
,
402 uint64_t * mapLength
);
405 IODMACommand
* command
,
411 IODMACommand
* command
,
414 void setVMTags(vm_tag_t kernelTag
, vm_tag_t userTag
);
415 vm_tag_t
getVMTag(vm_map_t map
);
419 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 0);
421 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 1);
422 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 2);
423 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 3);
424 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 4);
425 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 5);
426 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 6);
427 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 7);
428 #else /* !__LP64__ */
429 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 1);
430 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 2);
431 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 3);
432 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 4);
433 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 5);
434 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 6);
435 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 7);
436 #endif /* !__LP64__ */
437 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 8);
438 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 9);
439 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 10);
440 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 11);
441 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 12);
442 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 13);
443 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 14);
444 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 15);
447 virtual void free() APPLE_KEXT_OVERRIDE
;
449 static void initialize( void );
452 /*! @function withAddress
453 @abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
454 @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.
455 @param address The virtual address of the first byte in the memory.
456 @param withLength The length of memory.
457 @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.
458 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
460 static IOMemoryDescriptor
* withAddress(void * address
,
461 IOByteCount withLength
,
462 IODirection withDirection
);
465 static IOMemoryDescriptor
* withAddress(IOVirtualAddress address
,
466 IOByteCount withLength
,
467 IODirection withDirection
,
468 task_t withTask
) APPLE_KEXT_DEPRECATED
; /* use withAddressRange() and prepare() instead */
469 #endif /* !__LP64__ */
471 /*! @function withPhysicalAddress
472 @abstract Create an IOMemoryDescriptor to describe one physical range.
473 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.
474 @param address The physical address of the first byte in the memory.
475 @param withLength The length of memory.
476 @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.
477 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
479 static IOMemoryDescriptor
* withPhysicalAddress(
480 IOPhysicalAddress address
,
481 IOByteCount withLength
,
482 IODirection withDirection
);
485 static IOMemoryDescriptor
* withRanges(IOVirtualRange
* ranges
,
487 IODirection withDirection
,
489 bool asReference
= false) APPLE_KEXT_DEPRECATED
; /* use withAddressRanges() instead */
490 #endif /* !__LP64__ */
492 /*! @function withAddressRange
493 @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
494 @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.
495 @param address The virtual address of the first byte in the memory.
496 @param length The length of memory.
498 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.
499 @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.
500 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
502 static IOMemoryDescriptor
* withAddressRange(
503 mach_vm_address_t address
,
504 mach_vm_size_t length
,
505 IOOptionBits options
,
508 /*! @function withAddressRanges
509 @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
510 @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.
511 @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.
512 @param rangeCount The member count of the ranges array.
514 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.
515 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.
516 @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.
517 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
519 static IOMemoryDescriptor
* withAddressRanges(
520 IOAddressRange
* ranges
,
522 IOOptionBits options
,
525 /*! @function withOptions
526 @abstract Master initialiser for all variants of memory descriptors.
527 @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.
530 @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.
532 @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.
534 @param offset Only used when options:type = UPL, in which case this field contains an offset for the memory within the buffers upl.
536 @param task Only used options:type = Virtual, The task each of the virtual ranges are mapped into.
539 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.
540 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.
541 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.
542 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.
544 @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.
546 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
548 static IOMemoryDescriptor
*withOptions(void * buffers
,
552 IOOptionBits options
,
553 IOMapper
* mapper
= kIOMapperSystem
);
556 static IOMemoryDescriptor
* withPhysicalRanges(
557 IOPhysicalRange
* ranges
,
559 IODirection withDirection
,
560 bool asReference
= false) APPLE_KEXT_DEPRECATED
; /* use withOptions() and kIOMemoryTypePhysical instead */
561 #endif /* !__LP64__ */
564 static IOMemoryDescriptor
* withSubRange(IOMemoryDescriptor
*of
,
567 IODirection withDirection
) APPLE_KEXT_DEPRECATED
; /* use IOSubMemoryDescriptor::withSubRange() and kIOMemoryThreadSafe instead */
568 #endif /* !__LP64__ */
570 /*! @function withPersistentMemoryDescriptor
571 @abstract Copy constructor that generates a new memory descriptor if the backing memory for the same task's virtual address and length has changed.
572 @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.
573 @param originalMD The memory descriptor to be duplicated.
574 @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. */
575 static IOMemoryDescriptor
*
576 withPersistentMemoryDescriptor(IOMemoryDescriptor
*originalMD
);
579 // obsolete initializers
580 // - initWithOptions is the designated initializer
581 virtual bool initWithAddress(void * address
,
582 IOByteCount withLength
,
583 IODirection withDirection
) APPLE_KEXT_DEPRECATED
; /* use initWithOptions() instead */
584 virtual bool initWithAddress(IOVirtualAddress address
,
585 IOByteCount withLength
,
586 IODirection withDirection
,
587 task_t withTask
) APPLE_KEXT_DEPRECATED
; /* use initWithOptions() instead */
588 virtual bool initWithPhysicalAddress(
589 IOPhysicalAddress address
,
590 IOByteCount withLength
,
591 IODirection withDirection
) APPLE_KEXT_DEPRECATED
; /* use initWithOptions() instead */
592 virtual bool initWithRanges(IOVirtualRange
* ranges
,
594 IODirection withDirection
,
596 bool asReference
= false) APPLE_KEXT_DEPRECATED
; /* use initWithOptions() instead */
597 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
599 IODirection withDirection
,
600 bool asReference
= false) APPLE_KEXT_DEPRECATED
; /* use initWithOptions() instead */
601 #endif /* __LP64__ */
603 /*! @function getDirection
604 @abstract Accessor to get the direction the memory descriptor was created with.
605 @discussion This method returns the direction the memory descriptor was created with.
606 @result The direction. */
608 virtual IODirection
getDirection() const;
610 /*! @function getLength
611 @abstract Accessor to get the length of the memory descriptor (over all its ranges).
612 @discussion This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.
613 @result The byte count. */
615 virtual IOByteCount
getLength() const;
618 @abstract Set the tag for the memory descriptor.
619 @discussion This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
620 @param tag The tag. */
622 virtual void setTag( IOOptionBits tag
);
625 @abstract Accessor to the retrieve the tag for the memory descriptor.
626 @discussion This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
629 virtual IOOptionBits
getTag( void );
631 /*! @function getFlags
632 @abstract Accessor to the retrieve the options the memory descriptor was created with.
633 @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.
634 @result The flags bitfield. */
636 uint64_t getFlags(void);
638 /*! @function readBytes
639 @abstract Copy data from the memory descriptor's buffer to the specified buffer.
640 @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.
641 @param offset A byte offset into the memory descriptor's memory.
642 @param bytes The caller supplied buffer to copy the data to.
643 @param withLength The length of the data to copy.
644 @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. */
646 virtual IOByteCount
readBytes(IOByteCount offset
,
647 void * bytes
, IOByteCount withLength
);
649 /*! @function writeBytes
650 @abstract Copy data to the memory descriptor's buffer from the specified buffer.
651 @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.
652 @param offset A byte offset into the memory descriptor's memory.
653 @param bytes The caller supplied buffer to copy the data from.
654 @param withLength The length of the data to copy.
655 @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. */
657 virtual IOByteCount
writeBytes(IOByteCount offset
,
658 const void * bytes
, IOByteCount withLength
);
661 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
662 IOByteCount
* length
);
663 #endif /* !__LP64__ */
665 /*! @function getPhysicalAddress
666 @abstract Return the physical address of the first byte in the memory.
667 @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.
668 @result A physical address. */
670 IOPhysicalAddress
getPhysicalAddress();
673 virtual void * getVirtualSegment(IOByteCount offset
,
674 IOByteCount
* length
) APPLE_KEXT_DEPRECATED
; /* use map() and getVirtualAddress() instead */
675 #endif /* !__LP64__ */
677 /*! @function prepare
678 @abstract Prepare the memory for an I/O transfer.
679 @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.
680 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
681 @result An IOReturn code. */
683 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
) = 0;
685 /*! @function complete
686 @abstract Complete processing of the memory after an I/O transfer finishes.
687 @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.
688 @param forDirection DEPRECATED The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
689 @result An IOReturn code. */
691 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
) = 0;
697 /*! @function createMappingInTask
698 @abstract Maps a IOMemoryDescriptor into a task.
699 @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.
700 @param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space.
701 @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
702 @param options Mapping options are defined in IOTypes.h,<br>
703 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>
704 kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br>
705 kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br>
706 kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br>
707 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>
708 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>
709 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>
710 @param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
711 @param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
712 @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. */
714 IOMemoryMap
* createMappingInTask(
716 mach_vm_address_t atAddress
,
717 IOOptionBits options
,
718 mach_vm_size_t offset
= 0,
719 mach_vm_size_t length
= 0 );
722 virtual IOMemoryMap
* map(
724 IOVirtualAddress atAddress
,
725 IOOptionBits options
,
726 IOByteCount offset
= 0,
727 IOByteCount length
= 0 ) APPLE_KEXT_DEPRECATED
; /* use createMappingInTask() instead */
728 #endif /* !__LP64__ */
731 @abstract Maps a IOMemoryDescriptor into the kernel map.
732 @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.
733 @param options Mapping options as in the full version of the createMappingInTask method, with kIOMapAnywhere assumed.
734 @result See the full version of the createMappingInTask method. */
736 virtual IOMemoryMap
* map(
737 IOOptionBits options
= 0 );
739 /*! @function setMapping
740 @abstract Establishes an already existing mapping.
741 @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.
742 @param task Address space in which the mapping exists.
743 @param mapAddress Virtual address of the mapping.
744 @param options Caching and read-only attributes of the mapping.
745 @result A IOMemoryMap object created to represent the mapping. */
747 virtual IOMemoryMap
* setMapping(
749 IOVirtualAddress mapAddress
,
750 IOOptionBits options
= 0 );
752 // Following methods are private implementation
756 #endif /* __LP64__ */
757 IOReturn
redirect( task_t safeTask
, bool redirect
);
759 IOReturn
handleFault(
761 mach_vm_size_t sourceOffset
,
762 mach_vm_size_t length
);
764 IOReturn
populateDevicePager(
767 mach_vm_address_t address
,
768 mach_vm_size_t sourceOffset
,
769 mach_vm_size_t length
,
770 IOOptionBits options
);
772 virtual IOMemoryMap
* makeMapping(
773 IOMemoryDescriptor
* owner
,
775 IOVirtualAddress atAddress
,
776 IOOptionBits options
,
778 IOByteCount length
);
781 virtual void addMapping(
782 IOMemoryMap
* mapping
);
784 virtual void removeMapping(
785 IOMemoryMap
* mapping
);
787 virtual IOReturn
doMap(
789 IOVirtualAddress
* atAddress
,
790 IOOptionBits options
,
791 IOByteCount sourceOffset
= 0,
792 IOByteCount length
= 0 );
794 virtual IOReturn
doUnmap(
796 IOVirtualAddress logical
,
797 IOByteCount length
);
800 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
802 /*! @class IOMemoryMap : public OSObject
803 @abstract A class defining common methods for describing a memory mapping.
804 @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. */
806 class IOMemoryMap
: public OSObject
808 OSDeclareDefaultStructors(IOMemoryMap
)
809 #ifdef XNU_KERNEL_PRIVATE
811 IOMemoryDescriptor
* fMemory
;
812 IOMemoryMap
* fSuperMap
;
813 mach_vm_size_t fOffset
;
814 mach_vm_address_t fAddress
;
815 mach_vm_size_t fLength
;
817 vm_map_t fAddressMap
;
818 IOOptionBits fOptions
;
820 ipc_port_t fRedirEntry
;
821 IOMemoryDescriptor
* fOwner
;
822 uint8_t fUserClientUnmap
;
824 IOTrackingUser fTracking
;
826 #endif /* XNU_KERNEL_PRIVATE */
829 virtual void taggedRelease(const void *tag
= 0) const APPLE_KEXT_OVERRIDE
;
830 virtual void free() APPLE_KEXT_OVERRIDE
;
833 /*! @function getVirtualAddress
834 @abstract Accessor to the virtual address of the first byte in the mapping.
835 @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.
836 @result A virtual address. */
838 virtual IOVirtualAddress
getVirtualAddress();
840 /*! @function getPhysicalSegment
841 @abstract Break a mapping into its physically contiguous segments.
842 @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.
843 @param offset A byte offset into the mapping whose physical address to return.
844 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
845 @result A physical address, or zero if the offset is beyond the length of the mapping. */
848 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
849 IOByteCount
* length
,
850 IOOptionBits options
= 0);
851 #else /* !__LP64__ */
852 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
853 IOByteCount
* length
);
854 #endif /* !__LP64__ */
856 /*! @function getPhysicalAddress
857 @abstract Return the physical address of the first byte in the mapping.
858 @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.
859 @result A physical address. */
861 IOPhysicalAddress
getPhysicalAddress();
863 /*! @function getLength
864 @abstract Accessor to the length of the mapping.
865 @discussion This method returns the length of the mapping.
866 @result A byte count. */
868 virtual IOByteCount
getLength();
870 /*! @function getAddressTask
871 @abstract Accessor to the task of the mapping.
872 @discussion This method returns the mach task the mapping exists in.
873 @result A mach task_t. */
875 virtual task_t
getAddressTask();
877 /*! @function getMemoryDescriptor
878 @abstract Accessor to the IOMemoryDescriptor the mapping was created from.
879 @discussion This method returns the IOMemoryDescriptor the mapping was created from.
880 @result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */
882 virtual IOMemoryDescriptor
* getMemoryDescriptor();
884 /*! @function getMapOptions
885 @abstract Accessor to the options the mapping was created with.
886 @discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with.
887 @result Options for the mapping, including cache settings. */
889 virtual IOOptionBits
getMapOptions();
892 @abstract Force the IOMemoryMap to unmap, without destroying the object.
893 @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.
894 @result An IOReturn code. */
896 virtual IOReturn
unmap();
898 virtual void taskDied();
900 /*! @function redirect
901 @abstract Replace the memory mapped in a process with new backing memory.
902 @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.
903 @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.
904 @param options Mapping options are defined in IOTypes.h, and are documented in IOMemoryDescriptor::map()
905 @param offset As with IOMemoryDescriptor::map(), a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default.
906 @result An IOReturn code. */
909 // For 32 bit XNU, there is a 32 bit (IOByteCount) and a 64 bit (mach_vm_size_t) interface;
910 // for 64 bit, these fall together on the 64 bit one.
911 virtual IOReturn
redirect(IOMemoryDescriptor
* newBackingMemory
,
912 IOOptionBits options
,
913 IOByteCount offset
= 0);
915 virtual IOReturn
redirect(IOMemoryDescriptor
* newBackingMemory
,
916 IOOptionBits options
,
917 mach_vm_size_t offset
= 0);
920 /*! @function getAddress
921 @abstract Accessor to the virtual address of the first byte in the mapping.
922 @discussion This method returns the virtual address of the first byte in the mapping.
923 @result A virtual address. */
924 inline mach_vm_address_t
getAddress() __attribute__((always_inline
));
925 /*! @function getSize
926 @abstract Accessor to the length of the mapping.
927 @discussion This method returns the length of the mapping.
928 @result A byte count. */
929 inline mach_vm_size_t
getSize() __attribute__((always_inline
));
930 #else /* !__LP64__ */
931 /*! @function getAddress
932 @abstract Accessor to the virtual address of the first byte in the mapping.
933 @discussion This method returns the virtual address of the first byte in the mapping.
934 @result A virtual address. */
935 virtual mach_vm_address_t
getAddress();
936 /*! @function getSize
937 @abstract Accessor to the length of the mapping.
938 @discussion This method returns the length of the mapping.
939 @result A byte count. */
940 virtual mach_vm_size_t
getSize();
941 #endif /* !__LP64__ */
943 #ifdef XNU_KERNEL_PRIVATE
944 // for IOMemoryDescriptor use
945 IOMemoryMap
* copyCompatible( IOMemoryMap
* newMapping
);
949 mach_vm_address_t toAddress
,
950 IOOptionBits options
,
951 mach_vm_size_t offset
,
952 mach_vm_size_t length
);
954 bool setMemoryDescriptor(IOMemoryDescriptor
* _memory
, mach_vm_size_t _offset
);
957 task_t intoTask
, bool redirect
);
959 IOReturn
userClientUnmap();
960 #endif /* XNU_KERNEL_PRIVATE */
964 mach_vm_size_t offset
,
965 mach_vm_size_t length
);
967 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 0);
968 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 1);
969 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 2);
970 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 3);
971 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 4);
972 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 5);
973 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 6);
974 OSMetaClassDeclareReservedUnused(IOMemoryMap
, 7);
977 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
978 #ifdef XNU_KERNEL_PRIVATE
979 // Also these flags should not overlap with the options to
980 // IOMemoryDescriptor::initWithRanges(... IOOptionsBits options);
982 _kIOMemorySourceSegment
= 0x00002000
984 #endif /* XNU_KERNEL_PRIVATE */
986 // The following classes are private implementation of IOMemoryDescriptor - they
987 // should not be referenced directly, just through the public API's in the
988 // IOMemoryDescriptor class. For example, an IOGeneralMemoryDescriptor instance
989 // might be created by IOMemoryDescriptor::withAddressRange(), but there should be
990 // no need to reference as anything but a generic IOMemoryDescriptor *.
992 class IOGeneralMemoryDescriptor
: public IOMemoryDescriptor
994 OSDeclareDefaultStructors(IOGeneralMemoryDescriptor
);
1005 unsigned _rangesCount
; /* number of address ranges in list */
1007 bool _rangesIsAllocated
; /* is list allocated by us? */
1008 #endif /* !__LP64__ */
1010 task_t _task
; /* task where all ranges are mapped to */
1015 } _singleRange
; /* storage space for a single range */
1017 unsigned _wireCount
; /* number of outstanding wires */
1020 uintptr_t _cachedVirtualAddress
;
1022 IOPhysicalAddress _cachedPhysicalAddress
;
1023 #endif /* !__LP64__ */
1025 bool _initialized
; /* has superclass been initialized? */
1028 virtual void free() APPLE_KEXT_OVERRIDE
;
1030 virtual IOReturn
dmaCommandOperation(DMACommandOps op
, void *vData
, UInt dataSize
) const APPLE_KEXT_OVERRIDE
;
1032 virtual uint64_t getPreparationID( void ) APPLE_KEXT_OVERRIDE
;
1034 #ifdef XNU_KERNEL_PRIVATE
1035 // Internal APIs may be made virtual at some time in the future.
1036 IOReturn
wireVirtual(IODirection forDirection
);
1039 IODMACommand
* command
,
1040 const IODMAMapSpecification
* mapSpec
,
1043 uint64_t * mapAddress
,
1044 uint64_t * mapLength
);
1045 bool initMemoryEntries(size_t size
, IOMapper
* mapper
);
1047 IOMemoryReference
* memoryReferenceAlloc(uint32_t capacity
,
1048 IOMemoryReference
* realloc
);
1049 void memoryReferenceFree(IOMemoryReference
* ref
);
1050 void memoryReferenceRelease(IOMemoryReference
* ref
);
1052 IOReturn
memoryReferenceCreate(
1053 IOOptionBits options
,
1054 IOMemoryReference
** reference
);
1056 IOReturn
memoryReferenceMap(IOMemoryReference
* ref
,
1058 mach_vm_size_t inoffset
,
1059 mach_vm_size_t size
,
1060 IOOptionBits options
,
1061 mach_vm_address_t
* inaddr
);
1063 static IOReturn
memoryReferenceSetPurgeable(
1064 IOMemoryReference
* ref
,
1065 IOOptionBits newState
,
1066 IOOptionBits
* oldState
);
1067 static IOReturn
memoryReferenceGetPageCounts(
1068 IOMemoryReference
* ref
,
1069 IOByteCount
* residentPageCount
,
1070 IOByteCount
* dirtyPageCount
);
1076 virtual void setPosition(IOByteCount position
);
1077 virtual void mapIntoKernel(unsigned rangeIndex
);
1078 virtual void unmapFromKernel();
1079 #endif /* !__LP64__ */
1082 OSData
* _memoryEntries
;
1083 unsigned int _pages
;
1084 ppnum_t _highestPage
;
1085 uint32_t __iomd_reservedA
;
1086 uint32_t __iomd_reservedB
;
1088 IOLock
* _prepareLock
;
1092 * IOMemoryDescriptor required methods
1095 // Master initaliser
1096 virtual bool initWithOptions(void * buffers
,
1100 IOOptionBits options
,
1101 IOMapper
* mapper
= kIOMapperSystem
) APPLE_KEXT_OVERRIDE
;
1104 // Secondary initialisers
1105 virtual bool initWithAddress(void * address
,
1106 IOByteCount withLength
,
1107 IODirection withDirection
) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1109 virtual bool initWithAddress(IOVirtualAddress address
,
1110 IOByteCount withLength
,
1111 IODirection withDirection
,
1112 task_t withTask
) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1114 virtual bool initWithPhysicalAddress(
1115 IOPhysicalAddress address
,
1116 IOByteCount withLength
,
1117 IODirection withDirection
) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1119 virtual bool initWithRanges( IOVirtualRange
* ranges
,
1121 IODirection withDirection
,
1123 bool asReference
= false) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1125 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
1127 IODirection withDirection
,
1128 bool asReference
= false) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1130 virtual addr64_t
getPhysicalSegment64( IOByteCount offset
,
1131 IOByteCount
* length
) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1133 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
1134 IOByteCount
* length
) APPLE_KEXT_OVERRIDE
;
1136 virtual IOPhysicalAddress
getSourceSegment(IOByteCount offset
,
1137 IOByteCount
* length
) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1139 virtual void * getVirtualSegment(IOByteCount offset
,
1140 IOByteCount
* length
) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED
;
1141 #endif /* !__LP64__ */
1143 virtual IOReturn
setPurgeable( IOOptionBits newState
,
1144 IOOptionBits
* oldState
) APPLE_KEXT_OVERRIDE
;
1146 virtual addr64_t
getPhysicalSegment( IOByteCount offset
,
1147 IOByteCount
* length
,
1149 IOOptionBits options
= 0 ) APPLE_KEXT_OVERRIDE
;
1150 #else /* !__LP64__ */
1151 IOOptionBits options
) APPLE_KEXT_OVERRIDE
;
1152 #endif /* !__LP64__ */
1154 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
) APPLE_KEXT_OVERRIDE
;
1156 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
) APPLE_KEXT_OVERRIDE
;
1158 virtual IOReturn
doMap(
1159 vm_map_t addressMap
,
1160 IOVirtualAddress
* atAddress
,
1161 IOOptionBits options
,
1162 IOByteCount sourceOffset
= 0,
1163 IOByteCount length
= 0 ) APPLE_KEXT_OVERRIDE
;
1165 virtual IOReturn
doUnmap(
1166 vm_map_t addressMap
,
1167 IOVirtualAddress logical
,
1168 IOByteCount length
) APPLE_KEXT_OVERRIDE
;
1170 virtual bool serialize(OSSerialize
*s
) const APPLE_KEXT_OVERRIDE
;
1172 // Factory method for cloning a persistent IOMD, see IOMemoryDescriptor
1173 static IOMemoryDescriptor
*
1174 withPersistentMemoryDescriptor(IOGeneralMemoryDescriptor
*originalMD
);
1178 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1181 mach_vm_address_t
IOMemoryMap::getAddress()
1183 return (getVirtualAddress());
1186 mach_vm_size_t
IOMemoryMap::getSize()
1188 return (getLength());
1190 #else /* !__LP64__ */
1191 #include <IOKit/IOSubMemoryDescriptor.h>
1192 #endif /* !__LP64__ */
1194 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1196 #endif /* !_IOMEMORYDESCRIPTOR_H */