int GeforceSensors::addTachometer(int index) { UInt8 length = 0; void * data = 0; char name[5]; if (kIOReturnSuccess == fakeSMC->callPlatformFunction(kFakeSMCGetKeyValue, false, (void *)KEY_FAN_NUMBER, (void *)&length, (void *)&data, 0)) { bcopy(data, &length, 1); snprintf(name, 5, KEY_FORMAT_FAN_SPEED, length); if (addSensor(name, TYPE_FPE2, 2, index)) { length++; if (kIOReturnSuccess != fakeSMC->callPlatformFunction(kFakeSMCSetKeyValue, false, (void *)KEY_FAN_NUMBER, (void *)1, (void *)&length, 0)) WarningLog("error updating FNum value"); return length-1; } } else WarningLog("error reading FNum value"); return -1; }
SuperIOSensor *SuperIOMonitor::addTachometer(unsigned long index, const char* id) { UInt8 length = 0; void * data = 0; if (kIOReturnSuccess == fakeSMC->callPlatformFunction(kFakeSMCGetKeyValue, true, (void *)KEY_FAN_NUMBER, (void *)&length, (void *)&data, 0)) { length = 0; bcopy(data, &length, 1); char name[5]; snprintf(name, 5, KEY_FORMAT_FAN_SPEED, length); if (SuperIOSensor *sensor = addSensor(name, TYPE_FPE2, 2, kSuperIOTachometerSensor, index)) { if (id) { snprintf(name, 5, KEY_FORMAT_FAN_ID, length); if (kIOReturnSuccess != fakeSMC->callPlatformFunction(kFakeSMCAddKeyValue, false, (void *)name, (void *)TYPE_CH8, (void *)((UInt64)strlen(id)), (void *)id)) WarningLog("error adding tachometer id value"); } length++; if (kIOReturnSuccess != fakeSMC->callPlatformFunction(kFakeSMCSetKeyValue, true, (void *)KEY_FAN_NUMBER, (void *)1, (void *)&length, 0)) WarningLog("error updating FNum value"); return sensor; } } else WarningLog("error reading FNum value"); return 0; }
bool ACPIMonitor::addTachometer(const char* method, const char* caption) { UInt8 length = 0; void * data = 0; if (kIOReturnSuccess == fakeSMC->callPlatformFunction(kFakeSMCGetKeyValue, true, (void *)KEY_FAN_NUMBER, (void *)&length, (void *)&data, 0)) { length = 0; bcopy(data, &length, 1); char name[5]; snprintf(name, 5, KEY_FORMAT_FAN_SPEED, length); if (addSensor(method, name, TYPE_FPE2, 2)) { if (caption) { snprintf(name, 5, KEY_FORMAT_FAN_ID, length); if (kIOReturnSuccess != fakeSMC->callPlatformFunction(kFakeSMCAddKeyValue, false, (void *)name, (void *)TYPE_CH8, (void *)((UInt64)strlen(caption)), (void *)caption)) WarningLog("error adding tachometer id value"); } length++; if (kIOReturnSuccess != fakeSMC->callPlatformFunction(kFakeSMCSetKeyValue, true, (void *)KEY_FAN_NUMBER, (void *)1, (void *)&length, 0)) WarningLog("error updating FNum value"); return true; } } else WarningLog("error reading FNum value"); return false; }
bool GeforceSensors::addSensor(const char* key, const char* type, unsigned char size, int index) { if (kIOReturnSuccess == fakeSMC->callPlatformFunction(kFakeSMCAddKeyHandler, true, (void *)key, (void *)type, (void *)size, (void *)this)) { if (sensors->setObject(key, OSNumber::withNumber(index, 32))) { return true; } else { WarningLog("%s key sensor not set", key); return 0; } } WarningLog("%s key sensor not added", key); return 0; }
bool FakeSMCKey::setValueFromBuffer(const void *aBuffer, unsigned char aSize) { if (!aBuffer || aSize == 0) return false; if (aSize != size) { if (value) IOFree(value, size); size = aSize; if (!(value = IOMalloc(size))) return false; } bcopy(aBuffer, value, size); if (handler) { IOReturn result = handler->callPlatformFunction(kFakeSMCSetValueCallback, false, (void *)name, (void *)value, (void *)size, 0); if (kIOReturnSuccess != result) WarningLog("value changed event callback error for key %s, return 0x%x", name, result); } return true; }
bool FakeSMC::start(IOService *provider) { if (!super::start(provider)) return false; if (!(smcDevice = new FakeSMCDevice)) { WarningLog("Failed to create SMCDevice!"); return false; } if (!smcDevice->init(provider, OSDynamicCast(OSDictionary, getProperty("Configuration")))) { WarningLog("Failed to init SMCDevice!"); return false; } smcDevice->registerService(); registerService(); return true; }
void IT87x::stop (IOService* provider) { DebugLog("stoping..."); if (kIOReturnSuccess != fakeSMC->callPlatformFunction(kFakeSMCRemoveKeyHandler, true, this, NULL, NULL, NULL)) { WarningLog("Can't remove key handler"); IOSleep(500); } super::stop(provider); }
const void *FakeSMCKey::getValue() { if (handler) { IOReturn result = handler->callPlatformFunction(kFakeSMCGetValueCallback, false, (void *)name, (void *)value, (void *)size, 0); if (kIOReturnSuccess != result) WarningLog("value update request callback error for key %s, return 0x%x", name, result); } return value; };
void GeforceSensors::stop (IOService* provider) { DebugLog("Stoping..."); sensors->flushCollection(); if (kIOReturnSuccess != fakeSMC->callPlatformFunction(kFakeSMCRemoveKeyHandler, true, this, NULL, NULL, NULL)) { WarningLog("Can't remove key handler"); IOSleep(500); } super::stop(provider); }
bool SuperIOMonitor::start(IOService *provider) { DebugLog("starting..."); if (!super::start(provider)) return false; if (!(fakeSMC = waitForService(serviceMatching(kFakeSMCDeviceService)))) { WarningLog("can't locate fake SMC device, kext will not load"); return false; } return true; }
bool FakeSMCPlugin::start(IOService *provider) { DebugLog("Starting..."); if (!super::start(provider)) return false; if (!(fakeSMC = waitForService(serviceMatching(kFakeSMCDeviceService)))) { WarningLog("Can't locate fake SMC device!"); return false; } return true; }
bool IT87x::probePort() { UInt16 id = listenPortWord(SUPERIO_CHIP_ID_REGISTER); if (id == 0 || id == 0xffff) return false; switch (id) { case IT8512F: case IT8712F: case IT8716F: case IT8718F: case IT8720F: case IT8721F: case IT8726F: case IT8728F: case IT8752F: model = id; break; default: WarningLog("found unsupported chip ID=0x%x", id); return false; } selectLogicalDevice(ITE_ENVIRONMENT_CONTROLLER_LDN); if (!getLogicalDeviceAddress()) return false; bool* valid; UInt8 vendor = readByte(ITE_VENDOR_ID_REGISTER, valid); if (!valid || vendor != ITE_VENDOR_ID) return false; if ((readByte(ITE_CONFIGURATION_REGISTER, valid) & 0x10) == 0) return false; if (!valid) return false; return true; }
bool PC8739x::start(IOService * provider) { DebugLog("starting..."); if (!super::start(provider)) return false; InfoLog("found NSC %s, revision 0x%x", getModelName(), revision); OSDictionary* configuration = OSDynamicCast(OSDictionary, getProperty("Sensors Configuration")); UInt32 adr = (listenPortByte(NSC_MEM) & 0xff) + ((listenPortByte(NSC_MEM + 1) << 8) & 0xff00) + ((listenPortByte(NSC_MEM + 2) & 0xff) << 16) + ((listenPortByte(NSC_MEM + 3) & 0xff) << 24); IOPhysicalAddress bar = (IOPhysicalAddress)(adr & ~0xf); if(IOMemoryDescriptor *theDescriptor = IOMemoryDescriptor::withPhysicalAddress(bar, 0x200, kIODirectionOutIn)) if(mmio = theDescriptor->map()){ mmioBase = (volatile UInt8 *)mmio->getVirtualAddress(); } else { WarningLog("MCHBAR failed to map"); return false; } // Heatsink if (!addSensor(KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 2)) WarningLog("error adding heatsink temperature sensor"); // Northbridge if (!addSensor(KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 0)) WarningLog("error adding system temperature sensor"); // DIMM if (!addSensor(KEY_DIMM_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 1)) WarningLog("error adding DIMM temperature sensor"); // AUX if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 3)) WarningLog("error adding AUX temperature sensor"); // Tachometers // for (int i = 0; i < 5; i++) { //only one OSString* name = 0; int i=0; if (configuration) { char key[7]; snprintf(key, 7, "FANIN%X", i); name = OSDynamicCast(OSString, configuration->getObject(key)); } UInt32 nameLength = name ? name->getLength() : 0; if (readTachometer(i) > 10 || nameLength > 0) if (!addTachometer(i, (nameLength > 0 ? name->getCStringNoCopy() : 0))) WarningLog("error adding tachometer sensor %d", i); // } return true; }
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 = OSDynamicCast(OSDictionary, list->getObject(getModelName())); if (!configuration) configuration = OSDynamicCast(OSDictionary, getProperty("Default")); // Temperature Sensors if (configuration) { for (int i = 0; i < 4; i++) { char key[8]; snprintf(key, 8, "TEMPIN%X", i); if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key))) if (name->isEqualTo("Processor")) { 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("Auxiliary")) { if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor,i)) WarningLog("error adding auxiliary temperature sensor"); } } } else { if (!addSensor(KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 0)) WarningLog("error adding heatsink temperature sensor"); if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 1)) WarningLog("error adding auxiliary temperature sensor"); if (!addSensor(KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 2)) WarningLog("error adding system temperature sensor"); } // Voltage if (configuration) { for (int i = 0; i < 9; i++) //Zorglub { char key[5]; snprintf(key, 5, "VIN%X", i); if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key))) { if (name->isEqualTo("Processor")) { if (!addSensor(KEY_CPU_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i)) WarningLog("error adding CPU voltage sensor"); } else if (name->isEqualTo("Memory")) { if (!addSensor(KEY_MEMORY_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i)) WarningLog("error adding memory voltage sensor"); } } } } // Tachometers for (int i = 0; i < 5; i++) { OSString* name = NULL; if (configuration) { char key[7]; snprintf(key, 7, "FANIN%X", i); name = OSDynamicCast(OSString, configuration->getObject(key)); } UInt64 nameLength = name ? strlen(name->getCStringNoCopy()) : 0; if (readTachometer(i) > 10 || nameLength > 0) if (!addTachometer(i, (nameLength > 0 ? name->getCStringNoCopy() : 0))) WarningLog("error adding tachometer sensor %d", i); } return true; }
bool ACPIMonitor::start(IOService * provider) { if (!super::start(provider)) return false; acpiDevice = (IOACPIPlatformDevice *)provider; char key[5]; //Here is Fan in ACPI OSArray* fanNames = OSDynamicCast(OSArray, getProperty("FanNames")); for (int i=0; i<10; i++) { snprintf(key, 5, "FAN%X", i); if (kIOReturnSuccess == acpiDevice->validateObject(key)) { OSString* name = NULL; if (fanNames ) name = OSDynamicCast(OSString, fanNames->getObject(i)); if (!addTachometer(key, name ? name->getCStringNoCopy() : 0)) WarningLog("Can't add tachometer sensor, key %s", key); } else { snprintf(key, 5, "FTN%X", i); if (kIOReturnSuccess == acpiDevice->validateObject(key)) { OSString* name = NULL; if (fanNames ) name = OSDynamicCast(OSString, fanNames->getObject(i)); if (!addTachometer(key, name ? name->getCStringNoCopy() : 0)) WarningLog("Can't add tachometer sensor, key %s", key); } else break; } } //Next step - temperature keys if (kIOReturnSuccess == acpiDevice->validateObject("TCPU")) addSensor("TCPU", KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2); if (kIOReturnSuccess == acpiDevice->validateObject("TSYS")) addSensor("TSYS", KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2); if (kIOReturnSuccess == acpiDevice->validateObject("TDIM")) addSensor("TDIM", KEY_DIMM_TEMPERATURE, TYPE_SP78, 2); if (kIOReturnSuccess == acpiDevice->validateObject("TAMB")) addSensor("TAMB", KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2); if (kIOReturnSuccess == acpiDevice->validateObject("TCPP")) addSensor("TCPP", KEY_CPU_PROXIMITY_TEMPERATURE, TYPE_SP78, 2); // We should add also GPU reading stuff for those who has no supported plug in but have the value on EC registers //Voltage if (kIOReturnSuccess == acpiDevice->validateObject("VCPU")) addSensor("VSN0", KEY_CPU_VOLTAGE, TYPE_FP2E, 2); if (kIOReturnSuccess == acpiDevice->validateObject("VMEM")) addSensor("VSN0", KEY_MEMORY_VOLTAGE, TYPE_FP2E, 2); if (kIOReturnSuccess == acpiDevice->validateObject("VSN1")) addSensor("VSN1", "Vp0C", TYPE_FP2E, 2); if (kIOReturnSuccess == acpiDevice->validateObject("VSN2")) addSensor("VSN2", "Vp1C", TYPE_FP2E, 2); if (kIOReturnSuccess == acpiDevice->validateObject("VSN3")) addSensor("VSN3", "Vp2C", TYPE_FP2E, 2); //Amperage if (kIOReturnSuccess == acpiDevice->validateObject("ISN0")) addSensor("ISN0", "ICAC", TYPE_UI16, 2); if (kIOReturnSuccess == acpiDevice->validateObject("ISN1")) addSensor("ISN1", "Ip0C", TYPE_UI16, 2); if (kIOReturnSuccess == acpiDevice->validateObject("ISN2")) addSensor("ISN2", "Ip1C", TYPE_UI16, 2); if (kIOReturnSuccess == acpiDevice->validateObject("ISN3")) addSensor("ISN3", "Ip2C", TYPE_UI16, 2); //Power if (kIOReturnSuccess == acpiDevice->validateObject("PSN0")) addSensor("PSN0", "PC0C", TYPE_UI16, 2); if (kIOReturnSuccess == acpiDevice->validateObject("PSN1")) addSensor("PSN1", "PC1C", TYPE_UI16, 2); // AC Power/Battery if (kIOReturnSuccess == acpiDevice->validateObject("ACDC")) // Power Source Read AC/Battery { addSensor("ACDC", "ACEN", TYPE_UI8, 1); addSensor("ACDC", "ACFP", TYPE_FLAG, 1); addSensor("ACDC", "ACIN", TYPE_FLAG, 1); } // TODO real SMC returns ACID only when AC is plugged, if not is zeroed, so hardcoding it in plist is not OK IMHO // Same goes for ACIC, but no idea how we can get the AC current value.. // Here if ACDC returns 0 we need to set the on battery BATP flag // Battery stuff, need to implement rest of the keys once i figure those if (kIOReturnSuccess == acpiDevice->validateObject("BAK0")) // Battery 0 Current addSensor("BAK0", "B0AC", TYPE_SI16, 2); if (kIOReturnSuccess == acpiDevice->validateObject("BAK1")) // Battery 0 Voltage addSensor("BAK1", "B0AV", TYPE_UI16, 2); //Keys from info.plist OSString *tmpString = 0; OSData *tmpObj = 0; // UInt32 tmpUI32; // char tmpCString[7]; char acpiName[5]; char aKey[5]; OSIterator *iter = 0; const OSSymbol *dictKey = 0; OSDictionary *keysToAdd = 0; keysToAdd = OSDynamicCast(OSDictionary, getProperty("keysToAdd")); if (keysToAdd) { iter = OSCollectionIterator::withCollection(keysToAdd); if (iter) { while ((dictKey = (const OSSymbol *)iter->getNextObject())) { tmpObj = 0; snprintf(acpiName, 5, "%s", dictKey->getCStringNoCopy()); //WarningLog(" Found key %s", acpiName); tmpString = OSDynamicCast(OSString, keysToAdd->getObject(dictKey)); if (tmpString) { snprintf(aKey, 5, "%s", tmpString->getCStringNoCopy()); InfoLog("Custom name=%s key=%s", acpiName, aKey); if (kIOReturnSuccess == acpiDevice->validateObject(acpiName)) { if (aKey[0] == 'F') { if (!addTachometer(aKey, acpiName)) WarningLog("Can't add tachometer sensor, key %s", aKey); } else { addSensor(acpiName, aKey, TYPE_UI16, 2); } } } else { WarningLog(" no value for key %s", acpiName); } } iter->release(); } else { WarningLog(" can't interate keysToAdd"); } } else { WarningLog(" keysToAdd not found"); } registerService(0); return true; }
bool GeforceSensors::start(IOService * provider) { DebugLog("Starting..."); if (!super::start(provider)) return false; if (!(fakeSMC = waitForService(serviceMatching(kFakeSMCDeviceService)))) { WarningLog("Can't locate fake SMC device, kext will not load"); return false; } struct nouveau_device *device = &card; //Find card number card.card_index = getVacantGPUIndex(); if (card.card_index < 0) { nv_error(device, "failed to obtain vacant GPU index\n"); return false; } // map device memory // device->pcidev = (IOPCIDevice*)provider; if (device->pcidev) { device->pcidev->setMemoryEnable(true); if ((device->mmio = device->pcidev->mapDeviceMemoryWithIndex(0))) { nv_debug(device, "memory mapped successfully\n"); } else { nv_error(device, "failed to map memory\n"); return false; } } else { nv_error(device, "failed to assign PCI device\n"); return false; } // identify chipset if (!nouveau_identify(device)) return false; // shadow and parse bios //try to load bios from registry first from "vbios" property created by Chameleon boolloader if (OSData *vbios = OSDynamicCast(OSData, provider->getProperty("vbios"))) { device->bios.size = vbios->getLength(); device->bios.data = (u8*)IOMalloc(card.bios.size); memcpy(device->bios.data, vbios->getBytesNoCopy(), device->bios.size); } if (!device->bios.data || !device->bios.size || nouveau_bios_score(device, true) < 1) if (!nouveau_bios_shadow(device)) { if (device->bios.data && device->bios.size) { IOFree(card.bios.data, card.bios.size); device->bios.data = NULL; device->bios.size = 0; } nv_error(device, "unable to shadow VBIOS\n"); return false; } nouveau_vbios_init(device); nouveau_bios_parse(device); // initialize funcs and variables if (!nouveau_init(device)) { nv_error(device, "unable to initialize monitoring driver\n"); return false; } nv_info(device, "chipset: %s (NV%02X) bios: %02x.%02x.%02x.%02x\n", device->cname, (unsigned int)device->chipset, device->bios.version.major, device->bios.version.chip, device->bios.version.minor, device->bios.version.micro); if (device->card_type < NV_C0) { // init i2c structures nouveau_i2c_create(device); // setup nouveau i2c sensors nouveau_i2c_probe(device); } // Register sensors char key[5]; if (card.core_temp_get || card.board_temp_get) { nv_debug(device, "registering i2c temperature sensors...\n"); if (card.core_temp_get && card.board_temp_get) { snprintf(key, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, card.card_index); this->addSensor(key, TYPE_SP78, 2, 0); snprintf(key, 5, KEY_FORMAT_GPU_HEATSINK_TEMPERATURE, card.card_index); addSensor(key, TYPE_SP78, 2, 0); } else if (card.core_temp_get) { snprintf(key, 5, KEY_FORMAT_GPU_PROXIMITY_TEMPERATURE, card.card_index); addSensor(key, TYPE_SP78, 2, 0); } else if (card.board_temp_get) { snprintf(key, 5, KEY_FORMAT_GPU_PROXIMITY_TEMPERATURE, card.card_index); addSensor(key, TYPE_SP78, 2, 0); } } else if (card.temp_get) { nv_debug(device, "registering temperature sensors...\n"); snprintf(key, 5, KEY_FORMAT_GPU_PROXIMITY_TEMPERATURE, card.card_index); addSensor(key, TYPE_SP78, 2, 0); } if (card.clocks_get) { nv_debug(device, "registering clocks sensors...\n"); if (card.clocks_get(&card, nouveau_clock_core) > 0) { snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_FREQUENCY, card.card_index); addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, nouveau_clock_core); } if (card.clocks_get(&card, nouveau_clock_shader) > 0) { snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_SHADER_FREQUENCY, card.card_index); addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, nouveau_clock_shader); } if (card.clocks_get(&card, nouveau_clock_rop) > 0) { snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_ROP_FREQUENCY, card.card_index); addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, nouveau_clock_rop); } if (card.clocks_get(&card, nouveau_clock_memory) > 0) { snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_MEMORY_FREQUENCY, card.card_index); addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, nouveau_clock_memory); } } if (card.fan_pwm_get || card.fan_rpm_get) { nv_debug(device, "registering PWM sensors...\n"); if (card.fan_rpm_get && card.fan_rpm_get(device) > 0) { char title[6]; snprintf (title, 6, "GPU %X", card.card_index + 1); UInt8 fanIndex = 0; if (addTachometer( fanIndex)) { if (card.fan_pwm_get && card.fan_pwm_get(device) > 0) { snprintf(key, 5, KEY_FAKESMC_FORMAT_GPUPWM, fanIndex); addSensor(key, TYPE_UI8, TYPE_UI8_SIZE, 0); } } } } if (card.voltage_get && card.voltage.supported) { nv_debug(device, "registering voltage sensors...\n"); snprintf(key, 5, KEY_FORMAT_GPU_VOLTAGE, card.card_index); addSensor(key, TYPE_FP2E, TYPE_FPXX_SIZE, 0); } nv_info(device, "started\n"); return true; }
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 X3100monitor::start(IOService * provider) { if (!provider || !super::start(provider)) return false; if (!(fakeSMC = waitForService(serviceMatching(kFakeSMCDeviceService)))) { WarningLog("Can't locate fake SMC device, kext will not load"); return false; } IOMemoryDescriptor * theDescriptor; IOPhysicalAddress bar = (IOPhysicalAddress)((VCard->configRead32(kMCHBAR)) & ~0xf); DebugLog("Fx3100: register space=%08lx\n", (long unsigned int)bar); theDescriptor = IOMemoryDescriptor::withPhysicalAddress (bar, 0x2000, kIODirectionOutIn); // | kIOMapInhibitCache); if(theDescriptor != NULL) { mmio = theDescriptor->map(); if(mmio != NULL) { mmio_base = (volatile UInt8 *)mmio->getVirtualAddress(); #if DEBUG DebugLog(" MCHBAR mapped\n"); for (int i=0; i<0x2f; i +=16) { DebugLog("%04lx: ", (long unsigned int)i+0x1000); for (int j=0; j<16; j += 1) { DebugLog("%02lx ", (long unsigned int)INVID8(i+j+0x1000)); } DebugLog("\n"); } #endif } else { InfoLog(" MCHBAR failed to map\n"); return -1; } } char name[5]; //try to find empty key for (int i = 0; i < 0x10; i++) { snprintf(name, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, i); UInt8 length = 0; void * data = 0; IOReturn result = fakeSMC->callPlatformFunction(kFakeSMCGetKeyValue, true, (void *)name, (void *)&length, (void *)&data, 0); if (kIOReturnSuccess == result) { continue; } if (addSensor(name, TYPE_SP78, 2, i)) { numCard = i; break; } } if (kIOReturnSuccess != fakeSMC->callPlatformFunction(kFakeSMCAddKeyHandler, false, (void *)name, (void *)TYPE_SP78, (void *)2, this)) { WarningLog("Can't add key to fake SMC device, kext will not load"); return false; } return true; }
// Class free void VoodooPState::free(void) { WarningLog("Unloading"); IOService::free(); }