- iter = IORegistryIterator::iterateOver( gIOServicePlane,
- kIORegistryIterateRecursively );
- if( iter)
- {
- do
- {
- iter->reset();
- while((service = (IOService *) iter->getNextObject()))
- {
- IOInstallServicePlatformAction(service, gIOPlatformSleepActionKey, &gIOSleepActionQueue, false);
- IOInstallServicePlatformAction(service, gIOPlatformWakeActionKey, &gIOWakeActionQueue, true);
- IOInstallServicePlatformAction(service, gIOPlatformQuiesceActionKey, iocpu_get_platform_quiesce_queue(), false);
- IOInstallServicePlatformAction(service, gIOPlatformActiveActionKey, iocpu_get_platform_active_queue(), true);
- }
- }
- while( !service && !iter->isValid());
- iter->release();
- }
-
- iocpu_run_platform_actions(&gIOSleepActionQueue, 0, 0U-1,
- NULL, NULL, NULL);
-
- 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() == kBootCPUNumber)
- {
- bootCPU = target;
- } else if (target->getCPUState() == kIOCPUStateRunning)
- {
- target->haltCPU();
- }
- }
-
- rootDomain->tracePoint( kIOPMTracePointSleepPlatformDriver );
-
- // Now sleep the boot CPU.
- if (bootCPU)
- bootCPU->haltCPU();
-
- rootDomain->tracePoint( kIOPMTracePointWakePlatformActions );
-
- iocpu_run_platform_actions(&gIOWakeActionQueue, 0, 0U-1,
- NULL, NULL, NULL);
-
- iocpu_platform_action_entry_t * entry;
- while ((entry = gIOAllActionsQueue))
- {
- gIOAllActionsQueue = entry->alloc_list;
- iocpu_remove_platform_action(entry);
- IODelete(entry, iocpu_platform_action_entry_t, 1);
- }
-
- if (!queue_empty(&gIOSleepActionQueue))
- panic("gIOSleepActionQueue");
- if (!queue_empty(&gIOWakeActionQueue))
- panic("gIOWakeActionQueue");
-
- 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() != kBootCPUNumber)
- && (target->getCPUState() == kIOCPUStateStopped))
- {
- processor_start(target->getMachProcessor());
- }
- }
-}
-
-void IOCPU::initCPUs(void)
-{
- if (gIOCPUs == 0) {
- gIOCPUs = OSArray::withCapacity(1);
-
- gIOCPUStateKey = OSSymbol::withCStringNoCopy("IOCPUState");
-
- gIOCPUStateNames[kIOCPUStateUnregistered] =
- OSString::withCStringNoCopy("Unregistered");
- gIOCPUStateNames[kIOCPUStateUninitalized] =
- OSString::withCStringNoCopy("Uninitalized");
- gIOCPUStateNames[kIOCPUStateStopped] =
- OSString::withCStringNoCopy("Stopped");
- gIOCPUStateNames[kIOCPUStateRunning] =
- OSString::withCStringNoCopy("Running");
- }
-}
-
-bool IOCPU::start(IOService *provider)
-{
- OSData *busFrequency, *cpuFrequency, *timebaseFrequency;
-
- if (!super::start(provider)) return false;
-
- initCPUs();
-
- _cpuGroup = gIOCPUs;
- cpuNub = provider;
-
- gIOCPUs->setObject(this);
-
- // 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", (uintptr_t)this, sizeof(uintptr_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)
-{
- OSString *stateStr;
-
- if (aKey == gIOCPUStateKey) {
- stateStr = OSDynamicCast(OSString, anObject);
- if (stateStr == 0) return false;
-
- if (_cpuNumber == 0) return false;
-
- if (stateStr->isEqualTo("running")) {
- if (_cpuState == kIOCPUStateStopped) {
- processor_start(machProcessor);
- } else if (_cpuState != kIOCPUStateRunning) {
- return false;
- }
- } else if (stateStr->isEqualTo("stopped")) {
- if (_cpuState == kIOCPUStateRunning) {
- haltCPU();
- } else if (_cpuState != kIOCPUStateStopped) {
- return false;
- }
- } else return false;
-
- return true;
- }
-
- return super::setProperty(aKey, anObject);
-}
-
-bool IOCPU::serializeProperties(OSSerialize *serialize) const
+ 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