]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOMemoryDescriptor.h
xnu-792.10.96.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 *
37839358
A
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.
1c79356b 11 *
37839358
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
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.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22#ifndef _IOMEMORYDESCRIPTOR_H
23#define _IOMEMORYDESCRIPTOR_H
24
55e303ae
A
25#include <sys/cdefs.h>
26
1c79356b
A
27#include <IOKit/IOTypes.h>
28#include <libkern/c++/OSContainers.h>
29
55e303ae
A
30__BEGIN_DECLS
31#include <mach/memory_object_types.h>
32__END_DECLS
33
1c79356b
A
34struct IOPhysicalRange
35{
36 IOPhysicalAddress address;
37 IOByteCount length;
38};
39
40class IOMemoryMap;
55e303ae 41class IOMapper;
1c79356b
A
42
43/*
44 * Direction of transfer, with respect to the described memory.
45 */
46enum IODirection
47{
48 kIODirectionNone = 0x0, // same as VM_PROT_NONE
49 kIODirectionIn = 0x1, // User land 'read', same as VM_PROT_READ
50 kIODirectionOut = 0x2, // User land 'write', same as VM_PROT_WRITE
55e303ae
A
51 kIODirectionOutIn = kIODirectionOut | kIODirectionIn,
52 kIODirectionInOut = kIODirectionIn | kIODirectionOut
53};
54
55/*
91447636 56 * IOOptionBits used in the withOptions variant
55e303ae
A
57 */
58enum {
59 kIOMemoryDirectionMask = 0x00000007,
60 kIOMemoryAutoPrepare = 0x00000008, // Shared with Buffer MD
61
62 kIOMemoryTypeVirtual = 0x00000010,
63 kIOMemoryTypePhysical = 0x00000020,
64 kIOMemoryTypeUPL = 0x00000030,
91447636
A
65 kIOMemoryTypePersistentMD = 0x00000040, // Persistent Memory Descriptor
66 kIOMemoryTypeUIO = 0x00000050,
c0fea474
A
67 kIOMemoryTypeVirtual64 = 0x00000060,
68 kIOMemoryTypePhysical64 = 0x00000070,
55e303ae
A
69 kIOMemoryTypeMask = 0x000000f0,
70
71 kIOMemoryAsReference = 0x00000100,
72 kIOMemoryBufferPageable = 0x00000400,
73 kIOMemoryDontMap = 0x00000800,
74 kIOMemoryPersistent = 0x00010000
1c79356b
A
75};
76
55e303ae
A
77#define kIOMapperNone ((IOMapper *) -1)
78#define kIOMapperSystem ((IOMapper *) 0)
79
91447636
A
80enum
81{
82 kIOMemoryPurgeableKeepCurrent = 1,
83 kIOMemoryPurgeableNonVolatile = 2,
84 kIOMemoryPurgeableVolatile = 3,
85 kIOMemoryPurgeableEmpty = 4
86};
87enum
88{
89 kIOMemoryIncoherentIOFlush = 1,
90 kIOMemoryIncoherentIOStore = 2,
91};
92
c0fea474
A
93#define IOMEMORYDESCRIPTOR_SUPPORTS_DMACOMMAND 1
94
95
1c79356b
A
96/*! @class IOMemoryDescriptor : public OSObject
97 @abstract An abstract base class defining common methods for describing physical or virtual memory.
98 @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. */
99
100class IOMemoryDescriptor : public OSObject
101{
102 friend class _IOMemoryMap;
103 friend class IOSubMemoryDescriptor;
104
105 OSDeclareDefaultStructors(IOMemoryDescriptor);
106
107protected:
108/*! @struct ExpansionData
109 @discussion This structure will be used to expand the capablilties of this class in the future.
110 */
0b4e3aa0 111 struct ExpansionData {
9bccf70c
A
112 void * devicePager;
113 unsigned int pagerContig:1;
114 unsigned int unused:31;
115 IOMemoryDescriptor * memory;
0b4e3aa0 116 };
1c79356b
A
117
118/*! @var reserved
119 Reserved for future use. (Internal use only) */
120 ExpansionData * reserved;
121
122protected:
123 OSSet * _mappings;
124 IOOptionBits _flags;
125 void * _memEntry;
126
55e303ae 127 IODirection _direction; /* DEPRECATED: use _flags instead. direction of transfer */
1c79356b
A
128 IOByteCount _length; /* length of all ranges */
129 IOOptionBits _tag;
130
0b4e3aa0 131public:
c0fea474 132typedef IOOptionBits DMACommandOps;
0b4e3aa0
A
133 virtual IOPhysicalAddress getSourceSegment( IOByteCount offset,
134 IOByteCount * length );
55e303ae
A
135 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 0);
136
137/*! @function initWithOptions
138 @abstract Master initialiser for all variants of memory descriptors. For a more complete description see IOMemoryDescriptor::withOptions.
139 @discussion Note this function can be used to re-init a previously created memory descriptor.
140 @result true on success, false on failure. */
141 virtual bool initWithOptions(void * buffers,
142 UInt32 count,
143 UInt32 offset,
144 task_t task,
145 IOOptionBits options,
c0fea474 146 IOMapper * mapper = kIOMapperSystem);
55e303ae
A
147 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 1);
148
91447636
A
149 virtual addr64_t getPhysicalSegment64( IOByteCount offset,
150 IOByteCount * length );
55e303ae 151 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 2);
0b4e3aa0 152
91447636
A
153
154/*! @function setPurgeable
155 @abstract Control the purgeable status of a memory descriptors memory.
156 @discussion Buffers may be allocated with the ability to have their purgeable status changed - IOBufferMemoryDescriptor with the kIOMemoryPurgeable option, VM_FLAGS_PURGEABLE may be passed to vm_allocate() in user space to allocate such buffers. The purgeable status of such a buffer may be controlled with setPurgeable(). The process of making a purgeable memory descriptor non-volatile and determining its previous state is atomic - if a purgeable memory descriptor is made nonvolatile and the old state is returned as kIOMemoryPurgeableVolatile, then the memory's previous contents are completely intact and will remain so until the memory is made volatile again. If the old state is returned as kIOMemoryPurgeableEmpty then the memory was reclaimed while it was in a volatile state and its previous contents have been lost.
157 @param newState - the desired new purgeable state of the memory:<br>
158 kIOMemoryPurgeableKeepCurrent - make no changes to the memory's purgeable state.<br>
159 kIOMemoryPurgeableVolatile - make the memory volatile - the memory may be reclaimed by the VM system without saving its contents to backing store.<br>
160 kIOMemoryPurgeableNonVolatile - make the memory nonvolatile - the memory is treated as with usual allocations and must be saved to backing store if paged.<br>
161 kIOMemoryPurgeableEmpty - make the memory volatile, and discard any pages allocated to it.
162 @param oldState - if non-NULL, the previous purgeable state of the memory is returned here:<br>
163 kIOMemoryPurgeableNonVolatile - the memory was nonvolatile.<br>
164 kIOMemoryPurgeableVolatile - the memory was volatile but its content has not been discarded by the VM system.<br>
165 kIOMemoryPurgeableEmpty - the memory was volatile and has been discarded by the VM system.<br>
166 @result An IOReturn code. */
167
168 virtual IOReturn setPurgeable( IOOptionBits newState,
169 IOOptionBits * oldState );
170 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 3);
171
172/*! @function performOperation
173 @abstract Perform an operation on the memory descriptor's memory.
174 @discussion This method performs some operation on a range of the memory descriptor's memory. When a memory descriptor's memory is not mapped, it should be more efficient to use this method than mapping the memory to perform the operation virtually.
175 @param options The operation to perform on the memory:<br>
176 kIOMemoryIncoherentIOFlush - pass this option to store to memory and flush any data in the processor cache for the memory range, with synchronization to ensure the data has passed through all levels of processor cache. It may not be supported on all architectures. This type of flush may be used for non-coherent I/O such as AGP - it is NOT required for PCI coherent operations. The memory descriptor must have been previously prepared.<br>
177 kIOMemoryIncoherentIOStore - pass this option to store to memory any data in the processor cache for the memory range, with synchronization to ensure the data has passed through all levels of processor cache. It may not be supported on all architectures. This type of flush may be used for non-coherent I/O such as AGP - it is NOT required for PCI coherent operations. The memory descriptor must have been previously prepared.
178 @param offset A byte offset into the memory descriptor's memory.
179 @param length The length of the data range.
180 @result An IOReturn code. */
181
182 virtual IOReturn performOperation( IOOptionBits options,
183 IOByteCount offset, IOByteCount length );
184 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 4);
185
c0fea474
A
186#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
187 // Used for dedicated communications for IODMACommand
188 virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
189 OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 5);
190#endif
55e303ae 191
c0fea474
A
192private:
193#if (defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
1c79356b 194 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 5);
c0fea474 195#endif
1c79356b
A
196 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 6);
197 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 7);
198 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 8);
199 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 9);
200 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 10);
201 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 11);
202 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 12);
203 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 13);
204 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 14);
205 OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 15);
206
207protected:
208 virtual void free();
209public:
210 static void initialize( void );
211
212public:
213/*! @function withAddress
214 @abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
215 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map.
216 @param address The virtual address of the first byte in the memory.
217 @param withLength The length of memory.
218 @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.
219 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
220
221 static IOMemoryDescriptor * withAddress(void * address,
222 IOByteCount withLength,
223 IODirection withDirection);
224
225/*! @function withAddress
226 @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
227 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.
228 @param address The virtual address of the first byte in the memory.
229 @param withLength The length of memory.
230 @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.
231 @param withTask The task the virtual ranges are mapped into.
232 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
233
234 static IOMemoryDescriptor * withAddress(vm_address_t address,
235 IOByteCount withLength,
236 IODirection withDirection,
237 task_t withTask);
238
239/*! @function withPhysicalAddress
240 @abstract Create an IOMemoryDescriptor to describe one physical range.
241 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.
242 @param address The physical address of the first byte in the memory.
243 @param withLength The length of memory.
244 @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.
245 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
246
247 static IOMemoryDescriptor * withPhysicalAddress(
248 IOPhysicalAddress address,
249 IOByteCount withLength,
250 IODirection withDirection );
251
252/*! @function withRanges
253 @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
254 @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.
255 @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
256 @param withCount The member count of the ranges array.
257 @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.
258 @param withTask The task each of the virtual ranges are mapped into.
259 @param asReference If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.
260 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
261
55e303ae
A
262 static IOMemoryDescriptor * withRanges(IOVirtualRange * ranges,
263 UInt32 withCount,
264 IODirection withDirection,
265 task_t withTask,
266 bool asReference = false);
267
c0fea474
A
268#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
269/*! @function withAddressRange
270 @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
271 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.
272 @param address The virtual address of the first byte in the memory.
273 @param withLength The length of memory.
274 @param options
275 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.
276 kIOMemoryNoAutoPrepare Indicates that the temporary AutoPrepare of kernel_task memory should not be performed.
277 @param task The task the virtual ranges are mapped into.
278 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
279
280 static IOMemoryDescriptor * withAddressRange(
281 mach_vm_address_t address,
282 mach_vm_size_t length,
283 IOOptionBits options,
284 task_t task);
285
286/*! @function withAddressRanges
287 @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
288 @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.
289 @param ranges An array of IOAddressRange structures which specify the virtual ranges in the specified map which make up the memory to be described. IOAddressRange is the 64bit version of IOVirtualRange.
290 @param rangeCount The member count of the ranges array.
291 @param options
292 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.
293 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.
294 kIOMemoryNoAutoPrepare Indicates that the temporary AutoPrepare of kernel_task memory should not be performed.
295 @param task The task each of the virtual ranges are mapped into.
296 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
297
298 static IOMemoryDescriptor * withAddressRanges(
299 IOAddressRange * ranges,
300 UInt32 rangeCount,
301 IOOptionBits options,
302 task_t withTask);
303#endif
304
55e303ae
A
305/*! @function withOptions
306 @abstract Master initialiser for all variants of memory descriptors.
307 @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.
308
309
310 @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.
311
312 @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.
313
314 @param offset Only used when options:type = UPL, in which case this field contains an offset for the memory within the buffers upl.
315
316 @param task Only used options:type = Virtual, The task each of the virtual ranges are mapped into.
317
318 @param options
319 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.
320 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.
321 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.
322 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.
323 kIOMemoryNoAutoPrepare Indicates that the temporary AutoPrepare of kernel_task memory should not be performed.
324
325 @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.
326
327 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
328
329 static IOMemoryDescriptor *withOptions(void * buffers,
330 UInt32 count,
331 UInt32 offset,
332 task_t task,
333 IOOptionBits options,
c0fea474 334 IOMapper * mapper = kIOMapperSystem);
1c79356b
A
335
336/*! @function withPhysicalRanges
337 @abstract Create an IOMemoryDescriptor to describe one or more physical ranges.
338 @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges.
339 @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
340 @param withCount The member count of the ranges array.
341 @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.
342 @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.
343 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
344
345 static IOMemoryDescriptor * withPhysicalRanges(
346 IOPhysicalRange * ranges,
347 UInt32 withCount,
55e303ae 348 IODirection withDirection,
1c79356b
A
349 bool asReference = false);
350
351/*! @function withSubRange
352 @abstract Create an IOMemoryDescriptor to describe a subrange of an existing descriptor.
353 @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.
354 @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.
355 @param offset A byte offset into the parent memory descriptor's memory.
356 @param length The length of the subrange.
357 @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.
358 @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
359
55e303ae
A
360 static IOMemoryDescriptor * withSubRange(IOMemoryDescriptor *of,
361 IOByteCount offset,
362 IOByteCount length,
363 IODirection withDirection);
1c79356b 364
91447636
A
365/*! @function withPersistentMemoryDescriptor
366 @abstract Copy constructor that generates a new memory descriptor if the backing memory for the same task's virtual address and length has changed.
367 @discussion If the original memory descriptor's address and length is still backed by the same real memory, i.e. the user hasn't deallocated and the reallocated memory at the same address then the original memory descriptor is returned with a additional reference. Otherwise we build a totally new memory descriptor with the same characteristics as the previous one but with a new view of the vm. Note not legal to call this function with anything except an IOGeneralMemoryDescriptor that was created with the kIOMemoryPersistent option.
368 @param originalMD The memory descriptor to be duplicated.
369 @result Either the original memory descriptor with an additional retain or a new memory descriptor, 0 for a bad original memory descriptor or some other resource shortage. */
370 static IOMemoryDescriptor *
371 withPersistentMemoryDescriptor(IOMemoryDescriptor *originalMD);
372
1c79356b
A
373/*! @function initWithAddress
374 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the kernel task.
375 @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.
376 @param address The virtual address of the first byte in the memory.
377 @param withLength The length of memory.
378 @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.
379 @result true on success, false on failure. */
380
381 virtual bool initWithAddress(void * address,
382 IOByteCount withLength,
383 IODirection withDirection) = 0;
384
385/*! @function initWithAddress
386 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the specified map.
387 @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.
388 @param address The virtual address of the first byte in the memory.
389 @param withLength The length of memory.
390 @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.
391 @param withTask The task the virtual ranges are mapped into.
392 @result true on success, false on failure. */
393
394 virtual bool initWithAddress(vm_address_t address,
395 IOByteCount withLength,
396 IODirection withDirection,
397 task_t withTask) = 0;
398
399/*! @function initWithPhysicalAddress
400 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one physical range.
401 @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.
402 @param address The physical address of the first byte in the memory.
403 @param withLength The length of memory.
404 @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.
405 @result true on success, false on failure. */
406
407 virtual bool initWithPhysicalAddress(
408 IOPhysicalAddress address,
409 IOByteCount withLength,
410 IODirection withDirection ) = 0;
411
412/*! @function initWithRanges
413 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more virtual ranges.
414 @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.
415 @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
416 @param withCount The member count of the ranges array.
417 @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.
418 @param withTask The task each of the virtual ranges are mapped into.
419 @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.
420 @result true on success, false on failure. */
421
55e303ae
A
422 virtual bool initWithRanges(IOVirtualRange * ranges,
423 UInt32 withCount,
424 IODirection withDirection,
425 task_t withTask,
426 bool asReference = false) = 0;
1c79356b
A
427
428/*! @function initWithPhysicalRanges
429 @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more physical ranges.
430 @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.
431 @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
432 @param withCount The member count of the ranges array.
433 @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.
434 @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.
435 @result true on success, false on failure. */
436
437 virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
438 UInt32 withCount,
439 IODirection withDirection,
440 bool asReference = false) = 0;
441
442/*! @function getDirection
443 @abstract Accessor to get the direction the memory descriptor was created with.
444 @discussion This method returns the direction the memory descriptor was created with.
445 @result The direction. */
446
447 virtual IODirection getDirection() const;
448
449/*! @function getLength
450 @abstract Accessor to get the length of the memory descriptor (over all its ranges).
451 @discussion This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.
452 @result The byte count. */
453
454 virtual IOByteCount getLength() const;
455
456/*! @function setTag
457 @abstract Set the tag for the memory descriptor.
458 @discussion This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
459 @param tag The tag. */
460
461 virtual void setTag( IOOptionBits tag );
462
463/*! @function getTag
464 @abstract Accessor to the retrieve the tag for the memory descriptor.
465 @discussion This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
466 @result The tag. */
467
468 virtual IOOptionBits getTag( void );
469
470/*! @function readBytes
471 @abstract Copy data from the memory descriptor's buffer to the specified buffer.
472 @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.
473 @param offset A byte offset into the memory descriptor's memory.
474 @param bytes The caller supplied buffer to copy the data to.
475 @param withLength The length of the data to copy.
476 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
477
478 virtual IOByteCount readBytes(IOByteCount offset,
0b4e3aa0 479 void * bytes, IOByteCount withLength);
1c79356b
A
480
481/*! @function writeBytes
482 @abstract Copy data to the memory descriptor's buffer from the specified buffer.
483 @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer.
484 @param offset A byte offset into the memory descriptor's memory.
485 @param bytes The caller supplied buffer to copy the data from.
486 @param withLength The length of the data to copy.
487 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
488
489 virtual IOByteCount writeBytes(IOByteCount offset,
0b4e3aa0 490 const void * bytes, IOByteCount withLength);
1c79356b
A
491
492/*! @function getPhysicalSegment
493 @abstract Break a memory descriptor into its physically contiguous segments.
494 @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.
495 @param offset A byte offset into the memory whose physical address to return.
496 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
497 @result A physical address, or zero if the offset is beyond the length of the memory. */
498
499 virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
500 IOByteCount * length) = 0;
501
502/*! @function getPhysicalAddress
503 @abstract Return the physical address of the first byte in the memory.
504 @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.
505 @result A physical address. */
506
9bccf70c
A
507 /* inline */ IOPhysicalAddress getPhysicalAddress();
508 /* { return( getPhysicalSegment( 0, 0 )); } */
1c79356b 509
0b4e3aa0
A
510 /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */
511 /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset,
512 /* DEPRECATED */ IOByteCount * length) = 0;
513 /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */
1c79356b
A
514
515/*! @function prepare
516 @abstract Prepare the memory for an I/O transfer.
55e303ae 517 @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.
1c79356b
A
518 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
519 @result An IOReturn code. */
520
521 virtual IOReturn prepare(IODirection forDirection = kIODirectionNone) = 0;
522
523/*! @function complete
524 @abstract Complete processing of the memory after an I/O transfer finishes.
55e303ae
A
525 @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.
526 @param forDirection DEPRECATED The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
1c79356b
A
527 @result An IOReturn code. */
528
529 virtual IOReturn complete(IODirection forDirection = kIODirectionNone) = 0;
530
531 /*
532 * Mapping functions.
533 */
534
535/*! @function map
536 @abstract Maps a IOMemoryDescriptor into a task.
537 @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.
538 @param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space.
539 @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
540 @param options Mapping options are defined in IOTypes.h,<br>
541 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>
542 kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br>
543 kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br>
544 kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br>
545 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>
91447636 546 kIOMapUnique allows a special kind of mapping to be created that may be used with the IOMemoryMap::redirect() API. These mappings will not be shared as is the default - there will always be a unique mapping created for the caller, not an existing mapping with an extra reference.<br>
1c79356b
A
547 @param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
548 @param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
549 @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. */
550
551 virtual IOMemoryMap * map(
552 task_t intoTask,
553 IOVirtualAddress atAddress,
554 IOOptionBits options,
555 IOByteCount offset = 0,
556 IOByteCount length = 0 );
557
558/*! @function map
559 @abstract Maps a IOMemoryDescriptor into the kernel map.
560 @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.
561 @param options Mapping options as in the full version of the map method, with kIOMapAnywhere assumed.
562 @result See the full version of the map method. */
563
564 virtual IOMemoryMap * map(
565 IOOptionBits options = 0 );
566
567/*! @function setMapping
568 @abstract Establishes an already existing mapping.
569 @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.
570 @param task Address space in which the mapping exists.
571 @param mapAddress Virtual address of the mapping.
572 @param options Caching and read-only attributes of the mapping.
573 @result A IOMemoryMap object created to represent the mapping. */
574
575 virtual IOMemoryMap * setMapping(
576 task_t task,
577 IOVirtualAddress mapAddress,
578 IOOptionBits options = 0 );
579
e3027f41
A
580 // Following methods are private implementation
581
582 // make virtual
583 IOReturn redirect( task_t safeTask, bool redirect );
584
0b4e3aa0
A
585 IOReturn handleFault(
586 void * pager,
587 vm_map_t addressMap,
588 IOVirtualAddress address,
589 IOByteCount sourceOffset,
590 IOByteCount length,
591 IOOptionBits options );
592
1c79356b
A
593protected:
594 virtual IOMemoryMap * makeMapping(
595 IOMemoryDescriptor * owner,
596 task_t intoTask,
597 IOVirtualAddress atAddress,
598 IOOptionBits options,
599 IOByteCount offset,
600 IOByteCount length );
601
602 virtual void addMapping(
603 IOMemoryMap * mapping );
604
605 virtual void removeMapping(
606 IOMemoryMap * mapping );
607
608 virtual IOReturn doMap(
609 vm_map_t addressMap,
610 IOVirtualAddress * atAddress,
611 IOOptionBits options,
612 IOByteCount sourceOffset = 0,
613 IOByteCount length = 0 );
614
615 virtual IOReturn doUnmap(
616 vm_map_t addressMap,
617 IOVirtualAddress logical,
618 IOByteCount length );
619};
620
621/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
622
623/*! @class IOMemoryMap : public OSObject
624 @abstract An abstract base class defining common methods for describing a memory mapping.
625 @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. */
626
627class IOMemoryMap : public OSObject
628{
629 OSDeclareAbstractStructors(IOMemoryMap)
630
631public:
632/*! @function getVirtualAddress
633 @abstract Accessor to the virtual address of the first byte in the mapping.
634 @discussion This method returns the virtual address of the first byte in the mapping.
635 @result A virtual address. */
636
637 virtual IOVirtualAddress getVirtualAddress() = 0;
638
639/*! @function getPhysicalSegment
640 @abstract Break a mapping into its physically contiguous segments.
641 @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.
642 @param offset A byte offset into the mapping whose physical address to return.
643 @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
644 @result A physical address, or zero if the offset is beyond the length of the mapping. */
645
646 virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
647 IOByteCount * length) = 0;
648
649/*! @function getPhysicalAddress
650 @abstract Return the physical address of the first byte in the mapping.
651 @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.
652 @result A physical address. */
653
9bccf70c
A
654 /* inline */ IOPhysicalAddress getPhysicalAddress();
655 /* { return( getPhysicalSegment( 0, 0 )); } */
1c79356b
A
656
657/*! @function getLength
658 @abstract Accessor to the length of the mapping.
659 @discussion This method returns the length of the mapping.
660 @result A byte count. */
661
662 virtual IOByteCount getLength() = 0;
663
664/*! @function getAddressTask
665 @abstract Accessor to the task of the mapping.
666 @discussion This method returns the mach task the mapping exists in.
667 @result A mach task_t. */
668
669 virtual task_t getAddressTask() = 0;
670
671/*! @function getMemoryDescriptor
672 @abstract Accessor to the IOMemoryDescriptor the mapping was created from.
673 @discussion This method returns the IOMemoryDescriptor the mapping was created from.
674 @result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */
675
676 virtual IOMemoryDescriptor * getMemoryDescriptor() = 0;
677
678/*! @function getMapOptions
679 @abstract Accessor to the options the mapping was created with.
680 @discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with.
681 @result Options for the mapping, including cache settings. */
682
683 virtual IOOptionBits getMapOptions() = 0;
684
685/*! @function unmap
686 @abstract Force the IOMemoryMap to unmap, without destroying the object.
687 @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.
688 @result An IOReturn code. */
689
690 virtual IOReturn unmap() = 0;
691
55e303ae 692 virtual void taskDied() = 0;
91447636
A
693
694/*! @function redirect
695 @abstract Replace the memory mapped in a process with new backing memory.
696 @discussion An IOMemoryMap created with the kIOMapUnique option to IOMemoryDescriptor::map() can remapped to a new IOMemoryDescriptor backing object. If the new IOMemoryDescriptor is specified as NULL, client access to the memory map is blocked until a new backing object has been set. By blocking access and copying data, the caller can create atomic copies of the memory while the client is potentially reading or writing the memory.
697 @param newBackingMemory The IOMemoryDescriptor that represents the physical memory that is to be now mapped in the virtual range the IOMemoryMap represents. If newBackingMemory is NULL, any access to the mapping will hang (in vm_fault()) until access has been restored by a new call to redirect() with non-NULL newBackingMemory argument.
698 @param options Mapping options are defined in IOTypes.h, and are documented in IOMemoryDescriptor::map()
699 @param offset As with IOMemoryDescriptor::map(), a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default.
700 @result An IOReturn code. */
701
702 virtual IOReturn redirect(IOMemoryDescriptor * newBackingMemory,
703 IOOptionBits options,
704 IOByteCount offset = 0) = 0;
1c79356b
A
705};
706
707/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
708
e3027f41 709// The following classes are private implementation of IOMemoryDescriptor - they
0b4e3aa0
A
710// should not be referenced directly, just through the public API's in the
711// IOMemoryDescriptor class. For example, an IOGeneralMemoryDescriptor instance
712// might be created by IOMemoryDescriptor::withAddress(), but there should be
713// no need to reference as anything but a generic IOMemoryDescriptor *.
e3027f41 714
55e303ae
A
715// Also these flags should not overlap with the options to
716// IOMemoryDescriptor::initWithRanges(... IOOptionsBits options);
717
1c79356b 718enum {
55e303ae 719 kIOMemoryPreparedReadOnly = 0x00008000,
1c79356b
A
720};
721
722class IOGeneralMemoryDescriptor : public IOMemoryDescriptor
723{
724 OSDeclareDefaultStructors(IOGeneralMemoryDescriptor);
725
91447636
A
726public:
727 union Ranges {
c0fea474
A
728 IOVirtualRange *v;
729 IOAddressRange *v64;
730 IOPhysicalRange *p;
91447636
A
731 void *uio;
732 };
733protected:
734 Ranges _ranges;
1c79356b
A
735 unsigned _rangesCount; /* number of address ranges in list */
736 bool _rangesIsAllocated; /* is list allocated by us? */
737
738 task_t _task; /* task where all ranges are mapped to */
739
740 union {
55e303ae
A
741 IOVirtualRange v;
742 IOPhysicalRange p;
1c79356b
A
743 } _singleRange; /* storage space for a single range */
744
745 unsigned _wireCount; /* number of outstanding wires */
746
55e303ae
A
747 /* DEPRECATED */ vm_address_t _cachedVirtualAddress; /* a cached virtual-to-physical */
748
749 /* DEPRECATED */ IOPhysicalAddress _cachedPhysicalAddress;
1c79356b
A
750
751 bool _initialized; /* has superclass been initialized? */
752
753 virtual void free();
754
c0fea474
A
755#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
756 virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
757#endif
55e303ae
A
758
759private:
91447636 760
0b4e3aa0 761 /* DEPRECATED */ virtual void setPosition(IOByteCount position);
0b4e3aa0
A
762 /* DEPRECATED */ virtual void mapIntoKernel(unsigned rangeIndex);
763 /* DEPRECATED */ virtual void unmapFromKernel();
1c79356b 764
c0fea474
A
765 // Internal APIs may be made virtual at some time in the future.
766 IOReturn wireVirtual(IODirection forDirection);
767 void *createNamedEntry();
768
769 // Internal
770 OSData * _memoryEntries;
771 unsigned int _pages;
772 ppnum_t _highestPage;
773 uint32_t __iomd_reservedA;
774 uint32_t __iomd_reservedB;
775 uint32_t __iomd_reservedC;
776
1c79356b
A
777public:
778 /*
779 * IOMemoryDescriptor required methods
780 */
781
55e303ae
A
782 // Master initaliser
783 virtual bool initWithOptions(void * buffers,
784 UInt32 count,
785 UInt32 offset,
786 task_t task,
787 IOOptionBits options,
c0fea474 788 IOMapper * mapper = kIOMapperSystem);
d7e50217 789
55e303ae
A
790 // Secondary initialisers
791 virtual bool initWithAddress(void * address,
792 IOByteCount withLength,
793 IODirection withDirection);
794
795 virtual bool initWithAddress(vm_address_t address,
1c79356b 796 IOByteCount withLength,
55e303ae
A
797 IODirection withDirection,
798 task_t withTask);
1c79356b
A
799
800 virtual bool initWithPhysicalAddress(
801 IOPhysicalAddress address,
802 IOByteCount withLength,
803 IODirection withDirection );
804
805 virtual bool initWithRanges( IOVirtualRange * ranges,
806 UInt32 withCount,
807 IODirection withDirection,
808 task_t withTask,
809 bool asReference = false);
810
811 virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
812 UInt32 withCount,
813 IODirection withDirection,
814 bool asReference = false);
815
c0fea474
A
816#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
817 virtual addr64_t getPhysicalSegment64( IOByteCount offset,
818 IOByteCount * length );
819#endif
820
1c79356b
A
821 virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
822 IOByteCount * length);
823
0b4e3aa0
A
824 virtual IOPhysicalAddress getSourceSegment(IOByteCount offset,
825 IOByteCount * length);
826
827 /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset,
828 /* DEPRECATED */ IOByteCount * length);
1c79356b
A
829
830 virtual IOReturn prepare(IODirection forDirection = kIODirectionNone);
831
832 virtual IOReturn complete(IODirection forDirection = kIODirectionNone);
833
834 virtual IOReturn doMap(
835 vm_map_t addressMap,
836 IOVirtualAddress * atAddress,
837 IOOptionBits options,
838 IOByteCount sourceOffset = 0,
839 IOByteCount length = 0 );
840
841 virtual IOReturn doUnmap(
842 vm_map_t addressMap,
843 IOVirtualAddress logical,
844 IOByteCount length );
9bccf70c 845 virtual bool serialize(OSSerialize *s) const;
91447636
A
846
847 // Factory method for cloning a persistent IOMD, see IOMemoryDescriptor
848 static IOMemoryDescriptor *
849 withPersistentMemoryDescriptor(IOGeneralMemoryDescriptor *originalMD);
1c79356b
A
850};
851
852/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
853
854class IOSubMemoryDescriptor : public IOMemoryDescriptor
855{
9bccf70c 856 friend class IOMemoryDescriptor;
1c79356b
A
857
858 OSDeclareDefaultStructors(IOSubMemoryDescriptor);
859
860protected:
861 IOMemoryDescriptor * _parent;
862 IOByteCount _start;
863
864 virtual void free();
865
1c79356b
A
866 virtual bool initWithAddress(void * address,
867 IOByteCount withLength,
868 IODirection withDirection);
869
870 virtual bool initWithAddress(vm_address_t address,
871 IOByteCount withLength,
872 IODirection withDirection,
873 task_t withTask);
874
875 virtual bool initWithPhysicalAddress(
876 IOPhysicalAddress address,
877 IOByteCount withLength,
878 IODirection withDirection );
879
880 virtual bool initWithRanges( IOVirtualRange * ranges,
881 UInt32 withCount,
882 IODirection withDirection,
883 task_t withTask,
884 bool asReference = false);
885
886 virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
887 UInt32 withCount,
888 IODirection withDirection,
889 bool asReference = false);
890
891 IOMemoryDescriptor::withAddress;
892 IOMemoryDescriptor::withPhysicalAddress;
893 IOMemoryDescriptor::withPhysicalRanges;
894 IOMemoryDescriptor::withRanges;
895 IOMemoryDescriptor::withSubRange;
896
c0fea474
A
897#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
898 // used by IODMACommand
899 virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
900#endif
901
1c79356b 902public:
55e303ae
A
903 /*
904 * Initialize or reinitialize an IOSubMemoryDescriptor to describe
905 * a subrange of an existing descriptor.
906 *
907 * An IOSubMemoryDescriptor can be re-used by calling initSubRange
908 * again on an existing instance -- note that this behavior is not
909 * commonly supported in other IOKit classes, although it is here.
910 */
911 virtual bool initSubRange( IOMemoryDescriptor * parent,
912 IOByteCount offset, IOByteCount length,
913 IODirection withDirection );
914
1c79356b
A
915 /*
916 * IOMemoryDescriptor required methods
917 */
918
c0fea474
A
919#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
920 virtual addr64_t getPhysicalSegment64( IOByteCount offset,
921 IOByteCount * length );
922#endif
923
1c79356b
A
924 virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
925 IOByteCount * length);
926
0b4e3aa0
A
927 virtual IOPhysicalAddress getSourceSegment(IOByteCount offset,
928 IOByteCount * length);
929
1c79356b
A
930 virtual IOByteCount readBytes(IOByteCount offset,
931 void * bytes, IOByteCount withLength);
932
933 virtual IOByteCount writeBytes(IOByteCount offset,
934 const void * bytes, IOByteCount withLength);
935
936 virtual void * getVirtualSegment(IOByteCount offset,
937 IOByteCount * length);
938
939 virtual IOReturn prepare(IODirection forDirection = kIODirectionNone);
940
941 virtual IOReturn complete(IODirection forDirection = kIODirectionNone);
942
e3027f41
A
943 // make virtual
944 IOReturn redirect( task_t safeTask, bool redirect );
945
9bccf70c
A
946 virtual bool serialize(OSSerialize *s) const;
947
91447636
A
948 virtual IOReturn setPurgeable( IOOptionBits newState,
949 IOOptionBits * oldState );
950 virtual IOReturn performOperation( IOOptionBits options,
951 IOByteCount offset, IOByteCount length );
952
1c79356b
A
953protected:
954 virtual IOMemoryMap * makeMapping(
955 IOMemoryDescriptor * owner,
956 task_t intoTask,
957 IOVirtualAddress atAddress,
958 IOOptionBits options,
959 IOByteCount offset,
960 IOByteCount length );
91447636
A
961
962 virtual IOReturn doMap(
963 vm_map_t addressMap,
964 IOVirtualAddress * atAddress,
965 IOOptionBits options,
966 IOByteCount sourceOffset = 0,
967 IOByteCount length = 0 );
1c79356b
A
968};
969
970/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
971
972#endif /* !_IOMEMORYDESCRIPTOR_H */