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