コード例 #1
0
ファイル: X3100.cpp プロジェクト: Beshuta/HWSensors
IOService* X3100monitor::probe(IOService *provider, SInt32 *score)
{
	if (super::probe(provider, score) != this) return 0;
	UInt32 vendor_id, device_id;
	if (OSDictionary * dictionary = serviceMatching(kGenericPCIDevice)) {
		if (OSIterator * iterator = getMatchingServices(dictionary)) {
			
			IOPCIDevice* device = 0;
			
			while (device = OSDynamicCast(IOPCIDevice, iterator->getNextObject())) {
				OSData *data = OSDynamicCast(OSData, device->getProperty("vendor-id"));
				if (data)
					vendor_id = *(UInt32*)data->getBytesNoCopy();
				
				data = OSDynamicCast(OSData, device->getProperty("device-id"));				
				if (data)
					device_id = *(UInt32*)data->getBytesNoCopy();
				
				if ((vendor_id==0x8086) && (device_id==0x2a00)){
					InfoLog("found %lx chip", (long unsigned int)device_id);
					VCard = device;
				}
			}
		}
	}	
	return this;
}
コード例 #2
0
IOService* GeforceSensors::probe(IOService *provider, SInt32 *score)
{
  UInt32 vendor_id, device_id, class_id;
	DebugLog("Probing...");
	
	if (super::probe(provider, score) != this) return 0;
	
	InfoLog("GeforceSensors by kozlek (C) 2012");
	s8 ret = 0;
	if (OSDictionary * dictionary = serviceMatching(kGenericPCIDevice)) {
		if (OSIterator * iterator = getMatchingServices(dictionary)) {
			ret = 1;
			IOPCIDevice* device = 0;
			do {
			  device = OSDynamicCast(IOPCIDevice, iterator->getNextObject());
        if (!device) {
          break;
        }
				OSData *data = OSDynamicCast(OSData, device->getProperty(fVendor));
        vendor_id = 0;
				if (data)
					vendor_id = *(UInt32*)data->getBytesNoCopy();
				
        device_id = 0;
				data = OSDynamicCast(OSData, device->getProperty(fDevice));				
				if (data)
					device_id = *(UInt32*)data->getBytesNoCopy();
				
        class_id = 0;
				data = OSDynamicCast(OSData, device->getProperty(fClass));				
				if (data)
					class_id = *(UInt32*)data->getBytesNoCopy();
				
				if ((vendor_id==0x10de) && (class_id == 0x030000)) {
					InfoLog("found %x Nvidia chip", (unsigned int)device_id);
					card.pcidev = device;
          card.device_id = device_id;
					ret = 1; //TODO - count a number of cards
          card.card_index = ret;
					break;
				}
			} while (device);	
		}
	}
	if(ret)
		return this;
	else return 0;
	
	return this;
}
コード例 #3
0
ファイル: FakeSMC.cpp プロジェクト: dongdooo/HWSensors
bool FakeSMC::start(IOService *provider)
{
	if (!super::start(provider)) 
        return false;
    
    int arg_value = 1;
    
    // Check if we have SMC already
    if (OSDictionary *matching = serviceMatching("IOACPIPlatformDevice")) {
        if (OSIterator *iterator = getMatchingServices(matching)) {
            
            OSString *smcNameProperty = OSString::withCString("APP0001");

            while (IOService *service = (IOService*)iterator->getNextObject()) {
                
                OSObject *serviceNameProperty = service->getProperty("name");
                
                if (serviceNameProperty && serviceNameProperty->isEqualTo(smcNameProperty)) {
                    HWSensorsFatalLog("SMC device detected, will not create another one");
                    return false;
                }
            }
            
            OSSafeRelease(iterator);
        }
        
        OSSafeRelease(matching);
    }
    
	if (!smcDevice->initAndStart(provider, this)) {
        HWSensorsInfoLog("failed to initialize SMC device");
		return false;
    }

	registerService();
    
    // Load keys from NVRAM
    if (PE_parse_boot_argn("-fakesmc-use-nvram", &arg_value, sizeof(arg_value))) {
        if (UInt32 count = smcDevice->loadKeysFromNVRAM())
            HWSensorsInfoLog("%d key%s loaded from NVRAM", count, count == 1 ? "" : "s");
        else
            HWSensorsInfoLog("NVRAM will be used to store system written keys...");
    }

	return true;
}
コード例 #4
0
ファイル: sessionhelper.cpp プロジェクト: ZhaozhengPlus/libqi
void SessionHelper::info(const std::vector<std::string> &patternVec, bool verbose, bool showHidden, bool showDoc, bool showRaw, bool parseable)
{
  std::set<std::string> matchServs;

  //pattern match, and display
  for (unsigned int i = 0; i < patternVec.size(); ++i)
  {
    std::list<std::string> tmp = getMatchingServices(patternVec[i], showHidden);
    matchServs.insert(tmp.begin(), tmp.end());
  }

  if (matchServs.empty())
    throw std::runtime_error("no services matching the given pattern(s) were found");

  for (unsigned int j = 0; j < _servicesInfos.size(); ++j)
    for(const std::string &it: matchServs)
      if (it == _servicesInfos[j].name())
        showServiceInfo(_servicesInfos[j], verbose, showHidden, showDoc, showRaw, parseable);
}
コード例 #5
0
IOReturn IOPMPagingPlexus::setAggressiveness ( unsigned long type, unsigned long )
{
    OSDictionary *	dict;
    OSIterator *	iter;
    OSObject *		next;
    IOService *		candidate = 0;
    IOService *		pagingProvider;

    if( type != kPMMinutesToSleep)
        return IOPMNoErr;
    
    IOLockLock(ourLock);
    if ( systemBooting ) {
        systemBooting = false;
        IOLockUnlock(ourLock);
        dict = IOBSDNameMatching(rootdevice);
        if ( dict ) {
            iter = getMatchingServices(dict);
            if ( iter ) {
                while ( (next = iter->getNextObject()) ) {
                    if ( (candidate = OSDynamicCast(IOService,next)) ) {
                        break;
                    }
                }
                iter->release();
            }
        }
        if ( candidate ) {
            pagingProvider = findProvider(candidate);
            if ( pagingProvider ) {
                processSiblings(pagingProvider);
                pagingProvider->addPowerChild(this);
                getPMRootDomain()->removePowerChild(((IOPowerConnection *)getParentEntry(gIOPowerPlane)));
                processChildren();
            }
        }
    }
    else {
        IOLockUnlock(ourLock);
    }
    return IOPMNoErr;
}
コード例 #6
0
bool RadeonSensors::probIsAcceleratorAlreadyLoaded()
{
    bool acceleratorFound = false;

    if (OSDictionary *matching = serviceMatching("IOAccelerator")) {
        if (OSIterator *iterator = getMatchingServices(matching)) {
            while (IOService *service = (IOService*)iterator->getNextObject()) {
                if (pciDevice == service->getParentEntry(gIOServicePlane)) {
                    acceleratorFound = true;
                    break;
                }
            }

            OSSafeReleaseNULL(iterator);
        }
        
        OSSafeReleaseNULL(matching);
    }

    return acceleratorFound;
}
コード例 #7
0
ファイル: GPUSensors.cpp プロジェクト: dfkthf1975/HWSensors-1
IOReturn GPUSensors::probeEvent()
{
    HWSensorsDebugLog("Probe event...");
    
    bool acceleratorFound = false;
    
    if (OSDictionary *matching = serviceMatching("IOAccelerator")) {
        if (OSIterator *iterator = getMatchingServices(matching)) {
            while (IOService *service = (IOService*)iterator->getNextObject()) {
                if (pciDevice == service->getParentEntry(gIOServicePlane)) {
                    acceleratorFound = true;
                    break;
                }
            }
            
            OSSafeRelease(iterator);
        }
        
        OSSafeRelease(matching);
    }
    
    if (acceleratorFound) {
        releaseTimerEventSource;
        onAcceleratorFound(pciDevice);
    }
    else if (probeCounter++ == 45) {
        releaseTimerEventSource;
        onTimeoutExceeded(pciDevice);
    }
    else {
        if (probeCounter > 0 && !(probeCounter % 15))
            HWSensorsInfoLog("still waiting for IOAccelerator to start...");
        
        timerEventSource->setTimeoutMS(1000);
    }
    
    return kIOReturnSuccess;
}
コード例 #8
0
ファイル: sessionhelper.cpp プロジェクト: ZhaozhengPlus/libqi
SessionHelper::MatchMap SessionHelper::getMatchMap(const std::vector<std::string> &patternList, ShPatternResolver patternResolver, bool hidden)
{
  MatchMap matchMap;

  for (unsigned int i = 0; i < patternList.size(); ++i)
  {
    std::string servicePattern;
    std::string memberPattern;

    splitName(patternList[i], servicePattern, memberPattern, true);
    std::list<std::string> matchingServices = getMatchingServices(servicePattern, hidden);

    for(const std::string &it: matchingServices)
    {
      if (!matchMap.count(it))
        matchMap[it].first = getServiceHelper(it);

      std::pair<ServiceHelper, std::set<std::string> > &matchPair = matchMap[it];
      std::list<std::string> matchingMembers = (matchPair.first.*patternResolver)(memberPattern, hidden);
      matchMap[it].second.insert(matchingMembers.begin(), matchingMembers.end());
    }
  }
  return matchMap;
}
コード例 #9
0
int PTnVmon::probe_devices()
{
	IOPCIDevice* PTCard=NULL;
	int i=0;
	UInt16 vendor_id;
	IOLog("PTKawainVi: started\n");
	OSData* idKey;
	OSDictionary * iopci = serviceMatching("IOPCIDevice");
	OSString* str;
#if __LP64__
	mach_vm_address_t addr;
	//mach_vm_size_t size;
#else
	vm_address_t addr;
	//vm_size_t size;
#endif
	nvclock.num_cards=0;
	if (iopci) {
		OSIterator * iterator = getMatchingServices(iopci);
		if (iterator) {
			while (PTCard = OSDynamicCast(IOPCIDevice, iterator->getNextObject())) {
				vendor_id=0;
				str=OSDynamicCast(OSString, PTCard->getProperty("IOName"));
				idKey=OSDynamicCast(OSData, PTCard->getProperty("vendor-id"));
				if (idKey)
					vendor_id=*(UInt32*)idKey->getBytesNoCopy();
				if ((str->isEqualTo("display"))&&(vendor_id==0x10de)){
					PTCard->setMemoryEnable(true);
					nvio = PTCard->mapDeviceMemoryWithIndex(0);		
					addr = (vm_address_t)nvio->getVirtualAddress();
					idKey=OSDynamicCast(OSData, PTCard->getProperty("device-id"));
					if (idKey)
						nvclock.card[i].device_id=*(UInt32*)idKey->getBytesNoCopy();
					IOLog("Vendor ID: %x, Device ID: %x\n", vendor_id, nvclock.card[i].device_id);
					nvclock.card[i].arch = get_gpu_arch(nvclock.card[i].device_id);
					IOLog("Architecture: %x\n", nvclock.card[i].arch);
					nvclock.card[i].number = i;
					nvclock.card[i].card_name = (char*)get_card_name(nvclock.card[i].device_id, &nvclock.card[i].gpu);
					IOLog("%s\n", nvclock.card[i].card_name);
					nvclock.card[i].state = 0;
					
					nvclock.card[i].reg_address = addr;
					map_mem_card( &nvclock.card[i], addr );
					
					
					
					
					i++;
					
				}
			}
		}
	}
	
	nvclock.num_cards = i;
	
	if (!i) {
		IOLog("PTKawainVi: No nVidia graphics adapters found\n");
	}	
	
	return nvclock.num_cards;
}
コード例 #10
0
ファイル: FakeSMC.cpp プロジェクト: ritzcarltn/HWSensors
bool FakeSMC::start(IOService *provider)
{
	if (!super::start(provider)) 
        return false;

    if (!(keyStore = OSDynamicCast(FakeSMCKeyStore, waitForMatchingService(serviceMatching(kFakeSMCKeyStoreService), kFakeSMCDefaultWaitTimeout)))) {
        HWSensorsInfoLog("still waiting for FakeSMCKeyStore...");
        return false;
//        HWSensorsDebugLog("creating FakeSMCKeyStore");
//        
//        if (!(keyStore = new FakeSMCKeyStore)) {
//            HWSensorsInfoLog("failed to create FakeSMCKeyStore");
//            return false;
//        }
//
//        HWSensorsDebugLog("initializing FakeSMCKeyStore");
//
//        if (keyStore->initAndStart(this, configuration)) {
//            keyStore->setProperty("IOUserClientClass", "FakeSMCKeyStoreUserClient");
//        }
//        else {
//            keyStore->release();
//            HWSensorsFatalLog("failed to initialize FakeSMCKeyStore device");
//            return false;
//        }
    }

//    if (IOService *resources = waitForMatchingService(serviceMatching("IOResources"), 0))
//        this->attach(resources);

    OSDictionary *configuration = OSDynamicCast(OSDictionary, getProperty("Configuration"));

    // Load preconfigured keys
    HWSensorsDebugLog("loading keys...");

    if (!configuration) {
        HWSensorsFatalLog("no configuration node found!");
        return false;
    }

    if (UInt32 count = keyStore->addKeysFromDictionary(OSDynamicCast(OSDictionary, configuration->getObject("Keys")))) {
        HWSensorsInfoLog("%d preconfigured key%s added", count, count == 1 ? "" : "s");
    }
	else {
		HWSensorsWarningLog("no preconfigured keys found");
	}

    // Load wellknown type names
    HWSensorsDebugLog("loading types...");

    keyStore->addWellKnownTypesFromDictionary(OSDynamicCast(OSDictionary, configuration->getObject("Types")));

    // Set Clover platform keys
    if (OSDictionary *dictionary = OSDynamicCast(OSDictionary, configuration->getObject("Clover"))) {
        UInt32 count = 0;
        if (IORegistryEntry* cloverPlatformNode = fromPath("/efi/platform", gIODTPlane)) {
            if (OSIterator *iterator = OSCollectionIterator::withCollection(dictionary)) {
                while (OSString *name = OSDynamicCast(OSString, iterator->getNextObject())) {
                    if (OSData *data = OSDynamicCast(OSData, cloverPlatformNode->getProperty(name))) {
                        if (OSArray *items = OSDynamicCast(OSArray, dictionary->getObject(name))) {
                            OSString *key = OSDynamicCast(OSString, items->getObject(0));
                            OSString *type = OSDynamicCast(OSString, items->getObject(1));

                            if (keyStore->addKeyWithValue(key->getCStringNoCopy(), type->getCStringNoCopy(), data->getLength(), data->getBytesNoCopy()))
                                count++;
                        }
                    }
                }
                OSSafeRelease(iterator);
            }
        }

        if (count)
            HWSensorsInfoLog("%d key%s exported by Clover EFI", count, count == 1 ? "" : "s");
    }

    // Check if we have SMC already
    bool smcDeviceFound = false;

    if (OSDictionary *matching = serviceMatching("IOACPIPlatformDevice")) {
        if (OSIterator *iterator = getMatchingServices(matching)) {
            
            OSString *smcNameProperty = OSString::withCString("APP0001");

            while (IOService *service = (IOService*)iterator->getNextObject()) {
                
                OSObject *serviceNameProperty = service->getProperty("name");
                
                if (serviceNameProperty && serviceNameProperty->isEqualTo(smcNameProperty)) {
                    smcDeviceFound = true;
                }
            }
            
            OSSafeRelease(iterator);
        }
        
        OSSafeRelease(matching);
    }

    if (!smcDeviceFound) {
        if (!(smcDevice = new FakeSMCDevice)) {
            HWSensorsInfoLog("failed to create SMC device");
            return false;
        }

        IOService *platformExpert = waitForMatchingService(serviceMatching("IOACPIPlatformExpert"), kFakeSMCDefaultWaitTimeout);

        if (!smcDevice->initAndStart(platformExpert, this)) {
            HWSensorsFatalLog("failed to initialize SMC device");
            return false;
        }
    }
    else {
        HWSensorsInfoLog("found physical SMC device, will not create virtual one. Providing only basic plugins functionality");
    }

    int arg_value = 1;

    // Load keys from NVRAM
    if (PE_parse_boot_argn("-fakesmc-use-nvram", &arg_value, sizeof(arg_value))) {
        if (UInt32 count = keyStore->loadKeysFromNVRAM())
            HWSensorsInfoLog("%d key%s loaded from NVRAM", count, count == 1 ? "" : "s");
        else
            HWSensorsInfoLog("NVRAM will be used to store system written keys...");
    }

  	registerService();

	return true;
}