]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOStartIOKit.cpp
xnu-1228.9.59.tar.gz
[apple/xnu.git] / iokit / Kernel / IOStartIOKit.cpp
1 /*
2 * Copyright (c) 1998-2006 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 * Copyright (c) 1998,1999 Apple Computer, Inc. All rights reserved.
30 *
31 * HISTORY
32 *
33 */
34
35 #include <libkern/c++/OSUnserialize.h>
36 #include <libkern/version.h>
37 #include <IOKit/IORegistryEntry.h>
38 #include <IOKit/IODeviceTreeSupport.h>
39 #include <IOKit/IOCatalogue.h>
40 #include <IOKit/IOUserClient.h>
41 #include <IOKit/IOMemoryDescriptor.h>
42 #include <IOKit/IOPlatformExpert.h>
43 #include <IOKit/IOLib.h>
44 #include <IOKit/IOKitKeys.h>
45 #include <IOKit/IOKitDebug.h>
46 #include <IOKit/pwr_mgt/IOPMinformeeList.h>
47
48 #include <IOKit/assert.h>
49
50 #include "IOKitKernelInternal.h"
51
52 extern "C" {
53
54 extern void OSlibkernInit (void);
55
56 #include <kern/clock.h>
57 #include <sys/time.h>
58
59 void IOKitInitializeTime( void )
60 {
61 mach_timespec_t t;
62
63 t.tv_sec = 30;
64 t.tv_nsec = 0;
65 IOService::waitForService(
66 IOService::resourceMatching("IORTC"), &t );
67 #ifdef ppc
68 IOService::waitForService(
69 IOService::resourceMatching("IONVRAM"), &t );
70 #endif
71
72 clock_initialize_calendar();
73 }
74
75 void IOKitResetTime( void )
76 {
77 uint32_t secs, microsecs;
78
79 clock_initialize_calendar();
80
81 clock_get_calendar_microtime(&secs, &microsecs);
82 gIOLastWakeTime.tv_sec = secs;
83 gIOLastWakeTime.tv_usec = microsecs;
84 }
85
86
87 // From <osfmk/kern/debug.c>
88 extern int debug_mode;
89
90 void StartIOKit( void * p1, void * p2, void * p3, void * p4 )
91 {
92 IOPlatformExpertDevice * rootNub;
93 int debugFlags;
94 IORegistryEntry * root;
95 OSObject * obj;
96 extern const char * gIOKernelKmods;
97 OSString * errorString = NULL; // must release
98 OSDictionary * fakeKmods; // must release
99 OSCollectionIterator * kmodIter; // must release
100 OSString * kmodName; // don't release
101
102 if( PE_parse_boot_argn( "io", &debugFlags, sizeof (debugFlags) ))
103 gIOKitDebug = debugFlags;
104
105 // Check for the log synchronous bit set in io
106 if (gIOKitDebug & kIOLogSynchronous)
107 debug_mode = true;
108
109 //
110 // Have to start IOKit environment before we attempt to start
111 // the C++ runtime environment. At some stage we have to clean up
112 // the initialisation path so that OS C++ can initialise independantly
113 // of iokit basic service initialisation, or better we have IOLib stuff
114 // initialise as basic OS services.
115 //
116 IOLibInit();
117 OSlibkernInit();
118
119 /*****
120 * Declare the fake kmod_info structs for built-in components
121 * that must be tracked as independent units for dependencies.
122 */
123 fakeKmods = OSDynamicCast(OSDictionary,
124 OSUnserialize(gIOKernelKmods, &errorString));
125
126 if (!fakeKmods) {
127 if (errorString) {
128 panic("Kernel kmod list syntax error: %s\n",
129 errorString->getCStringNoCopy());
130 errorString->release();
131 } else {
132 panic("Error loading kernel kmod list.\n");
133 }
134 }
135
136 kmodIter = OSCollectionIterator::withCollection(fakeKmods);
137 if (!kmodIter) {
138 panic("Can't declare in-kernel kmods.\n");
139 }
140 while ((kmodName = OSDynamicCast(OSString, kmodIter->getNextObject()))) {
141
142 OSString * kmodVersion = OSDynamicCast(OSString,
143 fakeKmods->getObject(kmodName));
144 if (!kmodVersion) {
145 panic("Can't declare in-kernel kmod; \"%s\" has "
146 "an invalid version.\n",
147 kmodName->getCStringNoCopy());
148 }
149
150 // empty version strings get replaced with current kernel version
151 const char *vers = (strlen(kmodVersion->getCStringNoCopy())
152 ? kmodVersion->getCStringNoCopy()
153 : osrelease);
154
155 if (KERN_SUCCESS != kmod_create_fake(kmodName->getCStringNoCopy(), vers)) {
156 panic("Failure declaring in-kernel kmod \"%s\".\n",
157 kmodName->getCStringNoCopy());
158 }
159 }
160
161 kmodIter->release();
162 fakeKmods->release();
163
164
165
166 root = IORegistryEntry::initialize();
167 assert( root );
168 IOService::initialize();
169 IOCatalogue::initialize();
170 IOUserClient::initialize();
171 IOMemoryDescriptor::initialize();
172
173 // Initializes IOPMinformeeList class-wide shared lock
174 IOPMinformeeList::getSharedRecursiveLock();
175
176 obj = OSString::withCString( version );
177 assert( obj );
178 if( obj ) {
179 root->setProperty( kIOKitBuildVersionKey, obj );
180 obj->release();
181 }
182 obj = IOKitDiagnostics::diagnostics();
183 if( obj ) {
184 root->setProperty( kIOKitDiagnosticsKey, obj );
185 obj->release();
186 }
187
188 rootNub = new IOPlatformExpertDevice;
189
190 if( rootNub && rootNub->initWithArgs( p1, p2, p3, p4)) {
191 rootNub->attach( 0 );
192
193 /* Enter into the catalogue the drivers
194 * provided by BootX.
195 */
196 gIOCatalogue->recordStartupExtensions();
197
198 rootNub->registerService();
199
200 #if !NO_KEXTD
201 /* Add a busy count to keep the registry busy until kextd has
202 * completely finished launching. This is decremented when kextd
203 * messages the kernel after the in-kernel linker has been
204 * removed and personalities have been sent.
205 */
206 IOService::getServiceRoot()->adjustBusy(1);
207 #endif
208 }
209 }
210
211 void
212 IORegistrySetOSBuildVersion(char * build_version)
213 {
214 IORegistryEntry * root = IORegistryEntry::getRegistryRoot();
215
216 if (root) {
217 if (build_version) {
218 root->setProperty(kOSBuildVersionKey, build_version);
219 } else {
220 root->removeProperty(kOSBuildVersionKey);
221 }
222 }
223
224 return;
225 }
226
227 }; /* extern "C" */