/*
- * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1998-2016 Apple Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
*
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
*
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
#ifndef _IOMEMORYDESCRIPTOR_H
#define _IOMEMORYDESCRIPTOR_H
#include <sys/cdefs.h>
#include <IOKit/IOTypes.h>
+#include <IOKit/IOLocks.h>
#include <libkern/c++/OSContainers.h>
+#ifdef XNU_KERNEL_PRIVATE
+#include <IOKit/IOKitDebug.h>
+#endif
-__BEGIN_DECLS
#include <mach/memory_object_types.h>
-__END_DECLS
-
-struct IOPhysicalRange
-{
- IOPhysicalAddress address;
- IOByteCount length;
-};
class IOMemoryMap;
class IOMapper;
+class IOService;
+class IODMACommand;
/*
* Direction of transfer, with respect to the described memory.
*/
+#ifdef __LP64__
+enum
+#else /* !__LP64__ */
enum IODirection
+#endif /* !__LP64__ */
{
kIODirectionNone = 0x0, // same as VM_PROT_NONE
kIODirectionIn = 0x1, // User land 'read', same as VM_PROT_READ
kIODirectionOut = 0x2, // User land 'write', same as VM_PROT_WRITE
kIODirectionOutIn = kIODirectionOut | kIODirectionIn,
- kIODirectionInOut = kIODirectionIn | kIODirectionOut
+ kIODirectionInOut = kIODirectionIn | kIODirectionOut,
+
+ // these flags are valid for the prepare() method only
+ kIODirectionPrepareToPhys32 = 0x00000004,
+ kIODirectionPrepareNoFault = 0x00000008,
+ kIODirectionPrepareReserved1 = 0x00000010,
+#define IODIRECTIONPREPARENONCOHERENTDEFINED 1
+ kIODirectionPrepareNonCoherent = 0x00000020,
+
+ // these flags are valid for the complete() method only
+#define IODIRECTIONCOMPLETEWITHERRORDEFINED 1
+ kIODirectionCompleteWithError = 0x00000040,
+#define IODIRECTIONCOMPLETEWITHDATAVALIDDEFINED 1
+ kIODirectionCompleteWithDataValid = 0x00000080,
};
+#ifdef __LP64__
+typedef IOOptionBits IODirection;
+#endif /* __LP64__ */
+
/*
* IOOptionBits used in the withOptions variant
*/
enum {
kIOMemoryDirectionMask = 0x00000007,
+#ifdef XNU_KERNEL_PRIVATE
kIOMemoryAutoPrepare = 0x00000008, // Shared with Buffer MD
-
+#endif
+
kIOMemoryTypeVirtual = 0x00000010,
kIOMemoryTypePhysical = 0x00000020,
kIOMemoryTypeUPL = 0x00000030,
kIOMemoryTypePersistentMD = 0x00000040, // Persistent Memory Descriptor
kIOMemoryTypeUIO = 0x00000050,
+#ifdef __LP64__
+ kIOMemoryTypeVirtual64 = kIOMemoryTypeVirtual,
+ kIOMemoryTypePhysical64 = kIOMemoryTypePhysical,
+#else /* !__LP64__ */
kIOMemoryTypeVirtual64 = 0x00000060,
kIOMemoryTypePhysical64 = 0x00000070,
+#endif /* !__LP64__ */
kIOMemoryTypeMask = 0x000000f0,
kIOMemoryAsReference = 0x00000100,
kIOMemoryBufferPageable = 0x00000400,
- kIOMemoryDontMap = 0x00000800,
- kIOMemoryPersistent = 0x00010000
+ kIOMemoryMapperNone = 0x00000800, // Shared with Buffer MD
+ kIOMemoryHostOnly = 0x00001000, // Never DMA accessible
+#ifdef XNU_KERNEL_PRIVATE
+ kIOMemoryRedirected = 0x00004000,
+ kIOMemoryPreparedReadOnly = 0x00008000,
+#endif
+ kIOMemoryPersistent = 0x00010000,
+ kIOMemoryMapCopyOnWrite = 0x00020000,
+ kIOMemoryRemote = 0x00040000,
+ kIOMemoryThreadSafe = 0x00100000, // Shared with Buffer MD
+ kIOMemoryClearEncrypt = 0x00200000, // Shared with Buffer MD
+ kIOMemoryUseReserve = 0x00800000, // Shared with Buffer MD
+#define IOMEMORYUSERESERVEDEFINED 1
+
+#ifdef XNU_KERNEL_PRIVATE
+ kIOMemoryBufferPurgeable = 0x00400000,
+ kIOMemoryBufferCacheMask = 0x70000000,
+ kIOMemoryBufferCacheShift = 28,
+#endif
};
-#define kIOMapperNone ((IOMapper *) -1)
#define kIOMapperSystem ((IOMapper *) 0)
enum
{
kIOMemoryPurgeableKeepCurrent = 1,
+
kIOMemoryPurgeableNonVolatile = 2,
kIOMemoryPurgeableVolatile = 3,
- kIOMemoryPurgeableEmpty = 4
+ kIOMemoryPurgeableEmpty = 4,
+
+ // modifiers for kIOMemoryPurgeableVolatile behavior
+ kIOMemoryPurgeableVolatileGroup0 = VM_VOLATILE_GROUP_0,
+ kIOMemoryPurgeableVolatileGroup1 = VM_VOLATILE_GROUP_1,
+ kIOMemoryPurgeableVolatileGroup2 = VM_VOLATILE_GROUP_2,
+ kIOMemoryPurgeableVolatileGroup3 = VM_VOLATILE_GROUP_3,
+ kIOMemoryPurgeableVolatileGroup4 = VM_VOLATILE_GROUP_4,
+ kIOMemoryPurgeableVolatileGroup5 = VM_VOLATILE_GROUP_5,
+ kIOMemoryPurgeableVolatileGroup6 = VM_VOLATILE_GROUP_6,
+ kIOMemoryPurgeableVolatileGroup7 = VM_VOLATILE_GROUP_7,
+ kIOMemoryPurgeableVolatileBehaviorFifo = VM_PURGABLE_BEHAVIOR_FIFO,
+ kIOMemoryPurgeableVolatileBehaviorLifo = VM_PURGABLE_BEHAVIOR_LIFO,
+ kIOMemoryPurgeableVolatileOrderingObsolete = VM_PURGABLE_ORDERING_OBSOLETE,
+ kIOMemoryPurgeableVolatileOrderingNormal = VM_PURGABLE_ORDERING_NORMAL,
+ kIOMemoryPurgeableFaultOnAccess = VM_PURGABLE_DEBUG_FAULT,
};
enum
{
kIOMemoryIncoherentIOFlush = 1,
kIOMemoryIncoherentIOStore = 2,
+
+ kIOMemoryClearEncrypted = 50,
+ kIOMemorySetEncrypted = 51,
};
#define IOMEMORYDESCRIPTOR_SUPPORTS_DMACOMMAND 1
+struct IODMAMapSpecification
+{
+ uint64_t alignment;
+ IOService * device;
+ uint32_t options;
+ uint8_t numAddressBits;
+ uint8_t resvA[3];
+ uint32_t resvB[4];
+};
+
+struct IODMAMapPageList
+{
+ uint32_t pageOffset;
+ uint32_t pageListCount;
+ const upl_page_info_t * pageList;
+};
+
+// mapOptions for iovmMapMemory
+enum
+{
+ kIODMAMapReadAccess = 0x00000001,
+ kIODMAMapWriteAccess = 0x00000002,
+ kIODMAMapPhysicallyContiguous = 0x00000010,
+ kIODMAMapDeviceMemory = 0x00000020,
+ kIODMAMapPagingPath = 0x00000040,
+ kIODMAMapIdentityMap = 0x00000080,
+
+ kIODMAMapPageListFullyOccupied = 0x00000100,
+ kIODMAMapFixedAddress = 0x00000200,
+};
+
+#ifdef KERNEL_PRIVATE
+
+// Used for dmaCommandOperation communications for IODMACommand and mappers
+
+enum {
+ kIOMDWalkSegments = 0x01000000,
+ kIOMDFirstSegment = 1 | kIOMDWalkSegments,
+ kIOMDGetCharacteristics = 0x02000000,
+ kIOMDGetCharacteristicsMapped = 1 | kIOMDGetCharacteristics,
+ kIOMDDMAActive = 0x03000000,
+ kIOMDSetDMAActive = 1 | kIOMDDMAActive,
+ kIOMDSetDMAInactive = kIOMDDMAActive,
+ kIOMDAddDMAMapSpec = 0x04000000,
+ kIOMDDMAMap = 0x05000000,
+ kIOMDDMAUnmap = 0x06000000,
+ kIOMDDMACommandOperationMask = 0xFF000000,
+};
+struct IOMDDMACharacteristics {
+ UInt64 fLength;
+ UInt32 fSGCount;
+ UInt32 fPages;
+ UInt32 fPageAlign;
+ ppnum_t fHighestPage;
+ IODirection fDirection;
+ UInt8 fIsPrepared;
+};
+
+struct IOMDDMAMapArgs {
+ IOMapper * fMapper;
+ IODMACommand * fCommand;
+ IODMAMapSpecification fMapSpec;
+ uint64_t fOffset;
+ uint64_t fLength;
+ uint64_t fAlloc;
+ uint64_t fAllocLength;
+ uint8_t fMapContig;
+};
+
+struct IOMDDMAWalkSegmentArgs {
+ UInt64 fOffset; // Input/Output offset
+ UInt64 fIOVMAddr, fLength; // Output variables
+ UInt8 fMapped; // Input Variable, Require mapped IOVMA
+ UInt64 fMappedBase; // Input base of mapping
+};
+typedef UInt8 IOMDDMAWalkSegmentState[128];
+// fMapped:
+enum
+{
+ kIOMDDMAWalkMappedLocal = 2
+};
+
+#endif /* KERNEL_PRIVATE */
+
+enum
+{
+ kIOPreparationIDUnprepared = 0,
+ kIOPreparationIDUnsupported = 1,
+ kIOPreparationIDAlwaysPrepared = 2,
+};
+
+#ifdef XNU_KERNEL_PRIVATE
+struct IOMemoryReference;
+#endif
+
/*! @class IOMemoryDescriptor : public OSObject
@abstract An abstract base class defining common methods for describing physical or virtual memory.
class IOMemoryDescriptor : public OSObject
{
- friend class _IOMemoryMap;
- friend class IOSubMemoryDescriptor;
+ friend class IOMemoryMap;
+ friend class IOMultiMemoryDescriptor;
OSDeclareDefaultStructors(IOMemoryDescriptor);
protected:
-/*! @struct ExpansionData
- @discussion This structure will be used to expand the capablilties of this class in the future.
- */
- struct ExpansionData {
- void * devicePager;
- unsigned int pagerContig:1;
- unsigned int unused:31;
- IOMemoryDescriptor * memory;
- };
/*! @var reserved
Reserved for future use. (Internal use only) */
- ExpansionData * reserved;
+ struct IOMemoryDescriptorReserved * reserved;
protected:
OSSet * _mappings;
IOOptionBits _flags;
- void * _memEntry;
- IODirection _direction; /* DEPRECATED: use _flags instead. direction of transfer */
+
+#ifdef XNU_KERNEL_PRIVATE
+public:
+ struct IOMemoryReference * _memRef;
+ vm_tag_t _kernelTag;
+ vm_tag_t _userTag;
+ int16_t _dmaReferences;
+ uint16_t _internalFlags;
+ kern_allocation_name_t _mapName;
+protected:
+#else /* XNU_KERNEL_PRIVATE */
+ void * __iomd_reserved5;
+ uint16_t __iomd_reserved1[4];
+ uintptr_t __iomd_reserved2;
+#endif /* XNU_KERNEL_PRIVATE */
+
+ uintptr_t __iomd_reserved3;
+ uintptr_t __iomd_reserved4;
+
+#ifndef __LP64__
+ IODirection _direction; /* use _flags instead */
+#endif /* !__LP64__ */
IOByteCount _length; /* length of all ranges */
IOOptionBits _tag;
public:
typedef IOOptionBits DMACommandOps;
+#ifndef __LP64__
virtual IOPhysicalAddress getSourceSegment( IOByteCount offset,
- IOByteCount * length );
- OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 0);
+ IOByteCount * length ) APPLE_KEXT_DEPRECATED;
+#endif /* !__LP64__ */
/*! @function initWithOptions
@abstract Master initialiser for all variants of memory descriptors. For a more complete description see IOMemoryDescriptor::withOptions.
task_t task,
IOOptionBits options,
IOMapper * mapper = kIOMapperSystem);
- OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 1);
+#ifndef __LP64__
virtual addr64_t getPhysicalSegment64( IOByteCount offset,
- IOByteCount * length );
- OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 2);
-
+ IOByteCount * length ) APPLE_KEXT_DEPRECATED; /* use getPhysicalSegment() and kIOMemoryMapperNone instead */
+#endif /* !__LP64__ */
/*! @function setPurgeable
@abstract Control the purgeable status of a memory descriptors memory.
virtual IOReturn setPurgeable( IOOptionBits newState,
IOOptionBits * oldState );
- OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 3);
+
+
+/*! @function getPageCounts
+ @abstract Retrieve the number of resident and/or dirty pages encompassed by an IOMemoryDescriptor.
+ @discussion This method returns the number of resident and/or dirty pages encompassed by an IOMemoryDescriptor.
+ @param residentPageCount - If non-null, a pointer to a byte count that will return the number of resident pages encompassed by this IOMemoryDescriptor.
+ @param dirtyPageCount - If non-null, a pointer to a byte count that will return the number of dirty pages encompassed by this IOMemoryDescriptor.
+ @result An IOReturn code. */
+
+ IOReturn getPageCounts( IOByteCount * residentPageCount,
+ IOByteCount * dirtyPageCount);
/*! @function performOperation
@abstract Perform an operation on the memory descriptor's memory.
virtual IOReturn performOperation( IOOptionBits options,
IOByteCount offset, IOByteCount length );
- OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 4);
-#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
// Used for dedicated communications for IODMACommand
virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
- OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 5);
-#endif
+/*! @function getPhysicalSegment
+ @abstract Break a memory descriptor into its physically contiguous segments.
+ @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.
+ @param offset A byte offset into the memory whose physical address to return.
+ @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
+ @result A physical address, or zero if the offset is beyond the length of the memory. */
+
+#ifdef __LP64__
+ virtual addr64_t getPhysicalSegment( IOByteCount offset,
+ IOByteCount * length,
+ IOOptionBits options = 0 ) = 0;
+#else /* !__LP64__ */
+ virtual addr64_t getPhysicalSegment( IOByteCount offset,
+ IOByteCount * length,
+ IOOptionBits options );
+#endif /* !__LP64__ */
+
+ virtual uint64_t getPreparationID( void );
+ void setPreparationID( void );
+
+#ifdef XNU_KERNEL_PRIVATE
+ IOMemoryDescriptorReserved * getKernelReserved( void );
+ IOReturn dmaMap(
+ IOMapper * mapper,
+ IODMACommand * command,
+ const IODMAMapSpecification * mapSpec,
+ uint64_t offset,
+ uint64_t length,
+ uint64_t * mapAddress,
+ uint64_t * mapLength);
+ IOReturn dmaUnmap(
+ IOMapper * mapper,
+ IODMACommand * command,
+ uint64_t offset,
+ uint64_t mapAddress,
+ uint64_t mapLength);
+ void dmaMapRecord(
+ IOMapper * mapper,
+ IODMACommand * command,
+ uint64_t mapLength);
+
+ void setVMTags(vm_tag_t kernelTag, vm_tag_t userTag);
+ vm_tag_t getVMTag(vm_map_t map);
+#endif
+
private:
-#if (defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
+ OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 0);
+#ifdef __LP64__
+ OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 1);
+ OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 2);
+ OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 3);
+ OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 4);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 5);
-#endif
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 6);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 7);
+#else /* !__LP64__ */
+ OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 1);
+ OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 2);
+ OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 3);
+ OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 4);
+ OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 5);
+ OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 6);
+ OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 7);
+#endif /* !__LP64__ */
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 8);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 9);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 10);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 15);
protected:
- virtual void free();
+ virtual void free() APPLE_KEXT_OVERRIDE;
public:
static void initialize( void );
public:
/*! @function withAddress
@abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
- @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map.
+ @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.
@param address The virtual address of the first byte in the memory.
@param withLength The length of memory.
@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.
IOByteCount withLength,
IODirection withDirection);
-/*! @function withAddress
- @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
- @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.
- @param address The virtual address of the first byte in the memory.
- @param withLength The length of memory.
- @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.
- @param withTask The task the virtual ranges are mapped into.
- @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
-
- static IOMemoryDescriptor * withAddress(vm_address_t address,
+#ifndef __LP64__
+ static IOMemoryDescriptor * withAddress(IOVirtualAddress address,
IOByteCount withLength,
IODirection withDirection,
- task_t withTask);
+ task_t withTask) APPLE_KEXT_DEPRECATED; /* use withAddressRange() and prepare() instead */
+#endif /* !__LP64__ */
/*! @function withPhysicalAddress
@abstract Create an IOMemoryDescriptor to describe one physical range.
IOByteCount withLength,
IODirection withDirection );
-/*! @function withRanges
- @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
- @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.
- @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
- @param withCount The member count of the ranges array.
- @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.
- @param withTask The task each of the virtual ranges are mapped into.
- @param asReference If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.
- @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
-
+#ifndef __LP64__
static IOMemoryDescriptor * withRanges(IOVirtualRange * ranges,
UInt32 withCount,
IODirection withDirection,
task_t withTask,
- bool asReference = false);
+ bool asReference = false) APPLE_KEXT_DEPRECATED; /* use withAddressRanges() instead */
+#endif /* !__LP64__ */
-#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
/*! @function withAddressRange
@abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
- @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.
+ @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.
@param address The virtual address of the first byte in the memory.
- @param withLength The length of memory.
+ @param length The length of memory.
@param options
- 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.
- kIOMemoryNoAutoPrepare Indicates that the temporary AutoPrepare of kernel_task memory should not be performed.
- @param task The task the virtual ranges are mapped into.
+ 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.
+ @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.
@result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
static IOMemoryDescriptor * withAddressRange(
- mach_vm_address_t address,
- mach_vm_size_t length,
- IOOptionBits options,
- task_t task);
+ mach_vm_address_t address,
+ mach_vm_size_t length,
+ IOOptionBits options,
+ task_t task);
/*! @function withAddressRanges
@abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
- @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.
+ @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.
@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.
@param rangeCount The member count of the ranges array.
@param options
- 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.
- 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.
- kIOMemoryNoAutoPrepare Indicates that the temporary AutoPrepare of kernel_task memory should not be performed.
- @param task The task each of the virtual ranges are mapped into.
+ 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.
+ 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.
+ @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.
@result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
static IOMemoryDescriptor * withAddressRanges(
- IOAddressRange * ranges,
- UInt32 rangeCount,
- IOOptionBits options,
- task_t withTask);
-#endif
+ IOAddressRange * ranges,
+ UInt32 rangeCount,
+ IOOptionBits options,
+ task_t task);
/*! @function withOptions
@abstract Master initialiser for all variants of memory descriptors.
- @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. However we temporarily have setup a mechanism that automatically prepares kernel_task memory descriptors at creation time.
+ @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.
- @param buffers A pointer to an array of IOVirtualRanges or IOPhysicalRanges if the options:type is Virtual or Physical. For type UPL it is a upl_t returned by the mach/memory_object_types.h apis, primarily used internally by the UBC.
+ @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.
@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.
@param options
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.
- kIOMemoryTypeMask (options:type) kIOMemoryTypeVirtual, 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.
+ 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.
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.
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.
- kIOMemoryNoAutoPrepare Indicates that the temporary AutoPrepare of kernel_task memory should not be performed.
@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.
IOOptionBits options,
IOMapper * mapper = kIOMapperSystem);
-/*! @function withPhysicalRanges
- @abstract Create an IOMemoryDescriptor to describe one or more physical ranges.
- @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges.
- @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
- @param withCount The member count of the ranges array.
- @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.
- @param asReference If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.
- @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
-
+#ifndef __LP64__
static IOMemoryDescriptor * withPhysicalRanges(
IOPhysicalRange * ranges,
UInt32 withCount,
IODirection withDirection,
- bool asReference = false);
-
-/*! @function withSubRange
- @abstract Create an IOMemoryDescriptor to describe a subrange of an existing descriptor.
- @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a subrange of the specified memory descriptor. The parent memory descriptor is retained by the new descriptor.
- @param of The parent IOMemoryDescriptor of which a subrange is to be used for the new descriptor, which will be retained by the subrange IOMemoryDescriptor.
- @param offset A byte offset into the parent memory descriptor's memory.
- @param length The length of the subrange.
- @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. This is used over the direction of the parent descriptor.
- @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
+ bool asReference = false) APPLE_KEXT_DEPRECATED; /* use withOptions() and kIOMemoryTypePhysical instead */
+#endif /* !__LP64__ */
+#ifndef __LP64__
static IOMemoryDescriptor * withSubRange(IOMemoryDescriptor *of,
IOByteCount offset,
IOByteCount length,
- IODirection withDirection);
+ IODirection withDirection) APPLE_KEXT_DEPRECATED; /* use IOSubMemoryDescriptor::withSubRange() and kIOMemoryThreadSafe instead */
+#endif /* !__LP64__ */
/*! @function withPersistentMemoryDescriptor
@abstract Copy constructor that generates a new memory descriptor if the backing memory for the same task's virtual address and length has changed.
static IOMemoryDescriptor *
withPersistentMemoryDescriptor(IOMemoryDescriptor *originalMD);
-/*! @function initWithAddress
- @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the kernel task.
- @discussion This method initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other IOKit classes, although it is supported here.
- @param address The virtual address of the first byte in the memory.
- @param withLength The length of memory.
- @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.
- @result true on success, false on failure. */
-
+#ifndef __LP64__
+ // obsolete initializers
+ // - initWithOptions is the designated initializer
virtual bool initWithAddress(void * address,
IOByteCount withLength,
- IODirection withDirection) = 0;
-
-/*! @function initWithAddress
- @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the specified map.
- @discussion This method initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other IOKit classes, although it is supported here.
- @param address The virtual address of the first byte in the memory.
- @param withLength The length of memory.
- @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.
- @param withTask The task the virtual ranges are mapped into.
- @result true on success, false on failure. */
-
- virtual bool initWithAddress(vm_address_t address,
+ IODirection withDirection) APPLE_KEXT_DEPRECATED; /* use initWithOptions() instead */
+ virtual bool initWithAddress(IOVirtualAddress address,
IOByteCount withLength,
IODirection withDirection,
- task_t withTask) = 0;
-
-/*! @function initWithPhysicalAddress
- @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one physical range.
- @discussion This method initializes an IOMemoryDescriptor for memory consisting of a single physical memory range. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other IOKit classes, although it is supported here.
- @param address The physical address of the first byte in the memory.
- @param withLength The length of memory.
- @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.
- @result true on success, false on failure. */
-
+ task_t withTask) APPLE_KEXT_DEPRECATED; /* use initWithOptions() instead */
virtual bool initWithPhysicalAddress(
IOPhysicalAddress address,
IOByteCount withLength,
- IODirection withDirection ) = 0;
-
-/*! @function initWithRanges
- @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more virtual ranges.
- @discussion This method initializes an IOMemoryDescriptor for memory consisting of an array of virtual memory ranges each mapped into a specified source task. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other IOKit classes, although it is supported here.
- @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
- @param withCount The member count of the ranges array.
- @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.
- @param withTask The task each of the virtual ranges are mapped into.
- @param asReference If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.
- @result true on success, false on failure. */
-
+ IODirection withDirection ) APPLE_KEXT_DEPRECATED; /* use initWithOptions() instead */
virtual bool initWithRanges(IOVirtualRange * ranges,
UInt32 withCount,
IODirection withDirection,
task_t withTask,
- bool asReference = false) = 0;
-
-/*! @function initWithPhysicalRanges
- @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more physical ranges.
- @discussion This method initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other IOKit classes, although it is supported here.
- @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
- @param withCount The member count of the ranges array.
- @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.
- @param asReference If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.
- @result true on success, false on failure. */
-
+ bool asReference = false) APPLE_KEXT_DEPRECATED; /* use initWithOptions() instead */
virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
UInt32 withCount,
IODirection withDirection,
- bool asReference = false) = 0;
+ bool asReference = false) APPLE_KEXT_DEPRECATED; /* use initWithOptions() instead */
+#endif /* __LP64__ */
/*! @function getDirection
@abstract Accessor to get the direction the memory descriptor was created with.
virtual IOOptionBits getTag( void );
+/*! @function getFlags
+ @abstract Accessor to the retrieve the options the memory descriptor was created with.
+ @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.
+ @result The flags bitfield. */
+
+ uint64_t getFlags(void);
+
/*! @function readBytes
@abstract Copy data from the memory descriptor's buffer to the specified buffer.
- @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.
+ @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.
@param offset A byte offset into the memory descriptor's memory.
@param bytes The caller supplied buffer to copy the data to.
@param withLength The length of the data to copy.
- @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
+ @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. */
virtual IOByteCount readBytes(IOByteCount offset,
void * bytes, IOByteCount withLength);
/*! @function writeBytes
@abstract Copy data to the memory descriptor's buffer from the specified buffer.
- @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer.
+ @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.
@param offset A byte offset into the memory descriptor's memory.
@param bytes The caller supplied buffer to copy the data from.
@param withLength The length of the data to copy.
- @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
+ @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. */
virtual IOByteCount writeBytes(IOByteCount offset,
const void * bytes, IOByteCount withLength);
-/*! @function getPhysicalSegment
- @abstract Break a memory descriptor into its physically contiguous segments.
- @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.
- @param offset A byte offset into the memory whose physical address to return.
- @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
- @result A physical address, or zero if the offset is beyond the length of the memory. */
-
+#ifndef __LP64__
virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
- IOByteCount * length) = 0;
+ IOByteCount * length);
+#endif /* !__LP64__ */
/*! @function getPhysicalAddress
@abstract Return the physical address of the first byte in the memory.
@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.
@result A physical address. */
- /* inline */ IOPhysicalAddress getPhysicalAddress();
- /* { return( getPhysicalSegment( 0, 0 )); } */
+ IOPhysicalAddress getPhysicalAddress();
- /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */
- /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset,
- /* DEPRECATED */ IOByteCount * length) = 0;
- /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */
+#ifndef __LP64__
+ virtual void * getVirtualSegment(IOByteCount offset,
+ IOByteCount * length) APPLE_KEXT_DEPRECATED; /* use map() and getVirtualAddress() instead */
+#endif /* !__LP64__ */
/*! @function prepare
@abstract Prepare the memory for an I/O transfer.
* Mapping functions.
*/
-/*! @function map
+/*! @function createMappingInTask
@abstract Maps a IOMemoryDescriptor into a task.
@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.
@param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space.
kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br>
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>
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>
+ 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>
@param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
@param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
@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. */
+ IOMemoryMap * createMappingInTask(
+ task_t intoTask,
+ mach_vm_address_t atAddress,
+ IOOptionBits options,
+ mach_vm_size_t offset = 0,
+ mach_vm_size_t length = 0 );
+
+#ifndef __LP64__
virtual IOMemoryMap * map(
task_t intoTask,
IOVirtualAddress atAddress,
IOOptionBits options,
IOByteCount offset = 0,
- IOByteCount length = 0 );
+ IOByteCount length = 0 ) APPLE_KEXT_DEPRECATED; /* use createMappingInTask() instead */
+#endif /* !__LP64__ */
/*! @function map
@abstract Maps a IOMemoryDescriptor into the kernel map.
- @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 map method for further details.
- @param options Mapping options as in the full version of the map method, with kIOMapAnywhere assumed.
- @result See the full version of the map method. */
+ @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.
+ @param options Mapping options as in the full version of the createMappingInTask method, with kIOMapAnywhere assumed.
+ @result See the full version of the createMappingInTask method. */
virtual IOMemoryMap * map(
IOOptionBits options = 0 );
// Following methods are private implementation
- // make virtual
+#ifdef __LP64__
+ virtual
+#endif /* __LP64__ */
IOReturn redirect( task_t safeTask, bool redirect );
IOReturn handleFault(
+ void * _pager,
+ mach_vm_size_t sourceOffset,
+ mach_vm_size_t length);
+
+ IOReturn populateDevicePager(
void * pager,
vm_map_t addressMap,
- IOVirtualAddress address,
- IOByteCount sourceOffset,
- IOByteCount length,
+ mach_vm_address_t address,
+ mach_vm_size_t sourceOffset,
+ mach_vm_size_t length,
IOOptionBits options );
-protected:
virtual IOMemoryMap * makeMapping(
IOMemoryDescriptor * owner,
- task_t intoTask,
+ task_t intoTask,
IOVirtualAddress atAddress,
IOOptionBits options,
IOByteCount offset,
IOByteCount length );
+protected:
virtual void addMapping(
IOMemoryMap * mapping );
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*! @class IOMemoryMap : public OSObject
- @abstract An abstract base class defining common methods for describing a memory mapping.
+ @abstract A class defining common methods for describing a memory mapping.
@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. */
class IOMemoryMap : public OSObject
{
- OSDeclareAbstractStructors(IOMemoryMap)
+ OSDeclareDefaultStructors(IOMemoryMap)
+#ifdef XNU_KERNEL_PRIVATE
+public:
+ IOMemoryDescriptor * fMemory;
+ IOMemoryMap * fSuperMap;
+ mach_vm_size_t fOffset;
+ mach_vm_address_t fAddress;
+ mach_vm_size_t fLength;
+ task_t fAddressTask;
+ vm_map_t fAddressMap;
+ IOOptionBits fOptions;
+ upl_t fRedirUPL;
+ ipc_port_t fRedirEntry;
+ IOMemoryDescriptor * fOwner;
+ uint8_t fUserClientUnmap;
+#if IOTRACKING
+ IOTrackingUser fTracking;
+#endif
+#endif /* XNU_KERNEL_PRIVATE */
+
+protected:
+ virtual void taggedRelease(const void *tag = 0) const APPLE_KEXT_OVERRIDE;
+ virtual void free() APPLE_KEXT_OVERRIDE;
public:
/*! @function getVirtualAddress
@abstract Accessor to the virtual address of the first byte in the mapping.
- @discussion This method returns the virtual address of the first byte in the mapping.
+ @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.
@result A virtual address. */
- virtual IOVirtualAddress getVirtualAddress() = 0;
+ virtual IOVirtualAddress getVirtualAddress();
/*! @function getPhysicalSegment
@abstract Break a mapping into its physically contiguous segments.
@param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
@result A physical address, or zero if the offset is beyond the length of the mapping. */
+#ifdef __LP64__
+ virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
+ IOByteCount * length,
+ IOOptionBits options = 0);
+#else /* !__LP64__ */
virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
- IOByteCount * length) = 0;
+ IOByteCount * length);
+#endif /* !__LP64__ */
/*! @function getPhysicalAddress
@abstract Return the physical address of the first byte in the mapping.
@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.
@result A physical address. */
- /* inline */ IOPhysicalAddress getPhysicalAddress();
- /* { return( getPhysicalSegment( 0, 0 )); } */
+ IOPhysicalAddress getPhysicalAddress();
/*! @function getLength
@abstract Accessor to the length of the mapping.
@discussion This method returns the length of the mapping.
@result A byte count. */
- virtual IOByteCount getLength() = 0;
+ virtual IOByteCount getLength();
/*! @function getAddressTask
@abstract Accessor to the task of the mapping.
@discussion This method returns the mach task the mapping exists in.
@result A mach task_t. */
- virtual task_t getAddressTask() = 0;
+ virtual task_t getAddressTask();
/*! @function getMemoryDescriptor
@abstract Accessor to the IOMemoryDescriptor the mapping was created from.
@discussion This method returns the IOMemoryDescriptor the mapping was created from.
@result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */
- virtual IOMemoryDescriptor * getMemoryDescriptor() = 0;
+ virtual IOMemoryDescriptor * getMemoryDescriptor();
/*! @function getMapOptions
@abstract Accessor to the options the mapping was created with.
@discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with.
@result Options for the mapping, including cache settings. */
- virtual IOOptionBits getMapOptions() = 0;
+ virtual IOOptionBits getMapOptions();
/*! @function unmap
@abstract Force the IOMemoryMap to unmap, without destroying the object.
@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.
@result An IOReturn code. */
- virtual IOReturn unmap() = 0;
+ virtual IOReturn unmap();
- virtual void taskDied() = 0;
+ virtual void taskDied();
/*! @function redirect
@abstract Replace the memory mapped in a process with new backing memory.
@param offset As with IOMemoryDescriptor::map(), a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default.
@result An IOReturn code. */
+#ifndef __LP64__
+// For 32 bit XNU, there is a 32 bit (IOByteCount) and a 64 bit (mach_vm_size_t) interface;
+// for 64 bit, these fall together on the 64 bit one.
virtual IOReturn redirect(IOMemoryDescriptor * newBackingMemory,
IOOptionBits options,
- IOByteCount offset = 0) = 0;
+ IOByteCount offset = 0);
+#endif
+ virtual IOReturn redirect(IOMemoryDescriptor * newBackingMemory,
+ IOOptionBits options,
+ mach_vm_size_t offset = 0);
+
+#ifdef __LP64__
+/*! @function getAddress
+ @abstract Accessor to the virtual address of the first byte in the mapping.
+ @discussion This method returns the virtual address of the first byte in the mapping.
+ @result A virtual address. */
+ inline mach_vm_address_t getAddress() __attribute__((always_inline));
+/*! @function getSize
+ @abstract Accessor to the length of the mapping.
+ @discussion This method returns the length of the mapping.
+ @result A byte count. */
+ inline mach_vm_size_t getSize() __attribute__((always_inline));
+#else /* !__LP64__ */
+/*! @function getAddress
+ @abstract Accessor to the virtual address of the first byte in the mapping.
+ @discussion This method returns the virtual address of the first byte in the mapping.
+ @result A virtual address. */
+ virtual mach_vm_address_t getAddress();
+/*! @function getSize
+ @abstract Accessor to the length of the mapping.
+ @discussion This method returns the length of the mapping.
+ @result A byte count. */
+ virtual mach_vm_size_t getSize();
+#endif /* !__LP64__ */
+
+#ifdef XNU_KERNEL_PRIVATE
+ // for IOMemoryDescriptor use
+ IOMemoryMap * copyCompatible( IOMemoryMap * newMapping );
+
+ bool init(
+ task_t intoTask,
+ mach_vm_address_t toAddress,
+ IOOptionBits options,
+ mach_vm_size_t offset,
+ mach_vm_size_t length );
+
+ bool setMemoryDescriptor(IOMemoryDescriptor * _memory, mach_vm_size_t _offset);
+
+ IOReturn redirect(
+ task_t intoTask, bool redirect );
+
+ IOReturn userClientUnmap();
+#endif /* XNU_KERNEL_PRIVATE */
+
+ IOReturn wireRange(
+ uint32_t options,
+ mach_vm_size_t offset,
+ mach_vm_size_t length);
+
+ OSMetaClassDeclareReservedUnused(IOMemoryMap, 0);
+ OSMetaClassDeclareReservedUnused(IOMemoryMap, 1);
+ OSMetaClassDeclareReservedUnused(IOMemoryMap, 2);
+ OSMetaClassDeclareReservedUnused(IOMemoryMap, 3);
+ OSMetaClassDeclareReservedUnused(IOMemoryMap, 4);
+ OSMetaClassDeclareReservedUnused(IOMemoryMap, 5);
+ OSMetaClassDeclareReservedUnused(IOMemoryMap, 6);
+ OSMetaClassDeclareReservedUnused(IOMemoryMap, 7);
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+#ifdef XNU_KERNEL_PRIVATE
+// Also these flags should not overlap with the options to
+// IOMemoryDescriptor::initWithRanges(... IOOptionsBits options);
+enum {
+ _kIOMemorySourceSegment = 0x00002000
+};
+#endif /* XNU_KERNEL_PRIVATE */
// The following classes are private implementation of IOMemoryDescriptor - they
// should not be referenced directly, just through the public API's in the
// IOMemoryDescriptor class. For example, an IOGeneralMemoryDescriptor instance
-// might be created by IOMemoryDescriptor::withAddress(), but there should be
+// might be created by IOMemoryDescriptor::withAddressRange(), but there should be
// no need to reference as anything but a generic IOMemoryDescriptor *.
-// Also these flags should not overlap with the options to
-// IOMemoryDescriptor::initWithRanges(... IOOptionsBits options);
-
-enum {
- kIOMemoryPreparedReadOnly = 0x00008000,
-};
-
class IOGeneralMemoryDescriptor : public IOMemoryDescriptor
{
OSDeclareDefaultStructors(IOGeneralMemoryDescriptor);
protected:
Ranges _ranges;
unsigned _rangesCount; /* number of address ranges in list */
+#ifndef __LP64__
bool _rangesIsAllocated; /* is list allocated by us? */
+#endif /* !__LP64__ */
task_t _task; /* task where all ranges are mapped to */
unsigned _wireCount; /* number of outstanding wires */
- /* DEPRECATED */ vm_address_t _cachedVirtualAddress; /* a cached virtual-to-physical */
+#ifndef __LP64__
+ uintptr_t _cachedVirtualAddress;
- /* DEPRECATED */ IOPhysicalAddress _cachedPhysicalAddress;
+ IOPhysicalAddress _cachedPhysicalAddress;
+#endif /* !__LP64__ */
bool _initialized; /* has superclass been initialized? */
- virtual void free();
+public:
+ virtual void free() APPLE_KEXT_OVERRIDE;
-#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
- virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
-#endif
+ virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const APPLE_KEXT_OVERRIDE;
-private:
-
- /* DEPRECATED */ virtual void setPosition(IOByteCount position);
- /* DEPRECATED */ virtual void mapIntoKernel(unsigned rangeIndex);
- /* DEPRECATED */ virtual void unmapFromKernel();
+ virtual uint64_t getPreparationID( void ) APPLE_KEXT_OVERRIDE;
+#ifdef XNU_KERNEL_PRIVATE
// Internal APIs may be made virtual at some time in the future.
IOReturn wireVirtual(IODirection forDirection);
- void *createNamedEntry();
+ IOReturn dmaMap(
+ IOMapper * mapper,
+ IODMACommand * command,
+ const IODMAMapSpecification * mapSpec,
+ uint64_t offset,
+ uint64_t length,
+ uint64_t * mapAddress,
+ uint64_t * mapLength);
+ bool initMemoryEntries(size_t size, IOMapper * mapper);
+
+ IOMemoryReference * memoryReferenceAlloc(uint32_t capacity,
+ IOMemoryReference * realloc);
+ void memoryReferenceFree(IOMemoryReference * ref);
+ void memoryReferenceRelease(IOMemoryReference * ref);
+
+ IOReturn memoryReferenceCreate(
+ IOOptionBits options,
+ IOMemoryReference ** reference);
+
+ IOReturn memoryReferenceMap(IOMemoryReference * ref,
+ vm_map_t map,
+ mach_vm_size_t inoffset,
+ mach_vm_size_t size,
+ IOOptionBits options,
+ mach_vm_address_t * inaddr);
+
+ static IOReturn memoryReferenceSetPurgeable(
+ IOMemoryReference * ref,
+ IOOptionBits newState,
+ IOOptionBits * oldState);
+ static IOReturn memoryReferenceGetPageCounts(
+ IOMemoryReference * ref,
+ IOByteCount * residentPageCount,
+ IOByteCount * dirtyPageCount);
+#endif
+
+private:
+
+#ifndef __LP64__
+ virtual void setPosition(IOByteCount position);
+ virtual void mapIntoKernel(unsigned rangeIndex);
+ virtual void unmapFromKernel();
+#endif /* !__LP64__ */
// Internal
OSData * _memoryEntries;
ppnum_t _highestPage;
uint32_t __iomd_reservedA;
uint32_t __iomd_reservedB;
- uint32_t __iomd_reservedC;
+
+ IOLock * _prepareLock;
public:
/*
UInt32 offset,
task_t task,
IOOptionBits options,
- IOMapper * mapper = kIOMapperSystem);
+ IOMapper * mapper = kIOMapperSystem) APPLE_KEXT_OVERRIDE;
+#ifndef __LP64__
// Secondary initialisers
virtual bool initWithAddress(void * address,
IOByteCount withLength,
- IODirection withDirection);
+ IODirection withDirection) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
- virtual bool initWithAddress(vm_address_t address,
+ virtual bool initWithAddress(IOVirtualAddress address,
IOByteCount withLength,
IODirection withDirection,
- task_t withTask);
+ task_t withTask) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
virtual bool initWithPhysicalAddress(
IOPhysicalAddress address,
IOByteCount withLength,
- IODirection withDirection );
+ IODirection withDirection ) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
virtual bool initWithRanges( IOVirtualRange * ranges,
UInt32 withCount,
IODirection withDirection,
task_t withTask,
- bool asReference = false);
+ bool asReference = false) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
UInt32 withCount,
IODirection withDirection,
- bool asReference = false);
+ bool asReference = false) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
-#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
virtual addr64_t getPhysicalSegment64( IOByteCount offset,
- IOByteCount * length );
-#endif
+ IOByteCount * length ) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
- IOByteCount * length);
+ IOByteCount * length) APPLE_KEXT_OVERRIDE;
virtual IOPhysicalAddress getSourceSegment(IOByteCount offset,
- IOByteCount * length);
+ IOByteCount * length) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
- /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset,
- /* DEPRECATED */ IOByteCount * length);
+ virtual void * getVirtualSegment(IOByteCount offset,
+ IOByteCount * length) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
+#endif /* !__LP64__ */
- virtual IOReturn prepare(IODirection forDirection = kIODirectionNone);
+ virtual IOReturn setPurgeable( IOOptionBits newState,
+ IOOptionBits * oldState ) APPLE_KEXT_OVERRIDE;
+
+ virtual addr64_t getPhysicalSegment( IOByteCount offset,
+ IOByteCount * length,
+#ifdef __LP64__
+ IOOptionBits options = 0 ) APPLE_KEXT_OVERRIDE;
+#else /* !__LP64__ */
+ IOOptionBits options ) APPLE_KEXT_OVERRIDE;
+#endif /* !__LP64__ */
- virtual IOReturn complete(IODirection forDirection = kIODirectionNone);
+ virtual IOReturn prepare(IODirection forDirection = kIODirectionNone) APPLE_KEXT_OVERRIDE;
+
+ virtual IOReturn complete(IODirection forDirection = kIODirectionNone) APPLE_KEXT_OVERRIDE;
virtual IOReturn doMap(
vm_map_t addressMap,
IOVirtualAddress * atAddress,
IOOptionBits options,
IOByteCount sourceOffset = 0,
- IOByteCount length = 0 );
+ IOByteCount length = 0 ) APPLE_KEXT_OVERRIDE;
virtual IOReturn doUnmap(
vm_map_t addressMap,
IOVirtualAddress logical,
- IOByteCount length );
- virtual bool serialize(OSSerialize *s) const;
+ IOByteCount length ) APPLE_KEXT_OVERRIDE;
+
+ virtual bool serialize(OSSerialize *s) const APPLE_KEXT_OVERRIDE;
// Factory method for cloning a persistent IOMD, see IOMemoryDescriptor
static IOMemoryDescriptor *
withPersistentMemoryDescriptor(IOGeneralMemoryDescriptor *originalMD);
+
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-class IOSubMemoryDescriptor : public IOMemoryDescriptor
+#ifdef __LP64__
+mach_vm_address_t IOMemoryMap::getAddress()
{
- friend class IOMemoryDescriptor;
-
- OSDeclareDefaultStructors(IOSubMemoryDescriptor);
-
-protected:
- IOMemoryDescriptor * _parent;
- IOByteCount _start;
-
- virtual void free();
-
- virtual bool initWithAddress(void * address,
- IOByteCount withLength,
- IODirection withDirection);
-
- virtual bool initWithAddress(vm_address_t address,
- IOByteCount withLength,
- IODirection withDirection,
- task_t withTask);
-
- virtual bool initWithPhysicalAddress(
- IOPhysicalAddress address,
- IOByteCount withLength,
- IODirection withDirection );
-
- virtual bool initWithRanges( IOVirtualRange * ranges,
- UInt32 withCount,
- IODirection withDirection,
- task_t withTask,
- bool asReference = false);
-
- virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
- UInt32 withCount,
- IODirection withDirection,
- bool asReference = false);
-
- IOMemoryDescriptor::withAddress;
- IOMemoryDescriptor::withPhysicalAddress;
- IOMemoryDescriptor::withPhysicalRanges;
- IOMemoryDescriptor::withRanges;
- IOMemoryDescriptor::withSubRange;
-
-#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
- // used by IODMACommand
- virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
-#endif
-
-public:
- /*
- * Initialize or reinitialize an IOSubMemoryDescriptor to describe
- * a subrange of an existing descriptor.
- *
- * An IOSubMemoryDescriptor can be re-used by calling initSubRange
- * again on an existing instance -- note that this behavior is not
- * commonly supported in other IOKit classes, although it is here.
- */
- virtual bool initSubRange( IOMemoryDescriptor * parent,
- IOByteCount offset, IOByteCount length,
- IODirection withDirection );
+ return (getVirtualAddress());
+}
- /*
- * IOMemoryDescriptor required methods
- */
-
-#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
- virtual addr64_t getPhysicalSegment64( IOByteCount offset,
- IOByteCount * length );
-#endif
-
- virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
- IOByteCount * length);
-
- virtual IOPhysicalAddress getSourceSegment(IOByteCount offset,
- IOByteCount * length);
-
- virtual IOByteCount readBytes(IOByteCount offset,
- void * bytes, IOByteCount withLength);
-
- virtual IOByteCount writeBytes(IOByteCount offset,
- const void * bytes, IOByteCount withLength);
-
- virtual void * getVirtualSegment(IOByteCount offset,
- IOByteCount * length);
-
- virtual IOReturn prepare(IODirection forDirection = kIODirectionNone);
-
- virtual IOReturn complete(IODirection forDirection = kIODirectionNone);
-
- // make virtual
- IOReturn redirect( task_t safeTask, bool redirect );
-
- virtual bool serialize(OSSerialize *s) const;
-
- virtual IOReturn setPurgeable( IOOptionBits newState,
- IOOptionBits * oldState );
- virtual IOReturn performOperation( IOOptionBits options,
- IOByteCount offset, IOByteCount length );
-
-protected:
- virtual IOMemoryMap * makeMapping(
- IOMemoryDescriptor * owner,
- task_t intoTask,
- IOVirtualAddress atAddress,
- IOOptionBits options,
- IOByteCount offset,
- IOByteCount length );
-
- virtual IOReturn doMap(
- vm_map_t addressMap,
- IOVirtualAddress * atAddress,
- IOOptionBits options,
- IOByteCount sourceOffset = 0,
- IOByteCount length = 0 );
-};
+mach_vm_size_t IOMemoryMap::getSize()
+{
+ return (getLength());
+}
+#else /* !__LP64__ */
+#include <IOKit/IOSubMemoryDescriptor.h>
+#endif /* !__LP64__ */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */