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