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