bool IOBSDConsole::start(IOService * provider) { OSObject * notify; if (!super::start(provider)) return false; notify = addNotification( gIOPublishNotification, serviceMatching("IOHIKeyboard"), (IOServiceNotificationHandler) &IOBSDConsole::publishNotificationHandler, this, 0 ); assert( notify ); notify = addNotification( gIOPublishNotification, serviceMatching("IODisplayWrangler"), (IOServiceNotificationHandler) &IOBSDConsole::publishNotificationHandler, this, 0 ); assert( notify ); notify = addNotification( gIOPublishNotification, serviceMatching("IOAudioStream"), (IOServiceNotificationHandler) &IOBSDConsole::publishNotificationHandler, this, this ); assert( notify ); return( true ); }
bool org_pqrs_driver_Seil::start(IOService* provider) { IOLOG_INFO("start\n"); bool res = super::start(provider); if (!res) { return res; } org_pqrs_Seil::GlobalLock::initialize(); notifier_hookKeyboard_ = addMatchingNotification(gIOMatchedNotification, serviceMatching("IOHIKeyboard"), org_pqrs_driver_Seil::IOHIKeyboard_gIOMatchedNotification_callback, this, nullptr, 0); if (notifier_hookKeyboard_ == nullptr) { IOLOG_ERROR("initialize_notification notifier_hookKeyboard_ == nullptr\n"); return false; } notifier_unhookKeyboard_ = addMatchingNotification(gIOTerminatedNotification, serviceMatching("IOHIKeyboard"), org_pqrs_driver_Seil::IOHIKeyboard_gIOTerminatedNotification_callback, this, nullptr, 0); if (notifier_unhookKeyboard_ == nullptr) { IOLOG_ERROR("initialize_notification notifier_unhookKeyboard_ == nullptr\n"); return false; } // Publish ourselves so clients can find us registerService(); return res; }
bool org_pqrs_driver_NoEjectDelay::start(IOService* provider) { IOLOG_INFO("start\n"); bool res = super::start(provider); if (!res) { return res; } // ---------------------------------------- org_pqrs_NoEjectDelay::GlobalLock::initialize(); // ---------------------------------------- notifier_hookKeyboard_ = addMatchingNotification(gIOMatchedNotification, serviceMatching("IOHIKeyboard"), org_pqrs_driver_NoEjectDelay::IOHIKeyboard_gIOMatchedNotification_callback, this, NULL, 0); if (notifier_hookKeyboard_ == NULL) { IOLOG_ERROR("initialize_notification notifier_hookKeyboard_ == NULL\n"); return false; } notifier_unhookKeyboard_ = addMatchingNotification(gIOTerminatedNotification, serviceMatching("IOHIKeyboard"), org_pqrs_driver_NoEjectDelay::IOHIKeyboard_gIOTerminatedNotification_callback, this, NULL, 0); if (notifier_unhookKeyboard_ == NULL) { IOLOG_ERROR("initialize_notification notifier_unhookKeyboard_ == NULL\n"); return false; } notifier_hookEventService_ = addMatchingNotification(gIOMatchedNotification, serviceMatching("IOHIDEventService"), org_pqrs_driver_NoEjectDelay::IOHIKeyboard_gIOMatchedNotification_callback, this, NULL, 0); if (notifier_hookEventService_ == NULL) { IOLOG_ERROR("initialize_notification notifier_hookEventService_ == NULL\n"); return false; } notifier_unhookEventService_ = addMatchingNotification(gIOTerminatedNotification, serviceMatching("IOHIDEventService"), org_pqrs_driver_NoEjectDelay::IOHIKeyboard_gIOTerminatedNotification_callback, this, NULL, 0); if (notifier_unhookEventService_ == NULL) { IOLOG_ERROR("initialize_notification notifier_unhookEventService_ == NULL\n"); return false; } // ---------------------------------------- workLoop_ = IOWorkLoop::workLoop(); if (!workLoop_) return false; timerEventSource_ = IOTimerEventSource::timerEventSource(this, timer_callback); if (!timerEventSource_) return false; if (workLoop_->addEventSource(timerEventSource_) != kIOReturnSuccess) return false; timerEventSource_->setTimeoutMS(TIMER_INTERVAL_MS); // ---------------------------------------- return res; }
bool FakeSMCPlugin::start(IOService *provider) { if (!super::start(provider)) return false; if (!(headingProvider = waitForService(serviceMatching(kFakeSMCService)))) HWSensorsWarningLog("failed to locate FakeSMC service, specific OEM configurations will be unavailable"); if (!(storageProvider = waitForService(serviceMatching(kFakeSMCDeviceService)))) { HWSensorsFatalLog("failed to locate FakeSMCDevice"); return false; } return true; }
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; }
void IOPlatformExpert::setCPUInterruptProperties(IOService *service) { IOCPUInterruptController *controller; controller = OSDynamicCast(IOCPUInterruptController, waitForService(serviceMatching("IOCPUInterruptController"))); if (controller) controller->setCPUInterruptProperties(service); }
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; }
void com_prebeg_kext_KeyLog::activate() { IOLog("%s::%s\n", getName(), __FUNCTION__); notifyTerm = addMatchingNotification(gIOTerminatedNotification, serviceMatching("IOHIKeyboard"), (IOServiceMatchingNotificationHandler)&com_prebeg_kext_KeyLog::terminationHandler, this); return; }
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; }
// ====================================================================== bool org_pqrs_driver_Karabiner::initialize_notification(void) { notifier_hookKeyboard_ = addMatchingNotification(gIOMatchedNotification, serviceMatching("IOHIKeyboard"), org_pqrs_Karabiner::Core::IOHIKeyboard_gIOMatchedNotification_callback, this, NULL, 0); if (notifier_hookKeyboard_ == NULL) { IOLOG_ERROR("initialize_notification notifier_hookKeyboard_ == NULL\n"); return false; } notifier_unhookKeyboard_ = addMatchingNotification(gIOTerminatedNotification, serviceMatching("IOHIKeyboard"), org_pqrs_Karabiner::Core::IOHIKeyboard_gIOTerminatedNotification_callback, this, NULL, 0); if (notifier_unhookKeyboard_ == NULL) { IOLOG_ERROR("initialize_notification notifier_unhookKeyboard_ == NULL\n"); return false; } // ---------------------------------------- notifier_hookPointing_ = addMatchingNotification(gIOMatchedNotification, serviceMatching("IOHIPointing"), org_pqrs_Karabiner::Core::IOHIPointing_gIOMatchedNotification_callback, this, NULL, 0); if (notifier_hookPointing_ == NULL) { IOLOG_ERROR("initialize_notification notifier_hookPointing_ == NULL\n"); return false; } notifier_unhookPointing_ = addMatchingNotification(gIOTerminatedNotification, serviceMatching("IOHIPointing"), org_pqrs_Karabiner::Core::IOHIPointing_gIOTerminatedNotification_callback, this, NULL, 0); if (notifier_unhookPointing_ == NULL) { IOLOG_ERROR("initialize_notification notifier_unhookPointing_ == NULL\n"); return false; } return true; }
bool FakeSMCPlugin::start(IOService *provider) { if (!super::start(provider)) return false; if (!(fakeSMC = waitForService(serviceMatching(kFakeSMCDeviceService)))) { HWSensorsWarningLog("can't locate FakeSMCDevice"); return false; } return true; }
bool SuperIOMonitor::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; } return true; }
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; }
bool FakeSMCPlugin::start(IOService *provider) { DebugLog("Starting..."); if (!super::start(provider)) return false; if (!(fakeSMC = waitForService(serviceMatching(kFakeSMCDeviceService)))) { WarningLog("Can't locate fake SMC device!"); return false; } return true; }
//==================================================================================================== // IOHIDEventService::start //==================================================================================================== bool IOHIDEventSystem::start(IOService * provider) { if ( super::start(provider) == false ) return false; _workLoop = IOHIDWorkLoop::workLoop(); _commandGate = IOCommandGate::commandGate(this); if ( !_workLoop || !_commandGate ) return false; if ( _workLoop->addEventSource(_commandGate) != kIOReturnSuccess ) return false; _publishNotify = addNotification( gIOPublishNotification, serviceMatching("IOHIDEventService"), OSMemberFunctionCast(IOServiceNotificationHandler, this, &IOHIDEventSystem::notificationHandler), this, (void *)OSMemberFunctionCast(IOCommandGate::Action, this, &IOHIDEventSystem::handleServicePublicationGated) ); _terminateNotify = addNotification( gIOTerminatedNotification, serviceMatching("IOHIDEventService"), OSMemberFunctionCast(IOServiceNotificationHandler, this, &IOHIDEventSystem::notificationHandler), this, (void *)OSMemberFunctionCast(IOCommandGate::Action, this, &IOHIDEventSystem::handleServiceTerminationGated) ); if (!_publishNotify || !_terminateNotify) return false; _eventsOpen = true; registerService(); return true; }
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; }
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; }
/** * 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; }
void Insomnia::startPM(IOService *provider) { static const int kMyNumberOfStates = 2; static IOPMPowerState myPowerStates[kMyNumberOfStates] = { {kIOPMPowerStateVersion1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {kIOPMPowerStateVersion1, kIOPMPowerOn, kIOPMPowerOn, kIOPMPowerOn, 0, 0, 0, 0, 0, 0, 0, 0} }; PMinit(); provider->joinPMtree(this); registerPowerDriver(this, myPowerStates, kMyNumberOfStates); if (OSDictionary *tmpDict = serviceMatching("IOPMPowerSource")) { addMatchingNotification(gIOFirstPublishNotification, tmpDict, &Insomnia::_power_source_published, this); tmpDict->release(); } }
bool com_prebeg_kext_KeyLog::start(IOService *provider) { IOLog("%s::%s\n", getName(), __FUNCTION__); bool result = super::start(provider); registerService(); notify = addMatchingNotification(gIOPublishNotification, serviceMatching("IOHIKeyboard"), (IOServiceMatchingNotificationHandler)&com_prebeg_kext_KeyLog::notificationHandler, this); activate(); if (!result) { stop(provider); return false; } return result; }
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; }
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; }
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 IOI2CDriveBayGPIO::start(IOService *provider) { IOReturn status; OSData *data; mach_timespec_t timeout; DLOG("IOI2CDriveBayGPIO::start\n"); // Get our "reg" property.. I2C address. if (0 == (data = OSDynamicCast(OSData, provider->getProperty("reg")))) { DLOG("IOI2CDriveBayGPIO::start -- no reg property\n"); return false; } fReg = *((UInt32 *)data->getBytesNoCopy()); // Find the PCA9554M node. It provides our interrupt source... timeout.tv_sec = 30; timeout.tv_nsec = 0; if (0 == (fPCA9554M = waitForService(serviceMatching("IOI2CDriveBayMGPIO"), &timeout))) { DLOG("IOI2CDriveBayGPIO::start -- timeout waiting for IOI2CDriveBayMGPIO\n"); return false; } fConfigReg = 0xFF; // default to all input pins fPolarityReg = 0x00; // no polarity inversion // find out how to program the config register if (data = OSDynamicCast(OSData, provider->getProperty("config-reg"))) fConfigReg = (UInt8)*((UInt32 *)data->getBytesNoCopy()); // find out how to program the polarity register if (data = OSDynamicCast(OSData, provider->getProperty("polarity-reg"))) fPolarityReg = (UInt8)*((UInt32 *)data->getBytesNoCopy()); DLOG("IOI2CDriveBayGPIO(%x)::start fConfigReg = %02x fPolarityReg = %02x\n", (int)fReg, fConfigReg, fPolarityReg); // allocate my lock fClientLock = IOLockAlloc(); // Register with the combined PCA9554M DLOG("IOI2CDriveBayGPIO(%x)::start - register9554MInterruptClient\n", (int)fReg); if (kIOReturnSuccess != (status = fPCA9554M->callPlatformFunction("register9554MInterruptClient", false, (void *)fReg, (void *)&sProcess9554MInterrupt, (void *)this, (void *)true))) { DLOG("IOI2CDriveBayGPIO(%x)::start failed to register (%x)\n", (int)fReg, (int)status); return false; } // Start IOI2C services... if (false == super::start(provider)) { DLOG("IOI2CDriveBayGPIO(%x)::start -- super::start returned error\n", (int)fReg); return false; } super::callPlatformFunction("IOI2CSetDebugFlags", false, (void *)kStateFlags_kprintf, (void *)true, (void *)NULL, (void *)NULL); if (kIOReturnSuccess != readI2C(k9554OutputPort, &fOutputReg, 1)) { DLOG("IOI2CDriveBayGPIO(%x)::start -- super::start returned error\n", (int)fReg); freeI2CResources(); return false; } // start matching on children publishChildren(provider); registerService(); DLOG("IOI2CDriveBayGPIO@%lx::start succeeded\n", getI2CAddress()); return true; }
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; }
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 ACPIBacklightPanel::start( IOService * provider ) { DbgLog("%s::%s()\n", this->getName(),__FUNCTION__); #if 0 if (!provider) return false; _provider = provider; _provider->retain(); #endif _lock = IORecursiveLockAlloc(); if (!_lock) return false; findDevices(provider); getDeviceControl(); hasSaveMethod = hasSAVEMethod(backLightDevice); min = 0; max = setupIndexedLevels(); if (min == max) { IOLog("ACPIBacklight: setupIndexedLevels failed (min==max)... aborting"); return false; } // add interrupt source for delayed actions... _workSource = IOInterruptEventSource::interruptEventSource(this, OSMemberFunctionCast(IOInterruptEventAction, this, &ACPIBacklightPanel::processWorkQueue)); if (!_workSource) return false; IOWorkLoop* workLoop = getWorkLoop(); if (!workLoop) { _workSource->release(); _workSource = NULL; return false; } workLoop->addEventSource(_workSource); _workPending = 0; // add timer for smooth fade ins if (_extended && !(_options & kDisableSmooth)) { _smoothTimer = IOTimerEventSource::timerEventSource(this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &ACPIBacklightPanel::onSmoothTimer)); if (_smoothTimer) workLoop->addEventSource(_smoothTimer); } _cmdGate = IOCommandGate::commandGate(this); if (_cmdGate) workLoop->addEventSource(_cmdGate); // initialize from properties OSDictionary* dict = getPropertyTable(); setPropertiesGated(dict); // write current values from smoothData for (int i = 0; i < countof(smoothData); i++) { char buf[kSmoothBufSize]; snprintf(buf, sizeof(buf), kSmoothDelta, i); setProperty(buf, smoothData[i].delta, 32); snprintf(buf, sizeof(buf), kSmoothStep, i); setProperty(buf, smoothData[i].step, 32); snprintf(buf, sizeof(buf), kSmoothTimeout, i); setProperty(buf, smoothData[i].timeout, 32); } #ifdef DEBUG setProperty("CycleTest", 1, 32); setProperty("KLVX", 1, 32); #endif // make the service available for clients like 'ioio'... registerService(); // load and set default brightness level UInt32 value = loadFromNVRAM(); DbgLog("%s: loadFromNVRAM returns %d\n", this->getName(), value); // registerService above must be called before we wait for the BacklightHandler if (useBacklightHandler()) { DbgLog("%s: Waiting for BacklightHandler\n", this->getName()); waitForService(serviceMatching("BacklightHandler")); } // after backlight handler is in place, now we can manipulate backlight level UInt32 current = queryACPICurentBrightnessLevel(); setProperty(kRawBrightness, current, 32); #if 0 _provider->setProperty("AppleBacklightAtBoot", current, 32); _provider->setProperty("AppleMaxBrightness", BCLlevels[BCLlevelsCount-1], 32); #endif _committed_value = _value = _from_value = levelForValue(current); DbgLog("%s: current brightness: %d (%d)\n", this->getName(), _from_value, current); if (-1 != value) { _committed_value = value; DbgLog("%s: setting to value from nvram %d\n", this->getName(), value); setBrightnessLevelSmooth(value); } _saved_value = _committed_value; DbgLog("%s: min = %u, max = %u\n", this->getName(), min, max); // announce version extern kmod_info_t kmod_info; IOLog("ACPIBacklight: Version %s starting on OS X Darwin %d.%d.\n", kmod_info.version, version_major, version_minor); // place version/build info in ioreg properties RM,Build and RM,Version char buf[128]; snprintf(buf, sizeof(buf), "%s %s", kmod_info.name, kmod_info.version); setProperty("RM,Version", buf); #ifdef DEBUG setProperty("RM,Build", "Debug-" LOGNAME); #else setProperty("RM,Build", "Release-" LOGNAME); #endif return true; }