bool BatteryTracker::start(IOService* provider) { DEBUG_LOG("BatteryTracker::start: entering start\n"); if (!IOService::start(provider)) { IOLog("BatteryTracker: IOService::start failed!\n"); return false; } IOWorkLoop* workLoop = getWorkLoop(); if (!workLoop) { IOLog("BatteryTracker: getWorkLoop failed\n"); return false; } m_pCmdGate = IOCommandGate::commandGate(this); if (!m_pCmdGate) { IOLog("BatteryTracker: IOCommandGate::commmandGate failed\n"); return false; } workLoop->addEventSource(m_pCmdGate); DEBUG_LOG("ACPIBatteryManager: Version 1.52 starting BatteryTracker.\n"); m_pBatteryList = OSArray::withCapacity(2); m_pLock = IORecursiveLockAlloc(); registerService(); return true; }
// IOFireWireIRMAllocation::init // // bool IOFireWireIRMAllocation::init( IOFireWireController * control, Boolean releaseIRMResourcesOnFree, AllocationLostNotificationProc allocationLostProc, void *pLostProcRefCon) { if (!OSObject::init()) return false ; // Allocate a lock fLock = IORecursiveLockAlloc () ; if ( ! fLock ) return false ; // Initialize some class members fControl = control; fAllocationGeneration = 0xFFFFFFFF; fAllocationLostProc = allocationLostProc; fLostProcRefCon = pLostProcRefCon; fReleaseIRMResourcesOnFree = releaseIRMResourcesOnFree; fBandwidthUnits = 0; fIsochChannel = 64; fControl->addToIRMAllocationSet(this); isAllocated = false; return true; }
bool IOFireWireUserClientIniter::init(OSDictionary * propTable) { fProvider = NULL ; if( sIniterLock == NULL ) { IORecursiveLock * lock = IORecursiveLockAlloc(); //IOLog( "IOFireWireUserClientIniter<0x%08lx>::init - IORecursiveLockAlloc = 0x%08lx\n", this, lock ); bool result = false; while( sIniterLock == NULL && result == false ) { result = OSCompareAndSwapPtr( NULL, lock, (void * volatile *)&sIniterLock ); } if( result == false ) { //IOLog( "IOFireWireUserClientIniter<0x%08lx>::init - IORecursiveLockFree = 0x%08lx\n", this, lock ); IORecursiveLockFree( lock ); } } //IOLog( "IOFireWireUserClientIniter<0x%08lx>::init - sIniterLock = 0x%08lx\n", this, sIniterLock ); return super::init(propTable) ; }
KX_API(void,kx_spin_lock_init(kx_hw *hw,spinlock_t *lock,const char *name)) { lock->lock=IORecursiveLockAlloc(); lock->name=name; lock->file=NULL; lock->line=-1; lock->kx_lock=0; }
/** * For internal use, do not override * */ bool FakeSMCPlugin::init(OSDictionary *properties) { if (!gFakeSMCPluginLock) gFakeSMCPluginLock = IORecursiveLockAlloc(); if (!super::init(properties)) return false; sensors = OSDictionary::withCapacity(0); if (!sensors) return false; return true; }
bool IOWorkLoop::init() { // The super init and gateLock allocation MUST be done first if ( !super::init() ) return false; if ( gateLock == NULL ) { if ( !( gateLock = IORecursiveLockAlloc()) ) return false; } if ( workToDoLock == NULL ) { if ( !(workToDoLock = IOSimpleLockAlloc()) ) return false; IOSimpleLockInit(workToDoLock); workToDo = false; } if ( controlG == NULL ) { controlG = IOCommandGate::commandGate( this, OSMemberFunctionCast( IOCommandGate::Action, this, &IOWorkLoop::_maintRequest)); if ( !controlG ) return false; // Point the controlGate at the workLoop. Usually addEventSource // does this automatically. The problem is in this case addEventSource // uses the control gate and it has to be bootstrapped. controlG->setWorkLoop(this); if (addEventSource(controlG) != kIOReturnSuccess) return false; } if ( workThread == NULL ) { thread_continue_t cptr = OSMemberFunctionCast( thread_continue_t, this, &IOWorkLoop::threadMain); if (KERN_SUCCESS != kernel_thread_start(cptr, this, &workThread)) return false; } return true; }
bool FakeSMCKeyStore::init(OSDictionary *properties) { if (!super::init(properties)) return false; keysLock = IORecursiveLockAlloc(); if (!keysLock) return false; keys = OSArray::withCapacity(64); types = OSDictionary::withCapacity(16); keyCounterKey = FakeSMCKey::withValue(KEY_COUNTER, TYPE_UI32, TYPE_UI32_SIZE, "\0\0\0\1"); keys->setObject(keyCounterKey); fanCounterKey = FakeSMCKey::withValue(KEY_FAN_NUMBER, TYPE_UI8, TYPE_UI8_SIZE, "\0"); keys->setObject(fanCounterKey); return true; }
bool IOFWUserLocalIsochPort::initWithUserDCLProgram ( AllocateParams * params, IOFireWireUserClient & userclient, IOFireWireController & controller ) { // sanity checking if ( params->programExportBytes == 0 ) { ErrorLog ( "No program!" ) ; return false ; } fLock = IORecursiveLockAlloc () ; if ( ! fLock ) { ErrorLog ( "Couldn't allocate recursive lock\n" ) ; return false ; } // init easy params fUserObj = params->userObj ; fUserClient = & userclient ; fDCLPool = NULL ; fProgramCount = 0; fStarted = false ; IOReturn error = kIOReturnSuccess ; // get user program ranges: IOAddressRange * bufferRanges = new IOAddressRange[ params->bufferRangeCount ] ; if ( !bufferRanges ) { error = kIOReturnNoMemory ; } if ( !error ) { error = fUserClient->copyUserData(params->bufferRanges,(mach_vm_address_t)bufferRanges, sizeof ( IOAddressRange ) * params->bufferRangeCount ) ; } // create descriptor for program buffers IOMemoryDescriptor * bufferDesc = NULL ; if ( ! error ) { IOByteCount length = 0 ; for ( unsigned index = 0; index < params->bufferRangeCount; ++index ) { length += bufferRanges[ index ].length ; } bufferDesc = IOMemoryDescriptor::withAddressRanges ( bufferRanges, params->bufferRangeCount, kIODirectionOutIn, fUserClient->getOwningTask() ) ; if ( ! bufferDesc ) { error = kIOReturnNoMemory ; } else { // IOLog( "IOFWUserLocalIsochPort::initWithUserDCLProgram - checkMemoryInRange status 0x%08lx\n", checkMemoryInRange( bufferDesc, 0x000000001FFFFFFF ) ); error = bufferDesc->prepare( kIODirectionPrepareToPhys32 ) ; FWTrace( kFWTIsoch, kTPIsochPortUserInitWithUserDCLProgram, (uintptr_t)(fUserClient->getOwner()->getController()->getLink()), error, length, 0 ); // IOLog( "IOFWUserLocalIsochPort::initWithUserDCLProgram - prep 32 checkMemoryInRange status 0x%08lx\n", checkMemoryInRange( bufferDesc, 0x000000001FFFFFFF ) ); } } // create map for buffers; we will need to get a virtual address for them IOMemoryMap * bufferMap = NULL ; if ( !error ) { bufferMap = bufferDesc->map() ; if ( !bufferMap ) { DebugLog( "Couldn't map program buffers\n" ) ; error = kIOReturnVMError ; } bufferDesc->release() ; } IOMemoryDescriptor * userProgramExportDesc = NULL ; if ( !error ) { userProgramExportDesc = IOMemoryDescriptor::withAddressRange( params->programData, params->programExportBytes, kIODirectionOut, fUserClient->getOwningTask() ) ; } // get map of program export data if ( userProgramExportDesc ) { error = userProgramExportDesc->prepare() ; } if ( !error ) { DCLCommand * opcodes = NULL ; switch ( params->version ) { case kDCLExportDataLegacyVersion : error = importUserProgram( userProgramExportDesc, params->bufferRangeCount, bufferRanges, bufferMap ) ; ErrorLogCond( error, "importUserProgram returned %x\n", error ) ; if ( ! error ) { opcodes = (DCLCommand*)fProgramBuffer ; } break ; case kDCLExportDataNuDCLRosettaVersion : fDCLPool = fUserClient->getOwner()->getBus()->createDCLPool() ; if ( ! fDCLPool ) { error = kIOReturnNoMemory ; } if ( !error ) { error = fDCLPool->importUserProgram( userProgramExportDesc, params->bufferRangeCount, bufferRanges, bufferMap ) ; } fProgramBuffer = new UInt8[ sizeof( DCLNuDCLLeader ) ] ; { DCLNuDCLLeader * leader = (DCLNuDCLLeader*)fProgramBuffer ; { leader->pNextDCLCommand = NULL ; // unused - always NULL leader->opcode = kDCLNuDCLLeaderOp ; leader->program = fDCLPool ; } opcodes = (DCLCommand*)leader ; } break ; default : ErrorLog ( "unsupported DCL program type\n" ) ; error = kIOReturnBadArgument ; break ; } ErrorLogCond( !opcodes, "Couldn't get opcodes\n" ) ; IODCLProgram * program = NULL ; if ( opcodes ) { // IOFWLocalIsochPort::printDCLProgram( opcodes ) ; IOFireWireBus::DCLTaskInfoAux infoAux ; { infoAux.version = 2 ; infoAux.u.v2.bufferMemoryMap = bufferMap ; infoAux.u.v2.workloop = params->options & kFWIsochPortUseSeparateKernelThread ? createRealtimeThread() : NULL ; infoAux.u.v2.options = (IOFWIsochPortOptions)params->options ; } IOFireWireBus::DCLTaskInfo info = { 0, 0, 0, 0, 0, 0, & infoAux } ; program = fUserClient->getOwner()->getController()->getLink()->createDCLProgram( params->talking, opcodes, & info, params->startEvent, params->startState, params->startMask ) ; bufferMap->release() ; // retained by DCL program bufferMap = NULL ; if ( infoAux.u.v2.workloop ) { // If we created a custom workloop, it will be retained by the program... // We can release our reference... infoAux.u.v2.workloop->release() ; } DebugLogCond( !program, "createDCLProgram returned nil\n" ) ; } if ( program ) { if ( ! super::init( program, & controller ) ) { ErrorLog ( "IOFWUserIsochPort::init failed\n" ) ; error = kIOReturnError ; } } else { DebugLog ( "Couldn't create DCL program\n" ) ; error = kIOReturnNoMemory ; } userProgramExportDesc->complete() ; userProgramExportDesc->release() ; userProgramExportDesc = NULL ; } delete [] bufferRanges ; InfoLog( "-IOFWUserLocalIsochPort::initWithUserDCLProgram error=%x (build date "__TIME__" "__DATE__")\n", error ) ; return ( ! error ) ; }
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; }
bool FakeSMCDevice::initAndStart(IOService *platform, IOService *provider) { if (!provider || !super::init(platform, 0, 0)) return false; OSDictionary *properties = OSDynamicCast(OSDictionary, provider->getProperty("Configuration")); if (!properties) return false; status = (ApleSMCStatus *) IOMalloc(sizeof(struct AppleSMCStatus)); bzero((void*)status, sizeof(struct AppleSMCStatus)); interrupt_handler = 0; keys = OSArray::withCapacity(1); types = OSDictionary::withCapacity(0); exposedValues = OSDictionary::withCapacity(0); // Add fist key - counter key keyCounterKey = FakeSMCKey::withValue(KEY_COUNTER, TYPE_UI32, TYPE_UI32_SIZE, "\0\0\0\1"); keys->setObject(keyCounterKey); fanCounterKey = FakeSMCKey::withValue(KEY_FAN_NUMBER, TYPE_UI8, TYPE_UI8_SIZE, "\0"); keys->setObject(fanCounterKey); if (!gKeysLock) gKeysLock = IORecursiveLockAlloc(); // Load preconfigured keys FakeSMCDebugLog("loading keys..."); if (OSDictionary *dictionary = OSDynamicCast(OSDictionary, properties->getObject("Keys"))) { if (OSIterator *iterator = OSCollectionIterator::withCollection(dictionary)) { while (const OSSymbol *key = (const OSSymbol *)iterator->getNextObject()) { if (OSArray *array = OSDynamicCast(OSArray, dictionary->getObject(key))) { if (OSIterator *aiterator = OSCollectionIterator::withCollection(array)) { OSString *type = OSDynamicCast(OSString, aiterator->getNextObject()); OSData *value = OSDynamicCast(OSData, aiterator->getNextObject()); if (type && value) addKeyWithValue(key->getCStringNoCopy(), type->getCStringNoCopy(), value->getLength(), value->getBytesNoCopy()); OSSafeRelease(aiterator); } } key = 0; } OSSafeRelease(iterator); } HWSensorsInfoLog("%d preconfigured key%s added", keys->getCount(), keys->getCount() == 1 ? "" : "s"); } else { HWSensorsWarningLog("no preconfigured keys found"); } // Load wellknown type names FakeSMCDebugLog("loading types..."); if (OSDictionary *dictionary = OSDynamicCast(OSDictionary, properties->getObject("Types"))) { if (OSIterator *iterator = OSCollectionIterator::withCollection(dictionary)) { while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) { if (OSString *value = OSDynamicCast(OSString, dictionary->getObject(key))) { types->setObject(key, value); } } OSSafeRelease(iterator); } } // Set Clover platform keys if (OSDictionary *dictionary = OSDynamicCast(OSDictionary, properties->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 (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"); } // Start SMC device if (!super::start(platform)) return false; this->setName("SMC"); FakeSMCSetProperty("name", "APP0001"); if (OSString *compatibleKey = OSDynamicCast(OSString, properties->getObject("smc-compatible"))) FakeSMCSetProperty("compatible", (const char *)compatibleKey->getCStringNoCopy()); else FakeSMCSetProperty("compatible", "smc-napa"); if (!this->setProperty("_STA", (unsigned long long)0x0000000b, 32)) { HWSensorsErrorLog("failed to set '_STA' property"); return false; } if (OSBoolean *debugKey = OSDynamicCast(OSBoolean, properties->getObject("debug"))) debug = debugKey->getValue(); else debug = false; if (OSBoolean *traceKey = OSDynamicCast(OSBoolean, properties->getObject("trace"))) trace = traceKey->getValue(); else trace = false; IODeviceMemory::InitElement rangeList[1]; rangeList[0].start = 0x300; rangeList[0].length = 0x20; // rangeList[1].start = 0xfef00000; // rangeList[1].length = 0x10000; if(OSArray *array = IODeviceMemory::arrayFromList(rangeList, 1)) { this->setDeviceMemory(array); OSSafeRelease(array); } else { HWSensorsFatalLog("failed to create Device memory array"); return false; } OSArray *controllers = OSArray::withCapacity(1); if(!controllers) { HWSensorsFatalLog("failed to create controllers array"); return false; } controllers->setObject((OSSymbol *)OSSymbol::withCStringNoCopy("io-apic-0")); OSArray *specifiers = OSArray::withCapacity(1); if(!specifiers) { HWSensorsFatalLog("failed to create specifiers array"); return false; } UInt64 line = 0x06; OSData *tmpData = OSData::withBytes(&line, sizeof(line)); if (!tmpData) { HWSensorsFatalLog("failed to create specifiers data"); return false; } specifiers->setObject(tmpData); this->setProperty(gIOInterruptControllersKey, controllers) && this->setProperty(gIOInterruptSpecifiersKey, specifiers); this->attachToParent(platform, gIOServicePlane); registerService(); HWSensorsInfoLog("successfully initialized"); return true; }
bool IOWorkLoop::init() { // The super init and gateLock allocation MUST be done first. if ( !super::init() ) return false; // Allocate our ExpansionData if it hasn't been allocated already. if ( !reserved ) { reserved = IONew(ExpansionData,1); if ( !reserved ) return false; bzero(reserved,sizeof(ExpansionData)); } #if DEBUG OSBacktrace ( reserved->allocationBacktrace, sizeof ( reserved->allocationBacktrace ) / sizeof ( reserved->allocationBacktrace[0] ) ); #endif if ( gateLock == NULL ) { if ( !( gateLock = IORecursiveLockAlloc()) ) return false; } if ( workToDoLock == NULL ) { if ( !(workToDoLock = IOSimpleLockAlloc()) ) return false; IOSimpleLockInit(workToDoLock); workToDo = false; } if (!reserved) { reserved = IONew(ExpansionData, 1); reserved->options = 0; } IOStatisticsRegisterCounter(); if ( controlG == NULL ) { controlG = IOCommandGate::commandGate( this, OSMemberFunctionCast( IOCommandGate::Action, this, &IOWorkLoop::_maintRequest)); if ( !controlG ) return false; // Point the controlGate at the workLoop. Usually addEventSource // does this automatically. The problem is in this case addEventSource // uses the control gate and it has to be bootstrapped. controlG->setWorkLoop(this); if (addEventSource(controlG) != kIOReturnSuccess) return false; } if ( workThread == NULL ) { thread_continue_t cptr = OSMemberFunctionCast( thread_continue_t, this, &IOWorkLoop::threadMain); if (KERN_SUCCESS != kernel_thread_start(cptr, this, &workThread)) return false; } (void) thread_set_tag(workThread, THREAD_TAG_IOWORKLOOP); return true; }
AppleRAIDGlobals::AppleRAIDGlobals() { IOLog1("AppleRAIDGlobals() initing\n"); raidGlobalLock = IORecursiveLockAlloc(); raidControllerReferences = 0; }