]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOStartIOKit.cpp
xnu-7195.101.1.tar.gz
[apple/xnu.git] / iokit / Kernel / IOStartIOKit.cpp
CommitLineData
1c79356b 1/*
6d2010ae 2 * Copyright (c) 1998-2010 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 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.
0a7de745 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.
0a7de745 17 *
2d21ac55
A
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.
0a7de745 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>
f427ee49 31#include <libkern/section_keywords.h>
91447636 32#include <libkern/version.h>
1c79356b
A
33#include <IOKit/IORegistryEntry.h>
34#include <IOKit/IODeviceTreeSupport.h>
35#include <IOKit/IOCatalogue.h>
36#include <IOKit/IOUserClient.h>
37#include <IOKit/IOMemoryDescriptor.h>
38#include <IOKit/IOPlatformExpert.h>
f427ee49 39#include <IOKit/IOKernelReporters.h>
1c79356b
A
40#include <IOKit/IOLib.h>
41#include <IOKit/IOKitKeys.h>
42#include <IOKit/IOKitDebug.h>
6d2010ae 43#include <IOKit/pwr_mgt/RootDomain.h>
0c530ab8 44#include <IOKit/pwr_mgt/IOPMinformeeList.h>
6d2010ae
A
45#include <IOKit/IOStatisticsPrivate.h>
46#include <IOKit/IOKitKeysPrivate.h>
fe8ab488 47#include <IOKit/IOInterruptAccountingPrivate.h>
1c79356b 48#include <IOKit/assert.h>
39037602 49#include <sys/conf.h>
1c79356b 50
91447636
A
51#include "IOKitKernelInternal.h"
52
fe8ab488
A
53const OSSymbol * gIOProgressBackbufferKey;
54OSSet * gIORemoveOnReadProperties;
55
1c79356b 56extern "C" {
f427ee49
A
57void InitIOKit(void *dtTop);
58void ConfigureIOKit(void);
59void StartIOKitMatching(void);
39037602
A
60void IORegistrySetOSBuildVersion(char * build_version);
61void IORecordProgressBackbuffer(void * buffer, size_t size, uint32_t theme);
62
0a7de745 63extern void OSlibkernInit(void);
1c79356b 64
39236c6e 65void iokit_post_constructor_init(void);
b0d623f7 66
f427ee49
A
67SECURITY_READ_ONLY_LATE(static IOPlatformExpertDevice*) gRootNub;
68
1c79356b 69#include <kern/clock.h>
2d21ac55 70#include <sys/time.h>
1c79356b 71
0a7de745
A
72void
73IOKitInitializeTime( void )
1c79356b 74{
0a7de745 75 mach_timespec_t t;
1c79356b 76
55e303ae
A
77 t.tv_sec = 30;
78 t.tv_nsec = 0;
cb323159
A
79
80// RTC is not present on this target
81#ifndef BCM2837
55e303ae
A
82 IOService::waitForService(
83 IOService::resourceMatching("IORTC"), &t );
cb323159 84#endif
6d2010ae 85#if defined(__i386__) || defined(__x86_64__)
55e303ae
A
86 IOService::waitForService(
87 IOService::resourceMatching("IONVRAM"), &t );
1c79356b
A
88#endif
89
5ba3f43e 90 clock_initialize_calendar();
1c79356b
A
91}
92
0a7de745
A
93void
94iokit_post_constructor_init(void)
1c79356b 95{
0a7de745
A
96 IORegistryEntry * root;
97 OSObject * obj;
98
99 IOCPUInitialize();
f427ee49 100 IOPlatformActionsInitialize();
0a7de745
A
101 root = IORegistryEntry::initialize();
102 assert( root );
103 IOService::initialize();
104 IOCatalogue::initialize();
105 IOStatistics::initialize();
106 OSKext::initialize();
107 IOUserClient::initialize();
108 IOMemoryDescriptor::initialize();
109 IORootParent::initialize();
f427ee49 110 IOReporter::initialize();
0a7de745
A
111
112 // Initializes IOPMinformeeList class-wide shared lock
113 IOPMinformeeList::getSharedRecursiveLock();
114
115 obj = OSString::withCString( version );
116 assert( obj );
117 if (obj) {
118 root->setProperty( kIOKitBuildVersionKey, obj );
119 obj->release();
120 }
121 obj = IOKitDiagnostics::diagnostics();
122 if (obj) {
123 root->setProperty( kIOKitDiagnosticsKey, obj );
124 obj->release();
125 }
b0d623f7
A
126}
127
b0d623f7
A
128/*****
129 * Pointer into bootstrap KLD segment for functions never used past startup.
130 */
cb323159 131void (*record_startup_extensions_function)(void) = NULL;
b0d623f7 132
0a7de745 133void
f427ee49 134InitIOKit(void *dtTop)
b0d623f7 135{
f427ee49 136 int debugFlags = 0;
b0d623f7 137
0a7de745
A
138 if (PE_parse_boot_argn( "io", &debugFlags, sizeof(debugFlags))) {
139 gIOKitDebug = debugFlags;
140 }
f427ee49
A
141 // Enable IOWaitQuiet panics on arm64 macOS except on KASAN.
142 // existing 3rd party KEXTs may hold the registry busy on x86 RELEASE kernels.
143 // Enabling this on other platforms is tracked in rdar://66364108
144#if XNU_TARGET_OS_OSX && defined(__arm64__) && !KASAN
0a7de745
A
145 else {
146 gIOKitDebug |= kIOWaitQuietPanics;
147 }
f427ee49 148#endif
0a7de745
A
149
150 if (PE_parse_boot_argn( "iotrace", &debugFlags, sizeof(debugFlags))) {
151 gIOKitTrace = debugFlags;
152 }
153
154 // Compat for boot-args
155 gIOKitTrace |= (gIOKitDebug & kIOTraceCompatBootArgs);
156
157 if (PE_parse_boot_argn( "pmtimeout", &debugFlags, sizeof(debugFlags))) {
158 gCanSleepTimeout = debugFlags;
159 }
cb323159
A
160
161 if (PE_parse_boot_argn( "dk", &debugFlags, sizeof(debugFlags))) {
162 gIODKDebug = debugFlags;
163 }
164
165
0a7de745
A
166 //
167 // Have to start IOKit environment before we attempt to start
168 // the C++ runtime environment. At some stage we have to clean up
169 // the initialisation path so that OS C++ can initialise independantly
170 // of iokit basic service initialisation, or better we have IOLib stuff
171 // initialise as basic OS services.
172 //
173 IOLibInit();
174 OSlibkernInit();
cb323159 175 IOMachPortInitialize();
0a7de745
A
176
177 gIOProgressBackbufferKey = OSSymbol::withCStringNoCopy(kIOProgressBackbufferKey);
178 gIORemoveOnReadProperties = OSSet::withObjects((const OSObject **) &gIOProgressBackbufferKey, 1);
179
180 interruptAccountingInit();
181
f427ee49
A
182 gRootNub = new IOPlatformExpertDevice;
183 if (__improbable(gRootNub == NULL)) {
184 panic("Failed to allocate IOKit root nub");
185 }
186 bool ok = gRootNub->init(dtTop);
187 if (__improbable(!ok)) {
188 panic("Failed to initialize IOKit root nub");
189 }
190 gRootNub->attach(NULL);
0a7de745 191
f427ee49
A
192 /* If the bootstrap segment set up a function to record startup
193 * extensions, call it now.
194 */
195 if (record_startup_extensions_function) {
196 record_startup_extensions_function();
197 }
198}
0a7de745 199
f427ee49
A
200void
201ConfigureIOKit(void)
202{
203 assert(gRootNub != NULL);
204 gRootNub->configureDefaults();
205}
0a7de745 206
f427ee49
A
207void
208StartIOKitMatching(void)
209{
210 assert(gRootNub != NULL);
211 bool ok = gRootNub->startIOServiceMatching();
212 if (__improbable(!ok)) {
213 panic("Failed to start IOService matching");
214 }
2d21ac55
A
215
216#if !NO_KEXTD
f427ee49
A
217 /* Add a busy count to keep the registry busy until kextd has
218 * completely finished launching. This is decremented when kextd
219 * messages the kernel after the in-kernel linker has been
220 * removed and personalities have been sent.
221 */
222 IOService::getServiceRoot()->adjustBusy(1);
2d21ac55 223#endif
1c79356b
A
224}
225
2d21ac55
A
226void
227IORegistrySetOSBuildVersion(char * build_version)
228{
0a7de745 229 IORegistryEntry * root = IORegistryEntry::getRegistryRoot();
2d21ac55 230
0a7de745
A
231 if (root) {
232 if (build_version) {
233 root->setProperty(kOSBuildVersionKey, build_version);
234 } else {
235 root->removeProperty(kOSBuildVersionKey);
236 }
237 }
2d21ac55 238
0a7de745 239 return;
2d21ac55
A
240}
241
fe8ab488
A
242void
243IORecordProgressBackbuffer(void * buffer, size_t size, uint32_t theme)
244{
0a7de745 245 IORegistryEntry * chosen;
f427ee49
A
246
247 if (((unsigned int) size) != size) {
248 return;
249 }
0a7de745 250 if ((chosen = IORegistryEntry::fromPath(kIODeviceTreePlane ":/chosen"))) {
f427ee49 251 chosen->setProperty(kIOProgressBackbufferKey, buffer, (unsigned int) size);
0a7de745 252 chosen->setProperty(kIOProgressColorThemeKey, theme, 32);
fe8ab488 253
0a7de745
A
254 chosen->release();
255 }
256}
1c79356b 257}; /* extern "C" */