]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOKitKernelInternal.h
37e6f9416936de06a4357291e08461ca3b88adb7
[apple/xnu.git] / iokit / Kernel / IOKitKernelInternal.h
1 /*
2 * Copyright (c) 1998-2000 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
30 #ifndef _IOKIT_KERNELINTERNAL_H
31 #define _IOKIT_KERNELINTERNAL_H
32
33 #include <sys/cdefs.h>
34
35 __BEGIN_DECLS
36
37 #include <vm/vm_pageout.h>
38 #include <mach/memory_object_types.h>
39 #include <device/device_port.h>
40 #include <IOKit/IODMACommand.h>
41
42 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43
44 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
45
46 #define IOServiceTrace(csc, a, b, c, d) do { \
47 if(kIOTraceIOService & gIOKitDebug) { \
48 KERNEL_DEBUG_CONSTANT(IODBG_IOSERVICE(csc), a, b, c, d, 0); \
49 } \
50 } while(0)
51
52 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
53
54 #define IOServiceTrace(csc, a, b, c, d) do { \
55 (void)a; \
56 (void)b; \
57 (void)c; \
58 (void)d; \
59 } while (0)
60
61 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
62
63 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
64
65 typedef kern_return_t (*IOIteratePageableMapsCallback)(vm_map_t map, void * ref);
66
67 void IOLibInit(void);
68 kern_return_t IOIteratePageableMaps(vm_size_t size,
69 IOIteratePageableMapsCallback callback, void * ref);
70 vm_map_t IOPageableMapForAddress(uintptr_t address);
71
72 struct IOMemoryDescriptorMapAllocRef
73 {
74 vm_map_t map;
75 mach_vm_address_t mapped;
76 mach_vm_size_t size;
77 vm_prot_t prot;
78 vm_tag_t tag;
79 IOOptionBits options;
80 };
81
82 kern_return_t
83 IOMemoryDescriptorMapAlloc(vm_map_t map, void * ref);
84
85
86 mach_vm_address_t
87 IOKernelAllocateWithPhysicalRestrict(mach_vm_size_t size, mach_vm_address_t maxPhys,
88 mach_vm_size_t alignment, bool contiguous);
89 void
90 IOKernelFreePhysical(mach_vm_address_t address, mach_vm_size_t size);
91
92 extern vm_size_t debug_iomallocpageable_size;
93
94 // osfmk/device/iokit_rpc.c
95 extern kern_return_t IOMapPages(vm_map_t map, mach_vm_address_t va, mach_vm_address_t pa,
96 mach_vm_size_t length, unsigned int mapFlags);
97 extern kern_return_t IOUnmapPages(vm_map_t map, mach_vm_address_t va, mach_vm_size_t length);
98
99 extern kern_return_t IOProtectCacheMode(vm_map_t map, mach_vm_address_t va,
100 mach_vm_size_t length, unsigned int mapFlags);
101
102 extern ppnum_t IOGetLastPageNumber(void);
103
104 extern ppnum_t gIOLastPage;
105
106 extern IOSimpleLock * gIOPageAllocLock;
107 extern queue_head_t gIOPageAllocList;
108
109 /* Physical to physical copy (ints must be disabled) */
110 extern void bcopy_phys(addr64_t from, addr64_t to, vm_size_t size);
111
112 __END_DECLS
113
114 #define __IODEQUALIFY(type, expr) \
115 ({ typeof(expr) expr_ = (type)(uintptr_t)(expr); \
116 (type)(uintptr_t)(expr_); })
117
118
119 struct IODMACommandInternal
120 {
121 IOMDDMAWalkSegmentState fState;
122 IOMDDMACharacteristics fMDSummary;
123
124 UInt64 fPreparedOffset;
125 UInt64 fPreparedLength;
126
127 UInt32 fSourceAlignMask;
128
129 UInt8 fCursor;
130 UInt8 fCheckAddressing;
131 UInt8 fIterateOnly;
132 UInt8 fMisaligned;
133 UInt8 fMapContig;
134 UInt8 fPrepared;
135 UInt8 fDoubleBuffer;
136 UInt8 fNewMD;
137 UInt8 fLocalMapper;
138
139 vm_page_t fCopyPageAlloc;
140 vm_page_t fCopyNext;
141 vm_page_t fNextRemapPage;
142
143 ppnum_t fCopyPageCount;
144
145 uint64_t fLocalMapperAlloc;
146 uint64_t fLocalMapperAllocLength;
147
148 class IOBufferMemoryDescriptor * fCopyMD;
149
150 IOService * fDevice;
151
152 // IODMAEventSource use
153 IOReturn fStatus;
154 UInt64 fActualByteCount;
155 AbsoluteTime fTimeStamp;
156 };
157
158 struct IOMemoryDescriptorDevicePager {
159 void * devicePager;
160 unsigned int pagerContig:1;
161 unsigned int unused:31;
162 IOMemoryDescriptor * memory;
163 };
164
165 struct IOMemoryDescriptorReserved {
166 IOMemoryDescriptorDevicePager dp;
167 uint64_t preparationID;
168 // for kernel IOMD subclasses... they have no expansion
169 uint64_t kernReserved[4];
170 };
171
172 struct iopa_t
173 {
174 IOLock * lock;
175 queue_head_t list;
176 vm_size_t pagecount;
177 vm_size_t bytecount;
178 };
179
180 struct iopa_page_t
181 {
182 queue_chain_t link;
183 uint64_t avail;
184 uint32_t signature;
185 };
186 typedef struct iopa_page_t iopa_page_t;
187
188 typedef uintptr_t (*iopa_proc_t)(iopa_t * a);
189
190 enum
191 {
192 kIOPageAllocSignature = 'iopa'
193 };
194
195 extern "C" void iopa_init(iopa_t * a);
196 extern "C" uintptr_t iopa_alloc(iopa_t * a, iopa_proc_t alloc, vm_size_t bytes, uint32_t balign);
197 extern "C" uintptr_t iopa_free(iopa_t * a, uintptr_t addr, vm_size_t bytes);
198 extern "C" uint32_t gIOPageAllocChunkBytes;
199
200 extern "C" iopa_t gIOBMDPageAllocator;
201
202 extern "C" struct timeval gIOLastSleepTime;
203 extern "C" struct timeval gIOLastWakeTime;
204
205 extern clock_sec_t gIOConsoleLockTime;
206
207 extern OSSet * gIORemoveOnReadProperties;
208
209 extern "C" void IOKitInitializeTime( void );
210
211 extern "C" OSString * IOCopyLogNameForPID(int pid);
212
213 #if defined(__i386__) || defined(__x86_64__)
214 #ifndef __cplusplus
215 #error xx
216 #endif
217
218 extern const OSSymbol * gIOCreateEFIDevicePathSymbol;
219 extern "C" void IOSetKeyStoreData(IOMemoryDescriptor * data);
220 #endif
221 extern const OSSymbol * gAKSGetKey;
222
223 void IOScreenLockTimeUpdate(clock_sec_t secs);
224
225 void IOCPUInitialize(void);
226 IOReturn IOInstallServicePlatformActions(IOService * service);
227 IOReturn IORemoveServicePlatformActions(IOService * service);
228
229 #endif /* ! _IOKIT_KERNELINTERNAL_H */