1*c54f35caSApple OSS Distributions /*
2*c54f35caSApple OSS Distributions * Copyright (c) 1998-2010 Apple Inc. All rights reserved.
3*c54f35caSApple OSS Distributions *
4*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*c54f35caSApple OSS Distributions *
6*c54f35caSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*c54f35caSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*c54f35caSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*c54f35caSApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*c54f35caSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*c54f35caSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*c54f35caSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*c54f35caSApple OSS Distributions * terms of an Apple operating system software license agreement.
14*c54f35caSApple OSS Distributions *
15*c54f35caSApple OSS Distributions * Please obtain a copy of the License at
16*c54f35caSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*c54f35caSApple OSS Distributions *
18*c54f35caSApple OSS Distributions * The Original Code and all software distributed under the License are
19*c54f35caSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*c54f35caSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*c54f35caSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*c54f35caSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*c54f35caSApple OSS Distributions * Please see the License for the specific language governing rights and
24*c54f35caSApple OSS Distributions * limitations under the License.
25*c54f35caSApple OSS Distributions *
26*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*c54f35caSApple OSS Distributions */
28*c54f35caSApple OSS Distributions
29*c54f35caSApple OSS Distributions #include <libkern/c++/OSUnserialize.h>
30*c54f35caSApple OSS Distributions #include <libkern/c++/OSKext.h>
31*c54f35caSApple OSS Distributions #include <libkern/section_keywords.h>
32*c54f35caSApple OSS Distributions #include <libkern/version.h>
33*c54f35caSApple OSS Distributions #include <IOKit/IORegistryEntry.h>
34*c54f35caSApple OSS Distributions #include <IOKit/IODeviceTreeSupport.h>
35*c54f35caSApple OSS Distributions #include <IOKit/IOCatalogue.h>
36*c54f35caSApple OSS Distributions #include <IOKit/IOUserClient.h>
37*c54f35caSApple OSS Distributions #include <IOKit/IOMemoryDescriptor.h>
38*c54f35caSApple OSS Distributions #include <IOKit/IOPlatformExpert.h>
39*c54f35caSApple OSS Distributions #include <IOKit/IOKernelReporters.h>
40*c54f35caSApple OSS Distributions #include <IOKit/IOLib.h>
41*c54f35caSApple OSS Distributions #include <IOKit/IOKitKeys.h>
42*c54f35caSApple OSS Distributions #include <IOKit/IOKitDebug.h>
43*c54f35caSApple OSS Distributions #include <IOKit/pwr_mgt/RootDomain.h>
44*c54f35caSApple OSS Distributions #include <IOKit/pwr_mgt/IOPMinformeeList.h>
45*c54f35caSApple OSS Distributions #include <IOKit/IOStatisticsPrivate.h>
46*c54f35caSApple OSS Distributions #include <IOKit/IOKitKeysPrivate.h>
47*c54f35caSApple OSS Distributions #include <IOKit/IOInterruptAccountingPrivate.h>
48*c54f35caSApple OSS Distributions #include <IOKit/assert.h>
49*c54f35caSApple OSS Distributions #include <sys/conf.h>
50*c54f35caSApple OSS Distributions
51*c54f35caSApple OSS Distributions #include "IOKitKernelInternal.h"
52*c54f35caSApple OSS Distributions
53*c54f35caSApple OSS Distributions const OSSymbol * gIOProgressBackbufferKey;
54*c54f35caSApple OSS Distributions OSSet * gIORemoveOnReadProperties;
55*c54f35caSApple OSS Distributions
56*c54f35caSApple OSS Distributions extern "C" {
57*c54f35caSApple OSS Distributions void InitIOKit(void *dtTop);
58*c54f35caSApple OSS Distributions void ConfigureIOKit(void);
59*c54f35caSApple OSS Distributions void StartIOKitMatching(void);
60*c54f35caSApple OSS Distributions void IORegistrySetOSBuildVersion(char * build_version);
61*c54f35caSApple OSS Distributions void IORecordProgressBackbuffer(void * buffer, size_t size, uint32_t theme);
62*c54f35caSApple OSS Distributions
63*c54f35caSApple OSS Distributions extern void OSlibkernInit(void);
64*c54f35caSApple OSS Distributions
65*c54f35caSApple OSS Distributions void iokit_post_constructor_init(void);
66*c54f35caSApple OSS Distributions
67*c54f35caSApple OSS Distributions SECURITY_READ_ONLY_LATE(static IOPlatformExpertDevice*) gRootNub;
68*c54f35caSApple OSS Distributions
69*c54f35caSApple OSS Distributions #include <kern/clock.h>
70*c54f35caSApple OSS Distributions #include <sys/time.h>
71*c54f35caSApple OSS Distributions
72*c54f35caSApple OSS Distributions void
IOKitInitializeTime(void)73*c54f35caSApple OSS Distributions IOKitInitializeTime( void )
74*c54f35caSApple OSS Distributions {
75*c54f35caSApple OSS Distributions mach_timespec_t t;
76*c54f35caSApple OSS Distributions
77*c54f35caSApple OSS Distributions t.tv_sec = 30;
78*c54f35caSApple OSS Distributions t.tv_nsec = 0;
79*c54f35caSApple OSS Distributions
80*c54f35caSApple OSS Distributions // RTC is not present on this target
81*c54f35caSApple OSS Distributions #ifndef BCM2837
82*c54f35caSApple OSS Distributions IOService::waitForService(
83*c54f35caSApple OSS Distributions IOService::resourceMatching("IORTC"), &t );
84*c54f35caSApple OSS Distributions #endif
85*c54f35caSApple OSS Distributions #if defined(__i386__) || defined(__x86_64__)
86*c54f35caSApple OSS Distributions IOService::waitForService(
87*c54f35caSApple OSS Distributions IOService::resourceMatching("IONVRAM"), &t );
88*c54f35caSApple OSS Distributions #endif
89*c54f35caSApple OSS Distributions
90*c54f35caSApple OSS Distributions clock_initialize_calendar();
91*c54f35caSApple OSS Distributions }
92*c54f35caSApple OSS Distributions
93*c54f35caSApple OSS Distributions void
iokit_post_constructor_init(void)94*c54f35caSApple OSS Distributions iokit_post_constructor_init(void)
95*c54f35caSApple OSS Distributions {
96*c54f35caSApple OSS Distributions IORegistryEntry * root;
97*c54f35caSApple OSS Distributions OSObject * obj;
98*c54f35caSApple OSS Distributions
99*c54f35caSApple OSS Distributions IOCPUInitialize();
100*c54f35caSApple OSS Distributions IOPlatformActionsInitialize();
101*c54f35caSApple OSS Distributions root = IORegistryEntry::initialize();
102*c54f35caSApple OSS Distributions assert( root );
103*c54f35caSApple OSS Distributions IOService::initialize();
104*c54f35caSApple OSS Distributions IOCatalogue::initialize();
105*c54f35caSApple OSS Distributions IOStatistics::initialize();
106*c54f35caSApple OSS Distributions OSKext::initialize();
107*c54f35caSApple OSS Distributions IOUserClient::initialize();
108*c54f35caSApple OSS Distributions IOMemoryDescriptor::initialize();
109*c54f35caSApple OSS Distributions IORootParent::initialize();
110*c54f35caSApple OSS Distributions IOReporter::initialize();
111*c54f35caSApple OSS Distributions
112*c54f35caSApple OSS Distributions // Initializes IOPMinformeeList class-wide shared lock
113*c54f35caSApple OSS Distributions IOPMinformeeList::getSharedRecursiveLock();
114*c54f35caSApple OSS Distributions
115*c54f35caSApple OSS Distributions obj = OSString::withCString( version );
116*c54f35caSApple OSS Distributions assert( obj );
117*c54f35caSApple OSS Distributions if (obj) {
118*c54f35caSApple OSS Distributions root->setProperty( kIOKitBuildVersionKey, obj );
119*c54f35caSApple OSS Distributions obj->release();
120*c54f35caSApple OSS Distributions }
121*c54f35caSApple OSS Distributions obj = IOKitDiagnostics::diagnostics();
122*c54f35caSApple OSS Distributions if (obj) {
123*c54f35caSApple OSS Distributions root->setProperty( kIOKitDiagnosticsKey, obj );
124*c54f35caSApple OSS Distributions obj->release();
125*c54f35caSApple OSS Distributions }
126*c54f35caSApple OSS Distributions }
127*c54f35caSApple OSS Distributions
128*c54f35caSApple OSS Distributions /*****
129*c54f35caSApple OSS Distributions * Pointer into bootstrap KLD segment for functions never used past startup.
130*c54f35caSApple OSS Distributions */
131*c54f35caSApple OSS Distributions void (*record_startup_extensions_function)(void) = NULL;
132*c54f35caSApple OSS Distributions
133*c54f35caSApple OSS Distributions void
InitIOKit(void * dtTop)134*c54f35caSApple OSS Distributions InitIOKit(void *dtTop)
135*c54f35caSApple OSS Distributions {
136*c54f35caSApple OSS Distributions // Compat for boot-args
137*c54f35caSApple OSS Distributions gIOKitTrace |= (gIOKitDebug & kIOTraceCompatBootArgs);
138*c54f35caSApple OSS Distributions
139*c54f35caSApple OSS Distributions //
140*c54f35caSApple OSS Distributions // Have to start IOKit environment before we attempt to start
141*c54f35caSApple OSS Distributions // the C++ runtime environment. At some stage we have to clean up
142*c54f35caSApple OSS Distributions // the initialisation path so that OS C++ can initialise independantly
143*c54f35caSApple OSS Distributions // of iokit basic service initialisation, or better we have IOLib stuff
144*c54f35caSApple OSS Distributions // initialise as basic OS services.
145*c54f35caSApple OSS Distributions //
146*c54f35caSApple OSS Distributions IOLibInit();
147*c54f35caSApple OSS Distributions OSlibkernInit();
148*c54f35caSApple OSS Distributions IOMachPortInitialize();
149*c54f35caSApple OSS Distributions
150*c54f35caSApple OSS Distributions gIOProgressBackbufferKey = OSSymbol::withCStringNoCopy(kIOProgressBackbufferKey);
151*c54f35caSApple OSS Distributions gIORemoveOnReadProperties = OSSet::withObjects((const OSObject **) &gIOProgressBackbufferKey, 1);
152*c54f35caSApple OSS Distributions
153*c54f35caSApple OSS Distributions interruptAccountingInit();
154*c54f35caSApple OSS Distributions
155*c54f35caSApple OSS Distributions gRootNub = new IOPlatformExpertDevice;
156*c54f35caSApple OSS Distributions if (__improbable(gRootNub == NULL)) {
157*c54f35caSApple OSS Distributions panic("Failed to allocate IOKit root nub");
158*c54f35caSApple OSS Distributions }
159*c54f35caSApple OSS Distributions bool ok = gRootNub->init(dtTop);
160*c54f35caSApple OSS Distributions if (__improbable(!ok)) {
161*c54f35caSApple OSS Distributions panic("Failed to initialize IOKit root nub");
162*c54f35caSApple OSS Distributions }
163*c54f35caSApple OSS Distributions gRootNub->attach(NULL);
164*c54f35caSApple OSS Distributions
165*c54f35caSApple OSS Distributions /* If the bootstrap segment set up a function to record startup
166*c54f35caSApple OSS Distributions * extensions, call it now.
167*c54f35caSApple OSS Distributions */
168*c54f35caSApple OSS Distributions if (record_startup_extensions_function) {
169*c54f35caSApple OSS Distributions record_startup_extensions_function();
170*c54f35caSApple OSS Distributions }
171*c54f35caSApple OSS Distributions }
172*c54f35caSApple OSS Distributions
173*c54f35caSApple OSS Distributions void
ConfigureIOKit(void)174*c54f35caSApple OSS Distributions ConfigureIOKit(void)
175*c54f35caSApple OSS Distributions {
176*c54f35caSApple OSS Distributions assert(gRootNub != NULL);
177*c54f35caSApple OSS Distributions gRootNub->configureDefaults();
178*c54f35caSApple OSS Distributions }
179*c54f35caSApple OSS Distributions
180*c54f35caSApple OSS Distributions void
StartIOKitMatching(void)181*c54f35caSApple OSS Distributions StartIOKitMatching(void)
182*c54f35caSApple OSS Distributions {
183*c54f35caSApple OSS Distributions SOCD_TRACE_XNU(START_IOKIT);
184*c54f35caSApple OSS Distributions assert(gRootNub != NULL);
185*c54f35caSApple OSS Distributions bool ok = gRootNub->startIOServiceMatching();
186*c54f35caSApple OSS Distributions if (__improbable(!ok)) {
187*c54f35caSApple OSS Distributions panic("Failed to start IOService matching");
188*c54f35caSApple OSS Distributions }
189*c54f35caSApple OSS Distributions
190*c54f35caSApple OSS Distributions #if !NO_KEXTD
191*c54f35caSApple OSS Distributions if (OSKext::iokitDaemonAvailable()) {
192*c54f35caSApple OSS Distributions /* Add a busy count to keep the registry busy until the IOKit daemon has
193*c54f35caSApple OSS Distributions * completely finished launching. This is decremented when the IOKit daemon
194*c54f35caSApple OSS Distributions * messages the kernel after the in-kernel linker has been
195*c54f35caSApple OSS Distributions * removed and personalities have been sent.
196*c54f35caSApple OSS Distributions */
197*c54f35caSApple OSS Distributions IOService::getServiceRoot()->adjustBusy(1);
198*c54f35caSApple OSS Distributions }
199*c54f35caSApple OSS Distributions #endif
200*c54f35caSApple OSS Distributions }
201*c54f35caSApple OSS Distributions
202*c54f35caSApple OSS Distributions void
IORegistrySetOSBuildVersion(char * build_version)203*c54f35caSApple OSS Distributions IORegistrySetOSBuildVersion(char * build_version)
204*c54f35caSApple OSS Distributions {
205*c54f35caSApple OSS Distributions IORegistryEntry * root = IORegistryEntry::getRegistryRoot();
206*c54f35caSApple OSS Distributions
207*c54f35caSApple OSS Distributions if (root) {
208*c54f35caSApple OSS Distributions if (build_version) {
209*c54f35caSApple OSS Distributions root->setProperty(kOSBuildVersionKey, build_version);
210*c54f35caSApple OSS Distributions } else {
211*c54f35caSApple OSS Distributions root->removeProperty(kOSBuildVersionKey);
212*c54f35caSApple OSS Distributions }
213*c54f35caSApple OSS Distributions }
214*c54f35caSApple OSS Distributions
215*c54f35caSApple OSS Distributions return;
216*c54f35caSApple OSS Distributions }
217*c54f35caSApple OSS Distributions
218*c54f35caSApple OSS Distributions void
IORecordProgressBackbuffer(void * buffer,size_t size,uint32_t theme)219*c54f35caSApple OSS Distributions IORecordProgressBackbuffer(void * buffer, size_t size, uint32_t theme)
220*c54f35caSApple OSS Distributions {
221*c54f35caSApple OSS Distributions IORegistryEntry * chosen;
222*c54f35caSApple OSS Distributions
223*c54f35caSApple OSS Distributions if (((unsigned int) size) != size) {
224*c54f35caSApple OSS Distributions return;
225*c54f35caSApple OSS Distributions }
226*c54f35caSApple OSS Distributions if ((chosen = IORegistryEntry::fromPath(kIODeviceTreePlane ":/chosen"))) {
227*c54f35caSApple OSS Distributions chosen->setProperty(kIOProgressBackbufferKey, buffer, (unsigned int) size);
228*c54f35caSApple OSS Distributions chosen->setProperty(kIOProgressColorThemeKey, theme, 32);
229*c54f35caSApple OSS Distributions
230*c54f35caSApple OSS Distributions chosen->release();
231*c54f35caSApple OSS Distributions }
232*c54f35caSApple OSS Distributions }
233*c54f35caSApple OSS Distributions }; /* extern "C" */
234