1*bbb1b6f9SApple OSS Distributions /* 2*bbb1b6f9SApple OSS Distributions * Copyright (c) 1998-2016 Apple Inc. All rights reserved. 3*bbb1b6f9SApple OSS Distributions * 4*bbb1b6f9SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*bbb1b6f9SApple OSS Distributions * 6*bbb1b6f9SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*bbb1b6f9SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*bbb1b6f9SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*bbb1b6f9SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*bbb1b6f9SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*bbb1b6f9SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*bbb1b6f9SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*bbb1b6f9SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*bbb1b6f9SApple OSS Distributions * 15*bbb1b6f9SApple OSS Distributions * Please obtain a copy of the License at 16*bbb1b6f9SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*bbb1b6f9SApple OSS Distributions * 18*bbb1b6f9SApple OSS Distributions * The Original Code and all software distributed under the License are 19*bbb1b6f9SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*bbb1b6f9SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*bbb1b6f9SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*bbb1b6f9SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*bbb1b6f9SApple OSS Distributions * Please see the License for the specific language governing rights and 24*bbb1b6f9SApple OSS Distributions * limitations under the License. 25*bbb1b6f9SApple OSS Distributions * 26*bbb1b6f9SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*bbb1b6f9SApple OSS Distributions */ 28*bbb1b6f9SApple OSS Distributions 29*bbb1b6f9SApple OSS Distributions #ifndef __IOKIT_IOMAPPER_H 30*bbb1b6f9SApple OSS Distributions #define __IOKIT_IOMAPPER_H 31*bbb1b6f9SApple OSS Distributions 32*bbb1b6f9SApple OSS Distributions #include <sys/cdefs.h> 33*bbb1b6f9SApple OSS Distributions #include <IOKit/IOTypes.h> 34*bbb1b6f9SApple OSS Distributions #include <mach/vm_types.h> 35*bbb1b6f9SApple OSS Distributions 36*bbb1b6f9SApple OSS Distributions __BEGIN_DECLS 37*bbb1b6f9SApple OSS Distributions 38*bbb1b6f9SApple OSS Distributions // These are C accessors to the system mapper for non-IOKit clients 39*bbb1b6f9SApple OSS Distributions ppnum_t IOMapperIOVMAlloc(unsigned pages); 40*bbb1b6f9SApple OSS Distributions void IOMapperIOVMFree(ppnum_t addr, unsigned pages); 41*bbb1b6f9SApple OSS Distributions ppnum_t IOMapperInsertPage(ppnum_t addr, unsigned offset, ppnum_t page); 42*bbb1b6f9SApple OSS Distributions 43*bbb1b6f9SApple OSS Distributions __END_DECLS 44*bbb1b6f9SApple OSS Distributions 45*bbb1b6f9SApple OSS Distributions #if __cplusplus 46*bbb1b6f9SApple OSS Distributions 47*bbb1b6f9SApple OSS Distributions #include <IOKit/IOService.h> 48*bbb1b6f9SApple OSS Distributions #include <IOKit/IOMemoryDescriptor.h> 49*bbb1b6f9SApple OSS Distributions #include <IOKit/IODMACommand.h> 50*bbb1b6f9SApple OSS Distributions #include <libkern/c++/OSPtr.h> 51*bbb1b6f9SApple OSS Distributions 52*bbb1b6f9SApple OSS Distributions class OSData; 53*bbb1b6f9SApple OSS Distributions 54*bbb1b6f9SApple OSS Distributions extern const OSSymbol * gIOMapperIDKey; 55*bbb1b6f9SApple OSS Distributions 56*bbb1b6f9SApple OSS Distributions class IOMapper : public IOService 57*bbb1b6f9SApple OSS Distributions { 58*bbb1b6f9SApple OSS Distributions OSDeclareAbstractStructors(IOMapper); 59*bbb1b6f9SApple OSS Distributions 60*bbb1b6f9SApple OSS Distributions // Give the platform expert access to setMapperRequired(); 61*bbb1b6f9SApple OSS Distributions friend class IOPlatformExpert; 62*bbb1b6f9SApple OSS Distributions friend class IOMemoryDescriptor; 63*bbb1b6f9SApple OSS Distributions friend class IOGeneralMemoryDescriptor; 64*bbb1b6f9SApple OSS Distributions 65*bbb1b6f9SApple OSS Distributions private: 66*bbb1b6f9SApple OSS Distributions enum SystemMapperState { 67*bbb1b6f9SApple OSS Distributions kNoMapper = 0, 68*bbb1b6f9SApple OSS Distributions kUnknown = 1, 69*bbb1b6f9SApple OSS Distributions kHasMapper = 2, // Any other value is pointer to a live mapper 70*bbb1b6f9SApple OSS Distributions kWaitMask = 3, 71*bbb1b6f9SApple OSS Distributions }; 72*bbb1b6f9SApple OSS Distributions protected: 73*bbb1b6f9SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE 74*bbb1b6f9SApple OSS Distributions uint64_t __reservedA[6]; 75*bbb1b6f9SApple OSS Distributions kern_allocation_name_t fAllocName; 76*bbb1b6f9SApple OSS Distributions uint32_t __reservedB; 77*bbb1b6f9SApple OSS Distributions uint32_t fPageSize; 78*bbb1b6f9SApple OSS Distributions #else 79*bbb1b6f9SApple OSS Distributions uint64_t __reserved[8]; 80*bbb1b6f9SApple OSS Distributions #endif 81*bbb1b6f9SApple OSS Distributions bool fIsSystem; 82*bbb1b6f9SApple OSS Distributions 83*bbb1b6f9SApple OSS Distributions static void setMapperRequired(bool hasMapper); 84*bbb1b6f9SApple OSS Distributions static void waitForSystemMapper(); 85*bbb1b6f9SApple OSS Distributions 86*bbb1b6f9SApple OSS Distributions virtual bool initHardware(IOService *provider) = 0; 87*bbb1b6f9SApple OSS Distributions 88*bbb1b6f9SApple OSS Distributions public: 89*bbb1b6f9SApple OSS Distributions virtual bool start(IOService *provider) APPLE_KEXT_OVERRIDE; 90*bbb1b6f9SApple OSS Distributions virtual void free() APPLE_KEXT_OVERRIDE; 91*bbb1b6f9SApple OSS Distributions 92*bbb1b6f9SApple OSS Distributions // To get access to the system mapper IOMapper::gSystem 93*bbb1b6f9SApple OSS Distributions static IOMapper *gSystem; 94*bbb1b6f9SApple OSS Distributions 95*bbb1b6f9SApple OSS Distributions static void checkForSystemMapper()96*bbb1b6f9SApple OSS Distributions checkForSystemMapper() 97*bbb1b6f9SApple OSS Distributions { 98*bbb1b6f9SApple OSS Distributions if ((uintptr_t) gSystem & kWaitMask) { 99*bbb1b6f9SApple OSS Distributions waitForSystemMapper(); 100*bbb1b6f9SApple OSS Distributions } 101*bbb1b6f9SApple OSS Distributions } 102*bbb1b6f9SApple OSS Distributions 103*bbb1b6f9SApple OSS Distributions static OSPtr<IOMapper> copyMapperForDevice(IOService * device); 104*bbb1b6f9SApple OSS Distributions static OSPtr<IOMapper> copyMapperForDeviceWithIndex(IOService * device, unsigned int index); 105*bbb1b6f9SApple OSS Distributions 106*bbb1b6f9SApple OSS Distributions // { subclasses 107*bbb1b6f9SApple OSS Distributions 108*bbb1b6f9SApple OSS Distributions virtual uint64_t getPageSize(void) const = 0; 109*bbb1b6f9SApple OSS Distributions 110*bbb1b6f9SApple OSS Distributions virtual IOReturn iovmMapMemory(IOMemoryDescriptor * memory, 111*bbb1b6f9SApple OSS Distributions uint64_t descriptorOffset, 112*bbb1b6f9SApple OSS Distributions uint64_t length, 113*bbb1b6f9SApple OSS Distributions uint32_t mapOptions, 114*bbb1b6f9SApple OSS Distributions const IODMAMapSpecification * mapSpecification, 115*bbb1b6f9SApple OSS Distributions IODMACommand * dmaCommand, 116*bbb1b6f9SApple OSS Distributions const IODMAMapPageList * pageList, 117*bbb1b6f9SApple OSS Distributions uint64_t * mapAddress, 118*bbb1b6f9SApple OSS Distributions uint64_t * mapLength) = 0; 119*bbb1b6f9SApple OSS Distributions 120*bbb1b6f9SApple OSS Distributions virtual IOReturn iovmUnmapMemory(IOMemoryDescriptor * memory, 121*bbb1b6f9SApple OSS Distributions IODMACommand * dmaCommand, 122*bbb1b6f9SApple OSS Distributions uint64_t mapAddress, 123*bbb1b6f9SApple OSS Distributions uint64_t mapLength) = 0; 124*bbb1b6f9SApple OSS Distributions 125*bbb1b6f9SApple OSS Distributions virtual IOReturn iovmInsert(uint32_t options, 126*bbb1b6f9SApple OSS Distributions uint64_t mapAddress, 127*bbb1b6f9SApple OSS Distributions uint64_t offset, 128*bbb1b6f9SApple OSS Distributions uint64_t physicalAddress, 129*bbb1b6f9SApple OSS Distributions uint64_t length) = 0; 130*bbb1b6f9SApple OSS Distributions 131*bbb1b6f9SApple OSS Distributions virtual uint64_t mapToPhysicalAddress(uint64_t mappedAddress) = 0; 132*bbb1b6f9SApple OSS Distributions 133*bbb1b6f9SApple OSS Distributions // } 134*bbb1b6f9SApple OSS Distributions 135*bbb1b6f9SApple OSS Distributions private: 136*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 0); 137*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 1); 138*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 2); 139*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 3); 140*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 4); 141*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 5); 142*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 6); 143*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 7); 144*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 8); 145*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 9); 146*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 10); 147*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 11); 148*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 12); 149*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 13); 150*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 14); 151*bbb1b6f9SApple OSS Distributions OSMetaClassDeclareReservedUnused(IOMapper, 15); 152*bbb1b6f9SApple OSS Distributions }; 153*bbb1b6f9SApple OSS Distributions 154*bbb1b6f9SApple OSS Distributions #endif /* __cplusplus */ 155*bbb1b6f9SApple OSS Distributions 156*bbb1b6f9SApple OSS Distributions #endif /* !__IOKIT_IOMAPPER_H */ 157