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;
66 IOMemoryDescriptor
* memory
;
70 Reserved for future use. (Internal use only) */
71 ExpansionData
* reserved
;
78 IODirection _direction
; /* direction of transfer */
79 IOByteCount _length
; /* length of all ranges */
84 virtual IOPhysicalAddress
getSourceSegment( IOByteCount offset
,
85 IOByteCount
* length
);
88 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 0);
89 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 1);
90 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 2);
91 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 3);
92 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 4);
93 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 5);
94 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 6);
95 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 7);
96 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 8);
97 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 9);
98 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 10);
99 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 11);
100 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 12);
101 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 13);
102 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 14);
103 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 15);
108 static void initialize( void );
111 /*! @function withAddress
112 @abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
113 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map.
114 @param address The virtual address of the first byte in the memory.
115 @param withLength The length of memory.
116 @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.
117 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
119 static IOMemoryDescriptor
* withAddress(void * address
,
120 IOByteCount withLength
,
121 IODirection withDirection
);
123 /*! @function withAddress
124 @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
125 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.
126 @param address The virtual address of the first byte in the memory.
127 @param withLength The length of memory.
128 @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.
129 @param withTask The task the virtual ranges are mapped into.
130 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
132 static IOMemoryDescriptor
* withAddress(vm_address_t address
,
133 IOByteCount withLength
,
134 IODirection withDirection
,
137 /*! @function withPhysicalAddress
138 @abstract Create an IOMemoryDescriptor to describe one physical range.
139 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.
140 @param address The physical address of the first byte in the memory.
141 @param withLength The length of memory.
142 @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.
143 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
145 static IOMemoryDescriptor
* withPhysicalAddress(
146 IOPhysicalAddress address
,
147 IOByteCount withLength
,
148 IODirection withDirection
);
150 /*! @function withRanges
151 @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
152 @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.
153 @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
154 @param withCount The member count of the ranges array.
155 @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.
156 @param withTask The task each of the virtual ranges are mapped into.
157 @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.
158 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
160 static IOMemoryDescriptor
* withRanges(IOVirtualRange
* ranges
,
162 IODirection withDirection
,
164 bool asReference
= false);
166 /*! @function withPhysicalRanges
167 @abstract Create an IOMemoryDescriptor to describe one or more physical ranges.
168 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges.
169 @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
170 @param withCount The member count of the ranges array.
171 @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.
172 @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.
173 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
175 static IOMemoryDescriptor
* withPhysicalRanges(
176 IOPhysicalRange
* ranges
,
178 IODirection withDirection
,
179 bool asReference
= false);
181 /*! @function withSubRange
182 @abstract Create an IOMemoryDescriptor to describe a subrange of an existing descriptor.
183 @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.
184 @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.
185 @param offset A byte offset into the parent memory descriptor's memory.
186 @param length The length of the subrange.
187 @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.
188 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
190 static IOMemoryDescriptor
* withSubRange(IOMemoryDescriptor
* of
,
193 IODirection withDirection
);
195 /*! @function initWithAddress
196 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the kernel task.
197 @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.
198 @param address The virtual address of the first byte in the memory.
199 @param withLength The length of memory.
200 @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.
201 @result true on success, false on failure. */
203 virtual bool initWithAddress(void * address
,
204 IOByteCount withLength
,
205 IODirection withDirection
) = 0;
207 /*! @function initWithAddress
208 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the specified map.
209 @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.
210 @param address The virtual address of the first byte in the memory.
211 @param withLength The length of memory.
212 @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.
213 @param withTask The task the virtual ranges are mapped into.
214 @result true on success, false on failure. */
216 virtual bool initWithAddress(vm_address_t address
,
217 IOByteCount withLength
,
218 IODirection withDirection
,
219 task_t withTask
) = 0;
221 /*! @function initWithPhysicalAddress
222 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one physical range.
223 @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.
224 @param address The physical address of the first byte in the memory.
225 @param withLength The length of memory.
226 @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.
227 @result true on success, false on failure. */
229 virtual bool initWithPhysicalAddress(
230 IOPhysicalAddress address
,
231 IOByteCount withLength
,
232 IODirection withDirection
) = 0;
234 /*! @function initWithRanges
235 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more virtual ranges.
236 @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.
237 @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
238 @param withCount The member count of the ranges array.
239 @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.
240 @param withTask The task each of the virtual ranges are mapped into.
241 @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.
242 @result true on success, false on failure. */
244 virtual bool initWithRanges( IOVirtualRange
* ranges
,
246 IODirection withDirection
,
248 bool asReference
= false) = 0;
250 /*! @function initWithPhysicalRanges
251 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more physical ranges.
252 @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.
253 @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
254 @param withCount The member count of the ranges array.
255 @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.
256 @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.
257 @result true on success, false on failure. */
259 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
261 IODirection withDirection
,
262 bool asReference
= false) = 0;
264 /*! @function getDirection
265 @abstract Accessor to get the direction the memory descriptor was created with.
266 @discussion This method returns the direction the memory descriptor was created with.
267 @result The direction. */
269 virtual IODirection
getDirection() const;
271 /*! @function getLength
272 @abstract Accessor to get the length of the memory descriptor (over all its ranges).
273 @discussion This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.
274 @result The byte count. */
276 virtual IOByteCount
getLength() const;
279 @abstract Set the tag for the memory descriptor.
280 @discussion This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
281 @param tag The tag. */
283 virtual void setTag( IOOptionBits tag
);
286 @abstract Accessor to the retrieve the tag for the memory descriptor.
287 @discussion This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
290 virtual IOOptionBits
getTag( void );
292 /*! @function readBytes
293 @abstract Copy data from the memory descriptor's buffer to the specified buffer.
294 @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.
295 @param offset A byte offset into the memory descriptor's memory.
296 @param bytes The caller supplied buffer to copy the data to.
297 @param withLength The length of the data to copy.
298 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
300 virtual IOByteCount
readBytes(IOByteCount offset
,
301 void * bytes
, IOByteCount withLength
);
303 /*! @function writeBytes
304 @abstract Copy data to the memory descriptor's buffer from the specified buffer.
305 @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer.
306 @param offset A byte offset into the memory descriptor's memory.
307 @param bytes The caller supplied buffer to copy the data from.
308 @param withLength The length of the data to copy.
309 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
311 virtual IOByteCount
writeBytes(IOByteCount offset
,
312 const void * bytes
, IOByteCount withLength
);
314 /*! @function getPhysicalSegment
315 @abstract Break a memory descriptor into its physically contiguous segments.
316 @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.
317 @param offset A byte offset into the memory whose physical address to return.
318 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
319 @result A physical address, or zero if the offset is beyond the length of the memory. */
321 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
322 IOByteCount
* length
) = 0;
324 /*! @function getPhysicalAddress
325 @abstract Return the physical address of the first byte in the memory.
326 @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.
327 @result A physical address. */
329 /* inline */ IOPhysicalAddress
getPhysicalAddress();
330 /* { return( getPhysicalSegment( 0, 0 )); } */
332 /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */
333 /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset
,
334 /* DEPRECATED */ IOByteCount
* length
) = 0;
335 /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */
337 /*! @function prepare
338 @abstract Prepare the memory for an I/O transfer.
339 @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.
340 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
341 @result An IOReturn code. */
343 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
) = 0;
345 /*! @function complete
346 @abstract Complete processing of the memory after an I/O transfer finishes.
347 @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.
348 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
349 @result An IOReturn code. */
351 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
) = 0;
358 @abstract Maps a IOMemoryDescriptor into a task.
359 @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.
360 @param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space.
361 @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
362 @param options Mapping options are defined in IOTypes.h,<br>
363 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>
364 kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br>
365 kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br>
366 kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br>
367 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>
368 @param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
369 @param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
370 @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. */
372 virtual IOMemoryMap
* map(
374 IOVirtualAddress atAddress
,
375 IOOptionBits options
,
376 IOByteCount offset
= 0,
377 IOByteCount length
= 0 );
380 @abstract Maps a IOMemoryDescriptor into the kernel map.
381 @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.
382 @param options Mapping options as in the full version of the map method, with kIOMapAnywhere assumed.
383 @result See the full version of the map method. */
385 virtual IOMemoryMap
* map(
386 IOOptionBits options
= 0 );
388 /*! @function setMapping
389 @abstract Establishes an already existing mapping.
390 @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.
391 @param task Address space in which the mapping exists.
392 @param mapAddress Virtual address of the mapping.
393 @param options Caching and read-only attributes of the mapping.
394 @result A IOMemoryMap object created to represent the mapping. */
396 virtual IOMemoryMap
* setMapping(
398 IOVirtualAddress mapAddress
,
399 IOOptionBits options
= 0 );
401 // Following methods are private implementation
404 IOReturn
redirect( task_t safeTask
, bool redirect
);
406 IOReturn
handleFault(
409 IOVirtualAddress address
,
410 IOByteCount sourceOffset
,
412 IOOptionBits options
);
415 virtual IOMemoryMap
* makeMapping(
416 IOMemoryDescriptor
* owner
,
418 IOVirtualAddress atAddress
,
419 IOOptionBits options
,
421 IOByteCount length
);
423 virtual void addMapping(
424 IOMemoryMap
* mapping
);
426 virtual void removeMapping(
427 IOMemoryMap
* mapping
);
429 virtual IOReturn
doMap(
431 IOVirtualAddress
* atAddress
,
432 IOOptionBits options
,
433 IOByteCount sourceOffset
= 0,
434 IOByteCount length
= 0 );
436 virtual IOReturn
doUnmap(
438 IOVirtualAddress logical
,
439 IOByteCount length
);
442 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
444 /*! @class IOMemoryMap : public OSObject
445 @abstract An abstract base class defining common methods for describing a memory mapping.
446 @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. */
448 class IOMemoryMap
: public OSObject
450 OSDeclareAbstractStructors(IOMemoryMap
)
453 /*! @function getVirtualAddress
454 @abstract Accessor to the virtual address of the first byte in the mapping.
455 @discussion This method returns the virtual address of the first byte in the mapping.
456 @result A virtual address. */
458 virtual IOVirtualAddress
getVirtualAddress() = 0;
460 /*! @function getPhysicalSegment
461 @abstract Break a mapping into its physically contiguous segments.
462 @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.
463 @param offset A byte offset into the mapping whose physical address to return.
464 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
465 @result A physical address, or zero if the offset is beyond the length of the mapping. */
467 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
468 IOByteCount
* length
) = 0;
470 /*! @function getPhysicalAddress
471 @abstract Return the physical address of the first byte in the mapping.
472 @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.
473 @result A physical address. */
475 /* inline */ IOPhysicalAddress
getPhysicalAddress();
476 /* { return( getPhysicalSegment( 0, 0 )); } */
478 /*! @function getLength
479 @abstract Accessor to the length of the mapping.
480 @discussion This method returns the length of the mapping.
481 @result A byte count. */
483 virtual IOByteCount
getLength() = 0;
485 /*! @function getAddressTask
486 @abstract Accessor to the task of the mapping.
487 @discussion This method returns the mach task the mapping exists in.
488 @result A mach task_t. */
490 virtual task_t
getAddressTask() = 0;
492 /*! @function getMemoryDescriptor
493 @abstract Accessor to the IOMemoryDescriptor the mapping was created from.
494 @discussion This method returns the IOMemoryDescriptor the mapping was created from.
495 @result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */
497 virtual IOMemoryDescriptor
* getMemoryDescriptor() = 0;
499 /*! @function getMapOptions
500 @abstract Accessor to the options the mapping was created with.
501 @discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with.
502 @result Options for the mapping, including cache settings. */
504 virtual IOOptionBits
getMapOptions() = 0;
507 @abstract Force the IOMemoryMap to unmap, without destroying the object.
508 @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.
509 @result An IOReturn code. */
511 virtual IOReturn
unmap() = 0;
513 virtual void taskDied() = 0;
516 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
518 // The following classes are private implementation of IOMemoryDescriptor - they
519 // should not be referenced directly, just through the public API's in the
520 // IOMemoryDescriptor class. For example, an IOGeneralMemoryDescriptor instance
521 // might be created by IOMemoryDescriptor::withAddress(), but there should be
522 // no need to reference as anything but a generic IOMemoryDescriptor *.
525 kIOMemoryRequiresWire
= 0x00000001
528 class IOGeneralMemoryDescriptor
: public IOMemoryDescriptor
530 OSDeclareDefaultStructors(IOGeneralMemoryDescriptor
);
536 } _ranges
; /* list of address ranges */
537 unsigned _rangesCount
; /* number of address ranges in list */
538 bool _rangesIsAllocated
; /* is list allocated by us? */
540 task_t _task
; /* task where all ranges are mapped to */
545 } _singleRange
; /* storage space for a single range */
547 unsigned _wireCount
; /* number of outstanding wires */
549 vm_address_t _cachedVirtualAddress
; /* a cached virtual-to-physical */
550 IOPhysicalAddress _cachedPhysicalAddress
; /* mapping, for optimization */
552 bool _initialized
; /* has superclass been initialized? */
557 /* DEPRECATED */ IOByteCount _position
; /* absolute position over all ranges */
558 /* DEPRECATED */ virtual void setPosition(IOByteCount position
);
561 /* DEPRECATED */ unsigned _positionAtIndex
; /* range #n in which position is now */
562 /* DEPRECATED */ IOByteCount _positionAtOffset
; /* relative position within range #n */
563 OSData
*_memoryEntries
;
565 /* DEPRECATED */ vm_offset_t _kernPtrAligned
;
566 /* DEPRECATED */ unsigned _kernPtrAtIndex
;
567 /* DEPRECATED */ IOByteCount _kernSize
;
568 /* DEPRECATED */ virtual void mapIntoKernel(unsigned rangeIndex
);
569 /* DEPRECATED */ virtual void unmapFromKernel();
570 inline vm_map_t
getMapForTask( task_t task
, vm_address_t address
);
574 * IOMemoryDescriptor required methods
577 virtual bool initWithAddress(void * address
,
578 IOByteCount withLength
,
579 IODirection withDirection
);
581 virtual bool initWithAddress(vm_address_t address
,
582 IOByteCount withLength
,
583 IODirection withDirection
,
586 virtual bool initWithPhysicalAddress(
587 IOPhysicalAddress address
,
588 IOByteCount withLength
,
589 IODirection withDirection
);
591 virtual bool initWithRanges( IOVirtualRange
* ranges
,
593 IODirection withDirection
,
595 bool asReference
= false);
597 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
599 IODirection withDirection
,
600 bool asReference
= false);
602 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
603 IOByteCount
* length
);
605 virtual IOPhysicalAddress
getSourceSegment(IOByteCount offset
,
606 IOByteCount
* length
);
608 /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset
,
609 /* DEPRECATED */ IOByteCount
* length
);
611 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
);
613 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
);
615 virtual IOReturn
doMap(
617 IOVirtualAddress
* atAddress
,
618 IOOptionBits options
,
619 IOByteCount sourceOffset
= 0,
620 IOByteCount length
= 0 );
622 virtual IOReturn
doUnmap(
624 IOVirtualAddress logical
,
625 IOByteCount length
);
626 virtual bool serialize(OSSerialize
*s
) const;
629 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
631 class IOSubMemoryDescriptor
: public IOMemoryDescriptor
633 friend class IOMemoryDescriptor
;
635 OSDeclareDefaultStructors(IOSubMemoryDescriptor
);
638 IOMemoryDescriptor
* _parent
;
643 virtual bool initSubRange( IOMemoryDescriptor
* parent
,
644 IOByteCount offset
, IOByteCount length
,
645 IODirection withDirection
);
647 virtual bool initWithAddress(void * address
,
648 IOByteCount withLength
,
649 IODirection withDirection
);
651 virtual bool initWithAddress(vm_address_t address
,
652 IOByteCount withLength
,
653 IODirection withDirection
,
656 virtual bool initWithPhysicalAddress(
657 IOPhysicalAddress address
,
658 IOByteCount withLength
,
659 IODirection withDirection
);
661 virtual bool initWithRanges( IOVirtualRange
* ranges
,
663 IODirection withDirection
,
665 bool asReference
= false);
667 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
669 IODirection withDirection
,
670 bool asReference
= false);
672 IOMemoryDescriptor::withAddress
;
673 IOMemoryDescriptor::withPhysicalAddress
;
674 IOMemoryDescriptor::withPhysicalRanges
;
675 IOMemoryDescriptor::withRanges
;
676 IOMemoryDescriptor::withSubRange
;
680 * IOMemoryDescriptor required methods
683 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
684 IOByteCount
* length
);
686 virtual IOPhysicalAddress
getSourceSegment(IOByteCount offset
,
687 IOByteCount
* length
);
689 virtual IOByteCount
readBytes(IOByteCount offset
,
690 void * bytes
, IOByteCount withLength
);
692 virtual IOByteCount
writeBytes(IOByteCount offset
,
693 const void * bytes
, IOByteCount withLength
);
695 virtual void * getVirtualSegment(IOByteCount offset
,
696 IOByteCount
* length
);
698 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
);
700 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
);
703 IOReturn
redirect( task_t safeTask
, bool redirect
);
705 virtual bool serialize(OSSerialize
*s
) const;
708 virtual IOMemoryMap
* makeMapping(
709 IOMemoryDescriptor
* owner
,
711 IOVirtualAddress atAddress
,
712 IOOptionBits options
,
714 IOByteCount length
);
717 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
719 #endif /* !_IOMEMORYDESCRIPTOR_H */