X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/e5568f75972dfc723778653c11cb6b4dc825716a..bd504ef0e0b883cdd7917b73b3574eb9ce669905:/iokit/IOKit/IOMemoryDescriptor.h diff --git a/iokit/IOKit/IOMemoryDescriptor.h b/iokit/IOKit/IOMemoryDescriptor.h index 322a2760b..a44ce6f40 100644 --- a/iokit/IOKit/IOMemoryDescriptor.h +++ b/iokit/IOKit/IOMemoryDescriptor.h @@ -1,23 +1,29 @@ /* * Copyright (c) 1998-2000 Apple Computer, 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 @@ -25,25 +31,23 @@ #include #include +#include #include -__BEGIN_DECLS #include -__END_DECLS - -struct IOPhysicalRange -{ - IOPhysicalAddress address; - IOByteCount length; -}; class IOMemoryMap; class IOMapper; +class IOService; /* * 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 @@ -51,75 +55,134 @@ enum IODirection kIODirectionOutIn = kIODirectionOut | kIODirectionIn, kIODirectionInOut = kIODirectionIn | kIODirectionOut }; +#ifdef __LP64__ +typedef IOOptionBits IODirection; +#endif /* __LP64__ */ /* - * IOOptionBits used in the second withRanges variant + * 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, +#ifdef XNU_KERNEL_PRIVATE + kIOMemoryReserved6156215 = 0x00020000, +#endif + kIOMemoryThreadSafe = 0x00100000, // Shared with Buffer MD + kIOMemoryClearEncrypt = 0x00200000, // Shared with Buffer MD }; -#define kIOMapperNone ((IOMapper *) -1) #define kIOMapperSystem ((IOMapper *) 0) +enum +{ + kIOMemoryPurgeableKeepCurrent = 1, + kIOMemoryPurgeableNonVolatile = 2, + kIOMemoryPurgeableVolatile = 3, + kIOMemoryPurgeableEmpty = 4 +}; +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]; +}; + +enum +{ + kIODMAMapWriteAccess = 0x00000002, + kIODMAMapPhysicallyContiguous = 0x00000010, + kIODMAMapDeviceMemory = 0x00000020, + kIODMAMapPagingPath = 0x00000040, + kIODMAMapIdentityMap = 0x00000080, +}; + + +enum +{ + kIOPreparationIDUnprepared = 0, + kIOPreparationIDUnsupported = 1, + kIOPreparationIDAlwaysPrepared = 2, +}; + /*! @class IOMemoryDescriptor : public OSObject @abstract An abstract base class defining common methods for describing physical or virtual memory. @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. */ class IOMemoryDescriptor : public OSObject { - friend class _IOMemoryMap; - friend class IOSubMemoryDescriptor; + friend class IOMemoryMap; 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 __LP64__ + uint64_t __iomd_reserved1; + uint64_t __iomd_reserved2; + uint64_t __iomd_reserved3; + uint64_t __iomd_reserved4; +#else /* !__LP64__ */ + IODirection _direction; /* use _flags instead */ +#endif /* !__LP64__ */ IOByteCount _length; /* length of all ranges */ IOOptionBits _tag; public: - -/*! @function getBackingID - @abstract Get an unique identifier for the virtual memory systems backing memory object. - @discussion For memory descriptors that are directly mapped by real memory, IOGeneralMemoryDescriptors that are also persistent (kIOMemoryPersistent) return the id of the backing vm object. This returned value can be tested to see if 2 memory persistent memory descriptors share the same backing. The call itself is fairly heavy weight and can only be applied to persistent memory descriptors so it is not generally useful. This function is NOT virtual at the moment. We may choose to make it virtual in the future however. - @result 0 on non-persistent or non IOGeneralMemoryDescriptors, unique id if not. */ - // See implementation at end of file - inline void * getBackingID() const; - +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. @@ -130,20 +193,96 @@ public: UInt32 offset, task_t task, IOOptionBits options, - IOMapper * mapper = 0); - OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 1); + IOMapper * mapper = kIOMapperSystem); + +#ifndef __LP64__ + virtual addr64_t getPhysicalSegment64( IOByteCount offset, + IOByteCount * length ) APPLE_KEXT_DEPRECATED; /* use getPhysicalSegment() and kIOMemoryMapperNone instead */ +#endif /* !__LP64__ */ + +/*! @function setPurgeable + @abstract Control the purgeable status of a memory descriptors memory. + @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. + @param newState - the desired new purgeable state of the memory:
+ kIOMemoryPurgeableKeepCurrent - make no changes to the memory's purgeable state.
+ kIOMemoryPurgeableVolatile - make the memory volatile - the memory may be reclaimed by the VM system without saving its contents to backing store.
+ kIOMemoryPurgeableNonVolatile - make the memory nonvolatile - the memory is treated as with usual allocations and must be saved to backing store if paged.
+ kIOMemoryPurgeableEmpty - make the memory volatile, and discard any pages allocated to it. + @param oldState - if non-NULL, the previous purgeable state of the memory is returned here:
+ kIOMemoryPurgeableNonVolatile - the memory was nonvolatile.
+ kIOMemoryPurgeableVolatile - the memory was volatile but its content has not been discarded by the VM system.
+ kIOMemoryPurgeableEmpty - the memory was volatile and has been discarded by the VM system.
+ @result An IOReturn code. */ - virtual addr64_t IOMemoryDescriptor::getPhysicalSegment64( IOByteCount offset, - IOByteCount * length ); - OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 2); + virtual IOReturn setPurgeable( IOOptionBits newState, + IOOptionBits * oldState ); -private: +/*! @function performOperation + @abstract Perform an operation on the memory descriptor's memory. + @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. + @param options The operation to perform on the memory:
+ 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.
+ 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. + @param offset A byte offset into the memory descriptor's memory. + @param length The length of the data range. + @result An IOReturn code. */ + + virtual IOReturn performOperation( IOOptionBits options, + IOByteCount offset, IOByteCount length ); + // Used for dedicated communications for IODMACommand + virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const; + +/*! @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, + const IODMAMapSpecification * mapSpec, + uint64_t offset, + uint64_t length, + uint64_t * address, + ppnum_t * mapPages); +#endif + +private: + OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 0); +#ifdef __LP64__ + OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 1); + OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 2); OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 3); OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 4); OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 5); 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); @@ -161,7 +300,7 @@ public: 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. @@ -171,19 +310,12 @@ public: 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. @@ -198,28 +330,53 @@ public: 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__ */ + +/*! @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. 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 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. + @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); + +/*! @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. 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. + @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 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. @@ -229,10 +386,9 @@ public: @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. @@ -243,105 +399,55 @@ public: UInt32 offset, task_t task, IOOptionBits options, - IOMapper * mapper = 0); - -/*! @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. */ + IOMapper * mapper = kIOMapperSystem); +#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); - -/*! @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. */ - + 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. + @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. + @param originalMD The memory descriptor to be duplicated. + @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. */ + static IOMemoryDescriptor * + withPersistentMemoryDescriptor(IOMemoryDescriptor *originalMD); + +#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. @@ -373,48 +479,42 @@ public: /*! @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. @@ -436,7 +536,7 @@ public: * 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. @@ -447,22 +547,32 @@ public: kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.
kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.
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.
+ 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.
@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 ); @@ -482,26 +592,28 @@ public: // Following methods are private implementation - // make virtual +#ifdef __LP64__ + virtual +#endif /* __LP64__ */ IOReturn redirect( task_t safeTask, bool redirect ); IOReturn handleFault( 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 ); @@ -524,20 +636,39 @@ protected: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /*! @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; +#endif /* XNU_KERNEL_PRIVATE */ + +protected: + virtual void taggedRelease(const void *tag = 0) const; + virtual void free(); 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. @@ -546,81 +677,168 @@ public: @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(); + +/*! @function redirect + @abstract Replace the memory mapped in a process with new backing memory. + @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. + @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. + @param options Mapping options are defined in IOTypes.h, and are documented in IOMemoryDescriptor::map() + @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); +#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. */ +/*! @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_address_t getAddress() __attribute__((always_inline)); + 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. */ +/*! @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_address_t getAddress(); + virtual mach_vm_size_t getSize(); +#endif /* !__LP64__ */ + +#ifdef XNU_KERNEL_PRIVATE + // for IOMemoryDescriptor use + IOMemoryMap * copyCompatible( IOMemoryMap * newMapping ); - virtual void taskDied() = 0; + 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); +public: + union Ranges { + IOVirtualRange *v; + IOAddressRange *v64; + IOPhysicalRange *p; + void *uio; + }; protected: - union { - IOVirtualRange * v; - IOPhysicalRange * p; - } _ranges; /* list of address ranges */ + 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 */ @@ -631,94 +849,116 @@ protected: 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? */ +public: virtual void free(); + virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const; -private: - // Internal API may be made virtual at some time in the future. - IOReturn wireVirtual(IODirection forDirection); + virtual uint64_t getPreparationID( void ); - /* DEPRECATED */ IOByteCount _position; /* absolute position over all ranges */ - /* DEPRECATED */ virtual void setPosition(IOByteCount position); +#ifdef XNU_KERNEL_PRIVATE + // Internal APIs may be made virtual at some time in the future. + IOReturn wireVirtual(IODirection forDirection); + IOReturn dmaMap( + IOMapper * mapper, + const IODMAMapSpecification * mapSpec, + uint64_t offset, + uint64_t length, + uint64_t * address, + ppnum_t * mapPages); + bool initMemoryEntries(size_t size, IOMapper * mapper); +#endif -/* - * DEPRECATED IOByteCount _positionAtIndex; // relative position within range #n - * - * Re-use the _positionAtIndex as a count of the number of pages in - * this memory descriptor. Convieniently vm_address_t is an unsigned integer - * type so I can get away without having to change the type. - */ - unsigned int _pages; +private: -/* DEPRECATED */ unsigned _positionAtOffset; //range #n in which position is now +#ifndef __LP64__ + virtual void setPosition(IOByteCount position); + virtual void mapIntoKernel(unsigned rangeIndex); + virtual void unmapFromKernel(); +#endif /* !__LP64__ */ - OSData *_memoryEntries; + void *createNamedEntry(); - /* DEPRECATED */ vm_offset_t _kernPtrAligned; - /* DEPRECATED */ unsigned _kernPtrAtIndex; - /* DEPRECATED */ IOByteCount _kernSize; + // Internal + OSData * _memoryEntries; + unsigned int _pages; + ppnum_t _highestPage; + uint32_t __iomd_reservedA; + uint32_t __iomd_reservedB; - /* DEPRECATED */ virtual void mapIntoKernel(unsigned rangeIndex); - /* DEPRECATED */ virtual void unmapFromKernel(); + IOLock * _prepareLock; public: /* * IOMemoryDescriptor required methods */ -/*! @function getBackingID - @abstract Returns the vm systems unique id for the memory backing this IOGeneralMemoryDescriptor. See IOMemoryDescriptor::getBackingID for details. - @result 0 on non-persistent or non IOGeneralMemoryDescriptors, unique id if not. */ - void * getBackingID() const; - // Master initaliser virtual bool initWithOptions(void * buffers, UInt32 count, UInt32 offset, task_t task, IOOptionBits options, - IOMapper * mapper = 0); + IOMapper * mapper = kIOMapperSystem); +#ifndef __LP64__ // Secondary initialisers virtual bool initWithAddress(void * address, IOByteCount withLength, - IODirection withDirection); + IODirection withDirection) 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_DEPRECATED; virtual bool initWithPhysicalAddress( IOPhysicalAddress address, IOByteCount withLength, - IODirection withDirection ); + IODirection withDirection ) APPLE_KEXT_DEPRECATED; virtual bool initWithRanges( IOVirtualRange * ranges, UInt32 withCount, IODirection withDirection, task_t withTask, - bool asReference = false); + bool asReference = false) APPLE_KEXT_DEPRECATED; virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges, UInt32 withCount, IODirection withDirection, - bool asReference = false); + bool asReference = false) APPLE_KEXT_DEPRECATED; + + virtual addr64_t getPhysicalSegment64( IOByteCount offset, + IOByteCount * length ) APPLE_KEXT_DEPRECATED; virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset, IOByteCount * length); virtual IOPhysicalAddress getSourceSegment(IOByteCount offset, - IOByteCount * length); + IOByteCount * length) APPLE_KEXT_DEPRECATED; + + virtual void * getVirtualSegment(IOByteCount offset, + IOByteCount * length) APPLE_KEXT_DEPRECATED; +#endif /* !__LP64__ */ + + virtual IOReturn setPurgeable( IOOptionBits newState, + IOOptionBits * oldState ); - /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset, - /* DEPRECATED */ IOByteCount * length); + virtual addr64_t getPhysicalSegment( IOByteCount offset, + IOByteCount * length, +#ifdef __LP64__ + IOOptionBits options = 0 ); +#else /* !__LP64__ */ + IOOptionBits options ); +#endif /* !__LP64__ */ virtual IOReturn prepare(IODirection forDirection = kIODirectionNone); @@ -735,117 +975,31 @@ public: vm_map_t addressMap, IOVirtualAddress logical, IOByteCount length ); - virtual bool serialize(OSSerialize *s) const; -}; - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -class IOSubMemoryDescriptor : public IOMemoryDescriptor -{ - 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; - -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 ); - - /* - * IOMemoryDescriptor required methods - */ - - 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; -protected: - virtual IOMemoryMap * makeMapping( - IOMemoryDescriptor * owner, - task_t intoTask, - IOVirtualAddress atAddress, - IOOptionBits options, - IOByteCount offset, - IOByteCount length ); + // Factory method for cloning a persistent IOMD, see IOMemoryDescriptor + static IOMemoryDescriptor * + withPersistentMemoryDescriptor(IOGeneralMemoryDescriptor *originalMD); + }; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -// Implementation of inline functions -void * IOMemoryDescriptor::getBackingID() const +#ifdef __LP64__ +mach_vm_address_t IOMemoryMap::getAddress() { - const IOGeneralMemoryDescriptor *genMD = (const IOGeneralMemoryDescriptor *) - OSDynamicCast(IOGeneralMemoryDescriptor, this); + return (getVirtualAddress()); +} - if (genMD) - return genMD->getBackingID(); - else - return 0; +mach_vm_size_t IOMemoryMap::getSize() +{ + return (getLength()); } +#else /* !__LP64__ */ +#include +#endif /* !__LP64__ */ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #endif /* !_IOMEMORYDESCRIPTOR_H */