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 <sys/cdefs.h>
30 #include <IOKit/IOTypes.h>
31 #include <libkern/c++/OSContainers.h>
34 #include <mach/memory_object_types.h>
37 struct IOPhysicalRange
39 IOPhysicalAddress address
;
47 * Direction of transfer, with respect to the described memory.
51 kIODirectionNone
= 0x0, // same as VM_PROT_NONE
52 kIODirectionIn
= 0x1, // User land 'read', same as VM_PROT_READ
53 kIODirectionOut
= 0x2, // User land 'write', same as VM_PROT_WRITE
54 kIODirectionOutIn
= kIODirectionOut
| kIODirectionIn
,
55 kIODirectionInOut
= kIODirectionIn
| kIODirectionOut
59 * IOOptionBits used in the second withRanges variant
62 kIOMemoryDirectionMask
= 0x00000007,
63 kIOMemoryAutoPrepare
= 0x00000008, // Shared with Buffer MD
65 kIOMemoryTypeVirtual
= 0x00000010,
66 kIOMemoryTypePhysical
= 0x00000020,
67 kIOMemoryTypeUPL
= 0x00000030,
68 kIOMemoryTypeMask
= 0x000000f0,
70 kIOMemoryAsReference
= 0x00000100,
71 kIOMemoryBufferPageable
= 0x00000400,
72 kIOMemoryDontMap
= 0x00000800,
75 #define kIOMapperNone ((IOMapper *) -1)
76 #define kIOMapperSystem ((IOMapper *) 0)
78 /*! @class IOMemoryDescriptor : public OSObject
79 @abstract An abstract base class defining common methods for describing physical or virtual memory.
80 @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. */
82 class IOMemoryDescriptor
: public OSObject
84 friend class _IOMemoryMap
;
85 friend class IOSubMemoryDescriptor
;
87 OSDeclareDefaultStructors(IOMemoryDescriptor
);
90 /*! @struct ExpansionData
91 @discussion This structure will be used to expand the capablilties of this class in the future.
93 struct ExpansionData
{
95 unsigned int pagerContig
:1;
96 unsigned int unused
:31;
97 IOMemoryDescriptor
* memory
;
101 Reserved for future use. (Internal use only) */
102 ExpansionData
* reserved
;
109 IODirection _direction
; /* DEPRECATED: use _flags instead. direction of transfer */
110 IOByteCount _length
; /* length of all ranges */
115 virtual IOPhysicalAddress
getSourceSegment( IOByteCount offset
,
116 IOByteCount
* length
);
117 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 0);
119 /*! @function initWithOptions
120 @abstract Master initialiser for all variants of memory descriptors. For a more complete description see IOMemoryDescriptor::withOptions.
121 @discussion Note this function can be used to re-init a previously created memory descriptor.
122 @result true on success, false on failure. */
123 virtual bool initWithOptions(void * buffers
,
127 IOOptionBits options
,
128 IOMapper
* mapper
= 0);
129 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 1);
131 virtual addr64_t
IOMemoryDescriptor::getPhysicalSegment64( IOByteCount offset
,
132 IOByteCount
* length
);
133 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor
, 2);
137 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 3);
138 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 4);
139 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 5);
140 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 6);
141 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 7);
142 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 8);
143 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 9);
144 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 10);
145 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 11);
146 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 12);
147 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 13);
148 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 14);
149 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor
, 15);
154 static void initialize( void );
157 /*! @function withAddress
158 @abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
159 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map.
160 @param address The virtual address of the first byte in the memory.
161 @param withLength The length of memory.
162 @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.
163 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
165 static IOMemoryDescriptor
* withAddress(void * address
,
166 IOByteCount withLength
,
167 IODirection withDirection
);
169 /*! @function withAddress
170 @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
171 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.
172 @param address The virtual address of the first byte in the memory.
173 @param withLength The length of memory.
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 withTask The task the virtual ranges are mapped into.
176 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
178 static IOMemoryDescriptor
* withAddress(vm_address_t address
,
179 IOByteCount withLength
,
180 IODirection withDirection
,
183 /*! @function withPhysicalAddress
184 @abstract Create an IOMemoryDescriptor to describe one physical range.
185 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.
186 @param address The physical address of the first byte in the memory.
187 @param withLength The length of memory.
188 @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.
189 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
191 static IOMemoryDescriptor
* withPhysicalAddress(
192 IOPhysicalAddress address
,
193 IOByteCount withLength
,
194 IODirection withDirection
);
196 /*! @function withRanges
197 @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
198 @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.
199 @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
200 @param withCount The member count of the ranges array.
201 @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.
202 @param withTask The task each of the virtual ranges are mapped into.
203 @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.
204 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
206 static IOMemoryDescriptor
* withRanges(IOVirtualRange
* ranges
,
208 IODirection withDirection
,
210 bool asReference
= false);
212 /*! @function withOptions
213 @abstract Master initialiser for all variants of memory descriptors.
214 @discussion This method creates and initializes an IOMemoryDescriptor for memory it has three main variants: Virtual, Physical & mach UPL. These variants are selected with the options parameter, see below. This memory descriptor needs to be prepared before it can be used to extract data from the memory described. However we temporarily have setup a mechanism that automatically prepares kernel_task memory descriptors at creation time.
217 @param buffers A pointer to an array of IOVirtualRanges or IOPhysicalRanges if the options:type is Virtual or Physical. For type UPL it is a upl_t returned by the mach/memory_object_types.h apis, primarily used internally by the UBC.
219 @param count options:type = Virtual or Physical count contains a count of the number of entires in the buffers array. For options:type = UPL this field contains a total length.
221 @param offset Only used when options:type = UPL, in which case this field contains an offset for the memory within the buffers upl.
223 @param task Only used options:type = Virtual, The task each of the virtual ranges are mapped into.
226 kIOMemoryDirectionMask (options:direction) This nibble indicates the I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.
227 kIOMemoryTypeMask (options:type) kIOMemoryTypeVirtual, kIOMemoryTypePhysical, kIOMemoryTypeUPL Indicates that what type of memory basic memory descriptor to use. This sub-field also controls the interpretation of the buffers, count, offset & task parameters.
228 kIOMemoryAsReference For options:type = Virtual or Physical this indicate that the memory descriptor need not copy the ranges array into local memory. This is an optimisation to try to minimise unnecessary allocations.
229 kIOMemoryBufferPageable Only used by the IOBufferMemoryDescriptor as an indication that the kernel virtual memory is in fact pageable and we need to use the kernel pageable submap rather than the default map.
230 kIOMemoryNoAutoPrepare Indicates that the temporary AutoPrepare of kernel_task memory should not be performed.
232 @param mapper Which IOMapper should be used to map the in-memory physical addresses into I/O space addresses. Defaults to 0 which indicates that the system mapper is to be used, if present.
234 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
236 static IOMemoryDescriptor
*withOptions(void * buffers
,
240 IOOptionBits options
,
241 IOMapper
* mapper
= 0);
243 /*! @function withPhysicalRanges
244 @abstract Create an IOMemoryDescriptor to describe one or more physical ranges.
245 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges.
246 @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
247 @param withCount The member count of the ranges array.
248 @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.
249 @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.
250 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
252 static IOMemoryDescriptor
* withPhysicalRanges(
253 IOPhysicalRange
* ranges
,
255 IODirection withDirection
,
256 bool asReference
= false);
258 /*! @function withSubRange
259 @abstract Create an IOMemoryDescriptor to describe a subrange of an existing descriptor.
260 @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.
261 @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.
262 @param offset A byte offset into the parent memory descriptor's memory.
263 @param length The length of the subrange.
264 @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.
265 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
267 static IOMemoryDescriptor
* withSubRange(IOMemoryDescriptor
*of
,
270 IODirection withDirection
);
272 /*! @function initWithAddress
273 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the kernel task.
274 @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.
275 @param address The virtual address of the first byte in the memory.
276 @param withLength The length of memory.
277 @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.
278 @result true on success, false on failure. */
280 virtual bool initWithAddress(void * address
,
281 IOByteCount withLength
,
282 IODirection withDirection
) = 0;
284 /*! @function initWithAddress
285 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the specified map.
286 @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.
287 @param address The virtual address of the first byte in the memory.
288 @param withLength The length of memory.
289 @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.
290 @param withTask The task the virtual ranges are mapped into.
291 @result true on success, false on failure. */
293 virtual bool initWithAddress(vm_address_t address
,
294 IOByteCount withLength
,
295 IODirection withDirection
,
296 task_t withTask
) = 0;
298 /*! @function initWithPhysicalAddress
299 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one physical range.
300 @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.
301 @param address The physical address of the first byte in the memory.
302 @param withLength The length of memory.
303 @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.
304 @result true on success, false on failure. */
306 virtual bool initWithPhysicalAddress(
307 IOPhysicalAddress address
,
308 IOByteCount withLength
,
309 IODirection withDirection
) = 0;
311 /*! @function initWithRanges
312 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more virtual ranges.
313 @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.
314 @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
315 @param withCount The member count of the ranges array.
316 @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.
317 @param withTask The task each of the virtual ranges are mapped into.
318 @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.
319 @result true on success, false on failure. */
321 virtual bool initWithRanges(IOVirtualRange
* ranges
,
323 IODirection withDirection
,
325 bool asReference
= false) = 0;
327 /*! @function initWithPhysicalRanges
328 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more physical ranges.
329 @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.
330 @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
331 @param withCount The member count of the ranges array.
332 @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.
333 @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.
334 @result true on success, false on failure. */
336 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
338 IODirection withDirection
,
339 bool asReference
= false) = 0;
341 /*! @function getDirection
342 @abstract Accessor to get the direction the memory descriptor was created with.
343 @discussion This method returns the direction the memory descriptor was created with.
344 @result The direction. */
346 virtual IODirection
getDirection() const;
348 /*! @function getLength
349 @abstract Accessor to get the length of the memory descriptor (over all its ranges).
350 @discussion This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.
351 @result The byte count. */
353 virtual IOByteCount
getLength() const;
356 @abstract Set the tag for the memory descriptor.
357 @discussion This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
358 @param tag The tag. */
360 virtual void setTag( IOOptionBits tag
);
363 @abstract Accessor to the retrieve the tag for the memory descriptor.
364 @discussion This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
367 virtual IOOptionBits
getTag( void );
369 /*! @function readBytes
370 @abstract Copy data from the memory descriptor's buffer to the specified buffer.
371 @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.
372 @param offset A byte offset into the memory descriptor's memory.
373 @param bytes The caller supplied buffer to copy the data to.
374 @param withLength The length of the data to copy.
375 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
377 virtual IOByteCount
readBytes(IOByteCount offset
,
378 void * bytes
, IOByteCount withLength
);
380 /*! @function writeBytes
381 @abstract Copy data to the memory descriptor's buffer from the specified buffer.
382 @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer.
383 @param offset A byte offset into the memory descriptor's memory.
384 @param bytes The caller supplied buffer to copy the data from.
385 @param withLength The length of the data to copy.
386 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
388 virtual IOByteCount
writeBytes(IOByteCount offset
,
389 const void * bytes
, IOByteCount withLength
);
391 /*! @function getPhysicalSegment
392 @abstract Break a memory descriptor into its physically contiguous segments.
393 @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.
394 @param offset A byte offset into the memory whose physical address to return.
395 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
396 @result A physical address, or zero if the offset is beyond the length of the memory. */
398 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
399 IOByteCount
* length
) = 0;
401 /*! @function getPhysicalAddress
402 @abstract Return the physical address of the first byte in the memory.
403 @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.
404 @result A physical address. */
406 /* inline */ IOPhysicalAddress
getPhysicalAddress();
407 /* { return( getPhysicalSegment( 0, 0 )); } */
409 /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */
410 /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset
,
411 /* DEPRECATED */ IOByteCount
* length
) = 0;
412 /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */
414 /*! @function prepare
415 @abstract Prepare the memory for an I/O transfer.
416 @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. Note that the prepare call is not thread safe and it is expected that the client will more easily be able to guarantee single threading a particular memory descriptor.
417 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
418 @result An IOReturn code. */
420 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
) = 0;
422 /*! @function complete
423 @abstract Complete processing of the memory after an I/O transfer finishes.
424 @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. In 10.3 or greater systems the direction argument to complete is not longer respected. The direction is totally determined at prepare() time.
425 @param forDirection DEPRECATED The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
426 @result An IOReturn code. */
428 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
) = 0;
435 @abstract Maps a IOMemoryDescriptor into a task.
436 @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.
437 @param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space.
438 @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
439 @param options Mapping options are defined in IOTypes.h,<br>
440 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>
441 kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br>
442 kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br>
443 kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br>
444 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>
445 @param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
446 @param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
447 @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. */
449 virtual IOMemoryMap
* map(
451 IOVirtualAddress atAddress
,
452 IOOptionBits options
,
453 IOByteCount offset
= 0,
454 IOByteCount length
= 0 );
457 @abstract Maps a IOMemoryDescriptor into the kernel map.
458 @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.
459 @param options Mapping options as in the full version of the map method, with kIOMapAnywhere assumed.
460 @result See the full version of the map method. */
462 virtual IOMemoryMap
* map(
463 IOOptionBits options
= 0 );
465 /*! @function setMapping
466 @abstract Establishes an already existing mapping.
467 @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.
468 @param task Address space in which the mapping exists.
469 @param mapAddress Virtual address of the mapping.
470 @param options Caching and read-only attributes of the mapping.
471 @result A IOMemoryMap object created to represent the mapping. */
473 virtual IOMemoryMap
* setMapping(
475 IOVirtualAddress mapAddress
,
476 IOOptionBits options
= 0 );
478 // Following methods are private implementation
481 IOReturn
redirect( task_t safeTask
, bool redirect
);
483 IOReturn
handleFault(
486 IOVirtualAddress address
,
487 IOByteCount sourceOffset
,
489 IOOptionBits options
);
492 virtual IOMemoryMap
* makeMapping(
493 IOMemoryDescriptor
* owner
,
495 IOVirtualAddress atAddress
,
496 IOOptionBits options
,
498 IOByteCount length
);
500 virtual void addMapping(
501 IOMemoryMap
* mapping
);
503 virtual void removeMapping(
504 IOMemoryMap
* mapping
);
506 virtual IOReturn
doMap(
508 IOVirtualAddress
* atAddress
,
509 IOOptionBits options
,
510 IOByteCount sourceOffset
= 0,
511 IOByteCount length
= 0 );
513 virtual IOReturn
doUnmap(
515 IOVirtualAddress logical
,
516 IOByteCount length
);
519 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
521 /*! @class IOMemoryMap : public OSObject
522 @abstract An abstract base class defining common methods for describing a memory mapping.
523 @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. */
525 class IOMemoryMap
: public OSObject
527 OSDeclareAbstractStructors(IOMemoryMap
)
530 /*! @function getVirtualAddress
531 @abstract Accessor to the virtual address of the first byte in the mapping.
532 @discussion This method returns the virtual address of the first byte in the mapping.
533 @result A virtual address. */
535 virtual IOVirtualAddress
getVirtualAddress() = 0;
537 /*! @function getPhysicalSegment
538 @abstract Break a mapping into its physically contiguous segments.
539 @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.
540 @param offset A byte offset into the mapping whose physical address to return.
541 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
542 @result A physical address, or zero if the offset is beyond the length of the mapping. */
544 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
545 IOByteCount
* length
) = 0;
547 /*! @function getPhysicalAddress
548 @abstract Return the physical address of the first byte in the mapping.
549 @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.
550 @result A physical address. */
552 /* inline */ IOPhysicalAddress
getPhysicalAddress();
553 /* { return( getPhysicalSegment( 0, 0 )); } */
555 /*! @function getLength
556 @abstract Accessor to the length of the mapping.
557 @discussion This method returns the length of the mapping.
558 @result A byte count. */
560 virtual IOByteCount
getLength() = 0;
562 /*! @function getAddressTask
563 @abstract Accessor to the task of the mapping.
564 @discussion This method returns the mach task the mapping exists in.
565 @result A mach task_t. */
567 virtual task_t
getAddressTask() = 0;
569 /*! @function getMemoryDescriptor
570 @abstract Accessor to the IOMemoryDescriptor the mapping was created from.
571 @discussion This method returns the IOMemoryDescriptor the mapping was created from.
572 @result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */
574 virtual IOMemoryDescriptor
* getMemoryDescriptor() = 0;
576 /*! @function getMapOptions
577 @abstract Accessor to the options the mapping was created with.
578 @discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with.
579 @result Options for the mapping, including cache settings. */
581 virtual IOOptionBits
getMapOptions() = 0;
584 @abstract Force the IOMemoryMap to unmap, without destroying the object.
585 @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.
586 @result An IOReturn code. */
588 virtual IOReturn
unmap() = 0;
590 virtual void taskDied() = 0;
593 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
595 // The following classes are private implementation of IOMemoryDescriptor - they
596 // should not be referenced directly, just through the public API's in the
597 // IOMemoryDescriptor class. For example, an IOGeneralMemoryDescriptor instance
598 // might be created by IOMemoryDescriptor::withAddress(), but there should be
599 // no need to reference as anything but a generic IOMemoryDescriptor *.
601 // Also these flags should not overlap with the options to
602 // IOMemoryDescriptor::initWithRanges(... IOOptionsBits options);
605 kIOMemoryPreparedReadOnly
= 0x00008000,
608 class IOGeneralMemoryDescriptor
: public IOMemoryDescriptor
610 OSDeclareDefaultStructors(IOGeneralMemoryDescriptor
);
616 } _ranges
; /* list of address ranges */
617 unsigned _rangesCount
; /* number of address ranges in list */
618 bool _rangesIsAllocated
; /* is list allocated by us? */
620 task_t _task
; /* task where all ranges are mapped to */
625 } _singleRange
; /* storage space for a single range */
627 unsigned _wireCount
; /* number of outstanding wires */
629 /* DEPRECATED */ vm_address_t _cachedVirtualAddress
; /* a cached virtual-to-physical */
631 /* DEPRECATED */ IOPhysicalAddress _cachedPhysicalAddress
;
633 bool _initialized
; /* has superclass been initialized? */
639 // Internal API may be made virtual at some time in the future.
640 IOReturn
wireVirtual(IODirection forDirection
);
642 /* DEPRECATED */ IOByteCount _position
; /* absolute position over all ranges */
643 /* DEPRECATED */ virtual void setPosition(IOByteCount position
);
646 * DEPRECATED IOByteCount _positionAtIndex; // relative position within range #n
648 * Re-use the _positionAtIndex as a count of the number of pages in
649 * this memory descriptor. Convieniently vm_address_t is an unsigned integer
650 * type so I can get away without having to change the type.
654 /* DEPRECATED */ unsigned _positionAtOffset
; //range #n in which position is now
656 OSData
*_memoryEntries
;
658 /* DEPRECATED */ vm_offset_t _kernPtrAligned
;
659 /* DEPRECATED */ unsigned _kernPtrAtIndex
;
660 /* DEPRECATED */ IOByteCount _kernSize
;
662 /* DEPRECATED */ virtual void mapIntoKernel(unsigned rangeIndex
);
663 /* DEPRECATED */ virtual void unmapFromKernel();
667 * IOMemoryDescriptor required methods
671 virtual bool initWithOptions(void * buffers
,
675 IOOptionBits options
,
676 IOMapper
* mapper
= 0);
678 // Secondary initialisers
679 virtual bool initWithAddress(void * address
,
680 IOByteCount withLength
,
681 IODirection withDirection
);
683 virtual bool initWithAddress(vm_address_t address
,
684 IOByteCount withLength
,
685 IODirection withDirection
,
688 virtual bool initWithPhysicalAddress(
689 IOPhysicalAddress address
,
690 IOByteCount withLength
,
691 IODirection withDirection
);
693 virtual bool initWithRanges( IOVirtualRange
* ranges
,
695 IODirection withDirection
,
697 bool asReference
= false);
699 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
701 IODirection withDirection
,
702 bool asReference
= false);
704 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
705 IOByteCount
* length
);
707 virtual IOPhysicalAddress
getSourceSegment(IOByteCount offset
,
708 IOByteCount
* length
);
710 /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset
,
711 /* DEPRECATED */ IOByteCount
* length
);
713 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
);
715 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
);
717 virtual IOReturn
doMap(
719 IOVirtualAddress
* atAddress
,
720 IOOptionBits options
,
721 IOByteCount sourceOffset
= 0,
722 IOByteCount length
= 0 );
724 virtual IOReturn
doUnmap(
726 IOVirtualAddress logical
,
727 IOByteCount length
);
728 virtual bool serialize(OSSerialize
*s
) const;
731 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
733 class IOSubMemoryDescriptor
: public IOMemoryDescriptor
735 friend class IOMemoryDescriptor
;
737 OSDeclareDefaultStructors(IOSubMemoryDescriptor
);
740 IOMemoryDescriptor
* _parent
;
745 virtual bool initWithAddress(void * address
,
746 IOByteCount withLength
,
747 IODirection withDirection
);
749 virtual bool initWithAddress(vm_address_t address
,
750 IOByteCount withLength
,
751 IODirection withDirection
,
754 virtual bool initWithPhysicalAddress(
755 IOPhysicalAddress address
,
756 IOByteCount withLength
,
757 IODirection withDirection
);
759 virtual bool initWithRanges( IOVirtualRange
* ranges
,
761 IODirection withDirection
,
763 bool asReference
= false);
765 virtual bool initWithPhysicalRanges(IOPhysicalRange
* ranges
,
767 IODirection withDirection
,
768 bool asReference
= false);
770 IOMemoryDescriptor::withAddress
;
771 IOMemoryDescriptor::withPhysicalAddress
;
772 IOMemoryDescriptor::withPhysicalRanges
;
773 IOMemoryDescriptor::withRanges
;
774 IOMemoryDescriptor::withSubRange
;
778 * Initialize or reinitialize an IOSubMemoryDescriptor to describe
779 * a subrange of an existing descriptor.
781 * An IOSubMemoryDescriptor can be re-used by calling initSubRange
782 * again on an existing instance -- note that this behavior is not
783 * commonly supported in other IOKit classes, although it is here.
785 virtual bool initSubRange( IOMemoryDescriptor
* parent
,
786 IOByteCount offset
, IOByteCount length
,
787 IODirection withDirection
);
790 * IOMemoryDescriptor required methods
793 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
794 IOByteCount
* length
);
796 virtual IOPhysicalAddress
getSourceSegment(IOByteCount offset
,
797 IOByteCount
* length
);
799 virtual IOByteCount
readBytes(IOByteCount offset
,
800 void * bytes
, IOByteCount withLength
);
802 virtual IOByteCount
writeBytes(IOByteCount offset
,
803 const void * bytes
, IOByteCount withLength
);
805 virtual void * getVirtualSegment(IOByteCount offset
,
806 IOByteCount
* length
);
808 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
);
810 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
);
813 IOReturn
redirect( task_t safeTask
, bool redirect
);
815 virtual bool serialize(OSSerialize
*s
) const;
818 virtual IOMemoryMap
* makeMapping(
819 IOMemoryDescriptor
* owner
,
821 IOVirtualAddress atAddress
,
822 IOOptionBits options
,
824 IOByteCount length
);
827 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
829 #endif /* !_IOMEMORYDESCRIPTOR_H */