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