void FakeSMCDevice::saveKeyToNVRAM(FakeSMCKey *key) { if (!useNVRAM) return; KEYSLOCK; #if NVRAMKEYS_EXCEPTION if (!exceptionKeys || exceptionKeys->getObject(key->getKey())) { KEYSUNLOCK; return; } #endif if (IORegistryEntry *nvram = OSDynamicCast(IORegistryEntry, fromPath("/options", gIODTPlane))) { char name[32]; snprintf(name, 32, "%s-%s-%s", kFakeSMCKeyPropertyPrefix, key->getKey(), key->getType()); const OSSymbol *tempName = OSSymbol::withCString(name); if (genericNVRAM) nvram->IORegistryEntry::setProperty(tempName, OSData::withBytes(key->getValue(), key->getSize())); else nvram->setProperty(tempName, OSData::withBytes(key->getValue(), key->getSize())); OSSafeRelease(tempName); OSSafeRelease(nvram); } KEYSUNLOCK; }
void icarus::routes::compiler::compile(std::string from, std::ostream &to) { boost::filesystem::path fromPath(from); parser parser(fromPath.parent_path().string()); document document(fromPath.stem().string()); parser.parse(from, document); routes_writer writer; std::stringstream memoryStream; writer.write(memoryStream, document); to << memoryStream.rdbuf(); }
bool FakeSMCKeyStore::start(IOService *provider) { if (!super::start(provider)) return false; // Try to obtain OEM info from Clover EFI if (IORegistryEntry* platformNode = fromPath("/efi/platform", gIODTPlane)) { if (OSData *data = OSDynamicCast(OSData, platformNode->getProperty("OEMVendor"))) { if (OSString *vendor = OSString::withCString((char*)data->getBytesNoCopy())) { if (OSString *manufacturer = getManufacturerNameFromOEMName(vendor)) { this->setProperty(kOEMInfoManufacturer, manufacturer); OSSafeReleaseNULL(manufacturer); } //OSSafeReleaseNULL(vendor); } //OSSafeReleaseNULL(data); } if (OSData *data = OSDynamicCast(OSData, platformNode->getProperty("OEMBoard"))) { if (OSString *product = OSString::withCString((char*)data->getBytesNoCopy())) { this->setProperty(kOEMInfoProduct, product); //OSSafeReleaseNULL(product); } //OSSafeReleaseNULL(data); } } if ((!getProperty(kOEMInfoProduct) || !getProperty(kOEMInfoManufacturer)) && !setOemProperties(this)) { HWSensorsErrorLog("failed to get OEM info from Chameleon/Chimera or Clover EFI, platform profiles will be unavailable"); } if (OSString *manufacturer = OSDynamicCast(OSString, getProperty(kOEMInfoManufacturer)) ) { this->addKeyWithValue("HWS0", TYPE_CH8, manufacturer->getLength(), manufacturer->getCStringNoCopy()); } if (OSString *product = OSDynamicCast(OSString, getProperty(kOEMInfoProduct)) ) { this->addKeyWithValue("HWS1", TYPE_CH8, product->getLength(), product->getCStringNoCopy()); } IOService::publishResource(kFakeSMCKeyStoreService, this); registerService(); HWSensorsInfoLog("started"); return true; }
bool FileSystemManager::copyFileByName(QString oldPath, QString destDir, QString newFileName, bool confirm, bool silent, bool allowUndo) { SHFILEOPSTRUCT fileOperation = { 0 }; QString fromPath(oldPath), toPath(destDir); toPath = native(destDir / newFileName); TCHAR oldp[MAX_PATH] = {0}; TCHAR newp[MAX_PATH] = {0}; lstrcpy(oldp, (LPCTSTR) fromPath.utf16()); lstrcpy(newp, (LPCTSTR) toPath.utf16()); fileOperation.hwnd = winOS->GetWindowsHandle(); fileOperation.wFunc = FO_COPY; fileOperation.pFrom = (LPCTSTR) oldp; fileOperation.pTo = (LPCTSTR) newp; fileOperation.fFlags = FOF_RENAMEONCOLLISION | (allowUndo ? FOF_ALLOWUNDO : NULL) | (confirm ? NULL : FOF_NOCONFIRMATION) | (silent ? FOF_SILENT : NULL); // do the windows file operations for copy return (SHFileOperation(&fileOperation) == 0) && !fileOperation.fAnyOperationsAborted; }
void FakeSMCKeyStore::saveKeyToNVRAM(FakeSMCKey *key) { if (!useNVRAM) return; if (IORegistryEntry *nvram = OSDynamicCast(IORegistryEntry, fromPath("/options", gIODTPlane))) { char name[32]; snprintf(name, 32, "%s-%s-%s", kFakeSMCKeyPropertyPrefix, key->getKey(), key->getType()); const OSSymbol *tempName = OSSymbol::withCString(name); if (genericNVRAM) nvram->IORegistryEntry::setProperty(tempName, OSData::withBytes(key->getValue(), key->getSize())); else nvram->setProperty(tempName, OSData::withBytes(key->getValue(), key->getSize())); OSSafeRelease(tempName); OSSafeRelease(nvram); } }
void ACPIBacklightPanel::saveACPIBrightnessLevelNVRAM(UInt32 level1) { //DbgLog("%s::%s(): level=%d\n", this->getName(),__FUNCTION__, level1); UInt16 level = (UInt16)level1; if (IORegistryEntry *nvram = OSDynamicCast(IORegistryEntry, fromPath("/options", gIODTPlane))) { if (const OSSymbol* symbol = OSSymbol::withCString(kACPIBacklightLevel)) { if (OSData* number = OSData::withBytes(&level, sizeof(level))) { //DbgLog("%s: saveACPIBrightnessLevelNVRAM got nvram %p\n", this->getName(), nvram); if (!nvram->setProperty(symbol, number)) { DbgLog("%s: nvram->setProperty failed\n", this->getName()); } number->release(); } symbol->release(); } nvram->release(); } }
bool IT87x::start(IOService * provider) { DebugLog("starting ..."); if (!super::start(provider)) return false; InfoLog("found ITE %s", getModelName()); OSDictionary* list = OSDynamicCast(OSDictionary, getProperty("Sensors Configuration")); OSDictionary *configuration=NULL; OSData *data; IORegistryEntry * rootNode = fromPath("/efi/platform", gIODTPlane); if(rootNode) { data = OSDynamicCast(OSData, rootNode->getProperty("OEMVendor")); if (data) { bcopy(data->getBytesNoCopy(), vendor, data->getLength()); OSString * VendorNick = vendorID(OSString::withCString(vendor)); if (VendorNick) { data = OSDynamicCast(OSData, rootNode->getProperty("OEMBoard")); if (!data) { WarningLog("no OEMBoard"); data = OSDynamicCast(OSData, rootNode->getProperty("OEMProduct")); } if (data) { bcopy(data->getBytesNoCopy(), product, data->getLength()); OSDictionary *link = OSDynamicCast(OSDictionary, list->getObject(VendorNick)); if (link){ configuration = OSDynamicCast(OSDictionary, link->getObject(OSString::withCString(product))); InfoLog(" mother vendor=%s product=%s", vendor, product); } } } else { WarningLog("unknown OEMVendor %s", vendor); } } else { WarningLog("no OEMVendor"); } } if (list && !configuration) { configuration = OSDynamicCast(OSDictionary, list->getObject("Default")); WarningLog("set default configuration"); } if(configuration) { this->setProperty("Current Configuration", configuration); } // Temperature Sensors if (configuration) { for (int i = 0; i < 3; i++) { char key[8]; snprintf(key, 8, "TEMPIN%X", i); if(readTemperature(i)<MAX_TEMP_THRESHOLD) { // Need to check if temperature sensor valid if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key))) { if (name->isEqualTo("CPU")) { if (!addSensor(KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, i)) { WarningLog("error adding heatsink temperature sensor"); } } else if (name->isEqualTo("System")) { if (!addSensor(KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor,i)) { WarningLog("error adding system temperature sensor"); } } else if (name->isEqualTo("Ambient")) { if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor,i)) { WarningLog("error adding Ambient temperature sensor"); } } } } } } else { if(readTemperature(0)<MAX_TEMP_THRESHOLD) // Need to check if temperature sensor valid if (!addSensor(KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 0)) { WarningLog("error adding heatsink temperature sensor"); } if(readTemperature(1)<MAX_TEMP_THRESHOLD) // Need to check if temperature sensor valid if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 1)) { WarningLog("error adding Ambient temperature sensor"); } if(readTemperature(2)<MAX_TEMP_THRESHOLD) // Need to check if temperature sensor valid if (!addSensor(KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 2)) { WarningLog("error adding system temperature sensor"); } } // Voltage UInt8 tmp = readByte(address, ITE_ADC_CHANNEL_ENABLE); DebugLog("ADC Enable register = %X",tmp); vbat_updates = false; if(configuration) { OSBoolean* smartGuard = OSDynamicCast(OSBoolean, configuration->getObject("VBATNeedUpdates")); if(smartGuard && smartGuard->isTrue()) vbat_updates=true; } // Refresh VBAT reading on each access to the key if(vbat_updates) writeByte(address, ITE_CONFIGURATION_REGISTER, readByte(address, ITE_CONFIGURATION_REGISTER) | 0x40); if (configuration) { for (int i = 0; i < 9; i++) { char key[5]; OSString * name; long Ri=0; long Rf=1; long Vf=0; snprintf(key, 5, "VIN%X", i); if (process_sensor_entry(configuration->getObject(key), &name, &Ri, &Rf, &Vf)) { if (name->isEqualTo("CPU")) { if (!addSensor(KEY_CPU_VRM_SUPPLY0, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) WarningLog("error adding CPU voltage sensor"); } else if (name->isEqualTo("Memory")) { if (!addSensor(KEY_MEMORY_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) WarningLog("error adding memory voltage sensor"); } else if (name->isEqualTo("+5VC")) { if (!addSensor(KEY_5VC_VOLTAGE, TYPE_SP4B, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding AVCC Voltage Sensor!"); } } else if (name->isEqualTo("+5VSB")) { if (!addSensor(KEY_5VSB_VOLTAGE, TYPE_SP4B, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding AVCC Voltage Sensor!"); } } else if (name->isEqualTo("+12VC")) { if (!addSensor(KEY_12V_VOLTAGE, TYPE_SP4B, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding 12V Voltage Sensor!"); } } else if (name->isEqualTo("-12VC")) { if (!addSensor(KEY_N12VC_VOLTAGE, TYPE_SP4B, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding 12V Voltage Sensor!"); } } else if (name->isEqualTo("3VCC")) { if (!addSensor(KEY_3VCC_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding 3VCC Voltage Sensor!"); } } else if (name->isEqualTo("3VSB")) { if (!addSensor(KEY_3VSB_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding 3VSB Voltage Sensor!"); } } else if (name->isEqualTo("VBAT")) { if (!addSensor(KEY_VBAT_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) { WarningLog("ERROR Adding VBAT Voltage Sensor!"); } } } } } // Tachometers for (int i = 0; i < 5; i++) { OSString* name = NULL; char key[5]; if (configuration) { char key_temp[7]; snprintf(key_temp, 7, "FANIN%X", i); name = OSDynamicCast(OSString, configuration->getObject(key_temp)); } UInt32 nameLength = name ? (UInt32)strlen(name->getCStringNoCopy()) : 0; if (readTachometer(i) > 10 || nameLength > 0) { // Pff WTF ??? Add tachometer if it doesn't exist in a system but only the name defined in the config??? if (!addTachometer(i, (nameLength > 0 ? name->getCStringNoCopy() : 0))) // Need to look at this a bit later WarningLog("error adding tachometer sensor %d", i); } // Check if this chip support SmartGuardian feature hasSmartGuardian=false; if(configuration) { if(OSBoolean* smartGuard=OSDynamicCast(OSBoolean, configuration->getObject("SmartGuardian"))) if(smartGuard->isTrue()) hasSmartGuardian=true; } if(hasSmartGuardian) { // Ugly development hack started for (SuperIOSensorGroup) snprintf(key,5,KEY_FORMAT_FAN_TARGET_SPEED,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardPWMControl, i)) WarningLog("error adding PWM fan control"); snprintf(key,5,KEY_FORMAT_FAN_START_TEMP,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanStart, i)) WarningLog("error adding start temp fan control"); snprintf(key,5,KEY_FORMAT_FAN_OFF_TEMP,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanStop, i)) WarningLog("error adding stop temp fan control"); snprintf(key,5,KEY_FORMAT_FAN_FULL_TEMP,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanFullOn, i)) WarningLog("error adding full speed temp fan control"); snprintf(key,5,KEY_FORMAT_FAN_START_PWM,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardPWMStart, i)) WarningLog("error adding start PWM fan control"); snprintf(key,5,KEY_FORMAT_FAN_TEMP_DELTA,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanFullOff, i)) WarningLog("error adding temp full off fan control"); snprintf(key,5,KEY_FORMAT_FAN_CONTROL,i); if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanControl, i)) WarningLog("error adding register fan control"); } } if(hasSmartGuardian) { if (!addSensor(KEY_FORMAT_FAN_MAIN_CONTROL, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardMainControl, 0)) WarningLog("error adding Main fan control"); if (!addSensor(KEY_FORMAT_FAN_REG_CONTROL, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardRegControl, 0)) WarningLog("error adding Main fan control"); } return true; }
bool FakeSMCDevice::initAndStart(IOService *platform, IOService *provider) { if (!provider || !super::init(platform, 0, 0)) return false; OSDictionary *properties = OSDynamicCast(OSDictionary, provider->getProperty("Configuration")); if (!properties) return false; status = (ApleSMCStatus *) IOMalloc(sizeof(struct AppleSMCStatus)); bzero((void*)status, sizeof(struct AppleSMCStatus)); interrupt_handler = 0; keys = OSArray::withCapacity(1); types = OSDictionary::withCapacity(0); exposedValues = OSDictionary::withCapacity(0); // Add fist key - counter key keyCounterKey = FakeSMCKey::withValue(KEY_COUNTER, TYPE_UI32, TYPE_UI32_SIZE, "\0\0\0\1"); keys->setObject(keyCounterKey); fanCounterKey = FakeSMCKey::withValue(KEY_FAN_NUMBER, TYPE_UI8, TYPE_UI8_SIZE, "\0"); keys->setObject(fanCounterKey); if (!gKeysLock) gKeysLock = IORecursiveLockAlloc(); // Load preconfigured keys FakeSMCDebugLog("loading keys..."); if (OSDictionary *dictionary = OSDynamicCast(OSDictionary, properties->getObject("Keys"))) { if (OSIterator *iterator = OSCollectionIterator::withCollection(dictionary)) { while (const OSSymbol *key = (const OSSymbol *)iterator->getNextObject()) { if (OSArray *array = OSDynamicCast(OSArray, dictionary->getObject(key))) { if (OSIterator *aiterator = OSCollectionIterator::withCollection(array)) { OSString *type = OSDynamicCast(OSString, aiterator->getNextObject()); OSData *value = OSDynamicCast(OSData, aiterator->getNextObject()); if (type && value) addKeyWithValue(key->getCStringNoCopy(), type->getCStringNoCopy(), value->getLength(), value->getBytesNoCopy()); OSSafeRelease(aiterator); } } key = 0; } OSSafeRelease(iterator); } HWSensorsInfoLog("%d preconfigured key%s added", keys->getCount(), keys->getCount() == 1 ? "" : "s"); } else { HWSensorsWarningLog("no preconfigured keys found"); } // Load wellknown type names FakeSMCDebugLog("loading types..."); if (OSDictionary *dictionary = OSDynamicCast(OSDictionary, properties->getObject("Types"))) { if (OSIterator *iterator = OSCollectionIterator::withCollection(dictionary)) { while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) { if (OSString *value = OSDynamicCast(OSString, dictionary->getObject(key))) { types->setObject(key, value); } } OSSafeRelease(iterator); } } // Set Clover platform keys if (OSDictionary *dictionary = OSDynamicCast(OSDictionary, properties->getObject("Clover"))) { UInt32 count = 0; if (IORegistryEntry* cloverPlatformNode = fromPath("/efi/platform", gIODTPlane)) { if (OSIterator *iterator = OSCollectionIterator::withCollection(dictionary)) { while (OSString *name = OSDynamicCast(OSString, iterator->getNextObject())) { if (OSData *data = OSDynamicCast(OSData, cloverPlatformNode->getProperty(name))) { if (OSArray *items = OSDynamicCast(OSArray, dictionary->getObject(name))) { OSString *key = OSDynamicCast(OSString, items->getObject(0)); OSString *type = OSDynamicCast(OSString, items->getObject(1)); if (addKeyWithValue(key->getCStringNoCopy(), type->getCStringNoCopy(), data->getLength(), data->getBytesNoCopy())) count++; } } } OSSafeRelease(iterator); } } if (count) HWSensorsInfoLog("%d key%s exported by Clover EFI", count, count == 1 ? "" : "s"); } // Start SMC device if (!super::start(platform)) return false; this->setName("SMC"); FakeSMCSetProperty("name", "APP0001"); if (OSString *compatibleKey = OSDynamicCast(OSString, properties->getObject("smc-compatible"))) FakeSMCSetProperty("compatible", (const char *)compatibleKey->getCStringNoCopy()); else FakeSMCSetProperty("compatible", "smc-napa"); if (!this->setProperty("_STA", (unsigned long long)0x0000000b, 32)) { HWSensorsErrorLog("failed to set '_STA' property"); return false; } if (OSBoolean *debugKey = OSDynamicCast(OSBoolean, properties->getObject("debug"))) debug = debugKey->getValue(); else debug = false; if (OSBoolean *traceKey = OSDynamicCast(OSBoolean, properties->getObject("trace"))) trace = traceKey->getValue(); else trace = false; IODeviceMemory::InitElement rangeList[1]; rangeList[0].start = 0x300; rangeList[0].length = 0x20; // rangeList[1].start = 0xfef00000; // rangeList[1].length = 0x10000; if(OSArray *array = IODeviceMemory::arrayFromList(rangeList, 1)) { this->setDeviceMemory(array); OSSafeRelease(array); } else { HWSensorsFatalLog("failed to create Device memory array"); return false; } OSArray *controllers = OSArray::withCapacity(1); if(!controllers) { HWSensorsFatalLog("failed to create controllers array"); return false; } controllers->setObject((OSSymbol *)OSSymbol::withCStringNoCopy("io-apic-0")); OSArray *specifiers = OSArray::withCapacity(1); if(!specifiers) { HWSensorsFatalLog("failed to create specifiers array"); return false; } UInt64 line = 0x06; OSData *tmpData = OSData::withBytes(&line, sizeof(line)); if (!tmpData) { HWSensorsFatalLog("failed to create specifiers data"); return false; } specifiers->setObject(tmpData); this->setProperty(gIOInterruptControllersKey, controllers) && this->setProperty(gIOInterruptSpecifiersKey, specifiers); this->attachToParent(platform, gIOServicePlane); registerService(); HWSensorsInfoLog("successfully initialized"); return true; }
bool FakeSMC::start(IOService *provider) { if (!super::start(provider)) return false; if (!(keyStore = OSDynamicCast(FakeSMCKeyStore, waitForMatchingService(serviceMatching(kFakeSMCKeyStoreService), kFakeSMCDefaultWaitTimeout)))) { HWSensorsInfoLog("still waiting for FakeSMCKeyStore..."); return false; // HWSensorsDebugLog("creating FakeSMCKeyStore"); // // if (!(keyStore = new FakeSMCKeyStore)) { // HWSensorsInfoLog("failed to create FakeSMCKeyStore"); // return false; // } // // HWSensorsDebugLog("initializing FakeSMCKeyStore"); // // if (keyStore->initAndStart(this, configuration)) { // keyStore->setProperty("IOUserClientClass", "FakeSMCKeyStoreUserClient"); // } // else { // keyStore->release(); // HWSensorsFatalLog("failed to initialize FakeSMCKeyStore device"); // return false; // } } // if (IOService *resources = waitForMatchingService(serviceMatching("IOResources"), 0)) // this->attach(resources); OSDictionary *configuration = OSDynamicCast(OSDictionary, getProperty("Configuration")); // Load preconfigured keys HWSensorsDebugLog("loading keys..."); if (!configuration) { HWSensorsFatalLog("no configuration node found!"); return false; } if (UInt32 count = keyStore->addKeysFromDictionary(OSDynamicCast(OSDictionary, configuration->getObject("Keys")))) { HWSensorsInfoLog("%d preconfigured key%s added", count, count == 1 ? "" : "s"); } else { HWSensorsWarningLog("no preconfigured keys found"); } // Load wellknown type names HWSensorsDebugLog("loading types..."); keyStore->addWellKnownTypesFromDictionary(OSDynamicCast(OSDictionary, configuration->getObject("Types"))); // Set Clover platform keys if (OSDictionary *dictionary = OSDynamicCast(OSDictionary, configuration->getObject("Clover"))) { UInt32 count = 0; if (IORegistryEntry* cloverPlatformNode = fromPath("/efi/platform", gIODTPlane)) { if (OSIterator *iterator = OSCollectionIterator::withCollection(dictionary)) { while (OSString *name = OSDynamicCast(OSString, iterator->getNextObject())) { if (OSData *data = OSDynamicCast(OSData, cloverPlatformNode->getProperty(name))) { if (OSArray *items = OSDynamicCast(OSArray, dictionary->getObject(name))) { OSString *key = OSDynamicCast(OSString, items->getObject(0)); OSString *type = OSDynamicCast(OSString, items->getObject(1)); if (keyStore->addKeyWithValue(key->getCStringNoCopy(), type->getCStringNoCopy(), data->getLength(), data->getBytesNoCopy())) count++; } } } OSSafeRelease(iterator); } } if (count) HWSensorsInfoLog("%d key%s exported by Clover EFI", count, count == 1 ? "" : "s"); } // Check if we have SMC already bool smcDeviceFound = false; if (OSDictionary *matching = serviceMatching("IOACPIPlatformDevice")) { if (OSIterator *iterator = getMatchingServices(matching)) { OSString *smcNameProperty = OSString::withCString("APP0001"); while (IOService *service = (IOService*)iterator->getNextObject()) { OSObject *serviceNameProperty = service->getProperty("name"); if (serviceNameProperty && serviceNameProperty->isEqualTo(smcNameProperty)) { smcDeviceFound = true; } } OSSafeRelease(iterator); } OSSafeRelease(matching); } if (!smcDeviceFound) { if (!(smcDevice = new FakeSMCDevice)) { HWSensorsInfoLog("failed to create SMC device"); return false; } IOService *platformExpert = waitForMatchingService(serviceMatching("IOACPIPlatformExpert"), kFakeSMCDefaultWaitTimeout); if (!smcDevice->initAndStart(platformExpert, this)) { HWSensorsFatalLog("failed to initialize SMC device"); return false; } } else { HWSensorsInfoLog("found physical SMC device, will not create virtual one. Providing only basic plugins functionality"); } int arg_value = 1; // Load keys from NVRAM if (PE_parse_boot_argn("-fakesmc-use-nvram", &arg_value, sizeof(arg_value))) { if (UInt32 count = keyStore->loadKeysFromNVRAM()) HWSensorsInfoLog("%d key%s loaded from NVRAM", count, count == 1 ? "" : "s"); else HWSensorsInfoLog("NVRAM will be used to store system written keys..."); } registerService(); return true; }
bool FakeSMC::init(OSDictionary *dictionary) { if (!super::init(dictionary)) return false; IOLog("HWSensors v%s Copyright %d netkas, slice, usr-sse2, kozlek, navi, THe KiNG, RehabMan. All rights reserved.\n", HWSENSORS_VERSION_STRING, HWSENSORS_LASTYEAR); //HWSensorsInfoLog("Opensource SMC device emulator. Copyright 2009 netkas. All rights reserved."); if (!(smcDevice = new FakeSMCDevice)) { HWSensorsInfoLog("failed to create SMC device"); return false; } if (!setOemProperties(this)) { // Another try after 200 ms spin IOSleep(200); setOemProperties(this); } if (!getProperty(kOEMInfoProduct) || !getProperty(kOEMInfoManufacturer)) { HWSensorsErrorLog("failed to obtain OEM vendor & product information from DMI"); // Try to obtain OEM info from Clover EFI if (IORegistryEntry* platformNode = fromPath("/efi/platform", gIODTPlane)) { if (OSData *data = OSDynamicCast(OSData, platformNode->getProperty("OEMVendor"))) { if (OSString *vendor = OSString::withCString((char*)data->getBytesNoCopy())) { if (OSString *manufacturer = getManufacturerNameFromOEMName(vendor)) { this->setProperty(kOEMInfoManufacturer, manufacturer); //OSSafeReleaseNULL(manufacturer); } //OSSafeReleaseNULL(vendor); } //OSSafeReleaseNULL(data); } if (OSData *data = OSDynamicCast(OSData, platformNode->getProperty("OEMBoard"))) { if (OSString *product = OSString::withCString((char*)data->getBytesNoCopy())) { this->setProperty(kOEMInfoProduct, product); //OSSafeReleaseNULL(product); } //OSSafeReleaseNULL(data); } } else { HWSensorsErrorLog("failed to get OEM info from Clover EFI, specific platform profiles will be unavailable"); } } if (IORegistryEntry *efi = IORegistryEntry::fromPath("/efi", gIODTPlane)) { if (OSData *vendor = OSDynamicCast(OSData, efi->getProperty("firmware-vendor"))) { // firmware-vendor is in EFI node OSData *buffer = OSData::withCapacity(128); const unsigned char* data = static_cast<const unsigned char*>(vendor->getBytesNoCopy()); for (unsigned int index = 0; index < vendor->getLength(); index += 2) { buffer->appendByte(data[index], 1); } OSString *name = OSString::withCString(static_cast<const char *>(buffer->getBytesNoCopy())); setProperty(kFakeSMCFirmwareVendor, name); //OSSafeRelease(vendor); //OSSafeRelease(name); OSSafeRelease(buffer); } OSSafeRelease(efi); } return true; }
bool MacRISC2CPU::start(IOService *provider) { kern_return_t result; IORegistryEntry *cpusRegEntry, *uniNRegEntry, *mpicRegEntry, *devicetreeRegEntry; OSIterator *cpusIterator; OSData *tmpData; IOService *service; const OSSymbol *interruptControllerName; OSData *interruptData; OSArray *tmpArray; UInt32 maxCPUs, uniNVersion, physCPU; ml_processor_info_t processor_info; #if enableUserClientInterface DFScontMode = 0; fWorkLoop = 0; DFS_Status = false; GPU_Status = kGPUHigh; vStepped = false; #endif // callPlatformFunction symbols mpic_getProvider = OSSymbol::withCString("mpic_getProvider"); mpic_getIPIVector= OSSymbol::withCString("mpic_getIPIVector"); mpic_setCurrentTaskPriority = OSSymbol::withCString("mpic_setCurrentTaskPriority"); mpic_setUpForSleep = OSSymbol::withCString("mpic_setUpForSleep"); mpic_dispatchIPI = OSSymbol::withCString("mpic_dispatchIPI"); keyLargo_restoreRegisterState = OSSymbol::withCString("keyLargo_restoreRegisterState"); keyLargo_syncTimeBase = OSSymbol::withCString("keyLargo_syncTimeBase"); keyLargo_saveRegisterState = OSSymbol::withCString("keyLargo_saveRegisterState"); keyLargo_turnOffIO = OSSymbol::withCString("keyLargo_turnOffIO"); keyLargo_writeRegUInt8 = OSSymbol::withCString("keyLargo_writeRegUInt8"); keyLargo_getHostKeyLargo = OSSymbol::withCString("keyLargo_getHostKeyLargo"); keyLargo_setPowerSupply = OSSymbol::withCString("setPowerSupply"); uniN_setPowerState = OSSymbol::withCString(kUniNSetPowerState); uniN_setAACKDelay = OSSymbol::withCString(kUniNSetAACKDelay); pmu_cpuReset = OSSymbol::withCString("cpuReset"); ati_prepareDMATransaction = OSSymbol::withCString(kIOFBPrepareDMAValueKey); ati_performDMATransaction = OSSymbol::withCString(kIOFBPerformDMAValueKey); macRISC2PE = OSDynamicCast(MacRISC2PE, getPlatform()); if (macRISC2PE == 0) return false; if (!super::start(provider)) return false; // Get the Uni-N Version. uniNRegEntry = fromPath("/uni-n", gIODTPlane); if (uniNRegEntry == 0) return false; tmpData = OSDynamicCast(OSData, uniNRegEntry->getProperty("device-rev")); if (tmpData == 0) return false; uniNVersion = *(long *)tmpData->getBytesNoCopy(); // Find out if this is the boot CPU. bootCPU = false; tmpData = OSDynamicCast(OSData, provider->getProperty("state")); if (tmpData == 0) return false; if (!strcmp((char *)tmpData->getBytesNoCopy(), "running")) bootCPU = true; // Count the CPUs. numCPUs = 0; cpusRegEntry = fromPath("/cpus", gIODTPlane); if (cpusRegEntry == 0) return false; cpusIterator = cpusRegEntry->getChildIterator(gIODTPlane); while (cpusIterator->getNextObject()) numCPUs++; cpusIterator->release(); // [3830950] - The bootCPU driver inits globals for all instances (like gCPUIC) so if we're not the // boot CPU driver we wait here for that driver to finish its initialization if ((numCPUs > 1) && !bootCPU) // Wait for bootCPU driver to say it's up and running (void) waitForService (resourceMatching ("BootCPU")); // Limit the number of CPUs to one if uniNVersion is 1.0.7 or less. if (uniNVersion < kUniNVersion107) numCPUs = 1; // Limit the number of CPUs by the cpu=# boot arg. if (PE_parse_boot_arg("cpus", &maxCPUs)) { if (numCPUs > maxCPUs) numCPUs = maxCPUs; } ignoreSpeedChange = false; doSleep = false; topLevelPCIBridgeCount = 0; // Get the "flush-on-lock" property from the first cpu node. flushOnLock = false; cpusRegEntry = fromPath("/cpus/@0", gIODTPlane); if (cpusRegEntry == 0) return false; if (cpusRegEntry->getProperty("flush-on-lock") != 0) flushOnLock = true; // Set flushOnLock when numCPUs is not one. if (numCPUs != 1) flushOnLock = true; // If system is PowerMac3,5 (TowerG4), then set flushOnLock to disable nap devicetreeRegEntry = fromPath("/", gIODTPlane); tmpData = OSDynamicCast(OSData, devicetreeRegEntry->getProperty("model")); if (tmpData == 0) return false; #if 0 if(!strcmp((char *)tmpData->getBytesNoCopy(), "PowerMac3,5")) flushOnLock = true; #endif // Get the physical CPU number from the "reg" property. tmpData = OSDynamicCast(OSData, provider->getProperty("reg")); if (tmpData == 0) return false; physCPU = *(long *)tmpData->getBytesNoCopy(); setCPUNumber(physCPU); // Get the gpio offset for soft reset from the "soft-reset" property. tmpData = OSDynamicCast(OSData, provider->getProperty("soft-reset")); if (tmpData == 0) { if (physCPU == 0) soft_reset_offset = 0x5B; else soft_reset_offset = 0x5C; } else soft_reset_offset = *(long *)tmpData->getBytesNoCopy(); // Get the gpio offset for timebase enable from the "timebase-enable" property. tmpData = OSDynamicCast(OSData, provider->getProperty("timebase-enable")); if (tmpData == 0) timebase_enable_offset = 0x73; else timebase_enable_offset = *(long *)tmpData->getBytesNoCopy(); // See if reset is needed on wake resetOnWake = (provider->getProperty ("reset-on-wake") != NULL); if (resetOnWake) { vm_address_t reserveMem; reserveMem = (vm_address_t)IOMallocAligned (PAGE_SIZE, PAGE_SIZE); // Get one page (which we keep forever) if (reserveMem) { // map it reserveMemDesc = IOMemoryDescriptor::withAddress (reserveMem, PAGE_SIZE, kIODirectionNone, NULL); if (reserveMemDesc) { // get the physical address reserveMemPhys = reserveMemDesc->getPhysicalAddress(); } } } // On machines with a 'vmin' property in the CPU Node we need to make sure to tell the kernel to // ml_set_processor_voltage on needed processors. needVSetting = (provider->getProperty( "vmin" ) != 0); // While techincally the Apollo7PM machines do need AACK delay, it is already set in the bootROM // since we boot slow. We don't want the machine to switch AACKdelay off when we run DFS high so // setting this to false will take care of the issue. needAACKDelay = false; if (bootCPU) { gCPUIC = new IOCPUInterruptController; if (gCPUIC == 0) return false; if (gCPUIC->initCPUInterruptController(numCPUs) != kIOReturnSuccess) return false; gCPUIC->attach(this); gCPUIC->registerCPUInterruptController(); } // Get the l2cr value from the property list. tmpData = OSDynamicCast(OSData, provider->getProperty("l2cr")); if (tmpData != 0) { l2crValue = *(long *)tmpData->getBytesNoCopy() & 0x7FFFFFFF; } else { l2crValue = mfl2cr() & 0x7FFFFFFF; } // Wait for KeyLargo to show up. keyLargo = waitForService(serviceMatching("KeyLargo")); if (keyLargo == 0) return false; keyLargo->callPlatformFunction (keyLargo_getHostKeyLargo, false, &keyLargo, 0, 0, 0); if (keyLargo == 0) { kprintf ("MacRISC2CPU::start - getHostKeyLargo returned nil\n"); return false; } // Wait for MPIC to show up. mpic = waitForService(serviceMatching("AppleMPICInterruptController")); if (mpic == 0) return false; // Set the Interrupt Properties for this cpu. mpic->callPlatformFunction(mpic_getProvider, false, (void *)&mpicRegEntry, 0, 0, 0); interruptControllerName = IODTInterruptControllerName(mpicRegEntry); mpic->callPlatformFunction(mpic_getIPIVector, false, (void *)&physCPU, (void *)&interruptData, 0, 0); if ((interruptControllerName == 0) || (interruptData == 0)) return false; tmpArray = OSArray::withCapacity(1); tmpArray->setObject(interruptControllerName); cpuNub->setProperty(gIOInterruptControllersKey, tmpArray); tmpArray->release(); tmpArray = OSArray::withCapacity(1); tmpArray->setObject(interruptData); cpuNub->setProperty(gIOInterruptSpecifiersKey, tmpArray); tmpArray->release(); setCPUState(kIOCPUStateUninitalized); // necessary bootCPU initialization is done, so release other CPU drivers to do their thing // other drivers need to be unblocked *before* we call processor_start otherwise we deadlock if (bootCPU) publishResource ("BootCPU", this); if (physCPU < numCPUs) { processor_info.cpu_id = (cpu_id_t)this; processor_info.boot_cpu = bootCPU; processor_info.start_paddr = 0x0100; processor_info.l2cr_value = l2crValue; processor_info.supports_nap = !flushOnLock; processor_info.time_base_enable = OSMemberFunctionCast(time_base_enable_t, this, &MacRISC2CPU::enableCPUTimeBase); // [4091924] // Register this CPU with mach. result = ml_processor_register(&processor_info, &machProcessor, &ipi_handler); if (result == KERN_FAILURE) return false; processor_start(machProcessor); } // Before to go to sleep we wish to disable the napping mode so that the PMU // will not shutdown the system while going to sleep: service = waitForService(serviceMatching("IOPMrootDomain")); pmRootDomain = OSDynamicCast(IOPMrootDomain, service); if (pmRootDomain != 0) { kprintf("Register MacRISC2CPU %ld to acknowledge power changes\n", getCPUNumber()); pmRootDomain->registerInterestedDriver(this); // Join the Power Management Tree to receive setAggressiveness calls. PMinit(); provider->joinPMtree(this); } // Finds PMU and UniN so in quiesce we can put the machine to sleep. // I can not put these calls there because quiesce runs in interrupt // context and waitForService may block. pmu = waitForService(serviceMatching("ApplePMU")); uniN = waitForService(serviceMatching("AppleUniN")); if ((pmu == 0) || (uniN == 0)) return false; if (macRISC2PE->hasPMon) { // Find the platform monitor, if present service = waitForService(resourceMatching("IOPlatformMonitor")); ioPMon = OSDynamicCast (IOPlatformMonitor, service->getProperty("IOPlatformMonitor")); if (!ioPMon) return false; ioPMonDict = OSDictionary::withCapacity(2); if (!ioPMonDict) { ioPMon = NULL; } else { ioPMonDict->setObject (kIOPMonTypeKey, OSSymbol::withCString (kIOPMonTypeCPUCon)); ioPMonDict->setObject (kIOPMonCPUIDKey, OSNumber::withNumber ((long long)getCPUNumber(), 32)); if (messageClient (kIOPMonMessageRegister, ioPMon, (void *)ioPMonDict) != kIOReturnSuccess) { // IOPMon doesn't need to know about us, so don't bother with it IOLog ("MacRISC2CPU::start - failed to register cpu with IOPlatformMonitor\n"); ioPMonDict->release(); ioPMon = NULL; } } } if (macRISC2PE->hasPPlugin) { IOService *ioPPlugin; OSDictionary *ioPPluginDict; // Find the platform plugin, if present service = waitForService(resourceMatching("IOPlatformPlugin")); ioPPlugin = OSDynamicCast (IOService, service->getProperty("IOPlatformPlugin")); if (!ioPPlugin) return false; ioPPluginDict = OSDictionary::withCapacity(2); if (ioPPluginDict) { ioPPluginDict->setObject ("cpu-id", OSNumber::withNumber ((long long)getCPUNumber(), 32)); // Register with the plugin - same API as for platform monitor if (messageClient (kIOPMonMessageRegister, ioPPlugin, (void *)ioPPluginDict) != kIOReturnSuccess) { // ioPPlugin doesn't need to know about us, so don't bother with it IOLog ("MacRISC2CPU::start - failed to register cpu with IOPlatformPlugin\n"); } ioPPluginDict->release(); // Not needed any more } } #if enableUserClientInterface // // UserClient stuff... // fWorkLoop = getWorkLoop(); if(!fWorkLoop) { IOLog("MacRISC2CPU::start ERROR: failed to find a fWorkLoop\n"); } if(!initTimers()) { IOLog("MacRISC2CPU::start ERROR: failed to init the timers\n"); } #endif registerService(); return true; }
bool SMBIOSResolver::start(IOService * provider) { if( super::start(provider) != true ) return false; // Oh no if( IOService::getResourceService()->getProperty("SMBIOS-Resolver") ) return false; // We should exist only once if( !IOService::getResourceService()->getProperty("SMBIOS") ) return false; // AppleSMBIOS.kext didn´t start we bail out IOService * iosRoot = getServiceRoot(); if( !iosRoot ) return false; // Unable to get IOServiceRoot int doVerbose = 0; // PE_parse_boot_arg("smbios", &doVerbose); // bootarg SMBIOS=1 will give a verbose output to log (when I find something verbose worth outputting) // Dictionary from plist OSDictionary * hwDict = OSDynamicCast( OSDictionary, getProperty("Override")); // /rom/version IORegistryEntry * dtROMNode = fromPath("/rom", gIODTPlane); if( dtROMNode ) { OSString * romVersion = OSDynamicCast( OSString, hwDict->getObject("rom-version")); if(romVersion->getLength() > 0) dtROMNode->setProperty("version", OSData::withBytes(romVersion->getCStringNoCopy(), romVersion->getLength() + 1) ); dtROMNode->release(); } else { return false; // No /rom node in IODeviceTree plane } // root entries OSObject * dictString = 0; dictString = hwDict->getObject("manufacturer"); if(dictString) { OSString * rootManufacturer = OSDynamicCast( OSString, dictString); if(rootManufacturer->getLength() > 1) iosRoot->setProperty("manufacturer", OSData::withBytes(rootManufacturer->getCStringNoCopy(), rootManufacturer->getLength() + 1) ); } dictString = hwDict->getObject("system-type"); if(dictString) { OSData * systemType = OSDynamicCast( OSData, dictString); if(systemType) iosRoot->setProperty("system-type", systemType ); } dictString = hwDict->getObject("compatible"); if(dictString) { OSString * rootCompatible = OSDynamicCast( OSString, dictString); if(rootCompatible->getLength() > 1) iosRoot->setProperty("compatible", OSData::withBytes(rootCompatible->getCStringNoCopy(), rootCompatible->getLength() + 1) ); } dictString = hwDict->getObject("product-name"); if(dictString) { OSString * rootProductName = OSDynamicCast( OSString, dictString); if(rootProductName->getLength() > 1) iosRoot->setProperty("product-name", OSData::withBytes(rootProductName->getCStringNoCopy(), rootProductName->getLength() + 1) ); } dictString = hwDict->getObject("model"); if(dictString) { OSString * rootModel = OSDynamicCast( OSString, dictString); if(rootModel->getLength() > 1) { iosRoot->setProperty("model", OSData::withBytes(rootModel->getCStringNoCopy(), rootModel->getLength() + 1) ); iosRoot->setName(rootModel->getCStringNoCopy()); } } dictString = hwDict->getObject("version"); if(dictString) { OSString * rootVersion = OSDynamicCast( OSString, dictString); if(rootVersion->getLength() > 1) iosRoot->setProperty("version", OSData::withBytes(rootVersion->getCStringNoCopy(), rootVersion->getLength() + 1) ); } dictString = hwDict->getObject("board-id"); if(dictString) { OSString * rootBoardId = OSDynamicCast( OSString, dictString); if(rootBoardId->getLength() > 1) iosRoot->setProperty("board-id", OSData::withBytes(rootBoardId->getCStringNoCopy(), rootBoardId->getLength() + 1) ); } dictString = hwDict->getObject("serial-number"); if(dictString) { OSString * rootSerial = OSDynamicCast( OSString, dictString); if(rootSerial->getLength() > 1) { UInt8 length = rootSerial->getLength(); const char *serialNumberString = rootSerial->getCStringNoCopy(); // The serial-number property in the IORegistry is a 43-byte data object. // Bytes 0 through 2 are the last three bytes of the serial number string. // Bytes 11 through 20, inclusive, are the serial number string itself. // All other bytes are '\0'. OSData * data = OSData::withCapacity(43); if (data) { data->appendBytes(serialNumberString + (length - 3), 3); data->appendBytes(NULL, 10); data->appendBytes(serialNumberString, length); data->appendBytes(NULL, 43 - length - 10 - 3); iosRoot->setProperty("serial-number", data); data->release(); } iosRoot->setProperty(kIOPlatformSerialNumberKey, rootSerial); } } dictString = hwDict->getObject("UUID-key"); if(dictString) { OSString * rootUUIDKey = OSDynamicCast( OSString, hwDict->getObject("UUID-key")); iosRoot->setProperty(kIOPlatformUUIDKey, rootUUIDKey); publishResource(kIOPlatformUUIDKey, rootUUIDKey); } bool useEfiBus = false; UInt64 fsbFrequency = 0; UInt64 msr; dictString = hwDict->getObject("use-efi-bus"); if (dictString) useEfiBus = (OSDynamicCast(OSBoolean, dictString))->getValue(); IORegistryEntry * efiPlatform = fromPath("/efi/platform", gIODTPlane); if (efiPlatform && useEfiBus) { OSData * efiFSBFreq = OSDynamicCast(OSData, efiPlatform->getProperty("FSBFrequency")); bcopy(efiFSBFreq->getBytesNoCopy(), &fsbFrequency, efiFSBFreq->getLength()); efiPlatform->release(); } else { // No /efi/platform found fsbFrequency = gPEClockFrequencyInfo.bus_frequency_hz; // Value previously set by AppleSMBIOS if (!strncmp(cpuid_info()->cpuid_vendor, CPUID_VID_INTEL, sizeof(CPUID_VID_INTEL)) && (cpuid_info()->cpuid_features & CPUID_FEATURE_SSE2)) fsbFrequency /= 4; } dictString = hwDict->getObject("hardcode-bus"); if(dictString) { fsbFrequency = (OSDynamicCast(OSNumber, dictString))->unsigned64BitValue(); if (fsbFrequency) { if (fsbFrequency <= 10000) fsbFrequency *= 1000000; } else { if (!strncmp(cpuid_info()->cpuid_vendor, CPUID_VID_INTEL, sizeof(CPUID_VID_INTEL))) { if ((cpuid_info()->cpuid_family == 0x0f) && (cpuid_info()->cpuid_model >= 2)) { msr = rdmsr64(0x0000002C); switch ((msr >> 16) & 0x7) { case 0: if (cpuid_info()->cpuid_model == 2) fsbFrequency = 100 * 1000000; else { fsbFrequency = (800 * 1000000) / 3; // 266 fsbFrequency++; } break; case 1: fsbFrequency = (400 * 1000000) / 3; // 133 break; case 2: fsbFrequency = (600 * 1000000) / 3; // 200 break; case 3: fsbFrequency = (500 * 1000000) / 3; // 166 fsbFrequency++; break; case 4: fsbFrequency = (1000 * 1000000) / 3; // 333 break; default: break; } } else { fsbFrequency = 100 * 1000000; } if (cpuid_info()->cpuid_family == 0x06) { msr = rdmsr64(0x000000CD); switch (msr & 0x7) { case 0: fsbFrequency = (800 * 1000000) / 3; // 266 fsbFrequency++; break; case 1: fsbFrequency = (400 * 1000000) / 3; // 133 break; case 2: fsbFrequency = (600 * 1000000) / 3; // 200 break; case 3: fsbFrequency = (500 * 1000000) / 3; // 166 fsbFrequency++; break; case 4: fsbFrequency = (1000 * 1000000) / 3;// 333 break; case 5: fsbFrequency = (300 * 1000000) / 3; // 100 break; case 6: fsbFrequency = (1200 * 1000000) / 3;// 400 break; case 7: // should check fsbFrequency = (1400 * 1000000) / 3;// 466 fsbFrequency++; break; default: break; } } } }
// Class probe IOService * VoodooPState::probe(IOService * provider, SInt32 * score) { Ready = false; // Probe the superclass if (IOService::probe(provider, score) != this) return NULL; // Read our own values from the property list OSDictionary * dictionary = OSDynamicCast(OSDictionary, getProperty(keyPowerControl)); if (!dictionary) return NULL; UseEfiFsb = getPlistValue(dictionary, keyUseEfiFsb); VoltageOverride = getPlistValue(dictionary, keyVoltageOverride); VoltageProbe = getPlistValue(dictionary, keyVoltageProbe); UserVoltageMax = getPlistValue(dictionary, keyUserVoltageMax); UserVoltageMin = getPlistValue(dictionary, keyUserVoltageMin); ColdStart = getPlistValue(dictionary, keyColdStart); TimerInterval = getPlistValue(dictionary, keyTimerInterval); UseACPI = getPlistValue(dictionary, keyUseACPI); if(TimerInterval < 50){ TimerInterval = 50; } // Get CPU's from I/O Kit CpuCount = getCpuCount(); // No CPU's found -> bailout if (CpuCount == 0) return NULL; // Get FSB from /efi/platform CpuFSB = gPEClockFrequencyInfo.bus_frequency_max_hz >> 2; if (UseEfiFsb) { IORegistryEntry * entry = fromPath(keyEfiPlatform, gIODTPlane); if (entry) { OSObject * object = entry->getProperty(keyEfiFsbFrequency); if (object && (OSTypeIDInst(object) == OSTypeID(OSData))) { OSData * data = OSDynamicCast(OSData, object); if (data) { CpuFSB = * (UInt32 *) data->getBytesNoCopy(); gPEClockFrequencyInfo.bus_frequency_max_hz = CpuFSB << 2; } } } } CpuFSB = (CpuFSB+Mega/2) / Mega; // Mega is enough #if SUPPORT_VOODOO_KERNEL { UInt64 magic; nanoseconds_to_absolutetime(~(0), &magic); VoodooKernel = (magic == 2); } #endif // Enumerate CPU's CpuCoreTech = Unknown; { uint32_t data[4]; do_cpuid(0, data); ((uint32_t*)vendor)[0] = data[1]; ((uint32_t*)vendor)[1] = data[3]; ((uint32_t*)vendor)[2] = data[2]; vendor[15] = 0; do_cpuid(1, data); CpuSignature = data[0]; // Features ((uint32_t*)&Features)[0] = data[3]; ((uint32_t*)&Features)[1] = data[2]; for( int i = 0; i < 3; i++ ){ do_cpuid(0x80000002+i, data); memcpy( &brand_string[i*16], data, 16 ); } brand_string[16*3] = 0; } // Find core technology and cross core vendor specifics // Intel if (!strncmp(vendor, CPUID_VID_INTEL, sizeof(CPUID_VID_INTEL))) { if(!intel_probe(this)) return NULL; } // AMD else if (!strncmp(vendor, CPUID_VID_AMD, sizeof(CPUID_VID_AMD))) { if(!amd_probe(this)) return NULL; } // Unknown CPU or core technology else { ErrorLog("CPU: Core Technology Unknown - Signature %x (%s)(%s)", (unsigned int)CpuSignature, vendor, brand_string); return NULL; } return this; }