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