2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1998,1999 Apple Computer, Inc. All rights reserved.
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>
43 #include <IOKit/assert.h>
47 extern void OSlibkernInit (void);
48 extern void IOLibInit(void);
50 #include <kern/clock.h>
52 /*XXX power management hacks XXX*/
53 #include <IOKit/IOReturn.h>
54 #include <IOKit/IOMessage.h>
56 extern void *registerSleepWakeInterest(
60 /*XXX power management hacks XXX*/
63 calend_wakeup_resynch(
64 thread_call_param_t p0
,
65 thread_call_param_t p1
)
67 void IOKitResetTime(void);
72 static thread_call_t calend_sleep_wake_call
;
75 calend_sleep_wake_notif(
78 unsigned int messageType
,
83 if (messageType
!= kIOMessageSystemHasPoweredOn
)
84 return (kIOReturnUnsupported
);
86 if (calend_sleep_wake_call
!= NULL
)
87 thread_call_enter(calend_sleep_wake_call
);
89 return (kIOReturnSuccess
);
92 void IOKitResetTime( void )
98 IOService::waitForService(
99 IOService::resourceMatching("IORTC"), &t
);
101 IOService::waitForService(
102 IOService::resourceMatching("IONVRAM"), &t
);
105 if (calend_sleep_wake_call
== NULL
) {
106 calend_sleep_wake_call
= thread_call_allocate(
107 calend_wakeup_resynch
, NULL
);
109 registerSleepWakeInterest((void *)calend_sleep_wake_notif
, NULL
, NULL
);
112 clock_initialize_calendar();
115 // From <osfmk/kern/debug.c>
116 extern int debug_mode
;
118 void StartIOKit( void * p1
, void * p2
, void * p3
, void * p4
)
120 IOPlatformExpertDevice
* rootNub
;
122 IORegistryEntry
* root
;
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
130 IOLog( iokit_version
);
132 if( PE_parse_boot_arg( "io", &debugFlags
))
133 gIOKitDebug
= debugFlags
;
135 // Check for the log synchronous bit set in io
136 if (gIOKitDebug
& kIOLogSynchronous
)
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.
149 IOLog("_cppInit done\n");
152 * Declare the fake kmod_info structs for built-in components
153 * that must be tracked as independent units for dependencies.
155 fakeKmods
= OSDynamicCast(OSDictionary
,
156 OSUnserialize(gIOKernelKmods
, &errorString
));
160 panic("Kernel kmod list syntax error: %s\n",
161 errorString
->getCStringNoCopy());
162 errorString
->release();
164 panic("Error loading kernel kmod list.\n");
168 kmodIter
= OSCollectionIterator::withCollection(fakeKmods
);
170 panic("Can't declare in-kernel kmods.\n");
172 while ((kmodName
= OSDynamicCast(OSString
, kmodIter
->getNextObject()))) {
174 OSString
* kmodVersion
= OSDynamicCast(OSString
,
175 fakeKmods
->getObject(kmodName
));
177 panic("Can't declare in-kernel kmod; \"%s\" has "
178 "an invalid version.\n",
179 kmodName
->getCStringNoCopy());
181 if (KERN_SUCCESS
!= kmod_create_fake(kmodName
->getCStringNoCopy(),
182 kmodVersion
->getCStringNoCopy())) {
183 panic("Failure declaring in-kernel kmod \"%s\".\n",
184 kmodName
->getCStringNoCopy());
189 fakeKmods
->release();
193 root
= IORegistryEntry::initialize();
195 IOService::initialize();
196 IOCatalogue::initialize();
197 IOUserClient::initialize();
198 IOMemoryDescriptor::initialize();
200 obj
= OSString::withCString( iokit_version
);
203 root
->setProperty( kIOKitBuildVersionKey
, obj
);
206 obj
= IOKitDiagnostics::diagnostics();
208 root
->setProperty( kIOKitDiagnosticsKey
, obj
);
212 rootNub
= new IOPlatformExpertDevice
;
214 if( rootNub
&& rootNub
->initWithArgs( p1
, p2
, p3
, p4
)) {
215 rootNub
->attach( 0 );
217 /* Enter into the catalogue the drivers
220 gIOCatalogue
->recordStartupExtensions();
222 rootNub
->registerService();