]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOMemoryDescriptor.h
xnu-344.tar.gz
[apple/xnu.git] / iokit / IOKit / IOMemoryDescriptor.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22#ifndef _IOMEMORYDESCRIPTOR_H
23#define _IOMEMORYDESCRIPTOR_H
24
25#include <IOKit/IOTypes.h>
26#include <libkern/c++/OSContainers.h>
27
28struct IOPhysicalRange
29{
30 IOPhysicalAddress address;
31 IOByteCount length;
32};
33
34class IOMemoryMap;
35
36/*
37 * Direction of transfer, with respect to the described memory.
38 */
39enum IODirection
40{
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,
45};
46
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. */
50
51class IOMemoryDescriptor : public OSObject
52{
53 friend class _IOMemoryMap;
54 friend class IOSubMemoryDescriptor;
55
56 OSDeclareDefaultStructors(IOMemoryDescriptor);
57
58protected:
59/*! @struct ExpansionData
60 @discussion This structure will be used to expand the capablilties of this class in the future.
61 */
0b4e3aa0 62 struct ExpansionData {
9bccf70c
A
63 void * devicePager;
64 unsigned int pagerContig:1;
65 unsigned int unused:31;
66 IOMemoryDescriptor * memory;
0b4e3aa0 67 };
1c79356b
A
68
69/*! @var reserved
70 Reserved for future use. (Internal use only) */
71 ExpansionData * reserved;
72
73protected:
74 OSSet * _mappings;
75 IOOptionBits _flags;
76 void * _memEntry;
77
78 IODirection _direction; /* direction of transfer */
79 IOByteCount _length; /* length of all ranges */
80 IOOptionBits _tag;
81
0b4e3aa0
A
82public:
83
84 virtual IOPhysicalAddress getSourceSegment( IOByteCount offset,
85 IOByteCount * length );
86
1c79356b 87private:
0b4e3aa0 88 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 0);
1c79356b
A
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);
104
105protected:
106 virtual void free();
107public:
108 static void initialize( void );
109
110public:
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. */
118
119 static IOMemoryDescriptor * withAddress(void * address,
120 IOByteCount withLength,
121 IODirection withDirection);
122
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. */
131
132 static IOMemoryDescriptor * withAddress(vm_address_t address,
133 IOByteCount withLength,
134 IODirection withDirection,
135 task_t withTask);
136
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. */
144
145 static IOMemoryDescriptor * withPhysicalAddress(
146 IOPhysicalAddress address,
147 IOByteCount withLength,
148 IODirection withDirection );
149
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. */
159
160 static IOMemoryDescriptor * withRanges(IOVirtualRange * ranges,
161 UInt32 withCount,
162 IODirection withDirection,
163 task_t withTask,
164 bool asReference = false);
165
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. */
174
175 static IOMemoryDescriptor * withPhysicalRanges(
176 IOPhysicalRange * ranges,
177 UInt32 withCount,
178 IODirection withDirection,
179 bool asReference = false);
180
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. */
189
190 static IOMemoryDescriptor * withSubRange(IOMemoryDescriptor * of,
191 IOByteCount offset,
192 IOByteCount length,
193 IODirection withDirection);
194
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. */
202
203 virtual bool initWithAddress(void * address,
204 IOByteCount withLength,
205 IODirection withDirection) = 0;
206
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. */
215
216 virtual bool initWithAddress(vm_address_t address,
217 IOByteCount withLength,
218 IODirection withDirection,
219 task_t withTask) = 0;
220
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. */
228
229 virtual bool initWithPhysicalAddress(
230 IOPhysicalAddress address,
231 IOByteCount withLength,
232 IODirection withDirection ) = 0;
233
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. */
243
244 virtual bool initWithRanges( IOVirtualRange * ranges,
245 UInt32 withCount,
246 IODirection withDirection,
247 task_t withTask,
248 bool asReference = false) = 0;
249
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. */
258
259 virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
260 UInt32 withCount,
261 IODirection withDirection,
262 bool asReference = false) = 0;
263
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. */
268
269 virtual IODirection getDirection() const;
270
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. */
275
276 virtual IOByteCount getLength() const;
277
278/*! @function setTag
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. */
282
283 virtual void setTag( IOOptionBits tag );
284
285/*! @function getTag
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.
288 @result The tag. */
289
290 virtual IOOptionBits getTag( void );
291
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. */
299
300 virtual IOByteCount readBytes(IOByteCount offset,
0b4e3aa0 301 void * bytes, IOByteCount withLength);
1c79356b
A
302
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. */
310
311 virtual IOByteCount writeBytes(IOByteCount offset,
0b4e3aa0 312 const void * bytes, IOByteCount withLength);
1c79356b
A
313
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. */
320
321 virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
322 IOByteCount * length) = 0;
323
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. */
328
9bccf70c
A
329 /* inline */ IOPhysicalAddress getPhysicalAddress();
330 /* { return( getPhysicalSegment( 0, 0 )); } */
1c79356b 331
0b4e3aa0
A
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() */
1c79356b
A
336
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. */
342
343 virtual IOReturn prepare(IODirection forDirection = kIODirectionNone) = 0;
344
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. */
350
351 virtual IOReturn complete(IODirection forDirection = kIODirectionNone) = 0;
352
353 /*
354 * Mapping functions.
355 */
356
357/*! @function map
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. */
371
372 virtual IOMemoryMap * map(
373 task_t intoTask,
374 IOVirtualAddress atAddress,
375 IOOptionBits options,
376 IOByteCount offset = 0,
377 IOByteCount length = 0 );
378
379/*! @function map
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. */
384
385 virtual IOMemoryMap * map(
386 IOOptionBits options = 0 );
387
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. */
395
396 virtual IOMemoryMap * setMapping(
397 task_t task,
398 IOVirtualAddress mapAddress,
399 IOOptionBits options = 0 );
400
e3027f41
A
401 // Following methods are private implementation
402
403 // make virtual
404 IOReturn redirect( task_t safeTask, bool redirect );
405
0b4e3aa0
A
406 IOReturn handleFault(
407 void * pager,
408 vm_map_t addressMap,
409 IOVirtualAddress address,
410 IOByteCount sourceOffset,
411 IOByteCount length,
412 IOOptionBits options );
413
1c79356b
A
414protected:
415 virtual IOMemoryMap * makeMapping(
416 IOMemoryDescriptor * owner,
417 task_t intoTask,
418 IOVirtualAddress atAddress,
419 IOOptionBits options,
420 IOByteCount offset,
421 IOByteCount length );
422
423 virtual void addMapping(
424 IOMemoryMap * mapping );
425
426 virtual void removeMapping(
427 IOMemoryMap * mapping );
428
429 virtual IOReturn doMap(
430 vm_map_t addressMap,
431 IOVirtualAddress * atAddress,
432 IOOptionBits options,
433 IOByteCount sourceOffset = 0,
434 IOByteCount length = 0 );
435
436 virtual IOReturn doUnmap(
437 vm_map_t addressMap,
438 IOVirtualAddress logical,
439 IOByteCount length );
440};
441
442/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
443
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. */
447
448class IOMemoryMap : public OSObject
449{
450 OSDeclareAbstractStructors(IOMemoryMap)
451
452public:
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. */
457
458 virtual IOVirtualAddress getVirtualAddress() = 0;
459
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. */
466
467 virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
468 IOByteCount * length) = 0;
469
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. */
474
9bccf70c
A
475 /* inline */ IOPhysicalAddress getPhysicalAddress();
476 /* { return( getPhysicalSegment( 0, 0 )); } */
1c79356b
A
477
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. */
482
483 virtual IOByteCount getLength() = 0;
484
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. */
489
490 virtual task_t getAddressTask() = 0;
491
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. */
496
497 virtual IOMemoryDescriptor * getMemoryDescriptor() = 0;
498
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. */
503
504 virtual IOOptionBits getMapOptions() = 0;
505
506/*! @function unmap
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. */
510
511 virtual IOReturn unmap() = 0;
512
513 virtual void taskDied() = 0;
514};
515
516/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
517
e3027f41 518// The following classes are private implementation of IOMemoryDescriptor - they
0b4e3aa0
A
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 *.
e3027f41 523
1c79356b
A
524enum {
525 kIOMemoryRequiresWire = 0x00000001
526};
527
528class IOGeneralMemoryDescriptor : public IOMemoryDescriptor
529{
530 OSDeclareDefaultStructors(IOGeneralMemoryDescriptor);
531
532protected:
533 union {
534 IOVirtualRange * v;
535 IOPhysicalRange * p;
536 } _ranges; /* list of address ranges */
537 unsigned _rangesCount; /* number of address ranges in list */
538 bool _rangesIsAllocated; /* is list allocated by us? */
539
540 task_t _task; /* task where all ranges are mapped to */
541
542 union {
543 IOVirtualRange v;
544 IOPhysicalRange p;
545 } _singleRange; /* storage space for a single range */
546
547 unsigned _wireCount; /* number of outstanding wires */
548
549 vm_address_t _cachedVirtualAddress; /* a cached virtual-to-physical */
550 IOPhysicalAddress _cachedPhysicalAddress; /* mapping, for optimization */
551
552 bool _initialized; /* has superclass been initialized? */
553
554 virtual void free();
555
0b4e3aa0
A
556protected:
557 /* DEPRECATED */ IOByteCount _position; /* absolute position over all ranges */
558 /* DEPRECATED */ virtual void setPosition(IOByteCount position);
1c79356b
A
559
560private:
0b4e3aa0
A
561 /* DEPRECATED */ unsigned _positionAtIndex; /* range #n in which position is now */
562 /* DEPRECATED */ IOByteCount _positionAtOffset; /* relative position within range #n */
1c79356b
A
563 OSData *_memoryEntries;
564
0b4e3aa0
A
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();
1c79356b
A
570 inline vm_map_t getMapForTask( task_t task, vm_address_t address );
571
572public:
573 /*
574 * IOMemoryDescriptor required methods
575 */
576
577 virtual bool initWithAddress(void * address,
578 IOByteCount withLength,
579 IODirection withDirection);
580
581 virtual bool initWithAddress(vm_address_t address,
582 IOByteCount withLength,
583 IODirection withDirection,
584 task_t withTask);
585
586 virtual bool initWithPhysicalAddress(
587 IOPhysicalAddress address,
588 IOByteCount withLength,
589 IODirection withDirection );
590
591 virtual bool initWithRanges( IOVirtualRange * ranges,
592 UInt32 withCount,
593 IODirection withDirection,
594 task_t withTask,
595 bool asReference = false);
596
597 virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
598 UInt32 withCount,
599 IODirection withDirection,
600 bool asReference = false);
601
1c79356b
A
602 virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
603 IOByteCount * length);
604
0b4e3aa0
A
605 virtual IOPhysicalAddress getSourceSegment(IOByteCount offset,
606 IOByteCount * length);
607
608 /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset,
609 /* DEPRECATED */ IOByteCount * length);
1c79356b
A
610
611 virtual IOReturn prepare(IODirection forDirection = kIODirectionNone);
612
613 virtual IOReturn complete(IODirection forDirection = kIODirectionNone);
614
615 virtual IOReturn doMap(
616 vm_map_t addressMap,
617 IOVirtualAddress * atAddress,
618 IOOptionBits options,
619 IOByteCount sourceOffset = 0,
620 IOByteCount length = 0 );
621
622 virtual IOReturn doUnmap(
623 vm_map_t addressMap,
624 IOVirtualAddress logical,
625 IOByteCount length );
9bccf70c 626 virtual bool serialize(OSSerialize *s) const;
1c79356b
A
627};
628
629/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
630
631class IOSubMemoryDescriptor : public IOMemoryDescriptor
632{
9bccf70c 633 friend class IOMemoryDescriptor;
1c79356b
A
634
635 OSDeclareDefaultStructors(IOSubMemoryDescriptor);
636
637protected:
638 IOMemoryDescriptor * _parent;
639 IOByteCount _start;
640
641 virtual void free();
642
643 virtual bool initSubRange( IOMemoryDescriptor * parent,
644 IOByteCount offset, IOByteCount length,
645 IODirection withDirection );
646
647 virtual bool initWithAddress(void * address,
648 IOByteCount withLength,
649 IODirection withDirection);
650
651 virtual bool initWithAddress(vm_address_t address,
652 IOByteCount withLength,
653 IODirection withDirection,
654 task_t withTask);
655
656 virtual bool initWithPhysicalAddress(
657 IOPhysicalAddress address,
658 IOByteCount withLength,
659 IODirection withDirection );
660
661 virtual bool initWithRanges( IOVirtualRange * ranges,
662 UInt32 withCount,
663 IODirection withDirection,
664 task_t withTask,
665 bool asReference = false);
666
667 virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
668 UInt32 withCount,
669 IODirection withDirection,
670 bool asReference = false);
671
672 IOMemoryDescriptor::withAddress;
673 IOMemoryDescriptor::withPhysicalAddress;
674 IOMemoryDescriptor::withPhysicalRanges;
675 IOMemoryDescriptor::withRanges;
676 IOMemoryDescriptor::withSubRange;
677
678public:
679 /*
680 * IOMemoryDescriptor required methods
681 */
682
683 virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
684 IOByteCount * length);
685
0b4e3aa0
A
686 virtual IOPhysicalAddress getSourceSegment(IOByteCount offset,
687 IOByteCount * length);
688
1c79356b
A
689 virtual IOByteCount readBytes(IOByteCount offset,
690 void * bytes, IOByteCount withLength);
691
692 virtual IOByteCount writeBytes(IOByteCount offset,
693 const void * bytes, IOByteCount withLength);
694
695 virtual void * getVirtualSegment(IOByteCount offset,
696 IOByteCount * length);
697
698 virtual IOReturn prepare(IODirection forDirection = kIODirectionNone);
699
700 virtual IOReturn complete(IODirection forDirection = kIODirectionNone);
701
e3027f41
A
702 // make virtual
703 IOReturn redirect( task_t safeTask, bool redirect );
704
9bccf70c
A
705 virtual bool serialize(OSSerialize *s) const;
706
1c79356b
A
707protected:
708 virtual IOMemoryMap * makeMapping(
709 IOMemoryDescriptor * owner,
710 task_t intoTask,
711 IOVirtualAddress atAddress,
712 IOOptionBits options,
713 IOByteCount offset,
714 IOByteCount length );
715};
716
717/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
718
719#endif /* !_IOMEMORYDESCRIPTOR_H */