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