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