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