]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOStartIOKit.cpp
eab0c1972b40c2c1ef3cac7b93e4481925cf27a5
[apple/xnu.git] / iokit / Kernel / IOStartIOKit.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Copyright (c) 1998,1999 Apple Computer, Inc. All rights reserved.
32 *
33 * HISTORY
34 *
35 */
36
37 #include <libkern/c++/OSUnserialize.h>
38 #include <libkern/version.h>
39 #include <IOKit/IORegistryEntry.h>
40 #include <IOKit/IODeviceTreeSupport.h>
41 #include <IOKit/IOCatalogue.h>
42 #include <IOKit/IOUserClient.h>
43 #include <IOKit/IOMemoryDescriptor.h>
44 #include <IOKit/IOPlatformExpert.h>
45 #include <IOKit/IOLib.h>
46 #include <IOKit/IOKitKeys.h>
47 #include <IOKit/IOKitDebug.h>
48
49 #include <IOKit/assert.h>
50
51 #include "IOKitKernelInternal.h"
52
53 extern "C" {
54
55 extern void OSlibkernInit (void);
56
57 #include <kern/clock.h>
58
59 void IOKitResetTime( 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 #ifndef i386
68 IOService::waitForService(
69 IOService::resourceMatching("IONVRAM"), &t );
70 #endif
71
72 clock_initialize_calendar();
73 }
74
75 // From <osfmk/kern/debug.c>
76 extern int debug_mode;
77
78 void StartIOKit( void * p1, void * p2, void * p3, void * p4 )
79 {
80 IOPlatformExpertDevice * rootNub;
81 int debugFlags;
82 IORegistryEntry * root;
83 OSObject * obj;
84 extern const char * gIOKernelKmods;
85 OSString * errorString = NULL; // must release
86 OSDictionary * fakeKmods; // must release
87 OSCollectionIterator * kmodIter; // must release
88 OSString * kmodName; // don't release
89
90 if( PE_parse_boot_arg( "io", &debugFlags ))
91 gIOKitDebug = debugFlags;
92
93 // Check for the log synchronous bit set in io
94 if (gIOKitDebug & kIOLogSynchronous)
95 debug_mode = true;
96
97 //
98 // Have to start IOKit environment before we attempt to start
99 // the C++ runtime environment. At some stage we have to clean up
100 // the initialisation path so that OS C++ can initialise independantly
101 // of iokit basic service initialisation, or better we have IOLib stuff
102 // initialise as basic OS services.
103 //
104 IOLibInit();
105 OSlibkernInit();
106
107 /*****
108 * Declare the fake kmod_info structs for built-in components
109 * that must be tracked as independent units for dependencies.
110 */
111 fakeKmods = OSDynamicCast(OSDictionary,
112 OSUnserialize(gIOKernelKmods, &errorString));
113
114 if (!fakeKmods) {
115 if (errorString) {
116 panic("Kernel kmod list syntax error: %s\n",
117 errorString->getCStringNoCopy());
118 errorString->release();
119 } else {
120 panic("Error loading kernel kmod list.\n");
121 }
122 }
123
124 kmodIter = OSCollectionIterator::withCollection(fakeKmods);
125 if (!kmodIter) {
126 panic("Can't declare in-kernel kmods.\n");
127 }
128 while ((kmodName = OSDynamicCast(OSString, kmodIter->getNextObject()))) {
129
130 OSString * kmodVersion = OSDynamicCast(OSString,
131 fakeKmods->getObject(kmodName));
132 if (!kmodVersion) {
133 panic("Can't declare in-kernel kmod; \"%s\" has "
134 "an invalid version.\n",
135 kmodName->getCStringNoCopy());
136 }
137
138 // empty version strings get replaced with current kernel version
139 const char *vers = (strlen(kmodVersion->getCStringNoCopy())
140 ? kmodVersion->getCStringNoCopy()
141 : osrelease);
142
143 if (KERN_SUCCESS != kmod_create_fake(kmodName->getCStringNoCopy(), vers)) {
144 panic("Failure declaring in-kernel kmod \"%s\".\n",
145 kmodName->getCStringNoCopy());
146 }
147 }
148
149 kmodIter->release();
150 fakeKmods->release();
151
152
153
154 root = IORegistryEntry::initialize();
155 assert( root );
156 IOService::initialize();
157 IOCatalogue::initialize();
158 IOUserClient::initialize();
159 IOMemoryDescriptor::initialize();
160
161 obj = OSString::withCString( version );
162 assert( obj );
163 if( obj ) {
164 root->setProperty( kIOKitBuildVersionKey, obj );
165 obj->release();
166 }
167 obj = IOKitDiagnostics::diagnostics();
168 if( obj ) {
169 root->setProperty( kIOKitDiagnosticsKey, obj );
170 obj->release();
171 }
172
173 rootNub = new IOPlatformExpertDevice;
174
175 if( rootNub && rootNub->initWithArgs( p1, p2, p3, p4)) {
176 rootNub->attach( 0 );
177
178 /* Enter into the catalogue the drivers
179 * provided by BootX.
180 */
181 gIOCatalogue->recordStartupExtensions();
182
183 rootNub->registerService();
184 }
185 }
186
187 }; /* extern "C" */