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