Exemplo n.º 1
0
bool X3100monitor::start(IOService * provider)
{
	if (!super::start(provider)) 
        return false;
	
	//Find card number
    SInt8 cardIndex = getVacantGPUIndex();
    
    if (cardIndex < 0) {
        HWSensorsWarningLog("failed to obtain vacant GPU index");
        return false;
    }
    
    char key[5];
    
    snprintf(key, 5, KEY_FORMAT_GPU_PROXIMITY_TEMPERATURE, cardIndex);
    
    if (!addSensor(key, TYPE_SP78, 2, kFakeSMCTemperatureSensor, 0)) {
        HWSensorsWarningLog("failed to register temperature sensor");
        return false;
    }
    
    registerService();
	
	return true;	
}
bool GeforceSensors::start(IOService * provider)
{
	DebugLog("Starting...");
	
	if (!super::start(provider)) 
    return false;
  
  if (!(fakeSMC = waitForService(serviceMatching(kFakeSMCDeviceService)))) {
		WarningLog("Can't locate fake SMC device, kext will not load");
		return false;
	}  
  
  struct nouveau_device *device = &card;
  
  //Find card number
  card.card_index = getVacantGPUIndex();
  
  if (card.card_index < 0) {
    nv_error(device, "failed to obtain vacant GPU index\n");
    return false;
  }
  
  // map device memory
//  device->pcidev = (IOPCIDevice*)provider;
  if (device->pcidev) {
    
    device->pcidev->setMemoryEnable(true);
    
    if ((device->mmio = device->pcidev->mapDeviceMemoryWithIndex(0))) {
      nv_debug(device, "memory mapped successfully\n");
    }
    else {
      nv_error(device, "failed to map memory\n");
      return false;
    }
  }
  else {
    nv_error(device, "failed to assign PCI device\n");
    return false;
  }
  
  // identify chipset
  if (!nouveau_identify(device))
    return false;
  
  // shadow and parse bios
  
  //try to load bios from registry first from "vbios" property created by Chameleon boolloader
  if (OSData *vbios = OSDynamicCast(OSData, provider->getProperty("vbios"))) {
    device->bios.size = vbios->getLength();
    device->bios.data = (u8*)IOMalloc(card.bios.size);
    memcpy(device->bios.data, vbios->getBytesNoCopy(), device->bios.size);
  }
  
  if (!device->bios.data || !device->bios.size || nouveau_bios_score(device, true) < 1)
    if (!nouveau_bios_shadow(device)) {
      if (device->bios.data && device->bios.size) {
        IOFree(card.bios.data, card.bios.size);
        device->bios.data = NULL;
        device->bios.size = 0;
      }
      
      nv_error(device, "unable to shadow VBIOS\n");
      
      return false;
    }
  
  nouveau_vbios_init(device);
  nouveau_bios_parse(device);
  
  // initialize funcs and variables
  if (!nouveau_init(device)) {
    nv_error(device, "unable to initialize monitoring driver\n");
    return false;
  }
  
  nv_info(device, "chipset: %s (NV%02X) bios: %02x.%02x.%02x.%02x\n", device->cname, (unsigned int)device->chipset, device->bios.version.major, device->bios.version.chip, device->bios.version.minor, device->bios.version.micro);
  
  if (device->card_type < NV_C0) {
    // init i2c structures
    nouveau_i2c_create(device);
    
    // setup nouveau i2c sensors
    nouveau_i2c_probe(device);
  }
  
  // Register sensors
  char key[5];
  
  if (card.core_temp_get || card.board_temp_get) {
    nv_debug(device, "registering i2c temperature sensors...\n");
    
    if (card.core_temp_get && card.board_temp_get) {
      snprintf(key, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, card.card_index);
      this->addSensor(key, TYPE_SP78, 2, 0);
      
      snprintf(key, 5, KEY_FORMAT_GPU_HEATSINK_TEMPERATURE, card.card_index);
      addSensor(key, TYPE_SP78, 2, 0);
    }
    else if (card.core_temp_get) {
      snprintf(key, 5, KEY_FORMAT_GPU_PROXIMITY_TEMPERATURE, card.card_index);
      addSensor(key, TYPE_SP78, 2, 0);
    }
    else if (card.board_temp_get) {
      snprintf(key, 5, KEY_FORMAT_GPU_PROXIMITY_TEMPERATURE, card.card_index);
      addSensor(key, TYPE_SP78, 2, 0);
    }
  }
  else if (card.temp_get)
  {
    nv_debug(device, "registering temperature sensors...\n");
    
    snprintf(key, 5, KEY_FORMAT_GPU_PROXIMITY_TEMPERATURE, card.card_index);
    addSensor(key, TYPE_SP78, 2, 0);
  }
  
  if (card.clocks_get) {
    nv_debug(device, "registering clocks sensors...\n");
    
    if (card.clocks_get(&card, nouveau_clock_core) > 0) {
      snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_FREQUENCY, card.card_index);
      addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, nouveau_clock_core);
    }
    
    if (card.clocks_get(&card, nouveau_clock_shader) > 0) {
      snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_SHADER_FREQUENCY, card.card_index);
      addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, nouveau_clock_shader);
    }
    
    if (card.clocks_get(&card, nouveau_clock_rop) > 0) {
      snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_ROP_FREQUENCY, card.card_index);
      addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, nouveau_clock_rop);
    }
    
    if (card.clocks_get(&card, nouveau_clock_memory) > 0) {
      snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_MEMORY_FREQUENCY, card.card_index);
      addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, nouveau_clock_memory);
    }
  }
  
  if (card.fan_pwm_get || card.fan_rpm_get) {
    nv_debug(device, "registering PWM sensors...\n");
    
    if (card.fan_rpm_get && card.fan_rpm_get(device) > 0) {
      char title[6];
      snprintf (title, 6, "GPU %X", card.card_index + 1);
      
      UInt8 fanIndex = 0;
      
      if (addTachometer( fanIndex)) {
        if (card.fan_pwm_get && card.fan_pwm_get(device) > 0) {
          snprintf(key, 5, KEY_FAKESMC_FORMAT_GPUPWM, fanIndex);
          addSensor(key, TYPE_UI8, TYPE_UI8_SIZE, 0);
        }
      }
    }
  }
  
  if (card.voltage_get && card.voltage.supported) {
    nv_debug(device, "registering voltage sensors...\n");
    snprintf(key, 5, KEY_FORMAT_GPU_VOLTAGE, card.card_index);
    addSensor(key, TYPE_FP2E, TYPE_FPXX_SIZE, 0);
  }
  
  nv_info(device, "started\n");
  
  return true;
}
Exemplo n.º 3
0
bool SuperIOMonitor::addVoltageSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding voltage sensors...");
    
    for (int i = 0; i < voltageSensorsLimit(); i++)
    {				
        char key[5];
        OSString* name;
        float reference = 0.0f;
        float gain = 0.0f;
        float offset = 0.0f;
        
        snprintf(key, 5, "VIN%X", i);
        
        if (process_sensor_entry(configuration->getObject(key), &name, &reference, &gain, &offset)) {
            if (name->isEqualTo("CPU")) {
                if (!addSensor(KEY_CPU_VOLTAGE, TYPE_FP2E, TYPE_FPXX_SIZE, kSuperIOVoltageSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add CPU voltage sensor");
            }
            else if (name->isEqualTo("Memory")) {
                if (!addSensor(KEY_MEMORY_VOLTAGE, TYPE_FP2E, TYPE_FPXX_SIZE, kSuperIOVoltageSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add Memory voltage sensor");
            }
            else if (name->isEqualTo("Main 12V")) {
                if (!addSensor(KEY_MAIN_12V_VOLTAGE, TYPE_FP4C, TYPE_FPXX_SIZE, kSuperIOVoltageSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add Main 12V voltage sensor");
            }
            else if (name->isEqualTo("PCIe 12V")) {
                if (!addSensor(KEY_PCIE_12V_VOLTAGE, TYPE_FP4C, TYPE_FPXX_SIZE, kSuperIOVoltageSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add PCIe 12V voltage sensor");
            }
            else if (name->isEqualTo("Main 5V")) {
                if (!addSensor(KEY_MAIN_5V_VOLTAGE, TYPE_FP4C, TYPE_FPXX_SIZE, kSuperIOVoltageSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add Main 5V voltage sensor");
            }
            else if (name->isEqualTo("Standby 5V")) {
                if (!addSensor(KEY_STANDBY_5V_VOLTAGE, TYPE_FP4C, TYPE_FPXX_SIZE, kSuperIOVoltageSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add Standby 5V voltage sensor");
            }
            else if (name->isEqualTo("Main 3V")) {
                if (!addSensor(KEY_MAIN_3V3_VOLTAGE, TYPE_FP2E, TYPE_FPXX_SIZE, kSuperIOVoltageSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add Main 3V voltage sensor");
            }
            else if (name->isEqualTo("Auxiliary 3V")) {
                if (!addSensor(KEY_AUXILIARY_3V3V_VOLTAGE, TYPE_FP2E, TYPE_FPXX_SIZE, kSuperIOVoltageSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add Auxiliary 3V voltage sensor");
            }
            else if (name->isEqualTo("Power/Battery")) {
                if (!addSensor(KEY_POWERBATTERY_VOLTAGE, TYPE_FP2E, TYPE_FPXX_SIZE, kSuperIOVoltageSensor, i, reference, gain, offset))
                    HWSensorsWarningLog("can't add Power/Battery voltage sensor");
            }
            else if (name->isEqualTo("GPU")) {
                SInt8 index = getVacantGPUIndex();
                
                if (index > -1) {
                    snprintf(key, 5, KEY_FORMAT_GPU_VOLTAGE, index);
                    
                    if (!addSensor(key, TYPE_FP2E, TYPE_FPXX_SIZE, kSuperIOVoltageSensor, i, reference, gain, offset))
                        HWSensorsWarningLog("can't add GPU voltage sensor");
                }
                else HWSensorsWarningLog("failed to obtain vacant GPU index");
            }
            
            
            for (int j = 0; j <= 0xf; j++) {
                
                char caption[32];
                
                snprintf(caption, 15, "Power Supply %X", j);
                
                if (name->isEqualTo(caption)) {
                    snprintf(key, 5, KEY_FORMAT_POWERSUPPLY_VOLTAGE, j);
                    if (!addSensor(key, TYPE_FP4C, TYPE_FPXX_SIZE, kSuperIOVoltageSensor, i, reference, gain, offset))
                        HWSensorsWarningLog("can't add PWR%X voltage sensor", j);
                }
                else {
                
                    snprintf(caption, 17, "CPU VRM Supply %X", j);
                    
                    if (name->isEqualTo(caption)) {
                        snprintf(key, 5, KEY_FORMAT_CPU_VRMSUPPLY_VOLTAGE, j);
                        if (!addSensor(key, TYPE_FP4C, TYPE_FPXX_SIZE, kSuperIOVoltageSensor, i, reference, gain, offset))
                            HWSensorsWarningLog("can't add VRM%X voltage sensor", j);
                    }
                }
            }
        }
    }

    return true;
}
Exemplo n.º 4
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;
}