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