Exemplo n.º 1
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.º 2
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.º 3
0
bool SuperIOMonitor::addTachometerSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding tachometer sensors...");
    
    for (int i = 0; i < tachometerSensorsLimit(); i++) {
        OSString* name = NULL;
        
        char key[7];
            
        snprintf(key, 7, "FANIN%X", i);

        name = OSDynamicCast(OSString, configuration->getObject(key));
        
        UInt64 nameLength = name ? name->getLength() : 0;
        
        if (readTachometer(i) > 10 || nameLength > 0)
            if (!addTachometer(i, (nameLength > 0 ? name->getCStringNoCopy() : 0)))
                HWSensorsWarningLog("error adding tachometer sensor %d", i);
    }
    
    return true;
}
bool GeforceSensors::start(IOService *provider)
{
	HWSensorsDebugLog("Starting...");
	
	if (!super::start(provider))
        return false;
        
    struct nouveau_device *device = &card;
    
    // map device memory
    if ((device->pcidev = (IOPCIDevice*)provider)) {
        
        device->pcidev->setMemoryEnable(true);
        
        if ((device->mmio = device->pcidev->mapDeviceMemoryWithIndex(0))) {
            nv_debug(device, "memory mapped successfully\n");
        }
        else {
            HWSensorsFatalLog("failed to map memory");
            return false;
        }
    }
    else {
        HWSensorsFatalLog("failed to assign PCI device");
        return false;
    }
    
    card.card_index = -1;

    if (OSData *multiboard_capable = OSDynamicCast(OSData, provider->getProperty("rm_multiboard_capable"))) {
        if (0x1 == *((UInt32*)multiboard_capable->getBytesNoCopy())) {
            if (OSData *board_number = OSDynamicCast(OSData, provider->getProperty("rm_board_number"))) {
                UInt8 index = *((UInt32*)board_number->getBytesNoCopy());
                card.card_index = takeGPUIndex(index);
            }
        }
    }
    
    if (card.card_index < 0)
        card.card_index = takeVacantGPUIndex();
    
    if (card.card_index < 0) {
        HWSensorsFatalLog("failed to take vacant GPU index");
        return false;
    }
    
    // identify chipset
    if (!nouveau_identify(device)) {
        releaseGPUIndex(card.card_index);
        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_fatal(device, "unable to shadow VBIOS\n");
            
            releaseGPUIndex(card.card_index);
            card.card_index = -1;
            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");
        releaseGPUIndex(card.card_index);
        card.card_index = -1;
        return false;
    }
    
    nv_info(device, "chipset: %s (NV%02X) bios: %02x.%02x.%02x.%02x\n", device->cname, 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);
            addSensor(key, TYPE_SP78, 2, kFakeSMCTemperatureSensor, nouveau_temp_core);
            
            snprintf(key, 5, KEY_FORMAT_GPU_HEATSINK_TEMPERATURE, card.card_index);
            addSensor(key, TYPE_SP78, 2, kFakeSMCTemperatureSensor, nouveau_temp_board);
        }
        else if (card.core_temp_get) {
            snprintf(key, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, card.card_index);
            addSensor(key, TYPE_SP78, 2, kFakeSMCTemperatureSensor, nouveau_temp_core);
        }
        else if (card.board_temp_get) {
            snprintf(key, 5, KEY_FORMAT_GPU_HEATSINK_TEMPERATURE, card.card_index);
            addSensor(key, TYPE_SP78, 2, kFakeSMCTemperatureSensor, nouveau_temp_board);
        }
    }
    else if (card.temp_get)
    {
        nv_debug(device, "registering temperature sensors...\n");
        
        snprintf(key, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, card.card_index);
        addSensor(key, TYPE_SP78, 2, kFakeSMCTemperatureSensor, nouveau_temp_diode);
    }
    
    int arg_value = 1;

    if (card.clocks_get && !PE_parse_boot_argn("-gpusensors-no-clocks", &arg_value, sizeof(arg_value))) {
        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, kFakeSMCFrequencySensor, 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, kFakeSMCFrequencySensor, 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, kFakeSMCFrequencySensor, 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, kFakeSMCFrequencySensor, nouveau_clock_memory);
        }
    }
    
    if (card.fan_pwm_get || card.fan_rpm_get) {
        nv_debug(device, "registering PWM sensors...\n");

        char title[DIAG_FUNCTION_STR_LEN];
        snprintf (title, DIAG_FUNCTION_STR_LEN, "GPU %X", card.card_index + 1);
        
        if (card.fan_rpm_get && card.fan_rpm_get(device) >= 0)
            addTachometer(nouveau_fan_rpm, title, GPU_FAN_RPM, card.card_index);
        
        if (card.fan_pwm_get && card.fan_pwm_get(device) >= 0)
            addTachometer(nouveau_fan_pwm, title, GPU_FAN_PWM_CYCLE, card.card_index);
    }
    
    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, kFakeSMCVoltageSensor, 0);
    }
    
    registerService();
    
    nv_info(device, "started\n");
    
    return true;
}
Exemplo n.º 5
0
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;	
}
Exemplo n.º 6
0
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;	
}
Exemplo n.º 7
0
void ACPISensors::addSensorsFromArray(OSArray *array, FakeSMCSensorCategory category)
{
    if (array) {
        
        UInt32 group = 0;
        const char *title = NULL;
        
        switch (category) {
            case kFakeSMCCategoryTemperature:
                group = kFakeSMCTemperatureSensor;
                title = "temperature";
                break;
                
            case kFakeSMCCategoryFrequency:
                group = kFakeSMCFrequencySensor;
                title = "frequency";
                break;
                
            case kFakeSMCCategoryVoltage:
                group = kFakeSMCVoltageSensor;
                title = "voltage";
                break;
                
            case kFakeSMCCategoryCurrent:
                group = kFakeSMCCurrentSensor;
                title = "amperage";
                break;
                
            case kFakeSMCCategoryPower:
                group = kFakeSMCPowerSensor;
                title = "power";
                break;
                
            case kFakeSMCCategoryFan:
                group = kFakeSMCTachometerSensor;
                title = "tachometer";
                break;
                
            default:
                return;
        }
        
        for (UInt32 index = 0; index + 1 < array->getCount(); index += 2) {
            if (OSString *key = OSDynamicCast(OSString, array->getObject(index))) {
                if (OSString *method = OSDynamicCast(OSString, array->getObject(index + 1))) {
                    FakeSMCSensor *sensor = NULL;
                    
                    if (category == kFakeSMCCategoryFan) {
                        sensor = addTachometer(methods->getCount(), key->getCStringNoCopy());
                    }
                    else {
                        sensor = addSensorFromNode(key, category, group, methods->getCount());
                    }
                    
                    if (sensor) {
                        methods->setObject(method);//sensor->getKey(), method);
                    }
                    else {
                        ACPISensorsErrorLog("Failed to register %s sensor \"%s\" for method \"%s\"", title, key->getCStringNoCopy(), method->getCStringNoCopy());
                    }
                }
            }
        }
    }
}
Exemplo n.º 8
0
void ACPISensors::addSensorsFromDictionary(OSDictionary *dictionary, FakeSMCSensorCategory category)
{
    if (dictionary) {
        
        UInt32 group = 0;
        const char *title = NULL;
        
        switch (category) {
            case kFakeSMCCategoryTemperature:
                group = kFakeSMCTemperatureSensor;
                title = "temperature";
                break;
                
            case kFakeSMCCategoryFrequency:
                group = kFakeSMCFrequencySensor;
                title = "frequency";
                break;
                
            case kFakeSMCCategoryVoltage:
                group = kFakeSMCVoltageSensor;
                title = "voltage";
                break;
                
            case kFakeSMCCategoryCurrent:
                group = kFakeSMCCurrentSensor;
                title = "amperage";
                break;
                
            case kFakeSMCCategoryPower:
                group = kFakeSMCPowerSensor;
                title = "power";
                break;
                
            case kFakeSMCCategoryFan:
                group = kFakeSMCTachometerSensor;
                title = "tachometer";
                break;
                
            default:
                return;
        }
        
        OSCollectionIterator *iterator = OSCollectionIterator::withCollection(dictionary);
        
        while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) {
            
            OSString *method = OSDynamicCast(OSString, dictionary->getObject(key));
            
            if (method && kIOReturnSuccess == acpiDevice->validateObject(method->getCStringNoCopy())) {
                FakeSMCSensor *sensor = NULL;
                
                if (category == kFakeSMCCategoryFan) {
                    sensor = addTachometer(methods->getCount(), key->getCStringNoCopy());
                }
                else {
                    sensor = addSensorFromNode(key, category, group, methods->getCount());
                }
                
                if (sensor) {
                    methods->setObject(method);//sensor->getKey(), method);
                }
                else {
                    ACPISensorsErrorLog("Failed to register %s sensor \"%s\" for method \"%s\"", title, key->getCStringNoCopy(), method->getCStringNoCopy());
                }
            }
        }
    }
}
Exemplo n.º 9
0
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;
}
Exemplo n.º 10
0
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;
}
Exemplo n.º 11
0
bool GeforceSensors::managedStart(IOService *provider)
{
    HWSensorsDebugLog("Starting...");

    struct nouveau_device *device = &card;

    if (!device->bios.data || !device->bios.size) {
        if (!shadowBios()) {
            nv_fatal(device, "unable to shadow VBIOS\n");
            releaseGPUIndex(card.card_index);
            card.card_index = -1;
            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");
        releaseGPUIndex(card.card_index);
        card.card_index = -1;
        return false;
    }
    
    nv_info(device, "chipset: %s (NV%02X) bios: %02x.%02x.%02x.%02x\n", device->cname, 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) {
            snprintf(key, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, card.card_index);
            addSensorForKey(key, TYPE_SP78, 2, kFakeSMCTemperatureSensor, nouveau_temp_core);
        }
        else if (card.board_temp_get) {
            snprintf(key, 5, KEY_FORMAT_GPU_HEATSINK_TEMPERATURE, card.card_index);
            addSensorForKey(key, TYPE_SP78, 2, kFakeSMCTemperatureSensor, nouveau_temp_board);
        }
    }
    else if (card.temp_get)
    {
        nv_debug(device, "registering temperature sensors...\n");
        
        snprintf(key, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, card.card_index);
        addSensorForKey(key, TYPE_SP78, 2, kFakeSMCTemperatureSensor, nouveau_temp_diode);
    }
    
    int arg_value = 1;
    
    if (card.clocks_get && !PE_parse_boot_argn("-gpusensors-no-clocks", &arg_value, sizeof(arg_value))) {
        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);
            addSensorForKey(key, TYPE_UI32, TYPE_UI32_SIZE, kFakeSMCFrequencySensor, 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, kFakeSMCFrequencySensor, nouveau_clock_shader);
        //        }
        
        if (card.clocks_get(&card, nouveau_clock_rop) > 0) {
            snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_ROP_FREQUENCY, card.card_index);
            addSensorForKey(key, TYPE_UI32, TYPE_UI32_SIZE, kFakeSMCFrequencySensor, nouveau_clock_rop);
        }
        
        if (card.clocks_get(&card, nouveau_clock_memory) > 0) {
            snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_MEMORY_FREQUENCY, card.card_index);
            addSensorForKey(key, TYPE_UI32, TYPE_UI32_SIZE, kFakeSMCFrequencySensor, nouveau_clock_memory);
        }
    }
    
    if (card.fan_pwm_get || card.fan_rpm_get) {
        nv_debug(device, "registering PWM sensors...\n");
        
        char title[DIAG_FUNCTION_STR_LEN];
        snprintf (title, DIAG_FUNCTION_STR_LEN, "GPU %X", card.card_index + 1);
        
        if (card.fan_rpm_get && card.fan_rpm_get(&card) >= 0)
            addTachometer(nouveau_fan_rpm, title, GPU_FAN_RPM, card.card_index);
        
        if (card.fan_pwm_get && card.fan_pwm_get(&card) >= 0)
            addTachometer(nouveau_fan_pwm, title, GPU_FAN_PWM_CYCLE, card.card_index);
    }
    
    if (card.volt.get && card.volt.get(&card) >= 0/*card.voltage_get && card.voltage.supported*/) {
        nv_debug(device, "registering voltage sensors...\n");
        snprintf(key, 5, KEY_FORMAT_GPU_VOLTAGE, card.card_index);
        addSensorForKey(key, TYPE_FP2E, TYPE_FPXX_SIZE, kFakeSMCVoltageSensor, 0);
    }
    
    registerService();
    
    nv_info(device, "started\n");
    
    return true;
}
Exemplo n.º 12
0
bool ACPIMonitor::start(IOService * provider)
{
	if (!super::start(provider)) 
        return false;

	acpiDevice = (IOACPIPlatformDevice *)provider;
	
	if (!acpiDevice) {
        HWSensorsWarningLog("ACPI device not ready");
        return false;
    }
    
    if (OSDictionary *config = OSDynamicCast(OSDictionary, getProperty("Keys Associations"))) {
        // Temperatures
        if ((temperatures = OSDynamicCast(OSDictionary, config->getObject("Temperatures")))) {
            OSCollectionIterator *iterator = OSCollectionIterator::withCollection(temperatures);
            
            iterator->reset();
            
            while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) {
                
                OSString *method = OSDynamicCast(OSString, temperatures->getObject(key));
                
                if (method && kIOReturnSuccess == acpiDevice->evaluateObject(method->getCStringNoCopy())) {
                    if (!addSensor(key->getCStringNoCopy(), TYPE_SP78, TYPE_SPXX_SIZE, kFakeSMCTemperatureSensor, 0))
                        HWSensorsWarningLog("can't add temperature sensor for method %s with key %s", method->getCStringNoCopy(), key->getCStringNoCopy());
                }
            };
            
           //HWSensorsInfoLog("%d temperature sensor(s) added", count);
        }
        else return false;
        
        
        // Voltages
        if ((voltages = OSDynamicCast(OSDictionary, config->getObject("Voltages")))) {
            OSCollectionIterator *iterator = OSCollectionIterator::withCollection(voltages);
            
            iterator->reset();
            
            while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) {
                
                OSString *method = OSDynamicCast(OSString, voltages->getObject(key));
                
                if (method && kIOReturnSuccess == acpiDevice->evaluateObject(method->getCStringNoCopy())) {
                    if (!addSensor(key->getCStringNoCopy(), TYPE_FP4C, TYPE_FPXX_SIZE, kFakeSMCVoltageSensor, 0))
                        HWSensorsWarningLog("can't add voltage sensor for method %s with key %s", method->getCStringNoCopy(), key->getCStringNoCopy());
                }
            };
            
            //HWSensorsInfoLog("%d voltage sensor(s) added", count);
        }
        else return false;
        
        
        // Tachometers
        if ((tachometers = OSDynamicCast(OSDictionary, config->getObject("Tachometers")))) {
            UInt16 count = 0;
            OSArray* fanNames = OSDynamicCast(OSArray, getProperty("Fan Names"));
            
            OSCollectionIterator *iterator = OSCollectionIterator::withCollection(tachometers);
            
            iterator->reset();
            
            while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) {
                
                OSString *method = OSDynamicCast(OSString, tachometers->getObject(key));
                
                if (method && kIOReturnSuccess == acpiDevice->evaluateObject(method->getCStringNoCopy())) {
                    OSString* name = NULL;
                    
                    if (fanNames)
                        name = OSDynamicCast(OSString, fanNames->getObject(count));
                    
                    if (!addTachometer(count, name ? name->getCStringNoCopy() : 0))
                        HWSensorsWarningLog("Failed to register tachometer sensor %d", count);
                    
                    count++;
                }
            };
            
            //HWSensorsInfoLog("%d tachometer sensor(s) added", count);
        }
        else return false;
    }
    
	registerService();

	return true;	
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
bool Andigilog::start(IOService *provider)
{
    int i;
    bool res;
    UInt8 cmd, data, addrs[] = ASC7621_ADDRS;
    /* Mapping common for Intel boards */
    struct MList list[] = {
        { ASC7621_TEMP1H, ASC7621_TEMP1L, {"TC0D",TYPE_SP78,2,-1}, -1, 0, true },
        { ASC7621_TEMP2H, ASC7621_TEMP2L, {KEY_AMBIENT_TEMPERATURE,TYPE_SP78,2,-1}, -1, 0, true },
        { ASC7621_TEMP3H, ASC7621_TEMP3L, {KEY_DIMM_TEMPERATURE,TYPE_SP78,2,-1}, -1, 0, true },
        { ASC7621_TEMP4H, ASC7621_TEMP4L, {KEY_CPU_HEATSINK_TEMPERATURE,TYPE_SP78,2,-1}, -1, 0, true },
        
        { ASC7621_TACH1L, ASC7621_TACH1H, {"Fan 1",TYPE_FPE2,2,0}, true, 0, true },
        { ASC7621_TACH2L, ASC7621_TACH2H, {"Fan 2",TYPE_FPE2,2,1}, true, 0, true },
        { ASC7621_TACH3L, ASC7621_TACH3H, {"Fan 3",TYPE_FPE2,2,2}, true, 0, true },
        { ASC7621_TACH4L, ASC7621_TACH4H, {"Fan 4",TYPE_FPE2,2,2}, true, 0, true }
    };
    struct PList pwm[] = {
        { ASC7621_PWM1R, 0, -2 },
        { ASC7621_PWM2R, 0, -2 },
        { ASC7621_PWM3R, 0, -2 },
    };

    OSDictionary *conf = NULL, *sconf = OSDynamicCast(OSDictionary, getProperty("Sensors Configuration")), *dict;
    IOService *fRoot = getServiceRoot();
    OSString *str, *vendor = NULL;
    char *key;
    char tempkey[] = "_temp ", /* Ugly hack to keep keys in order for auto-generated plist */
    fankey[] = "tach ";

    
    res = super::start(provider);
    DbgPrint("start\n");
    
    if (!(i2cNub = OSDynamicCast(I2CDevice, provider))) {
        IOPrint("Failed to cast provider\n");
        return false;
    }
    
    i2cNub->retain();
    i2cNub->open(this);
    
    for (i = 0; i < sizeof(addrs) / sizeof(addrs[0]); i++)
        if (!i2cNub->ReadI2CBus(addrs[i], &(cmd = ASC7621_VID_REG), sizeof(cmd), &data,
                            sizeof(data)) && data == ASC7621_VID &&
            !i2cNub->ReadI2CBus(addrs[i], &(cmd = ASC7621_PID_REG), sizeof(cmd), &data,
                            sizeof(data)) && (data == ASC7621_PID || data == ASC7621A_PID)) {
                Asc7621_addr = addrs[i];
                IOPrint("aSC7621 attached at 0x%x.\n", Asc7621_addr);
                break;
            }
    if (!Asc7621_addr) {
        IOPrint("Device matching failed.\n");
        return false;
    }
    
    memcpy(&Measures, &list, sizeof(Measures));
    memcpy(&Pwm, &pwm, sizeof(Pwm));
    
    if (fRoot) {
        vendor = vendorID(OSDynamicCast(OSString, fRoot->getProperty("oem-mb-manufacturer") ?
                                        fRoot->getProperty("oem-mb-manufacturer") :
                                        (fRoot->getProperty("oem-manufacturer") ?
                                         fRoot->getProperty("oem-manufacturer") : NULL)));
        str = OSDynamicCast(OSString, fRoot->getProperty("oem-mb-product") ?
                            fRoot->getProperty("oem-mb-product") :
                            (fRoot->getProperty("oem-product-name") ?
                             fRoot->getProperty("oem-product-name") : NULL));
    }
    if (vendor)
        if (OSDictionary *link = OSDynamicCast(OSDictionary, sconf->getObject(vendor)))
            if(str)
                conf = OSDynamicCast(OSDictionary, link->getObject(str));
    if (sconf && !conf)
        conf = OSDynamicCast(OSDictionary, sconf->getObject("Active"));
    i = 0;
    for (int s = 0, j = 0, k = 0; i < NUM_SENSORS; i++) {
        if (conf) {
                if (Measures[i].fan < 0) {
                    snprintf(&tempkey[5], 2, "%d", j++);
                    key = tempkey;
                } else {
                    snprintf(&fankey[4], 2, "%d", k++);
                    key = fankey;
                }
                if ((dict = OSDynamicCast(OSDictionary, conf->getObject(key)))) {
                    str = OSDynamicCast(OSString, dict->getObject("id"));
                    memcpy(Measures[i].hwsensor.key, str->getCStringNoCopy(), str->getLength()+1);
                    if (Measures[i].fan > -1)
                        Measures[i].hwsensor.pwm = ((OSNumber *)OSDynamicCast(OSNumber, dict->getObject("pwm")))->
                        unsigned8BitValue();
                    Measures[i].hwsensor.size = ((OSNumber *)OSDynamicCast(OSNumber, dict->getObject("size")))->
                    unsigned8BitValue();
                    str = OSDynamicCast(OSString, dict->getObject("type"));
                    memcpy(Measures[i].hwsensor.type, str->getCStringNoCopy(), str->getLength()+1);
                }
        }
        if (Measures[i].hwsensor.key[0]) {
            if (Measures[i].fan < 0) {
                addSensor(Measures[i].hwsensor.key, Measures[i].hwsensor.type,
                          Measures[i].hwsensor.size, s);
                s++;
            } else {
                if (!config.start_fan)
                    config.start_fan = i;
                addTachometer(&Measures[i], Measures[i].fan = config.num_fan);
                config.num_fan++;
            }
        }
    }
    config.num_fan++;
    addKey(KEY_FAN_FORCE, TYPE_UI16, 2, 0);
  
    GetConf();
        
    return res;
}
Exemplo n.º 15
0
bool ACPISensors::start(IOService * provider)
{
	if (!super::start(provider))
        return false;

	acpiDevice = (IOACPIPlatformDevice *)provider;
	
	if (!acpiDevice) {
        HWSensorsFatalLog("ACPI device not ready");
        return false;
    }
    
    if (OSDictionary *configuration = getConfigurationNode())
    {
        // Temperatures
        if (OSDictionary *temps = OSDynamicCast(OSDictionary, configuration->getObject("Temperatures"))) {
            
            temperatures = OSDictionary::withCapacity(0);
            
            OSCollectionIterator *iterator = OSCollectionIterator::withCollection(temps);
            UInt16 count = 0;
            
            while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) {
                
                OSString *method = OSDynamicCast(OSString, temps->getObject(key));
                
                if (method && kIOReturnSuccess == acpiDevice->validateObject(method->getCStringNoCopy())) {
                    for (int i = 0; i < FakeSMCTemperatureCount; i++) {
                        if (addSensorToList(temperatures, key, method, FakeSMCTemperature[i].name, FakeSMCTemperature[i].key, FakeSMCTemperature[i].type, FakeSMCTemperature[i].size, kFakeSMCTemperatureSensor, count)) {
                            count++;
                            break;
                        }
                        else HWSensorsErrorLog("Failed to register temperature sensor \"%s\" for method \"%s\"", key->getCStringNoCopy(), method->getCStringNoCopy());
                    }
                }
            };
            
            if (count)
                HWSensorsInfoLog("%d temperature sensor%s added", count, count > 1 ? "s" : "");
        }
        else return false;
        
        
        // Voltages
        if (OSDictionary *volts = OSDynamicCast(OSDictionary, configuration->getObject("Voltages"))) {
            
            voltages = OSDictionary::withCapacity(0);
            
            OSCollectionIterator *iterator = OSCollectionIterator::withCollection(volts);
            UInt16 count = 0;
            
            while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) {
                
                OSString *method = OSDynamicCast(OSString, volts->getObject(key));
                
                if (method && kIOReturnSuccess == acpiDevice->validateObject(method->getCStringNoCopy())) {
                    for (int i = 0; i < FakeSMCVolatgeCount; i++) {
                        if (addSensorToList(voltages, key, method, FakeSMCVolatge[i].name, FakeSMCVolatge[i].key, FakeSMCVolatge[i].type, FakeSMCVolatge[i].size, kFakeSMCVoltageSensor, count)) {
                            count++;
                            break;
                        }
                        else HWSensorsErrorLog("Failed to register voltage sensor \"%s\" for method \"%s\"", key->getCStringNoCopy(), method->getCStringNoCopy());
                    }
                }
            };
            
            if (count)
                HWSensorsInfoLog("%d voltage sensor%s added", count, count > 1 ? "s" : "");
        }
        else return false;
        
        
        // Tachometers
        if (OSDictionary *fans = OSDynamicCast(OSDictionary, configuration->getObject("Tachometers"))) {
            tachometers = OSDictionary::withCapacity(0);
            
            OSCollectionIterator *iterator = OSCollectionIterator::withCollection(fans);
            UInt16 count = 0;
            
            OSDictionary* fanNames = OSDynamicCast(OSDictionary, configuration->getObject("Fan Names"));
            
            while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) {
                
                OSString *method = OSDynamicCast(OSString, fans->getObject(key));
                
                if (method && kIOReturnSuccess == acpiDevice->validateObject(method->getCStringNoCopy())) {
                    OSString* name = NULL;

                    if (fanNames)
                        name = OSDynamicCast(OSString, fanNames->getObject(key));
                    
                    if (FakeSMCSensor *sensor = addTachometer(count, name ? name->getCStringNoCopy() : 0)) {
                        tachometers->setObject(sensor->getKey(), method);
                        count++;
                    }
                    else HWSensorsErrorLog("Failed to register tachometer sensor for method \"%s\"", method->getCStringNoCopy());
                }
            };
            
            if (count)
                HWSensorsInfoLog("%d tachometer sensor%s added", count, count > 1 ? "s" : "");
        }
        else return false;
    }
    else HWSensorsErrorLog("no valid configuration provided");
    
	registerService();
    
    HWSensorsInfoLog("started");

	return true;	
}
Exemplo n.º 16
0
bool NVClockX::start(IOService * provider)
{
	HWSensorsDebugLog("Starting...");
	
	if (!super::start(provider)) 
        return false;
    
    if ((videoCard = (IOPCIDevice*)provider)) 
    {
        if (videoCard->setMemoryEnable(true)) 
        {
            if ((nvio = videoCard->mapDeviceMemoryWithIndex(0))) 
            {
                IOVirtualAddress addr = nvio->getVirtualAddress();
                
                if (OSData * data = OSDynamicCast(OSData, videoCard->getProperty("device-id"))) 
                {
                    nvclock.card[nvclock.num_cards].device_id=*(UInt32*)data->getBytesNoCopy();
                    
                    
                    nvclock.card[nvclock.num_cards].arch = get_gpu_arch(nvclock.card[nvclock.num_cards].device_id);
                    nvclock.card[nvclock.num_cards].number = nvclock.num_cards;
                    nvclock.card[nvclock.num_cards].card_name = (char*)get_card_name(nvclock.card[nvclock.num_cards].device_id, &nvclock.card[nvclock.num_cards].gpu);
                    nvclock.card[nvclock.num_cards].state = 0;
                    
                    //nvclock.card[nvclock.num_cards].reg_address = addr;
                    
                    //map_mem_card(&nvclock.card[nvclock.num_cards], addr);
                    // Map the registers of the nVidia chip 
                    // normally pmc is till 0x2000 but extended it for nv40 
                    nvclock.card[nvclock.num_cards].PEXTDEV = (volatile unsigned int*)(addr + 0x101000);
                    nvclock.card[nvclock.num_cards].PFB     = (volatile unsigned int*)(addr + 0x100000);
                    nvclock.card[nvclock.num_cards].PMC     = (volatile unsigned int*)(addr + 0x000000);
                    nvclock.card[nvclock.num_cards].PCIO    = (volatile unsigned char*)(addr + 0x601000);
                    nvclock.card[nvclock.num_cards].PDISPLAY= (volatile unsigned int*)(addr + NV_PDISPLAY_OFFSET);
                    nvclock.card[nvclock.num_cards].PRAMDAC = (volatile unsigned int*)(addr + 0x680000);
                    nvclock.card[nvclock.num_cards].PRAMIN  = (volatile unsigned int*)(addr + NV_PRAMIN_OFFSET);
                    nvclock.card[nvclock.num_cards].PROM    = (volatile unsigned char*)(addr + 0x300000);
                    
                    // On Geforce 8xxx cards it appears that the pci config header has been moved 
                    if(nvclock.card[nvclock.num_cards].arch & NV5X)
                        nvclock.card[nvclock.num_cards].PBUS = (volatile unsigned int*)(addr + 0x88000);
                    else
                        nvclock.card[nvclock.num_cards].PBUS = nvclock.card[nvclock.num_cards].PMC + 0x1800/4;
                    
                    nvclock.card[nvclock.num_cards].mem_mapped = 1;
                    
                    HWSensorsInfoLog("%s device-id=0x%x arch=0x%x", 
                                     nvclock.card[nvclock.num_cards].card_name, 
                                     nvclock.card[nvclock.num_cards].device_id, 
                                     nvclock.card[nvclock.num_cards].arch);
                    
                    nvclock.num_cards++;
                }
                else HWSensorsWarningLog("device-id property not found");                
            }
            else {
                HWSensorsWarningLog("failed to map device's memory");
                return false;
            }
        }
    }else {
        HWSensorsWarningLog("failed to assign PCI device");
        return false;
    }
    
	char key[7];
	
	nvclock.dpy = NULL;
	
	for (int index = 0; index < nvclock.num_cards; index++) {
		/* set the card object to the requested card */
		if (!set_card(index)){
			char buffer[256];
			HWSensorsWarningLog("%s", get_error(buffer, 256));
			return false;
		}

        OSData *bios = OSDynamicCast(OSData, videoCard->getProperty("vbios"));

        nvclock.card[index].bios = read_bios(bios ? bios->getBytesNoCopy() : NULL);
        
		/* Check if the card is supported, if not print a message. */
		if(nvclock.card[index].gpu == UNKNOWN){
			HWSensorsWarningLog("it seems your card isn't officialy supported yet");
			HWSensorsWarningLog("please tell the author the pci_id of the card for further investigation");
			HWSensorsWarningLog("continuing anyway");
		}
        
        SInt8 cardIndex = getVacantGPUIndex();
        
        if (cardIndex < 0) {
            HWSensorsWarningLog("failed to obtain vacant GPU index");
            return false;
        }
        
		if(nv_card->caps & (GPU_TEMP_MONITORING)) {
            HWSensorsInfoLog("registering temperature sensors");
            
            if(nv_card->caps & BOARD_TEMP_MONITORING) {
                snprintf(key, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, cardIndex);
                addSensor(key, TYPE_SP78, 2, kNVCLockDiodeTemperatureSensor, index);
                
				snprintf(key, 5, KEY_FORMAT_GPU_HEATSINK_TEMPERATURE, cardIndex);
				addSensor(key, TYPE_SP78, 2, kNVCLockBoardTemperatureSensor, index);
			}
            else {
                snprintf(key, 5, KEY_FORMAT_GPU_PROXIMITY_TEMPERATURE, cardIndex);
                addSensor(key, TYPE_SP78, 2, kNVCLockBoardTemperatureSensor, index);
            }
		}
		
		if (nv_card->caps & I2C_FANSPEED_MONITORING || nv_card->caps & GPU_FANSPEED_MONITORING){
            HWSensorsInfoLog("registering tachometer sensors");
            
            char title[6]; 
            
            snprintf (title, 6, "GPU %X", cardIndex);
            
			addTachometer(index, title);
		}
		
        HWSensorsInfoLog("registering frequency sensors");
        
        snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_FREQUENCY, index);
        addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, kNVCLockCoreFrequencySensor, index);
        
        snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_MEMORY_FREQUENCY, index);
        addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, kNVCLockMemoryFrequencySensor, index);
        
        snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_SHADER_FREQUENCY, index);
        addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, kNVCLockMemoryFrequencySensor, index);
		
		/*OSNumber* fanKey = OSDynamicCast(OSNumber, getProperty("FanSpeedPercentage"));
         
         if((fanKey!=NULL)&(nv_card->set_fanspeed!=NULL)) {
         HWSensorsInfoLog("Changing fan speed to %d", fanKey->unsigned8BitValue());
         nv_card->set_fanspeed(fanKey->unsigned8BitValue());
         }
         
         OSNumber* speedKey=OSDynamicCast(OSNumber, getProperty("GPUSpeed"));
         
         if ((speedKey!=NULL)&(nv_card->caps&GPU_OVERCLOCKING)) {
         HWSensorsInfoLog("Default speed %d", (UInt16)nv_card->get_gpu_speed());
         //HWSensorsInfoLog("%d", speedKey->unsigned16BitValue());
         nv_card->set_gpu_speed(speedKey->unsigned16BitValue());
         HWSensorsInfoLog("Overclocked to %d", (UInt16)nv_card->get_gpu_speed());
         }*/
	}
    
    registerService();
	
	return true;
}