]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOStartIOKit.cpp
xnu-1504.9.17.tar.gz
[apple/xnu.git] / iokit / Kernel / IOStartIOKit.cpp
CommitLineData
1c79356b 1/*
b0d623f7 2 * Copyright (c) 1998-2008 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
b0d623f7 29 * Copyright (c) 1998,1999 Apple Inc. All rights reserved.
1c79356b
A
30 *
31 * HISTORY
32 *
33 */
34
35#include <libkern/c++/OSUnserialize.h>
b0d623f7 36#include <libkern/c++/OSKext.h>
91447636 37#include <libkern/version.h>
1c79356b
A
38#include <IOKit/IORegistryEntry.h>
39#include <IOKit/IODeviceTreeSupport.h>
40#include <IOKit/IOCatalogue.h>
41#include <IOKit/IOUserClient.h>
42#include <IOKit/IOMemoryDescriptor.h>
43#include <IOKit/IOPlatformExpert.h>
44#include <IOKit/IOLib.h>
45#include <IOKit/IOKitKeys.h>
46#include <IOKit/IOKitDebug.h>
0c530ab8 47#include <IOKit/pwr_mgt/IOPMinformeeList.h>
1c79356b
A
48
49#include <IOKit/assert.h>
50
91447636
A
51#include "IOKitKernelInternal.h"
52
1c79356b
A
53extern "C" {
54
55extern void OSlibkernInit (void);
1c79356b 56
b0d623f7
A
57void iokit_post_constructor_init(void) __attribute__((section("__TEXT, initcode")));
58
1c79356b 59#include <kern/clock.h>
2d21ac55 60#include <sys/time.h>
1c79356b 61
2d21ac55 62void IOKitInitializeTime( void )
1c79356b 63{
55e303ae 64 mach_timespec_t t;
1c79356b 65
55e303ae
A
66 t.tv_sec = 30;
67 t.tv_nsec = 0;
68 IOService::waitForService(
69 IOService::resourceMatching("IORTC"), &t );
2d21ac55 70#ifdef ppc
55e303ae
A
71 IOService::waitForService(
72 IOService::resourceMatching("IONVRAM"), &t );
1c79356b
A
73#endif
74
75 clock_initialize_calendar();
76}
77
2d21ac55
A
78void IOKitResetTime( void )
79{
b0d623f7
A
80 clock_sec_t secs;
81 clock_usec_t microsecs;
2d21ac55
A
82
83 clock_initialize_calendar();
84
85 clock_get_calendar_microtime(&secs, &microsecs);
86 gIOLastWakeTime.tv_sec = secs;
87 gIOLastWakeTime.tv_usec = microsecs;
88}
89
b0d623f7 90void iokit_post_constructor_init(void)
1c79356b 91{
1c79356b
A
92 IORegistryEntry * root;
93 OSObject * obj;
1c79356b
A
94
95 root = IORegistryEntry::initialize();
96 assert( root );
97 IOService::initialize();
98 IOCatalogue::initialize();
99 IOUserClient::initialize();
100 IOMemoryDescriptor::initialize();
1c79356b 101
0c530ab8
A
102 // Initializes IOPMinformeeList class-wide shared lock
103 IOPMinformeeList::getSharedRecursiveLock();
104
91447636 105 obj = OSString::withCString( version );
1c79356b
A
106 assert( obj );
107 if( obj ) {
108 root->setProperty( kIOKitBuildVersionKey, obj );
109 obj->release();
110 }
111 obj = IOKitDiagnostics::diagnostics();
112 if( obj ) {
113 root->setProperty( kIOKitDiagnosticsKey, obj );
114 obj->release();
115 }
116
b0d623f7
A
117}
118
119// From <osfmk/kern/debug.c>
120extern int debug_mode;
121
122/*****
123 * Pointer into bootstrap KLD segment for functions never used past startup.
124 */
125void (*record_startup_extensions_function)(void) = 0;
126
127void StartIOKit( void * p1, void * p2, void * p3, void * p4 )
128{
129 IOPlatformExpertDevice * rootNub;
130 int debugFlags;
131
132 if( PE_parse_boot_argn( "io", &debugFlags, sizeof (debugFlags) ))
133 gIOKitDebug = debugFlags;
134
135 // Check for the log synchronous bit set in io
136 if (gIOKitDebug & kIOLogSynchronous)
137 debug_mode = true;
138
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
1c79356b
A
149 rootNub = new IOPlatformExpertDevice;
150
151 if( rootNub && rootNub->initWithArgs( p1, p2, p3, p4)) {
152 rootNub->attach( 0 );
153
b0d623f7
A
154 /* If the bootstrap segment set up a function to record startup
155 * extensions, call it now.
1c79356b 156 */
b0d623f7
A
157 if (record_startup_extensions_function) {
158 record_startup_extensions_function();
159 }
1c79356b
A
160
161 rootNub->registerService();
2d21ac55
A
162
163#if !NO_KEXTD
164 /* Add a busy count to keep the registry busy until kextd has
165 * completely finished launching. This is decremented when kextd
166 * messages the kernel after the in-kernel linker has been
167 * removed and personalities have been sent.
168 */
169 IOService::getServiceRoot()->adjustBusy(1);
170#endif
1c79356b
A
171 }
172}
173
2d21ac55
A
174void
175IORegistrySetOSBuildVersion(char * build_version)
176{
177 IORegistryEntry * root = IORegistryEntry::getRegistryRoot();
178
179 if (root) {
180 if (build_version) {
181 root->setProperty(kOSBuildVersionKey, build_version);
182 } else {
183 root->removeProperty(kOSBuildVersionKey);
184 }
185 }
186
187 return;
188}
189
1c79356b 190}; /* extern "C" */