- all->removeObject(service);
- }
- all->release();
- }
- }
-
- iocpu_run_platform_actions(&gActionQueues[kQueueSleep], 0, 0U-1,
- NULL, NULL, NULL, TRUE);
-
- rootDomain->tracePoint( kIOPMTracePointSleepCPUs );
-
- numCPUs = gIOCPUs->getCount();
- // Sleep the CPUs.
- cnt = numCPUs;
- while (cnt--)
- {
- target = OSDynamicCast(IOCPU, gIOCPUs->getObject(cnt));
-
- // We make certain that the bootCPU is the last to sleep
- // We'll skip it for now, and halt it after finishing the
- // non-boot CPU's.
- if (target->getCPUNumber() == (UInt32)master_cpu)
- {
- bootCPU = target;
- } else if (target->getCPUState() == kIOCPUStateRunning)
- {
- target->haltCPU();
- }
- }
-
- assert(bootCPU != NULL);
- assert(cpu_number() == master_cpu);
-
- console_suspend();
-
- rootDomain->tracePoint( kIOPMTracePointSleepPlatformDriver );
-
- // Now sleep the boot CPU.
- bootCPU->haltCPU();
-
- rootDomain->tracePoint( kIOPMTracePointWakePlatformActions );
-
- console_resume();
-
- iocpu_run_platform_actions(&gActionQueues[kQueueWake], 0, 0U-1,
- NULL, NULL, NULL, TRUE);
-
- iocpu_platform_action_entry_t * entry;
- for (uint32_t qidx = kQueueSleep; qidx <= kQueueActive; qidx++)
- {
- while (!(queue_empty(&gActionQueues[qidx])))
- {
- entry = (typeof(entry)) queue_first(&gActionQueues[qidx]);
- iocpu_remove_platform_action(entry);
- IODelete(entry, iocpu_platform_action_entry_t, 1);
- }
- }
-
- rootDomain->tracePoint( kIOPMTracePointWakeCPUs );
-
- // Wake the other CPUs.
- for (cnt = 0; cnt < numCPUs; cnt++)
- {
- target = OSDynamicCast(IOCPU, gIOCPUs->getObject(cnt));
-
- // Skip the already-woken boot CPU.
- if (target->getCPUNumber() != (UInt32)master_cpu) {
- if (target->getCPUState() == kIOCPUStateRunning)
- panic("Spurious wakeup of cpu %u", (unsigned int)(target->getCPUNumber()));
-
- if (target->getCPUState() == kIOCPUStateStopped)
- processor_start(target->getMachProcessor());
- }
- }
-}
-
-bool IOCPU::start(IOService *provider)
-{
- OSData *busFrequency, *cpuFrequency, *timebaseFrequency;
-
- if (!super::start(provider)) return false;
-
- _cpuGroup = gIOCPUs;
- cpuNub = provider;
-
- IOLockLock(gIOCPUsLock);
- gIOCPUs->setObject(this);
- IOLockUnlock(gIOCPUsLock);
-
- // Correct the bus, cpu and timebase frequencies in the device tree.
- if (gPEClockFrequencyInfo.bus_frequency_hz < 0x100000000ULL) {
- busFrequency = OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo.bus_clock_rate_hz, 4);
- } else {
- busFrequency = OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo.bus_frequency_hz, 8);
- }
- provider->setProperty("bus-frequency", busFrequency);
- busFrequency->release();
-
- if (gPEClockFrequencyInfo.cpu_frequency_hz < 0x100000000ULL) {
- cpuFrequency = OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo.cpu_clock_rate_hz, 4);
- } else {
- cpuFrequency = OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo.cpu_frequency_hz, 8);
- }
- provider->setProperty("clock-frequency", cpuFrequency);
- cpuFrequency->release();
-
- timebaseFrequency = OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo.timebase_frequency_hz, 4);
- provider->setProperty("timebase-frequency", timebaseFrequency);
- timebaseFrequency->release();
-
- super::setProperty("IOCPUID", getRegistryEntryID(), sizeof(uint64_t)*8);
-
- setCPUNumber(0);
- setCPUState(kIOCPUStateUnregistered);
-
- return true;
-}
-
-OSObject *IOCPU::getProperty(const OSSymbol *aKey) const
-{
- if (aKey == gIOCPUStateKey) return gIOCPUStateNames[_cpuState];
-
- return super::getProperty(aKey);
-}
-
-bool IOCPU::setProperty(const OSSymbol *aKey, OSObject *anObject)
-{
- if (aKey == gIOCPUStateKey) {
- return false;
- }
-
- return super::setProperty(aKey, anObject);
-}
-
-bool IOCPU::serializeProperties(OSSerialize *serialize) const
+ }
+
+ rootDomain->tracePoint( kIOPMTracePointWakeCPUs );
+
+ // Wake the other CPUs.
+ for (cnt = 0; cnt < numCPUs; cnt++) {
+ target = OSDynamicCast(IOCPU, gIOCPUs->getObject(cnt));
+
+ // Skip the already-woken boot CPU.
+ if (target->getCPUNumber() != (UInt32)master_cpu) {
+ if (target->getCPUState() == kIOCPUStateRunning) {
+ panic("Spurious wakeup of cpu %u", (unsigned int)(target->getCPUNumber()));
+ }
+
+ if (target->getCPUState() == kIOCPUStateStopped) {
+ processor_start(target->getMachProcessor());
+ }
+ }
+ }
+
+#if defined(__arm64__)
+ sched_restore_recommended_cores_after_sleep();
+#endif
+
+ thread_kern_set_pri(self, old_pri);
+}
+
+bool
+IOCPU::start(IOService *provider)
+{
+ OSData *busFrequency, *cpuFrequency, *timebaseFrequency;
+
+ if (!super::start(provider)) {
+ return false;
+ }
+
+ _cpuGroup = gIOCPUs;
+ cpuNub = provider;
+
+ IOLockLock(gIOCPUsLock);
+ gIOCPUs->setObject(this);
+ IOLockUnlock(gIOCPUsLock);
+
+ // Correct the bus, cpu and timebase frequencies in the device tree.
+ if (gPEClockFrequencyInfo.bus_frequency_hz < 0x100000000ULL) {
+ busFrequency = OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo.bus_clock_rate_hz, 4);
+ } else {
+ busFrequency = OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo.bus_frequency_hz, 8);
+ }
+ provider->setProperty("bus-frequency", busFrequency);
+ busFrequency->release();
+
+ if (gPEClockFrequencyInfo.cpu_frequency_hz < 0x100000000ULL) {
+ cpuFrequency = OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo.cpu_clock_rate_hz, 4);
+ } else {
+ cpuFrequency = OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo.cpu_frequency_hz, 8);
+ }
+ provider->setProperty("clock-frequency", cpuFrequency);
+ cpuFrequency->release();
+
+ timebaseFrequency = OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo.timebase_frequency_hz, 4);
+ provider->setProperty("timebase-frequency", timebaseFrequency);
+ timebaseFrequency->release();
+
+ super::setProperty("IOCPUID", getRegistryEntryID(), sizeof(uint64_t) * 8);
+
+ setCPUNumber(0);
+ setCPUState(kIOCPUStateUnregistered);
+
+ return true;
+}
+
+void
+IOCPU::detach(IOService *provider)
+{
+ super::detach(provider);
+ IOLockLock(gIOCPUsLock);
+ unsigned int index = gIOCPUs->getNextIndexOfObject(this, 0);
+ if (index != (unsigned int)-1) {
+ gIOCPUs->removeObject(index);
+ }
+ IOLockUnlock(gIOCPUsLock);
+}
+
+OSObject *
+IOCPU::getProperty(const OSSymbol *aKey) const
+{
+ if (aKey == gIOCPUStateKey) {
+ return gIOCPUStateNames[_cpuState];
+ }
+
+ return super::getProperty(aKey);
+}
+
+bool
+IOCPU::setProperty(const OSSymbol *aKey, OSObject *anObject)
+{
+ if (aKey == gIOCPUStateKey) {
+ return false;
+ }
+
+ return super::setProperty(aKey, anObject);
+}
+
+bool
+IOCPU::serializeProperties(OSSerialize *serialize) const