xref: /xnu-12377.1.9/iokit/IOKit/IOBufferMemoryDescriptor.h (revision f6217f891ac0bb64f3d375211650a4c1ff8ca1ea) !
1*f6217f89SApple OSS Distributions /*
2*f6217f89SApple OSS Distributions  * Copyright (c) 1998-2016 Apple Inc. All rights reserved.
3*f6217f89SApple OSS Distributions  *
4*f6217f89SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*f6217f89SApple OSS Distributions  *
6*f6217f89SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*f6217f89SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*f6217f89SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*f6217f89SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*f6217f89SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*f6217f89SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*f6217f89SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*f6217f89SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*f6217f89SApple OSS Distributions  *
15*f6217f89SApple OSS Distributions  * Please obtain a copy of the License at
16*f6217f89SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*f6217f89SApple OSS Distributions  *
18*f6217f89SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*f6217f89SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*f6217f89SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*f6217f89SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*f6217f89SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*f6217f89SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*f6217f89SApple OSS Distributions  * limitations under the License.
25*f6217f89SApple OSS Distributions  *
26*f6217f89SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*f6217f89SApple OSS Distributions  */
28*f6217f89SApple OSS Distributions #ifndef _IOBUFFERMEMORYDESCRIPTOR_H
29*f6217f89SApple OSS Distributions #define _IOBUFFERMEMORYDESCRIPTOR_H
30*f6217f89SApple OSS Distributions 
31*f6217f89SApple OSS Distributions #include <libkern/c++/OSPtr.h>
32*f6217f89SApple OSS Distributions #include <IOKit/IOMemoryDescriptor.h>
33*f6217f89SApple OSS Distributions #include <DriverKit/IOBufferMemoryDescriptor.h>
34*f6217f89SApple OSS Distributions 
35*f6217f89SApple OSS Distributions enum {
36*f6217f89SApple OSS Distributions 	kIOMemoryPhysicallyContiguous       = 0x00000010,
37*f6217f89SApple OSS Distributions 	kIOMemoryPageable                   = 0x00000020,
38*f6217f89SApple OSS Distributions 	kIOMemoryPurgeable                  = 0x00000040,
39*f6217f89SApple OSS Distributions 	kIOMemoryHostPhysicallyContiguous   = 0x00000080,
40*f6217f89SApple OSS Distributions 	kIOMemorySharingTypeMask            = 0x000f0000,
41*f6217f89SApple OSS Distributions 	kIOMemoryUnshared                   = 0x00000000,
42*f6217f89SApple OSS Distributions 	kIOMemoryKernelUserShared           = 0x00010000,
43*f6217f89SApple OSS Distributions 	// shared IOMemoryDescriptor options for IOBufferMemoryDescriptor:
44*f6217f89SApple OSS Distributions 	kIOBufferDescriptorMemoryFlags      = kIOMemoryDirectionMask
45*f6217f89SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
46*f6217f89SApple OSS Distributions 	    | kIOMemoryAutoPrepare
47*f6217f89SApple OSS Distributions #endif
48*f6217f89SApple OSS Distributions 	    | kIOMemoryThreadSafe
49*f6217f89SApple OSS Distributions 	    | kIOMemoryClearEncrypt
50*f6217f89SApple OSS Distributions 	    | kIOMemoryMapperNone
51*f6217f89SApple OSS Distributions 	    | kIOMemoryUseReserve
52*f6217f89SApple OSS Distributions };
53*f6217f89SApple OSS Distributions 
54*f6217f89SApple OSS Distributions #define _IOBUFFERMEMORYDESCRIPTOR_INTASKWITHOPTIONS_            1
55*f6217f89SApple OSS Distributions #define _IOBUFFERMEMORYDESCRIPTOR_HOSTPHYSICALLYCONTIGUOUS_     1
56*f6217f89SApple OSS Distributions #define IOBUFFERMEMORYDESCRIPTOR_SUPPORTS_INTASKWITHOPTIONS_TAGS        1
57*f6217f89SApple OSS Distributions /*!
58*f6217f89SApple OSS Distributions  *   @class IOBufferMemoryDescriptor
59*f6217f89SApple OSS Distributions  *   @abstract Provides a simple memory descriptor that allocates its own buffer memory.
60*f6217f89SApple OSS Distributions  */
61*f6217f89SApple OSS Distributions 
62*f6217f89SApple OSS Distributions class IOBufferMemoryDescriptor : public IOGeneralMemoryDescriptor
63*f6217f89SApple OSS Distributions {
64*f6217f89SApple OSS Distributions 	OSDeclareDefaultStructorsWithDispatch(IOBufferMemoryDescriptor);
65*f6217f89SApple OSS Distributions 
66*f6217f89SApple OSS Distributions private:
67*f6217f89SApple OSS Distributions /*! @struct ExpansionData
68*f6217f89SApple OSS Distributions  *   @discussion This structure will be used to expand the capablilties of this class in the future.
69*f6217f89SApple OSS Distributions  */
70*f6217f89SApple OSS Distributions 	struct ExpansionData {
71*f6217f89SApple OSS Distributions 		IOMemoryMap *   map;
72*f6217f89SApple OSS Distributions 	};
73*f6217f89SApple OSS Distributions 
74*f6217f89SApple OSS Distributions /*! @var reserved
75*f6217f89SApple OSS Distributions  *   Reserved for future use.  (Internal use only)  */
76*f6217f89SApple OSS Distributions 	APPLE_KEXT_WSHADOW_PUSH;
77*f6217f89SApple OSS Distributions 	ExpansionData * reserved;
78*f6217f89SApple OSS Distributions 
79*f6217f89SApple OSS Distributions protected:
80*f6217f89SApple OSS Distributions 	void *               _buffer;
81*f6217f89SApple OSS Distributions 	vm_size_t            _capacity;
82*f6217f89SApple OSS Distributions 	vm_offset_t          _alignment;
83*f6217f89SApple OSS Distributions 	IOOptionBits         _options;
84*f6217f89SApple OSS Distributions private:
85*f6217f89SApple OSS Distributions 	uintptr_t            _internalReserved;
86*f6217f89SApple OSS Distributions 	unsigned             _internalFlags;
87*f6217f89SApple OSS Distributions 	APPLE_KEXT_WSHADOW_POP;
88*f6217f89SApple OSS Distributions 
89*f6217f89SApple OSS Distributions private:
90*f6217f89SApple OSS Distributions #ifndef __LP64__
91*f6217f89SApple OSS Distributions 	virtual bool initWithOptions(
92*f6217f89SApple OSS Distributions 		IOOptionBits options,
93*f6217f89SApple OSS Distributions 		vm_size_t    capacity,
94*f6217f89SApple OSS Distributions 		vm_offset_t  alignment,
95*f6217f89SApple OSS Distributions 		task_t       inTask) APPLE_KEXT_DEPRECATED;                /* use withOptions() instead */
96*f6217f89SApple OSS Distributions #endif /* !__LP64__ */
97*f6217f89SApple OSS Distributions 
98*f6217f89SApple OSS Distributions public:
99*f6217f89SApple OSS Distributions 	virtual bool initWithPhysicalMask(
100*f6217f89SApple OSS Distributions 		task_t            inTask,
101*f6217f89SApple OSS Distributions 		IOOptionBits      options,
102*f6217f89SApple OSS Distributions 		mach_vm_size_t    capacity,
103*f6217f89SApple OSS Distributions 		mach_vm_address_t alignment,
104*f6217f89SApple OSS Distributions 		mach_vm_address_t physicalMask);
105*f6217f89SApple OSS Distributions 
106*f6217f89SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
107*f6217f89SApple OSS Distributions /*
108*f6217f89SApple OSS Distributions  * By default the buffer allocated in IOBufferMemoryDescriptor is
109*f6217f89SApple OSS Distributions  * considered to contain "pure data" and no kernel pointers. It
110*f6217f89SApple OSS Distributions  * is therefore colocated with other data buffers.
111*f6217f89SApple OSS Distributions  *
112*f6217f89SApple OSS Distributions  * This API allows to create a buffer that contains pointers and
113*f6217f89SApple OSS Distributions  * will not be redirected to the data heap/map.
114*f6217f89SApple OSS Distributions  */
115*f6217f89SApple OSS Distributions 	bool initControlWithPhysicalMask(
116*f6217f89SApple OSS Distributions 		task_t            inTask,
117*f6217f89SApple OSS Distributions 		IOOptionBits      options,
118*f6217f89SApple OSS Distributions 		mach_vm_size_t    capacity,
119*f6217f89SApple OSS Distributions 		mach_vm_address_t alignment,
120*f6217f89SApple OSS Distributions 		mach_vm_address_t physicalMask);
121*f6217f89SApple OSS Distributions #endif
122*f6217f89SApple OSS Distributions 
123*f6217f89SApple OSS Distributions #ifdef KERNEL_PRIVATE
124*f6217f89SApple OSS Distributions 	/*
125*f6217f89SApple OSS Distributions 	 * Create an IOBufferMemoryDescriptor with guard pages on each side of the buffer allocation.
126*f6217f89SApple OSS Distributions 	 * @param inTask The task the buffer will be allocated in. Pass NULL to allocate unmapped memory.
127*f6217f89SApple OSS Distributions 	 * @param options Options for the IOBufferMemoryDescriptor. See inTaskWithOptions for a description of available options.
128*f6217f89SApple OSS Distributions 	 *                Some options are not available when using guard pages. Specifically, physically contiguous memory and pageable memory
129*f6217f89SApple OSS Distributions 	 *                options are not supported. If these options are used, this will fail to create the memory descriptor and return NULL.
130*f6217f89SApple OSS Distributions 	 * @param capacity The number of bytes to allocate. Due to how memory with guard pages is allocated, this will be rounded up to page size.
131*f6217f89SApple OSS Distributions 	 *                 The buffer will also always be aligned to the page size.
132*f6217f89SApple OSS Distributions 	 * @result Returns an instance of class IOBufferMemoryDescriptor to be released by the caller, which will free the memory descriptor and associated buffer.
133*f6217f89SApple OSS Distributions 	 */
134*f6217f89SApple OSS Distributions 	static OSPtr<IOBufferMemoryDescriptor> inTaskWithGuardPages(
135*f6217f89SApple OSS Distributions 		task_t            inTask,
136*f6217f89SApple OSS Distributions 		IOOptionBits      options,
137*f6217f89SApple OSS Distributions 		mach_vm_size_t    capacity);
138*f6217f89SApple OSS Distributions 
139*f6217f89SApple OSS Distributions 	bool initWithGuardPages(
140*f6217f89SApple OSS Distributions 		task_t            inTask,
141*f6217f89SApple OSS Distributions 		IOOptionBits      options,
142*f6217f89SApple OSS Distributions 		mach_vm_size_t    capacity);
143*f6217f89SApple OSS Distributions #endif
144*f6217f89SApple OSS Distributions 
145*f6217f89SApple OSS Distributions #ifdef __LP64__
146*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 0);
147*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 1);
148*f6217f89SApple OSS Distributions #else /* !__LP64__ */
149*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOBufferMemoryDescriptor, 0);
150*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOBufferMemoryDescriptor, 1);
151*f6217f89SApple OSS Distributions #endif /* !__LP64__ */
152*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 2);
153*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 3);
154*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 4);
155*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 5);
156*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 6);
157*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 7);
158*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 8);
159*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 9);
160*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 10);
161*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 11);
162*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 12);
163*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 13);
164*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 14);
165*f6217f89SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 15);
166*f6217f89SApple OSS Distributions 
167*f6217f89SApple OSS Distributions protected:
168*f6217f89SApple OSS Distributions 	virtual void free() APPLE_KEXT_OVERRIDE;
169*f6217f89SApple OSS Distributions 
170*f6217f89SApple OSS Distributions public:
171*f6217f89SApple OSS Distributions 
172*f6217f89SApple OSS Distributions /*
173*f6217f89SApple OSS Distributions  * withOptions:
174*f6217f89SApple OSS Distributions  *
175*f6217f89SApple OSS Distributions  * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
176*f6217f89SApple OSS Distributions  * hold capacity bytes.  The descriptor's length is initially set to the
177*f6217f89SApple OSS Distributions  * capacity.
178*f6217f89SApple OSS Distributions  */
179*f6217f89SApple OSS Distributions #ifndef __LP64__
180*f6217f89SApple OSS Distributions 	virtual bool initWithOptions(   IOOptionBits options,
181*f6217f89SApple OSS Distributions 	    vm_size_t    capacity,
182*f6217f89SApple OSS Distributions 	    vm_offset_t  alignment) APPLE_KEXT_DEPRECATED;                         /* use withOptions() instead */
183*f6217f89SApple OSS Distributions #endif /* !__LP64__ */
184*f6217f89SApple OSS Distributions 
185*f6217f89SApple OSS Distributions 	static OSPtr<IOBufferMemoryDescriptor> withCopy(
186*f6217f89SApple OSS Distributions 		task_t            inTask,
187*f6217f89SApple OSS Distributions 		IOOptionBits      options,
188*f6217f89SApple OSS Distributions 		vm_map_t          sourceMap,
189*f6217f89SApple OSS Distributions 		mach_vm_address_t source,
190*f6217f89SApple OSS Distributions 		mach_vm_size_t    size);
191*f6217f89SApple OSS Distributions 
192*f6217f89SApple OSS Distributions 	static OSPtr<IOBufferMemoryDescriptor> withOptions(  IOOptionBits options,
193*f6217f89SApple OSS Distributions 	    vm_size_t    capacity,
194*f6217f89SApple OSS Distributions 	    vm_offset_t  alignment = 1);
195*f6217f89SApple OSS Distributions 
196*f6217f89SApple OSS Distributions /*! @function inTaskWithOptions
197*f6217f89SApple OSS Distributions  *   @abstract Creates a memory buffer with memory descriptor for that buffer.
198*f6217f89SApple OSS Distributions  *   @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.
199*f6217f89SApple OSS Distributions  *   @param inTask The task the buffer will be allocated in. Pass NULL to allocate unmapped memory.
200*f6217f89SApple OSS Distributions  *   @param options Options for the allocation:<br>
201*f6217f89SApple OSS Distributions  *   kIODirectionOut, kIODirectionIn - set the direction of the I/O transfer.<br>
202*f6217f89SApple OSS Distributions  *   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>
203*f6217f89SApple OSS Distributions  *   kIOMemoryPageable - pass to request memory be non-wired - the default for kernel allocated memory is wired.<br>
204*f6217f89SApple OSS Distributions  *   kIOMemoryPurgeable - pass to request memory that may later have its purgeable state set with IOMemoryDescriptor::setPurgeable. Only supported for kIOMemoryPageable allocations.<br>
205*f6217f89SApple OSS Distributions  *   kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.<br>
206*f6217f89SApple OSS Distributions  *   kIOMapInhibitCache - allocate memory with inhibited cache setting. <br>
207*f6217f89SApple OSS Distributions  *   kIOMapWriteThruCache - allocate memory with writethru cache setting. <br>
208*f6217f89SApple OSS Distributions  *   kIOMapCopybackCache - allocate memory with copyback cache setting. <br>
209*f6217f89SApple OSS Distributions  *   kIOMapWriteCombineCache - allocate memory with writecombined cache setting.
210*f6217f89SApple OSS Distributions  *   @param capacity The number of bytes to allocate.
211*f6217f89SApple OSS Distributions  *   @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.
212*f6217f89SApple OSS Distributions  *   @result Returns an instance of class IOBufferMemoryDescriptor to be released by the caller, which will free the memory desriptor and associated buffer. */
213*f6217f89SApple OSS Distributions 
214*f6217f89SApple OSS Distributions 	static OSPtr<IOBufferMemoryDescriptor> inTaskWithOptions(
215*f6217f89SApple OSS Distributions 		task_t       inTask,
216*f6217f89SApple OSS Distributions 		IOOptionBits options,
217*f6217f89SApple OSS Distributions 		vm_size_t    capacity,
218*f6217f89SApple OSS Distributions 		vm_offset_t  alignment = 1);
219*f6217f89SApple OSS Distributions 
220*f6217f89SApple OSS Distributions /*! @function inTaskWithOptions
221*f6217f89SApple OSS Distributions  *   @abstract Creates a memory buffer with memory descriptor for that buffer.
222*f6217f89SApple OSS Distributions  *   @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.
223*f6217f89SApple OSS Distributions  *   @param inTask The task the buffer will be allocated in. Pass NULL to allocate unmapped memory.
224*f6217f89SApple OSS Distributions  *   @param options Options for the allocation:<br>
225*f6217f89SApple OSS Distributions  *   kIODirectionOut, kIODirectionIn - set the direction of the I/O transfer.<br>
226*f6217f89SApple OSS Distributions  *   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>
227*f6217f89SApple OSS Distributions  *   kIOMemoryPageable - pass to request memory be non-wired - the default for kernel allocated memory is wired.<br>
228*f6217f89SApple OSS Distributions  *   kIOMemoryPurgeable - pass to request memory that may later have its purgeable state set with IOMemoryDescriptor::setPurgeable. Only supported for kIOMemoryPageable allocations.<br>
229*f6217f89SApple OSS Distributions  *   kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.<br>
230*f6217f89SApple OSS Distributions  *   kIOMapInhibitCache - allocate memory with inhibited cache setting. <br>
231*f6217f89SApple OSS Distributions  *   kIOMapWriteThruCache - allocate memory with writethru cache setting. <br>
232*f6217f89SApple OSS Distributions  *   kIOMapCopybackCache - allocate memory with copyback cache setting. <br>
233*f6217f89SApple OSS Distributions  *   kIOMapWriteCombineCache - allocate memory with writecombined cache setting.
234*f6217f89SApple OSS Distributions  *   @param capacity The number of bytes to allocate.
235*f6217f89SApple OSS Distributions  *   @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.
236*f6217f89SApple OSS Distributions  *   @param kernTag The kernel memory tag
237*f6217f89SApple OSS Distributions  *   @param userTag The user memory tag
238*f6217f89SApple OSS Distributions  *   @result Returns an instance of class IOBufferMemoryDescriptor to be released by the caller, which will free the memory desriptor and associated buffer. */
239*f6217f89SApple OSS Distributions 
240*f6217f89SApple OSS Distributions 	static OSPtr<IOBufferMemoryDescriptor> inTaskWithOptions(
241*f6217f89SApple OSS Distributions 		task_t       inTask,
242*f6217f89SApple OSS Distributions 		IOOptionBits options,
243*f6217f89SApple OSS Distributions 		vm_size_t    capacity,
244*f6217f89SApple OSS Distributions 		vm_offset_t  alignment,
245*f6217f89SApple OSS Distributions 		uint32_t     kernTag,
246*f6217f89SApple OSS Distributions 		uint32_t     userTag);
247*f6217f89SApple OSS Distributions 
248*f6217f89SApple OSS Distributions /*! @function inTaskWithPhysicalMask
249*f6217f89SApple OSS Distributions  *   @abstract Creates a memory buffer with memory descriptor for that buffer.
250*f6217f89SApple OSS Distributions  *   @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.
251*f6217f89SApple OSS Distributions  *   @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).
252*f6217f89SApple OSS Distributions  *   @param options Options for the allocation:<br>
253*f6217f89SApple OSS Distributions  *   kIODirectionOut, kIODirectionIn - set the direction of the I/O transfer.<br>
254*f6217f89SApple OSS Distributions  *   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>
255*f6217f89SApple OSS Distributions  *   kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.<br>
256*f6217f89SApple OSS Distributions  *   kIOMapInhibitCache - allocate memory with inhibited cache setting. <br>
257*f6217f89SApple OSS Distributions  *   kIOMapWriteThruCache - allocate memory with writethru cache setting. <br>
258*f6217f89SApple OSS Distributions  *   kIOMapCopybackCache - allocate memory with copyback cache setting. <br>
259*f6217f89SApple OSS Distributions  *   kIOMapWriteCombineCache - allocate memory with writecombined cache setting.
260*f6217f89SApple OSS Distributions  *   @param capacity The number of bytes to allocate.
261*f6217f89SApple OSS Distributions  *   @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.
262*f6217f89SApple OSS Distributions  *   @result Returns an instance of class IOBufferMemoryDescriptor to be released by the caller, which will free the memory desriptor and associated buffer. */
263*f6217f89SApple OSS Distributions 
264*f6217f89SApple OSS Distributions 	static OSPtr<IOBufferMemoryDescriptor> inTaskWithPhysicalMask(
265*f6217f89SApple OSS Distributions 		task_t            inTask,
266*f6217f89SApple OSS Distributions 		IOOptionBits      options,
267*f6217f89SApple OSS Distributions 		mach_vm_size_t    capacity,
268*f6217f89SApple OSS Distributions 		mach_vm_address_t physicalMask);
269*f6217f89SApple OSS Distributions 
270*f6217f89SApple OSS Distributions /*
271*f6217f89SApple OSS Distributions  * withCapacity:
272*f6217f89SApple OSS Distributions  *
273*f6217f89SApple OSS Distributions  * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
274*f6217f89SApple OSS Distributions  * hold capacity bytes.  The descriptor's length is initially set to the
275*f6217f89SApple OSS Distributions  * capacity.
276*f6217f89SApple OSS Distributions  */
277*f6217f89SApple OSS Distributions 	static OSPtr<IOBufferMemoryDescriptor> withCapacity(
278*f6217f89SApple OSS Distributions 		vm_size_t    capacity __xnu_data_size,
279*f6217f89SApple OSS Distributions 		IODirection  withDirection,
280*f6217f89SApple OSS Distributions 		bool         withContiguousMemory = false);
281*f6217f89SApple OSS Distributions #ifndef __LP64__
282*f6217f89SApple OSS Distributions 	virtual bool initWithBytes(const void * bytes,
283*f6217f89SApple OSS Distributions 	    vm_size_t    withLength,
284*f6217f89SApple OSS Distributions 	    IODirection  withDirection,
285*f6217f89SApple OSS Distributions 	    bool         withContiguousMemory = false) APPLE_KEXT_DEPRECATED;                    /* use withBytes() instead */
286*f6217f89SApple OSS Distributions #endif /* !__LP64__ */
287*f6217f89SApple OSS Distributions 
288*f6217f89SApple OSS Distributions /*
289*f6217f89SApple OSS Distributions  * withBytes:
290*f6217f89SApple OSS Distributions  *
291*f6217f89SApple OSS Distributions  * Returns a new IOBufferMemoryDescriptor preloaded with bytes (copied).
292*f6217f89SApple OSS Distributions  * The descriptor's length and capacity are set to the input buffer's size.
293*f6217f89SApple OSS Distributions  */
294*f6217f89SApple OSS Distributions 	static OSPtr<IOBufferMemoryDescriptor> withBytes(
295*f6217f89SApple OSS Distributions 		const void * bytes,
296*f6217f89SApple OSS Distributions 		vm_size_t    withLength __xnu_data_size,
297*f6217f89SApple OSS Distributions 		IODirection  withDirection,
298*f6217f89SApple OSS Distributions 		bool         withContiguousMemory = false);
299*f6217f89SApple OSS Distributions 
300*f6217f89SApple OSS Distributions /*
301*f6217f89SApple OSS Distributions  * setLength:
302*f6217f89SApple OSS Distributions  *
303*f6217f89SApple OSS Distributions  * Change the buffer length of the memory descriptor.  When a new buffer
304*f6217f89SApple OSS Distributions  * is created, the initial length of the buffer is set to be the same as
305*f6217f89SApple OSS Distributions  * the capacity.  The length can be adjusted via setLength for a shorter
306*f6217f89SApple OSS Distributions  * transfer (there is no need to create more buffer descriptors when you
307*f6217f89SApple OSS Distributions  * can reuse an existing one, even for different transfer sizes).   Note
308*f6217f89SApple OSS Distributions  * that the specified length must not exceed the capacity of the buffer.
309*f6217f89SApple OSS Distributions  */
310*f6217f89SApple OSS Distributions 	virtual void setLength(vm_size_t length);
311*f6217f89SApple OSS Distributions 
312*f6217f89SApple OSS Distributions /*
313*f6217f89SApple OSS Distributions  * setDirection:
314*f6217f89SApple OSS Distributions  *
315*f6217f89SApple OSS Distributions  * Change the direction of the transfer.  This method allows one to redirect
316*f6217f89SApple OSS Distributions  * the descriptor's transfer direction.  This eliminates the need to destroy
317*f6217f89SApple OSS Distributions  * and create new buffers when different transfer directions are needed.
318*f6217f89SApple OSS Distributions  */
319*f6217f89SApple OSS Distributions 	virtual void setDirection(IODirection direction);
320*f6217f89SApple OSS Distributions 
321*f6217f89SApple OSS Distributions /*
322*f6217f89SApple OSS Distributions  * getCapacity:
323*f6217f89SApple OSS Distributions  *
324*f6217f89SApple OSS Distributions  * Get the buffer capacity
325*f6217f89SApple OSS Distributions  */
326*f6217f89SApple OSS Distributions 	virtual vm_size_t getCapacity() const;
327*f6217f89SApple OSS Distributions 
328*f6217f89SApple OSS Distributions /*
329*f6217f89SApple OSS Distributions  * getBytesNoCopy:
330*f6217f89SApple OSS Distributions  *
331*f6217f89SApple OSS Distributions  * Return the virtual address of the beginning of the buffer
332*f6217f89SApple OSS Distributions  */
333*f6217f89SApple OSS Distributions 	__xnu_returns_data_pointer
334*f6217f89SApple OSS Distributions 	virtual void *getBytesNoCopy();
335*f6217f89SApple OSS Distributions 
336*f6217f89SApple OSS Distributions /*
337*f6217f89SApple OSS Distributions  * getBytesNoCopy:
338*f6217f89SApple OSS Distributions  *
339*f6217f89SApple OSS Distributions  * Return the virtual address of an offset from the beginning of the buffer
340*f6217f89SApple OSS Distributions  */
341*f6217f89SApple OSS Distributions 	__xnu_returns_data_pointer
342*f6217f89SApple OSS Distributions 	virtual void *getBytesNoCopy(vm_size_t start, vm_size_t withLength);
343*f6217f89SApple OSS Distributions 
344*f6217f89SApple OSS Distributions /*
345*f6217f89SApple OSS Distributions  * appendBytes:
346*f6217f89SApple OSS Distributions  *
347*f6217f89SApple OSS Distributions  * Add some data to the end of the buffer.  This method automatically
348*f6217f89SApple OSS Distributions  * maintains the memory descriptor buffer length.  Note that appendBytes
349*f6217f89SApple OSS Distributions  * will not copy past the end of the memory descriptor's current capacity.
350*f6217f89SApple OSS Distributions  */
351*f6217f89SApple OSS Distributions 	virtual bool appendBytes(const void *bytes, vm_size_t withLength __xnu_data_size);
352*f6217f89SApple OSS Distributions 
353*f6217f89SApple OSS Distributions #ifndef __LP64__
354*f6217f89SApple OSS Distributions 	virtual void * getVirtualSegment(IOByteCount offset,
355*f6217f89SApple OSS Distributions 	    IOByteCount * length) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;                             /* use getBytesNoCopy() instead */
356*f6217f89SApple OSS Distributions #endif /* !__LP64__ */
357*f6217f89SApple OSS Distributions };
358*f6217f89SApple OSS Distributions 
359*f6217f89SApple OSS Distributions #endif /* !_IOBUFFERMEMORYDESCRIPTOR_H */
360