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