Exemplo n.º 1
0
bool SuperIODevice::detectITEFamilyChip()
{
    // IT87XX can enter only on port 0x2E
    port = 0x2E;

    ite_family_enter(port);
    
    id = superio_listen_port_word(port, kSuperIOChipIDRegister);

    HWSensorsDebugLog("probing device on 0x%x, id=0x%x", port, id);

    ldn = 0;
    vendor = "";
    
    switch (id) {
        case IT8512F:
        case IT8712F:
        case IT8716F:
        case IT8718F:
        case IT8720F:
        case IT8721F:
        case IT8726F:
        case IT8620E:
        case IT8728F:
        case IT8752F:
        case IT8771E:
        case IT8772E:
            model = id;
            ldn = kFintekITEHardwareMonitorLDN;
            vendor = "ITE";
            break;
    }
    
    if (model != 0 && ldn != 0) {

        HWSensorsDebugLog("detected %s %s, starting address sanity checks", vendor, superio_get_model_name(model));

        superio_select_logical_device(port, ldn);
        
        IOSleep(10);
        
        address = superio_listen_port_word(port, kSuperIOBaseAddressRegister);
        
        IOSleep(10);
        
        UInt16 verify = superio_listen_port_word(port, kSuperIOBaseAddressRegister);
        
        IOSleep(10);
        
        ite_family_exit(port);
        
        if (address != verify || address < 0x100 || (address & 0xF007) != 0)
            return false;
        
        return true;
    }
    else ite_family_exit(port);
    
    return false;
}
Exemplo n.º 2
0
/**
 *  For internal use, do not override
 *
 */
void FakeSMCPlugin::stop(IOService* provider)
{
    HWSensorsDebugLog("removing handler");

    if (OSCollectionIterator *iterator = OSCollectionIterator::withCollection(keyStore->getKeys())) {
        while (FakeSMCKey *key = OSDynamicCast(FakeSMCKey, iterator->getNextObject())) {
            if (key->getHandler() == this) {
                if (FakeSMCSensor *sensor = getSensor(key->getKey())) {
                    if (sensor->getGroup() == kFakeSMCTachometerSensor) {
                        UInt8 index = index_of_hex_char(sensor->getKey()[1]);
                        HWSensorsDebugLog("releasing Fan%X", index);
                        keyStore->releaseFanIndex(index);
                    }
                }

                key->setHandler(NULL);
            }
        }
        OSSafeRelease(iterator);
    }

    HWSensorsDebugLog("releasing sensors collection");

    sensors->flushCollection();

    super::stop(provider);
}
Exemplo n.º 3
0
void FakeSMCPlugin::stop(IOService* provider)
{
    HWSensorsDebugLog("[stop] removing handler");
    if (kIOReturnSuccess != storageProvider->callPlatformFunction(kFakeSMCRemoveKeyHandler, true, this, NULL, NULL, NULL))
        HWSensorsFatalLog("failed to remove handler from storage provider");
    
    HWSensorsDebugLog("[stop] releasing tachometers");
    // Release all tachometers
    if (OSCollectionIterator *iterator = OSCollectionIterator::withCollection(sensors)) {
        while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) {
            if (FakeSMCSensor *sensor = getSensor(key->getCStringNoCopy())) {
                if (sensor->getGroup() == kFakeSMCTachometerSensor) {
                    UInt8 index = index_of_hex_char(sensor->getKey()[1]);
                    HWSensorsInfoLog("releasing Fan%X", index);
                    if (!releaseFanIndex(index))
                        HWSensorsErrorLog("failed to release Fan index: %d", index);
                }
            }
        }
        OSSafeRelease(iterator);
    }
    
    HWSensorsDebugLog("[stop] releasing sensors collection");
    sensors->flushCollection();
	
	super::stop(provider);
}
Exemplo n.º 4
0
void LPCSensors::tachometerControlInit(UInt8 number, float target)
{
    HWSensorsDebugLog("fan control [%d] init with target = %d", number, (int)target);

    tachometerControls[number].target = target;
    tachometerControls[number].control = readTachometerControl(number);
    tachometerControls[number].samples = kLPCSensorsControlSamplingTimeout / kLPCSensorsControlSamplingInterval;
    tachometerControls[number].active = true;

    if (!timerScheduled) {
        timerEventSource->setTimeoutMS(kLPCSensorsControlSamplingInterval);
        timerScheduled = true;
        HWSensorsDebugLog("timer scheduled");
    }
}
Exemplo n.º 5
0
bool SuperIOPlugin::addTemperatureSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding temperature sensors...");
        
    for (int i = 0; i < temperatureSensorsLimit(); i++) 
    {				
        char key[8];

        snprintf(key, 8, "TEMPIN%X", i);
        
        if (OSObject* node = configuration->getObject(key)) {
            for (int j = 0; j < FakeSMCTemperatureCount; j++) {
                if (addSensorFromConfigurationNode(node, FakeSMCTemperature[j].name, FakeSMCTemperature[j].key, FakeSMCTemperature[j].type, FakeSMCTemperature[j].size, kFakeSMCTemperatureSensor, i))
                    break;
            }
            
            if (gpuIndex < 0)
                gpuIndex = takeVacantGPUIndex();
                
            if (gpuIndex >= 0) {
                snprintf(key, 5, KEY_FORMAT_GPU_HEATSINK_TEMPERATURE, gpuIndex);
                if (!addSensorFromConfigurationNode(node, "GPU", key, TYPE_SP78, TYPE_SPXX_SIZE, kFakeSMCTemperatureSensor, i)) {
                    releaseGPUIndex(gpuIndex);
                    gpuIndex = -1;
                }
            }
        }
    }

    return true;
}
Exemplo n.º 6
0
FakeSMCKey *FakeSMCKeyStore::addKeyWithHandler(const char *name, const char *type, unsigned char size, FakeSMCKeyHandler *handler)
{
	if (FakeSMCKey *key = getKey(name)) {

        FakeSMCKeyHandler *existedHandler = key->getHandler();

        if (handler->getProbeScore() < existedHandler->getProbeScore()) {
            HWSensorsErrorLog("key %s already handled with prioritized handler %s", name, existedHandler ? existedHandler->getName() : "*Unreferenced*");
            return 0;
        }
        else {
            HWSensorsInfoLog("key %s handler %s has been replaced with new prioritized handler %s", name, existedHandler ? existedHandler->getName() : "*Unreferenced*", handler ? handler->getName() : "*Unreferenced*");
        }

        key->setType(type);
        key->setSize(size);
        key->setHandler(handler);

		return key;
	}

	HWSensorsDebugLog("adding key %s with handler, type: %s, size: %d", name, type, size);

	if (FakeSMCKey *key = FakeSMCKey::withHandler(name, type, size, handler)) {
        //KEYSLOCK;
		keys->setObject(key);
        //KEYSUNLOCK;
		updateKeyCounterKey();
		return key;
	}

	HWSensorsErrorLog("failed to create key %s", name);

	return 0;
}
Exemplo n.º 7
0
bool LPCSensors::addTemperatureSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding temperature sensors...");

    for (int i = 0; i < temperatureSensorsLimit(); i++)
    {
        char key[8];

        snprintf(key, 8, "TEMPIN%X", i);

        if (OSObject* node = configuration->getObject(key)) {
            if (!addSensorFromNode(node, kFakeSMCCategoryTemperature, kFakeSMCTemperatureSensor, i)) {

                if (checkConfigurationNode(configuration, "GPU Die")) {

                    if (gpuIndex < 0)
                        gpuIndex = takeVacantGPUIndex();
                    else
                        continue;

                    snprintf(key, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, gpuIndex);

                    if (!addSensorFromConfigurationNode(node, key, TYPE_SP78, TYPE_SPXX_SIZE, kFakeSMCTemperatureSensor, i)) {
                        releaseGPUIndex(gpuIndex);
                        gpuIndex = -1;
                    }
                }
            }
        }
    }

    return true;
}
Exemplo n.º 8
0
bool LPCSensors::addVoltageSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding voltage sensors...");

    for (int i = 0; i < voltageSensorsLimit(); i++)
    {
        char key[5];

        snprintf(key, 5, "VIN%X", i);

        if (OSObject* node = configuration->getObject(key)) {
            if (!addSensorFromNode(node, kFakeSMCCategoryVoltage, kFakeSMCVoltageSensor, i)) {
                
                if (checkConfigurationNode(configuration, "GPU Core")) {

                    if (gpuIndex < 0)
                        gpuIndex = takeVacantGPUIndex();
                    else
                        continue;

                    snprintf(key, 5, KEY_FORMAT_GPU_VOLTAGE, gpuIndex);

                    if (!addSensorFromConfigurationNode(node, key, TYPE_FP2E, TYPE_FPXX_SIZE, kFakeSMCVoltageSensor, i)) {
                        releaseGPUIndex(gpuIndex);
                        gpuIndex = -1;
                    }
                }
            }
        }
    }

    return true;
}
FakeSMCKey *FakeSMCKeyStore::getKey(const char *name)
{
    KEYSLOCK;
    
    FakeSMCKey* key = 0;
    if (OSCollectionIterator *iterator = OSCollectionIterator::withCollection(keys)) {
        
        // Made the key name valid (4 char long): add trailing spaces if needed
        char validKeyNameBuffer[5];
        copySymbol(name, validKeyNameBuffer);
        
		while ((key = OSDynamicCast(FakeSMCKey, iterator->getNextObject()))) {
            UInt32 key1 = HWSensorsKeyToInt(&validKeyNameBuffer);
			UInt32 key2 = HWSensorsKeyToInt(key->getKey());
			if (key1 == key2) {
				break;
			}
		}
        
        OSSafeRelease(iterator);
	}
    KEYSUNLOCK;
    
    if (!key)
        HWSensorsDebugLog("key %s not found", name);
    
	return key;
}
Exemplo n.º 10
0
FakeSMCKey *FakeSMCKeyStore::getKey(const char *name)
{
    //KEYSLOCK;
    OSCollection *snapshotKeys = keys->copyCollection();
    //KEYSUNLOCK;

    if (OSCollectionIterator *iterator = OSCollectionIterator::withCollection(snapshotKeys)) {

        char validKeyNameBuffer[5];
        copySymbol(name, validKeyNameBuffer);

		while (FakeSMCKey *key = OSDynamicCast(FakeSMCKey, iterator->getNextObject())) {
            UInt32 key1 = HWSensorsKeyToInt(&validKeyNameBuffer);
			UInt32 key2 = HWSensorsKeyToInt(key->getKey());
			if (key1 == key2) {
				OSSafeRelease(iterator);
                OSSafeRelease(snapshotKeys);
				return key;
			}
		}

        OSSafeRelease(iterator);
	}

    OSSafeRelease(snapshotKeys);

 	HWSensorsDebugLog("key %s not found", name);

	return 0;
}
Exemplo n.º 11
0
bool SuperIOPlugin::addVoltageSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding voltage sensors...");
       
    for (int i = 0; i < voltageSensorsLimit(); i++)
    {				
        char key[5];
        
        snprintf(key, 5, "VIN%X", i);
        
        if (OSObject* node = configuration->getObject(key)) {
            for (int j = 0; j < FakeSMCVolatgeCount; j++) {
                if (addSensorFromConfigurationNode(node, FakeSMCVolatge[j].name, FakeSMCVolatge[j].key, FakeSMCVolatge[j].type, FakeSMCVolatge[j].size, kFakeSMCVoltageSensor, i))
                    break;
            }

            if (gpuIndex < 0)
                gpuIndex = takeVacantGPUIndex();
            
            if (gpuIndex >= 0) {
                snprintf(key, 5, KEY_FORMAT_GPU_VOLTAGE, gpuIndex);
                if (!addSensorFromConfigurationNode(node, "GPU", key, TYPE_FP2E, TYPE_FPXX_SIZE, kFakeSMCVoltageSensor, i)) {
                    releaseGPUIndex(gpuIndex);
                    gpuIndex = -1;
                }
            }
        }
    }

    return true;
}
Exemplo n.º 12
0
bool GPUSensors::start(IOService *provider)
{
    HWSensorsDebugLog("Starting...");
    
    if (!provider || !super::start(provider))
        return false;
    
    if (!(pciDevice = OSDynamicCast(IOPCIDevice, provider))) {
        HWSensorsFatalLog("no PCI device");
        return false;
    }

    
    if (!(workloop = getWorkLoop())) {
        HWSensorsFatalLog("failed to obtain workloop");
        return false;
    }
    
    if (!(timerEventSource = IOTimerEventSource::timerEventSource( this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &GPUSensors::probeEvent)))) {
        HWSensorsFatalLog("failed to initialize timer event source");
        return false;
    }
    
    if (kIOReturnSuccess != workloop->addEventSource(timerEventSource))
    {
        HWSensorsFatalLog("failed to add timer event source into workloop");
        timerEventSource->release();
        return false;
    }
    
    timerEventSource->setTimeoutMS(500);
    
    return true;
}
Exemplo n.º 13
0
void PTIDSensors::parseTemperatureName(OSString *name, UInt32 index)
{
    if (name && readTemperature(index)) {
        char key[5];
        char str[64];
        
        key[0] = '\0';
        
        if (name->isEqualTo("CPU Core Package DTS") || name->isEqualTo("CPU Package Temperature"))
            snprintf(key, 5, KEY_CPU_PACKAGE_TEMPERATURE);
        else if (name->isEqualTo("CPU Temperature"))
            snprintf(key, 5, KEY_CPU_PROXIMITY_TEMPERATURE);
        else if (name->isEqualTo("PCH Temperature") || name->isEqualTo("PCH DTS Temperature from PCH"))
            snprintf(key, 5, KEY_PCH_DIE_TEMPERATURE);
        else if (name->isEqualTo("MCH DTS Temperature from PCH"))
            snprintf(key, 5, KEY_MCH_DIODE_TEMPERATURE);
        else if (name->isEqualTo("Ambient Temperature"))
            snprintf(key, 5, KEY_AMBIENT_TEMPERATURE);
        else {
            for (UInt8 i = 0; i < 4; i++) {
                snprintf(str, 64, "TS-on-DIMM%X Temperature", i);
                
                if (name->isEqualTo(str)) {
                    snprintf(key, 5, KEY_FORMAT_DIMM_TEMPERATURE, i);
                    break;
                }
                
                snprintf(str, 64, "Channel %X DIMM Temperature", i);
                
                if (name->isEqualTo(str)) {
                    snprintf(key, 5, KEY_FORMAT_DIMM_TEMPERATURE, i);
                    break;
                }
            }
            
            if (key[0] == '\0') {
                for (UInt8 i = 0; i < 8; i++) {
                    snprintf(str, 64, "TZ0%X _TMP", i);
                    
                    if (name->isEqualTo(str)) {
                        snprintf(key, 5, KEY_FORMAT_THERMALZONE_TEMPERATURE, i + 1);
                        break;
                    }
                    
                    snprintf(str, 64, "CPU Core %X DTS", i);
                    
                    if (name->isEqualTo(str)) {
                        snprintf(key, 5, KEY_FORMAT_CPU_DIODE_TEMPERATURE, i);
                        break;
                    }
                }
            }
        }
        
        if (key[0] != '\0') {
            HWSensorsDebugLog("adding %s sensor", name->getCStringNoCopy());
            addSensor(key, TYPE_SP78, TYPE_SPXX_SIZE, kFakeSMCTemperatureSensor, index);
        }
    }
}
Exemplo n.º 14
0
UInt32 FakeSMCDevice::loadKeysFromNVRAM()
{
    UInt32 count = 0;
    
    // Find driver and load keys from NVRAM
    if (OSDictionary *matching = serviceMatching("IODTNVRAM")) {
        if (IODTNVRAM *nvram = OSDynamicCast(IODTNVRAM, waitForMatchingService(matching, 1000000000ULL * 15))) {
            
            useNVRAM = true;
            
            if ((genericNVRAM = (0 == strncmp(nvram->getName(), "AppleNVRAM", sizeof("AppleNVRAM")))))
                HWSensorsInfoLog("fallback to generic NVRAM methods");
            
            OSSerialize *s = OSSerialize::withCapacity(0); // Workaround for IODTNVRAM->getPropertyTable returns IOKitPersonalities instead of NVRAM properties dictionary
            
            if (nvram->serializeProperties(s)) {
                if (OSDictionary *props = OSDynamicCast(OSDictionary, OSUnserializeXML(s->text()))) {
                    if (OSCollectionIterator *iterator = OSCollectionIterator::withCollection(props)) {
                        
                        size_t prefix_length = strlen(kFakeSMCKeyPropertyPrefix);
                        
                        char name[5]; name[4] = 0;
                        char type[5]; type[4] = 0;
                        
                        while (OSString *property = OSDynamicCast(OSString, iterator->getNextObject())) {
                            const char *buffer = static_cast<const char *>(property->getCStringNoCopy());
                            
                            if (property->getLength() >= prefix_length + 1 + 4 + 1 + 0 && 0 == strncmp(buffer, kFakeSMCKeyPropertyPrefix, prefix_length)) {
                                if (OSData *data = OSDynamicCast(OSData, props->getObject(property))) {
                                    strncpy(name, buffer + prefix_length + 1, 4); // fakesmc-key-???? ->
                                    strncpy(type, buffer + prefix_length + 1 + 4 + 1, 4); // fakesmc-key-xxxx-???? ->
                                    
                                    if (addKeyWithValue(name, type, data->getLength(), data->getBytesNoCopy())) {
                                        HWSensorsDebugLog("key %s of type %s loaded from NVRAM", name, type);
                                        count++;
                                    }
                                }
                            }
                        }
                        
                        OSSafeRelease(iterator);
                    }
                    
                    OSSafeRelease(props);
                }
            }
            
            OSSafeRelease(s);
            OSSafeRelease(nvram);
        }
        else {
            HWSensorsWarningLog("NVRAM is unavailable");
        }
        
        OSSafeRelease(matching);
    }
    
    return count;
}
Exemplo n.º 15
0
void LPCSensors::tachometerControlCancel(UInt8 number)
{
    disableTachometerControl(number);

    tachometerControls[number].active = false;

    HWSensorsDebugLog("fan control [%d] canceled", number);
}
Exemplo n.º 16
0
IOReturn GPUSensors::delayedStartEvent()
{
    HWSensorsDebugLog("delayed start...");

    onAcceleratorFound(pciDevice);
    releaseTimerEventSource(timerEventSource);
    return kIOReturnSuccess;
}
Exemplo n.º 17
0
void GPUSensors::stop(IOService *provider)
{
    HWSensorsDebugLog("Stop...");
    
    releaseTimerEventSource(timerEventSource);
    
    super::stop(provider);
}
Exemplo n.º 18
0
bool LPCSensors::tachometerControlSample(UInt8 number)
{
    if (tachometerControls[number].active) {

        float value = readTachometer(number);

        tachometerControls[number].error = tachometerControls[number].target - value;

        float difference = tachometerControls[number].error - tachometerControls[number].prevError;
        double derivative = difference / (kLPCSensorsControlSamplingInterval / 1000.0);

        tachometerControls[number].integral += tachometerControls[number].error *
        (kLPCSensorsControlSamplingInterval / 1000.0);

        tachometerControls[number].prevError = tachometerControls[number].error;

        float drive =
            tachometerControls[number].error * kLPCSensorsKp +
            tachometerControls[number].integral * kLPCSensorsKi +
            derivative * kLPCSensorsKd;

        tachometerControls[number].control +=  drive;

        tachometerControls[number].control = CLIP_CONTROL(tachometerControls[number].control);

        HWSensorsDebugLog("fan control [%d] probe error = %d control = %d drive = %d",
                          number,
                          (int)tachometerControls[number].error,
                          (int)tachometerControls[number].control,
                          (int)drive);

        writeTachometerControl(number, tachometerControls[number].control);

        if (--tachometerControls[number].samples <= 0) {
            HWSensorsDebugLog("fan control [%d] finished", number);
            tachometerControls[number].active = false;
            return false;
        }

        return true;
    }

    return false;
}
Exemplo n.º 19
0
FakeSMCKey *FakeSMCKeyStore::getKey(unsigned int index)
{
    //KEYSLOCK;
    FakeSMCKey *key = OSDynamicCast(FakeSMCKey, keys->getObject(index));
    //KEYSUNLOCK;

	if (!key) HWSensorsDebugLog("key with index %d not found", index);

	return key;
}
Exemplo n.º 20
0
bool GmaSensors::managedStart(IOService *provider)
{
	IOPhysicalAddress bar = (IOPhysicalAddress)((pciDevice->configRead32(kMCHBAR)) & ~0xf);
    
	HWSensorsDebugLog("Fx3100: register space=%08lx", (long unsigned int)bar);
	
	if(IOMemoryDescriptor * theDescriptor = IOMemoryDescriptor::withPhysicalAddress (bar, 0x2000, kIODirectionOutIn)) {
		if ((mmio = theDescriptor->map())) {
            
			mmio_base = (volatile UInt8 *)mmio->getVirtualAddress();

			/*HWSensorsDebugLog("MCHBAR mapped");
            
			for (int i = 0; i < 0x2f; i += 16) {
				HWSensorsDebugLog("%04lx: ", (long unsigned int)i+0x1000);
				for (int j=0; j<16; j += 1) {
					HWSensorsDebugLog("%02lx ", (long unsigned int)INVID8(i+j+0x1000));
				}
            HWSensorsDebugLog("");
			}*/
	
		}
		else {
            HWSensorsInfoLog("MCHBAR failed to map");
            return false;
        }
    }
    
    enableExclusiveAccessMode();
    
    //Find card number
    gpuIndex = takeVacantGPUIndex();
    
    if (gpuIndex < 0) {
        HWSensorsFatalLog("failed to obtain vacant GPU index");
        return false;
    }
    
    char key[5];
    
    snprintf(key, 5, KEY_FORMAT_GPU_PROXIMITY_TEMPERATURE, gpuIndex);
    
    if (!addSensor(key, TYPE_SP78, 2, kFakeSMCTemperatureSensor, 0)) {
        HWSensorsFatalLog("failed to register temperature sensor");
        releaseGPUIndex(gpuIndex);
        gpuIndex = -1;
        return false;
    }
    
    disableExclusiveAccessMode();
    
    registerService();
    
	return true;
}
Exemplo n.º 21
0
OSDictionary *FakeSMCPlugin::getConfigurationNode(OSDictionary *root, OSString *name)
{
    OSDictionary *configuration = NULL;
    
    if (root && name) {
        HWSensorsDebugLog("looking up for configuration node: %s", name->getCStringNoCopy());
        
        if (!(configuration = OSDynamicCast(OSDictionary, root->getObject(name))))
            if (OSString *link = OSDynamicCast(OSString, root->getObject(name)))
                configuration = getConfigurationNode(root, link);
    }
    
    return configuration;
}
Exemplo n.º 22
0
OSDictionary *SuperIOMonitor::lookupConfiguration(OSDictionary *root, OSString *name)
{
    OSDictionary *configuration = NULL;
    
    if (root && name) {
        HWSensorsDebugLog("looking up for configuration node: %s", name->getCStringNoCopy());
        
        if (!(configuration = OSDynamicCast(OSDictionary, root->getObject(name))))
            if (OSString *link = OSDynamicCast(OSString, root->getObject(name)))
                configuration = lookupConfiguration(root, link);    
    }
    
    return configuration;
}
Exemplo n.º 23
0
bool SuperIOPlugin::addTachometerSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding tachometer sensors...");
    
    for (int i = 0; i < tachometerSensorsLimit(); i++) {
        char key[7];
        snprintf(key, 7, "FANIN%X", i);
        
        if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key)))
            if (!addTachometer(i, (name->getLength() > 0 ? name->getCStringNoCopy() : 0)))
                HWSensorsWarningLog("failed to add tachometer sensor %d", i);
    }
    
    return true;
}
Exemplo n.º 24
0
FakeSMCSensor *FakeSMCPlugin::addSensor(const char *key, const char *type, UInt8 size, UInt32 group, UInt32 index, float reference, float gain, float offset)
{   
    if (getSensor(key)) {
        HWSensorsDebugLog("will not add handler for key %s, key already handled", key);
		return NULL;
    }
	
    if (FakeSMCSensor *sensor = FakeSMCSensor::withOwner(this, key, type, size, group, index, reference, gain, offset)) {
        if (addSensor(sensor))
            return sensor;
        else 
            OSSafeRelease(sensor);
    }
	
	return NULL;
}
Exemplo n.º 25
0
bool LPCSensors::addTachometerSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding tachometer sensors...");

    char key[7];
    UInt16 value = 0;

    // FAN manual control key
    addSensorForKey(KEY_FAN_MANUAL, SMC_TYPE_UI16, SMC_TYPE_UI16_SIZE, kLPCSensorsFanManualSwitch, 0);

    int location = LEFT_LOWER_FRONT;

    for (int i = 0; i < tachometerSensorsLimit(); i++) {
        
        UInt8 fanIndex;

        snprintf(key, 7, "FANIN%X", i);

        if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key))){
            if (addTachometer(i, name->getLength() > 0 ? name->getCStringNoCopy() : 0, FAN_RPM, 0, (FanLocationType)location++, &fanIndex)){

                if (isTachometerControlable(i) && fanIndex < UINT8_MAX) {

                    tachometerControls[i].number = fanIndex;
                    tachometerControls[i].target = -1;
                    tachometerControls[i].minimum = -1;

                    // Minimum RPM and fan control sensor
                    snprintf(key, 5, KEY_FORMAT_FAN_MIN, fanIndex);
                    addSensorForKey(key, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, kLPCSensorsFanMinController, i);

                    // Maximum RPM
                    snprintf(key, 5, KEY_FORMAT_FAN_MAX, fanIndex);
                    FakeSMCKey::encodeFloatValue(kLPCSensorsMaxRPM, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, &value);
                    setKeyValue(key, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, &value);

                    // Target RPM and fan control sensor
                    snprintf(key, 5, KEY_FORMAT_FAN_TARGET, fanIndex);
                    addSensorForKey(key, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, kLPCSensorsFanTargetController, i);
                }
            }
            else HWSensorsWarningLog("failed to add tachometer sensor %d", i);
        }
    }

    return true;
}
Exemplo n.º 26
0
bool GPUSensors::start(IOService *provider)
{
    HWSensorsDebugLog("Starting...");

    int arg_value = 1;

    if (PE_parse_boot_argn("-gpusensors-disable", &arg_value, sizeof(arg_value))) {
        return false;
    }
    
    if (!provider || !super::start(provider))
        return false;
    
    if (!(pciDevice = OSDynamicCast(IOPCIDevice, provider))) {
        HWSensorsFatalLog("no PCI device");
        return false;
    }

    if (!onStartUp(provider))
        return false;

    if (shouldWaitForAccelerator()) {
        if (!(workloop = getWorkLoop())) {
            HWSensorsFatalLog("failed to obtain workloop");
            return false;
        }
        
        if (!(timerEventSource = IOTimerEventSource::timerEventSource( this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &GPUSensors::probeEvent)))) {
            HWSensorsFatalLog("failed to initialize startup check timer event source");
            return false;
        }
        
        if (kIOReturnSuccess != workloop->addEventSource(timerEventSource))
        {
            HWSensorsFatalLog("failed to add startup check timer event source into workloop");
            timerEventSource->release();
            return false;
        }
        
        timerEventSource->setTimeoutMS(100);
    }
    else return managedStart(provider);
    
    return true;
}
Exemplo n.º 27
0
IOReturn GPUSensors::probeEvent()
{
    HWSensorsDebugLog("Probe event...");

    if (acceleratorLoadedCheck()) {
        releaseTimerEventSource;
        onAcceleratorFound(pciDevice);
    }
    else if (probeCounter++ == (1000.0f / (float)kGPUSensorsAcceleratorWaitCycle) * 45) {
        releaseTimerEventSource;
        onTimeoutExceeded(pciDevice);
    }
    else {
        if (probeCounter > 0 && !(probeCounter % ((int)(1000.0f / (float)kGPUSensorsAcceleratorWaitCycle) * 15)))
            HWSensorsInfoLog("still waiting for accelerator to start...");
        
        timerEventSource->setTimeoutMS(kGPUSensorsAcceleratorWaitCycle);
    }
    
    return kIOReturnSuccess;
}
Exemplo n.º 28
0
IOReturn LPCSensors::woorkloopTimerEvent(void)
{
    bool active = false;

    for (int index = 0; index < tachometerSensorsLimit(); index ++) {
        if (tachometerControls[index].active && tachometerControlSample(index)) {
            active = true;
        }
    }

    if (active) {
        timerEventSource->setTimeoutMS(kLPCSensorsControlSamplingInterval);
        timerScheduled = true;
        HWSensorsDebugLog("timer scheduled");
    }
    else {
        timerScheduled = false;
    }
    
    return kIOReturnSuccess;
}
Exemplo n.º 29
0
bool GeforceSensors::startupCheck(IOService *provider)
{
    HWSensorsDebugLog("Initializing...");

    struct nouveau_device *device = &card;

    if ((card.card_index = takeVacantGPUIndex()) < 0) {
        nv_fatal(device, "failed to take vacant GPU index\n");
        return false;
    }

    // map device memory
    if ((device->pcidev = pciDevice)) {

        device->pcidev->setMemoryEnable(true);

        if ((device->mmio = device->pcidev->mapDeviceMemoryWithIndex(0))) {
            nv_debug(device, "memory mapped successfully\n");
        }
        else {
            nv_fatal(device, "failed to map memory\n");
            return false;
        }
    }
    else {
        HWSensorsFatalLog("(pci%d): [Fatal] failed to assign PCI device", pciDevice->getBusNumber());
        return false;
    }

    // identify chipset
    if (!nouveau_identify(device)) {
        return false;
    }

    if (!shadowBios()) {
        nv_error(device, "early VBIOS shadow failed, will try after accelerator started\n");
    }

    return true;
}
Exemplo n.º 30
0
bool SuperIOMonitor::addTemperatureSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding temperature sensors...");
    
    for (int i = 0; i < temperatureSensorsLimit(); i++) 
    {				
        char key[8];
        OSString* name;
        float reference = 0.0f;
        float gain = 0.0f;
        float offset = 0.0f;

        snprintf(key, 8, "TEMPIN%X", i);
        
        if (process_sensor_entry(configuration->getObject(key), &name, &reference, &gain, &offset)) {
            if (name->isEqualTo("CPU")) {
                if (!addSensor(KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, TYPE_SPXX_SIZE, kSuperIOTemperatureSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add CPU temperature sensor");
            }
            if (name->isEqualTo("CPU Proximity")) {
                if (!addSensor(KEY_CPU_PROXIMITY_TEMPERATURE, TYPE_SP78, TYPE_SPXX_SIZE, kSuperIOTemperatureSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add CPU Proximity temperature sensor");
            }
            else if (name->isEqualTo("System")) {				
                if (!addSensor(KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, TYPE_SPXX_SIZE, kSuperIOTemperatureSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add System temperature sensor");
            }
            else if (name->isEqualTo("Ambient")) {				
                if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, TYPE_SPXX_SIZE, kSuperIOTemperatureSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add Ambient temperature sensor");
            }
            else if (name->isEqualTo("PCH")) {				
                if (!addSensor(KEY_PCH_DIE_TEMPERATURE, TYPE_SP78, TYPE_SPXX_SIZE, kSuperIOTemperatureSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add PCH temperature sensor");
            }
        }
    }

    return true;
}