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