void ListHookedDevice::Item::setVendorProduct(void) { if (! device_) return; IORegistryEntry* dev = device_; while (dev) { const OSNumber* vid = NULL; vid = OSDynamicCast(OSNumber, dev->getProperty(kIOHIDVendorIDKey)); const OSNumber* pid = NULL; pid = OSDynamicCast(OSNumber, dev->getProperty(kIOHIDProductIDKey)); if (vid && pid) { vendor_ = vid->unsigned32BitValue(); product_ = pid->unsigned32BitValue(); goto finish; } // check parent property. dev = dev->getParentEntry(IORegistryEntry::getPlane(kIOServicePlane)); } finish: IOLOG_DEBUG("HookedDevice::setVendorProduct device_:%p, vendor_:0x%04x, product_:0x%04x\n", device_, vendor_.get(), product_.get()); }
// ====================================================================== void ListHookedDevice::Item::setDeviceIdentifier(void) { if (!device_) return; IORegistryEntry* dev = device_; while (dev) { const OSNumber* vid = nullptr; vid = OSDynamicCast(OSNumber, dev->getProperty(kIOHIDVendorIDKey)); const OSNumber* pid = nullptr; pid = OSDynamicCast(OSNumber, dev->getProperty(kIOHIDProductIDKey)); if (vid && pid) { deviceIdentifier_.setVendor(DeviceVendor(vid->unsigned32BitValue())); deviceIdentifier_.setProduct(DeviceProduct(pid->unsigned32BitValue())); goto finish; } else { // ApplePS2Keyboard does not have ProductID, // so we check for Manufacturer and Product strings const char* name = dev->getName(); if (name && strcmp(name, "ApplePS2Keyboard") == 0) { // kIOHIDManufacturerKey == "Manufacturer" // kIOHIDProductKey == "Product" const OSString* manufacturer = OSDynamicCast(OSString, dev->getProperty(kIOHIDManufacturerKey)); const OSString* product = OSDynamicCast(OSString, dev->getProperty(kIOHIDProductKey)); if (manufacturer && product) { if (manufacturer->isEqualTo("Apple") && product->isEqualTo("Keyboard")) { deviceIdentifier_.setVendor(DeviceVendor::APPLE_COMPUTER); deviceIdentifier_.setProduct(DeviceProduct::APPLE_INTERNAL_KEYBOARD_TRACKPAD_0x0218); goto finish; } } } } // check parent property. dev = dev->getParentEntry(IORegistryEntry::getPlane(kIOServicePlane)); } finish: // Set LocationID if (dev) { const OSNumber* locationid = nullptr; locationid = OSDynamicCast(OSNumber, dev->getProperty(kIOHIDLocationIDKey)); if (locationid) { deviceIdentifier_.setLocation(DeviceLocation(locationid->unsigned32BitValue())); } } IOLOG_DEBUG("HookedDevice::setVendorProductLocation device_:%p, vendor:0x%04x, product:0x%04x location:0x%04x\n", device_, deviceIdentifier_.getVendor().get(), deviceIdentifier_.getProduct().get(), deviceIdentifier_.getLocation().get()); }
void IOPlatformExpert::registerNVRAMController(IONVRAMController * caller) { OSData * data; IORegistryEntry * entry; OSString * string = 0; uuid_string_t uuid; entry = IORegistryEntry::fromPath( "/efi/platform", gIODTPlane ); if ( entry ) { data = OSDynamicCast( OSData, entry->getProperty( "system-id" ) ); if ( data && data->getLength( ) == 16 ) { SHA1_CTX context; uint8_t digest[ SHA_DIGEST_LENGTH ]; const uuid_t space = { 0x2A, 0x06, 0x19, 0x90, 0xD3, 0x8D, 0x44, 0x40, 0xA1, 0x39, 0xC4, 0x97, 0x70, 0x37, 0x65, 0xAC }; SHA1Init( &context ); SHA1Update( &context, space, sizeof( space ) ); SHA1Update( &context, data->getBytesNoCopy( ), data->getLength( ) ); SHA1Final( digest, &context ); digest[ 6 ] = ( digest[ 6 ] & 0x0F ) | 0x50; digest[ 8 ] = ( digest[ 8 ] & 0x3F ) | 0x80; uuid_unparse( digest, uuid ); string = OSString::withCString( uuid ); } entry->release( ); } if ( string == 0 ) { entry = IORegistryEntry::fromPath( "/options", gIODTPlane ); if ( entry ) { data = OSDynamicCast( OSData, entry->getProperty( "platform-uuid" ) ); if ( data && data->getLength( ) == sizeof( uuid_t ) ) { uuid_unparse( ( uint8_t * ) data->getBytesNoCopy( ), uuid ); string = OSString::withCString( uuid ); } entry->release( ); } } if ( string ) { getProvider( )->setProperty( kIOPlatformUUIDKey, string ); publishResource( kIOPlatformUUIDKey, string ); string->release( ); } publishResource("IONVRAM"); }
/****************************************************************************** * CodecCommander::parseCodecPowerState - get codec power state from IOReg ******************************************************************************/ void CodecCommander::parseCodecPowerState() { // monitor power state of hda audio codec IORegistryEntry *hdaDriverEntry = IORegistryEntry::fromPath(hdaDriverPath); if (hdaDriverEntry != NULL) { OSNumber *powerState = OSDynamicCast(OSNumber, hdaDriverEntry->getProperty("IOAudioPowerState")); if (powerState != NULL) { hdaCurrentPowerState = powerState->unsigned8BitValue(); // if hda codec changed power state if (hdaCurrentPowerState != hdaPrevPowerState) { // store current power state as previous state for next workloop cycle hdaPrevPowerState = hdaCurrentPowerState; // notify about codec power loss state if (hdaCurrentPowerState == 0x0) { DEBUG_LOG("CodecCommander: cc: --> hda codec lost power\n"); eapdPoweredDown = true; coldBoot = false; //codec entered fugue state or sleep - no longer a cold boot updateCount = 0; } } } else { DEBUG_LOG("CodecCommander: IOAudioPowerState unknown\n"); return; } } else { DEBUG_LOG("CodecCommander: %s is unreachable\n", hdaDriverPath); return; } hdaDriverEntry->release(); }
/****************************************************************************** * CodecCommander::parseAudioEngineState - repeats the action when timer fires ******************************************************************************/ void CodecCommander::parseAudioEngineState() { IORegistryEntry *hdaEngineOutputEntry = IORegistryEntry::fromPath(engineOutputPath); if (hdaEngineOutputEntry != NULL) { OSNumber *state = OSDynamicCast(OSNumber, hdaEngineOutputEntry->getProperty("IOAudioEngineState")); if (state != NULL) { hdaEngineState = state->unsigned8BitValue(); //DEBUG_LOG("CodecCommander: EngineOutput power state %d\n", hdaEngineState); if (hdaEngineState == 0x1) DEBUG_LOG("CodecCommander: cc: --> audio stream active\n"); //else //DEBUG_LOG("CodecCommander: cc: --> audio stream inactive\n"); // will produce spam in console } else { DEBUG_LOG("CodecCommander: IOAudioEngineState unknown\n"); return; } } else { DEBUG_LOG("CodecCommander: %s is unreachable\n", engineOutputPath); return; } hdaEngineOutputEntry->release(); }
bool net_lundman_zfs_zvol::start (IOService *provider) { bool res = super::start(provider); IOLog("ZFS: Loading module ... \n"); /* * Initialize /dev/zfs, this calls spa_init->dmu_init->arc_init-> etc */ zfs_ioctl_osx_init(); ///sysctl_register_oid(&sysctl__debug_maczfs); //sysctl_register_oid(&sysctl__debug_maczfs_stalk); zfs_vfsops_init(); /* * When is the best time to start the system_taskq? It is strictly * speaking not used by SPL, but by ZFS. ZFS should really start it? */ system_taskq_init(); /* * hostid is left as 0 on OSX, and left to be set if developers wish to * use it. If it is 0, we will hash the hardware.uuid into a 32 bit * value and set the hostid. */ if (!zone_get_hostid(NULL)) { uint32_t myhostid = 0; IORegistryEntry *ioregroot = IORegistryEntry::getRegistryRoot(); if(ioregroot) { //IOLog("ioregroot is '%s'\n", ioregroot->getName(gIOServicePlane)); IORegistryEntry *macmodel = ioregroot->getChildEntry(gIOServicePlane); if(macmodel) { //IOLog("macmodel is '%s'\n", macmodel->getName(gIOServicePlane)); OSObject *ioplatformuuidobj; //ioplatformuuidobj = ioregroot->getProperty("IOPlatformUUID", gIOServicePlane, kIORegistryIterateRecursively); ioplatformuuidobj = macmodel->getProperty(kIOPlatformUUIDKey); if(ioplatformuuidobj) { OSString *ioplatformuuidstr = OSDynamicCast(OSString, ioplatformuuidobj); //IOLog("IOPlatformUUID is '%s'\n", ioplatformuuidstr->getCStringNoCopy()); myhostid = fnv_32a_str(ioplatformuuidstr->getCStringNoCopy(), FNV1_32A_INIT); sysctlbyname("kern.hostid", NULL, NULL, &myhostid, sizeof(myhostid)); printf("ZFS: hostid set to %08x from UUID '%s'\n", myhostid, ioplatformuuidstr->getCStringNoCopy()); } } } } return res; }
// ---------------------------------------------------------------------- bool org_pqrs_driver_Seil::isTargetDevice(IOHIKeyboard* kbd) { if (!kbd) return false; // ------------------------------------------------------------ uint32_t vendorID = 0; uint32_t productID = 0; IORegistryEntry* dev = kbd; while (dev) { const OSNumber* vid = nullptr; vid = OSDynamicCast(OSNumber, dev->getProperty(kIOHIDVendorIDKey)); const OSNumber* pid = nullptr; pid = OSDynamicCast(OSNumber, dev->getProperty(kIOHIDProductIDKey)); if (vid && pid) { vendorID = vid->unsigned32BitValue(); productID = pid->unsigned32BitValue(); goto finish; } // check parent property. dev = dev->getParentEntry(IORegistryEntry::getPlane(kIOServicePlane)); } finish: enum { VENDOR_LOGITECH = 0x046d, PRODUCT_LOGITECH_G700_LASER_MOUSE = 0xc06b, }; if (vendorID == VENDOR_LOGITECH && productID == PRODUCT_LOGITECH_G700_LASER_MOUSE) { IOLOG_INFO("vendorID:0x%04x, productID:0x%04x (skipped)\n", vendorID, productID); return false; } return true; }
bool getFSB() { FSB = 0; IORegistryEntry* efi = IORegistryEntry::fromPath("/efi/platform", IORegistryEntry::getPlane("IODeviceTree")); if (efi == 0) { warn("EFI registry entry not found!\n"); return false; } OSData* fsb = (OSData*) efi->getProperty("FSBFrequency"); if (fsb == 0) { warn("FSB frequency entry not found!\n"); return false; } bcopy(fsb->getBytesNoCopy(), &FSB, 8); info("FSB = %llu MHz\n", FSB/1000000ULL); efi = 0; fsb = 0; // in dono ka kaam khatam return true; }
int IODTGetDefault(const char *key, void *infoAddr, unsigned int infoSize ) { IORegistryEntry *defaults; OSData *defaultObj; unsigned int defaultSize; defaults = IORegistryEntry::fromPath( "/defaults", gIODTPlane ); if ( defaults == 0 ) return -1; defaultObj = OSDynamicCast( OSData, defaults->getProperty(key) ); if ( defaultObj == 0 ) return -1; defaultSize = defaultObj->getLength(); if ( defaultSize > infoSize) return -1; memcpy( infoAddr, defaultObj->getBytesNoCopy(), defaultSize ); return 0; }
void net_lundman_zfs_zvol_device::getBSDName(void) { IORegistryEntry *ioregdevice = OSDynamicCast ( IORegistryEntry, this ); if(ioregdevice) { OSObject *bsdnameosobj; bsdnameosobj = ioregdevice->getProperty(kIOBSDNameKey, gIOServicePlane, kIORegistryIterateRecursively); if(bsdnameosobj) { OSString* bsdnameosstr = OSDynamicCast(OSString, bsdnameosobj); IOLog("zvol: bsd name is '%s'\n", bsdnameosstr->getCStringNoCopy()); if (zv) { zv->zv_bsdname[0] = 'r'; // for 'rdiskX'. strlcpy(&zv->zv_bsdname[1], bsdnameosstr->getCStringNoCopy(), sizeof(zv->zv_bsdname)-1); //IOLog("name assigned '%s'\n", zv->zv_bsdname); } } } }
/****************************************************************************** * CodecCommander::parseCodecPowerState - get codec power state from IOReg ******************************************************************************/ void CodecCommander::parseCodecPowerState() { // monitor power state of hda audio codec IORegistryEntry *hdaDriverEntry = IORegistryEntry::fromPath(mConfiguration->getHDADriverPath()); if (hdaDriverEntry != NULL) { OSNumber *powerState = OSDynamicCast(OSNumber, hdaDriverEntry->getProperty("IOAudioPowerState")); if (powerState != NULL) { hdaCurrentPowerState = powerState->unsigned8BitValue(); // if hda codec changed power state if (hdaCurrentPowerState != hdaPrevPowerState) { DEBUG_LOG("CodecCommander: cc - power state transition from %d to %d recorded\n", hdaPrevPowerState, hdaCurrentPowerState); // store current power state as previous state for next workloop cycle hdaPrevPowerState = hdaCurrentPowerState; // notify about codec power loss state if (hdaCurrentPowerState == 0x0) { DEBUG_LOG("CodecCommander: HDA codec lost power\n"); handleStateChange(kStateSleep); // power down EAPDs properly eapdPoweredDown = true; coldBoot = false; //codec entered fugue state or sleep - no longer a cold boot } } } else DEBUG_LOG("CodecCommander: IOAudioPowerState unknown\n"); hdaDriverEntry->release(); } else DEBUG_LOG("CodecCommander: %s is unreachable\n", mConfiguration->getHDADriverPath()); }
OSReturn NoSleepExtension::readNVRAM(UInt8 *value) { #ifdef DEBUG IOLog("%s[%p]::%s(%p)\n", getName(), this, __FUNCTION__, value); #endif OSReturn ret = kOSReturnError; IORegistryEntry *entry = IORegistryEntry::fromPath( "/options", gIODTPlane ); if ( entry ) { OSObject *rawValue = entry->getProperty(IORegistrySleepSuppressionMode); if(rawValue != NULL) { #ifdef DEBUG IOLog("%s: rawValueClassName: %s\n", getName(), rawValue->getMetaClass()->getClassName()); #endif OSData *data = OSDynamicCast(OSData, rawValue); if(data->getLength() == 1) { *value = ((UInt8 *)data->getBytesNoCopy())[0]; ret = kOSReturnSuccess; #ifdef DEBUG IOLog("%s: reading nvram, value: 0x%02x\n", getName(), (*value)); #endif } #ifdef DEBUG else { IOLog("%s: read error: data->Len %s 1\n", getName(), (data->getLength() == 1)?"==":"!="); } #endif } entry->release(); } return ret; }
int IODTGetLoaderInfo( const char *key, void **infoAddr, int *infoSize ) { IORegistryEntry *chosen; OSData *propObj; unsigned int *propPtr; unsigned int propSize; chosen = IORegistryEntry::fromPath( "/chosen/memory-map", gIODTPlane ); if ( chosen == 0 ) return -1; propObj = OSDynamicCast( OSData, chosen->getProperty(key) ); if ( propObj == 0 ) return -1; propSize = propObj->getLength(); if ( propSize != (2 * sizeof(UInt32)) ) return -1; propPtr = (unsigned int *)propObj->getBytesNoCopy(); if ( propPtr == 0 ) return -1; *infoAddr = (void *)(uintptr_t) (propPtr[0]); *infoSize = (int) (propPtr[1]); return 0; }
IOPolledFilePollers * IOPolledFilePollers::copyPollers(IOService * media) { IOPolledFilePollers * vars; IOReturn err; IOService * service; OSObject * obj; IORegistryEntry * next; IORegistryEntry * child; if ((obj = media->copyProperty(kIOPolledInterfaceStackKey))) { return (OSDynamicCast(IOPolledFilePollers, obj)); } do { vars = OSTypeAlloc(IOPolledFilePollers); vars->init(); vars->pollers = OSArray::withCapacity(4); if (!vars->pollers) { err = kIOReturnNoMemory; break; } next = vars->media = media; do { IOPolledInterface * poller; OSObject * obj; obj = next->getProperty(kIOPolledInterfaceSupportKey); if (kOSBooleanFalse == obj) { vars->pollers->flushCollection(); break; } else if ((poller = OSDynamicCast(IOPolledInterface, obj))) vars->pollers->setObject(poller); if ((service = OSDynamicCast(IOService, next)) && service->getDeviceMemory() && !vars->pollers->getCount()) break; child = next; } while ((next = child->getParentEntry(gIOServicePlane)) && child->isParent(next, gIOServicePlane, true)); if (!vars->pollers->getCount()) { err = kIOReturnUnsupported; break; } } while (false); media->setProperty(kIOPolledInterfaceStackKey, vars); return (vars); }
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; }
// Class probe IOService * VoodooPState::probe(IOService * provider, SInt32 * score) { Ready = false; // Probe the superclass if (IOService::probe(provider, score) != this) return NULL; // Read our own values from the property list OSDictionary * dictionary = OSDynamicCast(OSDictionary, getProperty(keyPowerControl)); if (!dictionary) return NULL; UseEfiFsb = getPlistValue(dictionary, keyUseEfiFsb); VoltageOverride = getPlistValue(dictionary, keyVoltageOverride); VoltageProbe = getPlistValue(dictionary, keyVoltageProbe); UserVoltageMax = getPlistValue(dictionary, keyUserVoltageMax); UserVoltageMin = getPlistValue(dictionary, keyUserVoltageMin); ColdStart = getPlistValue(dictionary, keyColdStart); TimerInterval = getPlistValue(dictionary, keyTimerInterval); UseACPI = getPlistValue(dictionary, keyUseACPI); if(TimerInterval < 50){ TimerInterval = 50; } // Get CPU's from I/O Kit CpuCount = getCpuCount(); // No CPU's found -> bailout if (CpuCount == 0) return NULL; // Get FSB from /efi/platform CpuFSB = gPEClockFrequencyInfo.bus_frequency_max_hz >> 2; if (UseEfiFsb) { IORegistryEntry * entry = fromPath(keyEfiPlatform, gIODTPlane); if (entry) { OSObject * object = entry->getProperty(keyEfiFsbFrequency); if (object && (OSTypeIDInst(object) == OSTypeID(OSData))) { OSData * data = OSDynamicCast(OSData, object); if (data) { CpuFSB = * (UInt32 *) data->getBytesNoCopy(); gPEClockFrequencyInfo.bus_frequency_max_hz = CpuFSB << 2; } } } } CpuFSB = (CpuFSB+Mega/2) / Mega; // Mega is enough #if SUPPORT_VOODOO_KERNEL { UInt64 magic; nanoseconds_to_absolutetime(~(0), &magic); VoodooKernel = (magic == 2); } #endif // Enumerate CPU's CpuCoreTech = Unknown; { uint32_t data[4]; do_cpuid(0, data); ((uint32_t*)vendor)[0] = data[1]; ((uint32_t*)vendor)[1] = data[3]; ((uint32_t*)vendor)[2] = data[2]; vendor[15] = 0; do_cpuid(1, data); CpuSignature = data[0]; // Features ((uint32_t*)&Features)[0] = data[3]; ((uint32_t*)&Features)[1] = data[2]; for( int i = 0; i < 3; i++ ){ do_cpuid(0x80000002+i, data); memcpy( &brand_string[i*16], data, 16 ); } brand_string[16*3] = 0; } // Find core technology and cross core vendor specifics // Intel if (!strncmp(vendor, CPUID_VID_INTEL, sizeof(CPUID_VID_INTEL))) { if(!intel_probe(this)) return NULL; } // AMD else if (!strncmp(vendor, CPUID_VID_AMD, sizeof(CPUID_VID_AMD))) { if(!amd_probe(this)) return NULL; } // Unknown CPU or core technology else { ErrorLog("CPU: Core Technology Unknown - Signature %x (%s)(%s)", (unsigned int)CpuSignature, vendor, brand_string); return NULL; } return this; }
static void createNubs(IOService *provider) { const char nameID[2][8] = {"@0,name", "@1,name"}; const char name[11] = "Aty,Radeon"; const char typeID[2][15] = {"@0,device_type", "@1,device_type"}; const char type[] = "display"; OSObject *tempObj; int i; if (provider->getProperty(kIONDRVIgnoreKey)) return; provider->setProperty(kIONDRVIgnoreKey, kOSBooleanTrue); //prevent IONDRVFramebuffer from match LOG("createNubs\n"); if (!provider->getProperty("@0,name") && !provider->getProperty("@1,name")) { for (i = 0;i < 2;i++) { // Debug tempObj = OSData::withBytes(name, 11); provider->setProperty(nameID[i], tempObj); tempObj->release(); tempObj = OSData::withBytes(type, 8); provider->setProperty(typeID[i], tempObj); tempObj->release(); } } // have to move below part from IONDRVFramebuffer to make it work IORegistryIterator * iter; IORegistryEntry * next; IOService * newNub; OSArray * toDo = 0; bool firstLevel; OSData * data; if (provider->getProperty("@0,name")) { OSDictionary * dict; OSCollectionIterator * keys; const OSSymbol * key; char buffer[80]; const char * keyChrs; size_t len; char c; dict = provider->dictionaryWithProperties(); keys = OSCollectionIterator::withCollection(dict); if (dict) dict->release(); if (keys) { while ((key = OSDynamicCast(OSSymbol, keys->getNextObject()))) { keyChrs = key->getCStringNoCopy(); if ('@' != keyChrs[0]) continue; len = 0; do { c = keyChrs[len]; if (!c || (c == ',')) break; buffer[len] = c; len++; } while (len < (sizeof(buffer) - 1)); if (!c) continue; buffer[len] = 0; keyChrs += len + 1; next = provider->childFromPath(buffer, gIODTPlane); if (!next) { next = new IOService; if (next && !next->init()) { next->release(); next = 0; } if (!next) continue; next->setLocation(&buffer[1]); if (!next->attachToParent(provider, gIODTPlane)) continue; } OSObject * obj = dict->getObject(key); next->setProperty(keyChrs, dict->getObject(key)); if (!strcmp(keyChrs, "name")) { OSData * data = OSDynamicCast(OSData, obj); if (data) next->setName((const char *) data->getBytesNoCopy()); } next->release(); provider->removeProperty(key); } keys->release(); } } iter = IORegistryIterator::iterateOver( provider, gIODTPlane, 0 ); toDo = OSArray::withCapacity(2); if (iter && toDo) { bool haveDoneLibInit = false; UInt32 index = 0; do { while ((next = (IORegistryEntry *) iter->getNextObject())) { firstLevel = (provider == next->getParentEntry(gIODTPlane)); if (firstLevel) { data = OSDynamicCast( OSData, next->getProperty("device_type")); if (!data || (0 != strcmp("display", (char *) data->getBytesNoCopy()))) continue; if (!haveDoneLibInit) { haveDoneLibInit = (kIOReturnSuccess == _IONDRVLibrariesInitialize(provider)); if (!haveDoneLibInit) continue; } next->setProperty( kIOFBDependentIDKey, (uintptr_t) provider, 64 ); next->setProperty( kIOFBDependentIndexKey, index, 32 ); next->setProperty( kIONDRVIgnoreKey, kOSBooleanTrue ); index++; } toDo->setObject( next ); iter->enterEntry(); } } while (iter->exitEntry()); } if (iter) iter->release(); if (toDo) { OSObject * obj; OSArray * deviceMemory; obj = provider->copyProperty(gIODeviceMemoryKey); deviceMemory = OSDynamicCast(OSArray, obj); for (unsigned int i = 0; (next = (IORegistryEntry *) toDo->getObject(i)); i++) { newNub = new IONDRVDevice; if (!newNub) continue; if (!newNub->init(next, gIODTPlane)) { newNub->free(); newNub = 0; continue; } if (deviceMemory) newNub->setDeviceMemory(deviceMemory); newNub->attach(provider); newNub->registerService(kIOServiceSynchronous); } if (obj) obj->release(); toDo->release(); } }
IORegistryEntry * IODeviceTreeAlloc( void * dtTop ) { IORegistryEntry * parent; IORegistryEntry * child; IORegistryIterator * regIter; DTEntryIterator iter; DTEntry dtChild; DTEntry mapEntry; OSArray * stack; OSData * prop; OSDictionary * allInts; vm_offset_t * dtMap; unsigned int propSize; bool intMap; bool freeDT; gIODTPlane = IORegistryEntry::makePlane( kIODeviceTreePlane ); gIODTNameKey = OSSymbol::withCStringNoCopy( "name" ); gIODTUnitKey = OSSymbol::withCStringNoCopy( "AAPL,unit-string" ); gIODTCompatibleKey = OSSymbol::withCStringNoCopy( "compatible" ); gIODTTypeKey = OSSymbol::withCStringNoCopy( "device_type" ); gIODTModelKey = OSSymbol::withCStringNoCopy( "model" ); gIODTSizeCellKey = OSSymbol::withCStringNoCopy( "#size-cells" ); gIODTAddressCellKey = OSSymbol::withCStringNoCopy( "#address-cells" ); gIODTRangeKey = OSSymbol::withCStringNoCopy( "ranges" ); gIODTPersistKey = OSSymbol::withCStringNoCopy( "IODTPersist" ); assert( gIODTPlane && gIODTCompatibleKey && gIODTTypeKey && gIODTModelKey && gIODTSizeCellKey && gIODTAddressCellKey && gIODTRangeKey && gIODTPersistKey ); gIODTDefaultInterruptController = OSSymbol::withCStringNoCopy("IOPrimaryInterruptController"); gIODTNWInterruptMappingKey = OSSymbol::withCStringNoCopy("IONWInterrupts"); gIODTAAPLInterruptsKey = OSSymbol::withCStringNoCopy("AAPL,interrupts"); gIODTPHandleKey = OSSymbol::withCStringNoCopy("AAPL,phandle"); gIODTInterruptParentKey = OSSymbol::withCStringNoCopy("interrupt-parent"); gIODTPHandles = OSArray::withCapacity( 1 ); gIODTPHandleMap = OSArray::withCapacity( 1 ); gIODTInterruptCellKey = OSSymbol::withCStringNoCopy("#interrupt-cells"); assert( gIODTDefaultInterruptController && gIODTNWInterruptMappingKey && gIODTAAPLInterruptsKey && gIODTPHandleKey && gIODTInterruptParentKey && gIODTPHandles && gIODTPHandleMap && gIODTInterruptCellKey ); freeDT = (kSuccess == DTLookupEntry( 0, "/chosen/memory-map", &mapEntry )) && (kSuccess == DTGetProperty( mapEntry, "DeviceTree", (void **) &dtMap, &propSize )) && ((2 * sizeof(uint32_t)) == propSize); parent = MakeReferenceTable( (DTEntry)dtTop, freeDT ); stack = OSArray::withObjects( (const OSObject **) &parent, 1, 10 ); DTCreateEntryIterator( (DTEntry)dtTop, &iter ); do { parent = (IORegistryEntry *)stack->getObject( stack->getCount() - 1); //parent->release(); stack->removeObject( stack->getCount() - 1); while( kSuccess == DTIterateEntries( iter, &dtChild) ) { child = MakeReferenceTable( dtChild, freeDT ); child->attachToParent( parent, gIODTPlane); AddPHandle( child ); if( kSuccess == DTEnterEntry( iter, dtChild)) { stack->setObject( parent); parent = child; } // only registry holds retain child->release(); } } while( stack->getCount() && (kSuccess == DTExitEntry( iter, &dtChild))); stack->release(); DTDisposeEntryIterator( iter); // parent is now root of the created tree // make root name first compatible entry (purely cosmetic) if( (prop = (OSData *) parent->getProperty( gIODTCompatibleKey))) { parent->setName( parent->getName(), gIODTPlane ); parent->setName( (const char *) prop->getBytesNoCopy() ); } // attach tree to meta root parent->attachToParent( IORegistryEntry::getRegistryRoot(), gIODTPlane); parent->release(); if( freeDT ) { // free original device tree DTInit(0); IODTFreeLoaderInfo( "DeviceTree", (void *)dtMap[0], (int) round_page(dtMap[1]) ); } // adjust tree gIODTSharedInterrupts = OSDictionary::withCapacity(4); allInts = OSDictionary::withCapacity(4); intMap = false; regIter = IORegistryIterator::iterateOver( gIODTPlane, kIORegistryIterateRecursively ); assert( regIter && allInts && gIODTSharedInterrupts ); if( regIter && allInts && gIODTSharedInterrupts ) { while( (child = regIter->getNextObject())) { IODTMapInterruptsSharing( child, allInts ); if( !intMap && child->getProperty( gIODTInterruptParentKey)) intMap = true; } regIter->release(); } #if IODTSUPPORTDEBUG parent->setProperty("allInts", allInts); parent->setProperty("sharedInts", gIODTSharedInterrupts); regIter = IORegistryIterator::iterateOver( gIODTPlane, kIORegistryIterateRecursively ); if (regIter) { while( (child = regIter->getNextObject())) { OSArray * array = OSDynamicCast(OSArray, child->getProperty( gIOInterruptSpecifiersKey )); for( UInt32 i = 0; array && (i < array->getCount()); i++) { IOOptionBits options; IOReturn ret = IODTGetInterruptOptions( child, i, &options ); if( (ret != kIOReturnSuccess) || options) IOLog("%s[%ld] %ld (%x)\n", child->getName(), i, options, ret); } } regIter->release(); } #endif allInts->release(); if( intMap) // set a key in the root to indicate we found NW interrupt mapping parent->setProperty( gIODTNWInterruptMappingKey, (OSObject *) gIODTNWInterruptMappingKey ); return( parent); }
bool SMBIOSResolver::start(IOService * provider) { if( super::start(provider) != true ) return false; // Oh no if( IOService::getResourceService()->getProperty("SMBIOS-Resolver") ) return false; // We should exist only once if( !IOService::getResourceService()->getProperty("SMBIOS") ) return false; // AppleSMBIOS.kext didn´t start we bail out IOService * iosRoot = getServiceRoot(); if( !iosRoot ) return false; // Unable to get IOServiceRoot int doVerbose = 0; // PE_parse_boot_arg("smbios", &doVerbose); // bootarg SMBIOS=1 will give a verbose output to log (when I find something verbose worth outputting) // Dictionary from plist OSDictionary * hwDict = OSDynamicCast( OSDictionary, getProperty("Override")); // /rom/version IORegistryEntry * dtROMNode = fromPath("/rom", gIODTPlane); if( dtROMNode ) { OSString * romVersion = OSDynamicCast( OSString, hwDict->getObject("rom-version")); if(romVersion->getLength() > 0) dtROMNode->setProperty("version", OSData::withBytes(romVersion->getCStringNoCopy(), romVersion->getLength() + 1) ); dtROMNode->release(); } else { return false; // No /rom node in IODeviceTree plane } // root entries OSObject * dictString = 0; dictString = hwDict->getObject("manufacturer"); if(dictString) { OSString * rootManufacturer = OSDynamicCast( OSString, dictString); if(rootManufacturer->getLength() > 1) iosRoot->setProperty("manufacturer", OSData::withBytes(rootManufacturer->getCStringNoCopy(), rootManufacturer->getLength() + 1) ); } dictString = hwDict->getObject("system-type"); if(dictString) { OSData * systemType = OSDynamicCast( OSData, dictString); if(systemType) iosRoot->setProperty("system-type", systemType ); } dictString = hwDict->getObject("compatible"); if(dictString) { OSString * rootCompatible = OSDynamicCast( OSString, dictString); if(rootCompatible->getLength() > 1) iosRoot->setProperty("compatible", OSData::withBytes(rootCompatible->getCStringNoCopy(), rootCompatible->getLength() + 1) ); } dictString = hwDict->getObject("product-name"); if(dictString) { OSString * rootProductName = OSDynamicCast( OSString, dictString); if(rootProductName->getLength() > 1) iosRoot->setProperty("product-name", OSData::withBytes(rootProductName->getCStringNoCopy(), rootProductName->getLength() + 1) ); } dictString = hwDict->getObject("model"); if(dictString) { OSString * rootModel = OSDynamicCast( OSString, dictString); if(rootModel->getLength() > 1) { iosRoot->setProperty("model", OSData::withBytes(rootModel->getCStringNoCopy(), rootModel->getLength() + 1) ); iosRoot->setName(rootModel->getCStringNoCopy()); } } dictString = hwDict->getObject("version"); if(dictString) { OSString * rootVersion = OSDynamicCast( OSString, dictString); if(rootVersion->getLength() > 1) iosRoot->setProperty("version", OSData::withBytes(rootVersion->getCStringNoCopy(), rootVersion->getLength() + 1) ); } dictString = hwDict->getObject("board-id"); if(dictString) { OSString * rootBoardId = OSDynamicCast( OSString, dictString); if(rootBoardId->getLength() > 1) iosRoot->setProperty("board-id", OSData::withBytes(rootBoardId->getCStringNoCopy(), rootBoardId->getLength() + 1) ); } dictString = hwDict->getObject("serial-number"); if(dictString) { OSString * rootSerial = OSDynamicCast( OSString, dictString); if(rootSerial->getLength() > 1) { UInt8 length = rootSerial->getLength(); const char *serialNumberString = rootSerial->getCStringNoCopy(); // The serial-number property in the IORegistry is a 43-byte data object. // Bytes 0 through 2 are the last three bytes of the serial number string. // Bytes 11 through 20, inclusive, are the serial number string itself. // All other bytes are '\0'. OSData * data = OSData::withCapacity(43); if (data) { data->appendBytes(serialNumberString + (length - 3), 3); data->appendBytes(NULL, 10); data->appendBytes(serialNumberString, length); data->appendBytes(NULL, 43 - length - 10 - 3); iosRoot->setProperty("serial-number", data); data->release(); } iosRoot->setProperty(kIOPlatformSerialNumberKey, rootSerial); } } dictString = hwDict->getObject("UUID-key"); if(dictString) { OSString * rootUUIDKey = OSDynamicCast( OSString, hwDict->getObject("UUID-key")); iosRoot->setProperty(kIOPlatformUUIDKey, rootUUIDKey); publishResource(kIOPlatformUUIDKey, rootUUIDKey); } bool useEfiBus = false; UInt64 fsbFrequency = 0; UInt64 msr; dictString = hwDict->getObject("use-efi-bus"); if (dictString) useEfiBus = (OSDynamicCast(OSBoolean, dictString))->getValue(); IORegistryEntry * efiPlatform = fromPath("/efi/platform", gIODTPlane); if (efiPlatform && useEfiBus) { OSData * efiFSBFreq = OSDynamicCast(OSData, efiPlatform->getProperty("FSBFrequency")); bcopy(efiFSBFreq->getBytesNoCopy(), &fsbFrequency, efiFSBFreq->getLength()); efiPlatform->release(); } else { // No /efi/platform found fsbFrequency = gPEClockFrequencyInfo.bus_frequency_hz; // Value previously set by AppleSMBIOS if (!strncmp(cpuid_info()->cpuid_vendor, CPUID_VID_INTEL, sizeof(CPUID_VID_INTEL)) && (cpuid_info()->cpuid_features & CPUID_FEATURE_SSE2)) fsbFrequency /= 4; } dictString = hwDict->getObject("hardcode-bus"); if(dictString) { fsbFrequency = (OSDynamicCast(OSNumber, dictString))->unsigned64BitValue(); if (fsbFrequency) { if (fsbFrequency <= 10000) fsbFrequency *= 1000000; } else { if (!strncmp(cpuid_info()->cpuid_vendor, CPUID_VID_INTEL, sizeof(CPUID_VID_INTEL))) { if ((cpuid_info()->cpuid_family == 0x0f) && (cpuid_info()->cpuid_model >= 2)) { msr = rdmsr64(0x0000002C); switch ((msr >> 16) & 0x7) { case 0: if (cpuid_info()->cpuid_model == 2) fsbFrequency = 100 * 1000000; else { fsbFrequency = (800 * 1000000) / 3; // 266 fsbFrequency++; } break; case 1: fsbFrequency = (400 * 1000000) / 3; // 133 break; case 2: fsbFrequency = (600 * 1000000) / 3; // 200 break; case 3: fsbFrequency = (500 * 1000000) / 3; // 166 fsbFrequency++; break; case 4: fsbFrequency = (1000 * 1000000) / 3; // 333 break; default: break; } } else { fsbFrequency = 100 * 1000000; } if (cpuid_info()->cpuid_family == 0x06) { msr = rdmsr64(0x000000CD); switch (msr & 0x7) { case 0: fsbFrequency = (800 * 1000000) / 3; // 266 fsbFrequency++; break; case 1: fsbFrequency = (400 * 1000000) / 3; // 133 break; case 2: fsbFrequency = (600 * 1000000) / 3; // 200 break; case 3: fsbFrequency = (500 * 1000000) / 3; // 166 fsbFrequency++; break; case 4: fsbFrequency = (1000 * 1000000) / 3;// 333 break; case 5: fsbFrequency = (300 * 1000000) / 3; // 100 break; case 6: fsbFrequency = (1200 * 1000000) / 3;// 400 break; case 7: // should check fsbFrequency = (1400 * 1000000) / 3;// 466 fsbFrequency++; break; default: break; } } } }