#include <sys/cdefs.h>
#include <IOKit/IOTypes.h>
+#include <IOKit/IOLocks.h>
#include <libkern/c++/OSContainers.h>
__BEGIN_DECLS
kIOMemoryTypeUPL = 0x00000030,
kIOMemoryTypePersistentMD = 0x00000040, // Persistent Memory Descriptor
kIOMemoryTypeUIO = 0x00000050,
+ kIOMemoryTypeVirtual64 = 0x00000060,
+ kIOMemoryTypePhysical64 = 0x00000070,
kIOMemoryTypeMask = 0x000000f0,
kIOMemoryAsReference = 0x00000100,
kIOMemoryBufferPageable = 0x00000400,
kIOMemoryDontMap = 0x00000800,
- kIOMemoryPersistent = 0x00010000
+ kIOMemoryPersistent = 0x00010000,
+ kIOMemoryThreadSafe = 0x00020000
};
#define kIOMapperNone ((IOMapper *) -1)
kIOMemoryIncoherentIOStore = 2,
};
+#define IOMEMORYDESCRIPTOR_SUPPORTS_DMACOMMAND 1
+
+
/*! @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. */
IOOptionBits _tag;
public:
-
+typedef IOOptionBits DMACommandOps;
virtual IOPhysicalAddress getSourceSegment( IOByteCount offset,
IOByteCount * length );
OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 0);
UInt32 offset,
task_t task,
IOOptionBits options,
- IOMapper * mapper = 0);
+ IOMapper * mapper = kIOMapperSystem);
OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 1);
virtual addr64_t getPhysicalSegment64( IOByteCount offset,
IOByteCount offset, IOByteCount length );
OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 4);
-private:
+ // Used for dedicated communications for IODMACommand
+ virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
+ OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 5);
- OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 5);
+private:
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 6);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 7);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 8);
task_t withTask,
bool asReference = false);
+/*! @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. Note that unlike IOMemoryDescriptor::withAddress(), kernel_task memory must be explicitly prepared when passed to this api.
+ @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.
+ @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. Note that unlike IOMemoryDescriptor::withAddress(), kernel_task memory must be explicitly prepared when passed to this api.
+ @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.
+ @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);
+
/*! @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.
UInt32 offset,
task_t task,
IOOptionBits options,
- IOMapper * mapper = 0);
+ IOMapper * mapper = kIOMapperSystem);
/*! @function withPhysicalRanges
@abstract Create an IOMemoryDescriptor to describe one or more physical ranges.
/*! @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.
/*! @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.
* 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.
@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 );
+
+/*! @function map
+ @abstract Maps a IOMemoryDescriptor into a task - deprecated, only safe for 32 bit tasks. Use createMappingInTask instead.
+ @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.
+ @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
+ @param options Mapping options are defined in IOTypes.h,<br>
+ kIOMapAnywhere should be passed if the mapping can be created anywhere. If not set, the atAddress parameter sets the location of the mapping, if it is available in the target map.<br>
+ kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br>
+ kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br>
+ 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>
+ @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. */
+
virtual IOMemoryMap * map(
task_t intoTask,
IOVirtualAddress atAddress,
IOByteCount offset = 0,
IOByteCount length = 0 );
+
/*! @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 );
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,
virtual IOReturn redirect(IOMemoryDescriptor * newBackingMemory,
IOOptionBits options,
IOByteCount offset = 0) = 0;
+
+ virtual IOReturn redirect(IOMemoryDescriptor * newBackingMemory,
+ IOOptionBits options,
+ mach_vm_size_t offset = 0) = 0;
+
+ virtual mach_vm_address_t getAddress() = 0;
+ virtual mach_vm_size_t getSize() = 0;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
public:
union Ranges {
- IOVirtualRange * v;
- IOPhysicalRange * p;
+ IOVirtualRange *v;
+ IOAddressRange *v64;
+ IOPhysicalRange *p;
void *uio;
};
protected:
virtual void free();
+ virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
private:
- // Internal APIs may be made virtual at some time in the future.
- IOReturn wireVirtual(IODirection forDirection);
- void *createNamedEntry();
-
- /* DEPRECATED */ IOByteCount _position; /* absolute position over all ranges */
/* DEPRECATED */ virtual void setPosition(IOByteCount position);
+ /* DEPRECATED */ virtual void mapIntoKernel(unsigned rangeIndex);
+ /* DEPRECATED */ virtual void unmapFromKernel();
-/*
- * 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;
-
-/* DEPRECATED */ unsigned _positionAtOffset; //range #n in which position is now
-
- OSData *_memoryEntries;
+ // Internal APIs may be made virtual at some time in the future.
+ IOReturn wireVirtual(IODirection forDirection);
+ 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:
/*
UInt32 offset,
task_t task,
IOOptionBits options,
- IOMapper * mapper = 0);
+ IOMapper * mapper = kIOMapperSystem);
// Secondary initialisers
virtual bool initWithAddress(void * address,
IODirection withDirection,
bool asReference = false);
+ virtual addr64_t getPhysicalSegment64( IOByteCount offset,
+ IOByteCount * length );
+
virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
IOByteCount * length);
vm_map_t addressMap,
IOVirtualAddress logical,
IOByteCount length );
+
virtual bool serialize(OSSerialize *s) const;
// Factory method for cloning a persistent IOMD, see IOMemoryDescriptor
static IOMemoryDescriptor *
withPersistentMemoryDescriptor(IOGeneralMemoryDescriptor *originalMD);
+
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
IOMemoryDescriptor::withRanges;
IOMemoryDescriptor::withSubRange;
+ // used by IODMACommand
+ virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
+
public:
/*
* Initialize or reinitialize an IOSubMemoryDescriptor to describe
* IOMemoryDescriptor required methods
*/
+ virtual addr64_t getPhysicalSegment64( IOByteCount offset,
+ IOByteCount * length );
+
virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
IOByteCount * length);
protected:
virtual IOMemoryMap * makeMapping(
IOMemoryDescriptor * owner,
- task_t intoTask,
+ 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 );
+ vm_map_t addressMap,
+ IOVirtualAddress * atAddress,
+ IOOptionBits options,
+ IOByteCount sourceOffset = 0,
+ IOByteCount length = 0 );
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */