bool GmaSensors::willReadSensorValue(FakeSMCSensor *sensor, float *outValue) { if (sensor->getGroup() == kFakeSMCTemperatureSensor) { short value = 0; if (mmio_base) { OUTVID(TIC1, 3); // if ((INVID16(TSC1) & (1<<15)) && !(INVID16(TSC1) & (1<<8)))//enabled and ready for (int i=0; i<1000; i++) { //attempts to ready if (INVID16(TSS1) & (1<<10)) //valid? break; IOSleep(10); } value = INVID8(TR1); } *outValue = (float)(150 - value); } return true; }
float X3100monitor::getSensorValue(FakeSMCSensor *sensor) { if (sensor->getGroup() == kFakeSMCTemperatureSensor) { short value = 0; if (mmio_base) { OUTVID(TIC1, 3); // if ((INVID16(TSC1) & (1<<15)) && !(INVID16(TSC1) & (1<<8)))//enabled and ready for (int i=0; i<1000; i++) { //attempts to ready if (INVID16(TSS1) & (1<<10)) //valid? break; IOSleep(10); } value = INVID8(TR1); } return 150 - value; } return 0; }
IOReturn X3100monitor::callPlatformFunction(const OSSymbol *functionName, bool waitForFunction, void *param1, void *param2, void *param3, void *param4 ) { UInt16 t; if (functionName->isEqualTo(kFakeSMCGetValueCallback)) { const char* name = (const char*)param1; void* data = param2; if (name && data) { if (OSNumber *number = OSDynamicCast(OSNumber, sensors->getObject(name))) { UInt32 index = number->unsigned16BitValue(); if (index != numCard) { return kIOReturnBadArgument; } } short value; if (mmio_base) { OUTVID(TIC1, 3); // if ((INVID16(TSC1) & (1<<15)) && !(INVID16(TSC1) & (1<<8)))//enabled and ready for (int i=0; i<1000; i++) { //attempts to ready if (INVID16(TSS1) & (1<<10)) //valid? break; IOSleep(10); } value = INVID8(TR1); } t = 140 - value; bcopy(&t, data, 2); return kIOReturnSuccess; } //DebugLog("bad argument key name or data"); return kIOReturnBadArgument; } return super::callPlatformFunction(functionName, waitForFunction, param1, param2, param3, param4); }
bool X3100monitor::start(IOService * provider) { if (!provider || !super::start(provider)) return false; if (!(fakeSMC = waitForService(serviceMatching(kFakeSMCDeviceService)))) { WarningLog("Can't locate fake SMC device, kext will not load"); return false; } IOMemoryDescriptor * theDescriptor; IOPhysicalAddress bar = (IOPhysicalAddress)((VCard->configRead32(kMCHBAR)) & ~0xf); DebugLog("Fx3100: register space=%08lx\n", (long unsigned int)bar); theDescriptor = IOMemoryDescriptor::withPhysicalAddress (bar, 0x2000, kIODirectionOutIn); // | kIOMapInhibitCache); if(theDescriptor != NULL) { mmio = theDescriptor->map(); if(mmio != NULL) { mmio_base = (volatile UInt8 *)mmio->getVirtualAddress(); #if DEBUG DebugLog(" MCHBAR mapped\n"); for (int i=0; i<0x2f; i +=16) { DebugLog("%04lx: ", (long unsigned int)i+0x1000); for (int j=0; j<16; j += 1) { DebugLog("%02lx ", (long unsigned int)INVID8(i+j+0x1000)); } DebugLog("\n"); } #endif } else { InfoLog(" MCHBAR failed to map\n"); return -1; } } char name[5]; //try to find empty key for (int i = 0; i < 0x10; i++) { snprintf(name, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, i); UInt8 length = 0; void * data = 0; IOReturn result = fakeSMC->callPlatformFunction(kFakeSMCGetKeyValue, true, (void *)name, (void *)&length, (void *)&data, 0); if (kIOReturnSuccess == result) { continue; } if (addSensor(name, TYPE_SP78, 2, i)) { numCard = i; break; } } if (kIOReturnSuccess != fakeSMC->callPlatformFunction(kFakeSMCAddKeyHandler, false, (void *)name, (void *)TYPE_SP78, (void *)2, this)) { WarningLog("Can't add key to fake SMC device, kext will not load"); return false; } return true; }