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