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