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
{ };
65 Reserved for future use. (Internal use only) */
66 ExpansionData
* reserved
;
73 IODirection _direction
; /* direction of transfer */
74 IOByteCount _length
; /* length of all ranges */
78 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 0);
79 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 1);
80 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 2);
81 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 3);
82 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 4);
83 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 5);
84 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 6);
85 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 7);
86 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 8);
87 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 9);
88 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 10);
89 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 11);
90 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 12);
91 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 13);
92 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 14);
93 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 15);
98 static void initialize( void );
101 /*! @function withAddress
102 @abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
103 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map.
104 @param address The virtual address of the first byte in the memory.
105 @param withLength The length of memory.
106 @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.
107 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
109 static IOMemoryDescriptor
* withAddress(void * address
,
110 IOByteCount withLength
,
111 IODirection withDirection
);
113 /*! @function withAddress
114 @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
115 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.
116 @param address The virtual address of the first byte in the memory.
117 @param withLength The length of memory.
118 @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.
119 @param withTask The task the virtual ranges are mapped into.
120 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
122 static IOMemoryDescriptor
* withAddress(vm_address_t address
,
123 IOByteCount withLength
,
124 IODirection withDirection
,
127 /*! @function withPhysicalAddress
128 @abstract Create an IOMemoryDescriptor to describe one physical range.
129 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.
130 @param address The physical address of the first byte in the memory.
131 @param withLength The length of memory.
132 @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.
133 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
135 static IOMemoryDescriptor
* withPhysicalAddress(
136 IOPhysicalAddress address
,
137 IOByteCount withLength
,
138 IODirection withDirection
);
140 /*! @function withRanges
141 @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
142 @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.
143 @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
144 @param withCount The member count of the ranges array.
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 @param withTask The task each of the virtual ranges are mapped into.
147 @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.
148 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
150 static IOMemoryDescriptor
* withRanges(IOVirtualRange
* ranges
,
152 IODirection withDirection
,
154 bool asReference
= false);
156 /*! @function withPhysicalRanges
157 @abstract Create an IOMemoryDescriptor to describe one or more physical ranges.
158 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges.
159 @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
160 @param withCount The member count of the ranges array.
161 @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.
162 @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.
163 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
165 static IOMemoryDescriptor
* withPhysicalRanges(
166 IOPhysicalRange
* ranges
,
168 IODirection withDirection
,
169 bool asReference
= false);
171 /*! @function withSubRange
172 @abstract Create an IOMemoryDescriptor to describe a subrange of an existing descriptor.
173 @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.
174 @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.
175 @param offset A byte offset into the parent memory descriptor's memory.
176 @param length The length of the subrange.
177 @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.
178 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
180 static IOMemoryDescriptor
* withSubRange(IOMemoryDescriptor
* of
,
183 IODirection withDirection
);
185 /*! @function initWithAddress
186 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the kernel task.
187 @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.
188 @param address The virtual address of the first byte in the memory.
189 @param withLength The length of memory.
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.
191 @result true on success, false on failure. */
193 virtual bool initWithAddress(void * address
,
194 IOByteCount withLength
,
195 IODirection withDirection
) = 0;
197 /*! @function initWithAddress
198 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the specified map.
199 @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.
200 @param address The virtual address of the first byte in the memory.
201 @param withLength The length of memory.
202 @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.
203 @param withTask The task the virtual ranges are mapped into.
204 @result true on success, false on failure. */
206 virtual bool initWithAddress(vm_address_t address
,
207 IOByteCount withLength
,
208 IODirection withDirection
,
209 task_t withTask
) = 0;
211 /*! @function initWithPhysicalAddress
212 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one physical range.
213 @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.
214 @param address The physical address of the first byte in the memory.
215 @param withLength The length of memory.
216 @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.
217 @result true on success, false on failure. */
219 virtual bool initWithPhysicalAddress(
220 IOPhysicalAddress address
,
221 IOByteCount withLength
,
222 IODirection withDirection
) = 0;
224 /*! @function initWithRanges
225 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more virtual ranges.
226 @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.
227 @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
228 @param withCount The member count of the ranges array.
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 @param withTask The task each of the virtual ranges are mapped into.
231 @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.
232 @result true on success, false on failure. */
234 virtual bool initWithRanges( IOVirtualRange
* ranges
,
236 IODirection withDirection
,
238 bool asReference
= false) = 0;
240 /*! @function initWithPhysicalRanges
241 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more physical ranges.
242 @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.
243 @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
244 @param withCount The member count of the ranges array.
245 @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.
246 @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.
247 @result true on success, false on failure. */
249 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
251 IODirection withDirection
,
252 bool asReference
= false) = 0;
254 /*! @function getDirection
255 @abstract Accessor to get the direction the memory descriptor was created with.
256 @discussion This method returns the direction the memory descriptor was created with.
257 @result The direction. */
259 virtual IODirection
getDirection() const;
261 /*! @function getLength
262 @abstract Accessor to get the length of the memory descriptor (over all its ranges).
263 @discussion This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.
264 @result The byte count. */
266 virtual IOByteCount
getLength() const;
269 @abstract Set the tag for the memory descriptor.
270 @discussion This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
271 @param tag The tag. */
273 virtual void setTag( IOOptionBits tag
);
276 @abstract Accessor to the retrieve the tag for the memory descriptor.
277 @discussion This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
280 virtual IOOptionBits
getTag( void );
282 /*! @function readBytes
283 @abstract Copy data from the memory descriptor's buffer to the specified buffer.
284 @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.
285 @param offset A byte offset into the memory descriptor's memory.
286 @param bytes The caller supplied buffer to copy the data to.
287 @param withLength The length of the data to copy.
288 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
290 virtual IOByteCount
readBytes(IOByteCount offset
,
291 void * bytes
, IOByteCount withLength
) = 0;
293 /*! @function writeBytes
294 @abstract Copy data to the memory descriptor's buffer from the specified buffer.
295 @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer.
296 @param offset A byte offset into the memory descriptor's memory.
297 @param bytes The caller supplied buffer to copy the data from.
298 @param withLength The length of the data to copy.
299 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
301 virtual IOByteCount
writeBytes(IOByteCount offset
,
302 const void * bytes
, IOByteCount withLength
) = 0;
304 /*! @function getPhysicalSegment
305 @abstract Break a memory descriptor into its physically contiguous segments.
306 @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.
307 @param offset A byte offset into the memory whose physical address to return.
308 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
309 @result A physical address, or zero if the offset is beyond the length of the memory. */
311 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
312 IOByteCount
* length
) = 0;
314 /*! @function getPhysicalAddress
315 @abstract Return the physical address of the first byte in the memory.
316 @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.
317 @result A physical address. */
319 inline IOPhysicalAddress
getPhysicalAddress()
320 { return( getPhysicalSegment( 0, 0 )); }
325 * Get the virtual address of the buffer, relative to the given offset.
326 * If the memory wasn't mapped into the caller's address space, it will be
327 * mapped in now. If the current position is at the end of the buffer, a
330 virtual void * getVirtualSegment(IOByteCount offset
,
331 IOByteCount
* length
) = 0;
333 /*! @function prepare
334 @abstract Prepare the memory for an I/O transfer.
335 @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.
336 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
337 @result An IOReturn code. */
339 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
) = 0;
341 /*! @function complete
342 @abstract Complete processing of the memory after an I/O transfer finishes.
343 @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.
344 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
345 @result An IOReturn code. */
347 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
) = 0;
354 @abstract Maps a IOMemoryDescriptor into a task.
355 @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.
356 @param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space.
357 @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
358 @param options Mapping options are defined in IOTypes.h,<br>
359 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>
360 kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br>
361 kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br>
362 kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br>
363 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>
364 @param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
365 @param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
366 @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. */
368 virtual IOMemoryMap
* map(
370 IOVirtualAddress atAddress
,
371 IOOptionBits options
,
372 IOByteCount offset
= 0,
373 IOByteCount length
= 0 );
376 @abstract Maps a IOMemoryDescriptor into the kernel map.
377 @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.
378 @param options Mapping options as in the full version of the map method, with kIOMapAnywhere assumed.
379 @result See the full version of the map method. */
381 virtual IOMemoryMap
* map(
382 IOOptionBits options
= 0 );
384 /*! @function setMapping
385 @abstract Establishes an already existing mapping.
386 @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.
387 @param task Address space in which the mapping exists.
388 @param mapAddress Virtual address of the mapping.
389 @param options Caching and read-only attributes of the mapping.
390 @result A IOMemoryMap object created to represent the mapping. */
392 virtual IOMemoryMap
* setMapping(
394 IOVirtualAddress mapAddress
,
395 IOOptionBits options
= 0 );
398 virtual IOMemoryMap
* makeMapping(
399 IOMemoryDescriptor
* owner
,
401 IOVirtualAddress atAddress
,
402 IOOptionBits options
,
404 IOByteCount length
);
406 virtual void addMapping(
407 IOMemoryMap
* mapping
);
409 virtual void removeMapping(
410 IOMemoryMap
* mapping
);
412 virtual IOReturn
doMap(
414 IOVirtualAddress
* atAddress
,
415 IOOptionBits options
,
416 IOByteCount sourceOffset
= 0,
417 IOByteCount length
= 0 );
419 virtual IOReturn
doUnmap(
421 IOVirtualAddress logical
,
422 IOByteCount length
);
425 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
427 /*! @class IOMemoryMap : public OSObject
428 @abstract An abstract base class defining common methods for describing a memory mapping.
429 @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. */
431 class IOMemoryMap
: public OSObject
433 OSDeclareAbstractStructors(IOMemoryMap
)
436 /*! @function getVirtualAddress
437 @abstract Accessor to the virtual address of the first byte in the mapping.
438 @discussion This method returns the virtual address of the first byte in the mapping.
439 @result A virtual address. */
441 virtual IOVirtualAddress
getVirtualAddress() = 0;
443 /*! @function getPhysicalSegment
444 @abstract Break a mapping into its physically contiguous segments.
445 @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.
446 @param offset A byte offset into the mapping whose physical address to return.
447 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
448 @result A physical address, or zero if the offset is beyond the length of the mapping. */
450 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
451 IOByteCount
* length
) = 0;
453 /*! @function getPhysicalAddress
454 @abstract Return the physical address of the first byte in the mapping.
455 @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.
456 @result A physical address. */
458 inline IOPhysicalAddress
getPhysicalAddress()
459 { return( getPhysicalSegment( 0, 0 )); }
461 /*! @function getLength
462 @abstract Accessor to the length of the mapping.
463 @discussion This method returns the length of the mapping.
464 @result A byte count. */
466 virtual IOByteCount
getLength() = 0;
468 /*! @function getAddressTask
469 @abstract Accessor to the task of the mapping.
470 @discussion This method returns the mach task the mapping exists in.
471 @result A mach task_t. */
473 virtual task_t
getAddressTask() = 0;
475 /*! @function getMemoryDescriptor
476 @abstract Accessor to the IOMemoryDescriptor the mapping was created from.
477 @discussion This method returns the IOMemoryDescriptor the mapping was created from.
478 @result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */
480 virtual IOMemoryDescriptor
* getMemoryDescriptor() = 0;
482 /*! @function getMapOptions
483 @abstract Accessor to the options the mapping was created with.
484 @discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with.
485 @result Options for the mapping, including cache settings. */
487 virtual IOOptionBits
getMapOptions() = 0;
490 @abstract Force the IOMemoryMap to unmap, without destroying the object.
491 @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.
492 @result An IOReturn code. */
494 virtual IOReturn
unmap() = 0;
496 virtual void taskDied() = 0;
499 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
502 kIOMemoryRequiresWire
= 0x00000001
505 class IOGeneralMemoryDescriptor
: public IOMemoryDescriptor
507 OSDeclareDefaultStructors(IOGeneralMemoryDescriptor
);
513 } _ranges
; /* list of address ranges */
514 unsigned _rangesCount
; /* number of address ranges in list */
515 bool _rangesIsAllocated
; /* is list allocated by us? */
517 task_t _task
; /* task where all ranges are mapped to */
522 } _singleRange
; /* storage space for a single range */
524 unsigned _wireCount
; /* number of outstanding wires */
526 vm_address_t _cachedVirtualAddress
; /* a cached virtual-to-physical */
527 IOPhysicalAddress _cachedPhysicalAddress
; /* mapping, for optimization */
529 bool _initialized
; /* has superclass been initialized? */
533 protected: /* (to be deprecated) */
534 IOByteCount _position
; /* absolute position over all ranges */
535 virtual void setPosition(IOByteCount position
);
538 unsigned _positionAtIndex
; /* range #n in which position is now */
539 IOByteCount _positionAtOffset
; /* relative position within range #n */
540 OSData
*_memoryEntries
;
542 vm_offset_t _kernPtrAligned
;
543 unsigned _kernPtrAtIndex
;
544 IOByteCount _kernSize
;
545 virtual void mapIntoKernel(unsigned rangeIndex
);
546 virtual void unmapFromKernel();
547 inline vm_map_t
getMapForTask( task_t task
, vm_address_t address
);
551 * IOMemoryDescriptor required methods
554 virtual bool initWithAddress(void * address
,
555 IOByteCount withLength
,
556 IODirection withDirection
);
558 virtual bool initWithAddress(vm_address_t address
,
559 IOByteCount withLength
,
560 IODirection withDirection
,
563 virtual bool initWithPhysicalAddress(
564 IOPhysicalAddress address
,
565 IOByteCount withLength
,
566 IODirection withDirection
);
568 virtual bool initWithRanges( IOVirtualRange
* ranges
,
570 IODirection withDirection
,
572 bool asReference
= false);
574 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
576 IODirection withDirection
,
577 bool asReference
= false);
579 virtual IOByteCount
readBytes(IOByteCount offset
,
580 void * bytes
, IOByteCount withLength
);
582 virtual IOByteCount
writeBytes(IOByteCount offset
,
583 const void * bytes
, IOByteCount withLength
);
585 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
586 IOByteCount
* length
);
588 virtual void * getVirtualSegment(IOByteCount offset
,
589 IOByteCount
* length
);
591 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
);
593 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
);
595 virtual IOReturn
doMap(
597 IOVirtualAddress
* atAddress
,
598 IOOptionBits options
,
599 IOByteCount sourceOffset
= 0,
600 IOByteCount length
= 0 );
602 virtual IOReturn
doUnmap(
604 IOVirtualAddress logical
,
605 IOByteCount length
);
608 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
610 class IOSubMemoryDescriptor
: public IOMemoryDescriptor
612 friend IOMemoryDescriptor
;
614 OSDeclareDefaultStructors(IOSubMemoryDescriptor
);
617 IOMemoryDescriptor
* _parent
;
622 virtual bool initSubRange( IOMemoryDescriptor
* parent
,
623 IOByteCount offset
, IOByteCount length
,
624 IODirection withDirection
);
626 virtual bool initWithAddress(void * address
,
627 IOByteCount withLength
,
628 IODirection withDirection
);
630 virtual bool initWithAddress(vm_address_t address
,
631 IOByteCount withLength
,
632 IODirection withDirection
,
635 virtual bool initWithPhysicalAddress(
636 IOPhysicalAddress address
,
637 IOByteCount withLength
,
638 IODirection withDirection
);
640 virtual bool initWithRanges( IOVirtualRange
* ranges
,
642 IODirection withDirection
,
644 bool asReference
= false);
646 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
648 IODirection withDirection
,
649 bool asReference
= false);
651 IOMemoryDescriptor::withAddress
;
652 IOMemoryDescriptor::withPhysicalAddress
;
653 IOMemoryDescriptor::withPhysicalRanges
;
654 IOMemoryDescriptor::withRanges
;
655 IOMemoryDescriptor::withSubRange
;
659 * IOMemoryDescriptor required methods
662 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
663 IOByteCount
* length
);
665 virtual IOByteCount
readBytes(IOByteCount offset
,
666 void * bytes
, IOByteCount withLength
);
668 virtual IOByteCount
writeBytes(IOByteCount offset
,
669 const void * bytes
, IOByteCount withLength
);
671 virtual void * getVirtualSegment(IOByteCount offset
,
672 IOByteCount
* length
);
674 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
);
676 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
);
679 virtual IOMemoryMap
* makeMapping(
680 IOMemoryDescriptor
* owner
,
682 IOVirtualAddress atAddress
,
683 IOOptionBits options
,
685 IOByteCount length
);
688 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
690 #endif /* !_IOMEMORYDESCRIPTOR_H */