]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
39037602 | 2 | * Copyright (c) 1998-2016 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | #ifndef _IOBUFFERMEMORYDESCRIPTOR_H | |
29 | #define _IOBUFFERMEMORYDESCRIPTOR_H | |
30 | ||
31 | #include <IOKit/IOMemoryDescriptor.h> | |
cb323159 | 32 | #include <DriverKit/IOBufferMemoryDescriptor.h> |
1c79356b A |
33 | |
34 | enum { | |
0a7de745 A |
35 | kIOMemoryPhysicallyContiguous = 0x00000010, |
36 | kIOMemoryPageable = 0x00000020, | |
37 | kIOMemoryPurgeable = 0x00000040, | |
38 | kIOMemoryHostPhysicallyContiguous = 0x00000080, | |
39 | kIOMemorySharingTypeMask = 0x000f0000, | |
40 | kIOMemoryUnshared = 0x00000000, | |
41 | kIOMemoryKernelUserShared = 0x00010000, | |
42 | // shared IOMemoryDescriptor options for IOBufferMemoryDescriptor: | |
43 | kIOBufferDescriptorMemoryFlags = kIOMemoryDirectionMask | |
c910b4d9 | 44 | #ifdef XNU_KERNEL_PRIVATE |
0a7de745 | 45 | | kIOMemoryAutoPrepare |
c910b4d9 | 46 | #endif |
0a7de745 A |
47 | | kIOMemoryThreadSafe |
48 | | kIOMemoryClearEncrypt | |
49 | | kIOMemoryMapperNone | |
50 | | kIOMemoryUseReserve | |
1c79356b A |
51 | }; |
52 | ||
0a7de745 A |
53 | #define _IOBUFFERMEMORYDESCRIPTOR_INTASKWITHOPTIONS_ 1 |
54 | #define _IOBUFFERMEMORYDESCRIPTOR_HOSTPHYSICALLYCONTIGUOUS_ 1 | |
91447636 | 55 | /*! |
0a7de745 A |
56 | * @class IOBufferMemoryDescriptor |
57 | * @abstract Provides a simple memory descriptor that allocates its own buffer memory. | |
58 | */ | |
1c79356b A |
59 | |
60 | class IOBufferMemoryDescriptor : public IOGeneralMemoryDescriptor | |
61 | { | |
cb323159 | 62 | OSDeclareDefaultStructorsWithDispatch(IOBufferMemoryDescriptor); |
1c79356b | 63 | |
2d21ac55 | 64 | private: |
1c79356b | 65 | /*! @struct ExpansionData |
0a7de745 A |
66 | * @discussion This structure will be used to expand the capablilties of this class in the future. |
67 | */ | |
68 | struct ExpansionData { | |
69 | IOMemoryMap * map; | |
70 | }; | |
1c79356b A |
71 | |
72 | /*! @var reserved | |
0a7de745 A |
73 | * Reserved for future use. (Internal use only) */ |
74 | APPLE_KEXT_WSHADOW_PUSH; | |
75 | ExpansionData * reserved; | |
1c79356b A |
76 | |
77 | protected: | |
0a7de745 A |
78 | void * _buffer; |
79 | vm_size_t _capacity; | |
80 | vm_offset_t _alignment; | |
81 | IOOptionBits _options; | |
b0d623f7 | 82 | private: |
0a7de745 A |
83 | uintptr_t _internalReserved; |
84 | unsigned _internalFlags; | |
85 | APPLE_KEXT_WSHADOW_POP; | |
1c79356b A |
86 | |
87 | private: | |
b0d623f7 | 88 | #ifndef __LP64__ |
0a7de745 A |
89 | virtual bool initWithOptions( |
90 | IOOptionBits options, | |
91 | vm_size_t capacity, | |
92 | vm_offset_t alignment, | |
93 | task_t inTask) APPLE_KEXT_DEPRECATED; /* use withOptions() instead */ | |
b0d623f7 | 94 | #endif /* !__LP64__ */ |
0c530ab8 | 95 | |
6d2010ae | 96 | public: |
0a7de745 A |
97 | virtual bool initWithPhysicalMask( |
98 | task_t inTask, | |
99 | IOOptionBits options, | |
100 | mach_vm_size_t capacity, | |
101 | mach_vm_address_t alignment, | |
102 | mach_vm_address_t physicalMask); | |
2d21ac55 | 103 | |
b0d623f7 | 104 | #ifdef __LP64__ |
0a7de745 A |
105 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 0); |
106 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 1); | |
b0d623f7 | 107 | #else /* !__LP64__ */ |
0a7de745 A |
108 | OSMetaClassDeclareReservedUsed(IOBufferMemoryDescriptor, 0); |
109 | OSMetaClassDeclareReservedUsed(IOBufferMemoryDescriptor, 1); | |
b0d623f7 | 110 | #endif /* !__LP64__ */ |
0a7de745 A |
111 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 2); |
112 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 3); | |
113 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 4); | |
114 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 5); | |
115 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 6); | |
116 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 7); | |
117 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 8); | |
118 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 9); | |
119 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 10); | |
120 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 11); | |
121 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 12); | |
122 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 13); | |
123 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 14); | |
124 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 15); | |
1c79356b A |
125 | |
126 | protected: | |
0a7de745 | 127 | virtual void free() APPLE_KEXT_OVERRIDE; |
1c79356b | 128 | |
1c79356b A |
129 | public: |
130 | ||
0a7de745 A |
131 | /* |
132 | * withOptions: | |
133 | * | |
134 | * Returns a new IOBufferMemoryDescriptor with a buffer large enough to | |
135 | * hold capacity bytes. The descriptor's length is initially set to the | |
136 | * capacity. | |
137 | */ | |
b0d623f7 | 138 | #ifndef __LP64__ |
0a7de745 A |
139 | virtual bool initWithOptions( IOOptionBits options, |
140 | vm_size_t capacity, | |
141 | vm_offset_t alignment) APPLE_KEXT_DEPRECATED; /* use withOptions() instead */ | |
b0d623f7 | 142 | #endif /* !__LP64__ */ |
1c79356b | 143 | |
cb323159 A |
144 | static IOBufferMemoryDescriptor * withCopy( |
145 | task_t inTask, | |
146 | IOOptionBits options, | |
147 | vm_map_t sourceMap, | |
148 | mach_vm_address_t source, | |
149 | mach_vm_size_t size); | |
150 | ||
0a7de745 A |
151 | static IOBufferMemoryDescriptor * withOptions( IOOptionBits options, |
152 | vm_size_t capacity, | |
153 | vm_offset_t alignment = 1); | |
1c79356b | 154 | |
9bccf70c | 155 | /*! @function inTaskWithOptions |
0a7de745 A |
156 | * @abstract Creates a memory buffer with memory descriptor for that buffer. |
157 | * @discussion Added in Mac OS X 10.2, this method allocates a memory buffer with a given size and alignment in the task's address space specified, and returns a memory descriptor instance representing the memory. It is recommended that memory allocated for I/O or sharing via mapping be created via IOBufferMemoryDescriptor. Options passed with the request specify the kind of memory to be allocated - pageablity and sharing are specified with option bits. This function may block and so should not be called from interrupt level or while a simple lock is held. | |
158 | * @param inTask The task the buffer will be allocated in. | |
159 | * @param options Options for the allocation:<br> | |
160 | * kIODirectionOut, kIODirectionIn - set the direction of the I/O transfer.<br> | |
161 | * kIOMemoryPhysicallyContiguous - pass to request memory be physically contiguous. This option is heavily discouraged. The request may fail if memory is fragmented, may cause large amounts of paging activity, and may take a very long time to execute.<br> | |
162 | * kIOMemoryPageable - pass to request memory be non-wired - the default for kernel allocated memory is wired.<br> | |
163 | * kIOMemoryPurgeable - pass to request memory that may later have its purgeable state set with IOMemoryDescriptor::setPurgeable. Only supported for kIOMemoryPageable allocations.<br> | |
164 | * kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.<br> | |
165 | * kIOMapInhibitCache - allocate memory with inhibited cache setting. <br> | |
166 | * kIOMapWriteThruCache - allocate memory with writethru cache setting. <br> | |
167 | * kIOMapCopybackCache - allocate memory with copyback cache setting. <br> | |
168 | * kIOMapWriteCombineCache - allocate memory with writecombined cache setting. | |
169 | * @param capacity The number of bytes to allocate. | |
170 | * @param alignment The minimum required alignment of the buffer in bytes - 1 is the default for no required alignment. For example, pass 256 to get memory allocated at an address with bits 0-7 zero. | |
171 | * @result Returns an instance of class IOBufferMemoryDescriptor to be released by the caller, which will free the memory desriptor and associated buffer. */ | |
9bccf70c | 172 | |
0a7de745 A |
173 | static IOBufferMemoryDescriptor * inTaskWithOptions( |
174 | task_t inTask, | |
175 | IOOptionBits options, | |
176 | vm_size_t capacity, | |
177 | vm_offset_t alignment = 1); | |
9bccf70c | 178 | |
0c530ab8 | 179 | /*! @function inTaskWithPhysicalMask |
0a7de745 A |
180 | * @abstract Creates a memory buffer with memory descriptor for that buffer. |
181 | * @discussion Added in Mac OS X 10.5, this method allocates a memory buffer with a given size and alignment in the task's address space specified, and returns a memory descriptor instance representing the memory. It is recommended that memory allocated for I/O or sharing via mapping be created via IOBufferMemoryDescriptor. Options passed with the request specify the kind of memory to be allocated - pageablity and sharing are specified with option bits. This function may block and so should not be called from interrupt level or while a simple lock is held. | |
182 | * @param inTask The task the buffer will be mapped in. Pass NULL to create memory unmapped in any task (eg. for use as a DMA buffer). | |
183 | * @param options Options for the allocation:<br> | |
184 | * kIODirectionOut, kIODirectionIn - set the direction of the I/O transfer.<br> | |
185 | * kIOMemoryPhysicallyContiguous - pass to request memory be physically contiguous. This option is heavily discouraged. The request may fail if memory is fragmented, may cause large amounts of paging activity, and may take a very long time to execute.<br> | |
186 | * kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.<br> | |
187 | * kIOMapInhibitCache - allocate memory with inhibited cache setting. <br> | |
188 | * kIOMapWriteThruCache - allocate memory with writethru cache setting. <br> | |
189 | * kIOMapCopybackCache - allocate memory with copyback cache setting. <br> | |
190 | * kIOMapWriteCombineCache - allocate memory with writecombined cache setting. | |
191 | * @param capacity The number of bytes to allocate. | |
192 | * @param physicalMask The buffer will be allocated with pages such that physical addresses will only have bits set present in physicalMask. For example, pass 0x00000000FFFFFFFFULL for a buffer to be accessed by hardware that has 32 address bits. | |
193 | * @result Returns an instance of class IOBufferMemoryDescriptor to be released by the caller, which will free the memory desriptor and associated buffer. */ | |
0c530ab8 | 194 | |
0a7de745 A |
195 | static IOBufferMemoryDescriptor * inTaskWithPhysicalMask( |
196 | task_t inTask, | |
197 | IOOptionBits options, | |
198 | mach_vm_size_t capacity, | |
199 | mach_vm_address_t physicalMask); | |
0c530ab8 | 200 | |
0a7de745 A |
201 | /* |
202 | * withCapacity: | |
203 | * | |
204 | * Returns a new IOBufferMemoryDescriptor with a buffer large enough to | |
205 | * hold capacity bytes. The descriptor's length is initially set to the | |
206 | * capacity. | |
207 | */ | |
208 | static IOBufferMemoryDescriptor * withCapacity( | |
209 | vm_size_t capacity, | |
210 | IODirection withDirection, | |
211 | bool withContiguousMemory = false); | |
b0d623f7 | 212 | #ifndef __LP64__ |
0a7de745 A |
213 | virtual bool initWithBytes(const void * bytes, |
214 | vm_size_t withLength, | |
215 | IODirection withDirection, | |
216 | bool withContiguousMemory = false) APPLE_KEXT_DEPRECATED; /* use withBytes() instead */ | |
b0d623f7 | 217 | #endif /* !__LP64__ */ |
1c79356b | 218 | |
0a7de745 A |
219 | /* |
220 | * withBytes: | |
221 | * | |
222 | * Returns a new IOBufferMemoryDescriptor preloaded with bytes (copied). | |
223 | * The descriptor's length and capacity are set to the input buffer's size. | |
224 | */ | |
225 | static IOBufferMemoryDescriptor * withBytes( | |
226 | const void * bytes, | |
227 | vm_size_t withLength, | |
228 | IODirection withDirection, | |
229 | bool withContiguousMemory = false); | |
1c79356b | 230 | |
0a7de745 A |
231 | /* |
232 | * setLength: | |
233 | * | |
234 | * Change the buffer length of the memory descriptor. When a new buffer | |
235 | * is created, the initial length of the buffer is set to be the same as | |
236 | * the capacity. The length can be adjusted via setLength for a shorter | |
237 | * transfer (there is no need to create more buffer descriptors when you | |
238 | * can reuse an existing one, even for different transfer sizes). Note | |
239 | * that the specified length must not exceed the capacity of the buffer. | |
240 | */ | |
241 | virtual void setLength(vm_size_t length); | |
1c79356b | 242 | |
0a7de745 A |
243 | /* |
244 | * setDirection: | |
245 | * | |
246 | * Change the direction of the transfer. This method allows one to redirect | |
247 | * the descriptor's transfer direction. This eliminates the need to destroy | |
248 | * and create new buffers when different transfer directions are needed. | |
249 | */ | |
250 | virtual void setDirection(IODirection direction); | |
1c79356b | 251 | |
0a7de745 A |
252 | /* |
253 | * getCapacity: | |
254 | * | |
255 | * Get the buffer capacity | |
256 | */ | |
257 | virtual vm_size_t getCapacity() const; | |
1c79356b | 258 | |
0a7de745 A |
259 | /* |
260 | * getBytesNoCopy: | |
261 | * | |
262 | * Return the virtual address of the beginning of the buffer | |
263 | */ | |
264 | virtual void *getBytesNoCopy(); | |
1c79356b | 265 | |
0a7de745 A |
266 | /* |
267 | * getBytesNoCopy: | |
268 | * | |
269 | * Return the virtual address of an offset from the beginning of the buffer | |
270 | */ | |
271 | virtual void *getBytesNoCopy(vm_size_t start, vm_size_t withLength); | |
1c79356b | 272 | |
0a7de745 A |
273 | /* |
274 | * appendBytes: | |
275 | * | |
276 | * Add some data to the end of the buffer. This method automatically | |
277 | * maintains the memory descriptor buffer length. Note that appendBytes | |
278 | * will not copy past the end of the memory descriptor's current capacity. | |
279 | */ | |
280 | virtual bool appendBytes(const void *bytes, vm_size_t withLength); | |
0c530ab8 | 281 | |
b0d623f7 | 282 | #ifndef __LP64__ |
0a7de745 A |
283 | virtual void * getVirtualSegment(IOByteCount offset, |
284 | IOByteCount * length) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED; /* use getBytesNoCopy() instead */ | |
b0d623f7 | 285 | #endif /* !__LP64__ */ |
1c79356b A |
286 | }; |
287 | ||
288 | #endif /* !_IOBUFFERMEMORYDESCRIPTOR_H */ |