]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | #ifndef _IOMEMORYDESCRIPTOR_H | |
23 | #define _IOMEMORYDESCRIPTOR_H | |
24 | ||
25 | #include <IOKit/IOTypes.h> | |
26 | #include <libkern/c++/OSContainers.h> | |
27 | ||
28 | struct IOPhysicalRange | |
29 | { | |
30 | IOPhysicalAddress address; | |
31 | IOByteCount length; | |
32 | }; | |
33 | ||
34 | class IOMemoryMap; | |
35 | ||
36 | /* | |
37 | * Direction of transfer, with respect to the described memory. | |
38 | */ | |
39 | enum IODirection | |
40 | { | |
41 | kIODirectionNone = 0x0, // same as VM_PROT_NONE | |
42 | kIODirectionIn = 0x1, // User land 'read', same as VM_PROT_READ | |
43 | kIODirectionOut = 0x2, // User land 'write', same as VM_PROT_WRITE | |
44 | kIODirectionOutIn = kIODirectionIn | kIODirectionOut, | |
45 | }; | |
46 | ||
47 | /*! @class IOMemoryDescriptor : public OSObject | |
48 | @abstract An abstract base class defining common methods for describing physical or virtual memory. | |
49 | @discussion The IOMemoryDescriptor object represents a buffer or range of memory, specified as one or more physical or virtual address ranges. It contains methods to return the memory's physically contiguous segments (fragments), for use with the IOMemoryCursor, and methods to map the memory into any address space with caching and placed mapping options. */ | |
50 | ||
51 | class IOMemoryDescriptor : public OSObject | |
52 | { | |
53 | friend class _IOMemoryMap; | |
54 | friend class IOSubMemoryDescriptor; | |
55 | ||
56 | OSDeclareDefaultStructors(IOMemoryDescriptor); | |
57 | ||
58 | protected: | |
59 | /*! @struct ExpansionData | |
60 | @discussion This structure will be used to expand the capablilties of this class in the future. | |
61 | */ | |
0b4e3aa0 A |
62 | struct ExpansionData { |
63 | void * devicePager; | |
64 | unsigned int pagerContig:1; | |
65 | unsigned int unused:31; | |
66 | }; | |
1c79356b A |
67 | |
68 | /*! @var reserved | |
69 | Reserved for future use. (Internal use only) */ | |
70 | ExpansionData * reserved; | |
71 | ||
72 | protected: | |
73 | OSSet * _mappings; | |
74 | IOOptionBits _flags; | |
75 | void * _memEntry; | |
76 | ||
77 | IODirection _direction; /* direction of transfer */ | |
78 | IOByteCount _length; /* length of all ranges */ | |
79 | IOOptionBits _tag; | |
80 | ||
0b4e3aa0 A |
81 | public: |
82 | ||
83 | virtual IOPhysicalAddress getSourceSegment( IOByteCount offset, | |
84 | IOByteCount * length ); | |
85 | ||
1c79356b | 86 | private: |
0b4e3aa0 | 87 | OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 0); |
1c79356b A |
88 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 1); |
89 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 2); | |
90 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 3); | |
91 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 4); | |
92 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 5); | |
93 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 6); | |
94 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 7); | |
95 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 8); | |
96 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 9); | |
97 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 10); | |
98 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 11); | |
99 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 12); | |
100 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 13); | |
101 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 14); | |
102 | OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 15); | |
103 | ||
104 | protected: | |
105 | virtual void free(); | |
106 | public: | |
107 | static void initialize( void ); | |
108 | ||
109 | public: | |
110 | /*! @function withAddress | |
111 | @abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task. | |
112 | @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map. | |
113 | @param address The virtual address of the first byte in the memory. | |
114 | @param withLength The length of memory. | |
115 | @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. | |
116 | @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */ | |
117 | ||
118 | static IOMemoryDescriptor * withAddress(void * address, | |
119 | IOByteCount withLength, | |
120 | IODirection withDirection); | |
121 | ||
122 | /*! @function withAddress | |
123 | @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map. | |
124 | @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map. | |
125 | @param address The virtual address of the first byte in the memory. | |
126 | @param withLength The length of memory. | |
127 | @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. | |
128 | @param withTask The task the virtual ranges are mapped into. | |
129 | @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */ | |
130 | ||
131 | static IOMemoryDescriptor * withAddress(vm_address_t address, | |
132 | IOByteCount withLength, | |
133 | IODirection withDirection, | |
134 | task_t withTask); | |
135 | ||
136 | /*! @function withPhysicalAddress | |
137 | @abstract Create an IOMemoryDescriptor to describe one physical range. | |
138 | @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range. | |
139 | @param address The physical address of the first byte in the memory. | |
140 | @param withLength The length of memory. | |
141 | @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. | |
142 | @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */ | |
143 | ||
144 | static IOMemoryDescriptor * withPhysicalAddress( | |
145 | IOPhysicalAddress address, | |
146 | IOByteCount withLength, | |
147 | IODirection withDirection ); | |
148 | ||
149 | /*! @function withRanges | |
150 | @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges. | |
151 | @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. | |
152 | @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described. | |
153 | @param withCount The member count of the ranges array. | |
154 | @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. | |
155 | @param withTask The task each of the virtual ranges are mapped into. | |
156 | @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. | |
157 | @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */ | |
158 | ||
159 | static IOMemoryDescriptor * withRanges(IOVirtualRange * ranges, | |
160 | UInt32 withCount, | |
161 | IODirection withDirection, | |
162 | task_t withTask, | |
163 | bool asReference = false); | |
164 | ||
165 | /*! @function withPhysicalRanges | |
166 | @abstract Create an IOMemoryDescriptor to describe one or more physical ranges. | |
167 | @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges. | |
168 | @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described. | |
169 | @param withCount The member count of the ranges array. | |
170 | @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. | |
171 | @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. | |
172 | @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */ | |
173 | ||
174 | static IOMemoryDescriptor * withPhysicalRanges( | |
175 | IOPhysicalRange * ranges, | |
176 | UInt32 withCount, | |
177 | IODirection withDirection, | |
178 | bool asReference = false); | |
179 | ||
180 | /*! @function withSubRange | |
181 | @abstract Create an IOMemoryDescriptor to describe a subrange of an existing descriptor. | |
182 | @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. | |
183 | @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. | |
184 | @param offset A byte offset into the parent memory descriptor's memory. | |
185 | @param length The length of the subrange. | |
186 | @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. | |
187 | @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */ | |
188 | ||
189 | static IOMemoryDescriptor * withSubRange(IOMemoryDescriptor * of, | |
190 | IOByteCount offset, | |
191 | IOByteCount length, | |
192 | IODirection withDirection); | |
193 | ||
194 | /*! @function initWithAddress | |
195 | @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the kernel task. | |
196 | @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. | |
197 | @param address The virtual address of the first byte in the memory. | |
198 | @param withLength The length of memory. | |
199 | @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. | |
200 | @result true on success, false on failure. */ | |
201 | ||
202 | virtual bool initWithAddress(void * address, | |
203 | IOByteCount withLength, | |
204 | IODirection withDirection) = 0; | |
205 | ||
206 | /*! @function initWithAddress | |
207 | @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the specified map. | |
208 | @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. | |
209 | @param address The virtual address of the first byte in the memory. | |
210 | @param withLength The length of memory. | |
211 | @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. | |
212 | @param withTask The task the virtual ranges are mapped into. | |
213 | @result true on success, false on failure. */ | |
214 | ||
215 | virtual bool initWithAddress(vm_address_t address, | |
216 | IOByteCount withLength, | |
217 | IODirection withDirection, | |
218 | task_t withTask) = 0; | |
219 | ||
220 | /*! @function initWithPhysicalAddress | |
221 | @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one physical range. | |
222 | @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. | |
223 | @param address The physical address of the first byte in the memory. | |
224 | @param withLength The length of memory. | |
225 | @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. | |
226 | @result true on success, false on failure. */ | |
227 | ||
228 | virtual bool initWithPhysicalAddress( | |
229 | IOPhysicalAddress address, | |
230 | IOByteCount withLength, | |
231 | IODirection withDirection ) = 0; | |
232 | ||
233 | /*! @function initWithRanges | |
234 | @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more virtual ranges. | |
235 | @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. | |
236 | @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described. | |
237 | @param withCount The member count of the ranges array. | |
238 | @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. | |
239 | @param withTask The task each of the virtual ranges are mapped into. | |
240 | @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. | |
241 | @result true on success, false on failure. */ | |
242 | ||
243 | virtual bool initWithRanges( IOVirtualRange * ranges, | |
244 | UInt32 withCount, | |
245 | IODirection withDirection, | |
246 | task_t withTask, | |
247 | bool asReference = false) = 0; | |
248 | ||
249 | /*! @function initWithPhysicalRanges | |
250 | @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more physical ranges. | |
251 | @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. | |
252 | @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described. | |
253 | @param withCount The member count of the ranges array. | |
254 | @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. | |
255 | @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. | |
256 | @result true on success, false on failure. */ | |
257 | ||
258 | virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges, | |
259 | UInt32 withCount, | |
260 | IODirection withDirection, | |
261 | bool asReference = false) = 0; | |
262 | ||
263 | /*! @function getDirection | |
264 | @abstract Accessor to get the direction the memory descriptor was created with. | |
265 | @discussion This method returns the direction the memory descriptor was created with. | |
266 | @result The direction. */ | |
267 | ||
268 | virtual IODirection getDirection() const; | |
269 | ||
270 | /*! @function getLength | |
271 | @abstract Accessor to get the length of the memory descriptor (over all its ranges). | |
272 | @discussion This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths. | |
273 | @result The byte count. */ | |
274 | ||
275 | virtual IOByteCount getLength() const; | |
276 | ||
277 | /*! @function setTag | |
278 | @abstract Set the tag for the memory descriptor. | |
279 | @discussion This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor. | |
280 | @param tag The tag. */ | |
281 | ||
282 | virtual void setTag( IOOptionBits tag ); | |
283 | ||
284 | /*! @function getTag | |
285 | @abstract Accessor to the retrieve the tag for the memory descriptor. | |
286 | @discussion This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor. | |
287 | @result The tag. */ | |
288 | ||
289 | virtual IOOptionBits getTag( void ); | |
290 | ||
291 | /*! @function readBytes | |
292 | @abstract Copy data from the memory descriptor's buffer to the specified buffer. | |
293 | @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer. | |
294 | @param offset A byte offset into the memory descriptor's memory. | |
295 | @param bytes The caller supplied buffer to copy the data to. | |
296 | @param withLength The length of the data to copy. | |
297 | @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */ | |
298 | ||
299 | virtual IOByteCount readBytes(IOByteCount offset, | |
0b4e3aa0 | 300 | void * bytes, IOByteCount withLength); |
1c79356b A |
301 | |
302 | /*! @function writeBytes | |
303 | @abstract Copy data to the memory descriptor's buffer from the specified buffer. | |
304 | @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer. | |
305 | @param offset A byte offset into the memory descriptor's memory. | |
306 | @param bytes The caller supplied buffer to copy the data from. | |
307 | @param withLength The length of the data to copy. | |
308 | @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */ | |
309 | ||
310 | virtual IOByteCount writeBytes(IOByteCount offset, | |
0b4e3aa0 | 311 | const void * bytes, IOByteCount withLength); |
1c79356b A |
312 | |
313 | /*! @function getPhysicalSegment | |
314 | @abstract Break a memory descriptor into its physically contiguous segments. | |
315 | @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. | |
316 | @param offset A byte offset into the memory whose physical address to return. | |
317 | @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset. | |
318 | @result A physical address, or zero if the offset is beyond the length of the memory. */ | |
319 | ||
320 | virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset, | |
321 | IOByteCount * length) = 0; | |
322 | ||
323 | /*! @function getPhysicalAddress | |
324 | @abstract Return the physical address of the first byte in the memory. | |
325 | @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. | |
326 | @result A physical address. */ | |
327 | ||
328 | inline IOPhysicalAddress getPhysicalAddress() | |
329 | { return( getPhysicalSegment( 0, 0 )); } | |
330 | ||
0b4e3aa0 A |
331 | /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */ |
332 | /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset, | |
333 | /* DEPRECATED */ IOByteCount * length) = 0; | |
334 | /* DEPRECATED */ /* USE INSTEAD: map(), readBytes(), writeBytes() */ | |
1c79356b A |
335 | |
336 | /*! @function prepare | |
337 | @abstract Prepare the memory for an I/O transfer. | |
338 | @discussion This involves paging in the memory, if necessary, and wiring it down for the duration of the transfer. The complete() method completes the processing of the memory after the I/O transfer finishes. This method needn't called for non-pageable memory. | |
339 | @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor. | |
340 | @result An IOReturn code. */ | |
341 | ||
342 | virtual IOReturn prepare(IODirection forDirection = kIODirectionNone) = 0; | |
343 | ||
344 | /*! @function complete | |
345 | @abstract Complete processing of the memory after an I/O transfer finishes. | |
346 | @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. | |
347 | @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor. | |
348 | @result An IOReturn code. */ | |
349 | ||
350 | virtual IOReturn complete(IODirection forDirection = kIODirectionNone) = 0; | |
351 | ||
352 | /* | |
353 | * Mapping functions. | |
354 | */ | |
355 | ||
356 | /*! @function map | |
357 | @abstract Maps a IOMemoryDescriptor into a task. | |
358 | @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. | |
359 | @param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space. | |
360 | @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored. | |
361 | @param options Mapping options are defined in IOTypes.h,<br> | |
362 | 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> | |
363 | kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br> | |
364 | kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br> | |
365 | kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br> | |
366 | 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> | |
367 | @param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory. | |
368 | @param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory. | |
369 | @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. */ | |
370 | ||
371 | virtual IOMemoryMap * map( | |
372 | task_t intoTask, | |
373 | IOVirtualAddress atAddress, | |
374 | IOOptionBits options, | |
375 | IOByteCount offset = 0, | |
376 | IOByteCount length = 0 ); | |
377 | ||
378 | /*! @function map | |
379 | @abstract Maps a IOMemoryDescriptor into the kernel map. | |
380 | @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. | |
381 | @param options Mapping options as in the full version of the map method, with kIOMapAnywhere assumed. | |
382 | @result See the full version of the map method. */ | |
383 | ||
384 | virtual IOMemoryMap * map( | |
385 | IOOptionBits options = 0 ); | |
386 | ||
387 | /*! @function setMapping | |
388 | @abstract Establishes an already existing mapping. | |
389 | @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. | |
390 | @param task Address space in which the mapping exists. | |
391 | @param mapAddress Virtual address of the mapping. | |
392 | @param options Caching and read-only attributes of the mapping. | |
393 | @result A IOMemoryMap object created to represent the mapping. */ | |
394 | ||
395 | virtual IOMemoryMap * setMapping( | |
396 | task_t task, | |
397 | IOVirtualAddress mapAddress, | |
398 | IOOptionBits options = 0 ); | |
399 | ||
e3027f41 A |
400 | // Following methods are private implementation |
401 | ||
402 | // make virtual | |
403 | IOReturn redirect( task_t safeTask, bool redirect ); | |
404 | ||
0b4e3aa0 A |
405 | IOReturn handleFault( |
406 | void * pager, | |
407 | vm_map_t addressMap, | |
408 | IOVirtualAddress address, | |
409 | IOByteCount sourceOffset, | |
410 | IOByteCount length, | |
411 | IOOptionBits options ); | |
412 | ||
1c79356b A |
413 | protected: |
414 | virtual IOMemoryMap * makeMapping( | |
415 | IOMemoryDescriptor * owner, | |
416 | task_t intoTask, | |
417 | IOVirtualAddress atAddress, | |
418 | IOOptionBits options, | |
419 | IOByteCount offset, | |
420 | IOByteCount length ); | |
421 | ||
422 | virtual void addMapping( | |
423 | IOMemoryMap * mapping ); | |
424 | ||
425 | virtual void removeMapping( | |
426 | IOMemoryMap * mapping ); | |
427 | ||
428 | virtual IOReturn doMap( | |
429 | vm_map_t addressMap, | |
430 | IOVirtualAddress * atAddress, | |
431 | IOOptionBits options, | |
432 | IOByteCount sourceOffset = 0, | |
433 | IOByteCount length = 0 ); | |
434 | ||
435 | virtual IOReturn doUnmap( | |
436 | vm_map_t addressMap, | |
437 | IOVirtualAddress logical, | |
438 | IOByteCount length ); | |
439 | }; | |
440 | ||
441 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
442 | ||
443 | /*! @class IOMemoryMap : public OSObject | |
444 | @abstract An abstract base class defining common methods for describing a memory mapping. | |
445 | @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. */ | |
446 | ||
447 | class IOMemoryMap : public OSObject | |
448 | { | |
449 | OSDeclareAbstractStructors(IOMemoryMap) | |
450 | ||
451 | public: | |
452 | /*! @function getVirtualAddress | |
453 | @abstract Accessor to the virtual address of the first byte in the mapping. | |
454 | @discussion This method returns the virtual address of the first byte in the mapping. | |
455 | @result A virtual address. */ | |
456 | ||
457 | virtual IOVirtualAddress getVirtualAddress() = 0; | |
458 | ||
459 | /*! @function getPhysicalSegment | |
460 | @abstract Break a mapping into its physically contiguous segments. | |
461 | @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. | |
462 | @param offset A byte offset into the mapping whose physical address to return. | |
463 | @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset. | |
464 | @result A physical address, or zero if the offset is beyond the length of the mapping. */ | |
465 | ||
466 | virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset, | |
467 | IOByteCount * length) = 0; | |
468 | ||
469 | /*! @function getPhysicalAddress | |
470 | @abstract Return the physical address of the first byte in the mapping. | |
471 | @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. | |
472 | @result A physical address. */ | |
473 | ||
474 | inline IOPhysicalAddress getPhysicalAddress() | |
475 | { return( getPhysicalSegment( 0, 0 )); } | |
476 | ||
477 | /*! @function getLength | |
478 | @abstract Accessor to the length of the mapping. | |
479 | @discussion This method returns the length of the mapping. | |
480 | @result A byte count. */ | |
481 | ||
482 | virtual IOByteCount getLength() = 0; | |
483 | ||
484 | /*! @function getAddressTask | |
485 | @abstract Accessor to the task of the mapping. | |
486 | @discussion This method returns the mach task the mapping exists in. | |
487 | @result A mach task_t. */ | |
488 | ||
489 | virtual task_t getAddressTask() = 0; | |
490 | ||
491 | /*! @function getMemoryDescriptor | |
492 | @abstract Accessor to the IOMemoryDescriptor the mapping was created from. | |
493 | @discussion This method returns the IOMemoryDescriptor the mapping was created from. | |
494 | @result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */ | |
495 | ||
496 | virtual IOMemoryDescriptor * getMemoryDescriptor() = 0; | |
497 | ||
498 | /*! @function getMapOptions | |
499 | @abstract Accessor to the options the mapping was created with. | |
500 | @discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with. | |
501 | @result Options for the mapping, including cache settings. */ | |
502 | ||
503 | virtual IOOptionBits getMapOptions() = 0; | |
504 | ||
505 | /*! @function unmap | |
506 | @abstract Force the IOMemoryMap to unmap, without destroying the object. | |
507 | @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. | |
508 | @result An IOReturn code. */ | |
509 | ||
510 | virtual IOReturn unmap() = 0; | |
511 | ||
512 | virtual void taskDied() = 0; | |
513 | }; | |
514 | ||
515 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
516 | ||
e3027f41 | 517 | // The following classes are private implementation of IOMemoryDescriptor - they |
0b4e3aa0 A |
518 | // should not be referenced directly, just through the public API's in the |
519 | // IOMemoryDescriptor class. For example, an IOGeneralMemoryDescriptor instance | |
520 | // might be created by IOMemoryDescriptor::withAddress(), but there should be | |
521 | // no need to reference as anything but a generic IOMemoryDescriptor *. | |
e3027f41 | 522 | |
1c79356b A |
523 | enum { |
524 | kIOMemoryRequiresWire = 0x00000001 | |
525 | }; | |
526 | ||
527 | class IOGeneralMemoryDescriptor : public IOMemoryDescriptor | |
528 | { | |
529 | OSDeclareDefaultStructors(IOGeneralMemoryDescriptor); | |
530 | ||
531 | protected: | |
532 | union { | |
533 | IOVirtualRange * v; | |
534 | IOPhysicalRange * p; | |
535 | } _ranges; /* list of address ranges */ | |
536 | unsigned _rangesCount; /* number of address ranges in list */ | |
537 | bool _rangesIsAllocated; /* is list allocated by us? */ | |
538 | ||
539 | task_t _task; /* task where all ranges are mapped to */ | |
540 | ||
541 | union { | |
542 | IOVirtualRange v; | |
543 | IOPhysicalRange p; | |
544 | } _singleRange; /* storage space for a single range */ | |
545 | ||
546 | unsigned _wireCount; /* number of outstanding wires */ | |
547 | ||
548 | vm_address_t _cachedVirtualAddress; /* a cached virtual-to-physical */ | |
549 | IOPhysicalAddress _cachedPhysicalAddress; /* mapping, for optimization */ | |
550 | ||
551 | bool _initialized; /* has superclass been initialized? */ | |
552 | ||
553 | virtual void free(); | |
554 | ||
0b4e3aa0 A |
555 | protected: |
556 | /* DEPRECATED */ IOByteCount _position; /* absolute position over all ranges */ | |
557 | /* DEPRECATED */ virtual void setPosition(IOByteCount position); | |
1c79356b A |
558 | |
559 | private: | |
0b4e3aa0 A |
560 | /* DEPRECATED */ unsigned _positionAtIndex; /* range #n in which position is now */ |
561 | /* DEPRECATED */ IOByteCount _positionAtOffset; /* relative position within range #n */ | |
1c79356b A |
562 | OSData *_memoryEntries; |
563 | ||
0b4e3aa0 A |
564 | /* DEPRECATED */ vm_offset_t _kernPtrAligned; |
565 | /* DEPRECATED */ unsigned _kernPtrAtIndex; | |
566 | /* DEPRECATED */ IOByteCount _kernSize; | |
567 | /* DEPRECATED */ virtual void mapIntoKernel(unsigned rangeIndex); | |
568 | /* DEPRECATED */ virtual void unmapFromKernel(); | |
1c79356b A |
569 | inline vm_map_t getMapForTask( task_t task, vm_address_t address ); |
570 | ||
571 | public: | |
572 | /* | |
573 | * IOMemoryDescriptor required methods | |
574 | */ | |
575 | ||
576 | virtual bool initWithAddress(void * address, | |
577 | IOByteCount withLength, | |
578 | IODirection withDirection); | |
579 | ||
580 | virtual bool initWithAddress(vm_address_t address, | |
581 | IOByteCount withLength, | |
582 | IODirection withDirection, | |
583 | task_t withTask); | |
584 | ||
585 | virtual bool initWithPhysicalAddress( | |
586 | IOPhysicalAddress address, | |
587 | IOByteCount withLength, | |
588 | IODirection withDirection ); | |
589 | ||
590 | virtual bool initWithRanges( IOVirtualRange * ranges, | |
591 | UInt32 withCount, | |
592 | IODirection withDirection, | |
593 | task_t withTask, | |
594 | bool asReference = false); | |
595 | ||
596 | virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges, | |
597 | UInt32 withCount, | |
598 | IODirection withDirection, | |
599 | bool asReference = false); | |
600 | ||
1c79356b A |
601 | virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset, |
602 | IOByteCount * length); | |
603 | ||
0b4e3aa0 A |
604 | virtual IOPhysicalAddress getSourceSegment(IOByteCount offset, |
605 | IOByteCount * length); | |
606 | ||
607 | /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset, | |
608 | /* DEPRECATED */ IOByteCount * length); | |
1c79356b A |
609 | |
610 | virtual IOReturn prepare(IODirection forDirection = kIODirectionNone); | |
611 | ||
612 | virtual IOReturn complete(IODirection forDirection = kIODirectionNone); | |
613 | ||
614 | virtual IOReturn doMap( | |
615 | vm_map_t addressMap, | |
616 | IOVirtualAddress * atAddress, | |
617 | IOOptionBits options, | |
618 | IOByteCount sourceOffset = 0, | |
619 | IOByteCount length = 0 ); | |
620 | ||
621 | virtual IOReturn doUnmap( | |
622 | vm_map_t addressMap, | |
623 | IOVirtualAddress logical, | |
624 | IOByteCount length ); | |
625 | }; | |
626 | ||
627 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
628 | ||
629 | class IOSubMemoryDescriptor : public IOMemoryDescriptor | |
630 | { | |
631 | friend IOMemoryDescriptor; | |
632 | ||
633 | OSDeclareDefaultStructors(IOSubMemoryDescriptor); | |
634 | ||
635 | protected: | |
636 | IOMemoryDescriptor * _parent; | |
637 | IOByteCount _start; | |
638 | ||
639 | virtual void free(); | |
640 | ||
641 | virtual bool initSubRange( IOMemoryDescriptor * parent, | |
642 | IOByteCount offset, IOByteCount length, | |
643 | IODirection withDirection ); | |
644 | ||
645 | virtual bool initWithAddress(void * address, | |
646 | IOByteCount withLength, | |
647 | IODirection withDirection); | |
648 | ||
649 | virtual bool initWithAddress(vm_address_t address, | |
650 | IOByteCount withLength, | |
651 | IODirection withDirection, | |
652 | task_t withTask); | |
653 | ||
654 | virtual bool initWithPhysicalAddress( | |
655 | IOPhysicalAddress address, | |
656 | IOByteCount withLength, | |
657 | IODirection withDirection ); | |
658 | ||
659 | virtual bool initWithRanges( IOVirtualRange * ranges, | |
660 | UInt32 withCount, | |
661 | IODirection withDirection, | |
662 | task_t withTask, | |
663 | bool asReference = false); | |
664 | ||
665 | virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges, | |
666 | UInt32 withCount, | |
667 | IODirection withDirection, | |
668 | bool asReference = false); | |
669 | ||
670 | IOMemoryDescriptor::withAddress; | |
671 | IOMemoryDescriptor::withPhysicalAddress; | |
672 | IOMemoryDescriptor::withPhysicalRanges; | |
673 | IOMemoryDescriptor::withRanges; | |
674 | IOMemoryDescriptor::withSubRange; | |
675 | ||
676 | public: | |
677 | /* | |
678 | * IOMemoryDescriptor required methods | |
679 | */ | |
680 | ||
681 | virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset, | |
682 | IOByteCount * length); | |
683 | ||
0b4e3aa0 A |
684 | virtual IOPhysicalAddress getSourceSegment(IOByteCount offset, |
685 | IOByteCount * length); | |
686 | ||
1c79356b A |
687 | virtual IOByteCount readBytes(IOByteCount offset, |
688 | void * bytes, IOByteCount withLength); | |
689 | ||
690 | virtual IOByteCount writeBytes(IOByteCount offset, | |
691 | const void * bytes, IOByteCount withLength); | |
692 | ||
693 | virtual void * getVirtualSegment(IOByteCount offset, | |
694 | IOByteCount * length); | |
695 | ||
696 | virtual IOReturn prepare(IODirection forDirection = kIODirectionNone); | |
697 | ||
698 | virtual IOReturn complete(IODirection forDirection = kIODirectionNone); | |
699 | ||
e3027f41 A |
700 | // make virtual |
701 | IOReturn redirect( task_t safeTask, bool redirect ); | |
702 | ||
1c79356b A |
703 | protected: |
704 | virtual IOMemoryMap * makeMapping( | |
705 | IOMemoryDescriptor * owner, | |
706 | task_t intoTask, | |
707 | IOVirtualAddress atAddress, | |
708 | IOOptionBits options, | |
709 | IOByteCount offset, | |
710 | IOByteCount length ); | |
711 | }; | |
712 | ||
713 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
714 | ||
715 | #endif /* !_IOMEMORYDESCRIPTOR_H */ |