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