xref: /xnu-8020.121.3/iokit/Kernel/IOKitKernelInternal.h (revision fdd8201d7b966f0c3ea610489d29bd841d358941)
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 #include <IOKit/IOKitServer.h>
42 #include <kern/socd_client.h>
43 
44 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
45 
46 typedef kern_return_t (*IOIteratePageableMapsCallback)(vm_map_t map, void * ref);
47 
48 void IOLibInit(void);
49 kern_return_t IOIteratePageableMaps(vm_size_t size,
50     IOIteratePageableMapsCallback callback, void * ref);
51 vm_map_t IOPageableMapForAddress(uintptr_t address);
52 
53 struct IOMemoryDescriptorMapAllocRef {
54 	vm_map_t          map;
55 	mach_vm_address_t mapped;
56 	mach_vm_size_t    size;
57 	vm_prot_t         prot;
58 	vm_tag_t          tag;
59 	IOOptionBits      options;
60 };
61 
62 kern_return_t
63 IOMemoryDescriptorMapAlloc(vm_map_t map, void * ref);
64 
65 
66 mach_vm_address_t
67 IOKernelAllocateWithPhysicalRestrict(
68 	kalloc_heap_t       kheap,
69 	mach_vm_size_t      size,
70 	mach_vm_address_t   maxPhys,
71 	mach_vm_size_t      alignment,
72 	bool                contiguous);
73 void
74 IOKernelFreePhysical(
75 	kalloc_heap_t       kheap,
76 	mach_vm_address_t   address,
77 	mach_vm_size_t      size);
78 
79 #if IOTRACKING
80 IOReturn
81 IOMemoryMapTracking(IOTrackingUser * tracking, task_t * task,
82     mach_vm_address_t * address, mach_vm_size_t * size);
83 #endif /* IOTRACKING */
84 
85 extern vm_size_t debug_iomallocpageable_size;
86 
87 extern ppnum_t gIOLastPage;
88 
89 extern IOSimpleLock * gIOPageAllocLock;
90 extern queue_head_t   gIOPageAllocList;
91 
92 /* Physical to physical copy (ints must be disabled) */
93 extern void bcopy_phys(addr64_t from, addr64_t to, vm_size_t size);
94 
95 __END_DECLS
96 
97 #define __IODEQUALIFY(type, expr)                               \
98    ({ typeof(expr) expr_ = (type)(uintptr_t)(expr);             \
99        (type)(uintptr_t)(expr_); })
100 
101 struct IODMACommandMapSegment {
102 	uint64_t fDMAOffset;       // The offset of this segment in DMA
103 	uint64_t fMapOffset;       // Offset of segment in mapping
104 	uint64_t fPageOffset;      // Offset within first page of segment
105 };
106 
107 struct IODMACommandInternal {
108 	IOMDDMAWalkSegmentState      fState;
109 	IOMDDMACharacteristics       fMDSummary;
110 
111 	UInt64 fPreparedOffset;
112 	UInt64 fPreparedLength;
113 
114 	UInt32 fSourceAlignMask;
115 
116 	UInt8  fCursor;
117 	UInt8  fCheckAddressing;
118 	UInt8  fIterateOnly;
119 	UInt8  fMisaligned;
120 	UInt8  fPrepared;
121 	UInt8  fDoubleBuffer;
122 	UInt8  fNewMD;
123 	UInt8  fLocalMapperAllocValid;
124 	UInt8  fIOVMAddrValid;
125 	UInt8  fForceDoubleBuffer;
126 	UInt8  fSetActiveNoMapper;
127 
128 	vm_page_t fCopyPageAlloc;
129 	vm_page_t fCopyNext;
130 	vm_page_t fNextRemapPage;
131 
132 	ppnum_t  fCopyPageCount;
133 
134 	uint64_t  fLocalMapperAlloc;
135 	uint64_t  fLocalMapperAllocLength;
136 
137 	OSPtr<IOBufferMemoryDescriptor> fCopyMD;
138 
139 	IOService * fDevice;
140 
141 	// IODMAEventSource use
142 	IOReturn fStatus;
143 	UInt64   fActualByteCount;
144 	AbsoluteTime    fTimeStamp;
145 
146 	// Multisegment vars
147 	IODMACommandMapSegment * fMapSegments;
148 	uint32_t                 fMapSegmentsCount;
149 	uint64_t fLocalMapperAllocBase;
150 	uint64_t fOffset2Index;
151 	uint64_t fNextOffset;
152 	uint64_t fIndex;
153 };
154 
155 struct IOMemoryDescriptorDevicePager {
156 	void *                       devicePager;
157 	unsigned int             pagerContig:1;
158 	unsigned int             unused:31;
159 	IOMemoryDescriptor * memory;
160 };
161 
162 struct IOMemoryDescriptorReserved {
163 	IOMemoryDescriptorDevicePager dp;
164 	uint64_t                      descriptorID;
165 	uint64_t                      preparationID;
166 	// for kernel IOMD subclasses... they have no expansion
167 	uint64_t                      kernReserved[4];
168 	vm_tag_t                      kernelTag;
169 	vm_tag_t                      userTag;
170 	task_t                        creator;
171 	OSObject                    * contextObject;
172 };
173 
174 #if defined(__x86_64__)
175 struct iopa_t {
176 	IOLock       * lock;
177 	queue_head_t   list;
178 	vm_size_t      pagecount;
179 	vm_size_t      bytecount;
180 };
181 
182 struct iopa_page_t {
183 	queue_chain_t link;
184 	uint64_t      avail;
185 	uint32_t      signature;
186 };
187 typedef struct iopa_page_t iopa_page_t;
188 
189 typedef uintptr_t (*iopa_proc_t)(kalloc_heap_t kheap, iopa_t * a);
190 
191 enum{
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, kalloc_heap_t kheap,
197     vm_size_t bytes, vm_size_t balign);
198 extern "C" uintptr_t iopa_free(iopa_t * a, uintptr_t addr, vm_size_t bytes);
199 extern "C" uint32_t  gIOPageAllocChunkBytes;
200 
201 extern "C" iopa_t    gIOBMDPageAllocator;
202 #endif /* defined(__x86_64__) */
203 
204 
205 extern "C" struct timeval gIOLastSleepTime;
206 extern "C" struct timeval gIOLastWakeTime;
207 
208 extern clock_sec_t gIOConsoleLockTime;
209 
210 extern bool gCPUsRunning;
211 
212 extern OSSet * gIORemoveOnReadProperties;
213 
214 extern uint32_t gHaltTimeMaxLog;
215 extern uint32_t gHaltTimeMaxPanic;
216 
217 extern "C" void IOKitInitializeTime( void );
218 extern void IOMachPortInitialize(void);
219 
220 extern "C" OSString * IOCopyLogNameForPID(int pid);
221 
222 extern "C" void IOKitKernelLogBuffer(const char * title, const void * buffer, size_t size,
223     void (*output)(const char *format, ...));
224 
225 #if defined(__i386__) || defined(__x86_64__)
226 #ifndef __cplusplus
227 #error xx
228 #endif
229 
230 extern const OSSymbol * gIOCreateEFIDevicePathSymbol;
231 extern "C" void IOSetKeyStoreData(LIBKERN_CONSUMED IOMemoryDescriptor * data);
232 extern "C" void IOSetAPFSKeyStoreData(LIBKERN_CONSUMED IOMemoryDescriptor* data);
233 #endif
234 extern const  OSSymbol * gAKSGetKey;
235 
236 void IOScreenLockTimeUpdate(clock_sec_t secs);
237 
238 void     IOCPUInitialize(void);
239 IOReturn IOInstallServicePlatformActions(IOService * service);
240 IOReturn IOInstallServiceSleepPlatformActions(IOService * service);
241 IOReturn IORemoveServicePlatformActions(IOService * service);
242 void     IOCPUSleepKernel(void);
243 void     IOPlatformActionsInitialize(void);
244 
245 class IOSystemStateNotification : public IOService
246 {
247 	OSDeclareDefaultStructors(IOSystemStateNotification);
248 public:
249 	static IOService * initialize(void);
250 	virtual IOReturn setProperties( OSObject * properties) APPLE_KEXT_OVERRIDE;
251 	virtual bool serializeProperties(OSSerialize * serialize) const APPLE_KEXT_OVERRIDE;
252 };
253 
254 #endif /* ! _IOKIT_KERNELINTERNAL_H */
255