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