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