2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #ifndef _IOMEMORYDESCRIPTOR_H
23 #define _IOMEMORYDESCRIPTOR_H
25 #include <IOKit/IOTypes.h>
26 #include <libkern/c++/OSContainers.h>
28 struct IOPhysicalRange
30 IOPhysicalAddress address
;
37 * Direction of transfer, with respect to the described memory.
41 kIODirectionNone
= 0x0, // same as VM_PROT_NONE
42 kIODirectionIn
= 0x1, // User land 'read', same as VM_PROT_READ
43 kIODirectionOut
= 0x2, // User land 'write', same as VM_PROT_WRITE
44 kIODirectionOutIn
= kIODirectionIn
| kIODirectionOut
,
47 /*! @class IOMemoryDescriptor : public OSObject
48 @abstract An abstract base class defining common methods for describing physical or virtual memory.
49 @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. */
51 class IOMemoryDescriptor
: public OSObject
53 friend class _IOMemoryMap
;
54 friend class IOSubMemoryDescriptor
;
56 OSDeclareDefaultStructors(IOMemoryDescriptor
);
59 /*! @struct ExpansionData
60 @discussion This structure will be used to expand the capablilties of this class in the future.
62 struct ExpansionData
{
64 unsigned int pagerContig
:1;
65 unsigned int unused
:31;
69 Reserved for future use. (Internal use only) */
70 ExpansionData
* reserved
;
77 IODirection _direction
; /* direction of transfer */
78 IOByteCount _length
; /* length of all ranges */
83 virtual IOPhysicalAddress
getSourceSegment( IOByteCount offset
,
84 IOByteCount
* length
);
87 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 0);
88 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 1);
89 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 2);
90 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 3);
91 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 4);
92 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 5);
93 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 6);
94 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 7);
95 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 8);
96 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 9);
97 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 10);
98 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 11);
99 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 12);
100 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 13);
101 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 14);
102 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 15);
107 static void initialize( void );
110 /*! @function withAddress
111 @abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
112 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map.
113 @param address The virtual address of the first byte in the memory.
114 @param withLength The length of memory.
115 @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.
116 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
118 static IOMemoryDescriptor
* withAddress(void * address
,
119 IOByteCount withLength
,
120 IODirection withDirection
);
122 /*! @function withAddress
123 @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
124 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.
125 @param address The virtual address of the first byte in the memory.
126 @param withLength The length of memory.
127 @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.
128 @param withTask The task the virtual ranges are mapped into.
129 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
131 static IOMemoryDescriptor
* withAddress(vm_address_t address
,
132 IOByteCount withLength
,
133 IODirection withDirection
,
136 /*! @function withPhysicalAddress
137 @abstract Create an IOMemoryDescriptor to describe one physical range.
138 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.
139 @param address The physical address of the first byte in the memory.
140 @param withLength The length of memory.
141 @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.
142 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
144 static IOMemoryDescriptor
* withPhysicalAddress(
145 IOPhysicalAddress address
,
146 IOByteCount withLength
,
147 IODirection withDirection
);
149 /*! @function withRanges
150 @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
151 @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.
152 @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
153 @param withCount The member count of the ranges array.
154 @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.
155 @param withTask The task each of the virtual ranges are mapped into.
156 @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.
157 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
159 static IOMemoryDescriptor
* withRanges(IOVirtualRange
* ranges
,
161 IODirection withDirection
,
163 bool asReference
= false);
165 /*! @function withPhysicalRanges
166 @abstract Create an IOMemoryDescriptor to describe one or more physical ranges.
167 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges.
168 @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
169 @param withCount The member count of the ranges array.
170 @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 @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.
172 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
174 static IOMemoryDescriptor
* withPhysicalRanges(
175 IOPhysicalRange
* ranges
,
177 IODirection withDirection
,
178 bool asReference
= false);
180 /*! @function withSubRange
181 @abstract Create an IOMemoryDescriptor to describe a subrange of an existing descriptor.
182 @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.
183 @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.
184 @param offset A byte offset into the parent memory descriptor's memory.
185 @param length The length of the subrange.
186 @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.
187 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
189 static IOMemoryDescriptor
* withSubRange(IOMemoryDescriptor
* of
,
192 IODirection withDirection
);
194 /*! @function initWithAddress
195 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the kernel task.
196 @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.
197 @param address The virtual address of the first byte in the memory.
198 @param withLength The length of memory.
199 @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.
200 @result true on success, false on failure. */
202 virtual bool initWithAddress(void * address
,
203 IOByteCount withLength
,
204 IODirection withDirection
) = 0;
206 /*! @function initWithAddress
207 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the specified map.
208 @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.
209 @param address The virtual address of the first byte in the memory.
210 @param withLength The length of memory.
211 @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.
212 @param withTask The task the virtual ranges are mapped into.
213 @result true on success, false on failure. */
215 virtual bool initWithAddress(vm_address_t address
,
216 IOByteCount withLength
,
217 IODirection withDirection
,
218 task_t withTask
) = 0;
220 /*! @function initWithPhysicalAddress
221 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one physical range.
222 @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.
223 @param address The physical address of the first byte in the memory.
224 @param withLength The length of memory.
225 @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.
226 @result true on success, false on failure. */
228 virtual bool initWithPhysicalAddress(
229 IOPhysicalAddress address
,
230 IOByteCount withLength
,
231 IODirection withDirection
) = 0;
233 /*! @function initWithRanges
234 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more virtual ranges.
235 @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.
236 @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
237 @param withCount The member count of the ranges array.
238 @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.
239 @param withTask The task each of the virtual ranges are mapped into.
240 @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.
241 @result true on success, false on failure. */
243 virtual bool initWithRanges( IOVirtualRange
* ranges
,
245 IODirection withDirection
,
247 bool asReference
= false) = 0;
249 /*! @function initWithPhysicalRanges
250 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more physical ranges.
251 @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.
252 @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
253 @param withCount The member count of the ranges array.
254 @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.
255 @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.
256 @result true on success, false on failure. */
258 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
260 IODirection withDirection
,
261 bool asReference
= false) = 0;
263 /*! @function getDirection
264 @abstract Accessor to get the direction the memory descriptor was created with.
265 @discussion This method returns the direction the memory descriptor was created with.
266 @result The direction. */
268 virtual IODirection
getDirection() const;
270 /*! @function getLength
271 @abstract Accessor to get the length of the memory descriptor (over all its ranges).
272 @discussion This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.
273 @result The byte count. */
275 virtual IOByteCount
getLength() const;
278 @abstract Set the tag for the memory descriptor.
279 @discussion This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
280 @param tag The tag. */
282 virtual void setTag( IOOptionBits tag
);
285 @abstract Accessor to the retrieve the tag for the memory descriptor.
286 @discussion This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
289 virtual IOOptionBits
getTag( void );
291 /*! @function readBytes
292 @abstract Copy data from the memory descriptor's buffer to the specified buffer.
293 @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.
294 @param offset A byte offset into the memory descriptor's memory.
295 @param bytes The caller supplied buffer to copy the data to.
296 @param withLength The length of the data to copy.
297 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
299 virtual IOByteCount
readBytes(IOByteCount offset
,
300 void * bytes
, IOByteCount withLength
);
302 /*! @function writeBytes
303 @abstract Copy data to the memory descriptor's buffer from the specified buffer.
304 @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer.
305 @param offset A byte offset into the memory descriptor's memory.
306 @param bytes The caller supplied buffer to copy the data from.
307 @param withLength The length of the data to copy.
308 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
310 virtual IOByteCount
writeBytes(IOByteCount offset
,
311 const void * bytes
, IOByteCount withLength
);
313 /*! @function getPhysicalSegment
314 @abstract Break a memory descriptor into its physically contiguous segments.
315 @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.
316 @param offset A byte offset into the memory whose physical address to return.
317 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
318 @result A physical address, or zero if the offset is beyond the length of the memory. */
320 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
321 IOByteCount
* length
) = 0;
323 /*! @function getPhysicalAddress
324 @abstract Return the physical address of the first byte in the memory.
325 @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.
326 @result A physical address. */
328 inline IOPhysicalAddress
getPhysicalAddress()
329 { return( getPhysicalSegment( 0, 0 )); }
331 /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */
332 /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset
,
333 /* DEPRECATED */ IOByteCount
* length
) = 0;
334 /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */
336 /*! @function prepare
337 @abstract Prepare the memory for an I/O transfer.
338 @discussion This involves paging in the memory, if necessary, and wiring it down for the duration of the transfer. The complete() method completes the processing of the memory after the I/O transfer finishes. This method needn't called for non-pageable memory.
339 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
340 @result An IOReturn code. */
342 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
) = 0;
344 /*! @function complete
345 @abstract Complete processing of the memory after an I/O transfer finishes.
346 @discussion This method should not be called unless a prepare was previously issued; the prepare() and complete() must occur in pairs, before and after an I/O transfer involving pageable memory.
347 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
348 @result An IOReturn code. */
350 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
) = 0;
357 @abstract Maps a IOMemoryDescriptor into a task.
358 @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.
359 @param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space.
360 @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
361 @param options Mapping options are defined in IOTypes.h,<br>
362 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>
363 kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br>
364 kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br>
365 kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br>
366 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>
367 @param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
368 @param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
369 @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. */
371 virtual IOMemoryMap
* map(
373 IOVirtualAddress atAddress
,
374 IOOptionBits options
,
375 IOByteCount offset
= 0,
376 IOByteCount length
= 0 );
379 @abstract Maps a IOMemoryDescriptor into the kernel map.
380 @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.
381 @param options Mapping options as in the full version of the map method, with kIOMapAnywhere assumed.
382 @result See the full version of the map method. */
384 virtual IOMemoryMap
* map(
385 IOOptionBits options
= 0 );
387 /*! @function setMapping
388 @abstract Establishes an already existing mapping.
389 @discussion This method tells the IOMemoryDescriptor about a mapping that exists, but was created elsewhere. It allows later callers of the map method to share this externally created mapping. The IOMemoryMap object returned is created to represent it. This method is not commonly needed.
390 @param task Address space in which the mapping exists.
391 @param mapAddress Virtual address of the mapping.
392 @param options Caching and read-only attributes of the mapping.
393 @result A IOMemoryMap object created to represent the mapping. */
395 virtual IOMemoryMap
* setMapping(
397 IOVirtualAddress mapAddress
,
398 IOOptionBits options
= 0 );
400 // Following methods are private implementation
403 IOReturn
redirect( task_t safeTask
, bool redirect
);
405 IOReturn
handleFault(
408 IOVirtualAddress address
,
409 IOByteCount sourceOffset
,
411 IOOptionBits options
);
414 virtual IOMemoryMap
* makeMapping(
415 IOMemoryDescriptor
* owner
,
417 IOVirtualAddress atAddress
,
418 IOOptionBits options
,
420 IOByteCount length
);
422 virtual void addMapping(
423 IOMemoryMap
* mapping
);
425 virtual void removeMapping(
426 IOMemoryMap
* mapping
);
428 virtual IOReturn
doMap(
430 IOVirtualAddress
* atAddress
,
431 IOOptionBits options
,
432 IOByteCount sourceOffset
= 0,
433 IOByteCount length
= 0 );
435 virtual IOReturn
doUnmap(
437 IOVirtualAddress logical
,
438 IOByteCount length
);
441 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
443 /*! @class IOMemoryMap : public OSObject
444 @abstract An abstract base class defining common methods for describing a memory mapping.
445 @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. */
447 class IOMemoryMap
: public OSObject
449 OSDeclareAbstractStructors(IOMemoryMap
)
452 /*! @function getVirtualAddress
453 @abstract Accessor to the virtual address of the first byte in the mapping.
454 @discussion This method returns the virtual address of the first byte in the mapping.
455 @result A virtual address. */
457 virtual IOVirtualAddress
getVirtualAddress() = 0;
459 /*! @function getPhysicalSegment
460 @abstract Break a mapping into its physically contiguous segments.
461 @discussion This method returns the physical address of the byte at the given offset into the mapping, and optionally the length of the physically contiguous segment from that offset. It functions similarly to IOMemoryDescriptor::getPhysicalSegment.
462 @param offset A byte offset into the mapping whose physical address to return.
463 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
464 @result A physical address, or zero if the offset is beyond the length of the mapping. */
466 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
467 IOByteCount
* length
) = 0;
469 /*! @function getPhysicalAddress
470 @abstract Return the physical address of the first byte in the mapping.
471 @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.
472 @result A physical address. */
474 inline IOPhysicalAddress
getPhysicalAddress()
475 { return( getPhysicalSegment( 0, 0 )); }
477 /*! @function getLength
478 @abstract Accessor to the length of the mapping.
479 @discussion This method returns the length of the mapping.
480 @result A byte count. */
482 virtual IOByteCount
getLength() = 0;
484 /*! @function getAddressTask
485 @abstract Accessor to the task of the mapping.
486 @discussion This method returns the mach task the mapping exists in.
487 @result A mach task_t. */
489 virtual task_t
getAddressTask() = 0;
491 /*! @function getMemoryDescriptor
492 @abstract Accessor to the IOMemoryDescriptor the mapping was created from.
493 @discussion This method returns the IOMemoryDescriptor the mapping was created from.
494 @result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */
496 virtual IOMemoryDescriptor
* getMemoryDescriptor() = 0;
498 /*! @function getMapOptions
499 @abstract Accessor to the options the mapping was created with.
500 @discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with.
501 @result Options for the mapping, including cache settings. */
503 virtual IOOptionBits
getMapOptions() = 0;
506 @abstract Force the IOMemoryMap to unmap, without destroying the object.
507 @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.
508 @result An IOReturn code. */
510 virtual IOReturn
unmap() = 0;
512 virtual void taskDied() = 0;
515 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
517 // The following classes are private implementation of IOMemoryDescriptor - they
518 // should not be referenced directly, just through the public API's in the
519 // IOMemoryDescriptor class. For example, an IOGeneralMemoryDescriptor instance
520 // might be created by IOMemoryDescriptor::withAddress(), but there should be
521 // no need to reference as anything but a generic IOMemoryDescriptor *.
524 kIOMemoryRequiresWire
= 0x00000001
527 class IOGeneralMemoryDescriptor
: public IOMemoryDescriptor
529 OSDeclareDefaultStructors(IOGeneralMemoryDescriptor
);
535 } _ranges
; /* list of address ranges */
536 unsigned _rangesCount
; /* number of address ranges in list */
537 bool _rangesIsAllocated
; /* is list allocated by us? */
539 task_t _task
; /* task where all ranges are mapped to */
544 } _singleRange
; /* storage space for a single range */
546 unsigned _wireCount
; /* number of outstanding wires */
548 vm_address_t _cachedVirtualAddress
; /* a cached virtual-to-physical */
549 IOPhysicalAddress _cachedPhysicalAddress
; /* mapping, for optimization */
551 bool _initialized
; /* has superclass been initialized? */
556 /* DEPRECATED */ IOByteCount _position
; /* absolute position over all ranges */
557 /* DEPRECATED */ virtual void setPosition(IOByteCount position
);
560 /* DEPRECATED */ unsigned _positionAtIndex
; /* range #n in which position is now */
561 /* DEPRECATED */ IOByteCount _positionAtOffset
; /* relative position within range #n */
562 OSData
*_memoryEntries
;
564 /* DEPRECATED */ vm_offset_t _kernPtrAligned
;
565 /* DEPRECATED */ unsigned _kernPtrAtIndex
;
566 /* DEPRECATED */ IOByteCount _kernSize
;
567 /* DEPRECATED */ virtual void mapIntoKernel(unsigned rangeIndex
);
568 /* DEPRECATED */ virtual void unmapFromKernel();
569 inline vm_map_t
getMapForTask( task_t task
, vm_address_t address
);
573 * IOMemoryDescriptor required methods
576 virtual bool initWithAddress(void * address
,
577 IOByteCount withLength
,
578 IODirection withDirection
);
580 virtual bool initWithAddress(vm_address_t address
,
581 IOByteCount withLength
,
582 IODirection withDirection
,
585 virtual bool initWithPhysicalAddress(
586 IOPhysicalAddress address
,
587 IOByteCount withLength
,
588 IODirection withDirection
);
590 virtual bool initWithRanges( IOVirtualRange
* ranges
,
592 IODirection withDirection
,
594 bool asReference
= false);
596 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
598 IODirection withDirection
,
599 bool asReference
= false);
601 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
602 IOByteCount
* length
);
604 virtual IOPhysicalAddress
getSourceSegment(IOByteCount offset
,
605 IOByteCount
* length
);
607 /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset
,
608 /* DEPRECATED */ IOByteCount
* length
);
610 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
);
612 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
);
614 virtual IOReturn
doMap(
616 IOVirtualAddress
* atAddress
,
617 IOOptionBits options
,
618 IOByteCount sourceOffset
= 0,
619 IOByteCount length
= 0 );
621 virtual IOReturn
doUnmap(
623 IOVirtualAddress logical
,
624 IOByteCount length
);
627 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
629 class IOSubMemoryDescriptor
: public IOMemoryDescriptor
631 friend IOMemoryDescriptor
;
633 OSDeclareDefaultStructors(IOSubMemoryDescriptor
);
636 IOMemoryDescriptor
* _parent
;
641 virtual bool initSubRange( IOMemoryDescriptor
* parent
,
642 IOByteCount offset
, IOByteCount length
,
643 IODirection withDirection
);
645 virtual bool initWithAddress(void * address
,
646 IOByteCount withLength
,
647 IODirection withDirection
);
649 virtual bool initWithAddress(vm_address_t address
,
650 IOByteCount withLength
,
651 IODirection withDirection
,
654 virtual bool initWithPhysicalAddress(
655 IOPhysicalAddress address
,
656 IOByteCount withLength
,
657 IODirection withDirection
);
659 virtual bool initWithRanges( IOVirtualRange
* ranges
,
661 IODirection withDirection
,
663 bool asReference
= false);
665 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
667 IODirection withDirection
,
668 bool asReference
= false);
670 IOMemoryDescriptor::withAddress
;
671 IOMemoryDescriptor::withPhysicalAddress
;
672 IOMemoryDescriptor::withPhysicalRanges
;
673 IOMemoryDescriptor::withRanges
;
674 IOMemoryDescriptor::withSubRange
;
678 * IOMemoryDescriptor required methods
681 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
682 IOByteCount
* length
);
684 virtual IOPhysicalAddress
getSourceSegment(IOByteCount offset
,
685 IOByteCount
* length
);
687 virtual IOByteCount
readBytes(IOByteCount offset
,
688 void * bytes
, IOByteCount withLength
);
690 virtual IOByteCount
writeBytes(IOByteCount offset
,
691 const void * bytes
, IOByteCount withLength
);
693 virtual void * getVirtualSegment(IOByteCount offset
,
694 IOByteCount
* length
);
696 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
);
698 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
);
701 IOReturn
redirect( task_t safeTask
, bool redirect
);
704 virtual IOMemoryMap
* makeMapping(
705 IOMemoryDescriptor
* owner
,
707 IOVirtualAddress atAddress
,
708 IOOptionBits options
,
710 IOByteCount length
);
713 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
715 #endif /* !_IOMEMORYDESCRIPTOR_H */