1 /* 2 * Copyright (c) 1998-2010 Apple 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 #include <libkern/c++/OSUnserialize.h> 30 #include <libkern/c++/OSKext.h> 31 #include <libkern/version.h> 32 #include <IOKit/IORegistryEntry.h> 33 #include <IOKit/IODeviceTreeSupport.h> 34 #include <IOKit/IOCatalogue.h> 35 #include <IOKit/IOUserClient.h> 36 #include <IOKit/IOMemoryDescriptor.h> 37 #include <IOKit/IOPlatformExpert.h> 38 #include <IOKit/IOLib.h> 39 #include <IOKit/IOKitKeys.h> 40 #include <IOKit/IOKitDebug.h> 41 #include <IOKit/pwr_mgt/RootDomain.h> 42 #include <IOKit/pwr_mgt/IOPMinformeeList.h> 43 #include <IOKit/IOStatisticsPrivate.h> 44 #include <IOKit/IOKitKeysPrivate.h> 45 #include <IOKit/IOInterruptAccountingPrivate.h> 46 47 #include <IOKit/assert.h> 48 49 #include "IOKitKernelInternal.h" 50 51 const OSSymbol * gIOProgressBackbufferKey; 52 OSSet * gIORemoveOnReadProperties; 53 54 extern "C" { 55 56 extern void OSlibkernInit (void); 57 58 void iokit_post_constructor_init(void); 59 60 #include <kern/clock.h> 61 #include <sys/time.h> 62 63 void IOKitInitializeTime( void ) 64 { 65 mach_timespec_t t; 66 67 t.tv_sec = 30; 68 t.tv_nsec = 0; 69 IOService::waitForService( 70 IOService::resourceMatching("IORTC"), &t ); 71 #if defined(__i386__) || defined(__x86_64__) 72 IOService::waitForService( 73 IOService::resourceMatching("IONVRAM"), &t ); 74 #endif 75 76 clock_initialize_calendar(); 77 } 78 79 void iokit_post_constructor_init(void) 80 { 81 IORegistryEntry * root; 82 OSObject * obj; 83 84 IOCPUInitialize(); 85 root = IORegistryEntry::initialize(); 86 assert( root ); 87 IOService::initialize(); 88 IOCatalogue::initialize(); 89 IOStatistics::initialize(); 90 OSKext::initialize(); 91 IOUserClient::initialize(); 92 IOMemoryDescriptor::initialize(); 93 IORootParent::initialize(); 94 95 // Initializes IOPMinformeeList class-wide shared lock 96 IOPMinformeeList::getSharedRecursiveLock(); 97 98 obj = OSString::withCString( version ); 99 assert( obj ); 100 if( obj ) { 101 root->setProperty( kIOKitBuildVersionKey, obj ); 102 obj->release(); 103 } 104 obj = IOKitDiagnostics::diagnostics(); 105 if( obj ) { 106 root->setProperty( kIOKitDiagnosticsKey, obj ); 107 obj->release(); 108 } 109 } 110 111 // From <osfmk/kern/debug.c> 112 extern int debug_mode; 113 114 /***** 115 * Pointer into bootstrap KLD segment for functions never used past startup. 116 */ 117 void (*record_startup_extensions_function)(void) = 0; 118 119 void StartIOKit( void * p1, void * p2, void * p3, void * p4 ) 120 { 121 IOPlatformExpertDevice * rootNub; 122 int debugFlags; 123 124 if( PE_parse_boot_argn( "io", &debugFlags, sizeof (debugFlags) )) 125 gIOKitDebug = debugFlags; 126 #if DEVELOPMENT || DEBUG 127 else gIOKitDebug |= kIOWaitQuietPanics; 128 #endif /* DEVELOPMENT || DEBUG */ 129 130 if( PE_parse_boot_argn( "iotrace", &debugFlags, sizeof (debugFlags) )) 131 gIOKitTrace = debugFlags; 132 133 // Compat for boot-args 134 gIOKitTrace |= (gIOKitDebug & kIOTraceCompatBootArgs); 135 136 // Check for the log synchronous bit set in io 137 if (gIOKitDebug & kIOLogSynchronous) 138 debug_mode = true; 139 140 if( PE_parse_boot_argn( "pmtimeout", &debugFlags, sizeof (debugFlags) )) 141 gCanSleepTimeout = debugFlags; 142 // 143 // Have to start IOKit environment before we attempt to start 144 // the C++ runtime environment. At some stage we have to clean up 145 // the initialisation path so that OS C++ can initialise independantly 146 // of iokit basic service initialisation, or better we have IOLib stuff 147 // initialise as basic OS services. 148 // 149 IOLibInit(); 150 OSlibkernInit(); 151 152 gIOProgressBackbufferKey = OSSymbol::withCStringNoCopy(kIOProgressBackbufferKey); 153 gIORemoveOnReadProperties = OSSet::withObjects((const OSObject **) &gIOProgressBackbufferKey, 1); 154 155 interruptAccountingInit(); 156 157 rootNub = new IOPlatformExpertDevice; 158 159 if( rootNub && rootNub->initWithArgs( p1, p2, p3, p4)) { 160 rootNub->attach( 0 ); 161 162 /* If the bootstrap segment set up a function to record startup 163 * extensions, call it now. 164 */ 165 if (record_startup_extensions_function) { 166 record_startup_extensions_function(); 167 } 168 169 rootNub->registerService(); 170 171 #if !NO_KEXTD 172 /* Add a busy count to keep the registry busy until kextd has 173 * completely finished launching. This is decremented when kextd 174 * messages the kernel after the in-kernel linker has been 175 * removed and personalities have been sent. 176 */ 177 IOService::getServiceRoot()->adjustBusy(1); 178 #endif 179 } 180 } 181 182 void 183 IORegistrySetOSBuildVersion(char * build_version) 184 { 185 IORegistryEntry * root = IORegistryEntry::getRegistryRoot(); 186 187 if (root) { 188 if (build_version) { 189 root->setProperty(kOSBuildVersionKey, build_version); 190 } else { 191 root->removeProperty(kOSBuildVersionKey); 192 } 193 } 194 195 return; 196 } 197 198 void 199 IORecordProgressBackbuffer(void * buffer, size_t size, uint32_t theme) 200 { 201 IORegistryEntry * chosen; 202 if ((chosen = IORegistryEntry::fromPath(kIODeviceTreePlane ":/chosen"))) 203 { 204 chosen->setProperty(kIOProgressBackbufferKey, buffer, size); 205 chosen->setProperty(kIOProgressColorThemeKey, theme, 32); 206 207 chosen->release(); 208 } 209 } 210 211 }; /* extern "C" */ 212