void * IOBufferMemoryDescriptor::getVirtualSegment(IOByteCount offset, IOByteCount * lengthOfSegment) { void * bytes = getBytesNoCopy(offset, 0); if (bytes && lengthOfSegment) *lengthOfSegment = _length - offset; return bytes; }
bool getOSDataValue(const OSObject *obj, const char *name, T &value) { if (obj) { auto data = OSDynamicCast(OSData, obj); if (data && data->getLength() == sizeof(T)) { value = *static_cast<const T *>(data->getBytesNoCopy()); DBGLOG("iokit", "getOSData %s has %llX value", name, static_cast<uint64_t>(value)); return true; } else { SYSLOG("iokit", "getOSData %s has unexpected format", name); } } else { DBGLOG("iokit", "getOSData %s was not found", name); } return false; }
bool getOSDataValue(IORegistryEntry *sect, const char *name, T &value) { auto obj = sect->getProperty(name); if (obj) { auto data = OSDynamicCast(OSData, obj); if (data && data->getLength() == sizeof(T)) { value = *static_cast<const T *>(data->getBytesNoCopy()); DBGLOG("util @ getOSData %s has %llX value", name, static_cast<uint64_t>(value)); return true; } else { SYSLOG("util @ getOSData %s has unexpected format", name); } } else { DBGLOG("util @ getOSData %s was not found", name); } return false;; }
int getComputerModel() { auto entry = IORegistryEntry::fromPath("/", gIODTPlane); if (entry) { auto prop = entry->getProperty("compatible"); if (prop) { auto data = OSDynamicCast(OSData, prop); if (data) { //TODO: make this more reliable if (strstr(static_cast<const char *>(data->getBytesNoCopy()), "Book", strlen("Book"))) { return ComputerModel::ComputerLaptop; } else { return ComputerModel::ComputerDesktop; } } else { DBGLOG("iokit @ compatible property has invalid format"); } } else { DBGLOG("iokit @ failed to get compatible property"); } } DBGLOG("iokit @ failed to get DT entry"); return ComputerModel::ComputerAny; }
bool AlcEnabler::grabCodecs() { if (!that) { SYSLOG("alc @ you should call grabCodecs right before AppleHDA loading"); return false; } for (size_t lookup = 0; lookup < codecLookupSize; lookup++) { that->tmpLayout = -1; // Not using recursive lookup due to multiple possible entries auto sect = IOUtil::findEntryByPrefix("/AppleACPIPlatformExpert", "PCI", gIOServicePlane); size_t i {0}; while (sect && i < codecLookup[lookup].treeSize) { sect = IOUtil::findEntryByPrefix(sect, codecLookup[lookup].tree[i], gIOServicePlane, i+1 == codecLookup[lookup].treeSize ? [](IORegistryEntry *e) { if (that->tmpLayout < 0) { SYSLOG("alc @ invalid layout-id was previously found %d", that->tmpLayout); return; } auto ven = e->getProperty("IOHDACodecVendorID"); auto rev = e->getProperty("IOHDACodecRevisionID"); if (!ven || !rev) { SYSLOG("alc @ codec entry misses properties, skipping"); return; } auto venNum = OSDynamicCast(OSNumber, ven); auto revNum = OSDynamicCast(OSNumber, rev); if (!venNum || !revNum) { SYSLOG("alc @ codec entry contains invalid properties, skipping"); return; } auto ci = AlcEnabler::CodecInfo::create(venNum->unsigned64BitValue(), revNum->unsigned32BitValue(), that->tmpLayout); if (ci) { if (!that->codecs.push_back(ci)) { SYSLOG("alc @ failed to store codec info for %X %X", ci->vendor, ci->codec); AlcEnabler::CodecInfo::deleter(ci); } } else { SYSLOG("alc @ failed to create codec info for %X %X", ci->vendor, ci->codec); } } : nullptr); if (i == codecLookup[lookup].layoutNum) { if (sect) { auto lid = sect->getProperty("layout-id"); if (lid) { auto lidNum = OSDynamicCast(OSData, lid); if (lidNum && lidNum->getLength() > 0) { tmpLayout = static_cast<const uint8_t *>(lidNum->getBytesNoCopy())[0]; DBGLOG("alc @ found layout-id %d in %s", tmpLayout, codecLookup[lookup].tree[i]); i++; continue; } else { SYSLOG("alc @ %s contains invalid layout-id", codecLookup[lookup].tree[i]); } } } SYSLOG("alc @ no layout found in %s, aborting", codecLookup[lookup].tree[i]); break; } i++; } } return validateCodecs(); }