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();
116 void StartIOKit( void * p1
, void * p2
, void * p3
, void * p4
)
118 IOPlatformExpertDevice
* rootNub
;
120 IORegistryEntry
* root
;
122 extern const char * gIOKernelKmods
;
123 OSString
* errorString
= NULL
; // must release
124 OSDictionary
* fakeKmods
; // must release
125 OSCollectionIterator
* kmodIter
; // must release
126 OSString
* kmodName
; // don't release
128 IOLog( iokit_version
);
130 if( PE_parse_boot_arg( "io", &debugFlags
))
131 gIOKitDebug
= debugFlags
;
133 // Have to start IOKit environment before we attempt to start
134 // the C++ runtime environment. At some stage we have to clean up
135 // the initialisation path so that OS C++ can initialise independantly
136 // of iokit basic service initialisation, or better we have IOLib stuff
137 // initialise as basic OS services.
142 IOLog("_cppInit done\n");
146 * Declare the fake kmod_info structs for built-in components
147 * that must be tracked as independent units for dependencies.
149 fakeKmods
= OSDynamicCast(OSDictionary
,
150 OSUnserialize(gIOKernelKmods
, &errorString
));
154 panic("Kernel kmod list syntax error: %s\n",
155 errorString
->getCStringNoCopy());
156 errorString
->release();
158 panic("Error loading kernel kmod list.\n");
162 kmodIter
= OSCollectionIterator::withCollection(fakeKmods
);
164 panic("Can't declare in-kernel kmods.\n");
166 while ((kmodName
= OSDynamicCast(OSString
, kmodIter
->getNextObject()))) {
168 OSString
* kmodVersion
= OSDynamicCast(OSString
,
169 fakeKmods
->getObject(kmodName
));
171 panic("Can't declare in-kernel kmod; \"%s\" has "
172 "an invalid version.\n",
173 kmodName
->getCStringNoCopy());
175 if (KERN_SUCCESS
!= kmod_create_fake(kmodName
->getCStringNoCopy(),
176 kmodVersion
->getCStringNoCopy())) {
177 panic("Failure declaring in-kernel kmod \"%s\".\n",
178 kmodName
->getCStringNoCopy());
183 fakeKmods
->release();
187 root
= IORegistryEntry::initialize();
189 IOService::initialize();
190 IOCatalogue::initialize();
191 IOUserClient::initialize();
192 IOMemoryDescriptor::initialize();
194 obj
= OSString::withCString( iokit_version
);
197 root
->setProperty( kIOKitBuildVersionKey
, obj
);
200 obj
= IOKitDiagnostics::diagnostics();
202 root
->setProperty( kIOKitDiagnosticsKey
, obj
);
206 rootNub
= new IOPlatformExpertDevice
;
208 if( rootNub
&& rootNub
->initWithArgs( p1
, p2
, p3
, p4
)) {
209 rootNub
->attach( 0 );
211 /* Enter into the catalogue the drivers
214 gIOCatalogue
->recordStartupExtensions();
216 rootNub
->registerService();