]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOStartIOKit.cpp
xnu-792.17.14.tar.gz
[apple/xnu.git] / iokit / Kernel / IOStartIOKit.cpp
CommitLineData
1c79356b 1/*
8f6c56a5 2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
8f6c56a5
A
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
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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>
91447636 36#include <libkern/version.h>
1c79356b
A
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>
1c79356b
A
46
47#include <IOKit/assert.h>
48
91447636
A
49#include "IOKitKernelInternal.h"
50
1c79356b
A
51extern "C" {
52
53extern void OSlibkernInit (void);
1c79356b
A
54
55#include <kern/clock.h>
56
1c79356b
A
57void IOKitResetTime( void )
58{
55e303ae 59 mach_timespec_t t;
1c79356b 60
55e303ae
A
61 t.tv_sec = 30;
62 t.tv_nsec = 0;
63 IOService::waitForService(
64 IOService::resourceMatching("IORTC"), &t );
1c79356b 65#ifndef i386
55e303ae
A
66 IOService::waitForService(
67 IOService::resourceMatching("IONVRAM"), &t );
1c79356b
A
68#endif
69
70 clock_initialize_calendar();
71}
72
55e303ae
A
73// From <osfmk/kern/debug.c>
74extern int debug_mode;
1c79356b
A
75
76void StartIOKit( void * p1, void * p2, void * p3, void * p4 )
77{
78 IOPlatformExpertDevice * rootNub;
79 int debugFlags;
80 IORegistryEntry * root;
81 OSObject * obj;
82 extern const char * gIOKernelKmods;
83 OSString * errorString = NULL; // must release
84 OSDictionary * fakeKmods; // must release
85 OSCollectionIterator * kmodIter; // must release
86 OSString * kmodName; // don't release
87
1c79356b
A
88 if( PE_parse_boot_arg( "io", &debugFlags ))
89 gIOKitDebug = debugFlags;
55e303ae
A
90
91 // Check for the log synchronous bit set in io
92 if (gIOKitDebug & kIOLogSynchronous)
93 debug_mode = true;
94
1c79356b
A
95 //
96 // Have to start IOKit environment before we attempt to start
97 // the C++ runtime environment. At some stage we have to clean up
98 // the initialisation path so that OS C++ can initialise independantly
99 // of iokit basic service initialisation, or better we have IOLib stuff
100 // initialise as basic OS services.
101 //
102 IOLibInit();
103 OSlibkernInit();
104
1c79356b
A
105 /*****
106 * Declare the fake kmod_info structs for built-in components
107 * that must be tracked as independent units for dependencies.
108 */
109 fakeKmods = OSDynamicCast(OSDictionary,
110 OSUnserialize(gIOKernelKmods, &errorString));
111
112 if (!fakeKmods) {
113 if (errorString) {
114 panic("Kernel kmod list syntax error: %s\n",
115 errorString->getCStringNoCopy());
116 errorString->release();
117 } else {
118 panic("Error loading kernel kmod list.\n");
119 }
120 }
121
122 kmodIter = OSCollectionIterator::withCollection(fakeKmods);
123 if (!kmodIter) {
124 panic("Can't declare in-kernel kmods.\n");
125 }
126 while ((kmodName = OSDynamicCast(OSString, kmodIter->getNextObject()))) {
127
128 OSString * kmodVersion = OSDynamicCast(OSString,
129 fakeKmods->getObject(kmodName));
130 if (!kmodVersion) {
131 panic("Can't declare in-kernel kmod; \"%s\" has "
132 "an invalid version.\n",
133 kmodName->getCStringNoCopy());
134 }
91447636
A
135
136 // empty version strings get replaced with current kernel version
137 const char *vers = (strlen(kmodVersion->getCStringNoCopy())
138 ? kmodVersion->getCStringNoCopy()
139 : osrelease);
140
141 if (KERN_SUCCESS != kmod_create_fake(kmodName->getCStringNoCopy(), vers)) {
1c79356b
A
142 panic("Failure declaring in-kernel kmod \"%s\".\n",
143 kmodName->getCStringNoCopy());
144 }
145 }
146
147 kmodIter->release();
148 fakeKmods->release();
149
150
151
152 root = IORegistryEntry::initialize();
153 assert( root );
154 IOService::initialize();
155 IOCatalogue::initialize();
156 IOUserClient::initialize();
157 IOMemoryDescriptor::initialize();
1c79356b 158
91447636 159 obj = OSString::withCString( version );
1c79356b
A
160 assert( obj );
161 if( obj ) {
162 root->setProperty( kIOKitBuildVersionKey, obj );
163 obj->release();
164 }
165 obj = IOKitDiagnostics::diagnostics();
166 if( obj ) {
167 root->setProperty( kIOKitDiagnosticsKey, obj );
168 obj->release();
169 }
170
1c79356b
A
171 rootNub = new IOPlatformExpertDevice;
172
173 if( rootNub && rootNub->initWithArgs( p1, p2, p3, p4)) {
174 rootNub->attach( 0 );
175
176 /* Enter into the catalogue the drivers
177 * provided by BootX.
178 */
179 gIOCatalogue->recordStartupExtensions();
180
181 rootNub->registerService();
182 }
183}
184
185}; /* extern "C" */