xref: /xnu-10002.61.3/iokit/DriverKit/IOMemoryDescriptor.iig (revision 0f4c859e951fba394238ab619495c4e1d54d0f34)
1*0f4c859eSApple OSS Distributions/*
2*0f4c859eSApple OSS Distributions * Copyright (c) 2019-2019 Apple Inc. All rights reserved.
3*0f4c859eSApple OSS Distributions *
4*0f4c859eSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*0f4c859eSApple OSS Distributions *
6*0f4c859eSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*0f4c859eSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*0f4c859eSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*0f4c859eSApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*0f4c859eSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*0f4c859eSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*0f4c859eSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*0f4c859eSApple OSS Distributions * terms of an Apple operating system software license agreement.
14*0f4c859eSApple OSS Distributions *
15*0f4c859eSApple OSS Distributions * Please obtain a copy of the License at
16*0f4c859eSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*0f4c859eSApple OSS Distributions *
18*0f4c859eSApple OSS Distributions * The Original Code and all software distributed under the License are
19*0f4c859eSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*0f4c859eSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*0f4c859eSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*0f4c859eSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*0f4c859eSApple OSS Distributions * Please see the License for the specific language governing rights and
24*0f4c859eSApple OSS Distributions * limitations under the License.
25*0f4c859eSApple OSS Distributions *
26*0f4c859eSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*0f4c859eSApple OSS Distributions */
28*0f4c859eSApple OSS Distributions
29*0f4c859eSApple OSS Distributions#if !__IIG
30*0f4c859eSApple OSS Distributions#if KERNEL
31*0f4c859eSApple OSS Distributions#include <IOKit/IOMemoryDescriptor.h>
32*0f4c859eSApple OSS Distributions#endif
33*0f4c859eSApple OSS Distributions#endif
34*0f4c859eSApple OSS Distributions
35*0f4c859eSApple OSS Distributions#ifndef _IOKIT_UIOMEMORYDESCRIPTOR_H
36*0f4c859eSApple OSS Distributions#define _IOKIT_UIOMEMORYDESCRIPTOR_H
37*0f4c859eSApple OSS Distributions
38*0f4c859eSApple OSS Distributions#include <DriverKit/OSObject.iig>
39*0f4c859eSApple OSS Distributions
40*0f4c859eSApple OSS Distributionsclass IOService;
41*0f4c859eSApple OSS Distributionsclass IOMemoryMap;
42*0f4c859eSApple OSS Distributions
43*0f4c859eSApple OSS Distributions
44*0f4c859eSApple OSS Distributions// IOMemoryDescriptor Create options
45*0f4c859eSApple OSS Distributionsenum {
46*0f4c859eSApple OSS Distributions	kIOMemoryDirectionNone       = 0x00000000,
47*0f4c859eSApple OSS Distributions	kIOMemoryDirectionIn         = 0x00000001,
48*0f4c859eSApple OSS Distributions	kIOMemoryDirectionOut        = 0x00000002,
49*0f4c859eSApple OSS Distributions	kIOMemoryDirectionOutIn      = kIOMemoryDirectionIn | kIOMemoryDirectionOut,
50*0f4c859eSApple OSS Distributions	kIOMemoryDirectionInOut      = kIOMemoryDirectionOutIn,
51*0f4c859eSApple OSS Distributions	kIOMemoryDisableCopyOnWrite  = 0x00000010
52*0f4c859eSApple OSS Distributions};
53*0f4c859eSApple OSS Distributions
54*0f4c859eSApple OSS Distributions// IOMemoryDescriptor CreateMapping options
55*0f4c859eSApple OSS Distributionsenum {
56*0f4c859eSApple OSS Distributions	kIOMemoryMapFixedAddress          = 0x00000001,
57*0f4c859eSApple OSS Distributions	kIOMemoryMapReadOnly              = 0x00000002,
58*0f4c859eSApple OSS Distributions	kIOMemoryMapGuardedMask           = 0x0000001C,
59*0f4c859eSApple OSS Distributions	kIOMemoryMapGuardedDefault        = 0x00000000,
60*0f4c859eSApple OSS Distributions	kIOMemoryMapGuardedNone           = 0x00000004,
61*0f4c859eSApple OSS Distributions	kIOMemoryMapGuardedSmall          = 0x00000008,
62*0f4c859eSApple OSS Distributions	kIOMemoryMapGuardedLarge          = 0x0000000C,
63*0f4c859eSApple OSS Distributions	kIOMemoryMapCacheModeDefault      = 0x00000000,
64*0f4c859eSApple OSS Distributions	kIOMemoryMapCacheModeInhibit      = 0x00000100,
65*0f4c859eSApple OSS Distributions	kIOMemoryMapCacheModeCopyback     = 0x00000200,
66*0f4c859eSApple OSS Distributions	kIOMemoryMapCacheModeWriteThrough = 0x00000400,
67*0f4c859eSApple OSS Distributions};
68*0f4c859eSApple OSS Distributions
69*0f4c859eSApple OSS Distributionsstruct IOAddressSegment {
70*0f4c859eSApple OSS Distributions	uint64_t address;
71*0f4c859eSApple OSS Distributions	uint64_t length;
72*0f4c859eSApple OSS Distributions};
73*0f4c859eSApple OSS Distributions
74*0f4c859eSApple OSS Distributionsstruct _IOMDPrivateState {
75*0f4c859eSApple OSS Distributions	uint64_t length;
76*0f4c859eSApple OSS Distributions	uint64_t options;
77*0f4c859eSApple OSS Distributions};
78*0f4c859eSApple OSS Distributions
79*0f4c859eSApple OSS Distributions/*!
80*0f4c859eSApple OSS Distributions * @class IOMemoryDescriptor
81*0f4c859eSApple OSS Distributions *
82*0f4c859eSApple OSS Distributions * @abstract
83*0f4c859eSApple OSS Distributions * IOMemoryDescriptor describes a memory buffer.
84*0f4c859eSApple OSS Distributions *
85*0f4c859eSApple OSS Distributions * @discussion
86*0f4c859eSApple OSS Distributions * To allocate memory for I/O or sharing, use IOBufferMemoryDescriptor::Create()
87*0f4c859eSApple OSS Distributions * Methods in this class are used for memory that was supplied as a parameter.
88*0f4c859eSApple OSS Distributions *
89*0f4c859eSApple OSS Distributions
90*0f4c859eSApple OSS Distributions@iig implementation
91*0f4c859eSApple OSS Distributions#include <DriverKit/IOService.h>
92*0f4c859eSApple OSS Distributions@iig end
93*0f4c859eSApple OSS Distributions*/
94*0f4c859eSApple OSS Distributions
95*0f4c859eSApple OSS Distributionsclass KERNEL IOMemoryDescriptor : public OSObject
96*0f4c859eSApple OSS Distributions{
97*0f4c859eSApple OSS Distributionspublic:
98*0f4c859eSApple OSS Distributions
99*0f4c859eSApple OSS Distributions
100*0f4c859eSApple OSS Distributions	virtual bool
101*0f4c859eSApple OSS Distributions	init() override;
102*0f4c859eSApple OSS Distributions
103*0f4c859eSApple OSS Distributions	virtual void
104*0f4c859eSApple OSS Distributions	free() override;
105*0f4c859eSApple OSS Distributions
106*0f4c859eSApple OSS Distributions    /*!
107*0f4c859eSApple OSS Distributions     * @brief       Obtain the length of the memory described.
108*0f4c859eSApple OSS Distributions     * @param       returnLength Returned length.
109*0f4c859eSApple OSS Distributions     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
110*0f4c859eSApple OSS Distributions     */
111*0f4c859eSApple OSS Distributions	kern_return_t
112*0f4c859eSApple OSS Distributions	GetLength(
113*0f4c859eSApple OSS Distributions		uint64_t * returnLength) LOCALONLY;
114*0f4c859eSApple OSS Distributions
115*0f4c859eSApple OSS Distributions    /*!
116*0f4c859eSApple OSS Distributions     * @brief       Create a mapping of the memory in the callers address space.
117*0f4c859eSApple OSS Distributions     * @param       options
118*0f4c859eSApple OSS Distributions	 *              kIOMemoryMapFixedAddress map at the address requested
119*0f4c859eSApple OSS Distributions	 *              kIOMemoryMapReadOnly create a read only mapping
120*0f4c859eSApple OSS Distributions	 *              kIOMemoryMapCacheModeDefault default cache mode
121*0f4c859eSApple OSS Distributions	 *              kIOMemoryMapCacheModeInhibit inhibited cache mode
122*0f4c859eSApple OSS Distributions	 *              kIOMemoryMapCacheModeCopyback copyback cache mode
123*0f4c859eSApple OSS Distributions	 *              kIOMemoryMapCacheModeWriteThrough write through cache mode
124*0f4c859eSApple OSS Distributions	 * @param       address Requested address if kIOMemoryMapFixedAddress was passed
125*0f4c859eSApple OSS Distributions	 * @param       offset Start offset of the mapping in the descriptor.
126*0f4c859eSApple OSS Distributions	 * @param       length Pass zero to map the entire memory, or a value <= the length of the descriptor.
127*0f4c859eSApple OSS Distributions	 * @param       alignment of the memory virtual mapping. Only zero for no alignment is supported.
128*0f4c859eSApple OSS Distributions	 * @param       map Returned IOMemoryMap object with +1 retain count.
129*0f4c859eSApple OSS Distributions	 *              It should be retained until the map is no longer required.
130*0f4c859eSApple OSS Distributions     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
131*0f4c859eSApple OSS Distributions     */
132*0f4c859eSApple OSS Distributions	virtual kern_return_t
133*0f4c859eSApple OSS Distributions	CreateMapping(
134*0f4c859eSApple OSS Distributions		uint64_t options,
135*0f4c859eSApple OSS Distributions		uint64_t address,
136*0f4c859eSApple OSS Distributions		uint64_t offset,
137*0f4c859eSApple OSS Distributions		uint64_t length,
138*0f4c859eSApple OSS Distributions		uint64_t alignment,
139*0f4c859eSApple OSS Distributions		IOMemoryMap ** map);
140*0f4c859eSApple OSS Distributions
141*0f4c859eSApple OSS Distributions    /*!
142*0f4c859eSApple OSS Distributions     * @brief       Create a memory descriptor that is a subrange of another memory
143*0f4c859eSApple OSS Distributions     *              descriptor
144*0f4c859eSApple OSS Distributions     * @param       memoryDescriptorCreateOptions
145*0f4c859eSApple OSS Distributions	 *              kIOMemoryDirectionIn memory described will be writable
146*0f4c859eSApple OSS Distributions	 *              kIOMemoryDirectionOut memory described will be readable
147*0f4c859eSApple OSS Distributions	 * @param       offset Start offset of the memory relative to the descriptor ofDescriptor.
148*0f4c859eSApple OSS Distributions	 * @param       length Length of the memory.
149*0f4c859eSApple OSS Distributions	 * @param       ofDescriptor Memory descriptor describing source memory.
150*0f4c859eSApple OSS Distributions	 * @param       memory Returned IOMemoryDescriptor object with +1 retain count.
151*0f4c859eSApple OSS Distributions     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
152*0f4c859eSApple OSS Distributions     */
153*0f4c859eSApple OSS Distributions	static kern_return_t
154*0f4c859eSApple OSS Distributions	CreateSubMemoryDescriptor(
155*0f4c859eSApple OSS Distributions	    uint64_t memoryDescriptorCreateOptions,
156*0f4c859eSApple OSS Distributions	    uint64_t offset,
157*0f4c859eSApple OSS Distributions	    uint64_t length,
158*0f4c859eSApple OSS Distributions		IOMemoryDescriptor * ofDescriptor,
159*0f4c859eSApple OSS Distributions		IOMemoryDescriptor ** memory) __attribute__((availability(driverkit,introduced=20.0)));
160*0f4c859eSApple OSS Distributions
161*0f4c859eSApple OSS Distributions    /*!
162*0f4c859eSApple OSS Distributions     * @brief       Create a memory descriptor that is a concatenation of a set of memory
163*0f4c859eSApple OSS Distributions     *              descriptors
164*0f4c859eSApple OSS Distributions     * @param       memoryDescriptorCreateOptions
165*0f4c859eSApple OSS Distributions	 *              kIOMemoryDirectionIn memory described will be writable. The source
166*0f4c859eSApple OSS Distributions	 *              descriptors must include this direction.
167*0f4c859eSApple OSS Distributions	 *              kIOMemoryDirectionOut memory described will be readable. The source
168*0f4c859eSApple OSS Distributions	 *              descriptors must include this direction.
169*0f4c859eSApple OSS Distributions	 * @param       withDescriptorsCount Number of valid memory descriptors being passed
170*0f4c859eSApple OSS Distributions	 *              in the withDescriptors array.
171*0f4c859eSApple OSS Distributions	 * @param       withDescriptors Source memory descriptor array.
172*0f4c859eSApple OSS Distributions	 * @param       memory Returned IOMemoryDescriptor object with +1 retain count.
173*0f4c859eSApple OSS Distributions     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
174*0f4c859eSApple OSS Distributions     */
175*0f4c859eSApple OSS Distributions	static kern_return_t
176*0f4c859eSApple OSS Distributions	CreateWithMemoryDescriptors(
177*0f4c859eSApple OSS Distributions	    uint64_t memoryDescriptorCreateOptions,
178*0f4c859eSApple OSS Distributions		uint32_t withDescriptorsCount,
179*0f4c859eSApple OSS Distributions		IOMemoryDescriptor * const withDescriptors[32],
180*0f4c859eSApple OSS Distributions		IOMemoryDescriptor ** memory) __attribute__((availability(driverkit,introduced=20.0)));
181*0f4c859eSApple OSS Distributions
182*0f4c859eSApple OSS Distributionsprivate:
183*0f4c859eSApple OSS Distributions	kern_return_t
184*0f4c859eSApple OSS Distributions	Map(
185*0f4c859eSApple OSS Distributions		uint64_t options,
186*0f4c859eSApple OSS Distributions		uint64_t address,
187*0f4c859eSApple OSS Distributions		uint64_t length,
188*0f4c859eSApple OSS Distributions		uint64_t alignment,
189*0f4c859eSApple OSS Distributions
190*0f4c859eSApple OSS Distributions		uint64_t * returnAddress,
191*0f4c859eSApple OSS Distributions		uint64_t * returnLength) LOCALONLY;
192*0f4c859eSApple OSS Distributions};
193*0f4c859eSApple OSS Distributions
194*0f4c859eSApple OSS Distributionsclass EXTENDS (IOMemoryDescriptor) IOMemoryDescriptorPrivate
195*0f4c859eSApple OSS Distributions{
196*0f4c859eSApple OSS Distributions	virtual kern_return_t
197*0f4c859eSApple OSS Distributions	_CopyState(
198*0f4c859eSApple OSS Distributions		_IOMDPrivateState * state);
199*0f4c859eSApple OSS Distributions};
200*0f4c859eSApple OSS Distributions
201*0f4c859eSApple OSS Distributions
202*0f4c859eSApple OSS Distributions
203*0f4c859eSApple OSS Distributions#endif /* ! _IOKIT_UIOMEMORYDESCRIPTOR_H */
204