コード例 #1
0
ファイル: PTIDSensors.cpp プロジェクト: adreamsky/HWSensors
bool PTIDSensors::start(IOService * provider)
{
	if (!super::start(provider))
        return false;
    
	acpiDevice = (IOACPIPlatformDevice *)provider;
	
	if (!acpiDevice) {
        HWSensorsFatalLog("ACPI device not ready");
        return false;
    }
    
    // Update timers
    clock_get_system_nanotime((clock_sec_t*)&temperatureNextUpdate.tv_sec, (clock_nsec_t*)&temperatureNextUpdate.tv_nsec);
    
    acpiDevice->evaluateInteger("IVER", &version);
    
    if (version == 0) {
        OSString *name = OSDynamicCast(OSString, getProperty("IONameMatched"));
        
        if (name && name->isEqualTo("INT3F0D"))
            version = 0x30000;
        else
            return false;
    }
    
    setProperty("version", version, 64);
    
    // Parse sensors
    switch (version) {
        case 0x30000: {
            OSObject *object = NULL;
            
            // Temperatures
            if(kIOReturnSuccess == acpiDevice->evaluateObject("TSDL", &object) && object) {
                
                OSArray *description = OSDynamicCast(OSArray, object);
                
                if (OSIterator *iterator = OSCollectionIterator::withCollection(description)) {
                    
                    HWSensorsDebugLog("Parsing temperatures...");
                    
                    UInt32 count = 0;
                    
                    while (OSObject *item = iterator->getNextObject()) {
                        parseTemperatureName(OSDynamicCast(OSString, item), count / 2);
                        count += 2;
                    }
                }
            }
            else HWSensorsErrorLog("failed to evaluate TSDL table");
            
            // Tachometers
            if(kIOReturnSuccess == acpiDevice->evaluateObject("OSDL", &object) && object) {
                
                OSArray *description = OSDynamicCast(OSArray, object);
                
                if (OSIterator *iterator = OSCollectionIterator::withCollection(description)) {
                    
                    HWSensorsDebugLog("Parsing tachometers...");
                    
                    UInt32 count = 0;
                    
                    while (OSObject *item = iterator->getNextObject()) {
                        parseTachometerName(OSDynamicCast(OSString, item), count / 3);
                        count += 3;
                    }
                }
            }
            else HWSensorsErrorLog("failed to evaluate OSDL table");
            
            break;
        }
            
        case 0x20001: {
            OSObject *object = NULL;
            
            // Temperatures
            if(kIOReturnSuccess == acpiDevice->evaluateObject("TMPV", &object) && object) {
                
                OSArray *description = OSDynamicCast(OSArray, object);
                
                if (OSIterator *iterator = OSCollectionIterator::withCollection(description)) {
                    
                    HWSensorsDebugLog("Parsing temperatures...");
                    
                    UInt32 count = 0;
                    
                    while (OSObject *item = iterator->getNextObject()) {
                        parseTemperatureName(OSDynamicCast(OSString, item), count + 1);
                        count += 3;
                    }
                }
            }
            else HWSensorsErrorLog("failed to evaluate TMPV table");
            
            // Tachometers
            if(kIOReturnSuccess == acpiDevice->evaluateObject("OSDV", &object) && object) {
                
                OSArray *description = OSDynamicCast(OSArray, object);
                
                if (OSIterator *iterator = OSCollectionIterator::withCollection(description)) {
                    
                    HWSensorsDebugLog("Parsing tachometers...");
                    
                    UInt32 count = 0;
                    
                    while (OSObject *item = iterator->getNextObject()) {
                        parseTachometerName(OSDynamicCast(OSString, item), count + 2);
                        count++;
                    }
                }
            }
            else HWSensorsErrorLog("failed to evaluate OSDV table");
            
            break;
        }
            
        default:
            HWSensorsFatalLog("usupported interface version: 0x%x", (UInt32)version);
            return false;
    }
    
    registerService();
    
    HWSensorsInfoLog("started");
    
	return true;
}
コード例 #2
0
ファイル: PTIDSensors.cpp プロジェクト: coercion/HWSensors
bool PTIDSensors::start(IOService * provider)
{
	if (!super::start(provider))
        return false;
    
	acpiDevice = (IOACPIPlatformDevice *)provider;
	
	if (!acpiDevice) {
        HWSensorsFatalLog("ACPI device not ready");
        return false;
    }
    
    // Update timers
    temperaturesLastUpdated = ptimer_read() - NSEC_PER_SEC;
    tachometersLastUpdated = temperaturesLastUpdated;
    
    acpiDevice->evaluateInteger("IVER", &version);
    
    if (version == 0) {
        OSString *name = OSDynamicCast(OSString, provider->getProperty("name"));
        
        if (name && name->isEqualTo("INT3F0D"))
            version = 0x30000;
        else
            return false;
    }
    
    setProperty("version", version, 64);
    
    // Parse sensors
    switch (version) {
        case 0x30000: {
            OSObject *object = NULL;
            
            // Temperatures
            if(kIOReturnSuccess == acpiDevice->evaluateObject("TSDL", &object) && object) {
                
                OSArray *description = OSDynamicCast(OSArray, object);
                
                HWSensorsDebugLog("Parsing temperatures...");
                
                for (UInt32 index = 1; index < description->getCount(); index += 2) {
                    parseTemperatureName(OSDynamicCast(OSString, description->getObject(index)), (index - 1) / 2);
                }
            }
            else HWSensorsErrorLog("failed to evaluate TSDL table");
            
            // Tachometers
            if(kIOReturnSuccess == acpiDevice->evaluateObject("OSDL", &object) && object) {
                
                OSArray *description = OSDynamicCast(OSArray, object);
                
                HWSensorsDebugLog("Parsing tachometers...");
                
                for (UInt32 index = 2; index < description->getCount(); index += 3) {
                    parseTachometerName(OSDynamicCast(OSString, description->getObject(index)), OSDynamicCast(OSString, description->getObject(index - 1)), (index - 2) / 3);
                }
            }
            else HWSensorsErrorLog("failed to evaluate OSDL table");
            
            break;
        }
            
        case 0x20001: {
            OSObject *object = NULL;
            
            // Temperatures
            if(kIOReturnSuccess == acpiDevice->evaluateObject("TMPV", &object) && object) {
                
                OSArray *description = OSDynamicCast(OSArray, object);
                
                for (UInt32 index = 1; index < description->getCount(); index += 3) {
                    parseTemperatureName(OSDynamicCast(OSString, description->getObject(index)), index + 1);
                }
            }
            else HWSensorsErrorLog("failed to evaluate TMPV table");
            
            // Tachometers
            if(kIOReturnSuccess == acpiDevice->evaluateObject("OSDV", &object) && object) {
                
                OSArray *description = OSDynamicCast(OSArray, object);
                
                for (UInt32 index = 2; index < description->getCount(); index += 4) {
                    parseTachometerName(OSDynamicCast(OSString, description->getObject(index)), OSDynamicCast(OSString, description->getObject(index - 1)), index + 1);
                }
            }
            else HWSensorsErrorLog("failed to evaluate OSDV table");
            
            break;
        }
            
        default:
            HWSensorsFatalLog("usupported interface version: 0x%x", (unsigned int)version);
            return false;
    }
    
    registerService();
    
    HWSensorsInfoLog("started");
    
	return true;
}
コード例 #3
0
bool PTIDSensors::start(IOService * provider)
{
	if (!super::start(provider))
        return false;
    
	acpiDevice = (IOACPIPlatformDevice *)provider;
	
	if (!acpiDevice) {
        HWSensorsFatalLog("ACPI device not ready");
        return false;
    }
    
    // On some computers (eg. RehabMan's ProBook 4530s), the system will hang on startup
    // if kernel cache is used, because of the early call to updateTemperatures and/or
    // updateTachometers.  At least that is the case with an SSD and a valid pre-linked
    // kernel, along with kernel cache enabled.  This 1000ms sleep seems to fix the problem,
    // enabling a clean boot with PTIDSensors enabled.
    IOSleep(1000);
    
    // Update timers
    temperaturesLastUpdated = ptimer_read() - NSEC_PER_SEC;
    tachometersLastUpdated = temperaturesLastUpdated;
    
    acpiDevice->evaluateInteger("IVER", &version);
    
    if (version == 0) {
        OSString *name = OSDynamicCast(OSString, provider->getProperty("name"));
        
        if (name && name->isEqualTo("INT3F0D"))
            version = 0x30000;
        else
            return false;
    }
    
    setProperty("version", version, 64);
    
    // Parse sensors
    switch (version) {
        case 0x30000: {
            OSObject *object = NULL;
            
            // Temperatures
            if(kIOReturnSuccess == acpiDevice->evaluateObject("TSDL", &object) && object) {
                if (OSArray *description = OSDynamicCast(OSArray, object)) {
                    HWSensorsDebugLog("Parsing temperatures...");
                    
                    int count = description->getCount();
                    for (int i = 1; i < count; i += 2) {
                        parseTemperatureName(OSDynamicCast(OSString, description->getObject(i)), i/2);
                    }
                }
            }
            else HWSensorsErrorLog("failed to evaluate TSDL table");
            
            // Tachometers
            if(kIOReturnSuccess == acpiDevice->evaluateObject("OSDL", &object) && object) {
                if (OSArray *description = OSDynamicCast(OSArray, object)) {
                    HWSensorsDebugLog("Parsing tachometers...");
                    
                    int count = description->getCount();
                    for (int i = 2; i < count; i += 3) {
                        parseTachometerName(OSDynamicCast(OSString, description->getObject(i)), OSDynamicCast(OSString, description->getObject(i-1)), i/3);
                    }
                }
            }
            else HWSensorsErrorLog("failed to evaluate OSDL table");
            break;
        }
            
        case 0x20001: {
            OSObject *object = NULL;
            
            // Temperatures
            if (kIOReturnSuccess == acpiDevice->evaluateObject("TMPV", &object) && object) {
                if (OSArray *description = OSDynamicCast(OSArray, object)) {
                    HWSensorsDebugLog("Parsing temperatures...");
                    
                    int count = description->getCount();
                    for (int i = 1; i < count; i += 3) {
                        parseTemperatureName(OSDynamicCast(OSString, description->getObject(i)), i+1);
                    }
                }
            }
            else HWSensorsErrorLog("failed to evaluate TMPV table");
            
            // Tachometers
            if (kIOReturnSuccess == acpiDevice->evaluateObject("OSDV", &object) && object) {
                if (OSArray *description = OSDynamicCast(OSArray, object)) {
                    HWSensorsDebugLog("Parsing tachometers...");
                    
                    int count = description->getCount();
                    for (int i = 2; i < count; i += 4) {
                        parseTachometerName(OSDynamicCast(OSString, description->getObject(i)), OSDynamicCast(OSString, description->getObject(i-1)), i+1);
                    }
                }
            }
            else HWSensorsErrorLog("failed to evaluate OSDV table");
            break;
        }
            
        default:
            HWSensorsFatalLog("usupported interface version: 0x%x", (UInt32)version);
            return false;
    }
    
    registerService();
    
    HWSensorsInfoLog("started");
    
	return true;
}