Skip to content

Commit

Permalink
refactor: Split code into multiple headers
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualEhrmanntraut committed Nov 12, 2024
1 parent 2ea3203 commit ab4f8eb
Show file tree
Hide file tree
Showing 43 changed files with 1,214 additions and 713 deletions.
190 changes: 179 additions & 11 deletions NootedRed.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions NootedRed/Backlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <Headers/kern_api.hpp>
#include <Headers/kern_devinfo.hpp>
#include <PrivateHeaders/Backlight.hpp>
#include <PrivateHeaders/GPUDriversAMD/DC/DPCD.hpp>
#include <PrivateHeaders/GPUDriversAMD/DC/SignalTypes.hpp>
#include <PrivateHeaders/NRed.hpp>
#include <PrivateHeaders/PatcherPlus.hpp>

Expand Down Expand Up @@ -301,15 +303,15 @@ void *Backlight::wrapLinkCreate(void *data) {

auto signalType = getMember<UInt32>(ret, 0x38);
switch (signalType) {
case DC_SIGNAL_TYPE_LVDS: {
case SIGNAL_TYPE_LVDS: {
if (singleton().embeddedPanelLink != nullptr) {
SYSLOG("Backlight", "EMBEDDED PANEL LINK WAS ALREADY SET AND DISCOVERED NEW ONE!!!!");
SYSLOG("Backlight", "REPORT THIS TO THE DEVELOPERS AS SOON AS POSSIBLE!!!!");
}
singleton().embeddedPanelLink = ret;
DBGLOG("Backlight", "Will use DMCU for display brightness control.");
}
case DC_SIGNAL_TYPE_EDP: {
case SIGNAL_TYPE_EDP: {
if (singleton().embeddedPanelLink != nullptr) {
SYSLOG("Backlight", "EMBEDDED PANEL LINK WAS ALREADY SET AND DISCOVERED NEW ONE!!!!");
SYSLOG("Backlight", "REPORT THIS TO THE DEVELOPERS AS SOON AS POSSIBLE!!!!");
Expand Down
32 changes: 21 additions & 11 deletions NootedRed/HWLibs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
// See LICENSE for details.

#include <Headers/kern_api.hpp>
#include <PrivateHeaders/AMDCommon.hpp>
#include <PrivateHeaders/Firmware.hpp>
#include <PrivateHeaders/GPUDriversAMD/CAIL/ASICCaps.hpp>
#include <PrivateHeaders/GPUDriversAMD/CAIL/DevCaps.hpp>
#include <PrivateHeaders/GPUDriversAMD/Driver.hpp>
#include <PrivateHeaders/GPUDriversAMD/Family.hpp>
#include <PrivateHeaders/GPUDriversAMD/PSP.hpp>
#include <PrivateHeaders/HWLibs.hpp>
#include <PrivateHeaders/NRed.hpp>
#include <PrivateHeaders/PatcherPlus.hpp>
#include <PrivateHeaders/iVega/GoldenSettings.hpp>
#include <PrivateHeaders/iVega/IPOffset.hpp>
#include <PrivateHeaders/iVega/Regs/SMU.hpp>
#include <PrivateHeaders/iVega/RenoirPPSMC.hpp>

//------ Target Kexts ------//

Expand Down Expand Up @@ -115,8 +123,8 @@ void X5000HWLibs::processKext(KernelPatcher &patcher, size_t id, mach_vm_address

CAILAsicCapsEntry *orgCapsTable;
CAILAsicCapsInitEntry *orgCapsInitTable;
CAILDeviceTypeEntry *orgDeviceTypeTable;
DeviceCapabilityEntry *orgDevCapTable;
AMDDeviceTypeEntry *orgDeviceTypeTable;
AMDDeviceCapabilities *orgDevCapTable;

if (NRed::singleton().getAttributes().isCatalina()) {
orgDeviceTypeTable = nullptr;
Expand Down Expand Up @@ -206,31 +214,33 @@ void X5000HWLibs::processKext(KernelPatcher &patcher, size_t id, mach_vm_address

PANIC_COND(MachInfo::setKernelWriting(true, KernelPatcher::kernelWriteLock) != KERN_SUCCESS, "HWLibs",
"Failed to enable kernel writing");
if (orgDeviceTypeTable) { *orgDeviceTypeTable = {.deviceId = NRed::singleton().getDeviceID(), .deviceType = 6}; }
if (orgDeviceTypeTable) {
*orgDeviceTypeTable = {.deviceId = NRed::singleton().getDeviceID(), .deviceType = kAMDDeviceTypeNavi21};
}

auto targetDeviceId = NRed::singleton().getAttributes().isRenoir() ? 0x1636 : NRed::singleton().getDeviceID();
for (; orgCapsInitTable->deviceId != 0xFFFFFFFF; orgCapsInitTable++) {
if (orgCapsInitTable->familyId == AMDGPU_FAMILY_RAVEN && orgCapsInitTable->deviceId == targetDeviceId) {
if (orgCapsInitTable->familyId == AMD_FAMILY_RAVEN && orgCapsInitTable->deviceId == targetDeviceId) {
orgCapsInitTable->deviceId = NRed::singleton().getDeviceID();
orgCapsInitTable->revision = NRed::singleton().getDevRevision();
orgCapsInitTable->extRevision =
static_cast<UInt64>(NRed::singleton().getEnumRevision()) + NRed::singleton().getDevRevision();
orgCapsInitTable->pciRevision = NRed::singleton().getPciRevision();
*orgCapsTable = {
.familyId = AMDGPU_FAMILY_RAVEN,
.familyId = AMD_FAMILY_RAVEN,
.deviceId = NRed::singleton().getDeviceID(),
.revision = NRed::singleton().getDevRevision(),
.extRevision =
static_cast<UInt32>(NRed::singleton().getEnumRevision()) + NRed::singleton().getDevRevision(),
.pciRevision = NRed::singleton().getPciRevision(),
.caps = orgCapsInitTable->caps,
.ddiCaps = orgCapsInitTable->ddiCaps,
};
break;
}
}
PANIC_COND(orgCapsInitTable->deviceId == 0xFFFFFFFF, "HWLibs", "Failed to find init caps table entry");
for (; orgDevCapTable->familyId; orgDevCapTable++) {
if (orgDevCapTable->familyId == AMDGPU_FAMILY_RAVEN && orgDevCapTable->deviceId == targetDeviceId) {
if (orgDevCapTable->familyId == AMD_FAMILY_RAVEN && orgDevCapTable->deviceId == targetDeviceId) {
orgDevCapTable->deviceId = NRed::singleton().getDeviceID();
orgDevCapTable->extRevision =
static_cast<UInt64>(NRed::singleton().getEnumRevision()) + NRed::singleton().getDevRevision();
Expand Down Expand Up @@ -350,7 +360,7 @@ void X5000HWLibs::wrapPopulateFirmwareDirectory(void *that) {
auto *fw = singleton().orgCreateFirmware(vcnFW.data, vcnFW.length,
NRed::singleton().getAttributes().isRenoir() ? 0x0202 : 0x0100, filename);
PANIC_COND(fw == nullptr, "HWLibs", "Failed to create '%s' firmware", filename);
PANIC_COND(!singleton().orgPutFirmware(singleton().fwDirField.get(that), 6, fw), "HWLibs",
PANIC_COND(!singleton().orgPutFirmware(singleton().fwDirField.get(that), kAMDDeviceTypeNavi21, fw), "HWLibs",
"Failed to insert '%s' firmware", filename);
}

Expand Down Expand Up @@ -570,14 +580,14 @@ CAILResult X5000HWLibs::smu10InternalHwInit(void *) {

CAILResult X5000HWLibs::smu12InternalHwInit(void *) {
UInt32 i = 0;
for (; i < AMDGPU_MAX_USEC_TIMEOUT; i++) {
for (; i < AMD_MAX_USEC_TIMEOUT; i++) {
if (NRed::singleton().readReg32(MP1_Public | smnMP1_FIRMWARE_FLAGS) &
smnMP1_FIRMWARE_FLAGS_INTERRUPTS_ENABLED) {
break;
}
IOSleep(1);
}
if (i >= AMDGPU_MAX_USEC_TIMEOUT) { return kCAILResultFailed; }
if (i >= AMD_MAX_USEC_TIMEOUT) { return kCAILResultFailed; }

auto res = smuReset();
if (res != kCAILResultSuccess) { return res; }
Expand Down
8 changes: 6 additions & 2 deletions NootedRed/NRed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <Headers/kern_devinfo.hpp>
#include <Headers/kern_iokit.hpp>
#include <IOKit/acpi/IOACPIPlatformExpert.h>
#include <PrivateHeaders/AMDCommon.hpp>
#include <PrivateHeaders/AppleGFXHDA.hpp>
#include <PrivateHeaders/Backlight.hpp>
#include <PrivateHeaders/Firmware.hpp>
#include <PrivateHeaders/GPUDriversAMD/Driver.hpp>
#include <PrivateHeaders/HWLibs.hpp>
#include <PrivateHeaders/Hotfixes/AGDP.hpp>
#include <PrivateHeaders/Hotfixes/X6000FB.hpp>
Expand All @@ -18,6 +18,10 @@
#include <PrivateHeaders/X5000.hpp>
#include <PrivateHeaders/X6000.hpp>
#include <PrivateHeaders/X6000FB.hpp>
#include <PrivateHeaders/iVega/IPOffset.hpp>
#include <PrivateHeaders/iVega/Regs/GC.hpp>
#include <PrivateHeaders/iVega/Regs/NBIO.hpp>
#include <PrivateHeaders/iVega/Regs/SMU.hpp>

//------ Module Logic ------//

Expand Down Expand Up @@ -271,7 +275,7 @@ void NRed::writeReg32(UInt32 reg, UInt32 val) const {

UInt32 NRed::smuWaitForResponse() const {
UInt32 ret = AMDSMUFWResponse::kSMUFWResponseNoResponse;
for (UInt32 i = 0; i < AMDGPU_MAX_USEC_TIMEOUT; i++) {
for (UInt32 i = 0; i < AMD_MAX_USEC_TIMEOUT; i++) {
ret = this->readReg32(MP_BASE + mmMP1_SMN_C2PMSG_90);
if (ret != AMDSMUFWResponse::kSMUFWResponseNoResponse) { break; }

Expand Down
Loading

0 comments on commit ab4f8eb

Please sign in to comment.