1*1031c584SApple OSS Distributions /* 2*1031c584SApple OSS Distributions * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. 3*1031c584SApple OSS Distributions * 4*1031c584SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*1031c584SApple OSS Distributions * 6*1031c584SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*1031c584SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*1031c584SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*1031c584SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*1031c584SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*1031c584SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*1031c584SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*1031c584SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*1031c584SApple OSS Distributions * 15*1031c584SApple OSS Distributions * Please obtain a copy of the License at 16*1031c584SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*1031c584SApple OSS Distributions * 18*1031c584SApple OSS Distributions * The Original Code and all software distributed under the License are 19*1031c584SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*1031c584SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*1031c584SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*1031c584SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*1031c584SApple OSS Distributions * Please see the License for the specific language governing rights and 24*1031c584SApple OSS Distributions * limitations under the License. 25*1031c584SApple OSS Distributions * 26*1031c584SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*1031c584SApple OSS Distributions */ 28*1031c584SApple OSS Distributions 29*1031c584SApple OSS Distributions 30*1031c584SApple OSS Distributions #ifndef _IOKIT_KERNELINTERNAL_H 31*1031c584SApple OSS Distributions #define _IOKIT_KERNELINTERNAL_H 32*1031c584SApple OSS Distributions 33*1031c584SApple OSS Distributions #include <sys/cdefs.h> 34*1031c584SApple OSS Distributions 35*1031c584SApple OSS Distributions __BEGIN_DECLS 36*1031c584SApple OSS Distributions 37*1031c584SApple OSS Distributions #include <vm/vm_pageout.h> 38*1031c584SApple OSS Distributions #include <mach/memory_object_types.h> 39*1031c584SApple OSS Distributions #include <device/device_port.h> 40*1031c584SApple OSS Distributions #include <IOKit/IODMACommand.h> 41*1031c584SApple OSS Distributions #include <IOKit/IOKitServer.h> 42*1031c584SApple OSS Distributions #include <kern/socd_client.h> 43*1031c584SApple OSS Distributions 44*1031c584SApple OSS Distributions /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 45*1031c584SApple OSS Distributions 46*1031c584SApple OSS Distributions typedef kern_return_t (*IOIteratePageableMapsCallback)(vm_map_t map, void * ref); 47*1031c584SApple OSS Distributions 48*1031c584SApple OSS Distributions void IOLibInit(void); 49*1031c584SApple OSS Distributions kern_return_t IOIteratePageableMaps(vm_size_t size, 50*1031c584SApple OSS Distributions IOIteratePageableMapsCallback callback, void * ref); 51*1031c584SApple OSS Distributions vm_map_t IOPageableMapForAddress(uintptr_t address); 52*1031c584SApple OSS Distributions 53*1031c584SApple OSS Distributions struct IOMemoryDescriptorMapAllocRef { 54*1031c584SApple OSS Distributions vm_map_t map; 55*1031c584SApple OSS Distributions mach_vm_address_t mapped; 56*1031c584SApple OSS Distributions mach_vm_size_t size; 57*1031c584SApple OSS Distributions vm_prot_t prot; 58*1031c584SApple OSS Distributions vm_tag_t tag; 59*1031c584SApple OSS Distributions IOOptionBits options; 60*1031c584SApple OSS Distributions }; 61*1031c584SApple OSS Distributions 62*1031c584SApple OSS Distributions kern_return_t 63*1031c584SApple OSS Distributions IOMemoryDescriptorMapAlloc(vm_map_t map, void * ref); 64*1031c584SApple OSS Distributions 65*1031c584SApple OSS Distributions 66*1031c584SApple OSS Distributions mach_vm_address_t 67*1031c584SApple OSS Distributions IOKernelAllocateWithPhysicalRestrict( 68*1031c584SApple OSS Distributions kalloc_heap_t kheap, 69*1031c584SApple OSS Distributions mach_vm_size_t size, 70*1031c584SApple OSS Distributions mach_vm_address_t maxPhys, 71*1031c584SApple OSS Distributions mach_vm_size_t alignment, 72*1031c584SApple OSS Distributions bool contiguous); 73*1031c584SApple OSS Distributions void 74*1031c584SApple OSS Distributions IOKernelFreePhysical( 75*1031c584SApple OSS Distributions kalloc_heap_t kheap, 76*1031c584SApple OSS Distributions mach_vm_address_t address, 77*1031c584SApple OSS Distributions mach_vm_size_t size); 78*1031c584SApple OSS Distributions 79*1031c584SApple OSS Distributions #if IOTRACKING 80*1031c584SApple OSS Distributions IOReturn 81*1031c584SApple OSS Distributions IOMemoryMapTracking(IOTrackingUser * tracking, task_t * task, 82*1031c584SApple OSS Distributions mach_vm_address_t * address, mach_vm_size_t * size); 83*1031c584SApple OSS Distributions #endif /* IOTRACKING */ 84*1031c584SApple OSS Distributions 85*1031c584SApple OSS Distributions extern vm_size_t debug_iomallocpageable_size; 86*1031c584SApple OSS Distributions 87*1031c584SApple OSS Distributions extern ppnum_t gIOLastPage; 88*1031c584SApple OSS Distributions 89*1031c584SApple OSS Distributions extern IOSimpleLock * gIOPageAllocLock; 90*1031c584SApple OSS Distributions extern queue_head_t gIOPageAllocList; 91*1031c584SApple OSS Distributions 92*1031c584SApple OSS Distributions /* Physical to physical copy (ints must be disabled) */ 93*1031c584SApple OSS Distributions extern void bcopy_phys(addr64_t from, addr64_t to, vm_size_t size); 94*1031c584SApple OSS Distributions 95*1031c584SApple OSS Distributions __END_DECLS 96*1031c584SApple OSS Distributions 97*1031c584SApple OSS Distributions #define __IODEQUALIFY(type, expr) \ 98*1031c584SApple OSS Distributions ({ typeof(expr) expr_ = (type)(uintptr_t)(expr); \ 99*1031c584SApple OSS Distributions (type)(uintptr_t)(expr_); }) 100*1031c584SApple OSS Distributions 101*1031c584SApple OSS Distributions struct IODMACommandMapSegment { 102*1031c584SApple OSS Distributions uint64_t fDMAOffset; // The offset of this segment in DMA 103*1031c584SApple OSS Distributions uint64_t fMapOffset; // Offset of segment in mapping 104*1031c584SApple OSS Distributions uint64_t fPageOffset; // Offset within first page of segment 105*1031c584SApple OSS Distributions }; 106*1031c584SApple OSS Distributions 107*1031c584SApple OSS Distributions struct IODMACommandInternal { 108*1031c584SApple OSS Distributions IOMDDMAWalkSegmentState fState; 109*1031c584SApple OSS Distributions IOMDDMACharacteristics fMDSummary; 110*1031c584SApple OSS Distributions 111*1031c584SApple OSS Distributions UInt64 fPreparedOffset; 112*1031c584SApple OSS Distributions UInt64 fPreparedLength; 113*1031c584SApple OSS Distributions 114*1031c584SApple OSS Distributions UInt32 fSourceAlignMask; 115*1031c584SApple OSS Distributions 116*1031c584SApple OSS Distributions UInt8 fCursor; 117*1031c584SApple OSS Distributions UInt8 fCheckAddressing; 118*1031c584SApple OSS Distributions UInt8 fIterateOnly; 119*1031c584SApple OSS Distributions UInt8 fMisaligned; 120*1031c584SApple OSS Distributions UInt8 fPrepared; 121*1031c584SApple OSS Distributions UInt8 fDoubleBuffer; 122*1031c584SApple OSS Distributions UInt8 fNewMD; 123*1031c584SApple OSS Distributions UInt8 fLocalMapperAllocValid; 124*1031c584SApple OSS Distributions UInt8 fIOVMAddrValid; 125*1031c584SApple OSS Distributions UInt8 fForceDoubleBuffer; 126*1031c584SApple OSS Distributions UInt8 fSetActiveNoMapper; 127*1031c584SApple OSS Distributions 128*1031c584SApple OSS Distributions vm_page_t fCopyPageAlloc; 129*1031c584SApple OSS Distributions vm_page_t fCopyNext; 130*1031c584SApple OSS Distributions vm_page_t fNextRemapPage; 131*1031c584SApple OSS Distributions 132*1031c584SApple OSS Distributions ppnum_t fCopyPageCount; 133*1031c584SApple OSS Distributions 134*1031c584SApple OSS Distributions uint64_t fLocalMapperAlloc; 135*1031c584SApple OSS Distributions uint64_t fLocalMapperAllocLength; 136*1031c584SApple OSS Distributions 137*1031c584SApple OSS Distributions OSPtr<IOBufferMemoryDescriptor> fCopyMD; 138*1031c584SApple OSS Distributions 139*1031c584SApple OSS Distributions IOService * fDevice; 140*1031c584SApple OSS Distributions IOLock * fDextLock; 141*1031c584SApple OSS Distributions 142*1031c584SApple OSS Distributions // IODMAEventSource use 143*1031c584SApple OSS Distributions IOReturn fStatus; 144*1031c584SApple OSS Distributions UInt64 fActualByteCount; 145*1031c584SApple OSS Distributions AbsoluteTime fTimeStamp; 146*1031c584SApple OSS Distributions 147*1031c584SApple OSS Distributions // Multisegment vars 148*1031c584SApple OSS Distributions IODMACommandMapSegment * fMapSegments; 149*1031c584SApple OSS Distributions uint32_t fMapSegmentsCount; 150*1031c584SApple OSS Distributions uint64_t fLocalMapperAllocBase; 151*1031c584SApple OSS Distributions uint64_t fOffset2Index; 152*1031c584SApple OSS Distributions uint64_t fNextOffset; 153*1031c584SApple OSS Distributions uint64_t fIndex; 154*1031c584SApple OSS Distributions }; 155*1031c584SApple OSS Distributions 156*1031c584SApple OSS Distributions struct IOMemoryDescriptorDevicePager { 157*1031c584SApple OSS Distributions void * devicePager; 158*1031c584SApple OSS Distributions unsigned int pagerContig:1; 159*1031c584SApple OSS Distributions unsigned int unused:31; 160*1031c584SApple OSS Distributions IOMemoryDescriptor * memory; 161*1031c584SApple OSS Distributions }; 162*1031c584SApple OSS Distributions 163*1031c584SApple OSS Distributions struct IOMemoryDescriptorReserved { 164*1031c584SApple OSS Distributions IOMemoryDescriptorDevicePager dp; 165*1031c584SApple OSS Distributions uint64_t descriptorID; 166*1031c584SApple OSS Distributions uint64_t preparationID; 167*1031c584SApple OSS Distributions // for kernel IOMD subclasses... they have no expansion 168*1031c584SApple OSS Distributions uint64_t kernReserved[4]; 169*1031c584SApple OSS Distributions vm_tag_t kernelTag; 170*1031c584SApple OSS Distributions vm_tag_t userTag; 171*1031c584SApple OSS Distributions task_t creator; 172*1031c584SApple OSS Distributions OSObject * contextObject; 173*1031c584SApple OSS Distributions }; 174*1031c584SApple OSS Distributions 175*1031c584SApple OSS Distributions #if defined(__x86_64__) 176*1031c584SApple OSS Distributions struct iopa_t { 177*1031c584SApple OSS Distributions IOLock * lock; 178*1031c584SApple OSS Distributions queue_head_t list; 179*1031c584SApple OSS Distributions vm_size_t pagecount; 180*1031c584SApple OSS Distributions vm_size_t bytecount; 181*1031c584SApple OSS Distributions }; 182*1031c584SApple OSS Distributions 183*1031c584SApple OSS Distributions struct iopa_page_t { 184*1031c584SApple OSS Distributions queue_chain_t link; 185*1031c584SApple OSS Distributions uint64_t avail; 186*1031c584SApple OSS Distributions uint32_t signature; 187*1031c584SApple OSS Distributions }; 188*1031c584SApple OSS Distributions typedef struct iopa_page_t iopa_page_t; 189*1031c584SApple OSS Distributions 190*1031c584SApple OSS Distributions typedef uintptr_t (*iopa_proc_t)(kalloc_heap_t kheap, iopa_t * a); 191*1031c584SApple OSS Distributions 192*1031c584SApple OSS Distributions enum{ 193*1031c584SApple OSS Distributions kIOPageAllocSignature = 'iopa' 194*1031c584SApple OSS Distributions }; 195*1031c584SApple OSS Distributions 196*1031c584SApple OSS Distributions extern "C" void iopa_init(iopa_t * a); 197*1031c584SApple OSS Distributions extern "C" uintptr_t iopa_alloc(iopa_t * a, iopa_proc_t alloc, kalloc_heap_t kheap, 198*1031c584SApple OSS Distributions vm_size_t bytes, vm_size_t balign); 199*1031c584SApple OSS Distributions extern "C" uintptr_t iopa_free(iopa_t * a, uintptr_t addr, vm_size_t bytes); 200*1031c584SApple OSS Distributions extern "C" uint32_t gIOPageAllocChunkBytes; 201*1031c584SApple OSS Distributions 202*1031c584SApple OSS Distributions extern "C" iopa_t gIOBMDPageAllocator; 203*1031c584SApple OSS Distributions #endif /* defined(__x86_64__) */ 204*1031c584SApple OSS Distributions 205*1031c584SApple OSS Distributions 206*1031c584SApple OSS Distributions extern "C" struct timeval gIOLastSleepTime; 207*1031c584SApple OSS Distributions extern "C" struct timeval gIOLastWakeTime; 208*1031c584SApple OSS Distributions 209*1031c584SApple OSS Distributions extern clock_sec_t gIOConsoleLockTime; 210*1031c584SApple OSS Distributions 211*1031c584SApple OSS Distributions extern bool gCPUsRunning; 212*1031c584SApple OSS Distributions 213*1031c584SApple OSS Distributions extern OSSet * gIORemoveOnReadProperties; 214*1031c584SApple OSS Distributions 215*1031c584SApple OSS Distributions extern uint32_t gHaltTimeMaxLog; 216*1031c584SApple OSS Distributions extern uint32_t gHaltTimeMaxPanic; 217*1031c584SApple OSS Distributions 218*1031c584SApple OSS Distributions extern "C" void IOKitInitializeTime( void ); 219*1031c584SApple OSS Distributions extern void IOMachPortInitialize(void); 220*1031c584SApple OSS Distributions 221*1031c584SApple OSS Distributions extern "C" OSString * IOCopyLogNameForPID(int pid); 222*1031c584SApple OSS Distributions 223*1031c584SApple OSS Distributions extern "C" void IOKitKernelLogBuffer(const char * title, const void * buffer, size_t size, 224*1031c584SApple OSS Distributions void (*output)(const char *format, ...)); 225*1031c584SApple OSS Distributions 226*1031c584SApple OSS Distributions #if defined(__i386__) || defined(__x86_64__) 227*1031c584SApple OSS Distributions #ifndef __cplusplus 228*1031c584SApple OSS Distributions #error xx 229*1031c584SApple OSS Distributions #endif 230*1031c584SApple OSS Distributions 231*1031c584SApple OSS Distributions extern const OSSymbol * gIOCreateEFIDevicePathSymbol; 232*1031c584SApple OSS Distributions extern "C" void IOSetKeyStoreData(LIBKERN_CONSUMED IOMemoryDescriptor * data); 233*1031c584SApple OSS Distributions extern "C" void IOSetAPFSKeyStoreData(LIBKERN_CONSUMED IOMemoryDescriptor* data); 234*1031c584SApple OSS Distributions #endif 235*1031c584SApple OSS Distributions extern const OSSymbol * gAKSGetKey; 236*1031c584SApple OSS Distributions 237*1031c584SApple OSS Distributions void IOScreenLockTimeUpdate(clock_sec_t secs); 238*1031c584SApple OSS Distributions 239*1031c584SApple OSS Distributions void IOCPUInitialize(void); 240*1031c584SApple OSS Distributions IOReturn IOInstallServicePlatformActions(IOService * service); 241*1031c584SApple OSS Distributions IOReturn IOInstallServiceSleepPlatformActions(IOService * service); 242*1031c584SApple OSS Distributions IOReturn IORemoveServicePlatformActions(IOService * service); 243*1031c584SApple OSS Distributions void IOCPUSleepKernel(void); 244*1031c584SApple OSS Distributions void IOPlatformActionsInitialize(void); 245*1031c584SApple OSS Distributions 246*1031c584SApple OSS Distributions class IOSystemStateNotification : public IOService 247*1031c584SApple OSS Distributions { 248*1031c584SApple OSS Distributions OSDeclareDefaultStructors(IOSystemStateNotification); 249*1031c584SApple OSS Distributions public: 250*1031c584SApple OSS Distributions static IOService * initialize(void); 251*1031c584SApple OSS Distributions virtual IOReturn setProperties( OSObject * properties) APPLE_KEXT_OVERRIDE; 252*1031c584SApple OSS Distributions virtual bool serializeProperties(OSSerialize * serialize) const APPLE_KEXT_OVERRIDE; 253*1031c584SApple OSS Distributions }; 254*1031c584SApple OSS Distributions 255*1031c584SApple OSS Distributions #endif /* ! _IOKIT_KERNELINTERNAL_H */ 256