1/* iig(DriverKit-286) generated from IOMemoryDescriptor.iig */
2
3/* IOMemoryDescriptor.iig:1-78 */
4/*
5 * Copyright (c) 2019-2019 Apple Inc. All rights reserved.
6 *
7 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
8 *
9 * This file contains Original Code and/or Modifications of Original Code
10 * as defined in and that are subject to the Apple Public Source License
11 * Version 2.0 (the 'License'). You may not use this file except in
12 * compliance with the License. The rights granted to you under the License
13 * may not be used to create, or enable the creation or redistribution of,
14 * unlawful or unlicensed copies of an Apple operating system, or to
15 * circumvent, violate, or enable the circumvention or violation of, any
16 * terms of an Apple operating system software license agreement.
17 *
18 * Please obtain a copy of the License at
19 * http://www.opensource.apple.com/apsl/ and read it before using this file.
20 *
21 * The Original Code and all software distributed under the License are
22 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
23 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
24 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
26 * Please see the License for the specific language governing rights and
27 * limitations under the License.
28 *
29 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 */
31
32#if !__IIG
33#if KERNEL
34#include <IOKit/IOMemoryDescriptor.h>
35#endif
36#endif
37
38#ifndef _IOKIT_UIOMEMORYDESCRIPTOR_H
39#define _IOKIT_UIOMEMORYDESCRIPTOR_H
40
41#include <DriverKit/OSObject.h> /* .iig include */
42
43class IOService;
44class IOMemoryMap;
45
46
47// IOMemoryDescriptor Create options
48enum {
49 kIOMemoryDirectionNone = 0x00000000,
50 kIOMemoryDirectionIn = 0x00000001,
51 kIOMemoryDirectionOut = 0x00000002,
52 kIOMemoryDirectionOutIn = kIOMemoryDirectionIn | kIOMemoryDirectionOut,
53 kIOMemoryDirectionInOut = kIOMemoryDirectionOutIn,
54 kIOMemoryDisableCopyOnWrite = 0x00000010
55};
56
57// IOMemoryDescriptor CreateMapping options
58enum {
59 kIOMemoryMapFixedAddress = 0x00000001,
60 kIOMemoryMapReadOnly = 0x00000002,
61 kIOMemoryMapGuardedMask = 0x0000001C,
62 kIOMemoryMapGuardedDefault = 0x00000000,
63 kIOMemoryMapGuardedNone = 0x00000004,
64 kIOMemoryMapGuardedSmall = 0x00000008,
65 kIOMemoryMapGuardedLarge = 0x0000000C,
66 kIOMemoryMapCacheModeDefault = 0x00000000,
67 kIOMemoryMapCacheModeInhibit = 0x00000100,
68 kIOMemoryMapCacheModeCopyback = 0x00000200,
69 kIOMemoryMapCacheModeWriteThrough = 0x00000400,
70};
71
72struct IOAddressSegment {
73 uint64_t address;
74 uint64_t length;
75};
76
77struct _IOMDPrivateState {
78 uint64_t length;
79 uint64_t options;
80};
81
82/* source class IOMemoryDescriptor IOMemoryDescriptor.iig:79-191 */
83
84#if __DOCUMENTATION__
85#define KERNEL IIG_KERNEL
86
87/*!
88 * @class IOMemoryDescriptor
89 *
90 * @abstract
91 * IOMemoryDescriptor describes a memory buffer.
92 *
93 * @discussion
94 * To allocate memory for I/O or sharing, use IOBufferMemoryDescriptor::Create()
95 * Methods in this class are used for memory that was supplied as a parameter.
96 *
97
98*/
99
100class KERNEL IOMemoryDescriptor : public OSObject
101{
102public:
103
104
105 virtual bool
106 init() override;
107
108 virtual void
109 free() override;
110
111 /*!
112 * @brief Obtain the length of the memory described.
113 * @param returnLength Returned length.
114 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
115 */
116 kern_return_t
117 GetLength(
118 uint64_t * returnLength) LOCALONLY;
119
120 /*!
121 * @brief Create a mapping of the memory in the callers address space.
122 * @param options
123 * kIOMemoryMapFixedAddress map at the address requested
124 * kIOMemoryMapReadOnly create a read only mapping
125 * kIOMemoryMapCacheModeDefault default cache mode
126 * kIOMemoryMapCacheModeInhibit inhibited cache mode
127 * kIOMemoryMapCacheModeCopyback copyback cache mode
128 * kIOMemoryMapCacheModeWriteThrough write through cache mode
129 * @param address Requested address if kIOMemoryMapFixedAddress was passed
130 * @param offset Start offset of the mapping in the descriptor.
131 * @param length Pass zero to map the entire memory, or a value <= the length of the descriptor.
132 * @param alignment of the memory virtual mapping. Only zero for no alignment is supported.
133 * @param map Returned IOMemoryMap object with +1 retain count.
134 * It should be retained until the map is no longer required.
135 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
136 */
137 virtual kern_return_t
138 CreateMapping(
139 uint64_t options,
140 uint64_t address,
141 uint64_t offset,
142 uint64_t length,
143 uint64_t alignment,
144 IOMemoryMap ** map);
145
146 /*!
147 * @brief Create a memory descriptor that is a subrange of another memory
148 * descriptor
149 * @param memoryDescriptorCreateOptions
150 * kIOMemoryDirectionIn memory described will be writable
151 * kIOMemoryDirectionOut memory described will be readable
152 * @param offset Start offset of the memory relative to the descriptor ofDescriptor.
153 * @param length Length of the memory.
154 * @param ofDescriptor Memory descriptor describing source memory.
155 * @param memory Returned IOMemoryDescriptor object with +1 retain count.
156 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
157 */
158 static kern_return_t
159 CreateSubMemoryDescriptor(
160 uint64_t memoryDescriptorCreateOptions,
161 uint64_t offset,
162 uint64_t length,
163 IOMemoryDescriptor * ofDescriptor,
164 IOMemoryDescriptor ** memory) __attribute__((availability(driverkit,introduced=20.0)));
165
166 /*!
167 * @brief Create a memory descriptor that is a concatenation of a set of memory
168 * descriptors
169 * @param memoryDescriptorCreateOptions
170 * kIOMemoryDirectionIn memory described will be writable. The source
171 * descriptors must include this direction.
172 * kIOMemoryDirectionOut memory described will be readable. The source
173 * descriptors must include this direction.
174 * @param withDescriptorsCount Number of valid memory descriptors being passed
175 * in the withDescriptors array.
176 * @param withDescriptors Source memory descriptor array.
177 * @param memory Returned IOMemoryDescriptor object with +1 retain count.
178 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
179 */
180 static kern_return_t
181 CreateWithMemoryDescriptors(
182 uint64_t memoryDescriptorCreateOptions,
183 uint32_t withDescriptorsCount,
184 IOMemoryDescriptor * const withDescriptors[32],
185 IOMemoryDescriptor ** memory) __attribute__((availability(driverkit,introduced=20.0)));
186
187private:
188 kern_return_t
189 Map(
190 uint64_t options,
191 uint64_t address,
192 uint64_t length,
193 uint64_t alignment,
194
195 uint64_t * returnAddress,
196 uint64_t * returnLength) LOCALONLY;
197};
198
199#undef KERNEL
200#else /* __DOCUMENTATION__ */
201
202/* generated class IOMemoryDescriptor IOMemoryDescriptor.iig:79-191 */
203
204#define IOMemoryDescriptor__CopyState_ID 0xa2c0861d4118ce5eULL
205#define IOMemoryDescriptor_CreateMapping_ID 0xc5e69b0414ff6ee5ULL
206#define IOMemoryDescriptor_CreateSubMemoryDescriptor_ID 0xb085b5ee60ac732fULL
207#define IOMemoryDescriptor_CreateWithMemoryDescriptors_ID 0xba1530c996c4febcULL
208
209#define IOMemoryDescriptor__CopyState_Args \
210 _IOMDPrivateState * state
211
212#define IOMemoryDescriptor_CreateMapping_Args \
213 uint64_t options, \
214 uint64_t address, \
215 uint64_t offset, \
216 uint64_t length, \
217 uint64_t alignment, \
218 IOMemoryMap ** map
219
220#define IOMemoryDescriptor_CreateSubMemoryDescriptor_Args \
221 uint64_t memoryDescriptorCreateOptions, \
222 uint64_t offset, \
223 uint64_t length, \
224 IOMemoryDescriptor * ofDescriptor, \
225 IOMemoryDescriptor ** memory
226
227#define IOMemoryDescriptor_CreateWithMemoryDescriptors_Args \
228 uint64_t memoryDescriptorCreateOptions, \
229 uint32_t withDescriptorsCount, \
230 IOMemoryDescriptor ** const withDescriptors, \
231 IOMemoryDescriptor ** memory
232
233#define IOMemoryDescriptor_Methods \
234\
235public:\
236\
237 virtual kern_return_t\
238 Dispatch(const IORPC rpc) APPLE_KEXT_OVERRIDE;\
239\
240 static kern_return_t\
241 _Dispatch(IOMemoryDescriptor * self, const IORPC rpc);\
242\
243 kern_return_t\
244 _CopyState(\
245 _IOMDPrivateState * state,\
246 OSDispatchMethod supermethod = NULL);\
247\
248 kern_return_t\
249 GetLength(\
250 uint64_t * returnLength);\
251\
252 kern_return_t\
253 CreateMapping(\
254 uint64_t options,\
255 uint64_t address,\
256 uint64_t offset,\
257 uint64_t length,\
258 uint64_t alignment,\
259 IOMemoryMap ** map,\
260 OSDispatchMethod supermethod = NULL);\
261\
262 static kern_return_t\
263 CreateSubMemoryDescriptor(\
264 uint64_t memoryDescriptorCreateOptions,\
265 uint64_t offset,\
266 uint64_t length,\
267 IOMemoryDescriptor * ofDescriptor,\
268 IOMemoryDescriptor ** memory) __attribute__((availability(driverkit,introduced=20.0)));\
269\
270 static kern_return_t\
271 CreateWithMemoryDescriptors(\
272 uint64_t memoryDescriptorCreateOptions,\
273 uint32_t withDescriptorsCount,\
274 IOMemoryDescriptor ** const withDescriptors,\
275 IOMemoryDescriptor ** memory) __attribute__((availability(driverkit,introduced=20.0)));\
276\
277 kern_return_t\
278 Map(\
279 uint64_t options,\
280 uint64_t address,\
281 uint64_t length,\
282 uint64_t alignment,\
283 uint64_t * returnAddress,\
284 uint64_t * returnLength);\
285\
286\
287protected:\
288 /* _Impl methods */\
289\
290\
291public:\
292 /* _Invoke methods */\
293\
294 typedef kern_return_t (*_CopyState_Handler)(OSMetaClassBase * target, IOMemoryDescriptor__CopyState_Args);\
295 static kern_return_t\
296 _CopyState_Invoke(const IORPC rpc,\
297 OSMetaClassBase * target,\
298 _CopyState_Handler func);\
299\
300 typedef kern_return_t (*CreateMapping_Handler)(OSMetaClassBase * target, IOMemoryDescriptor_CreateMapping_Args);\
301 static kern_return_t\
302 CreateMapping_Invoke(const IORPC rpc,\
303 OSMetaClassBase * target,\
304 CreateMapping_Handler func);\
305\
306 typedef kern_return_t (*CreateSubMemoryDescriptor_Handler)(IOMemoryDescriptor_CreateSubMemoryDescriptor_Args);\
307 static kern_return_t\
308 CreateSubMemoryDescriptor_Invoke(const IORPC rpc,\
309 CreateSubMemoryDescriptor_Handler func);\
310\
311 typedef kern_return_t (*CreateWithMemoryDescriptors_Handler)(IOMemoryDescriptor_CreateWithMemoryDescriptors_Args);\
312 static kern_return_t\
313 CreateWithMemoryDescriptors_Invoke(const IORPC rpc,\
314 CreateWithMemoryDescriptors_Handler func);\
315\
316
317
318#define IOMemoryDescriptor_KernelMethods \
319\
320protected:\
321 /* _Impl methods */\
322\
323 kern_return_t\
324 _CopyState_Impl(IOMemoryDescriptor__CopyState_Args);\
325\
326 kern_return_t\
327 CreateMapping_Impl(IOMemoryDescriptor_CreateMapping_Args);\
328\
329 static kern_return_t\
330 CreateSubMemoryDescriptor_Impl(IOMemoryDescriptor_CreateSubMemoryDescriptor_Args);\
331\
332 static kern_return_t\
333 CreateWithMemoryDescriptors_Impl(IOMemoryDescriptor_CreateWithMemoryDescriptors_Args);\
334\
335
336
337#define IOMemoryDescriptor_VirtualMethods \
338\
339public:\
340\
341 virtual bool\
342 init(\
343) APPLE_KEXT_OVERRIDE;\
344\
345 virtual void\
346 free(\
347) APPLE_KEXT_OVERRIDE;\
348\
349
350
351#if !KERNEL
352
353extern OSMetaClass * gIOMemoryDescriptorMetaClass;
354extern const OSClassLoadInformation IOMemoryDescriptor_Class;
355
356class IOMemoryDescriptorMetaClass : public OSMetaClass
357{
358public:
359 virtual kern_return_t
360 New(OSObject * instance) override;
361 virtual kern_return_t
362 Dispatch(const IORPC rpc) override;
363};
364
365#endif /* !KERNEL */
366
367#if !KERNEL
368
369class IOMemoryDescriptorInterface : public OSInterface
370{
371public:
372};
373
374struct IOMemoryDescriptor_IVars;
375struct IOMemoryDescriptor_LocalIVars;
376
377class IOMemoryDescriptor : public OSObject, public IOMemoryDescriptorInterface
378{
379#if !KERNEL
380 friend class IOMemoryDescriptorMetaClass;
381#endif /* !KERNEL */
382
383#if !KERNEL
384public:
385#ifdef IOMemoryDescriptor_DECLARE_IVARS
386IOMemoryDescriptor_DECLARE_IVARS
387#else /* IOMemoryDescriptor_DECLARE_IVARS */
388 union
389 {
390 IOMemoryDescriptor_IVars * ivars;
391 IOMemoryDescriptor_LocalIVars * lvars;
392 };
393#endif /* IOMemoryDescriptor_DECLARE_IVARS */
394#endif /* !KERNEL */
395
396#if !KERNEL
397 static OSMetaClass *
398 sGetMetaClass() { return gIOMemoryDescriptorMetaClass; };
399#endif /* KERNEL */
400
401 using super = OSObject;
402
403#if !KERNEL
404 IOMemoryDescriptor_Methods
405 IOMemoryDescriptor_VirtualMethods
406#endif /* !KERNEL */
407
408};
409#endif /* !KERNEL */
410
411
412#endif /* !__DOCUMENTATION__ */
413
414
415/* IOMemoryDescriptor.iig:200- */
416
417
418
419#endif /* ! _IOKIT_UIOMEMORYDESCRIPTOR_H */
420