Skip to content

Commit

Permalink
Use device's revision values for caps tables, and device type 6
Browse files Browse the repository at this point in the history
Signed-off-by: Visual <[email protected]>
  • Loading branch information
VisualEhrmanntraut committed Apr 14, 2023
1 parent 3907aaf commit 3dc0c1c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
2 changes: 0 additions & 2 deletions NootedRed/kern_amd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,4 @@ struct DeviceCapabilityEntry {
const void *goldenRegisterSetings, *doorbellRange;
} PACKED;

constexpr uint64_t DEVICE_CAP_ENTRY_REV_DONT_CARE = 0xDEADCAFEU;

#endif /* kern_amd.hpp */
9 changes: 5 additions & 4 deletions NootedRed/kern_hwlibs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,21 @@ bool X5000HWLibs::processKext(KernelPatcher &patcher, size_t index, mach_vm_addr

PANIC_COND(MachInfo::setKernelWriting(true, KernelPatcher::kernelWriteLock) != KERN_SUCCESS, "hwlibs",
"Failed to enable kernel writing");
*orgDeviceTypeTable = {.deviceId = NRed::callback->deviceId, .deviceType = 0};
*orgDeviceTypeTable = {.deviceId = NRed::callback->deviceId, .deviceType = 6};
orgAsicInitCapsTable->familyId = orgAsicCapsTable->familyId = AMDGPU_FAMILY_RAVEN;
orgAsicInitCapsTable->deviceId = orgAsicCapsTable->deviceId = NRed::callback->deviceId;
orgAsicInitCapsTable->revision = orgAsicCapsTable->revision = NRed::callback->revision;
orgAsicInitCapsTable->emulatedRev = orgAsicCapsTable->emulatedRev =
static_cast<uint32_t>(NRed::callback->enumeratedRevision) + NRed::callback->revision;
orgAsicInitCapsTable->pciRev = orgAsicCapsTable->pciRev = 0xFFFFFFFF;
orgAsicInitCapsTable->pciRev = orgAsicCapsTable->pciRev = NRed::callback->pciRevision;
orgAsicInitCapsTable->caps = orgAsicCapsTable->caps = isRavenDerivative ? ddiCapsRaven : ddiCapsRenoir;
orgAsicInitCapsTable->goldenCaps =
goldenSettings[static_cast<uint32_t>(isRavenDerivative ? NRed::callback->chipType : ChipType::Renoir)];

deviceCapabilityTbl->familyId = AMDGPU_FAMILY_RAVEN;
deviceCapabilityTbl->deviceId = NRed::callback->deviceId;
deviceCapabilityTbl->internalRevision = deviceCapabilityTbl->externalRevision = DEVICE_CAP_ENTRY_REV_DONT_CARE;
deviceCapabilityTbl->internalRevision = NRed::callback->revision;
deviceCapabilityTbl->externalRevision = orgAsicInitCapsTable->emulatedRev;
auto capTblIndex = NRed::callback->chipType < ChipType::Raven2 ? 0 :
NRed::callback->chipType < ChipType::Renoir ? 1 :
2;
Expand Down Expand Up @@ -148,7 +149,7 @@ void X5000HWLibs::wrapPopulateFirmwareDirectory(void *that) {
auto *fw = callback->orgCreateFirmware(fwDesc.data, fwDesc.size, isRenoirDerivative ? 0x0202 : 0x0100, filename);
PANIC_COND(!fw, "hwlibs", "Failed to create '%s' firmware", filename);
DBGLOG("hwlibs", "Inserting %s!", filename);
PANIC_COND(!callback->orgPutFirmware(fwDir, 0, fw), "hwlibs", "Failed to inject %s firmware", filename);
PANIC_COND(!callback->orgPutFirmware(fwDir, 6, fw), "hwlibs", "Failed to inject %s firmware", filename);
}

void *X5000HWLibs::wrapCreatePowerTuneServices(void *that, void *param2) {
Expand Down
3 changes: 2 additions & 1 deletion NootedRed/kern_nred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ void NRed::processPatcher(KernelPatcher &patcher) {
static uint8_t builtin[] = {0x01};
this->iGPU->setProperty("built-in", builtin, arrsize(builtin));
this->deviceId = WIOKit::readPCIConfigValue(this->iGPU, WIOKit::kIOPCIConfigDeviceID);
auto *model = getBranding(this->deviceId, WIOKit::readPCIConfigValue(iGPU, WIOKit::kIOPCIConfigRevisionID));
this->pciRevision = WIOKit::readPCIConfigValue(NRed::callback->iGPU, WIOKit::kIOPCIConfigRevisionID);
auto *model = getBranding(this->deviceId, this->pciRevision);
if (model) {
auto len = static_cast<uint32_t>(strlen(model) + 1);
this->iGPU->setProperty("model", const_cast<char *>(model), len);
Expand Down
1 change: 1 addition & 0 deletions NootedRed/kern_nred.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class NRed {
uint32_t deviceId {0};
uint16_t enumeratedRevision {0};
uint16_t revision {0};
uint32_t pciRevision {0};
IOPCIDevice *iGPU {nullptr};
OSMetaClass *metaClassMap[4][2] = {{nullptr}};
mach_vm_address_t orgSafeMetaCast {0};
Expand Down
2 changes: 1 addition & 1 deletion NootedRed/kern_x6000fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool X6000FB::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_
orgAsicCapsTable->deviceId = NRed::callback->deviceId;
orgAsicCapsTable->revision = NRed::callback->revision;
orgAsicCapsTable->emulatedRev = NRed::callback->enumeratedRevision + NRed::callback->revision;
orgAsicCapsTable->pciRev = 0xFFFFFFFF;
orgAsicCapsTable->pciRev = NRed::callback->pciRevision;
MachInfo::setKernelWriting(false, KernelPatcher::kernelWriteLock);
DBGLOG("x6000fb", "Applied DDI Caps patches");

Expand Down

0 comments on commit 3dc0c1c

Please sign in to comment.