]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOStartIOKit.cpp
xnu-792.13.8.tar.gz
[apple/xnu.git] / iokit / Kernel / IOStartIOKit.cpp
1 /*
2 * Copyright (c) 1998-2005 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 extern void ml_hpet_cfg(uint32_t, uint32_t);
57
58 #include <kern/clock.h>
59
60 void IOKitResetTime( void )
61 {
62 mach_timespec_t t;
63
64 t.tv_sec = 30;
65 t.tv_nsec = 0;
66 IOService::waitForService(
67 IOService::resourceMatching("IORTC"), &t );
68 #ifndef i386
69 IOService::waitForService(
70 IOService::resourceMatching("IONVRAM"), &t );
71
72 #endif
73
74 clock_initialize_calendar();
75 }
76
77 // From <osfmk/kern/debug.c>
78 extern int debug_mode;
79
80 void StartIOKit( void * p1, void * p2, void * p3, void * p4 )
81 {
82 IOPlatformExpertDevice * rootNub;
83 int debugFlags;
84 IORegistryEntry * root;
85 OSObject * obj;
86 extern const char * gIOKernelKmods;
87 OSString * errorString = NULL; // must release
88 OSDictionary * fakeKmods; // must release
89 OSCollectionIterator * kmodIter; // must release
90 OSString * kmodName; // don't release
91
92 if( PE_parse_boot_arg( "io", &debugFlags ))
93 gIOKitDebug = debugFlags;
94
95 // Check for the log synchronous bit set in io
96 if (gIOKitDebug & kIOLogSynchronous)
97 debug_mode = true;
98
99 //
100 // Have to start IOKit environment before we attempt to start
101 // the C++ runtime environment. At some stage we have to clean up
102 // the initialisation path so that OS C++ can initialise independantly
103 // of iokit basic service initialisation, or better we have IOLib stuff
104 // initialise as basic OS services.
105 //
106 IOLibInit();
107 OSlibkernInit();
108
109 /*****
110 * Declare the fake kmod_info structs for built-in components
111 * that must be tracked as independent units for dependencies.
112 */
113 fakeKmods = OSDynamicCast(OSDictionary,
114 OSUnserialize(gIOKernelKmods, &errorString));
115
116 if (!fakeKmods) {
117 if (errorString) {
118 panic("Kernel kmod list syntax error: %s\n",
119 errorString->getCStringNoCopy());
120 errorString->release();
121 } else {
122 panic("Error loading kernel kmod list.\n");
123 }
124 }
125
126 kmodIter = OSCollectionIterator::withCollection(fakeKmods);
127 if (!kmodIter) {
128 panic("Can't declare in-kernel kmods.\n");
129 }
130 while ((kmodName = OSDynamicCast(OSString, kmodIter->getNextObject()))) {
131
132 OSString * kmodVersion = OSDynamicCast(OSString,
133 fakeKmods->getObject(kmodName));
134 if (!kmodVersion) {
135 panic("Can't declare in-kernel kmod; \"%s\" has "
136 "an invalid version.\n",
137 kmodName->getCStringNoCopy());
138 }
139
140 // empty version strings get replaced with current kernel version
141 const char *vers = (strlen(kmodVersion->getCStringNoCopy())
142 ? kmodVersion->getCStringNoCopy()
143 : osrelease);
144
145 if (KERN_SUCCESS != kmod_create_fake(kmodName->getCStringNoCopy(), vers)) {
146 panic("Failure declaring in-kernel kmod \"%s\".\n",
147 kmodName->getCStringNoCopy());
148 }
149 }
150
151 kmodIter->release();
152 fakeKmods->release();
153
154
155
156 root = IORegistryEntry::initialize();
157 assert( root );
158 IOService::initialize();
159 IOCatalogue::initialize();
160 IOUserClient::initialize();
161 IOMemoryDescriptor::initialize();
162
163 obj = OSString::withCString( version );
164 assert( obj );
165 if( obj ) {
166 root->setProperty( kIOKitBuildVersionKey, obj );
167 obj->release();
168 }
169 obj = IOKitDiagnostics::diagnostics();
170 if( obj ) {
171 root->setProperty( kIOKitDiagnosticsKey, obj );
172 obj->release();
173 }
174
175 rootNub = new IOPlatformExpertDevice;
176
177 if( rootNub && rootNub->initWithArgs( p1, p2, p3, p4)) {
178 rootNub->attach( 0 );
179
180 /* Enter into the catalogue the drivers
181 * provided by BootX.
182 */
183 gIOCatalogue->recordStartupExtensions();
184
185 rootNub->registerService();
186 }
187 }
188
189 }; /* extern "C" */