|
Mac Dev Center
Mac OS X Reference Library Drivers, Kernel, & Hardware: Kernel Device Drivers Kernel Framework Reference
|
IOMemoryDescriptor |
| Inherits from: | |
| Declared In: |
An abstract base class defining common methods for describing physical or virtual memory.
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.
Complete processing of the memory after an I/O transfer finishes.
Maps a IOMemoryDescriptor into a task.
Accessor to get the direction the memory descriptor was created with.
Accessor to get the length of the memory descriptor (over all its ranges).
Return the physical address of the first byte in the memory.
Break a memory descriptor into its physically contiguous segments.
Accessor to the retrieve the tag for the memory descriptor.
Master initialiser for all variants of memory descriptors. For a more complete description see IOMemoryDescriptor::withOptions.
Maps a IOMemoryDescriptor into the kernel map.
Perform an operation on the memory descriptor's memory.
Prepare the memory for an I/O transfer.
Copy data from the memory descriptor's buffer to the specified buffer.
Establishes an already existing mapping.
Control the purgeable status of a memory descriptors memory.
Set the tag for the memory descriptor.
Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
Create an IOMemoryDescriptor to describe one virtual range of the specified map.
Create an IOMemoryDescriptor to describe one or more virtual ranges.
Master initialiser for all variants of memory descriptors.
Copy constructor that generates a new memory descriptor if the backing memory for the same task's virtual address and length has changed.
Create an IOMemoryDescriptor to describe one physical range.
Copy data to the memory descriptor's buffer from the specified buffer.
complete |
Complete processing of the memory after an I/O transfer finishes.
public
virtual IOReturn complete( IODirection forDirection = kIODirectionNone) = 0;
forDirectionDEPRECATED The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
An IOReturn code.
This method should not be called unless a prepare was previously issued; the prepare() and complete() must occur in pairs, before and after an I/O transfer involving pageable memory. In 10.3 or greater systems the direction argument to complete is not longer respected. The direction is totally determined at prepare() time.
createMappingInTask |
Maps a IOMemoryDescriptor into a task.
public
IOMemoryMap * createMappingInTask( task_t intoTask, mach_vm_address_t atAddress, IOOptionBits options, mach_vm_size_t offset = 0, mach_vm_size_t length = 0 );
intoTaskSets the target task for the mapping. Pass kernel_task for the kernel address space.
atAddressIf a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
optionsMapping options are defined in IOTypes.h,
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.
kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.
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.
offsetIs a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
lengthIs the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
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.
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.
getDirection |
Accessor to get the direction the memory descriptor was created with.
public
virtual IODirection getDirection() const;
The direction.
This method returns the direction the memory descriptor was created with.
getLength |
Accessor to get the length of the memory descriptor (over all its ranges).
public
virtual IOByteCount getLength() const;
The byte count.
This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.
getPhysicalAddress |
Return the physical address of the first byte in the memory.
public
IOPhysicalAddress getPhysicalAddress();
A physical address.
This method returns the physical address of the first byte in the memory. It is most useful on memory known to be physically contiguous.
getPhysicalSegment |
Break a memory descriptor into its physically contiguous segments.
public
#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__ */
offsetA byte offset into the memory whose physical address to return.
lengthIf non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
A physical address, or zero if the offset is beyond the length of the memory.
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.
getTag |
Accessor to the retrieve the tag for the memory descriptor.
public
virtual IOOptionBits getTag( void );
The tag.
This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
initWithOptions |
Master initialiser for all variants of memory descriptors. For a more complete description see IOMemoryDescriptor::withOptions.
public
virtual bool initWithOptions( void *buffers, UInt32 count, UInt32 offset, task_t task, IOOptionBits options, IOMapper *mapper = kIOMapperSystem);
true on success, false on failure.
Note this function can be used to re-init a previously created memory descriptor.
map |
Maps a IOMemoryDescriptor into the kernel map.
public
virtual IOMemoryMap * map( IOOptionBits options = 0 );
optionsMapping options as in the full version of the createMappingInTask method, with kIOMapAnywhere assumed.
See the full version of the createMappingInTask method.
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.
performOperation |
Perform an operation on the memory descriptor's memory.
public
virtual IOReturn performOperation( IOOptionBits options, IOByteCount offset, IOByteCount length );
optionsThe 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.
offsetA byte offset into the memory descriptor's memory.
lengthThe length of the data range.
An IOReturn code.
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.
prepare |
Prepare the memory for an I/O transfer.
public
virtual IOReturn prepare( IODirection forDirection = kIODirectionNone) = 0;
forDirectionThe direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
An IOReturn code.
This involves paging in the memory, if necessary, and wiring it down for the duration of the transfer. The complete() method completes the processing of the memory after the I/O transfer finishes. Note that the prepare call is not thread safe and it is expected that the client will more easily be able to guarantee single threading a particular memory descriptor.
readBytes |
Copy data from the memory descriptor's buffer to the specified buffer.
public
virtual IOByteCount readBytes( IOByteCount offset, void *bytes, IOByteCount withLength);
offsetA byte offset into the memory descriptor's memory.
bytesThe caller supplied buffer to copy the data to.
withLengthThe length of the data to copy.
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.
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.
setMapping |
Establishes an already existing mapping.
public
virtual IOMemoryMap * setMapping( task_t task, IOVirtualAddress mapAddress, IOOptionBits options = 0 );
taskAddress space in which the mapping exists.
mapAddressVirtual address of the mapping.
optionsCaching and read-only attributes of the mapping.
A IOMemoryMap object created to represent the mapping.
This method tells the IOMemoryDescriptor about a mapping that exists, but was created elsewhere. It allows later callers of the map method to share this externally created mapping. The IOMemoryMap object returned is created to represent it. This method is not commonly needed.
setPurgeable |
Control the purgeable status of a memory descriptors memory.
public
virtual IOReturn setPurgeable( IOOptionBits newState, IOOptionBits *oldState );
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.
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.
An IOReturn code.
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.
setTag |
Set the tag for the memory descriptor.
public
virtual void setTag( IOOptionBits tag );
tagThe tag.
This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
withAddress |
Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
public
static IOMemoryDescriptor * withAddress( void *address, IOByteCount withLength, IODirection withDirection);
addressThe virtual address of the first byte in the memory.
withLengthThe length of memory.
withDirectionAn I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.
The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.
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.
withAddressRange |
Create an IOMemoryDescriptor to describe one virtual range of the specified map.
public
static IOMemoryDescriptor * withAddressRange( mach_vm_address_t address, mach_vm_size_t length, IOOptionBits options, task_t task);
addressThe virtual address of the first byte in the memory.
withLengthThe length of memory.
optionskIOMemoryDirectionMask (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.
taskThe 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 created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.
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.
withAddressRanges |
Create an IOMemoryDescriptor to describe one or more virtual ranges.
public
static IOMemoryDescriptor * withAddressRanges( IOAddressRange *ranges, UInt32 rangeCount, IOOptionBits options, task_t task);
rangesAn 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.
rangeCountThe member count of the ranges array.
optionskIOMemoryDirectionMask (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.
taskThe 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 created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.
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.
withOptions |
Master initialiser for all variants of memory descriptors.
public
static IOMemoryDescriptor *withOptions( void *buffers, UInt32 count, UInt32 offset, task_t task, IOOptionBits options, IOMapper *mapper = kIOMapperSystem);
buffersA 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.
countoptions: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.
offsetOnly used when options:type = UPL, in which case this field contains an offset for the memory within the buffers upl.
taskOnly used options:type = Virtual, The task each of the virtual ranges are mapped into.
optionskIOMemoryDirectionMask (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) 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.
mapperWhich 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.
The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.
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.
withPersistentMemoryDescriptor |
Copy constructor that generates a new memory descriptor if the backing memory for the same task's virtual address and length has changed.
public
static IOMemoryDescriptor * withPersistentMemoryDescriptor( IOMemoryDescriptor *originalMD);
originalMDThe memory descriptor to be duplicated.
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.
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.
withPhysicalAddress |
Create an IOMemoryDescriptor to describe one physical range.
public
static IOMemoryDescriptor * withPhysicalAddress( IOPhysicalAddress address, IOByteCount withLength, IODirection withDirection );
addressThe physical address of the first byte in the memory.
withLengthThe length of memory.
withDirectionAn I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.
The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.
This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.
writeBytes |
Copy data to the memory descriptor's buffer from the specified buffer.
public
virtual IOByteCount writeBytes( IOByteCount offset, const void * bytes, IOByteCount withLength);
offsetA byte offset into the memory descriptor's memory.
bytesThe caller supplied buffer to copy the data from.
withLengthThe length of the data to copy.
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.
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.
ExpansionData |
protected
struct ExpansionData { void *devicePager; unsigned int pagerContig:1; unsigned int unused:31; IOMemoryDescriptor *memory; };
This structure will be used to expand the capablilties of this class in the future.
reserved |
protected
ExpansionData * reserved;
Reserved for future use. (Internal use only)
Last Updated: 2009-10-14