1*c54f35caSApple OSS Distributions/* 2*c54f35caSApple OSS Distributions * Copyright (c) 2019-2019 Apple Inc. All rights reserved. 3*c54f35caSApple OSS Distributions * 4*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*c54f35caSApple OSS Distributions * 6*c54f35caSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*c54f35caSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*c54f35caSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*c54f35caSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*c54f35caSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*c54f35caSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*c54f35caSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*c54f35caSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*c54f35caSApple OSS Distributions * 15*c54f35caSApple OSS Distributions * Please obtain a copy of the License at 16*c54f35caSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*c54f35caSApple OSS Distributions * 18*c54f35caSApple OSS Distributions * The Original Code and all software distributed under the License are 19*c54f35caSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*c54f35caSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*c54f35caSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*c54f35caSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*c54f35caSApple OSS Distributions * Please see the License for the specific language governing rights and 24*c54f35caSApple OSS Distributions * limitations under the License. 25*c54f35caSApple OSS Distributions * 26*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*c54f35caSApple OSS Distributions */ 28*c54f35caSApple OSS Distributions 29*c54f35caSApple OSS Distributions#if !__IIG 30*c54f35caSApple OSS Distributions#if KERNEL 31*c54f35caSApple OSS Distributions#include <IOKit/IOMemoryDescriptor.h> 32*c54f35caSApple OSS Distributions#endif 33*c54f35caSApple OSS Distributions#endif 34*c54f35caSApple OSS Distributions 35*c54f35caSApple OSS Distributions#ifndef _IOKIT_UIOMEMORYDESCRIPTOR_H 36*c54f35caSApple OSS Distributions#define _IOKIT_UIOMEMORYDESCRIPTOR_H 37*c54f35caSApple OSS Distributions 38*c54f35caSApple OSS Distributions#include <DriverKit/OSObject.iig> 39*c54f35caSApple OSS Distributions 40*c54f35caSApple OSS Distributionsclass IOService; 41*c54f35caSApple OSS Distributionsclass IOMemoryMap; 42*c54f35caSApple OSS Distributions 43*c54f35caSApple OSS Distributions 44*c54f35caSApple OSS Distributions// IOMemoryDescriptor Create options 45*c54f35caSApple OSS Distributionsenum { 46*c54f35caSApple OSS Distributions kIOMemoryDirectionNone = 0x00000000, 47*c54f35caSApple OSS Distributions kIOMemoryDirectionIn = 0x00000001, 48*c54f35caSApple OSS Distributions kIOMemoryDirectionOut = 0x00000002, 49*c54f35caSApple OSS Distributions kIOMemoryDirectionOutIn = kIOMemoryDirectionIn | kIOMemoryDirectionOut, 50*c54f35caSApple OSS Distributions kIOMemoryDirectionInOut = kIOMemoryDirectionOutIn, 51*c54f35caSApple OSS Distributions kIOMemoryDisableCopyOnWrite = 0x00000010 52*c54f35caSApple OSS Distributions}; 53*c54f35caSApple OSS Distributions 54*c54f35caSApple OSS Distributions// IOMemoryDescriptor CreateMapping options 55*c54f35caSApple OSS Distributionsenum { 56*c54f35caSApple OSS Distributions kIOMemoryMapFixedAddress = 0x00000001, 57*c54f35caSApple OSS Distributions kIOMemoryMapReadOnly = 0x00000002, 58*c54f35caSApple OSS Distributions kIOMemoryMapGuardedMask = 0x0000001C, 59*c54f35caSApple OSS Distributions kIOMemoryMapGuardedDefault = 0x00000000, 60*c54f35caSApple OSS Distributions kIOMemoryMapGuardedNone = 0x00000004, 61*c54f35caSApple OSS Distributions kIOMemoryMapGuardedSmall = 0x00000008, 62*c54f35caSApple OSS Distributions kIOMemoryMapGuardedLarge = 0x0000000C, 63*c54f35caSApple OSS Distributions kIOMemoryMapCacheModeDefault = 0x00000000, 64*c54f35caSApple OSS Distributions kIOMemoryMapCacheModeInhibit = 0x00000100, 65*c54f35caSApple OSS Distributions kIOMemoryMapCacheModeCopyback = 0x00000200, 66*c54f35caSApple OSS Distributions kIOMemoryMapCacheModeWriteThrough = 0x00000400, 67*c54f35caSApple OSS Distributions}; 68*c54f35caSApple OSS Distributions 69*c54f35caSApple OSS Distributionsstruct IOAddressSegment { 70*c54f35caSApple OSS Distributions uint64_t address; 71*c54f35caSApple OSS Distributions uint64_t length; 72*c54f35caSApple OSS Distributions}; 73*c54f35caSApple OSS Distributions 74*c54f35caSApple OSS Distributionsstruct _IOMDPrivateState { 75*c54f35caSApple OSS Distributions uint64_t length; 76*c54f35caSApple OSS Distributions uint64_t options; 77*c54f35caSApple OSS Distributions}; 78*c54f35caSApple OSS Distributions 79*c54f35caSApple OSS Distributions/*! 80*c54f35caSApple OSS Distributions * @class IOMemoryDescriptor 81*c54f35caSApple OSS Distributions * 82*c54f35caSApple OSS Distributions * @abstract 83*c54f35caSApple OSS Distributions * IOMemoryDescriptor describes a memory buffer. 84*c54f35caSApple OSS Distributions * 85*c54f35caSApple OSS Distributions * @discussion 86*c54f35caSApple OSS Distributions * To allocate memory for I/O or sharing, use IOBufferMemoryDescriptor::Create() 87*c54f35caSApple OSS Distributions * Methods in this class are used for memory that was supplied as a parameter. 88*c54f35caSApple OSS Distributions * 89*c54f35caSApple OSS Distributions 90*c54f35caSApple OSS Distributions@iig implementation 91*c54f35caSApple OSS Distributions#include <DriverKit/IOService.h> 92*c54f35caSApple OSS Distributions@iig end 93*c54f35caSApple OSS Distributions*/ 94*c54f35caSApple OSS Distributions 95*c54f35caSApple OSS Distributionsclass KERNEL IOMemoryDescriptor : public OSObject 96*c54f35caSApple OSS Distributions{ 97*c54f35caSApple OSS Distributionspublic: 98*c54f35caSApple OSS Distributions 99*c54f35caSApple OSS Distributions 100*c54f35caSApple OSS Distributions virtual bool 101*c54f35caSApple OSS Distributions init() override; 102*c54f35caSApple OSS Distributions 103*c54f35caSApple OSS Distributions virtual void 104*c54f35caSApple OSS Distributions free() override; 105*c54f35caSApple OSS Distributions 106*c54f35caSApple OSS Distributions /*! 107*c54f35caSApple OSS Distributions * @brief Obtain the length of the memory described. 108*c54f35caSApple OSS Distributions * @param returnLength Returned length. 109*c54f35caSApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 110*c54f35caSApple OSS Distributions */ 111*c54f35caSApple OSS Distributions kern_return_t 112*c54f35caSApple OSS Distributions GetLength( 113*c54f35caSApple OSS Distributions uint64_t * returnLength) LOCALONLY; 114*c54f35caSApple OSS Distributions 115*c54f35caSApple OSS Distributions /*! 116*c54f35caSApple OSS Distributions * @brief Create a mapping of the memory in the callers address space. 117*c54f35caSApple OSS Distributions * @param options 118*c54f35caSApple OSS Distributions * kIOMemoryMapFixedAddress map at the address requested 119*c54f35caSApple OSS Distributions * kIOMemoryMapReadOnly create a read only mapping 120*c54f35caSApple OSS Distributions * kIOMemoryMapCacheModeDefault default cache mode 121*c54f35caSApple OSS Distributions * kIOMemoryMapCacheModeInhibit inhibited cache mode 122*c54f35caSApple OSS Distributions * kIOMemoryMapCacheModeCopyback copyback cache mode 123*c54f35caSApple OSS Distributions * kIOMemoryMapCacheModeWriteThrough write through cache mode 124*c54f35caSApple OSS Distributions * @param address Requested address if kIOMemoryMapFixedAddress was passed 125*c54f35caSApple OSS Distributions * @param offset Start offset of the mapping in the descriptor. 126*c54f35caSApple OSS Distributions * @param length Pass zero to map the entire memory, or a value <= the length of the descriptor. 127*c54f35caSApple OSS Distributions * @param alignment of the memory virtual mapping. Only zero for no alignment is supported. 128*c54f35caSApple OSS Distributions * @param map Returned IOMemoryMap object with +1 retain count. 129*c54f35caSApple OSS Distributions * It should be retained until the map is no longer required. 130*c54f35caSApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 131*c54f35caSApple OSS Distributions */ 132*c54f35caSApple OSS Distributions virtual kern_return_t 133*c54f35caSApple OSS Distributions CreateMapping( 134*c54f35caSApple OSS Distributions uint64_t options, 135*c54f35caSApple OSS Distributions uint64_t address, 136*c54f35caSApple OSS Distributions uint64_t offset, 137*c54f35caSApple OSS Distributions uint64_t length, 138*c54f35caSApple OSS Distributions uint64_t alignment, 139*c54f35caSApple OSS Distributions IOMemoryMap ** map); 140*c54f35caSApple OSS Distributions 141*c54f35caSApple OSS Distributions /*! 142*c54f35caSApple OSS Distributions * @brief Create a memory descriptor that is a subrange of another memory 143*c54f35caSApple OSS Distributions * descriptor 144*c54f35caSApple OSS Distributions * @param memoryDescriptorCreateOptions 145*c54f35caSApple OSS Distributions * kIOMemoryDirectionIn memory described will be writable 146*c54f35caSApple OSS Distributions * kIOMemoryDirectionOut memory described will be readable 147*c54f35caSApple OSS Distributions * @param offset Start offset of the memory relative to the descriptor ofDescriptor. 148*c54f35caSApple OSS Distributions * @param length Length of the memory. 149*c54f35caSApple OSS Distributions * @param ofDescriptor Memory descriptor describing source memory. 150*c54f35caSApple OSS Distributions * @param memory Returned IOMemoryDescriptor object with +1 retain count. 151*c54f35caSApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 152*c54f35caSApple OSS Distributions */ 153*c54f35caSApple OSS Distributions static kern_return_t 154*c54f35caSApple OSS Distributions CreateSubMemoryDescriptor( 155*c54f35caSApple OSS Distributions uint64_t memoryDescriptorCreateOptions, 156*c54f35caSApple OSS Distributions uint64_t offset, 157*c54f35caSApple OSS Distributions uint64_t length, 158*c54f35caSApple OSS Distributions IOMemoryDescriptor * ofDescriptor, 159*c54f35caSApple OSS Distributions IOMemoryDescriptor ** memory) __attribute__((availability(driverkit,introduced=20.0))); 160*c54f35caSApple OSS Distributions 161*c54f35caSApple OSS Distributions /*! 162*c54f35caSApple OSS Distributions * @brief Create a memory descriptor that is a concatenation of a set of memory 163*c54f35caSApple OSS Distributions * descriptors 164*c54f35caSApple OSS Distributions * @param memoryDescriptorCreateOptions 165*c54f35caSApple OSS Distributions * kIOMemoryDirectionIn memory described will be writable. The source 166*c54f35caSApple OSS Distributions * descriptors must include this direction. 167*c54f35caSApple OSS Distributions * kIOMemoryDirectionOut memory described will be readable. The source 168*c54f35caSApple OSS Distributions * descriptors must include this direction. 169*c54f35caSApple OSS Distributions * @param withDescriptorsCount Number of valid memory descriptors being passed 170*c54f35caSApple OSS Distributions * in the withDescriptors array. 171*c54f35caSApple OSS Distributions * @param withDescriptors Source memory descriptor array. 172*c54f35caSApple OSS Distributions * @param memory Returned IOMemoryDescriptor object with +1 retain count. 173*c54f35caSApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 174*c54f35caSApple OSS Distributions */ 175*c54f35caSApple OSS Distributions static kern_return_t 176*c54f35caSApple OSS Distributions CreateWithMemoryDescriptors( 177*c54f35caSApple OSS Distributions uint64_t memoryDescriptorCreateOptions, 178*c54f35caSApple OSS Distributions uint32_t withDescriptorsCount, 179*c54f35caSApple OSS Distributions IOMemoryDescriptor * const withDescriptors[32], 180*c54f35caSApple OSS Distributions IOMemoryDescriptor ** memory) __attribute__((availability(driverkit,introduced=20.0))); 181*c54f35caSApple OSS Distributions 182*c54f35caSApple OSS Distributionsprivate: 183*c54f35caSApple OSS Distributions kern_return_t 184*c54f35caSApple OSS Distributions Map( 185*c54f35caSApple OSS Distributions uint64_t options, 186*c54f35caSApple OSS Distributions uint64_t address, 187*c54f35caSApple OSS Distributions uint64_t length, 188*c54f35caSApple OSS Distributions uint64_t alignment, 189*c54f35caSApple OSS Distributions 190*c54f35caSApple OSS Distributions uint64_t * returnAddress, 191*c54f35caSApple OSS Distributions uint64_t * returnLength) LOCALONLY; 192*c54f35caSApple OSS Distributions}; 193*c54f35caSApple OSS Distributions 194*c54f35caSApple OSS Distributionsclass EXTENDS (IOMemoryDescriptor) IOMemoryDescriptorPrivate 195*c54f35caSApple OSS Distributions{ 196*c54f35caSApple OSS Distributions virtual kern_return_t 197*c54f35caSApple OSS Distributions _CopyState( 198*c54f35caSApple OSS Distributions _IOMDPrivateState * state); 199*c54f35caSApple OSS Distributions}; 200*c54f35caSApple OSS Distributions 201*c54f35caSApple OSS Distributions 202*c54f35caSApple OSS Distributions 203*c54f35caSApple OSS Distributions#endif /* ! _IOKIT_UIOMEMORYDESCRIPTOR_H */ 204