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