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