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