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