bool SuperIODevice::start(IOService *provider) { if (!super::start(provider)) return false; // Gigabyte mobos usualy use ITE if (OSDictionary *matching = serviceMatching(kFakeSMCService)) { if (IOService *headingProvider = waitForMatchingService(matching, kFakeSMCDefaultWaitTimeout)) { if (OSString *manufacturer = OSDynamicCast(OSString, headingProvider->getProperty(kOEMInfoManufacturer))) { if (manufacturer->isEqualTo("Gigabyte")) { if (!detectITEFamilyChip()) { UInt16 ite_id = id; if (!detectWinbondFamilyChip()) { HWSensorsFatalLog("found unsupported chip! ITE sequence ID=0x%x, Winbond sequence ID=0x%x", ite_id, id); return false; } } } } } OSSafeRelease(matching); } // Other vendors usualy use Winbond family chipsets if (model == 0) { if (!detectWinbondFamilyChip()) { UInt16 wnbnd_id = id; if (!detectITEFamilyChip()) { HWSensorsFatalLog("found unsupported chip! ITE sequence ID=0x%x, Winbond sequence ID=0x%x", id, wnbnd_id); return false; } } } HWSensorsInfoLog("found %s %s on port=0x%x address=0x%x", vendor, superio_get_model_name(model), port, address); char string[128]; snprintf(string, sizeof(string), "%s,%s", vendor, superio_get_model_name(model)); setName(string); //setProperty("name", &string, (UInt32)strlen(string) + 1); setProperty(kSuperIOHWMAddress, address, 16); setProperty(kSuperIOControlPort, port, 8); setProperty(kSuperIOModelValue, model, 16); setProperty(kSuperIOModelName, superio_get_model_name(model)); setProperty(kSuperIOVendorName, vendor); setProperty(kSuperIODeviceID, OSData::withBytes(&id, sizeof(id))); registerService(); return true; }
UInt32 FakeSMCDevice::loadKeysFromNVRAM() { UInt32 count = 0; // Find driver and load keys from NVRAM if (OSDictionary *matching = serviceMatching("IODTNVRAM")) { if (IODTNVRAM *nvram = OSDynamicCast(IODTNVRAM, waitForMatchingService(matching, 1000000000ULL * 15))) { useNVRAM = true; if ((genericNVRAM = (0 == strncmp(nvram->getName(), "AppleNVRAM", sizeof("AppleNVRAM"))))) HWSensorsInfoLog("fallback to generic NVRAM methods"); OSSerialize *s = OSSerialize::withCapacity(0); // Workaround for IODTNVRAM->getPropertyTable returns IOKitPersonalities instead of NVRAM properties dictionary if (nvram->serializeProperties(s)) { if (OSDictionary *props = OSDynamicCast(OSDictionary, OSUnserializeXML(s->text()))) { if (OSCollectionIterator *iterator = OSCollectionIterator::withCollection(props)) { size_t prefix_length = strlen(kFakeSMCKeyPropertyPrefix); char name[5]; name[4] = 0; char type[5]; type[4] = 0; while (OSString *property = OSDynamicCast(OSString, iterator->getNextObject())) { const char *buffer = static_cast<const char *>(property->getCStringNoCopy()); if (property->getLength() >= prefix_length + 1 + 4 + 1 + 0 && 0 == strncmp(buffer, kFakeSMCKeyPropertyPrefix, prefix_length)) { if (OSData *data = OSDynamicCast(OSData, props->getObject(property))) { strncpy(name, buffer + prefix_length + 1, 4); // fakesmc-key-???? -> strncpy(type, buffer + prefix_length + 1 + 4 + 1, 4); // fakesmc-key-xxxx-???? -> if (addKeyWithValue(name, type, data->getLength(), data->getBytesNoCopy())) { HWSensorsDebugLog("key %s of type %s loaded from NVRAM", name, type); count++; } } } } OSSafeRelease(iterator); } OSSafeRelease(props); } } OSSafeRelease(s); OSSafeRelease(nvram); } else { HWSensorsWarningLog("NVRAM is unavailable"); } OSSafeRelease(matching); } return count; }
BrcmFirmwareStore* BrcmPatchRAM::getFirmwareStore() { if (!mFirmwareStore) mFirmwareStore = OSDynamicCast(BrcmFirmwareStore, waitForMatchingService(serviceMatching(kBrcmFirmwareStoreService), 2000UL*1000UL*1000UL)); if (!mFirmwareStore) AlwaysLog("[%04x:%04x]: BrcmFirmwareStore does not appear to be available.\n", mVendorId, mProductId); return mFirmwareStore; }
BrcmFirmwareStore* BrcmPatchRAM::getFirmwareStore() { if (!mFirmwareStore) { // check to see if it already loaded mFirmwareStore = OSDynamicCast(BrcmFirmwareStore, waitForMatchingService(serviceMatching(kBrcmFirmwareStoreService), 0)); if (!mFirmwareStore) { // not loaded, so publish personality... publishResourcePersonality(kBrcmFirmwareStoreService); // and wait... mFirmwareStore = OSDynamicCast(BrcmFirmwareStore, waitForMatchingService(serviceMatching(kBrcmFirmwareStoreService), 2000UL*1000UL*1000UL)); } #ifdef NON_RESIDENT // also need BrcmPatchRAMResidency IOService* residency = OSDynamicCast(BrcmPatchRAMResidency, waitForMatchingService(serviceMatching(kBrcmPatchRAMResidency), 0)); if (!residency) { // not loaded, so publish personality... publishResourcePersonality(kBrcmPatchRAMResidency); // and wait... residency = OSDynamicCast(BrcmPatchRAMResidency, waitForMatchingService(serviceMatching(kBrcmPatchRAMResidency), 2000UL*1000UL*1000UL)); if (residency) residency->release(); else AlwaysLog("[%04x:%04x]: BrcmPatchRAMResidency does not appear to be available.\n", mVendorId, mProductId); } #endif } if (!mFirmwareStore) AlwaysLog("[%04x:%04x]: BrcmFirmwareStore does not appear to be available.\n", mVendorId, mProductId); return mFirmwareStore; }
/** * For internal use, do not override * */ bool FakeSMCPlugin::start(IOService *provider) { if (!super::start(provider)) return false; if (OSDictionary *matching = serviceMatching(kFakeSMCKeyStoreService)) { if (!(keyStore = OSDynamicCast(FakeSMCKeyStore, waitForMatchingService(matching, kFakeSMCDefaultWaitTimeout)))) { HWSensorsFatalLog("still waiting for FakeSMCKeyStore..."); return false; } OSSafeRelease(matching); } return true; }
/** * Wait for VBoxGuest.kext to be started */ IOService * org_virtualbox_VBoxVFS::waitForCoreService(void) { IOService *service; OSDictionary *serviceToMatch = serviceMatching("org_virtualbox_VBoxGuest"); if (!serviceToMatch) { PINFO("unable to create matching dictionary"); return false; } /* Wait 10 seconds for VBoxGuest to be started */ service = waitForMatchingService(serviceToMatch, 10ULL * 1000000000ULL); serviceToMatch->release(); return service; }
UInt32 ACPIBacklightPanel::loadFromNVRAM(void) { DbgLog("%s::%s()\n", this->getName(),__FUNCTION__); IORegistryEntry* nvram = IORegistryEntry::fromPath("/chosen/nvram", gIODTPlane); if (!nvram) { DbgLog("%s: no /chosen/nvram, trying IODTNVRAM\n", this->getName()); // probably booting w/ Clover if (OSDictionary* matching = serviceMatching("IODTNVRAM")) { nvram = waitForMatchingService(matching, 1000000000ULL * 15); matching->release(); } } else DbgLog("%s: have nvram from /chosen/nvram\n", this->getName()); UInt32 val = -1; if (nvram) { // need to serialize as getProperty on nvram does not work if (OSSerialize* serial = OSSerialize::withCapacity(0)) { nvram->serializeProperties(serial); if (OSDictionary* props = OSDynamicCast(OSDictionary, OSUnserializeXML(serial->text()))) { if (OSData* number = OSDynamicCast(OSData, props->getObject(kACPIBacklightLevel))) { val = 0; unsigned l = number->getLength(); if (l <= sizeof(val)) memcpy(&val, number->getBytesNoCopy(), l); DbgLog("%s: read level from nvram = %d\n", this->getName(), val); //number->release(); } else DbgLog("%s: no acpi-backlight-level in nvram\n", this->getName()); props->release(); } serial->release(); } nvram->release(); } return val; }
bool ACPIACAdapter::start(IOService* provider) { if (!IOService::start(provider)) { IOLog("ACPIACAdapter: IOService::start failed!\n"); return false; } fProvider = OSDynamicCast(IOACPIPlatformDevice, provider); if (!fProvider) { IOLog("ACPIACAdapter: provider not IOACPIPlatformDevice\n"); return false; } fProvider->retain(); DEBUG_LOG("ACPIBatteryManager::start Version 1.52 starting ACPIACAdapter.\n"); // get tracker for notifications fTracker = OSDynamicCast(BatteryTracker, waitForMatchingService(serviceMatching(kBatteryTrackerService))); return true; }
bool IntelBacklightHandler::start(IOService *provider) { if (!super::start(provider)) return false; IOPCIDevice* pci = OSDynamicCast(IOPCIDevice, provider); if (!pci) { IOLog("IntelBacklightHandler is not an IOPCIDevice... aborting\n"); return false; } // setup for direct access IOService* service = waitForMatchingService(serviceMatching("ACPIBacklightPanel"), 2000UL*1000UL*1000UL); if (!service) { IOLog("ACPIBacklightPanel not found... aborting\n"); return false; } ACPIBacklightPanel* panel = OSDynamicCast(ACPIBacklightPanel, service); if (!panel) { IOLog("Backlight service was not ACPIBacklightPanel\n"); return false; } // setup BAR1 address... _baseMap = pci->mapDeviceMemoryWithRegister(kIOPCIConfigBaseAddress0); if (!_baseMap) { IOLog("unable to map BAR1... aborting\n"); return false; } _baseAddr = reinterpret_cast<volatile void *>(_baseMap->getVirtualAddress()); if (!_baseAddr) { IOLog("unable to get virtual address for BAR1... aborting\n"); return false; } OSNumber* num = OSDynamicCast(OSNumber, getProperty("kFrameBufferType")); if (num == NULL) { IOLog("unable to get framebuffer type\n"); return false; } _fbtype = num->unsigned32BitValue(); // now register with ACPIBacklight if (!panel->setBacklightHandler(this, &_params)) { // setBacklightHandler will return false for old PNLF patches _baseMap->release(); return false; } _panel = panel; panel->retain(); // register service so ACPIBacklightPanel can proceed... registerService(); return true; }
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; }