2 * Copyright (c) 2019-2019 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 #include <IOKit/IOMemoryDescriptor.h>
35 #ifndef _IOKIT_UIOMEMORYDESCRIPTOR_H
36 #define _IOKIT_UIOMEMORYDESCRIPTOR_H
38 #include <DriverKit/OSObject.iig>
44 // IOMemoryDescriptor Create options
46 kIOMemoryDirectionIn = 0x00000001,
47 kIOMemoryDirectionOut = 0x00000002,
48 kIOMemoryDirectionOutIn = kIOMemoryDirectionIn | kIOMemoryDirectionOut,
49 kIOMemoryDirectionInOut = kIOMemoryDirectionOutIn,
50 kIOMemoryDisableCopyOnWrite = 0x00000010
53 // IOMemoryDescriptor CreateMapping options
55 kIOMemoryMapFixedAddress = 0x00000001,
56 kIOMemoryMapReadOnly = 0x00000002,
57 kIOMemoryMapCacheModeDefault = 0x00000000,
58 kIOMemoryMapCacheModeInhibit = 0x00000100,
59 kIOMemoryMapCacheModeCopyback = 0x00000200,
60 kIOMemoryMapCacheModeWriteThrough = 0x00000400,
63 struct IOAddressSegment {
68 struct _IOMDPrivateState {
74 * @class IOMemoryDescriptor
77 * IOMemoryDescriptor describes a memory buffer.
80 * To allocate memory for I/O or sharing, use IOBufferMemoryDescriptor::Create()
81 * Methods in this class are used for memory that was supplied as a parameter.
85 #include <DriverKit/IOService.h>
89 class KERNEL IOMemoryDescriptor : public OSObject
101 * @brief Obtain the length of the memory described.
102 * @param returnLength Returned length.
103 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
107 uint64_t * returnLength) LOCALONLY;
110 * @brief Create a mapping of the memory in the callers address space.
112 * kIOMemoryMapFixedAddress map at the address requested
113 * kIOMemoryMapReadOnly create a read only mapping
114 * kIOMemoryMapCacheModeDefault default cache mode
115 * kIOMemoryMapCacheModeInhibit inhibited cache mode
116 * kIOMemoryMapCacheModeCopyback copyback cache mode
117 * kIOMemoryMapCacheModeWriteThrough write through cache mode
118 * @param address Requested address if kIOMemoryMapFixedAddress was passed
119 * @param offset Start offset of the mapping in the descriptor.
120 * @param length Pass zero to map the entire memory, or a value <= the length of the descriptor.
121 * @param alignment of the memory virtual mapping. Only zero for no alignment is supported.
122 * @param map Returned IOMemoryMap object with +1 retain count.
123 * It should be retained until the map is no longer required.
124 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
126 virtual kern_return_t
136 * @brief Create a memory descriptor that is a subrange of another memory
138 * @param memoryDescriptorCreateOptions
139 * kIOMemoryDirectionIn memory described will be writable
140 * kIOMemoryDirectionOut memory described will be readable
141 * @param offset Start offset of the memory relative to the descriptor ofDescriptor.
142 * @param length Length of the memory.
143 * @param ofDescriptor Memory descriptor describing source memory.
144 * @param memory Returned IOMemoryDescriptor object with +1 retain count.
145 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
148 CreateSubMemoryDescriptor(
149 uint64_t memoryDescriptorCreateOptions,
152 IOMemoryDescriptor * ofDescriptor,
153 IOMemoryDescriptor ** memory) __attribute__((availability(driverkit,introduced=20.0)));
156 * @brief Create a memory descriptor that is a concatenation of a set of memory
158 * @param memoryDescriptorCreateOptions
159 * kIOMemoryDirectionIn memory described will be writable. The source
160 * descriptors must include this direction.
161 * kIOMemoryDirectionOut memory described will be readable. The source
162 * descriptors must include this direction.
163 * @param withDescriptorsCount Number of valid memory descriptors being passed
164 * in the withDescriptors array.
165 * @param withDescriptors Source memory descriptor array.
166 * @param memory Returned IOMemoryDescriptor object with +1 retain count.
167 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
170 CreateWithMemoryDescriptors(
171 uint64_t memoryDescriptorCreateOptions,
172 uint32_t withDescriptorsCount,
173 IOMemoryDescriptor * const withDescriptors[32],
174 IOMemoryDescriptor ** memory) __attribute__((availability(driverkit,introduced=20.0)));
184 uint64_t * returnAddress,
185 uint64_t * returnLength) LOCALONLY;
188 class EXTENDS (IOMemoryDescriptor) IOMemoryDescriptorPrivate
190 virtual kern_return_t
192 _IOMDPrivateState * state);
197 #endif /* ! _IOKIT_UIOMEMORYDESCRIPTOR_H */