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