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