]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOStartIOKit.cpp
xnu-344.21.73.tar.gz
[apple/xnu.git] / iokit / Kernel / IOStartIOKit.cpp
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
d7e50217 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
d7e50217
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
d7e50217
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * Copyright (c) 1998,1999 Apple Computer, Inc. All rights reserved.
27 *
28 * HISTORY
29 *
30 */
31
32#include <libkern/c++/OSUnserialize.h>
33#include <IOKit/IORegistryEntry.h>
34#include <IOKit/IODeviceTreeSupport.h>
35#include <IOKit/IOCatalogue.h>
36#include <IOKit/IOUserClient.h>
37#include <IOKit/IOMemoryDescriptor.h>
38#include <IOKit/IOPlatformExpert.h>
39#include <IOKit/IOLib.h>
40#include <IOKit/IOKitKeys.h>
41#include <IOKit/IOKitDebug.h>
1c79356b
A
42
43#include <IOKit/assert.h>
44
45extern "C" {
46
47extern void OSlibkernInit (void);
48extern void IOLibInit(void);
49
50#include <kern/clock.h>
51
0b4e3aa0
A
52/*XXX power management hacks XXX*/
53#include <IOKit/IOReturn.h>
54#include <IOKit/IOMessage.h>
55
56extern void *registerSleepWakeInterest(
57 void *callback,
58 void *target,
59 void *refCon);
60/*XXX power management hacks XXX*/
61
62static void
63calend_wakeup_resynch(
64 thread_call_param_t p0,
65 thread_call_param_t p1)
66{
67 void IOKitResetTime(void);
68
69 IOKitResetTime();
70}
71
72static thread_call_t calend_sleep_wake_call;
73
74static IOReturn
75calend_sleep_wake_notif(
76 void *target,
77 void *refCon,
78 unsigned int messageType,
79 void *provider,
80 void *messageArg,
81 vm_size_t argSize)
82{
83 if (messageType != kIOMessageSystemHasPoweredOn)
84 return (kIOReturnUnsupported);
85
86 if (calend_sleep_wake_call != NULL)
87 thread_call_enter(calend_sleep_wake_call);
88
89 return (kIOReturnSuccess);
90}
1c79356b
A
91
92void IOKitResetTime( void )
93{
94 mach_timespec_t t;
95
96 t.tv_sec = 30;
97 t.tv_nsec = 0;
98 IOService::waitForService(
99 IOService::resourceMatching("IORTC"), &t );
100#ifndef i386
101 IOService::waitForService(
102 IOService::resourceMatching("IONVRAM"), &t );
103#endif
104
0b4e3aa0
A
105 if (calend_sleep_wake_call == NULL) {
106 calend_sleep_wake_call = thread_call_allocate(
107 calend_wakeup_resynch, NULL);
108
9bccf70c 109 registerSleepWakeInterest((void *)calend_sleep_wake_notif, NULL, NULL);
0b4e3aa0
A
110 }
111
1c79356b
A
112 clock_initialize_calendar();
113}
114
d7e50217
A
115// From <osfmk/kern/debug.c>
116extern int debug_mode;
1c79356b
A
117
118void StartIOKit( void * p1, void * p2, void * p3, void * p4 )
119{
120 IOPlatformExpertDevice * rootNub;
121 int debugFlags;
122 IORegistryEntry * root;
123 OSObject * obj;
124 extern const char * gIOKernelKmods;
125 OSString * errorString = NULL; // must release
126 OSDictionary * fakeKmods; // must release
127 OSCollectionIterator * kmodIter; // must release
128 OSString * kmodName; // don't release
129
130 IOLog( iokit_version );
131
132 if( PE_parse_boot_arg( "io", &debugFlags ))
133 gIOKitDebug = debugFlags;
d7e50217
A
134
135 // Check for the log synchronous bit set in io
136 if (gIOKitDebug & kIOLogSynchronous)
137 debug_mode = true;
138
1c79356b
A
139 //
140 // Have to start IOKit environment before we attempt to start
141 // the C++ runtime environment. At some stage we have to clean up
142 // the initialisation path so that OS C++ can initialise independantly
143 // of iokit basic service initialisation, or better we have IOLib stuff
144 // initialise as basic OS services.
145 //
146 IOLibInit();
147 OSlibkernInit();
148
149 IOLog("_cppInit done\n");
150
1c79356b
A
151 /*****
152 * Declare the fake kmod_info structs for built-in components
153 * that must be tracked as independent units for dependencies.
154 */
155 fakeKmods = OSDynamicCast(OSDictionary,
156 OSUnserialize(gIOKernelKmods, &errorString));
157
158 if (!fakeKmods) {
159 if (errorString) {
160 panic("Kernel kmod list syntax error: %s\n",
161 errorString->getCStringNoCopy());
162 errorString->release();
163 } else {
164 panic("Error loading kernel kmod list.\n");
165 }
166 }
167
168 kmodIter = OSCollectionIterator::withCollection(fakeKmods);
169 if (!kmodIter) {
170 panic("Can't declare in-kernel kmods.\n");
171 }
172 while ((kmodName = OSDynamicCast(OSString, kmodIter->getNextObject()))) {
173
174 OSString * kmodVersion = OSDynamicCast(OSString,
175 fakeKmods->getObject(kmodName));
176 if (!kmodVersion) {
177 panic("Can't declare in-kernel kmod; \"%s\" has "
178 "an invalid version.\n",
179 kmodName->getCStringNoCopy());
180 }
181 if (KERN_SUCCESS != kmod_create_fake(kmodName->getCStringNoCopy(),
182 kmodVersion->getCStringNoCopy())) {
183 panic("Failure declaring in-kernel kmod \"%s\".\n",
184 kmodName->getCStringNoCopy());
185 }
186 }
187
188 kmodIter->release();
189 fakeKmods->release();
190
191
192
193 root = IORegistryEntry::initialize();
194 assert( root );
195 IOService::initialize();
196 IOCatalogue::initialize();
197 IOUserClient::initialize();
198 IOMemoryDescriptor::initialize();
1c79356b
A
199
200 obj = OSString::withCString( iokit_version );
201 assert( obj );
202 if( obj ) {
203 root->setProperty( kIOKitBuildVersionKey, obj );
204 obj->release();
205 }
206 obj = IOKitDiagnostics::diagnostics();
207 if( obj ) {
208 root->setProperty( kIOKitDiagnosticsKey, obj );
209 obj->release();
210 }
211
1c79356b
A
212 rootNub = new IOPlatformExpertDevice;
213
214 if( rootNub && rootNub->initWithArgs( p1, p2, p3, p4)) {
215 rootNub->attach( 0 );
216
217 /* Enter into the catalogue the drivers
218 * provided by BootX.
219 */
220 gIOCatalogue->recordStartupExtensions();
221
222 rootNub->registerService();
223 }
224}
225
226}; /* extern "C" */