]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOMapper.h
f59b9b0533a80ae1a811254f93533ccba2bfc6a8
[apple/xnu.git] / iokit / IOKit / IOMapper.h
1 /*
2 * Copyright (c) 1998-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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
39 ppnum_t IOMapperIOVMAlloc(unsigned pages);
40 void IOMapperIOVMFree(ppnum_t addr, unsigned pages);
41
42 ppnum_t IOMapperInsertPage(ppnum_t addr, unsigned offset, ppnum_t page);
43 void IOMapperInsertPPNPages(ppnum_t addr, unsigned offset,
44 ppnum_t *pageList, unsigned pageCount);
45 void IOMapperInsertUPLPages(ppnum_t addr, unsigned offset,
46 upl_page_info_t *pageList, unsigned pageCount);
47 __END_DECLS
48
49 #if __cplusplus
50
51 #include <IOKit/IOService.h>
52 #include <IOKit/IOMemoryDescriptor.h>
53
54 class OSData;
55
56 class IOMapper : public IOService
57 {
58 OSDeclareAbstractStructors(IOMapper);
59
60 // Give the platform expert access to setMapperRequired();
61 friend class IOPlatformExpert;
62
63 private:
64 enum SystemMapperState {
65 kNoMapper = 0,
66 kUnknown = 1,
67 kHasMapper = 2, // Any other value is pointer to a live mapper
68 kWaitMask = 3,
69 };
70 protected:
71 void *fTable;
72 ppnum_t fTablePhys;
73 IOItemCount fTableSize;
74 OSData *fTableHandle;
75 bool fIsSystem;
76
77 virtual bool start(IOService *provider);
78 virtual void free();
79
80 static void setMapperRequired(bool hasMapper);
81 static void waitForSystemMapper();
82
83 virtual bool initHardware(IOService *provider) = 0;
84
85 virtual bool allocTable(IOByteCount size);
86
87 public:
88 // Static routines capable of allocating tables that are physically
89 // contiguous in real memory space.
90 static OSData * NewARTTable(IOByteCount size,
91 void ** virtAddrP, ppnum_t *physAddrP);
92 static void FreeARTTable(OSData *handle, IOByteCount size);
93
94
95 // To get access to the system mapper IOMapper::gSystem
96 static IOMapper *gSystem;
97
98 virtual ppnum_t iovmAlloc(IOItemCount pages) = 0;
99 virtual void iovmFree(ppnum_t addr, IOItemCount pages) = 0;
100
101 virtual void iovmInsert(ppnum_t addr, IOItemCount offset, ppnum_t page) = 0;
102 virtual void iovmInsert(ppnum_t addr, IOItemCount offset,
103 ppnum_t *pageList, IOItemCount pageCount);
104 virtual void iovmInsert(ppnum_t addr, IOItemCount offset,
105 upl_page_info_t *pageList, IOItemCount pageCount);
106 static void checkForSystemMapper()
107 { if ((vm_address_t) gSystem & kWaitMask) waitForSystemMapper(); };
108
109 // Function will panic if the given address is not found in a valid
110 // iovm mapping.
111 virtual addr64_t mapAddr(IOPhysicalAddress addr) = 0;
112
113 private:
114 OSMetaClassDeclareReservedUnused(IOMapper, 0);
115 OSMetaClassDeclareReservedUnused(IOMapper, 1);
116 OSMetaClassDeclareReservedUnused(IOMapper, 2);
117 OSMetaClassDeclareReservedUnused(IOMapper, 3);
118 OSMetaClassDeclareReservedUnused(IOMapper, 4);
119 OSMetaClassDeclareReservedUnused(IOMapper, 5);
120 OSMetaClassDeclareReservedUnused(IOMapper, 6);
121 OSMetaClassDeclareReservedUnused(IOMapper, 7);
122 OSMetaClassDeclareReservedUnused(IOMapper, 8);
123 OSMetaClassDeclareReservedUnused(IOMapper, 9);
124 OSMetaClassDeclareReservedUnused(IOMapper, 10);
125 OSMetaClassDeclareReservedUnused(IOMapper, 11);
126 OSMetaClassDeclareReservedUnused(IOMapper, 12);
127 OSMetaClassDeclareReservedUnused(IOMapper, 13);
128 OSMetaClassDeclareReservedUnused(IOMapper, 14);
129 OSMetaClassDeclareReservedUnused(IOMapper, 15);
130 };
131
132 #endif /* __cplusplus */
133
134 #endif /* !__IOKIT_IOMAPPER_H */