]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
6d2010ae | 2 | * Copyright (c) 1998-2010 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 | 27 | */ |
1c79356b A |
28 | |
29 | #include <libkern/c++/OSUnserialize.h> | |
b0d623f7 | 30 | #include <libkern/c++/OSKext.h> |
91447636 | 31 | #include <libkern/version.h> |
1c79356b A |
32 | #include <IOKit/IORegistryEntry.h> |
33 | #include <IOKit/IODeviceTreeSupport.h> | |
34 | #include <IOKit/IOCatalogue.h> | |
35 | #include <IOKit/IOUserClient.h> | |
36 | #include <IOKit/IOMemoryDescriptor.h> | |
37 | #include <IOKit/IOPlatformExpert.h> | |
38 | #include <IOKit/IOLib.h> | |
39 | #include <IOKit/IOKitKeys.h> | |
40 | #include <IOKit/IOKitDebug.h> | |
6d2010ae | 41 | #include <IOKit/pwr_mgt/RootDomain.h> |
0c530ab8 | 42 | #include <IOKit/pwr_mgt/IOPMinformeeList.h> |
6d2010ae A |
43 | #include <IOKit/IOStatisticsPrivate.h> |
44 | #include <IOKit/IOKitKeysPrivate.h> | |
1c79356b A |
45 | |
46 | #include <IOKit/assert.h> | |
47 | ||
91447636 A |
48 | #include "IOKitKernelInternal.h" |
49 | ||
1c79356b A |
50 | extern "C" { |
51 | ||
52 | extern void OSlibkernInit (void); | |
1c79356b | 53 | |
b0d623f7 A |
54 | void iokit_post_constructor_init(void) __attribute__((section("__TEXT, initcode"))); |
55 | ||
1c79356b | 56 | #include <kern/clock.h> |
2d21ac55 | 57 | #include <sys/time.h> |
1c79356b | 58 | |
2d21ac55 | 59 | void IOKitInitializeTime( void ) |
1c79356b | 60 | { |
55e303ae | 61 | mach_timespec_t t; |
1c79356b | 62 | |
55e303ae A |
63 | t.tv_sec = 30; |
64 | t.tv_nsec = 0; | |
65 | IOService::waitForService( | |
66 | IOService::resourceMatching("IORTC"), &t ); | |
6d2010ae | 67 | #if defined(__i386__) || defined(__x86_64__) |
55e303ae A |
68 | IOService::waitForService( |
69 | IOService::resourceMatching("IONVRAM"), &t ); | |
1c79356b A |
70 | #endif |
71 | ||
72 | clock_initialize_calendar(); | |
73 | } | |
74 | ||
2d21ac55 A |
75 | void IOKitResetTime( void ) |
76 | { | |
b0d623f7 A |
77 | clock_sec_t secs; |
78 | clock_usec_t microsecs; | |
2d21ac55 A |
79 | |
80 | clock_initialize_calendar(); | |
81 | ||
82 | clock_get_calendar_microtime(&secs, µsecs); | |
83 | gIOLastWakeTime.tv_sec = secs; | |
84 | gIOLastWakeTime.tv_usec = microsecs; | |
6d2010ae A |
85 | |
86 | IOService::updateConsoleUsers(NULL, kIOMessageSystemHasPoweredOn); | |
2d21ac55 A |
87 | } |
88 | ||
b0d623f7 | 89 | void iokit_post_constructor_init(void) |
1c79356b | 90 | { |
1c79356b A |
91 | IORegistryEntry * root; |
92 | OSObject * obj; | |
1c79356b A |
93 | |
94 | root = IORegistryEntry::initialize(); | |
95 | assert( root ); | |
96 | IOService::initialize(); | |
97 | IOCatalogue::initialize(); | |
6d2010ae A |
98 | IOStatistics::initialize(); |
99 | OSKext::initialize(); | |
1c79356b A |
100 | IOUserClient::initialize(); |
101 | IOMemoryDescriptor::initialize(); | |
6d2010ae | 102 | IORootParent::initialize(); |
1c79356b | 103 | |
0c530ab8 A |
104 | // Initializes IOPMinformeeList class-wide shared lock |
105 | IOPMinformeeList::getSharedRecursiveLock(); | |
106 | ||
91447636 | 107 | obj = OSString::withCString( version ); |
1c79356b A |
108 | assert( obj ); |
109 | if( obj ) { | |
110 | root->setProperty( kIOKitBuildVersionKey, obj ); | |
111 | obj->release(); | |
112 | } | |
113 | obj = IOKitDiagnostics::diagnostics(); | |
114 | if( obj ) { | |
115 | root->setProperty( kIOKitDiagnosticsKey, obj ); | |
116 | obj->release(); | |
117 | } | |
b0d623f7 A |
118 | } |
119 | ||
120 | // From <osfmk/kern/debug.c> | |
121 | extern int debug_mode; | |
122 | ||
123 | /***** | |
124 | * Pointer into bootstrap KLD segment for functions never used past startup. | |
125 | */ | |
126 | void (*record_startup_extensions_function)(void) = 0; | |
127 | ||
128 | void StartIOKit( void * p1, void * p2, void * p3, void * p4 ) | |
129 | { | |
130 | IOPlatformExpertDevice * rootNub; | |
131 | int debugFlags; | |
132 | ||
133 | if( PE_parse_boot_argn( "io", &debugFlags, sizeof (debugFlags) )) | |
6d2010ae A |
134 | gIOKitDebug = debugFlags; |
135 | ||
060df5ea A |
136 | if( PE_parse_boot_argn( "iotrace", &debugFlags, sizeof (debugFlags) )) |
137 | gIOKitTrace = debugFlags; | |
138 | ||
139 | // Compat for boot-args | |
140 | gIOKitTrace |= (gIOKitDebug & kIOTraceCompatBootArgs); | |
060df5ea | 141 | |
b0d623f7 A |
142 | // Check for the log synchronous bit set in io |
143 | if (gIOKitDebug & kIOLogSynchronous) | |
144 | debug_mode = true; | |
6d2010ae | 145 | |
b0d623f7 A |
146 | // |
147 | // Have to start IOKit environment before we attempt to start | |
148 | // the C++ runtime environment. At some stage we have to clean up | |
149 | // the initialisation path so that OS C++ can initialise independantly | |
150 | // of iokit basic service initialisation, or better we have IOLib stuff | |
151 | // initialise as basic OS services. | |
152 | // | |
153 | IOLibInit(); | |
154 | OSlibkernInit(); | |
155 | ||
1c79356b A |
156 | rootNub = new IOPlatformExpertDevice; |
157 | ||
158 | if( rootNub && rootNub->initWithArgs( p1, p2, p3, p4)) { | |
159 | rootNub->attach( 0 ); | |
160 | ||
b0d623f7 A |
161 | /* If the bootstrap segment set up a function to record startup |
162 | * extensions, call it now. | |
1c79356b | 163 | */ |
b0d623f7 A |
164 | if (record_startup_extensions_function) { |
165 | record_startup_extensions_function(); | |
166 | } | |
1c79356b A |
167 | |
168 | rootNub->registerService(); | |
2d21ac55 A |
169 | |
170 | #if !NO_KEXTD | |
171 | /* Add a busy count to keep the registry busy until kextd has | |
172 | * completely finished launching. This is decremented when kextd | |
173 | * messages the kernel after the in-kernel linker has been | |
174 | * removed and personalities have been sent. | |
175 | */ | |
176 | IOService::getServiceRoot()->adjustBusy(1); | |
177 | #endif | |
1c79356b A |
178 | } |
179 | } | |
180 | ||
2d21ac55 A |
181 | void |
182 | IORegistrySetOSBuildVersion(char * build_version) | |
183 | { | |
184 | IORegistryEntry * root = IORegistryEntry::getRegistryRoot(); | |
185 | ||
186 | if (root) { | |
187 | if (build_version) { | |
188 | root->setProperty(kOSBuildVersionKey, build_version); | |
189 | } else { | |
190 | root->removeProperty(kOSBuildVersionKey); | |
191 | } | |
192 | } | |
193 | ||
194 | return; | |
195 | } | |
196 | ||
1c79356b | 197 | }; /* extern "C" */ |