static KeyboardReserved * GetKeyboardReservedStructEventForService(IOHIKeyboard *service, UInt32 * index = 0) { KeyboardReserved * retVal = 0; if (gKeyboardReservedArray) { OSCollectionIterator * iterator = 0; iterator = OSCollectionIterator::withCollection(gKeyboardReservedArray); if (iterator) { bool done = false; while (!done) { OSObject * obj = 0; while (!done && (NULL != (obj = iterator->getNextObject()))) { OSData * data = OSDynamicCast(OSData, obj); if (data) { retVal = (KeyboardReserved *)data->getBytesNoCopy(); if (retVal && (retVal->service == service)) { if (index) *index = gKeyboardReservedArray->getNextIndexOfObject(obj, 0); done = true; } else { retVal = 0; } } } if (iterator->isValid()) { done = true; } else { iterator->reset(); } } iterator->release(); } } return retVal; }
static IOReturn _removeDrivers( OSArray * array, OSDictionary * matching ) { OSCollectionIterator * tables; OSDictionary * dict; OSArray * arrayCopy; IOReturn ret = kIOReturnSuccess; // remove configs from catalog. arrayCopy = OSArray::withCapacity(100); if ( !arrayCopy ) return kIOReturnNoMemory; tables = OSCollectionIterator::withCollection(arrayCopy); arrayCopy->release(); if ( !tables ) return kIOReturnNoMemory; arrayCopy->merge(array); array->flushCollection(); tables->reset(); while ( (dict = (OSDictionary *)tables->getNextObject()) ) { /* Remove from the catalogue's array any personalities * that match the matching dictionary. * This comparison must be done with only the keys in the * "matching" dict to enable general matching. */ if ( dict->isEqualTo(matching, matching) ) continue; array->setObject(dict); } tables->release(); return ret; }
bool driver::init(OSDictionary *properties) { OSArray *speedArray = NULL; OSCollectionIterator *speedIterator = NULL; OSString *speedKey; chkpoint("Initializing\n"); if (super::init(properties) == false) fail("super::init"); speedArray = OSDynamicCast(OSArray, getProperty(kVID)); if (speedArray == NULL) fail("no " kVID "!\n"); speedIterator = OSCollectionIterator::withCollection(speedArray); if (speedIterator == NULL) fail("no speediterator!\n"); speedIterator->reset(); while (speedKey = (OSString *)speedIterator->getNextObject()) { sscanf(speedKey->getCStringNoCopy(),"%d,%d,%x",&speedstep_cpu_setting[num_speeds].cpuMhz,&speedstep_cpu_setting[num_speeds].cpuMv,&speedstep_cpu_setting[num_speeds].VID); if (speedstep_cpu_setting[num_speeds].cpuMhz<=100 || speedstep_cpu_setting[num_speeds].cpuMv<=700 || speedstep_cpu_setting[num_speeds].VID < 0xFF) { // Some sane values - 700mv is the absolute minimum possible? bzero(&speedstep_cpu_setting[num_speeds],sizeof(speedstep_cpu_t)); err("Ignoring invalid mhz,mv specified = %s\n",speedKey->getCStringNoCopy()); } else { //speedstep_cpu_setting[num_speeds].VID=VID(speedstep_cpu_setting[num_speeds].cpuMhz,speedstep_cpu_setting[num_speeds].cpuMv); info("Identified configured speed %uMhz, %umv, VID=0x%04x\n",speedstep_cpu_setting[num_speeds].cpuMhz,speedstep_cpu_setting[num_speeds].cpuMv,speedstep_cpu_setting[num_speeds].VID); num_speeds++; } } if (!num_speeds) fail("No valid speeds given"); // No valid settings, bail! dbg("%d speed settings used\n", num_speeds); eist_lock=IOSimpleLockAlloc(); if (!eist_lock) fail("IOSimpleLockAlloc"); return(true); fail: return(false); }
bool eqMac2DriverEngine::createAudioStreams(IOAudioSampleRate *initialSampleRate) { bool result = false; OSNumber* number = NULL; UInt32 numStreams; UInt32 streamNum; OSArray* formatArray = NULL; OSArray* sampleRateArray = NULL; UInt32 startingChannelID = 1; OSString* desc; desc = OSDynamicCast(OSString, getProperty(DESCRIPTION_KEY)); if (desc) setDescription(desc->getCStringNoCopy()); number = OSDynamicCast(OSNumber, getProperty(NUM_STREAMS_KEY)); if (number) numStreams = number->unsigned32BitValue(); else numStreams = NUM_STREAMS; formatArray = OSDynamicCast(OSArray, getProperty(FORMATS_KEY)); if (formatArray == NULL) { IOLog("SF formatArray is NULL\n"); goto Done; } sampleRateArray = OSDynamicCast(OSArray, getProperty(SAMPLE_RATES_KEY)); if (sampleRateArray == NULL) { IOLog("SF sampleRateArray is NULL\n"); goto Done; } for (streamNum = 0; streamNum < numStreams; streamNum++) { UInt32 maxBitWidth = 0; UInt32 maxNumChannels = 0; OSCollectionIterator* formatIterator = NULL; OSCollectionIterator* sampleRateIterator = NULL; OSDictionary* formatDict; IOAudioSampleRate sampleRate; IOAudioStreamFormat initialFormat; bool initialFormatSet; UInt32 channelID; char outputStreamName[64]; char inputStreamName[64]; initialFormatSet = false; sampleRate.whole = 0; sampleRate.fraction = 0; inputStream = new IOAudioStream; if (inputStream == NULL) { IOLog("SF could not create new input IOAudioStream\n"); goto Error; } outputStream = new IOAudioStream; if (outputStream == NULL) { IOLog("SF could not create new output IOAudioStream\n"); goto Error; } snprintf(inputStreamName, 64, "eqMac2Driver Input Stream #%u", (unsigned int)streamNum + 1); snprintf(outputStreamName, 64, "eqMac2Driver Output Stream #%u", (unsigned int)streamNum + 1); if (!inputStream->initWithAudioEngine(this, kIOAudioStreamDirectionInput, startingChannelID, inputStreamName) || !outputStream->initWithAudioEngine(this, kIOAudioStreamDirectionOutput, startingChannelID, outputStreamName)) { IOLog("SF could not init one of the streams with audio engine. \n"); goto Error; } formatIterator = OSCollectionIterator::withCollection(formatArray); if (!formatIterator) { IOLog("SF NULL formatIterator\n"); goto Error; } sampleRateIterator = OSCollectionIterator::withCollection(sampleRateArray); if (!sampleRateIterator) { IOLog("SF NULL sampleRateIterator\n"); goto Error; } formatIterator->reset(); while ((formatDict = (OSDictionary *)formatIterator->getNextObject())) { IOAudioStreamFormat format; if (OSDynamicCast(OSDictionary, formatDict) == NULL) { IOLog("SF error casting formatDict\n"); goto Error; } if (IOAudioStream::createFormatFromDictionary(formatDict, &format) == NULL) { IOLog("SF error in createFormatFromDictionary()\n"); goto Error; } if (!initialFormatSet) { initialFormat = format; } sampleRateIterator->reset(); while ((number = (OSNumber *)sampleRateIterator->getNextObject())) { if (!OSDynamicCast(OSNumber, number)) { IOLog("SF error iterating sample rates\n"); goto Error; } sampleRate.whole = number->unsigned32BitValue(); inputStream->addAvailableFormat(&format, &sampleRate, &sampleRate); outputStream->addAvailableFormat(&format, &sampleRate, &sampleRate); if (format.fNumChannels > maxNumChannels) { maxNumChannels = format.fNumChannels; } if (format.fBitWidth > maxBitWidth) { maxBitWidth = format.fBitWidth; } if (initialSampleRate->whole == 0) { initialSampleRate->whole = sampleRate.whole; } } } mBufferSize = blockSize * numBlocks * maxNumChannels * maxBitWidth / 8; //IOLog("eqMac2Driver streamBufferSize: %ld\n", mBufferSize); if (mBuffer == NULL) { mBuffer = (void *)IOMalloc(mBufferSize); if (!mBuffer) { IOLog("eqMac2Driver: Error allocating output buffer - %lu bytes.\n", (unsigned long)mBufferSize); goto Error; } mThruBuffer = (float*)IOMalloc(mBufferSize); if (!mThruBuffer) { IOLog("eqMac2Driver: Error allocating thru buffer - %lu bytes.\n", (unsigned long)mBufferSize); goto Error; } memset((UInt8*)mThruBuffer, 0, mBufferSize); } inputStream->setFormat(&initialFormat); inputStream->setSampleBuffer(mBuffer, mBufferSize); addAudioStream(inputStream); inputStream->release(); outputStream->setFormat(&initialFormat); outputStream->setSampleBuffer(mBuffer, mBufferSize); addAudioStream(outputStream); outputStream->release(); formatIterator->release(); sampleRateIterator->release(); for (channelID = startingChannelID; channelID < (startingChannelID + maxNumChannels); channelID++) { char channelName[20]; snprintf(channelName, 20, "Channel %u", (unsigned int)channelID); } startingChannelID += maxNumChannels; continue; Error: IOLog("eqMac2DriverEngine[%p]::createAudioStreams() - ERROR\n", this); if (inputStream) inputStream->release(); if (outputStream) outputStream->release(); if (formatIterator) formatIterator->release(); if (sampleRateIterator) sampleRateIterator->release(); goto Done; } result = true; Done: if (!result) IOLog("eqMac2DriverEngine[%p]::createAudioStreams() - failed!\n", this); return result; }
//********************************************************************************* // printDictionaryKeys // // Print the keys for the given dictionary and selected contents. //********************************************************************************* void printDictionaryKeys (OSDictionary * inDictionary, char * inMsg) { OSCollectionIterator * mcoll = OSCollectionIterator::withCollection (inDictionary); OSSymbol * mkey; OSString * ioClass; unsigned int i = 0; mcoll->reset (); mkey = OSDynamicCast (OSSymbol, mcoll->getNextObject ()); while (mkey) { // kprintf ("dictionary key #%d: %s\n", i, mkey->getCStringNoCopy () ); // if this is the IOClass key, print it's contents if ( mkey->isEqualTo ("IOClass") ) { ioClass = (OSString *) inDictionary->getObject ("IOClass"); if ( ioClass ) IOLog ("%s IOClass is %s\n", inMsg, ioClass->getCStringNoCopy () ); } // if this is an IOProviderClass key print it if ( mkey->isEqualTo ("IOProviderClass") ) { ioClass = (OSString *) inDictionary->getObject ("IOProviderClass"); if ( ioClass ) IOLog ("%s IOProviderClass is %s\n", inMsg, ioClass->getCStringNoCopy () ); } // also print IONameMatch keys if ( mkey->isEqualTo ("IONameMatch") ) { ioClass = (OSString *) inDictionary->getObject ("IONameMatch"); if ( ioClass ) IOLog ("%s IONameMatch is %s\n", inMsg, ioClass->getCStringNoCopy () ); } // also print IONameMatched keys if ( mkey->isEqualTo ("IONameMatched") ) { ioClass = (OSString *) inDictionary->getObject ("IONameMatched"); if ( ioClass ) IOLog ("%s IONameMatched is %s\n", inMsg, ioClass->getCStringNoCopy () ); } #if 0 // print clock-id if ( mkey->isEqualTo ("AAPL,clock-id") ) { char * cstr; cstr = getCStringForObject (inDictionary->getObject ("AAPL,clock-id")); if (cstr) kprintf (" ===> AAPL,clock-id is %s\n", cstr ); } #endif // print name if ( mkey->isEqualTo ("name") ) { char nameStr[64]; nameStr[0] = 0; getCStringForObject (inDictionary->getObject ("name"), nameStr ); if (strlen(nameStr) > 0) IOLog ("%s name is %s\n", inMsg, nameStr); } mkey = (OSSymbol *) mcoll->getNextObject (); i++; } mcoll->release (); }
bool ACPIMonitor::start(IOService * provider) { if (!super::start(provider)) return false; acpiDevice = (IOACPIPlatformDevice *)provider; if (!acpiDevice) { HWSensorsWarningLog("ACPI device not ready"); return false; } if (OSDictionary *config = OSDynamicCast(OSDictionary, getProperty("Keys Associations"))) { // Temperatures if ((temperatures = OSDynamicCast(OSDictionary, config->getObject("Temperatures")))) { OSCollectionIterator *iterator = OSCollectionIterator::withCollection(temperatures); iterator->reset(); while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) { OSString *method = OSDynamicCast(OSString, temperatures->getObject(key)); if (method && kIOReturnSuccess == acpiDevice->evaluateObject(method->getCStringNoCopy())) { if (!addSensor(key->getCStringNoCopy(), TYPE_SP78, TYPE_SPXX_SIZE, kFakeSMCTemperatureSensor, 0)) HWSensorsWarningLog("can't add temperature sensor for method %s with key %s", method->getCStringNoCopy(), key->getCStringNoCopy()); } }; //HWSensorsInfoLog("%d temperature sensor(s) added", count); } else return false; // Voltages if ((voltages = OSDynamicCast(OSDictionary, config->getObject("Voltages")))) { OSCollectionIterator *iterator = OSCollectionIterator::withCollection(voltages); iterator->reset(); while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) { OSString *method = OSDynamicCast(OSString, voltages->getObject(key)); if (method && kIOReturnSuccess == acpiDevice->evaluateObject(method->getCStringNoCopy())) { if (!addSensor(key->getCStringNoCopy(), TYPE_FP4C, TYPE_FPXX_SIZE, kFakeSMCVoltageSensor, 0)) HWSensorsWarningLog("can't add voltage sensor for method %s with key %s", method->getCStringNoCopy(), key->getCStringNoCopy()); } }; //HWSensorsInfoLog("%d voltage sensor(s) added", count); } else return false; // Tachometers if ((tachometers = OSDynamicCast(OSDictionary, config->getObject("Tachometers")))) { UInt16 count = 0; OSArray* fanNames = OSDynamicCast(OSArray, getProperty("Fan Names")); OSCollectionIterator *iterator = OSCollectionIterator::withCollection(tachometers); iterator->reset(); while (OSString *key = OSDynamicCast(OSString, iterator->getNextObject())) { OSString *method = OSDynamicCast(OSString, tachometers->getObject(key)); if (method && kIOReturnSuccess == acpiDevice->evaluateObject(method->getCStringNoCopy())) { OSString* name = NULL; if (fanNames) name = OSDynamicCast(OSString, fanNames->getObject(count)); if (!addTachometer(count, name ? name->getCStringNoCopy() : 0)) HWSensorsWarningLog("Failed to register tachometer sensor %d", count); count++; } }; //HWSensorsInfoLog("%d tachometer sensor(s) added", count); } else return false; } registerService(); return true; }
void KLDBootstrap::readBooterExtensions(void) { IORegistryEntry * booterMemoryMap = NULL; // must release OSDictionary * propertyDict = NULL; // must release OSCollectionIterator * keyIterator = NULL; // must release OSString * deviceTreeName = NULL; // do not release const _DeviceTreeBuffer * deviceTreeBuffer = NULL; // do not free char * booterDataPtr = NULL; // do not free OSData * booterData = NULL; // must release OSKext * aKext = NULL; // must release OSKextLog(/* kext */ NULL, kOSKextLogProgressLevel | kOSKextLogDirectoryScanFlag | kOSKextLogKextBookkeepingFlag, "Reading startup extensions from booter memory."); booterMemoryMap = IORegistryEntry::fromPath( "/chosen/memory-map", gIODTPlane); if (!booterMemoryMap) { OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogGeneralFlag | kOSKextLogDirectoryScanFlag, "Can't read booter memory map."); goto finish; } propertyDict = booterMemoryMap->dictionaryWithProperties(); if (!propertyDict) { OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogDirectoryScanFlag, "Can't get property dictionary from memory map."); goto finish; } keyIterator = OSCollectionIterator::withCollection(propertyDict); if (!keyIterator) { OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogGeneralFlag, "Can't allocate iterator for driver images."); goto finish; } /* Create dictionary of excluded kexts */ OSKext::createExcludeListFromBooterData(propertyDict, keyIterator); keyIterator->reset(); while ( ( deviceTreeName = OSDynamicCast(OSString, keyIterator->getNextObject() ))) { const char * devTreeNameCString = deviceTreeName->getCStringNoCopy(); OSData * deviceTreeEntry = OSDynamicCast(OSData, propertyDict->getObject(deviceTreeName)); /* Clear out the booterData from the prior iteration. */ OSSafeReleaseNULL(booterData); /* If there is no entry for the name, we can't do much with it. */ if (!deviceTreeEntry) { continue; } /* Make sure it is a kext */ if (strncmp(devTreeNameCString, BOOTER_KEXT_PREFIX, CONST_STRLEN(BOOTER_KEXT_PREFIX))) { continue; } deviceTreeBuffer = (const _DeviceTreeBuffer *) deviceTreeEntry->getBytesNoCopy(0, sizeof(deviceTreeBuffer)); if (!deviceTreeBuffer) { /* We can't get to the data, so we can't do anything, * not even free it from physical memory (if it's there). */ OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogDirectoryScanFlag, "Device tree entry %s has NULL pointer.", devTreeNameCString); goto finish; // xxx - continue, panic? } booterDataPtr = (char *)ml_static_ptovirt(deviceTreeBuffer->paddr); if (!booterDataPtr) { OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogDirectoryScanFlag, "Can't get virtual address for device tree entry %s.", devTreeNameCString); goto finish; } /* Wrap the booter data buffer in an OSData and set a dealloc function * so it will take care of the physical memory when freed. Kexts will * retain the booterData for as long as they need it. Remove the entry * from the booter memory map after this is done. */ booterData = OSData::withBytesNoCopy(booterDataPtr, deviceTreeBuffer->length); if (!booterData) { OSKextLog(/* kext */ NULL, kOSKextLogErrorLevel | kOSKextLogGeneralFlag, "Error - Can't allocate OSData wrapper for device tree entry %s.", devTreeNameCString); goto finish; } booterData->setDeallocFunction(osdata_phys_free); /* Create the kext for the entry, then release it, because the * kext system keeps them around until explicitly removed. * Any creation/registration failures are already logged for us. */ OSKext * newKext = OSKext::withBooterData(deviceTreeName, booterData); OSSafeReleaseNULL(newKext); booterMemoryMap->removeProperty(deviceTreeName); } /* while ( (deviceTreeName = OSDynamicCast(OSString, ...) ) ) */ finish: OSSafeReleaseNULL(booterMemoryMap); OSSafeReleaseNULL(propertyDict); OSSafeReleaseNULL(keyIterator); OSSafeReleaseNULL(booterData); OSSafeReleaseNULL(aKext); return; }
/********************************************************************* * Remove drivers from the catalog which match the * properties in the matching dictionary. *********************************************************************/ bool IOCatalogue::removeDrivers( OSDictionary * matching, bool doNubMatching) { OSCollectionIterator * tables; OSDictionary * dict; OSOrderedSet * set; OSArray * arrayCopy; if ( !matching ) return false; set = OSOrderedSet::withCapacity(10, IOServiceOrdering, (void *)gIOProbeScoreKey); if ( !set ) return false; arrayCopy = OSArray::withCapacity(100); if ( !arrayCopy ) { set->release(); return false; } tables = OSCollectionIterator::withCollection(arrayCopy); arrayCopy->release(); if ( !tables ) { set->release(); return false; } UniqueProperties( matching ); IOLockLock(lock); kernelTables->reset(); arrayCopy->merge(array); array->flushCollection(); tables->reset(); while ( (dict = (OSDictionary *)tables->getNextObject()) ) { /* This comparison must be done with only the keys in the * "matching" dict to enable general searches. */ if ( dict->isEqualTo(matching, matching) ) { AddNewImports( set, dict ); continue; } array->setObject(dict); } // Start device matching. if ( doNubMatching && (set->getCount() > 0) ) { IOService::catalogNewDrivers(set); generation++; } IOLockUnlock(lock); set->release(); tables->release(); return true; }
bool AREngine::CreateStreams(IOAudioSampleRate* outInitialSampleRate, UInt32* outNumberChannels) { // set the return values bool theAnswer = true; *outNumberChannels = 0; // set up some local variables OSArray* theFormatArray = NULL; OSArray* theSampleRateArray = NULL; OSString* theOSString = NULL; UInt32 theNumberStreams = NUM_STREAMS; OSNumber* theOSNumber = NULL; // get the array of formats theFormatArray = OSDynamicCast(OSArray, getProperty(FORMATS_KEY)); FailIfNULLWithAction(theFormatArray, theAnswer = false, Done, "AREngine::CreateStreams: Couldn't get the format array"); // get the array of sample rates theSampleRateArray = OSDynamicCast(OSArray, getProperty(SAMPLE_RATES_KEY)); FailIfNULLWithAction(theSampleRateArray, theAnswer = false, Done, "AREngine::CreateStreams: Couldn't get the sample rate array"); // get the description theOSString = OSDynamicCast(OSString, getProperty(DESCRIPTION_KEY)); if(theOSString != NULL) { setDescription(theOSString->getCStringNoCopy()); } // get the number of streams theOSNumber = OSDynamicCast(OSNumber, getProperty(NUM_STREAMS_KEY)); if(theOSNumber != NULL) { theNumberStreams = theOSNumber->unsigned32BitValue(); } // make the streams for(UInt32 theStreamNumber = 0; theStreamNumber < theNumberStreams; ++theStreamNumber) { // initialize some local variables bool theResult = false; UInt32 theMaxBitWidth = 0; UInt32 theMaxNumberChannels = 0; IOAudioStream* theInputStream = NULL; IOAudioStream* theOutputStream = NULL; OSCollectionIterator* theFormatIterator = NULL; OSCollectionIterator* theSampleRateIterator = NULL; OSDictionary* theFormatDictionary = NULL; IOAudioSampleRate theSampleRate = { 0, 0 }; IOAudioStreamFormat theInitialFormat; bool theInitialFormatSet = false; char theInputStreamName[32]; char theOutputStreamName[32]; UInt32 theStreamBufferSize = 0; // allocate and initialize the input stream if(theNumberStreams > 1) { snprintf(theInputStreamName, 32, "Input Stream #%ld", theStreamNumber + 1); } else { snprintf(theInputStreamName, 32, "Input Stream"); } theInputStream = new IOAudioStream; FailIfNULLWithAction(theInputStream, theAnswer = false, Error, "AREngine::CreateStreams: couldn't create the input stream"); theResult = theInputStream->initWithAudioEngine(this, kIOAudioStreamDirectionInput, *outNumberChannels + 1, theInputStreamName); FailIfWithAction(!theResult, theAnswer = false, Error, "AREngine::CreateStreams: couldn't initialize the input stream"); // allocate and initialize the output stream if(theNumberStreams > 1) { snprintf(theOutputStreamName, 32, "Output Stream #%ld", theStreamNumber + 1); } else { snprintf(theOutputStreamName, 32, "Output Stream"); } theOutputStream = new IOAudioStream; FailIfNULLWithAction(theOutputStream, theAnswer = false, Error, "AREngine::CreateStreams: couldn't create the output stream"); theResult = theOutputStream->initWithAudioEngine(this, kIOAudioStreamDirectionOutput, *outNumberChannels + 1, theOutputStreamName); FailIfWithAction(!theResult, theAnswer = false, Error, "AREngine::CreateStreams: couldn't initialize the output stream"); // make an iterator for the format array theFormatIterator = OSCollectionIterator::withCollection(theFormatArray); FailIfNULLWithAction(theFormatIterator, theAnswer = false, Error, "AREngine::CreateStreams: couldn't create the format iterator"); // make an iterator for the sample rate array theSampleRateIterator = OSCollectionIterator::withCollection(theSampleRateArray); FailIfNULLWithAction(theSampleRateIterator, theAnswer = false, Error, "AREngine::CreateStreams: couldn't create the sample rate iterator"); // iterate through the formats theFormatIterator->reset(); theFormatDictionary = (OSDictionary*)theFormatIterator->getNextObject(); while(theFormatDictionary != NULL) { // make sure we have a dictionary if(OSDynamicCast(OSDictionary, theFormatDictionary) != NULL) { // convert the dictionary into something we can deal with IOAudioStreamFormat theFormat; FailIfNULLWithAction(IOAudioStream::createFormatFromDictionary(theFormatDictionary, &theFormat), theAnswer = false, Error, "AREngine::CreateStreams: couldn't make a format out of the dictionary"); // make sure the initial format is set if(!theInitialFormatSet) { theInitialFormat = theFormat; } // iterate through the sample rates theSampleRateIterator->reset(); theOSNumber = (OSNumber*)theSampleRateIterator->getNextObject(); while(theOSNumber != NULL) { // make sure we have a number if(OSDynamicCast(OSNumber, theOSNumber) != NULL) { // get the sample rate theSampleRate.whole = theOSNumber->unsigned32BitValue(); // make sure the initial sample rate is set if(outInitialSampleRate->whole == 0) { outInitialSampleRate->whole = theSampleRate.whole; } // add the format to the input stream theInputStream->addAvailableFormat(&theFormat, &theSampleRate, &theSampleRate); // add the format to the output stream theOutputStream->addAvailableFormat(&theFormat, &theSampleRate, &theSampleRate); // track a few things theMaxNumberChannels = (theFormat.fNumChannels > theMaxNumberChannels) ? theFormat.fNumChannels : theMaxNumberChannels; theMaxBitWidth = (theFormat.fBitWidth > theMaxBitWidth) ? theFormat.fBitWidth : theMaxBitWidth; } // go to the next sample rate theOSNumber = (OSNumber*)theSampleRateIterator->getNextObject(); } } // go to the next format theFormatDictionary = (OSDictionary*)theFormatIterator->getNextObject(); } // calculate the size of the stream buffer theStreamBufferSize = mBlockSize * mNumberBlocks * theMaxNumberChannels * theMaxBitWidth / 8; // allocate the buffers if necessary if(mOutputBuffer == NULL) { // calculate the size mOutputBufferSize = theStreamBufferSize * theNumberStreams; // allocate the output buffer mOutputBuffer = (void*)IOMallocAligned(mOutputBufferSize, PAGE_SIZE); FailIfNULLWithAction(mOutputBuffer, theAnswer = false, Error, "AREngine::CreateStreams: couldn't allocate the output buffer"); // the input size is the same as the output size mInputBufferSize = mOutputBufferSize; // allocate the input buffer mInputBuffer = mOutputBuffer; } // set some info about the stream theInputStream->setTerminalType(INPUT_UNDEFINED); theOutputStream->setTerminalType(OUTPUT_UNDEFINED); // set the initial stream formats theInputStream->setFormat(&theInitialFormat, false); theOutputStream->setFormat(&theInitialFormat, false); // set the data buffer for the streams theInputStream->setSampleBuffer(&((UInt8*)mInputBuffer)[theStreamBufferSize * theStreamNumber], theStreamBufferSize); theOutputStream->setSampleBuffer(&((UInt8*)mOutputBuffer)[theStreamBufferSize * theStreamNumber], theStreamBufferSize); // add the streams to the engine addAudioStream(theInputStream); theInputStream->release(); theInputStream = NULL; addAudioStream(theOutputStream); theOutputStream->release(); theOutputStream = NULL; theFormatIterator->release(); theFormatIterator = NULL; theSampleRateIterator->release(); theSampleRateIterator = NULL; *outNumberChannels += theMaxNumberChannels; continue; Error: if(theInputStream) { theInputStream->release(); } if(theOutputStream) { theOutputStream->release(); } if(theFormatIterator) { theFormatIterator->release(); } if(theSampleRateIterator) { theSampleRateIterator->release(); } goto Done; } Done: return theAnswer; }
bool PhantomAudioEngine::createAudioStreams(IOAudioSampleRate *initialSampleRate) { bool result = false; OSNumber *number; UInt32 numStreams, streamNum; OSArray *formatArray, *sampleRateArray; UInt32 startingChannelID = 1; IOAudioControl *control; OSString *desc; OSBoolean *boolean; bool separateStreamBuffers = FALSE, separateInputBuffers = FALSE; desc = OSDynamicCast(OSString, getProperty(DESCRIPTION_KEY)); if (desc) { setDescription(desc->getCStringNoCopy()); } number = OSDynamicCast(OSNumber, getProperty(NUM_STREAMS_KEY)); if (number) { numStreams = number->unsigned32BitValue(); } else { numStreams = NUM_STREAMS; } formatArray = OSDynamicCast(OSArray, getProperty(FORMATS_KEY)); if (formatArray == NULL) { goto Done; } sampleRateArray = OSDynamicCast(OSArray, getProperty(SAMPLE_RATES_KEY)); if (sampleRateArray == NULL) { goto Done; } boolean = OSDynamicCast(OSBoolean, getProperty(SEPARATE_STREAM_BUFFERS_KEY)); if (boolean != NULL) { separateStreamBuffers = boolean->getValue(); } boolean = OSDynamicCast(OSBoolean, getProperty(SEPARATE_INPUT_BUFFERS_KEY)); if (boolean != NULL) { separateInputBuffers = boolean->getValue(); } if (separateStreamBuffers) { IOLog("PhantomAudioEngine::createAudioStreams() - Creating a separate buffer for each stream.\n"); } else { IOLog("PhantomAudioEngine::createAudioStreams() - Sharing one buffer among all streams.\n"); } if (separateInputBuffers) { IOLog("PhantomAudioEngine::createAudioStreams() - Creating separate buffers for input and output.\n"); } else { IOLog("PhantomAudioEngine::createAudioStreams() - Sharing input and output buffers.\n"); } for (streamNum = 0; streamNum < numStreams; streamNum++) { IOAudioStream *inputStream = NULL, *outputStream = NULL; UInt32 maxBitWidth = 0; UInt32 maxNumChannels = 0; OSCollectionIterator *formatIterator = NULL, *sampleRateIterator = NULL; OSDictionary *formatDict; IOAudioSampleRate sampleRate; IOAudioStreamFormat initialFormat; bool initialFormatSet; UInt32 channelID; char outputStreamName[20], inputStreamName[20]; UInt32 streamBufferSize; initialFormatSet = false; sampleRate.whole = 0; sampleRate.fraction = 0; inputStream = new IOAudioStream; if (inputStream == NULL) { goto Error; } outputStream = new IOAudioStream; if (outputStream == NULL) { goto Error; } sprintf(inputStreamName, "Input Stream #%ld", streamNum + 1); sprintf(outputStreamName, "Output Stream #%ld", streamNum + 1); if (!inputStream->initWithAudioEngine(this, kIOAudioStreamDirectionInput, startingChannelID, inputStreamName) || !outputStream->initWithAudioEngine(this, kIOAudioStreamDirectionOutput, startingChannelID, outputStreamName)) { goto Error; } formatIterator = OSCollectionIterator::withCollection(formatArray); if (!formatIterator) { goto Error; } sampleRateIterator = OSCollectionIterator::withCollection(sampleRateArray); if (!sampleRateIterator) { goto Error; } formatIterator->reset(); while (formatDict = (OSDictionary *)formatIterator->getNextObject()) { IOAudioStreamFormat format; if (OSDynamicCast(OSDictionary, formatDict) == NULL) { goto Error; } if (IOAudioStream::createFormatFromDictionary(formatDict, &format) == NULL) { goto Error; } if (!initialFormatSet) { initialFormat = format; } sampleRateIterator->reset(); while (number = (OSNumber *)sampleRateIterator->getNextObject()) { if (!OSDynamicCast(OSNumber, number)) { goto Error; } sampleRate.whole = number->unsigned32BitValue(); inputStream->addAvailableFormat(&format, &sampleRate, &sampleRate); if (format.fBitDepth == 24) { IOAudioStream::AudioIOFunction functions[2]; functions[0] = process24BitSamples; functions[1] = clip24BitSamples; //outputStream->addAvailableFormat(&format, &sampleRate, &sampleRate, functions, 2); outputStream->addAvailableFormat(&format, &sampleRate, &sampleRate, (IOAudioStream::AudioIOFunction)clip24BitSamples); if (format.fNumericRepresentation == kIOAudioStreamSampleFormatLinearPCM && format.fIsMixable == TRUE) { format.fIsMixable = FALSE; outputStream->addAvailableFormat(&format, &sampleRate, &sampleRate, (IOAudioStream::AudioIOFunction)clip24BitSamples); } } else if (format.fBitDepth == 16) { IOAudioStream::AudioIOFunction functions[2]; functions[0] = process16BitSamples; functions[1] = clip16BitSamples; //outputStream->addAvailableFormat(&format, &sampleRate, &sampleRate, functions, 2); outputStream->addAvailableFormat(&format, &sampleRate, &sampleRate, (IOAudioStream::AudioIOFunction)clip16BitSamples); if (format.fNumericRepresentation == kIOAudioStreamSampleFormatLinearPCM && format.fIsMixable == TRUE) { format.fIsMixable = FALSE; outputStream->addAvailableFormat(&format, &sampleRate, &sampleRate, (IOAudioStream::AudioIOFunction)clip24BitSamples); } } else { outputStream->addAvailableFormat(&format, &sampleRate, &sampleRate); if (format.fNumericRepresentation == kIOAudioStreamSampleFormatLinearPCM && format.fIsMixable == TRUE) { format.fIsMixable = FALSE; outputStream->addAvailableFormat(&format, &sampleRate, &sampleRate, (IOAudioStream::AudioIOFunction)clip24BitSamples); } } if (format.fNumChannels > maxNumChannels) { maxNumChannels = format.fNumChannels; } if (format.fBitWidth > maxBitWidth) { maxBitWidth = format.fBitWidth; } if (initialSampleRate->whole == 0) { initialSampleRate->whole = sampleRate.whole; } } } streamBufferSize = blockSize * numBlocks * maxNumChannels * maxBitWidth / 8; if (outputBuffer == NULL) { if (separateStreamBuffers) { outputBufferSize = streamBufferSize * numStreams; } else { outputBufferSize = streamBufferSize; } outputBuffer = (void *)IOMalloc(outputBufferSize); if (!outputBuffer) { IOLog("Error allocating output buffer - %lu bytes.\n", outputBufferSize); goto Error; } inputBufferSize = outputBufferSize; if (separateInputBuffers) { inputBuffer = (void *)IOMalloc(inputBufferSize); if (!inputBuffer) { IOLog("Error allocating input buffer - %lu bytes.\n", inputBufferSize); goto Error; } } else { inputBuffer = outputBuffer; } } inputStream->setFormat(&initialFormat); outputStream->setFormat(&initialFormat); if (separateStreamBuffers) { inputStream->setSampleBuffer(&((UInt8 *)inputBuffer)[streamBufferSize * streamNum], streamBufferSize); outputStream->setSampleBuffer(&((UInt8 *)outputBuffer)[streamBufferSize * streamNum], streamBufferSize); } else { inputStream->setSampleBuffer(inputBuffer, streamBufferSize); outputStream->setSampleBuffer(outputBuffer, streamBufferSize); } addAudioStream(inputStream); inputStream->release(); addAudioStream(outputStream); outputStream->release(); formatIterator->release(); sampleRateIterator->release(); for (channelID = startingChannelID; channelID < (startingChannelID + maxNumChannels); channelID++) { char channelName[20]; sprintf(channelName, "Channel %lu", channelID); control = IOAudioLevelControl::createVolumeControl(65535, 0, 65535, (-22 << 16) + (32768), 0, channelID, channelName, 0, kIOAudioControlUsageOutput); if (!control) { goto Error; } control->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)PhantomAudioDevice::volumeChangeHandler, audioDevice); addDefaultAudioControl(control); control->release(); control = IOAudioToggleControl::createMuteControl(false, channelID, channelName, 0, kIOAudioControlUsageOutput); if (!control) { goto Error; } control->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)PhantomAudioDevice::outputMuteChangeHandler, audioDevice); addDefaultAudioControl(control); control->release(); control = IOAudioLevelControl::createVolumeControl(65535, 0, 65535, (-22 << 16) + (32768), 0, channelID, channelName, 0, kIOAudioControlUsageInput); if (!control) { goto Error; } control->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)PhantomAudioDevice::gainChangeHandler, audioDevice); addDefaultAudioControl(control); control->release(); control = IOAudioToggleControl::createMuteControl(false, channelID, channelName, 0, kIOAudioControlUsageInput); if (!control) { goto Error; } control->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)PhantomAudioDevice::inputMuteChangeHandler, audioDevice); addDefaultAudioControl(control); control->release(); control = IOAudioToggleControl::createMuteControl(true, channelID, channelName, 0, kIOAudioControlUsagePassThru); if (!control) { goto Error; } control->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)PhantomAudioDevice::passThruChangeHandler, audioDevice); addDefaultAudioControl(control); control->release(); } startingChannelID += maxNumChannels; continue; Error: IOLog("PhantomAudioEngine[%p]::createAudioStreams() - ERROR\n", this); if (inputStream) { inputStream->release(); } if (outputStream) { outputStream->release(); } if (formatIterator) { formatIterator->release(); } if (sampleRateIterator) { sampleRateIterator->release(); } goto Done; } control = IOAudioLevelControl::createVolumeControl(65535, 0, 65535, (-22 << 16) + (32768), 0, kIOAudioControlChannelIDAll, kIOAudioControlChannelNameAll, 0, kIOAudioControlUsageOutput); if (!control) { goto Done; } control->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)PhantomAudioDevice::volumeChangeHandler, audioDevice); addDefaultAudioControl(control); control->release(); control = IOAudioToggleControl::createMuteControl(false, kIOAudioControlChannelIDAll, kIOAudioControlChannelNameAll, 0, kIOAudioControlUsageOutput); if (!control) { goto Done; } control->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)PhantomAudioDevice::outputMuteChangeHandler, audioDevice); addDefaultAudioControl(control); control->release(); control = IOAudioLevelControl::createVolumeControl(65535, 0, 65535, (-22 << 16) + (32768), 0, kIOAudioControlChannelIDAll, kIOAudioControlChannelNameAll, 0, kIOAudioControlUsageInput); if (!control) { goto Done; } control->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)PhantomAudioDevice::gainChangeHandler, audioDevice); addDefaultAudioControl(control); control->release(); control = IOAudioToggleControl::createMuteControl(false, kIOAudioControlChannelIDAll, kIOAudioControlChannelNameAll, 0, kIOAudioControlUsageInput); if (!control) { goto Done; } control->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)PhantomAudioDevice::inputMuteChangeHandler, audioDevice); addDefaultAudioControl(control); control->release(); control = IOAudioToggleControl::createMuteControl(true, kIOAudioControlChannelIDAll, kIOAudioControlChannelNameAll, 0, kIOAudioControlUsagePassThru); if (!control) { goto Done; } control->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)PhantomAudioDevice::passThruChangeHandler, audioDevice); addDefaultAudioControl(control); control->release(); result = true; Done: if (!result) { IOLog("PhantomAudioEngine[%p]::createAudioStreams() - failed!\n", this); } return result; }
IOReturn ApplePS2CypressTouchPad::setParamProperties( OSDictionary * dict ) { if (dict == 0) return super::setParamProperties(dict); OSNumber * clicking = OSDynamicCast( OSNumber, dict->getObject("Clicking") ); OSNumber * dragging = OSDynamicCast( OSNumber, dict->getObject("Dragging") ); OSNumber * draglock = OSDynamicCast( OSNumber, dict->getObject("DragLock") ); OSNumber * hscroll = OSDynamicCast( OSNumber, dict->getObject("TrackpadHorizScroll") ); OSNumber * vscroll = OSDynamicCast( OSNumber, dict->getObject("TrackpadScroll") ); OSNumber * scrollspeed = OSDynamicCast( OSNumber, dict->getObject("HIDTrackpadScrollAcceleration") ); OSNumber * onefingermaxtaptime = OSDynamicCast( OSNumber, dict->getObject("Cypress1FingerMaxTapTime") ); OSNumber * twofingermaxtaptime = OSDynamicCast( OSNumber, dict->getObject("Cypress2FingerMaxTapTime") ); OSNumber * threefingermaxtaptime = OSDynamicCast( OSNumber, dict->getObject("Cypress3FingerMaxTapTime") ); OSNumber * fourfingermaxtaptime = OSDynamicCast( OSNumber, dict->getObject("Cypress4FingerMaxTapTime") ); OSNumber * fivefingermaxtaptime = OSDynamicCast( OSNumber, dict->getObject("Cypress5FingerMaxTapTime") ); OSNumber * dragPressureAverage = OSDynamicCast( OSNumber, dict->getObject("CypressDragPressureAverage")); OSNumber * fiveFingerSleepTimer = OSDynamicCast( OSNumber, dict->getObject("Cypress5FingerSleepTimer")); OSNumber * fiveFingerScreenLockTimer = OSDynamicCast( OSNumber, dict->getObject("Cypress5FingerScreenLockTimer")); OSNumber * pressureFiltering = OSDynamicCast( OSNumber, dict->getObject("CypressPressureFiltering")); OSNumber * twoFingerFiltering = OSDynamicCast( OSNumber, dict->getObject("Cypress2FingerFiltering")); OSNumber * threeFingerFiltering = OSDynamicCast( OSNumber, dict->getObject("Cypress3FingerFiltering")); OSNumber * fourFingerFiltering = OSDynamicCast( OSNumber, dict->getObject("Cypress4FingerFiltering")); OSBoolean * fourFingerHorizSwipeGesture = OSDynamicCast( OSBoolean, dict->getObject("CypressFourFingerHorizSwipeGesture") ); OSBoolean * fourFingerVertSwipeGesture = OSDynamicCast( OSBoolean, dict->getObject("CypressFourFingerVertSwipeGesture") ); OSBoolean * twoFingerRightClick = OSDynamicCast( OSBoolean, dict->getObject("CypressTwoFingerRightClick") ); OSBoolean * threeFingerDrag = OSDynamicCast( OSBoolean, dict->getObject("CypressThreeFingerDrag")); OSBoolean * fiveFingerSleep = OSDynamicCast( OSBoolean, dict->getObject("CypressFiveFingerSleep")); OSBoolean * fiveFingerScreenLock = OSDynamicCast( OSBoolean, dict->getObject("CypressFiveFingerScreenLock")); #ifdef DEBUG OSCollectionIterator* iter = OSCollectionIterator::withCollection( dict ); OSObject* obj; iter->reset(); while ((obj = iter->getNextObject()) != NULL) { OSString* str = OSDynamicCast( OSString, obj ); OSNumber* val = OSDynamicCast( OSNumber, dict->getObject( str ) ); if (val) DEBUG_LOG("%s: Dictionary Object: %s Value: %d\n", getName(), str->getCStringNoCopy(), val->unsigned32BitValue()); else DEBUG_LOG("%s: Dictionary Object: %s Value: ??\n", getName(), str->getCStringNoCopy()); } #endif if (pressureFiltering) { _pressureFiltering = pressureFiltering->unsigned32BitValue(); _kalZ.noiseLevel(_pressureFiltering); setProperty("CypressPressureFiltering", pressureFiltering); } if (twoFingerFiltering) { _twoFingerFiltering = twoFingerFiltering->unsigned32BitValue(); setProperty("Cypress2FingerFiltering", twoFingerFiltering); } if (threeFingerFiltering) { _threeFingerFiltering = threeFingerFiltering->unsigned32BitValue(); setProperty("Cypress3FingerFiltering", threeFingerFiltering); } if (fourFingerFiltering) { _fourFingerFiltering = fourFingerFiltering->unsigned32BitValue(); setProperty("Cypress4FingerFiltering", fourFingerFiltering); } if (clicking) { _clicking = clicking->unsigned32BitValue() & 0x1 ? true : false; setProperty("Clicking", clicking); } _clicking = true; if (dragging) { _dragging = dragging->unsigned32BitValue() & 0x1 ? true : false; setProperty("Dragging", dragging); } _dragging = true; if (draglock) { _dragLock = draglock->unsigned32BitValue() & 0x1 ? true : false; setProperty("DragLock", draglock); } _dragLock = true; if (hscroll) { _trackpadHorizScroll = hscroll->unsigned32BitValue() & 0x1 ? true : false; setProperty("TrackpadHorizScroll", hscroll); } _trackpadHorizScroll = true; if (vscroll) { _trackpadScroll = vscroll->unsigned32BitValue() & 0x1 ? true : false; setProperty("TrackpadScroll", vscroll); } _trackpadScroll = true; if (scrollspeed) { _twoFingerDivider = (float)(scrollspeed->unsigned32BitValue()); setProperty("HIDTrackpadScrollAcceleration", scrollspeed); } if (dragPressureAverage) { _dragPressureAverage = dragPressureAverage->unsigned32BitValue(); setProperty("CypressDragPressureAverage", dragPressureAverage); } _dragPressureAverage = 85; if (onefingermaxtaptime) { _onefingermaxtaptime = ((onefingermaxtaptime->unsigned32BitValue()) * 1000000); setProperty("Cypress1FingerMaxTapTime", onefingermaxtaptime); } if (twofingermaxtaptime) { _twofingermaxtaptime = ((twofingermaxtaptime->unsigned32BitValue()) * 1000000); setProperty("Cypress2FingerMaxTapTime", twofingermaxtaptime); } if (threefingermaxtaptime) { _threefingermaxtaptime = ((threefingermaxtaptime->unsigned32BitValue()) * 1000000); setProperty("Cypress3FingerMaxTapTime", threefingermaxtaptime); } if (fourfingermaxtaptime) { _fourfingermaxtaptime = ((fourfingermaxtaptime->unsigned32BitValue()) * 1000000); setProperty("Cypress4FingerMaxTapTime", fourfingermaxtaptime); } if (fivefingermaxtaptime) { _fivefingermaxtaptime = ((fivefingermaxtaptime->unsigned32BitValue()) * 1000000); setProperty("Cypress3FingerMaxTapTime", fivefingermaxtaptime); } if (fourFingerHorizSwipeGesture) { _fourFingerHorizSwipeGesture = fourFingerHorizSwipeGesture->isTrue(); setProperty("CypressFourFingerHorizSwipeGesture", fourFingerHorizSwipeGesture->isTrue()); } _fourFingerHorizSwipeGesture = true; if (fourFingerVertSwipeGesture) { _fourFingerVertSwipeGesture = fourFingerVertSwipeGesture->isTrue(); setProperty("CypressFourFingerVertSwipeGesture", fourFingerVertSwipeGesture->isTrue()); } _fourFingerVertSwipeGesture = true; if (threeFingerDrag) { _threeFingerDrag = threeFingerDrag->isTrue(); setProperty("CypressThreeFingerDrag", threeFingerDrag->isTrue()); } _threeFingerDrag = true; if (twoFingerRightClick) { _twoFingerRightClick = twoFingerRightClick->isTrue(); setProperty("CypressTwoFingerRightClick", twoFingerRightClick->isTrue()); } if (fiveFingerScreenLock) { _fiveFingerScreenLock = fiveFingerScreenLock->isTrue(); setProperty("CypressFiveFingerScreenLock", fiveFingerScreenLock->isTrue()); } _fiveFingerScreenLock = true; if (fiveFingerSleep) { _fiveFingerSleep = fiveFingerSleep->isTrue(); setProperty("CypressFiveFingerSleep", fiveFingerSleep->isTrue()); } _fiveFingerSleep = true; if (fiveFingerSleepTimer) { _fivefingersleeptime = ((fiveFingerSleepTimer->unsigned32BitValue()) * 1000000); setProperty("Cypress5FingerSleepTimer", fiveFingerSleepTimer); } _fivefingersleeptime = 4 * 1000000; if (fiveFingerScreenLockTimer) { _fivefingerscreenlocktime = ((fiveFingerScreenLockTimer->unsigned32BitValue()) * 1000000); setProperty("Cypress5FingerScreenLockTimer", fiveFingerScreenLockTimer); } _fivefingerscreenlocktime = 1 * 1000000; return super::setParamProperties(dict); }