Exemplo n.º 1
0
void ACPIProbe::logValue(const char* method, OSObject *value)
{
    if (OSNumber *number = OSDynamicCast(OSNumber, value)) {
        ACPISensorsInfoLog("%s = %lld", method, number->unsigned64BitValue());
    }
    else if (OSString *string = OSDynamicCast(OSString, value)) {
        ACPISensorsInfoLog("%s = %s", method, string->getCStringNoCopy());
    }
    else if (OSData *data = OSDynamicCast(OSData, value)) {
        IOLog ("%s (%s): %s = 0x", getName(), acpiDevice->getName(), method);
        const UInt8 *buffer = (const UInt8*)data->getBytesNoCopy();
        for (unsigned int i = 0; i < data->getLength(); i++) {
            IOLog ("%02x", buffer[i]);
        }
        IOLog ("\n");
    }
    else if (OSArray *array = OSDynamicCast(OSArray, value)) {
        for (unsigned int i = 0; i < array->getCount(); i++) {
            char name[64];
            
            snprintf(name, 64, "%s[%d]", method, i);
            
            logValue(name, array->getObject(i));
        }
    }
    else {
        ACPISensorsInfoLog("call %s (data not shown)", method);
    }
}
Exemplo n.º 2
0
void ACPIProbe::addProfile(OSString *name, OSArray *methods, OSNumber *interval, OSNumber *timeout, OSNumber *verbose)
{
    if (ACPIProbeProfile *profile = ACPIProbeProfile::withParameters(name, methods, interval, timeout, verbose)) {
        profiles->setObject(name, profile);
        profileList->setObject(profile);
        ACPISensorsInfoLog("'%s' profile loaded", name->getCStringNoCopy());
    }
}
Exemplo n.º 3
0
void ACPIProbe::logValue(const char* method, OSObject *value)
{
    if (OSNumber *number = OSDynamicCast(OSNumber, value)) {
        ACPISensorsInfoLog("%s = %lld", method, number->unsigned64BitValue());
    }
    else if (OSArray *array = OSDynamicCast(OSArray, value)) {
        for (unsigned int i = 0; i < array->getCount(); i++) {
            char name[64];
            
            snprintf(name, 64, "%s[%d]", method, i);
            
            logValue(name, array->getObject(i));
        }
    }
}
Exemplo n.º 4
0
IOReturn ACPIProbe::setActiveProfile(const char *name)
{
    if (profiles && profiles->getCount()) {

        if (ACPIProbeProfile *profile = (ACPIProbeProfile *)profiles->getObject(name)) {
            activeProfile = profile;
            activeProfile->startedAt = 0;

            timerEventSource->cancelTimeout();
            timerEventSource->setTimeoutMS(100);

            ACPISensorsInfoLog("'%s' profile activated", name);
            return kIOReturnSuccess;
        }
        else {
            return kIOReturnBadArgument;
        }
    }

    return kIOReturnAborted;
}
Exemplo n.º 5
0
bool ACPIProbe::start(IOService * provider)
{
    ACPISensorsDebugLog("starting...");
    
	if (!super::start(provider))
        return false;
    
	if (!(acpiDevice = OSDynamicCast(IOACPIPlatformDevice, provider))) {
        ACPISensorsFatalLog("ACPI device not ready");
        return false;
    }
    
    methods = OSArray::withCapacity(0);
    OSNumber *interval = NULL;
    OSNumber *timeout = NULL;
    OSBoolean *logging = NULL;
    OSArray *list = NULL;
    
    
    // Try to load configuration from info.plist first
    if (OSDictionary *configuration = getConfigurationNode())
    {
        OSBoolean* disable = OSDynamicCast(OSBoolean, configuration->getObject("DisableDevice"));
        if (disable && disable->isTrue())
            return false;
        
        interval = OSDynamicCast(OSNumber, configuration->getObject("PollingInterval"));
        timeout = OSDynamicCast(OSNumber, configuration->getObject("PollingTimeout"));
        logging = OSDynamicCast(OSBoolean, configuration->getObject("LoggingEnabled"));
        list = OSDynamicCast(OSArray, configuration->getObject("Methods"));
    }
    // Try to load configuration provided by ACPI device
    else {
        OSObject *object = NULL;
        
        if (kIOReturnSuccess == acpiDevice->evaluateObject("INVL", &object) && object)
            interval = OSDynamicCast(OSNumber, object);
        
        if (kIOReturnSuccess == acpiDevice->evaluateObject("TOUT", &object) && object)
            timeout = OSDynamicCast(OSNumber, object);
        
        if (kIOReturnSuccess == acpiDevice->evaluateObject("LOGG", &object) && object) {
            if (OSNumber *number = OSDynamicCast(OSNumber, object)) {
                logging = OSBoolean::withBoolean(number->unsigned8BitValue() == 1);
            }
        }
        
        if (kIOReturnSuccess == acpiDevice->evaluateObject("LIST", &object) && object)
            list = OSDynamicCast(OSArray, object);
        else
            ACPISensorsErrorLog("polling methods table (LIST) not found");
    }
    
    if (interval) {
        pollingInterval = (double)interval->unsigned64BitValue() / (double)1000.0;
        ACPISensorsInfoLog("polling interval %lld ms", interval->unsigned64BitValue());
        
        if (pollingInterval) {
            
            if (timeout) {
                pollingTimeout = (double)timeout->unsigned64BitValue() / 1000.0;
                ACPISensorsInfoLog("polling timeout %lld ms", timeout->unsigned64BitValue());
            }
            
            if (logging) {
                loggingEnabled = logging->isTrue();
                ACPISensorsInfoLog("logging %s", loggingEnabled ? "enabled" : "disabled");
            }
            
            if (list) {
                for (unsigned int i = 0; i < list->getCount(); i++) {
                    if (OSString *method = OSDynamicCast(OSString, list->getObject(i))) {
                        if (method->getLength() && kIOReturnSuccess == acpiDevice->validateObject(method->getCStringNoCopy())) {
                            methods->setObject(method);
                            ACPISensorsInfoLog("method \"%s\" registered", method->getCStringNoCopy());
                        }
                        else ACPISensorsErrorLog("unable to register method \"%s\"", method->getCStringNoCopy());
                    }
                }
            }
        }
        else ACPISensorsWarningLog("polling interval is set to zero, driver will be disabled");
    }
    
//REVIEW_REHABMAN: just bail if no methods to call... no need to stick around...
    if (!methods->getCount())
        return false;

    if (methods->getCount()) {
        // woorkloop
        if (!(workloop = getWorkLoop())) {
            HWSensorsFatalLog("Failed to obtain workloop");
            return false;
        }
        
        if (!(timerEventSource = IOTimerEventSource::timerEventSource( this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &ACPIProbe::woorkloopTimerEvent)))) {
            ACPISensorsFatalLog("failed to initialize timer event source");
            return false;
        }
        
        if (kIOReturnSuccess != workloop->addEventSource(timerEventSource))
        {
            ACPISensorsFatalLog("failed to add timer event source into workloop");
            return false;
        }
        
        timerEventSource->setTimeoutMS(100);
        
        //ACPISensorsInfoLog("%d method%s registered", methods->getCount(), methods->getCount() > 1 ? "s" : "");
    }
    
	registerService();
    
    ACPISensorsInfoLog("started");
    
	return true;
}
Exemplo n.º 6
0
bool ACPISensors::start(IOService * provider)
{
    ACPISensorsDebugLog("starting...");
    
	if (!super::start(provider))
        return false;

	if (!(acpiDevice = OSDynamicCast(IOACPIPlatformDevice, provider))) {
        ACPISensorsFatalLog("ACPI device not ready");
        return false;
    }

    methods = OSArray::withCapacity(0);
    
    // Try to load configuration provided by ACPI device
    OSObject *object = NULL;
        
    // Use Kelvins?
    if (kIOReturnSuccess == acpiDevice->evaluateObject("KLVN", &object) && object) {
        if (OSNumber *kelvins = OSDynamicCast(OSNumber, object)) {
            useKelvins = kelvins->unsigned8BitValue() == 1;
        }

        OSSafeReleaseNULL(object);
    }

    // Allow the device to be completely disabled depending on Platform
    OSDictionary *configuration = getConfigurationNode();
    if (configuration)
    {
        OSBoolean* disable = OSDynamicCast(OSBoolean, configuration->getObject("DisableDevice"));
        if (disable && disable->isTrue()) {
            return false;
        }
    }

    // Parse temperature table
    if (kIOReturnSuccess == acpiDevice->evaluateObject("TEMP", &object) && object) {
        addSensorsFromArray(OSDynamicCast(OSArray, object), kFakeSMCCategoryTemperature);
        OSSafeReleaseNULL(object);
    }
    else ACPISensorsDebugLog("temprerature description table (TEMP) not found");
    
    // Parse voltage table
    if (kIOReturnSuccess == acpiDevice->evaluateObject("VOLT", &object) && object) {
        addSensorsFromArray(OSDynamicCast(OSArray, object), kFakeSMCCategoryVoltage);
        OSSafeReleaseNULL(object);
    }
    else ACPISensorsDebugLog("voltage description table (VOLT) not found");
    
    // Parse amperage table
    if (kIOReturnSuccess == acpiDevice->evaluateObject("AMPR", &object) && object) {
        addSensorsFromArray(OSDynamicCast(OSArray, object), kFakeSMCCategoryCurrent);
        OSSafeReleaseNULL(object);
    }
    else ACPISensorsDebugLog("amperage description table (AMPR) not found");
    
    // Parse power table
    if (kIOReturnSuccess == acpiDevice->evaluateObject("POWR", &object) && object) {
        addSensorsFromArray(OSDynamicCast(OSArray, object), kFakeSMCCategoryPower);
        OSSafeReleaseNULL(object);
    }
    else ACPISensorsDebugLog("power description table (POWR) not found");
    
    // Parse tachometer table
    if (kIOReturnSuccess == acpiDevice->evaluateObject("TACH", &object) && object) {
        addSensorsFromArray(OSDynamicCast(OSArray, object), kFakeSMCCategoryFan);
        OSSafeReleaseNULL(object);
    }
    else ACPISensorsDebugLog("tachometer description table (TACH) not found");

    // If nothing was found on ACPI device try to load configuration from info.plist
    if (object == NULL && configuration)
    {
        if (OSDictionary *temperatures = OSDynamicCast(OSDictionary, configuration->getObject("Temperatures"))) {

            if (OSBoolean *kelvins = OSDynamicCast(OSBoolean, temperatures->getObject("UseKelvins"))) {
                useKelvins = kelvins->isTrue();
            }

            addSensorsFromDictionary(OSDynamicCast(OSDictionary, temperatures), kFakeSMCCategoryTemperature);
        }

        addSensorsFromDictionary(OSDynamicCast(OSDictionary, configuration->getObject("Voltages")), kFakeSMCCategoryVoltage);
        addSensorsFromDictionary(OSDynamicCast(OSDictionary, configuration->getObject("Currents")), kFakeSMCCategoryCurrent);
        addSensorsFromDictionary(OSDynamicCast(OSDictionary, configuration->getObject("Powers")), kFakeSMCCategoryPower);
        addSensorsFromDictionary(OSDynamicCast(OSDictionary, configuration->getObject("Tachometers")), kFakeSMCCategoryFan);
    }
    
    if (methods->getCount())
        ACPISensorsInfoLog("%d sensor%s added", methods->getCount(), methods->getCount() > 1 ? "s" : "");

	registerService();
    
    ACPISensorsInfoLog("started");

	return true;	
}
Exemplo n.º 7
0
bool ACPIProbe::start(IOService * provider)
{
    ACPISensorsDebugLog("starting...");
    
	if (!super::start(provider))
        return false;
    
	if (!(acpiDevice = OSDynamicCast(IOACPIPlatformDevice, provider))) {
        ACPISensorsFatalLog("ACPI device not ready");
        return false;
    }

    profiles = OSDictionary::withCapacity(0);
    profileList = OSArray::withCapacity(0);

    OSObject *object = NULL;


    // Try to load configuration provided by ACPI device

        if (kIOReturnSuccess == acpiDevice->evaluateObject("LIST", &object) && object) {
            if (OSArray *list = OSDynamicCast(OSArray, object)) {
                for (unsigned int i = 0; i < list->getCount(); i++) {
                    if (OSString *method = OSDynamicCast(OSString, list->getObject(i))) {
                        if (kIOReturnSuccess == acpiDevice->evaluateObject(method->getCStringNoCopy(), &object) && object) {
                            if (OSArray *config = OSDynamicCast(OSArray, object)) {
                                if (config->getCount() > 4) {
                                    OSString *pName = OSDynamicCast(OSString, config->getObject(0));
                                    OSNumber *pInterval = OSDynamicCast(OSNumber, config->getObject(1));
                                    OSNumber *pTimeout = OSDynamicCast(OSNumber, config->getObject(2));
                                    OSNumber *pVerbose = OSDynamicCast(OSNumber, config->getObject(3));

                                    OSArray *pMethods = OSArray::withCapacity(config->getCount() - 4);

                                    for (unsigned int offset = 4; offset < config->getCount(); offset++) {
                                        if (OSString *methodName = OSDynamicCast(OSString, config->getObject(offset))) {
                                            pMethods->setObject(methodName);
                                        }
                                    }

                                    addProfile(pName, pMethods, pInterval, pTimeout, pVerbose);
                                }
                            }

                            OSSafeRelease(object);
                        }
                    }
                }

                OSSafeRelease(list);
            }

        }
        else {
            ACPISensorsErrorLog("profile definition table (LIST) not found");
        }

    // Try to load configuration from info.plist
    if (profiles->getCount() == 0) {
        if (OSDictionary *configuration = getConfigurationNode())
        {
            OSString *pName = OSDynamicCast(OSString, configuration->getObject("ProfileName"));
            OSNumber *pInterval = OSDynamicCast(OSNumber, configuration->getObject("PollingInterval"));
            OSNumber *pTimeout = OSDynamicCast(OSNumber, configuration->getObject("PollingTimeout"));
            OSBoolean *pVerboseBool = OSDynamicCast(OSBoolean, configuration->getObject("VerboseLog"));
            OSNumber *pVerbose = OSNumber::withNumber(pVerboseBool->getValue() ? 1 : 0, 8);
            OSArray *pMethods = OSDynamicCast(OSArray, configuration->getObject("MethodsToPoll"));

            addProfile(pName, pMethods, pInterval, pTimeout, pVerbose);
        }
    }

    if (this->profiles->getCount()) {

        // Parse active profile
        if (kIOReturnSuccess == acpiDevice->evaluateObject("ACTV", &object) && object) {
            if (OSString *method = OSDynamicCast(OSString, object)) {
                if (kIOReturnSuccess == acpiDevice->evaluateObject(method->getCStringNoCopy(), &object) && object) {
                    if (OSArray *config = OSDynamicCast(OSArray, object)) {
                        if (config->getCount() > 4) {
                            if (OSString *profile = OSDynamicCast(OSString, config->getObject(0))) {
                                if (!(activeProfile = (ACPIProbeProfile *)profiles->getObject(profile))) {
                                    activeProfile = (ACPIProbeProfile *)profileList->getObject(0);
                                }
                            }
                        }
                    }

                    OSSafeRelease(object);
                }

                OSSafeRelease(method);
            }
        }

        // woorkloop
        if (!(workloop = getWorkLoop())) {
            HWSensorsFatalLog("Failed to obtain workloop");
            return false;
        }
        
        if (!(timerEventSource = IOTimerEventSource::timerEventSource( this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &ACPIProbe::woorkloopTimerEvent)))) {
            ACPISensorsFatalLog("failed to initialize timer event source");
            return false;
        }
        
        if (kIOReturnSuccess != workloop->addEventSource(timerEventSource))
        {
            ACPISensorsFatalLog("failed to add timer event source into workloop");
            return false;
        }
        
        timerEventSource->setTimeoutMS(100);
        
        //ACPISensorsInfoLog("%d method%s registered", methods->getCount(), methods->getCount() > 1 ? "s" : "");
    }

    // two power states - off and on
	static const IOPMPowerState powerStates[2] = {
        { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 1, IOPMDeviceUsable, IOPMPowerOn, IOPMPowerOn, 0, 0, 0, 0, 0, 0, 0, 0 }
    };

    // register interest in power state changes
	PMinit();
	provider->joinPMtree(this);
	registerPowerDriver(this, (IOPMPowerState *)powerStates, 2);
    
	registerService();
    
    ACPISensorsInfoLog("started");
    
	return true;
}