2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 #ifndef _IOMEMORYDESCRIPTOR_H
26 #define _IOMEMORYDESCRIPTOR_H
28 #include <IOKit/IOTypes.h>
29 #include <libkern/c++/OSContainers.h>
31 struct IOPhysicalRange
33 IOPhysicalAddress address
;
40 * Direction of transfer, with respect to the described memory.
44 kIODirectionNone
= 0x0, // same as VM_PROT_NONE
45 kIODirectionIn
= 0x1, // User land 'read', same as VM_PROT_READ
46 kIODirectionOut
= 0x2, // User land 'write', same as VM_PROT_WRITE
47 kIODirectionOutIn
= kIODirectionIn
| kIODirectionOut
,
50 /*! @class IOMemoryDescriptor : public OSObject
51 @abstract An abstract base class defining common methods for describing physical or virtual memory.
52 @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. */
54 class IOMemoryDescriptor
: public OSObject
56 friend class _IOMemoryMap
;
57 friend class IOSubMemoryDescriptor
;
59 OSDeclareDefaultStructors(IOMemoryDescriptor
);
62 /*! @struct ExpansionData
63 @discussion This structure will be used to expand the capablilties of this class in the future.
65 struct ExpansionData
{
67 unsigned int pagerContig
:1;
68 unsigned int unused
:31;
69 IOMemoryDescriptor
* memory
;
73 Reserved for future use. (Internal use only) */
74 ExpansionData
* reserved
;
81 IODirection _direction
; /* direction of transfer */
82 IOByteCount _length
; /* length of all ranges */
87 virtual IOPhysicalAddress
getSourceSegment( IOByteCount offset
,
88 IOByteCount
* length
);
91 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 0);
92 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 1);
93 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 2);
94 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 3);
95 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 4);
96 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 5);
97 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 6);
98 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 7);
99 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 8);
100 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 9);
101 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 10);
102 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 11);
103 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 12);
104 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 13);
105 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 14);
106 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 15);
111 static void initialize( void );
114 /*! @function withAddress
115 @abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
116 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map.
117 @param address The virtual address of the first byte in the memory.
118 @param withLength The length of memory.
119 @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.
120 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
122 static IOMemoryDescriptor
* withAddress(void * address
,
123 IOByteCount withLength
,
124 IODirection withDirection
);
126 /*! @function withAddress
127 @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
128 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.
129 @param address The virtual address of the first byte in the memory.
130 @param withLength The length of memory.
131 @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.
132 @param withTask The task the virtual ranges are mapped into.
133 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
135 static IOMemoryDescriptor
* withAddress(vm_address_t address
,
136 IOByteCount withLength
,
137 IODirection withDirection
,
140 /*! @function withPhysicalAddress
141 @abstract Create an IOMemoryDescriptor to describe one physical range.
142 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.
143 @param address The physical address of the first byte in the memory.
144 @param withLength The length of memory.
145 @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.
146 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
148 static IOMemoryDescriptor
* withPhysicalAddress(
149 IOPhysicalAddress address
,
150 IOByteCount withLength
,
151 IODirection withDirection
);
153 /*! @function withRanges
154 @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
155 @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.
156 @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
157 @param withCount The member count of the ranges array.
158 @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.
159 @param withTask The task each of the virtual ranges are mapped into.
160 @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.
161 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
163 static IOMemoryDescriptor
* withRanges(IOVirtualRange
* ranges
,
165 IODirection withDirection
,
167 bool asReference
= false);
169 /*! @function withPhysicalRanges
170 @abstract Create an IOMemoryDescriptor to describe one or more physical ranges.
171 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges.
172 @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
173 @param withCount The member count of the ranges array.
174 @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.
175 @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.
176 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
178 static IOMemoryDescriptor
* withPhysicalRanges(
179 IOPhysicalRange
* ranges
,
181 IODirection withDirection
,
182 bool asReference
= false);
184 /*! @function withSubRange
185 @abstract Create an IOMemoryDescriptor to describe a subrange of an existing descriptor.
186 @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.
187 @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.
188 @param offset A byte offset into the parent memory descriptor's memory.
189 @param length The length of the subrange.
190 @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.
191 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
193 static IOMemoryDescriptor
* withSubRange(IOMemoryDescriptor
* of
,
196 IODirection withDirection
);
198 /*! @function initWithAddress
199 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the kernel task.
200 @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.
201 @param address The virtual address of the first byte in the memory.
202 @param withLength The length of memory.
203 @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.
204 @result true on success, false on failure. */
206 virtual bool initWithAddress(void * address
,
207 IOByteCount withLength
,
208 IODirection withDirection
) = 0;
210 /*! @function initWithAddress
211 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the specified map.
212 @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.
213 @param address The virtual address of the first byte in the memory.
214 @param withLength The length of memory.
215 @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.
216 @param withTask The task the virtual ranges are mapped into.
217 @result true on success, false on failure. */
219 virtual bool initWithAddress(vm_address_t address
,
220 IOByteCount withLength
,
221 IODirection withDirection
,
222 task_t withTask
) = 0;
224 /*! @function initWithPhysicalAddress
225 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one physical range.
226 @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.
227 @param address The physical address of the first byte in the memory.
228 @param withLength The length of memory.
229 @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.
230 @result true on success, false on failure. */
232 virtual bool initWithPhysicalAddress(
233 IOPhysicalAddress address
,
234 IOByteCount withLength
,
235 IODirection withDirection
) = 0;
237 /*! @function initWithRanges
238 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more virtual ranges.
239 @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.
240 @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
241 @param withCount The member count of the ranges array.
242 @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.
243 @param withTask The task each of the virtual ranges are mapped into.
244 @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.
245 @result true on success, false on failure. */
247 virtual bool initWithRanges( IOVirtualRange
* ranges
,
249 IODirection withDirection
,
251 bool asReference
= false) = 0;
253 /*! @function initWithPhysicalRanges
254 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more physical ranges.
255 @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.
256 @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
257 @param withCount The member count of the ranges array.
258 @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.
259 @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.
260 @result true on success, false on failure. */
262 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
264 IODirection withDirection
,
265 bool asReference
= false) = 0;
267 /*! @function getDirection
268 @abstract Accessor to get the direction the memory descriptor was created with.
269 @discussion This method returns the direction the memory descriptor was created with.
270 @result The direction. */
272 virtual IODirection
getDirection() const;
274 /*! @function getLength
275 @abstract Accessor to get the length of the memory descriptor (over all its ranges).
276 @discussion This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.
277 @result The byte count. */
279 virtual IOByteCount
getLength() const;
282 @abstract Set the tag for the memory descriptor.
283 @discussion This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
284 @param tag The tag. */
286 virtual void setTag( IOOptionBits tag
);
289 @abstract Accessor to the retrieve the tag for the memory descriptor.
290 @discussion This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
293 virtual IOOptionBits
getTag( void );
295 /*! @function readBytes
296 @abstract Copy data from the memory descriptor's buffer to the specified buffer.
297 @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.
298 @param offset A byte offset into the memory descriptor's memory.
299 @param bytes The caller supplied buffer to copy the data to.
300 @param withLength The length of the data to copy.
301 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
303 virtual IOByteCount
readBytes(IOByteCount offset
,
304 void * bytes
, IOByteCount withLength
);
306 /*! @function writeBytes
307 @abstract Copy data to the memory descriptor's buffer from the specified buffer.
308 @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer.
309 @param offset A byte offset into the memory descriptor's memory.
310 @param bytes The caller supplied buffer to copy the data from.
311 @param withLength The length of the data to copy.
312 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
314 virtual IOByteCount
writeBytes(IOByteCount offset
,
315 const void * bytes
, IOByteCount withLength
);
317 /*! @function getPhysicalSegment
318 @abstract Break a memory descriptor into its physically contiguous segments.
319 @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.
320 @param offset A byte offset into the memory whose physical address to return.
321 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
322 @result A physical address, or zero if the offset is beyond the length of the memory. */
324 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
325 IOByteCount
* length
) = 0;
327 /*! @function getPhysicalAddress
328 @abstract Return the physical address of the first byte in the memory.
329 @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.
330 @result A physical address. */
332 /* inline */ IOPhysicalAddress
getPhysicalAddress();
333 /* { return( getPhysicalSegment( 0, 0 )); } */
335 /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */
336 /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset
,
337 /* DEPRECATED */ IOByteCount
* length
) = 0;
338 /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */
340 /*! @function prepare
341 @abstract Prepare the memory for an I/O transfer.
342 @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.
343 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
344 @result An IOReturn code. */
346 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
) = 0;
348 /*! @function complete
349 @abstract Complete processing of the memory after an I/O transfer finishes.
350 @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.
351 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
352 @result An IOReturn code. */
354 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
) = 0;
361 @abstract Maps a IOMemoryDescriptor into a task.
362 @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.
363 @param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space.
364 @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
365 @param options Mapping options are defined in IOTypes.h,<br>
366 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>
367 kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br>
368 kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br>
369 kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br>
370 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>
371 @param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
372 @param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
373 @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. */
375 virtual IOMemoryMap
* map(
377 IOVirtualAddress atAddress
,
378 IOOptionBits options
,
379 IOByteCount offset
= 0,
380 IOByteCount length
= 0 );
383 @abstract Maps a IOMemoryDescriptor into the kernel map.
384 @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.
385 @param options Mapping options as in the full version of the map method, with kIOMapAnywhere assumed.
386 @result See the full version of the map method. */
388 virtual IOMemoryMap
* map(
389 IOOptionBits options
= 0 );
391 /*! @function setMapping
392 @abstract Establishes an already existing mapping.
393 @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.
394 @param task Address space in which the mapping exists.
395 @param mapAddress Virtual address of the mapping.
396 @param options Caching and read-only attributes of the mapping.
397 @result A IOMemoryMap object created to represent the mapping. */
399 virtual IOMemoryMap
* setMapping(
401 IOVirtualAddress mapAddress
,
402 IOOptionBits options
= 0 );
404 // Following methods are private implementation
407 IOReturn
redirect( task_t safeTask
, bool redirect
);
409 IOReturn
handleFault(
412 IOVirtualAddress address
,
413 IOByteCount sourceOffset
,
415 IOOptionBits options
);
418 virtual IOMemoryMap
* makeMapping(
419 IOMemoryDescriptor
* owner
,
421 IOVirtualAddress atAddress
,
422 IOOptionBits options
,
424 IOByteCount length
);
426 virtual void addMapping(
427 IOMemoryMap
* mapping
);
429 virtual void removeMapping(
430 IOMemoryMap
* mapping
);
432 virtual IOReturn
doMap(
434 IOVirtualAddress
* atAddress
,
435 IOOptionBits options
,
436 IOByteCount sourceOffset
= 0,
437 IOByteCount length
= 0 );
439 virtual IOReturn
doUnmap(
441 IOVirtualAddress logical
,
442 IOByteCount length
);
445 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
447 /*! @class IOMemoryMap : public OSObject
448 @abstract An abstract base class defining common methods for describing a memory mapping.
449 @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. */
451 class IOMemoryMap
: public OSObject
453 OSDeclareAbstractStructors(IOMemoryMap
)
456 /*! @function getVirtualAddress
457 @abstract Accessor to the virtual address of the first byte in the mapping.
458 @discussion This method returns the virtual address of the first byte in the mapping.
459 @result A virtual address. */
461 virtual IOVirtualAddress
getVirtualAddress() = 0;
463 /*! @function getPhysicalSegment
464 @abstract Break a mapping into its physically contiguous segments.
465 @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.
466 @param offset A byte offset into the mapping whose physical address to return.
467 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
468 @result A physical address, or zero if the offset is beyond the length of the mapping. */
470 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
471 IOByteCount
* length
) = 0;
473 /*! @function getPhysicalAddress
474 @abstract Return the physical address of the first byte in the mapping.
475 @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.
476 @result A physical address. */
478 /* inline */ IOPhysicalAddress
getPhysicalAddress();
479 /* { return( getPhysicalSegment( 0, 0 )); } */
481 /*! @function getLength
482 @abstract Accessor to the length of the mapping.
483 @discussion This method returns the length of the mapping.
484 @result A byte count. */
486 virtual IOByteCount
getLength() = 0;
488 /*! @function getAddressTask
489 @abstract Accessor to the task of the mapping.
490 @discussion This method returns the mach task the mapping exists in.
491 @result A mach task_t. */
493 virtual task_t
getAddressTask() = 0;
495 /*! @function getMemoryDescriptor
496 @abstract Accessor to the IOMemoryDescriptor the mapping was created from.
497 @discussion This method returns the IOMemoryDescriptor the mapping was created from.
498 @result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */
500 virtual IOMemoryDescriptor
* getMemoryDescriptor() = 0;
502 /*! @function getMapOptions
503 @abstract Accessor to the options the mapping was created with.
504 @discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with.
505 @result Options for the mapping, including cache settings. */
507 virtual IOOptionBits
getMapOptions() = 0;
510 @abstract Force the IOMemoryMap to unmap, without destroying the object.
511 @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.
512 @result An IOReturn code. */
514 virtual IOReturn
unmap() = 0;
516 virtual void taskDied() = 0;
519 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
521 // The following classes are private implementation of IOMemoryDescriptor - they
522 // should not be referenced directly, just through the public API's in the
523 // IOMemoryDescriptor class. For example, an IOGeneralMemoryDescriptor instance
524 // might be created by IOMemoryDescriptor::withAddress(), but there should be
525 // no need to reference as anything but a generic IOMemoryDescriptor *.
528 kIOMemoryRequiresWire
= 0x00000001
531 class IOGeneralMemoryDescriptor
: public IOMemoryDescriptor
533 OSDeclareDefaultStructors(IOGeneralMemoryDescriptor
);
539 } _ranges
; /* list of address ranges */
540 unsigned _rangesCount
; /* number of address ranges in list */
541 bool _rangesIsAllocated
; /* is list allocated by us? */
543 task_t _task
; /* task where all ranges are mapped to */
548 } _singleRange
; /* storage space for a single range */
550 unsigned _wireCount
; /* number of outstanding wires */
552 vm_address_t _cachedVirtualAddress
; /* a cached virtual-to-physical */
553 IOPhysicalAddress _cachedPhysicalAddress
; /* mapping, for optimization */
555 bool _initialized
; /* has superclass been initialized? */
560 /* DEPRECATED */ IOByteCount _position
; /* absolute position over all ranges */
561 /* DEPRECATED */ virtual void setPosition(IOByteCount position
);
564 /* DEPRECATED */ unsigned _positionAtIndex
; /* range #n in which position is now */
565 /* DEPRECATED */ IOByteCount _positionAtOffset
; /* relative position within range #n */
566 OSData
*_memoryEntries
;
568 /* DEPRECATED */ vm_offset_t _kernPtrAligned
;
569 /* DEPRECATED */ unsigned _kernPtrAtIndex
;
570 /* DEPRECATED */ IOByteCount _kernSize
;
571 /* DEPRECATED */ virtual void mapIntoKernel(unsigned rangeIndex
);
572 /* DEPRECATED */ virtual void unmapFromKernel();
573 inline vm_map_t
getMapForTask( task_t task
, vm_address_t address
);
577 * IOMemoryDescriptor required methods
580 virtual bool initWithAddress(void * address
,
581 IOByteCount withLength
,
582 IODirection withDirection
);
584 virtual bool initWithAddress(vm_address_t address
,
585 IOByteCount withLength
,
586 IODirection withDirection
,
589 virtual bool initWithPhysicalAddress(
590 IOPhysicalAddress address
,
591 IOByteCount withLength
,
592 IODirection withDirection
);
594 virtual bool initWithRanges( IOVirtualRange
* ranges
,
596 IODirection withDirection
,
598 bool asReference
= false);
600 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
602 IODirection withDirection
,
603 bool asReference
= false);
605 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
606 IOByteCount
* length
);
608 virtual IOPhysicalAddress
getSourceSegment(IOByteCount offset
,
609 IOByteCount
* length
);
611 /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset
,
612 /* DEPRECATED */ IOByteCount
* length
);
614 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
);
616 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
);
618 virtual IOReturn
doMap(
620 IOVirtualAddress
* atAddress
,
621 IOOptionBits options
,
622 IOByteCount sourceOffset
= 0,
623 IOByteCount length
= 0 );
625 virtual IOReturn
doUnmap(
627 IOVirtualAddress logical
,
628 IOByteCount length
);
629 virtual bool serialize(OSSerialize
*s
) const;
632 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
634 class IOSubMemoryDescriptor
: public IOMemoryDescriptor
636 friend class IOMemoryDescriptor
;
638 OSDeclareDefaultStructors(IOSubMemoryDescriptor
);
641 IOMemoryDescriptor
* _parent
;
646 virtual bool initSubRange( IOMemoryDescriptor
* parent
,
647 IOByteCount offset
, IOByteCount length
,
648 IODirection withDirection
);
650 virtual bool initWithAddress(void * address
,
651 IOByteCount withLength
,
652 IODirection withDirection
);
654 virtual bool initWithAddress(vm_address_t address
,
655 IOByteCount withLength
,
656 IODirection withDirection
,
659 virtual bool initWithPhysicalAddress(
660 IOPhysicalAddress address
,
661 IOByteCount withLength
,
662 IODirection withDirection
);
664 virtual bool initWithRanges( IOVirtualRange
* ranges
,
666 IODirection withDirection
,
668 bool asReference
= false);
670 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
672 IODirection withDirection
,
673 bool asReference
= false);
675 IOMemoryDescriptor::withAddress
;
676 IOMemoryDescriptor::withPhysicalAddress
;
677 IOMemoryDescriptor::withPhysicalRanges
;
678 IOMemoryDescriptor::withRanges
;
679 IOMemoryDescriptor::withSubRange
;
683 * IOMemoryDescriptor required methods
686 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
687 IOByteCount
* length
);
689 virtual IOPhysicalAddress
getSourceSegment(IOByteCount offset
,
690 IOByteCount
* length
);
692 virtual IOByteCount
readBytes(IOByteCount offset
,
693 void * bytes
, IOByteCount withLength
);
695 virtual IOByteCount
writeBytes(IOByteCount offset
,
696 const void * bytes
, IOByteCount withLength
);
698 virtual void * getVirtualSegment(IOByteCount offset
,
699 IOByteCount
* length
);
701 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
);
703 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
);
706 IOReturn
redirect( task_t safeTask
, bool redirect
);
708 virtual bool serialize(OSSerialize
*s
) const;
711 virtual IOMemoryMap
* makeMapping(
712 IOMemoryDescriptor
* owner
,
714 IOVirtualAddress atAddress
,
715 IOOptionBits options
,
717 IOByteCount length
);
720 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
722 #endif /* !_IOMEMORYDESCRIPTOR_H */