Recover changes
This commit is contained in:
@@ -29,6 +29,10 @@
|
||||
#include <switch.h>
|
||||
#include <pwm.h>
|
||||
#include <registers.h>
|
||||
#include <battery.h>
|
||||
#include <display_refresh_rate.h>
|
||||
#include <rgltr.h>
|
||||
#include <notification.h>
|
||||
|
||||
#include "board.hpp"
|
||||
#include "board_fuse.hpp"
|
||||
@@ -41,14 +45,15 @@ namespace board {
|
||||
SysClkSocType gSocType;
|
||||
u8 gDramID;
|
||||
HorizonOCConsoleType gConsoleType = HorizonOCConsoleType_Iowa;
|
||||
FuseSpeedoData gSpeedos;
|
||||
FuseData fuseData;
|
||||
u8 speedoBracket;
|
||||
Result nvCheck = 1;
|
||||
u23 fd = 0, fd2 = 0;
|
||||
PwmChannelSession iCon;
|
||||
|
||||
u32 fd = 0, fd2 = 0;
|
||||
|
||||
void FetchHardwareInfos() {
|
||||
FuseReadSpeedos(gSpeedos);
|
||||
FuseSetGpuBracket(gSpeedos.gpuSpeedo, speedoBracket);
|
||||
ReadFuses(fuseData);
|
||||
SetGpuBracket(fuseData.gpuSpeedo, speedoBracket);
|
||||
|
||||
u64 sku = 0, dramID = 0;
|
||||
Result rc = splInitialize();
|
||||
@@ -74,8 +79,7 @@ namespace board {
|
||||
CacheGpuVoltTable();
|
||||
}
|
||||
|
||||
gConsoleType = static_cast<HorizonOCConsoleType> sku;
|
||||
g_dramID = dramID;
|
||||
gConsoleType = static_cast<HorizonOCConsoleType>(sku);
|
||||
}
|
||||
|
||||
/* TODO: Check for config */
|
||||
@@ -90,6 +94,12 @@ namespace board {
|
||||
ASSERT_RESULT_OK(rc, "pcvInitialize");
|
||||
}
|
||||
|
||||
rc = apmExtInitialize();
|
||||
ASSERT_RESULT_OK(rc, "apmExtInitialize");
|
||||
|
||||
rc = psmInitialize();
|
||||
ASSERT_RESULT_OK(rc, "psmInitialize");
|
||||
|
||||
if(HOSSVC_HAS_TC) {
|
||||
rc = tcInitialize();
|
||||
ASSERT_RESULT_OK(rc, "tcInitialize");
|
||||
@@ -101,10 +111,16 @@ namespace board {
|
||||
rc = tmp451Initialize();
|
||||
ASSERT_RESULT_OK(rc, "tmp451Initialize");
|
||||
|
||||
nvInitialize_rc = nvInitialize();
|
||||
if (R_SUCCEEDED(nvInitialize_rc)) {
|
||||
Result nvCheck = 1;
|
||||
if (R_SUCCEEDED(nvInitialize())) {
|
||||
nvCheck = nvOpen(&fd, "/dev/nvhost-ctrl-gpu");
|
||||
nvCheck_sched = nvOpen(&fd2, "/dev/nvsched-ctrl");
|
||||
Result nvCheck_sched = nvOpen(&fd2, "/dev/nvsched-ctrl");
|
||||
/* This can be improved. */
|
||||
NvSchedSucceed(nvCheck_sched);
|
||||
|
||||
if (R_SUCCEEDED(nvCheck_sched)) {
|
||||
SchedSetFD2(fd2);
|
||||
}
|
||||
}
|
||||
|
||||
rc = rgltrInitialize();
|
||||
@@ -113,19 +129,17 @@ namespace board {
|
||||
rc = pmdmntInitialize();
|
||||
ASSERT_RESULT_OK(rc, "pmdmntInitialize");
|
||||
|
||||
StartGpuLoad(nvCheck, fd);
|
||||
|
||||
StartMiscThread(pwmCheck)
|
||||
StartLoad(nvCheck, fd);
|
||||
|
||||
batteryInfoInitialize();
|
||||
FetchHardwareInfos();
|
||||
|
||||
Result pwmCheck = 1;
|
||||
if (hosversionAtLeast(6,0,0) && R_SUCCEEDED(pwmInitialize())) {
|
||||
pwmCheck = pwmOpenSession2(&g_ICon, 0x3D000001);
|
||||
pwmCheck = pwmOpenSession2(&iCon, 0x3D000001);
|
||||
}
|
||||
|
||||
StartMiscThread(pwmCheck);
|
||||
StartMiscThread(pwmCheck, &iCon);
|
||||
|
||||
if (gConsoleType != HorizonOCConsoleType_Hoag) {
|
||||
u64 clkVirtAddr, dsiVirtAddr, outsize;
|
||||
@@ -164,7 +178,7 @@ namespace board {
|
||||
|
||||
ExitMiscThread();
|
||||
|
||||
pwmChannelSessionClose(&g_ICon);
|
||||
pwmChannelSessionClose(&iCon);
|
||||
pwmExit();
|
||||
rgltrExit();
|
||||
batteryInfoExit();
|
||||
@@ -185,7 +199,7 @@ namespace board {
|
||||
}
|
||||
|
||||
u8 GetDramID() {
|
||||
return dramID;
|
||||
return gDramID;
|
||||
}
|
||||
|
||||
bool IsDram8GB() {
|
||||
@@ -209,4 +223,16 @@ namespace board {
|
||||
}
|
||||
}
|
||||
|
||||
FuseData *GetFuseData() {
|
||||
return &fuseData;
|
||||
}
|
||||
|
||||
u8 GetGpuSpeedoBracket() {
|
||||
return speedoBracket;
|
||||
}
|
||||
|
||||
bool IsUsingRetroSuperDisplay() {
|
||||
return false; /* stub for now. */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
#include <sysclk.h>
|
||||
#include "board_fuse.hpp"
|
||||
#include "board_load.hpp"
|
||||
#include "board_name.hpp"
|
||||
#include "board_freq.hpp"
|
||||
#include "board_sensor.hpp"
|
||||
#include "board_volt.hpp"
|
||||
#include "board_profile.hpp"
|
||||
|
||||
#define HOSSVC_HAS_CLKRST (hosversionAtLeast(8,0,0))
|
||||
#define HOSSVC_HAS_TC (hosversionAtLeast(5,0,0))
|
||||
@@ -38,7 +46,10 @@ namespace board {
|
||||
SysClkSocType GetSocType();
|
||||
HorizonOCConsoleType GetConsoleType();
|
||||
u8 GetDramID();
|
||||
u8 GetGpuSpeedoBracket();
|
||||
bool IsDram8GB();
|
||||
void SetDisplayRefreshDockedState(bool docked);
|
||||
FuseData *GetFuseData();
|
||||
bool IsUsingRetroSuperDisplay();
|
||||
|
||||
}
|
||||
|
||||
@@ -27,20 +27,13 @@
|
||||
#include <switch.h>
|
||||
#include <sysclk.h>
|
||||
#include <nxExt.h>
|
||||
#include <display_refresh_rate.h>
|
||||
#include "board.hpp"
|
||||
#include "board_name.hpp"
|
||||
#include "../error.h"
|
||||
#include "../errors.h"
|
||||
|
||||
namespace board {
|
||||
|
||||
PcvModuleId GetPcvModuleId(SysClkModule sysclkModule) {
|
||||
PcvModuleId pcvModuleId;
|
||||
Result rc = pcvGetModuleId(&pcvModuleId, GetPcvModule(sysclkModule));
|
||||
ASSERT_RESULT_OK(rc, "pcvGetModuleId");
|
||||
|
||||
return pcvModuleId;
|
||||
}
|
||||
|
||||
PcvModule GetPcvModule(SysClkModule sysclkModule) {
|
||||
switch (sysclkModule) {
|
||||
case SysClkModule_CPU:
|
||||
@@ -53,14 +46,22 @@ namespace board {
|
||||
ASSERT_ENUM_VALID(SysClkModule, sysclkModule);
|
||||
}
|
||||
|
||||
return (PcvModule)0;
|
||||
return static_cast<PcvModule>(0);
|
||||
}
|
||||
|
||||
PcvModuleId GetPcvModuleId(SysClkModule sysclkModule) {
|
||||
PcvModuleId pcvModuleId;
|
||||
Result rc = pcvGetModuleId(&pcvModuleId, GetPcvModule(sysclkModule));
|
||||
ASSERT_RESULT_OK(rc, "pcvGetModuleId");
|
||||
|
||||
return pcvModuleId;
|
||||
}
|
||||
|
||||
void ClkrstSetHz(ClkrstSession &session, u32 hz) {
|
||||
ASSERT_RESULT_OK(clkrstSetClockRate(&session, hz), "clkrstSetClockRate");
|
||||
}
|
||||
|
||||
void PcvSetHz(PcvModuleId moduleID, u32 hz) {
|
||||
void PcvSetHz(PcvModule moduleID, u32 hz) {
|
||||
ASSERT_RESULT_OK(pcvSetClockRate(moduleID, hz), "pcvSetClockRate");
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ namespace board {
|
||||
|
||||
/* Voltage bug workaround. */
|
||||
if (module == SysClkModule_CPU) {
|
||||
svcSleepThread(200'000);
|
||||
svcSleepThread(250'000);
|
||||
ClkrstSetHz(session, hz);
|
||||
}
|
||||
|
||||
@@ -95,7 +96,7 @@ namespace board {
|
||||
PcvSetHz(GetPcvModule(module), hz);
|
||||
|
||||
if (module == SysClkModule_CPU) {
|
||||
svcSleepThread(200'000);
|
||||
svcSleepThread(250'000);
|
||||
PcvSetHz(GetPcvModule(module), hz);
|
||||
}
|
||||
}
|
||||
@@ -114,7 +115,7 @@ namespace board {
|
||||
u32 hz = 0;
|
||||
|
||||
if (module == HorizonOCModule_Display) {
|
||||
return GetDisplayRate();
|
||||
return GetDisplayRate(hz);
|
||||
}
|
||||
|
||||
if (HOSSVC_HAS_CLKRST) {
|
||||
@@ -145,7 +146,7 @@ namespace board {
|
||||
case SysClkModule_MEM:
|
||||
return t210ClkMemFreq();
|
||||
case HorizonOCModule_Display:
|
||||
return GetDisplayRate();
|
||||
return GetDisplayRate(hz);
|
||||
return hz;
|
||||
default:
|
||||
ASSERT_ENUM_VALID(SysClkModule, module);
|
||||
@@ -192,6 +193,7 @@ namespace board {
|
||||
}
|
||||
|
||||
void ResetToStock() {
|
||||
Result rc;
|
||||
if (hosversionAtLeast(9,0,0)) {
|
||||
std::uint32_t confId = 0;
|
||||
rc = apmExtGetCurrentPerformanceConfiguration(&confId);
|
||||
@@ -223,7 +225,7 @@ namespace board {
|
||||
}
|
||||
|
||||
void ResetToStockDisplay() {
|
||||
if (GetConsoleType != HorizonOCConsoleType_Hoag) {
|
||||
if (GetConsoleType() != HorizonOCConsoleType_Hoag) {
|
||||
DisplayRefresh_SetRate(60);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <switch.h>
|
||||
#include <sysclk.h>
|
||||
#include <nxExt.h>
|
||||
#include "../errors.h"
|
||||
|
||||
namespace board {
|
||||
|
||||
@@ -35,7 +36,7 @@ namespace board {
|
||||
|
||||
u32 GetHz(SysClkModule module);
|
||||
u32 GetRealHz(SysClkModule module);
|
||||
u32 GetFreqList(SysClkModule module, u32 *outList, u32 maxCount, u32 *outCount);
|
||||
void GetFreqList(SysClkModule module, u32 *outList, u32 maxCount, u32 *outCount);
|
||||
u32 GetHighestDockedDisplayRate();
|
||||
|
||||
void ResetToStock();
|
||||
|
||||
@@ -25,24 +25,12 @@
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <fuse.h>
|
||||
#include "board_fuse.hpp"
|
||||
#include <cstring>
|
||||
|
||||
namespace board {
|
||||
|
||||
namespace {
|
||||
constexpr u32 FuseCpuSpeedoCalib = 0x114;
|
||||
// constexpr u32 FuseCpuSpeedo1Calib = 0x12C;
|
||||
constexpr u32 FuseGpuSpeedoCalib = 0x130;
|
||||
|
||||
constexpr u32 FuseSocSpeedoCalib = 0x134;
|
||||
// constexpr u32 FuseSocSpeedo1Calib = 0x138;
|
||||
// constexpr u32 FuseSocSpeedo2Calib = 0x13C;
|
||||
|
||||
constexpr u32 FuseCpuIddqCalib = 0x118;
|
||||
constexpr u32 FuseSocIddqCalib = 0x140;
|
||||
constexpr u32 FuseGpuIddqCalib = 0x228;
|
||||
}
|
||||
|
||||
void SetGpuBracket(u8 speedo, u8 &gpuBracket) {
|
||||
if (speedo <= 1624) {
|
||||
gpuBracket = 0;
|
||||
@@ -63,7 +51,7 @@ namespace board {
|
||||
gpuBracket = 3;
|
||||
}
|
||||
|
||||
FuseReadSpeedo(FuseSpeedoData &speedo) {
|
||||
void ReadFuses(FuseData &speedo) {
|
||||
u64 pid = 0;
|
||||
constexpr u64 UsbID = 0x0100000000000006;
|
||||
if (R_FAILED(pmdmntGetProcessId(&pid, UsbID))) {
|
||||
@@ -99,12 +87,15 @@ namespace board {
|
||||
break;
|
||||
}
|
||||
|
||||
speedo.cpuSpeedo = *reinterpret_cast<u16*>(dump + FuseCpuSpeedoCalib);
|
||||
speedo.gpuSpeedo = *reinterpret_cast<u16*>(dump + FuseGpuSpeedoCalib);
|
||||
speedo.socSpeedo = *reinterpret_cast<u16*>(dump + FuseSocSpeedoCalib);
|
||||
speedo.cpuIDDQ = *reinterpret_cast<u16*>(dump + FuseCpuIddqCalib);
|
||||
speedo.gpuIDDQ = *reinterpret_cast<u16*>(dump + FuseSocIddqCalib);
|
||||
speedo.socIDDQ = *reinterpret_cast<u16*>(dump + FUSE_GPU_IDDQ_CALIB);
|
||||
speedo.cpuSpeedo = *reinterpret_cast<u16*>(dump + FUSE_CPU_SPEEDO_0_CALIB);
|
||||
speedo.gpuSpeedo = *reinterpret_cast<u16*>(dump + FUSE_CPU_SPEEDO_2_CALIB);
|
||||
speedo.socSpeedo = *reinterpret_cast<u16*>(dump + FUSE_SOC_SPEEDO_0_CALIB);
|
||||
|
||||
speedo.cpuIDDQ = *reinterpret_cast<u16*>(dump + FUSE_CPU_IDDQ_CALIB) * 4;
|
||||
speedo.gpuIDDQ = *reinterpret_cast<u16*>(dump + FUSE_GPU_IDDQ_CALIB) * 5;
|
||||
speedo.socIDDQ = *reinterpret_cast<u16*>(dump + FUSE_SOC_IDDQ_CALIB) * 4;
|
||||
speedo.waferX = *reinterpret_cast<u16*>(dump + FUSE_OPT_X_COORDINATE);
|
||||
speedo.waferY = *reinterpret_cast<u16*>(dump + FUSE_OPT_Y_COORDINATE);
|
||||
|
||||
svcCloseHandle(debug);
|
||||
return;
|
||||
|
||||
@@ -24,11 +24,13 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
namespace board {
|
||||
|
||||
struct FuseSpeedoData {
|
||||
struct FuseData {
|
||||
u16 cpuSpeedo;
|
||||
u16 gpuSpeedo;
|
||||
u16 socSpeedo;
|
||||
@@ -36,9 +38,12 @@ namespace board {
|
||||
u16 cpuIDDQ;
|
||||
u16 gpuIDDQ;
|
||||
u16 socIDDQ;
|
||||
|
||||
u16 waferX;
|
||||
u16 waferY;
|
||||
};
|
||||
|
||||
FuseReadSpeedo(FuseSpeedoData speedo);
|
||||
FuseSetGpuBracket(u8 gpuSpeedo, u8 &gpuBracket);
|
||||
void ReadFuses(FuseData &speedo);
|
||||
void SetGpuBracket(u8 gpuSpeedo, u8 &gpuBracket);
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,10 @@
|
||||
#include <algorithm>
|
||||
#include <math.h>
|
||||
#include <numeric>
|
||||
#include "board_misc.hpp"
|
||||
#include <minIni.h>
|
||||
#include <battery.h>
|
||||
#include "board_misc.hpp"
|
||||
#include "board.hpp"
|
||||
|
||||
namespace board {
|
||||
|
||||
@@ -42,7 +44,8 @@ namespace board {
|
||||
Thread cpuCore2Thread;
|
||||
|
||||
u32 gpuLoad;
|
||||
u32 _fd;
|
||||
u32 _fd, _fd2;
|
||||
Result nvCheckSched;
|
||||
|
||||
u64 idletick0 = 0;
|
||||
u64 idletick1 = 0;
|
||||
@@ -61,8 +64,8 @@ namespace board {
|
||||
if (R_SUCCEEDED(nvCheck)) do {
|
||||
u32 temp;
|
||||
if (R_SUCCEEDED(nvIoctl(_fd, NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD, &temp))) {
|
||||
gpu_load_array[i++ % gpu_samples_average] = temp;
|
||||
gpuLoad = std::accumulate(&gpu_load_array[0], &gpu_load_array[gpu_samples_average], 0) / gpu_samples_average;
|
||||
gpu_load_array[i++ % GpuSamples] = temp;
|
||||
gpuLoad = std::accumulate(&gpu_load_array[0], &gpu_load_array[GpuSamples], 0) / GpuSamples;
|
||||
}
|
||||
svcSleepThread(16'666'000); // wait a bit (this is the perfect amount of time to keep the reading accurate)
|
||||
} while(true);
|
||||
@@ -80,10 +83,10 @@ namespace board {
|
||||
}
|
||||
}
|
||||
|
||||
void StartLoad() {
|
||||
void StartLoad(Result nvCheck, u32 fd) {
|
||||
_fd = fd;
|
||||
threadCreate(&gpuThread, GpuLoadThread, &nvCheck, NULL, 0x1000, 0x3F, -2);
|
||||
threadStart(&gpuThread)
|
||||
threadStart(&gpuThread);
|
||||
|
||||
leventClear(&threadexit);
|
||||
threadCreate(&cpuCore0Thread, CheckCore, &idletick0, NULL, 0x1000, 0x10, 0);
|
||||
@@ -136,7 +139,7 @@ namespace board {
|
||||
constexpr u32 NVschedCtrlDisable = 0x00000602;
|
||||
}
|
||||
|
||||
void SetGpuSchedulingMode(GpuSchedulingMode mode, GpuSchedulingOverrideMethod method, Result nvCheckSched, u32 fd2) {
|
||||
void SetGpuSchedulingMode(GpuSchedulingMode mode, GpuSchedulingOverrideMethod method) {
|
||||
if (R_FAILED(nvCheckSched) && method == GpuSchedulingOverrideMethod_NvService) {
|
||||
return;
|
||||
}
|
||||
@@ -147,14 +150,14 @@ namespace board {
|
||||
case GpuSchedulingMode_DoNotOverride: break;
|
||||
case GpuSchedulingMode_Disabled:
|
||||
if (method == GpuSchedulingOverrideMethod_NvService) {
|
||||
nvIoctl(fd2, NVschedCtrlDisable, &temp);
|
||||
nvIoctl(_fd2, NVschedCtrlDisable, &temp);
|
||||
} else {
|
||||
enabled = false;
|
||||
}
|
||||
break;
|
||||
case GpuSchedulingMode_Enabled:
|
||||
if (method == GpuSchedulingOverrideMethod_NvService) {
|
||||
nvIoctl(fd2, NVschedCtrlEnable, &temp);
|
||||
nvIoctl(_fd2, NVschedCtrlEnable, &temp);
|
||||
} else {
|
||||
enabled = true;
|
||||
}
|
||||
@@ -174,4 +177,12 @@ namespace board {
|
||||
}
|
||||
}
|
||||
|
||||
void SchedSetFD2(u32 fd2) {
|
||||
_fd2 = fd2;
|
||||
}
|
||||
|
||||
void NvSchedSucceed(Result nvSched) {
|
||||
nvCheckSched = nvSched;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,12 +26,15 @@
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <sysclk.h>
|
||||
|
||||
namespace board {
|
||||
|
||||
void StartLoad(Result nvCheck, u32 fd);
|
||||
void ExitLoad();
|
||||
u32 GetPartLoad();
|
||||
void SetGpuSchedulingMode(GpuSchedulingMode mode, GpuSchedulingOverrideMethod method, Result nvCheckSched, u32 fd2);
|
||||
u32 GetPartLoad(SysClkPartLoad loadSource);
|
||||
void SetGpuSchedulingMode(GpuSchedulingMode mode, GpuSchedulingOverrideMethod method);
|
||||
void SchedSetFD2(u32 fd2);
|
||||
void NvSchedSucceed(Result nvSched);
|
||||
|
||||
}
|
||||
|
||||
@@ -25,11 +25,15 @@
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <pwm.h>
|
||||
#include <cmath>
|
||||
#include <rgltr.h>
|
||||
|
||||
namespace board {
|
||||
|
||||
Thread miscThread;
|
||||
u8 fanLevel = 0;
|
||||
PwmChannelSession *_iCon;
|
||||
|
||||
void MiscThreadFunc(void *pwmCheckPtr) {
|
||||
Result pwmCheck = *static_cast<Result *>(pwmCheckPtr);
|
||||
@@ -38,7 +42,7 @@ namespace board {
|
||||
|
||||
while (true) {
|
||||
if (R_SUCCEEDED(pwmCheck)) {
|
||||
if (R_SUCCEEDED(pwmChannelSessionGetDutyCycle(&g_ICon, &temp))) {
|
||||
if (R_SUCCEEDED(pwmChannelSessionGetDutyCycle(_iCon, &temp))) {
|
||||
temp *= 10;
|
||||
temp = trunc(temp);
|
||||
temp /= 10;
|
||||
@@ -46,7 +50,7 @@ namespace board {
|
||||
}
|
||||
}
|
||||
|
||||
fanLevel = static_cast<u8>(Rotation_Duty);
|
||||
fanLevel = static_cast<u8>(rotationDuty);
|
||||
svcSleepThread(300'000'000);
|
||||
}
|
||||
}
|
||||
@@ -55,7 +59,8 @@ namespace board {
|
||||
return fanLevel;
|
||||
}
|
||||
|
||||
void StartMiscThread(Result pwmCheck) {
|
||||
void StartMiscThread(Result pwmCheck, PwmChannelSession *iCon) {
|
||||
_iCon = iCon;
|
||||
threadCreate(&miscThread, MiscThreadFunc, &pwmCheck, NULL, 0x1000, 0x10, 3);
|
||||
threadStart(&miscThread);
|
||||
}
|
||||
|
||||
@@ -28,10 +28,11 @@
|
||||
|
||||
#include <switch.h>
|
||||
#include <sysclk.h>
|
||||
#include <pwm.h>
|
||||
|
||||
namespace board {
|
||||
|
||||
void StartMiscThread(Result pwmCheck);
|
||||
void StartMiscThread(Result pwmCheck, PwmChannelSession *iCon);
|
||||
void ExitMiscThread();
|
||||
u8 GetFanLevel();
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <switch.h>
|
||||
#include <sysclk.h>
|
||||
#include "board.hpp"
|
||||
|
||||
namespace board {
|
||||
|
||||
@@ -44,4 +45,9 @@ namespace board {
|
||||
return sysclkFormatThermalSensor(sensor, pretty);
|
||||
}
|
||||
|
||||
const char *GetPowerSensorName(SysClkPowerSensor sensor, bool pretty) {
|
||||
ASSERT_ENUM_VALID(SysClkPowerSensor, sensor);
|
||||
return sysclkFormatPowerSensor(sensor, pretty);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,5 +33,6 @@ namespace board {
|
||||
const char *GetModuleName(SysClkModule module, bool pretty);
|
||||
const char *GetProfileName(SysClkProfile profile, bool pretty);
|
||||
const char *GetThermalSensorName(SysClkThermalSensor sensor, bool pretty);
|
||||
const char *GetPowerSensorName(SysClkPowerSensor sensor, bool pretty);
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <switch.h>
|
||||
#include <sysclk.h>
|
||||
#include <nxExt.h>
|
||||
#include "board.hpp"
|
||||
|
||||
namespace board {
|
||||
|
||||
|
||||
@@ -24,17 +24,19 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <sysclk.h>
|
||||
#include <switch.h>
|
||||
#include <nxExt.h>
|
||||
#include <cmath.h>
|
||||
#include <cmath>
|
||||
#include <battery.h>
|
||||
#include <pwm.h>
|
||||
#include "board.hpp"
|
||||
|
||||
namespace board {
|
||||
|
||||
u32 GetTemperatureMilli(SysClkThermalSensor sensor) {
|
||||
u32 millis = 0;
|
||||
s32 millis = 0;
|
||||
BatteryChargeInfo info;
|
||||
|
||||
if (sensor == SysClkThermalSensor_SOC) {
|
||||
millis = tmp451TempSoc();
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include <memmem.h>
|
||||
#include <registers.h>
|
||||
#include <cstring>
|
||||
#include <rgltr.h>
|
||||
#include <battery.h>
|
||||
#include "board.hpp"
|
||||
#include "board_freq.hpp"
|
||||
#include "board_volt.hpp"
|
||||
@@ -45,14 +47,14 @@ namespace board {
|
||||
struct EristaCpuUvEntry {
|
||||
u32 tune0;
|
||||
u32 tune1;
|
||||
} EristaCpuUvEntry;
|
||||
};
|
||||
|
||||
struct MarikoCpuUvEntry {
|
||||
u32 tune0_low;
|
||||
u32 tune0_high;
|
||||
u32 tune1_low;
|
||||
u32 tune1_high;
|
||||
} MarikoCpuUvEntry;
|
||||
};
|
||||
|
||||
EristaCpuUvEntry eristaCpuUvTable[5] = {
|
||||
{0xffff, 0x27007ff},
|
||||
@@ -95,23 +97,23 @@ namespace board {
|
||||
|
||||
void CacheDfllData() {
|
||||
u64 temp;
|
||||
rc = svcQueryMemoryMapping(&cldvfs, &temp, CLDVFS_REGION_BASE, CLDVFS_REGION_SIZE);
|
||||
Result rc = svcQueryMemoryMapping(&cldvfs, &temp, CLDVFS_REGION_BASE, CLDVFS_REGION_SIZE);
|
||||
ASSERT_RESULT_OK(rc, "svcQueryMemoryMapping (cldvfs)");
|
||||
|
||||
if (GetSocType() == SysClkSocType_Erista) {
|
||||
cachedTune.tune0Low = *static_cast<u32 *>(cldvfs + CL_DVFS_TUNE0_0);
|
||||
cachedTune.tune1Low = *static_cast<u32 *>(cldvfs + CL_DVFS_TUNE1_0);
|
||||
cachedTune.tune0Low = *reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE0_0);
|
||||
cachedTune.tune1Low = *reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE1_0);
|
||||
} else {
|
||||
SetHz(SysClkModule_CPU, 1785000000);
|
||||
cachedTune.tune0High = *static_cast<u32 *>(cldvfs + CL_DVFS_TUNE0_0);
|
||||
cachedTune.tune0High = *reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE0_0);
|
||||
ResetToStockCpu();
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: clean up this code. */
|
||||
void SetDfllTunings(u32 levelLow, u32 levelHigh, u32 tbreakPoint) {
|
||||
u32* tune0_ptr = static_cast<u32 *>(cldvfs + CL_DVFS_TUNE0_0);
|
||||
u32* tune1_ptr = static_cast<u32 *>(cldvfs + CL_DVFS_TUNE1_0);
|
||||
u32* tune0_ptr = reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE0_0);
|
||||
u32* tune1_ptr = reinterpret_cast<u32 *>(cldvfs + CL_DVFS_TUNE1_0);
|
||||
if (GetSocType() == SysClkSocType_Mariko) {
|
||||
if (GetHz(SysClkModule_CPU) < tbreakPoint && (levelLow || levelHigh)) {
|
||||
if (levelLow) {
|
||||
@@ -253,10 +255,10 @@ namespace board {
|
||||
rc = rgltrOpenSession(&session, PcvPowerDomainId_Max77621_Gpu);
|
||||
} else {
|
||||
rc = rgltrOpenSession(&session, PcvPowerDomainId_Max77812_Gpu);
|
||||
ASSERT_RESULT_OK(rc, "rgltrOpenSession")
|
||||
rgltrGetVoltage(&session, &out);
|
||||
rgltrCloseSession(&session);
|
||||
}
|
||||
ASSERT_RESULT_OK(rc, "rgltrOpenSession")
|
||||
rgltrGetVoltage(&session, &out);
|
||||
rgltrCloseSession(&session);
|
||||
break;
|
||||
case HocClkVoltage_EMCVDDQ_MarikoOnly:
|
||||
if (GetSocType() == SysClkSocType_Mariko) {
|
||||
@@ -327,9 +329,9 @@ namespace board {
|
||||
|
||||
void CacheGpuVoltTable() {
|
||||
UnkRegulator reg = {
|
||||
.voltageMinUV = 600000,
|
||||
.voltageStep = 12500,
|
||||
.voltageMax = 1400000,
|
||||
.voltageMin = 600000,
|
||||
.voltageStep = 12500,
|
||||
.voltageMax = 1400000,
|
||||
};
|
||||
|
||||
Handle handle = GetPcvHandle();
|
||||
@@ -417,7 +419,7 @@ namespace board {
|
||||
return;
|
||||
}
|
||||
|
||||
Result rc = svcWriteDebugProcessMemory(handle, table, voltData.dvfsAddress, sizeof(table));
|
||||
Result rc = svcWriteDebugProcessMemory(handle, table, voltData.voltTableAddress, sizeof(table));
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
voltData.ramVmin = vmin;
|
||||
@@ -441,7 +443,7 @@ namespace board {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < std::size(gpuDvfsArray); ++i) {
|
||||
for (u32 i = 0; i < std::size(gpuVoltArray); ++i) {
|
||||
if (freqMhz <= ramTable[bracket][i]) {
|
||||
return gpuVoltArray[i];
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace board {
|
||||
|
||||
/* TODO: Find out what component this actually targets. */
|
||||
struct UnkRegulator {
|
||||
u32 voltageMinUV;
|
||||
u32 voltageMin;
|
||||
u32 voltageStep;
|
||||
u32 voltageMax;
|
||||
};
|
||||
@@ -53,8 +53,9 @@ namespace board {
|
||||
// u64 dvco_calibration_max;
|
||||
};
|
||||
|
||||
void SetDfllTunings(u32 levelLow, u32 levelHigh, u32 tbreakPoint);
|
||||
void CacheDfllData();
|
||||
u32 CalculateTbreak();
|
||||
u32 CalculateTbreak(u32 table);
|
||||
u32 GetVoltage(HocClkVoltage voltage);
|
||||
void CacheGpuVoltTable();
|
||||
void PcvHijackGpuVolts(u32 vmin);
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
#include "clock_manager.h"
|
||||
#include <cstring>
|
||||
#include "file_utils.h"
|
||||
#include "board.h"
|
||||
#include "process_management.h"
|
||||
#include "board/board.hpp"
|
||||
#include "process_management.hpp"
|
||||
#include "errors.h"
|
||||
#include "ipc_service.h"
|
||||
#include "kip.h"
|
||||
@@ -61,6 +61,7 @@ u32 initialConfigValues[SysClkConfigValue_EnumMax]; // initial config. used for
|
||||
bool kipAvailable = false;
|
||||
bool isCpuGovernorInBoostMode = false;
|
||||
bool isVRREnabled = false;
|
||||
|
||||
ClockManager *ClockManager::GetInstance()
|
||||
{
|
||||
return instance;
|
||||
@@ -136,14 +137,20 @@ ClockManager::ClockManager()
|
||||
-2
|
||||
);
|
||||
|
||||
for(int i = 0; i < HorizonOCSpeedo_EnumMax; i++) {
|
||||
this->context->speedos[i] = Board::getSpeedo((HorizonOCSpeedo)i);
|
||||
this->context->iddq[i] = Board::getIDDQ((HorizonOCSpeedo)i);
|
||||
}
|
||||
board::FuseData *fuse = board::GetFuseData();
|
||||
|
||||
this->context->dramID = Board::GetDramID();
|
||||
this->context->isDram8GB = Board::IsDram8GB();
|
||||
Board::SetGpuSchedulingMode((GpuSchedulingMode)this->config->GetConfigValue(HorizonOCConfigValue_GPUScheduling), (GpuSchedulingOverrideMethod)this->config->GetConfigValue(HorizonOCConfigValue_GPUSchedulingMethod));
|
||||
this->context->speedos[0] = fuse->cpuSpeedo;
|
||||
this->context->speedos[1] = fuse->gpuSpeedo;
|
||||
this->context->speedos[2] = fuse->socSpeedo;
|
||||
this->context->iddq[0] = fuse->cpuIDDQ;
|
||||
this->context->iddq[1] = fuse->gpuIDDQ;
|
||||
this->context->iddq[2] = fuse->socIDDQ;
|
||||
this->context->waferX = fuse->waferX;
|
||||
this->context->waferY = fuse->waferY;
|
||||
|
||||
this->context->dramID = board::GetDramID();
|
||||
this->context->isDram8GB = board::IsDram8GB();
|
||||
board::SetGpuSchedulingMode((GpuSchedulingMode)this->config->GetConfigValue(HorizonOCConfigValue_GPUScheduling), (GpuSchedulingOverrideMethod)this->config->GetConfigValue(HorizonOCConfigValue_GPUSchedulingMethod));
|
||||
this->context->gpuSchedulingMode = (GpuSchedulingMode)this->config->GetConfigValue(HorizonOCConfigValue_GPUScheduling);
|
||||
|
||||
this->context->isSysDockInstalled = this->sysDockIntegration->getCurrentSysDockState();
|
||||
@@ -152,6 +159,7 @@ ClockManager::ClockManager()
|
||||
this->saltyNXIntegration->LoadSaltyNX();
|
||||
}
|
||||
|
||||
this->context->isUsingRetroSuper = board::IsUsingRetroSuperDisplay();
|
||||
|
||||
threadStart(&cpuGovernorTHREAD);
|
||||
threadStart(&gpuGovernorTHREAD);
|
||||
@@ -224,7 +232,7 @@ std::uint32_t ClockManager::GetMaxAllowedHz(SysClkModule module, SysClkProfile p
|
||||
{
|
||||
if (profile < SysClkProfile_HandheldCharging)
|
||||
{
|
||||
switch(Board::GetSocType()) {
|
||||
switch (board::GetSocType()) {
|
||||
case SysClkSocType_Erista:
|
||||
return 460800000;
|
||||
case SysClkSocType_Mariko:
|
||||
@@ -244,7 +252,7 @@ std::uint32_t ClockManager::GetMaxAllowedHz(SysClkModule module, SysClkProfile p
|
||||
}
|
||||
else if (profile <= SysClkProfile_HandheldChargingUSB)
|
||||
{
|
||||
switch(Board::GetSocType()) {
|
||||
switch(board::GetSocType()) {
|
||||
case SysClkSocType_Erista:
|
||||
return 768000000;
|
||||
case SysClkSocType_Mariko:
|
||||
@@ -263,7 +271,7 @@ std::uint32_t ClockManager::GetMaxAllowedHz(SysClkModule module, SysClkProfile p
|
||||
}
|
||||
}
|
||||
} else if(module == SysClkModule_CPU) {
|
||||
if(profile < SysClkProfile_HandheldCharging && Board::GetSocType() == SysClkSocType_Erista) {
|
||||
if(profile < SysClkProfile_HandheldCharging && board::GetSocType() == SysClkSocType_Erista) {
|
||||
return 1581000000;
|
||||
} else {
|
||||
return ~0;
|
||||
@@ -317,8 +325,8 @@ void ClockManager::RefreshFreqTableRow(SysClkModule module)
|
||||
std::uint32_t freqs[SYSCLK_FREQ_LIST_MAX];
|
||||
std::uint32_t count;
|
||||
|
||||
FileUtils::LogLine("[mgr] %s freq list refresh", Board::GetModuleName(module, true));
|
||||
Board::GetFreqList(module, &freqs[0], SYSCLK_FREQ_LIST_MAX, &count);
|
||||
FileUtils::LogLine("[mgr] %s freq list refresh", board::GetModuleName(module, true));
|
||||
board::GetFreqList(module, &freqs[0], SYSCLK_FREQ_LIST_MAX, &count);
|
||||
|
||||
std::uint32_t *hz = &this->freqTable[module].list[0];
|
||||
this->freqTable[module].count = 0;
|
||||
@@ -369,7 +377,8 @@ void ClockManager::CpuGovernorThread(void* arg) {
|
||||
|
||||
u32 downHoldRemaining = 0;
|
||||
u32 lastHz = 0;
|
||||
|
||||
u32 minHz = 612;
|
||||
u32 tick = 0;
|
||||
for (;;) {
|
||||
if (!mgr->running || !isCpuGovernorEnabled) {
|
||||
downHoldRemaining = 0;
|
||||
@@ -397,7 +406,7 @@ void ClockManager::CpuGovernorThread(void* arg) {
|
||||
|
||||
std::scoped_lock lock{mgr->contextMutex};
|
||||
|
||||
u32 cpuLoad = Board::GetPartLoad(HocClkPartLoad_CPUMax);
|
||||
u32 cpuLoad = board::GetPartLoad(HocClkPartLoad_CPUMax);
|
||||
|
||||
u32 tableMaxHz = table.list[table.count - 1];
|
||||
u32 desiredHz = ClockManager::SchedutilTargetHz(cpuLoad, tableMaxHz);
|
||||
@@ -423,8 +432,16 @@ void ClockManager::CpuGovernorThread(void* arg) {
|
||||
if (downHoldRemaining > 0)
|
||||
downHoldRemaining--;
|
||||
|
||||
if(++tick > 50) {
|
||||
minHz = mgr->config->GetConfigValue(HorizonOCConfigValue_CpuGovernorMinimumFreq);
|
||||
tick = 0;
|
||||
}
|
||||
|
||||
if(newHz < minHz)
|
||||
newHz = minHz;
|
||||
|
||||
if ((!goingDown || (downHoldRemaining == 0)) && mgr->IsAssignableHz(SysClkModule_CPU, newHz)) {
|
||||
Board::SetHz(SysClkModule_CPU, newHz);
|
||||
board::SetHz(SysClkModule_CPU, newHz);
|
||||
mgr->context->freqs[SysClkModule_CPU] = newHz;
|
||||
lastHz = newHz;
|
||||
}
|
||||
@@ -453,7 +470,7 @@ void ClockManager::GovernorThread(void* arg) {
|
||||
|
||||
std::scoped_lock lock{mgr->contextMutex};
|
||||
|
||||
u32 gpuLoad = Board::GetPartLoad(HocClkPartLoad_GPU);
|
||||
u32 gpuLoad = board::GetPartLoad(HocClkPartLoad_GPU);
|
||||
u32 tableMaxHz = table.list[table.count - 1];
|
||||
u32 desiredHz = ClockManager::SchedutilTargetHz(gpuLoad, tableMaxHz);
|
||||
u32 targetHz = ClockManager::ResolveTargetHz(mgr, SysClkModule_GPU);
|
||||
@@ -477,7 +494,7 @@ void ClockManager::GovernorThread(void* arg) {
|
||||
downHoldRemaining--;
|
||||
|
||||
if ((!goingDown || (downHoldRemaining == 0)) && mgr->IsAssignableHz(SysClkModule_GPU, newHz)) {
|
||||
Board::SetHz(SysClkModule_GPU, newHz);
|
||||
board::SetHz(SysClkModule_GPU, newHz);
|
||||
mgr->context->freqs[SysClkModule_GPU] = newHz;
|
||||
lastHz = newHz;
|
||||
}
|
||||
@@ -495,11 +512,6 @@ void ClockManager::VRRThread(void* arg) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(Board::IsHoag()) { // don't do anything on lite
|
||||
svcSleepThread(~0ULL);
|
||||
continue;
|
||||
}
|
||||
|
||||
std::scoped_lock lock{mgr->contextMutex};
|
||||
|
||||
u8 fps;
|
||||
@@ -517,7 +529,7 @@ void ClockManager::VRRThread(void* arg) {
|
||||
continue;
|
||||
}
|
||||
// if(appletGetFocusState() != AppletFocusState_InFocus) {
|
||||
// Board::ResetToStockDisplay();
|
||||
// board::ResetToStockDisplay();
|
||||
// continue;
|
||||
// }
|
||||
|
||||
@@ -533,46 +545,49 @@ void ClockManager::VRRThread(void* arg) {
|
||||
if(targetHz) {
|
||||
maxDisplay = targetHz;
|
||||
} else {
|
||||
maxDisplay = 60;
|
||||
maxDisplay = 60; // don't assume display stuff!
|
||||
}
|
||||
|
||||
u8 minDisplay = Board::GetConsoleType() == HorizonOCConsoleType_Aula ? 45 : 40;
|
||||
u8 minDisplay = board::GetConsoleType() == HorizonOCConsoleType_Aula ? 45 : 40;
|
||||
if(maxDisplay == minDisplay)
|
||||
continue;
|
||||
|
||||
if(fps >= minDisplay && fps <= maxDisplay)
|
||||
Board::SetHz(HorizonOCModule_Display, fps);
|
||||
else {
|
||||
if(fps >= minDisplay && fps <= maxDisplay) {
|
||||
board::SetHz(HorizonOCModule_Display, fps);
|
||||
mgr->context->freqs[HorizonOCModule_Display] = fps;
|
||||
mgr->context->realFreqs[HorizonOCModule_Display] = fps;
|
||||
} else {
|
||||
for(u32 i = 0; i < 10; i++) {
|
||||
u32 compareHz = fps * i;
|
||||
if(compareHz >= minDisplay && compareHz <= maxDisplay) {
|
||||
Board::SetHz(HorizonOCModule_Display, compareHz);
|
||||
board::SetHz(HorizonOCModule_Display, compareHz);
|
||||
mgr->context->freqs[HorizonOCModule_Display] = compareHz;
|
||||
mgr->context->realFreqs[HorizonOCModule_Display] = compareHz;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(++tick > 50) {
|
||||
Board::ResetToStockDisplay();
|
||||
board::SetHz(HorizonOCModule_Display, maxDisplay);
|
||||
tick = 0;
|
||||
svcSleepThread(25'000'000);
|
||||
svcSleepThread(50'000'000);
|
||||
}
|
||||
|
||||
svcSleepThread(POLL_NS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ClockManager::HandleSafetyFeatures() {
|
||||
AppletOperationMode opMode = appletGetOperationMode();
|
||||
if(this->config->GetConfigValue(HocClkConfigValue_HandheldTDP) && opMode == AppletOperationMode_Handheld) {
|
||||
if(Board::GetConsoleType() == HorizonOCConsoleType_Hoag) {
|
||||
if(Board::GetPowerMw(SysClkPowerSensor_Avg) < -(int)this->config->GetConfigValue(HocClkConfigValue_LiteTDPLimit)) {
|
||||
if(this->config->GetConfigValue(HocClkConfigValue_HandheldTDP) && (this->context->profile != SysClkProfile_Docked)) { // Enable while charging as non-PD charger can cause lack of power
|
||||
if (board::GetConsoleType() == HorizonOCConsoleType_Hoag) {
|
||||
if (board::GetPowerMw(SysClkPowerSensor_Avg) < - this->config->GetConfigValue(HocClkConfigValue_LiteTDPLimit)) {
|
||||
ResetToStockClocks();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(Board::GetPowerMw(SysClkPowerSensor_Avg) < -(int)this->config->GetConfigValue(HocClkConfigValue_HandheldTDPLimit)) {
|
||||
if(board::GetPowerMw(SysClkPowerSensor_Avg) < - this->config->GetConfigValue(HocClkConfigValue_HandheldTDPLimit)) {
|
||||
ResetToStockClocks();
|
||||
return;
|
||||
}
|
||||
@@ -620,15 +635,15 @@ void ClockManager::HandleGovernor(uint32_t targetHz) {
|
||||
|
||||
if(newCpuGovernorState == false && lastCpuGovernorState == true) {
|
||||
svcSleepThread(100'000'000); // thread syncing. probably a cleaner way to do this but hey, it works!
|
||||
Board::ResetToStockCpu();
|
||||
board::ResetToStockCpu();
|
||||
}
|
||||
if(newGpuGovernorState == false && lastGpuGovernorState == true) {
|
||||
svcSleepThread(100'000'000);
|
||||
Board::ResetToStockGpu();
|
||||
board::ResetToStockGpu();
|
||||
}
|
||||
if (newVrrGovernorState == false && lastVrrGovernorState == true) {
|
||||
svcSleepThread(100'000'000);
|
||||
Board::ResetToStockDisplay();
|
||||
board::ResetToStockDisplay();
|
||||
}
|
||||
if(newCpuGovernorState != lastCpuGovernorState || newGpuGovernorState != lastGpuGovernorState || newVrrGovernorState != lastVrrGovernorState) {
|
||||
FileUtils::LogLine("[mgr] Governor state changed: CPU %s, GPU %s, VRR %s", newCpuGovernorState ? "enabled" : "disabled", newGpuGovernorState ? "enabled" : "disabled", newVrrGovernorState ? "enabled" : "disabled");
|
||||
@@ -640,9 +655,9 @@ void ClockManager::HandleGovernor(uint32_t targetHz) {
|
||||
|
||||
void ClockManager::DVFSBeforeSet(u32 targetHz) {
|
||||
s32 dvfsOffset = this->config->GetConfigValue(HorizonOCConfigValue_DVFSOffset);
|
||||
u32 vmin = Board::GetMinimumGpuVoltage(targetHz / 1000000) + dvfsOffset;
|
||||
u32 vmin = board::GetMinimumGpuVmin(targetHz / 1000000, board::GetGpuSpeedoBracket()) + dvfsOffset;
|
||||
|
||||
Board::PcvHijackDvfs(vmin);
|
||||
board::PcvHijackGpuVolts(vmin);
|
||||
|
||||
/* Update the voltage. */
|
||||
if (I2c_BuckConverter_GetMvOut(&I2c_Mariko_GPU) < vmin) {
|
||||
@@ -655,7 +670,7 @@ void ClockManager::DVFSBeforeSet(u32 targetHz) {
|
||||
void ClockManager::DVFSAfterSet(u32 targetHz) {
|
||||
s32 dvfsOffset = this->config->GetConfigValue(HorizonOCConfigValue_DVFSOffset);
|
||||
dvfsOffset = std::max(dvfsOffset, -80);
|
||||
u32 vmin = Board::GetMinimumGpuVoltage(targetHz / 1000000);
|
||||
u32 vmin = board::GetMinimumGpuVmin(targetHz / 1000000, board::GetGpuSpeedoBracket());
|
||||
|
||||
if (vmin) {
|
||||
vmin += dvfsOffset;
|
||||
@@ -663,27 +678,27 @@ void ClockManager::DVFSAfterSet(u32 targetHz) {
|
||||
|
||||
u32 maxHz = this->GetMaxAllowedHz(SysClkModule_GPU, this->context->profile);
|
||||
u32 nearestHz = this->GetNearestHz(SysClkModule_GPU, targetHz, maxHz);
|
||||
Board::PcvHijackDvfs(vmin);
|
||||
board::PcvHijackGpuVolts(vmin);
|
||||
|
||||
if (targetHz) {
|
||||
Board::SetHz(SysClkModule_GPU, ~0);
|
||||
Board::SetHz(SysClkModule_GPU, nearestHz);
|
||||
board::SetHz(SysClkModule_GPU, ~0);
|
||||
board::SetHz(SysClkModule_GPU, nearestHz);
|
||||
} else {
|
||||
Board::SetHz(SysClkModule_GPU, ~0);
|
||||
Board::ResetToStockGpu();
|
||||
board::SetHz(SysClkModule_GPU, ~0);
|
||||
board::ResetToStockGpu();
|
||||
}
|
||||
}
|
||||
|
||||
void ClockManager::HandleCpuUv() {
|
||||
if(Board::GetSocType() == SysClkSocType_Erista)
|
||||
Board::SetCpuUvLevel(this->config->GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000);
|
||||
if(board::GetSocType() == SysClkSocType_Erista)
|
||||
board::SetDfllTunings(this->config->GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000);
|
||||
else
|
||||
Board::SetCpuUvLevel(this->config->GetConfigValue(KipConfigValue_marikoCpuUVLow), this->config->GetConfigValue(KipConfigValue_marikoCpuUVHigh), Board::CalculateTbreak(this->config->GetConfigValue(KipConfigValue_tableConf)));
|
||||
board::SetDfllTunings(this->config->GetConfigValue(KipConfigValue_marikoCpuUVLow), this->config->GetConfigValue(KipConfigValue_marikoCpuUVHigh), board::CalculateTbreak(this->config->GetConfigValue(KipConfigValue_tableConf)));
|
||||
}
|
||||
|
||||
void ClockManager::DVFSReset() {
|
||||
if (Board::GetSocType() == SysClkSocType_Mariko && this->config->GetConfigValue(HorizonOCConfigValue_DVFSMode) == DVFSMode_Hijack) {
|
||||
Board::PcvHijackDvfs(0);
|
||||
if (board::GetSocType() == SysClkSocType_Mariko && this->config->GetConfigValue(HorizonOCConfigValue_DVFSMode) == DVFSMode_Hijack) {
|
||||
board::PcvHijackGpuVolts(0);
|
||||
|
||||
u32 targetHz = this->context->overrideFreqs[SysClkModule_GPU];
|
||||
if (!targetHz) {
|
||||
@@ -695,11 +710,11 @@ void ClockManager::DVFSReset() {
|
||||
u32 maxHz = this->GetMaxAllowedHz(SysClkModule_GPU, this->context->profile);
|
||||
u32 nearestHz = this->GetNearestHz(SysClkModule_GPU, targetHz, maxHz);
|
||||
|
||||
Board::SetHz(SysClkModule_GPU, ~0);
|
||||
board::SetHz(SysClkModule_GPU, ~0);
|
||||
if(targetHz) {
|
||||
Board::SetHz(SysClkModule_GPU, nearestHz);
|
||||
board::SetHz(SysClkModule_GPU, nearestHz);
|
||||
} else {
|
||||
Board::ResetToStockGpu();
|
||||
board::ResetToStockGpu();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -709,25 +724,25 @@ void ClockManager::HandleFreqReset(SysClkModule module, bool isBoost) {
|
||||
{
|
||||
case SysClkModule_CPU:
|
||||
if(!(isBoost || (this->config->GetConfigValue(HocClkConfigValue_OverwriteBoostMode) && isBoost)))
|
||||
Board::ResetToStockCpu();
|
||||
board::ResetToStockCpu();
|
||||
if(this->config->GetConfigValue(HorizonOCConfigValue_LiveCpuUv)) {
|
||||
if(Board::GetSocType() == SysClkSocType_Erista)
|
||||
Board::SetCpuUvLevel(this->config->GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000);
|
||||
if(board::GetSocType() == SysClkSocType_Erista)
|
||||
board::SetDfllTunings(this->config->GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000);
|
||||
else
|
||||
Board::SetCpuUvLevel(this->config->GetConfigValue(KipConfigValue_marikoCpuUVLow), this->config->GetConfigValue(KipConfigValue_marikoCpuUVHigh), Board::CalculateTbreak(this->config->GetConfigValue(KipConfigValue_tableConf)));
|
||||
board::SetDfllTunings(this->config->GetConfigValue(KipConfigValue_marikoCpuUVLow), this->config->GetConfigValue(KipConfigValue_marikoCpuUVHigh), board::CalculateTbreak(this->config->GetConfigValue(KipConfigValue_tableConf)));
|
||||
}
|
||||
|
||||
break;
|
||||
case SysClkModule_GPU:
|
||||
Board::ResetToStockGpu();
|
||||
board::ResetToStockGpu();
|
||||
break;
|
||||
case SysClkModule_MEM:
|
||||
Board::ResetToStockMem();
|
||||
board::ResetToStockMem();
|
||||
DVFSReset();
|
||||
break;
|
||||
case HorizonOCModule_Display:
|
||||
if(this->config->GetConfigValue(HorizonOCConfigValue_OverwriteRefreshRate) && !Board::IsHoag()) {
|
||||
Board::ResetToStockDisplay();
|
||||
if(this->config->GetConfigValue(HorizonOCConfigValue_OverwriteRefreshRate)) {
|
||||
board::ResetToStockDisplay();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -742,9 +757,9 @@ void ClockManager::SetClocks(bool isBoost) {
|
||||
std::uint32_t nearestHz = 0;
|
||||
|
||||
if(isBoost && !this->config->GetConfigValue(HocClkConfigValue_OverwriteBoostMode)) {
|
||||
u32 boostFreq = Board::GetHz(SysClkModule_CPU);
|
||||
u32 boostFreq = board::GetHz(SysClkModule_CPU);
|
||||
if (boostFreq / 1000000 > 1785) {
|
||||
Board::SetHz(SysClkModule_CPU, boostFreq);
|
||||
board::SetHz(SysClkModule_CPU, boostFreq);
|
||||
}
|
||||
return; // Return if we are't overwriting boost mode
|
||||
}
|
||||
@@ -752,7 +767,7 @@ void ClockManager::SetClocks(bool isBoost) {
|
||||
bool returnRaw = false; // Return a value scaled to MHz instead of raw value
|
||||
for (unsigned int module = 0; module < SysClkModule_EnumMax; module++)
|
||||
{
|
||||
u32 oldHz = Board::GetHz((SysClkModule)module); // Get Old hz (used primarily for DVFS Logic)
|
||||
u32 oldHz = board::GetHz((SysClkModule)module); // Get Old hz (used primarily for DVFS Logic)
|
||||
|
||||
if(module > SysClkModule_MEM)
|
||||
returnRaw = true;
|
||||
@@ -772,17 +787,19 @@ void ClockManager::SetClocks(bool isBoost) {
|
||||
|
||||
bool noCPU = isCpuGovernorEnabled;
|
||||
bool noGPU = isGpuGovernorEnabled;
|
||||
if(!Board::IsHoag()) {
|
||||
bool noDisp = isVRREnabled;
|
||||
if(noDisp && module == HorizonOCModule_Display)
|
||||
continue;
|
||||
bool noDisp = isVRREnabled;
|
||||
if(noDisp && module == HorizonOCModule_Display)
|
||||
continue;
|
||||
|
||||
if(module == HorizonOCModule_Display && this->config->GetConfigValue(HorizonOCConfigValue_OverwriteRefreshRate)) {
|
||||
if(targetHz)
|
||||
Board::SetHz(HorizonOCModule_Display, targetHz);
|
||||
else
|
||||
Board::ResetToStockDisplay();
|
||||
if(module == HorizonOCModule_Display && this->config->GetConfigValue(HorizonOCConfigValue_OverwriteRefreshRate) && !noDisp) {
|
||||
if(targetHz) {
|
||||
board::SetHz(HorizonOCModule_Display, targetHz);
|
||||
this->context->freqs[HorizonOCModule_Display] = targetHz;
|
||||
this->context->realFreqs[HorizonOCModule_Display] = targetHz;
|
||||
} else {
|
||||
HandleFreqReset(HorizonOCModule_Display, isBoost);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Skip GPU and CPU if governors handle them
|
||||
@@ -804,23 +821,23 @@ void ClockManager::SetClocks(bool isBoost) {
|
||||
if (nearestHz != this->context->freqs[module]) {
|
||||
FileUtils::LogLine(
|
||||
"[mgr] %s clock set : %u.%u MHz (target = %u.%u MHz)",
|
||||
Board::GetModuleName((SysClkModule)module, true),
|
||||
board::GetModuleName((SysClkModule)module, true),
|
||||
nearestHz / 1000000, nearestHz / 100000 - nearestHz / 1000000 * 10,
|
||||
targetHz / 1000000, targetHz / 100000 - targetHz / 1000000 * 10
|
||||
);
|
||||
|
||||
if(module == SysClkModule_MEM && Board::GetSocType() == SysClkSocType_Mariko && targetHz > oldHz && this->config->GetConfigValue(HorizonOCConfigValue_DVFSMode) == DVFSMode_Hijack) {
|
||||
if(module == SysClkModule_MEM && board::GetSocType() == SysClkSocType_Mariko && targetHz > oldHz && this->config->GetConfigValue(HorizonOCConfigValue_DVFSMode) == DVFSMode_Hijack) {
|
||||
DVFSBeforeSet(targetHz);
|
||||
}
|
||||
|
||||
Board::SetHz((SysClkModule)module, nearestHz);
|
||||
board::SetHz((SysClkModule)module, nearestHz);
|
||||
this->context->freqs[module] = nearestHz;
|
||||
|
||||
if(module == SysClkModule_CPU && (this->config->GetConfigValue(HorizonOCConfigValue_LiveCpuUv))) {
|
||||
HandleCpuUv();
|
||||
}
|
||||
|
||||
if(module == SysClkModule_MEM && Board::GetSocType() == SysClkSocType_Mariko && targetHz < oldHz && this->config->GetConfigValue(HorizonOCConfigValue_DVFSMode) == DVFSMode_Hijack) {
|
||||
if(module == SysClkModule_MEM && board::GetSocType() == SysClkSocType_Mariko && targetHz < oldHz && this->config->GetConfigValue(HorizonOCConfigValue_DVFSMode) == DVFSMode_Hijack) {
|
||||
DVFSAfterSet(targetHz);
|
||||
}
|
||||
}
|
||||
@@ -850,21 +867,21 @@ void ClockManager::Tick()
|
||||
}
|
||||
|
||||
void ClockManager::ResetToStockClocks() {
|
||||
Board::ResetToStockCpu();
|
||||
board::ResetToStockCpu();
|
||||
if(this->config->GetConfigValue(HorizonOCConfigValue_LiveCpuUv))
|
||||
{
|
||||
if(Board::GetSocType() == SysClkSocType_Erista)
|
||||
Board::SetCpuUvLevel(this->config->GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000);
|
||||
if(board::GetSocType() == SysClkSocType_Erista)
|
||||
board::SetDfllTunings(this->config->GetConfigValue(KipConfigValue_eristaCpuUV), 0, 1581000000);
|
||||
else
|
||||
Board::SetCpuUvLevel(this->config->GetConfigValue(KipConfigValue_marikoCpuUVLow), this->config->GetConfigValue(KipConfigValue_marikoCpuUVHigh), Board::CalculateTbreak(this->config->GetConfigValue(KipConfigValue_tableConf)));
|
||||
board::SetDfllTunings(this->config->GetConfigValue(KipConfigValue_marikoCpuUVLow), this->config->GetConfigValue(KipConfigValue_marikoCpuUVHigh), board::CalculateTbreak(this->config->GetConfigValue(KipConfigValue_tableConf)));
|
||||
}
|
||||
|
||||
Board::ResetToStockGpu();
|
||||
board::ResetToStockGpu();
|
||||
}
|
||||
|
||||
void ClockManager::WaitForNextTick()
|
||||
{
|
||||
if(!(Board::GetHz(SysClkModule_MEM) < 665000000))
|
||||
if(!(board::GetHz(SysClkModule_MEM) < 665000000))
|
||||
svcSleepThread(this->GetConfig()->GetConfigValue(SysClkConfigValue_PollingIntervalMs) * 1000000ULL);
|
||||
else
|
||||
svcSleepThread(5000 * 1000000ULL); // 5 seconds in sleep mode
|
||||
@@ -878,7 +895,7 @@ bool ClockManager::RefreshContext()
|
||||
Result rc = apmExtGetCurrentPerformanceConfiguration(&mode);
|
||||
ASSERT_RESULT_OK(rc, "apmExtGetCurrentPerformanceConfiguration");
|
||||
|
||||
std::uint64_t applicationId = ProcessManagement::GetCurrentApplicationId();
|
||||
std::uint64_t applicationId = processManagement::GetCurrentApplicationId();
|
||||
if (applicationId != this->context->applicationId)
|
||||
{
|
||||
FileUtils::LogLine("[mgr] TitleID change: %016lX", applicationId);
|
||||
@@ -886,10 +903,10 @@ bool ClockManager::RefreshContext()
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
SysClkProfile profile = Board::GetProfile();
|
||||
SysClkProfile profile = board::GetProfile();
|
||||
if (profile != this->context->profile)
|
||||
{
|
||||
FileUtils::LogLine("[mgr] Profile change: %s", Board::GetProfileName(profile, true));
|
||||
FileUtils::LogLine("[mgr] Profile change: %s", board::GetProfileName(profile, true));
|
||||
this->context->profile = profile;
|
||||
hasChanged = true;
|
||||
}
|
||||
@@ -897,11 +914,11 @@ bool ClockManager::RefreshContext()
|
||||
// restore clocks to stock values on app or profile change
|
||||
if (hasChanged)
|
||||
{
|
||||
Board::ResetToStock();
|
||||
if (Board::GetSocType() == SysClkSocType_Mariko && this->config->GetConfigValue(HorizonOCConfigValue_DVFSMode) == DVFSMode_Hijack) {
|
||||
Board::PcvHijackDvfs(0);
|
||||
Board::SetHz(SysClkModule_GPU, ~0);
|
||||
Board::ResetToStockGpu();
|
||||
board::ResetToStock();
|
||||
if (board::GetSocType() == SysClkSocType_Mariko && this->config->GetConfigValue(HorizonOCConfigValue_DVFSMode) == DVFSMode_Hijack) {
|
||||
board::PcvHijackGpuVolts(0);
|
||||
board::SetHz(SysClkModule_GPU, ~0);
|
||||
board::ResetToStockGpu();
|
||||
}
|
||||
this->WaitForNextTick();
|
||||
}
|
||||
@@ -909,10 +926,10 @@ bool ClockManager::RefreshContext()
|
||||
std::uint32_t hz = 0;
|
||||
for (unsigned int module = 0; module < SysClkModule_EnumMax; module++)
|
||||
{
|
||||
hz = Board::GetHz((SysClkModule)module);
|
||||
hz = board::GetHz((SysClkModule)module);
|
||||
if (hz != 0 && hz != this->context->freqs[module])
|
||||
{
|
||||
FileUtils::LogLine("[mgr] %s clock change: %u.%u MHz", Board::GetModuleName((SysClkModule)module, true), hz / 1000000, hz / 100000 - hz / 1000000 * 10);
|
||||
FileUtils::LogLine("[mgr] %s clock change: %u.%u MHz", board::GetModuleName((SysClkModule)module, true), hz / 1000000, hz / 100000 - hz / 1000000 * 10);
|
||||
this->context->freqs[module] = hz;
|
||||
hasChanged = true;
|
||||
}
|
||||
@@ -922,7 +939,7 @@ bool ClockManager::RefreshContext()
|
||||
{
|
||||
if (hz)
|
||||
{
|
||||
FileUtils::LogLine("[mgr] %s override change: %u.%u MHz", Board::GetModuleName((SysClkModule)module, true), hz / 1000000, hz / 100000 - hz / 1000000 * 10);
|
||||
FileUtils::LogLine("[mgr] %s override change: %u.%u MHz", board::GetModuleName((SysClkModule)module, true), hz / 1000000, hz / 100000 - hz / 1000000 * 10);
|
||||
}
|
||||
this->context->overrideFreqs[module] = hz;
|
||||
hasChanged = true;
|
||||
@@ -936,10 +953,10 @@ bool ClockManager::RefreshContext()
|
||||
bool shouldLogTemp = this->ConfigIntervalTimeout(SysClkConfigValue_TempLogIntervalMs, ns, &this->lastTempLogNs);
|
||||
for (unsigned int sensor = 0; sensor < SysClkThermalSensor_EnumMax; sensor++)
|
||||
{
|
||||
millis = Board::GetTemperatureMilli((SysClkThermalSensor)sensor);
|
||||
millis = board::GetTemperatureMilli((SysClkThermalSensor)sensor);
|
||||
if (shouldLogTemp)
|
||||
{
|
||||
FileUtils::LogLine("[mgr] %s temp: %u.%u °C", Board::GetThermalSensorName((SysClkThermalSensor)sensor, true), millis / 1000, (millis - millis / 1000 * 1000) / 100);
|
||||
FileUtils::LogLine("[mgr] %s temp: %u.%u °C", board::GetThermalSensorName((SysClkThermalSensor)sensor, true), millis / 1000, (millis - millis / 1000 * 1000) / 100);
|
||||
}
|
||||
this->context->temps[sensor] = millis;
|
||||
}
|
||||
@@ -949,10 +966,10 @@ bool ClockManager::RefreshContext()
|
||||
bool shouldLogPower = this->ConfigIntervalTimeout(SysClkConfigValue_PowerLogIntervalMs, ns, &this->lastPowerLogNs);
|
||||
for (unsigned int sensor = 0; sensor < SysClkPowerSensor_EnumMax; sensor++)
|
||||
{
|
||||
mw = Board::GetPowerMw((SysClkPowerSensor)sensor);
|
||||
mw = board::GetPowerMw((SysClkPowerSensor)sensor);
|
||||
if (shouldLogPower)
|
||||
{
|
||||
FileUtils::LogLine("[mgr] Power %s: %d mW", Board::GetPowerSensorName((SysClkPowerSensor)sensor, false), mw);
|
||||
FileUtils::LogLine("[mgr] Power %s: %d mW", board::GetPowerSensorName((SysClkPowerSensor)sensor, false), mw);
|
||||
}
|
||||
this->context->power[sensor] = mw;
|
||||
}
|
||||
@@ -962,10 +979,10 @@ bool ClockManager::RefreshContext()
|
||||
bool shouldLogFreq = this->ConfigIntervalTimeout(SysClkConfigValue_FreqLogIntervalMs, ns, &this->lastFreqLogNs);
|
||||
for (unsigned int module = 0; module < SysClkModule_EnumMax; module++)
|
||||
{
|
||||
realHz = Board::GetRealHz((SysClkModule)module);
|
||||
realHz = board::GetRealHz((SysClkModule)module);
|
||||
if (shouldLogFreq)
|
||||
{
|
||||
FileUtils::LogLine("[mgr] %s real freq: %u.%u MHz", Board::GetModuleName((SysClkModule)module, true), realHz / 1000000, realHz / 100000 - realHz / 1000000 * 10);
|
||||
FileUtils::LogLine("[mgr] %s real freq: %u.%u MHz", board::GetModuleName((SysClkModule)module, true), realHz / 1000000, realHz / 100000 - realHz / 1000000 * 10);
|
||||
}
|
||||
this->context->realFreqs[module] = realHz;
|
||||
}
|
||||
@@ -973,12 +990,12 @@ bool ClockManager::RefreshContext()
|
||||
// ram load do not and should not force a refresh, hasChanged untouched
|
||||
for (unsigned int loadSource = 0; loadSource < SysClkPartLoad_EnumMax; loadSource++)
|
||||
{
|
||||
this->context->partLoad[loadSource] = Board::GetPartLoad((SysClkPartLoad)loadSource);
|
||||
this->context->partLoad[loadSource] = board::GetPartLoad((SysClkPartLoad)loadSource);
|
||||
}
|
||||
|
||||
for (unsigned int voltageSource = 0; voltageSource < HocClkVoltage_EnumMax; voltageSource++)
|
||||
{
|
||||
this->context->voltages[voltageSource] = Board::GetVoltage((HocClkVoltage)voltageSource);
|
||||
this->context->voltages[voltageSource] = board::GetVoltage((HocClkVoltage)voltageSource);
|
||||
}
|
||||
|
||||
if (this->ConfigIntervalTimeout(SysClkConfigValue_CsvWriteIntervalMs, ns, &this->lastCsvWriteNs))
|
||||
@@ -986,21 +1003,22 @@ bool ClockManager::RefreshContext()
|
||||
FileUtils::WriteContextToCsv(this->context);
|
||||
}
|
||||
|
||||
// this->context->maxDisplayFreq = Board::GetHighestDockedDisplayRate();
|
||||
if(!Board::IsHoag()) {
|
||||
u32 targetHz = this->context->overrideFreqs[HorizonOCModule_Display];
|
||||
if (!targetHz)
|
||||
{
|
||||
targetHz = this->config->GetAutoClockHz(this->context->applicationId, HorizonOCModule_Display, this->context->profile, true);
|
||||
if(!targetHz)
|
||||
targetHz = this->config->GetAutoClockHz(GLOBAL_PROFILE_ID, HorizonOCModule_Display, this->context->profile, true);
|
||||
}
|
||||
|
||||
if(targetHz && this->context->realFreqs[HorizonOCModule_Display] > targetHz && this->context->profile != SysClkProfile_Docked)
|
||||
this->context->realFreqs[HorizonOCModule_Display] = targetHz; // clean up display real freqs, should probably be moved to the real freqs loop?
|
||||
|
||||
Board::SetDisplayRefreshDockedState(this->context->profile == SysClkProfile_Docked);
|
||||
// this->context->maxDisplayFreq = board::GetHighestDockedDisplayRate();
|
||||
u32 targetHz = this->context->overrideFreqs[HorizonOCModule_Display];
|
||||
if (!targetHz)
|
||||
{
|
||||
targetHz = this->config->GetAutoClockHz(this->context->applicationId, HorizonOCModule_Display, this->context->profile, true);
|
||||
if(!targetHz)
|
||||
targetHz = this->config->GetAutoClockHz(GLOBAL_PROFILE_ID, HorizonOCModule_Display, this->context->profile, true);
|
||||
}
|
||||
|
||||
if(targetHz && this->context->realFreqs[HorizonOCModule_Display] > targetHz && this->context->profile != SysClkProfile_Docked) {
|
||||
this->context->realFreqs[HorizonOCModule_Display] = targetHz; // clean up display real freqs, should probably be moved to the real freqs loop?
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
if(board::GetConsoleType() != HorizonOCConsoleType_Hoag)
|
||||
board::SetDisplayRefreshDockedState(this->context->profile == SysClkProfile_Docked);
|
||||
if(this->context->isSaltyNXInstalled)
|
||||
this->context->fps = saltyNXIntegration->GetFPS();
|
||||
else
|
||||
@@ -1016,7 +1034,7 @@ bool ClockManager::RefreshContext()
|
||||
|
||||
void ClockManager::SetKipData() {
|
||||
// TODO: figure out if this REALLY causes issues (i doubt it)
|
||||
// if(Board::GetSocType() == SysClkSocType_Mariko) {
|
||||
// if(board::GetSocType() == SysClkSocType_Mariko) {
|
||||
// if(R_FAILED(I2c_BuckConverter_SetMvOut(&I2c_Mariko_DRAM_VDDQ, this->config->GetConfigValue(KipConfigValue_marikoEmcVddqVolt) / 1000))) {
|
||||
// FileUtils::LogLine("[clock_manager] Failed set i2c vddq");
|
||||
// writeNotification("Horizon OC\nFailed to write I2C\nwhile setting vddq");
|
||||
@@ -1259,7 +1277,7 @@ void ClockManager::GetKipData() {
|
||||
configValues.values[KipConfigValue_marikoGpuVmin] = cust_get_mariko_gpu_vmin(&table);
|
||||
configValues.values[KipConfigValue_marikoGpuVmax] = cust_get_mariko_gpu_vmax(&table);
|
||||
configValues.values[KipConfigValue_commonGpuVoltOffset] = cust_get_common_gpu_offset(&table);
|
||||
configValues.values[KipConfigValue_gpuSpeedo] = Board::getSpeedo(HorizonOCSpeedo_GPU); // cust_get_gpu_speedo(&table);
|
||||
configValues.values[KipConfigValue_gpuSpeedo] = board::GetFuseData()->gpuSpeedo; // cust_get_gpu_speedo(&table);
|
||||
|
||||
for (int i = 0; i < 24; i++) {
|
||||
configValues.values[KipConfigValue_g_volt_76800 + i] = cust_get_mariko_gpu_volt(&table, i);
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <sysclk.h>
|
||||
#include <switch.h>
|
||||
#include "config.h"
|
||||
#include "board.h"
|
||||
#include <nxExt/cpp/lockable_mutex.h>
|
||||
#include "integrations.h"
|
||||
|
||||
@@ -140,7 +139,7 @@ class ClockManager
|
||||
* @param isBoost Is in boost mode
|
||||
*/
|
||||
void SetClocks(bool isBoost);
|
||||
|
||||
|
||||
/**
|
||||
* Main function, runs every 5s in sleep mode, and a user specified amount when awake
|
||||
*
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -215,9 +215,9 @@ bool Config::SetProfiles(std::uint64_t tid, SysClkTitleProfileList* profiles, bo
|
||||
{
|
||||
numProfiles++;
|
||||
|
||||
std::string key = std::string(Board::GetProfileName((SysClkProfile)profile, false)) +
|
||||
"_" +
|
||||
Board::GetModuleName((SysClkModule)module, false);
|
||||
std::string key = std::string(board::GetProfileName((SysClkProfile)profile, false)) +
|
||||
"_" +
|
||||
board::GetModuleName((SysClkModule)module, false);
|
||||
std::string value = std::to_string(*mhz);
|
||||
|
||||
keys.push_back(key);
|
||||
@@ -317,7 +317,7 @@ int Config::BrowseIniFunc(const char* section, const char* key, const char* valu
|
||||
|
||||
for(unsigned int profile = 0; profile < SysClkProfile_EnumMax; profile++)
|
||||
{
|
||||
const char* profileCode = Board::GetProfileName((SysClkProfile)profile, false);
|
||||
const char* profileCode = board::GetProfileName((SysClkProfile)profile, false);
|
||||
size_t profileCodeLen = strlen(profileCode);
|
||||
|
||||
if(!strncmp(key, profileCode, profileCodeLen) && key[profileCodeLen] == '_')
|
||||
@@ -326,7 +326,7 @@ int Config::BrowseIniFunc(const char* section, const char* key, const char* valu
|
||||
|
||||
for(unsigned int module = 0; module < SysClkModule_EnumMax; module++)
|
||||
{
|
||||
const char* moduleCode = Board::GetModuleName((SysClkModule)module, false);
|
||||
const char* moduleCode = board::GetModuleName((SysClkModule)module, false);
|
||||
size_t moduleCodeLen = strlen(moduleCode);
|
||||
if(!strncmp(subkey, moduleCode, moduleCodeLen) && subkey[moduleCodeLen] == '\0')
|
||||
{
|
||||
@@ -426,13 +426,13 @@ bool Config::SetConfigValues(SysClkConfigValueList* configValues, bool immediate
|
||||
|
||||
std::vector<const char*> iniKeys;
|
||||
std::vector<std::string> iniValues;
|
||||
|
||||
|
||||
iniKeys.reserve(SysClkConfigValue_EnumMax + 1);
|
||||
iniValues.reserve(SysClkConfigValue_EnumMax);
|
||||
|
||||
for(unsigned int kval = 0; kval < SysClkConfigValue_EnumMax; kval++)
|
||||
{
|
||||
if(!sysclkValidConfigValue((SysClkConfigValue)kval, configValues->values[kval]) ||
|
||||
if(!sysclkValidConfigValue((SysClkConfigValue)kval, configValues->values[kval]) ||
|
||||
configValues->values[kval] == sysclkDefaultConfigValue((SysClkConfigValue)kval))
|
||||
{
|
||||
continue;
|
||||
@@ -490,12 +490,12 @@ bool Config::ResetConfigValue(SysClkConfigValue kval)
|
||||
|
||||
std::vector<const char*> iniKeys;
|
||||
std::vector<std::string> iniValues;
|
||||
|
||||
|
||||
iniKeys.reserve(2);
|
||||
iniValues.reserve(1);
|
||||
|
||||
const char* keyStr = sysclkFormatConfigValue(kval, false);
|
||||
|
||||
|
||||
iniKeys.push_back(keyStr);
|
||||
iniValues.push_back("");
|
||||
|
||||
@@ -515,6 +515,6 @@ bool Config::ResetConfigValue(SysClkConfigValue kval)
|
||||
|
||||
this->configValues[kval] = defaultValue;
|
||||
FileUtils::LogLine("[cfg] Reset config value %u to default: %llu", kval, defaultValue);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -35,7 +35,7 @@
|
||||
#include <switch.h>
|
||||
#include <minIni.h>
|
||||
#include <nxExt.h>
|
||||
#include "board.h"
|
||||
#include "board/board.hpp"
|
||||
|
||||
#define CONFIG_VAL_SECTION "values"
|
||||
|
||||
|
||||
@@ -12,14 +12,14 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "integrations.h"
|
||||
#include <sys/stat.h>
|
||||
#include <SaltyNX.h>
|
||||
#include "process_management.h"
|
||||
#include "process_management.hpp"
|
||||
|
||||
SysDockIntegration::SysDockIntegration() {
|
||||
}
|
||||
@@ -42,10 +42,10 @@ bool SaltyNXIntegration::getCurrentSaltyNXState() {
|
||||
struct stat st = {0};
|
||||
return stat("sdmc:/atmosphere/contents/0000000000534C56/flags/boot2.flag", &st) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool SaltyNXIntegration::CheckPort() {
|
||||
Handle saltysd;
|
||||
|
||||
|
||||
for (int i = 0; i < 67; i++) {
|
||||
if (R_SUCCEEDED(svcConnectToNamedPort(&saltysd, "InjectServ"))) {
|
||||
svcCloseHandle(saltysd);
|
||||
@@ -54,7 +54,7 @@ bool SaltyNXIntegration::CheckPort() {
|
||||
if (i == 66) return false;
|
||||
svcSleepThread(1'000'000);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < 67; i++) {
|
||||
if (R_SUCCEEDED(svcConnectToNamedPort(&saltysd, "InjectServ"))) {
|
||||
svcCloseHandle(saltysd);
|
||||
@@ -62,10 +62,10 @@ bool SaltyNXIntegration::CheckPort() {
|
||||
}
|
||||
svcSleepThread(1'000'000);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void SaltyNXIntegration::LoadSharedMemory() {
|
||||
if (SaltySD_Connect())
|
||||
return;
|
||||
@@ -75,7 +75,7 @@ void SaltyNXIntegration::LoadSharedMemory() {
|
||||
if (!shmemMap(&_sharedmemory))
|
||||
SharedMemoryUsed = true;
|
||||
}
|
||||
|
||||
|
||||
void SaltyNXIntegration::searchSharedMemoryBlock(uintptr_t base) {
|
||||
ptrdiff_t search_offset = 0;
|
||||
while (search_offset < 0x1000) {
|
||||
@@ -86,38 +86,38 @@ void SaltyNXIntegration::searchSharedMemoryBlock(uintptr_t base) {
|
||||
}
|
||||
NxFps = 0;
|
||||
}
|
||||
|
||||
|
||||
u64 prevTid = 0;
|
||||
|
||||
u8 SaltyNXIntegration::GetFPS() {
|
||||
if (!SharedMemoryUsed)
|
||||
return 254;
|
||||
|
||||
u64 tid = ProcessManagement::GetCurrentApplicationId();
|
||||
|
||||
u64 tid = processManagement::GetCurrentApplicationId();
|
||||
if (tid == 0)
|
||||
return 254;
|
||||
|
||||
|
||||
if (prevTid != tid) {
|
||||
NxFps = 0;
|
||||
prevTid = tid;
|
||||
}
|
||||
|
||||
|
||||
if (!NxFps) {
|
||||
uintptr_t base = (uintptr_t)shmemGetAddr(&_sharedmemory);
|
||||
searchSharedMemoryBlock(base);
|
||||
}
|
||||
|
||||
|
||||
return NxFps ? NxFps->FPS : 254;
|
||||
}
|
||||
|
||||
u16 SaltyNXIntegration::GetResolutionHeight() {
|
||||
if (!SharedMemoryUsed)
|
||||
return 0;
|
||||
|
||||
u64 tid = ProcessManagement::GetCurrentApplicationId();
|
||||
|
||||
u64 tid = processManagement::GetCurrentApplicationId();
|
||||
if (tid == 0)
|
||||
return 0;
|
||||
|
||||
|
||||
if (prevTid != tid) {
|
||||
NxFps = 0;
|
||||
prevTid = tid;
|
||||
@@ -130,7 +130,7 @@ u16 SaltyNXIntegration::GetResolutionHeight() {
|
||||
if(NxFps) {
|
||||
NxFps->renderCalls[0].calls = 0xFFFF;
|
||||
svcSleepThread(10*1000);
|
||||
|
||||
|
||||
return NxFps->renderCalls[0].height == 0 ? NxFps->viewportCalls[0].height : NxFps->renderCalls[0].height;
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
|
||||
#include "errors.h"
|
||||
#include "file_utils.h"
|
||||
#include "board.h"
|
||||
#include "process_management.h"
|
||||
#include "board/board.hpp"
|
||||
#include "process_management.hpp"
|
||||
#include "clock_manager.h"
|
||||
#include "ipc_service.h"
|
||||
#define INNER_HEAP_SIZE 0x40000
|
||||
@@ -65,7 +65,7 @@ extern "C"
|
||||
|
||||
fake_heap_start = (char*)addr;
|
||||
fake_heap_end = (char*)addr + size;
|
||||
|
||||
|
||||
virtmemSetup();
|
||||
}
|
||||
|
||||
@@ -120,10 +120,10 @@ int main(int argc, char** argv)
|
||||
|
||||
try
|
||||
{
|
||||
Board::Initialize();
|
||||
ProcessManagement::Initialize();
|
||||
board::Initialize();
|
||||
processManagement::Initialize();
|
||||
|
||||
ProcessManagement::WaitForQLaunch();
|
||||
processManagement::WaitForQLaunch();
|
||||
|
||||
ClockManager* clockMgr = new ClockManager();
|
||||
IpcService* ipcSrv = new IpcService(clockMgr);
|
||||
@@ -147,8 +147,8 @@ int main(int argc, char** argv)
|
||||
ipcSrv->SetRunning(false);
|
||||
delete ipcSrv;
|
||||
delete clockMgr;
|
||||
ProcessManagement::Exit();
|
||||
Board::Exit();
|
||||
processManagement::Exit();
|
||||
board::Exit();
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -25,61 +25,63 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "process_management.h"
|
||||
#include "process_management.hpp"
|
||||
#include "file_utils.h"
|
||||
#include "errors.h"
|
||||
#define IS_QLAUNCH 0x20f
|
||||
|
||||
void ProcessManagement::Initialize()
|
||||
{
|
||||
Result rc = 0;
|
||||
namespace processManagement {
|
||||
|
||||
rc = pmdmntInitialize();
|
||||
ASSERT_RESULT_OK(rc, "pmdmntInitialize");
|
||||
|
||||
rc = pminfoInitialize();
|
||||
ASSERT_RESULT_OK(rc, "pminfoInitialize");
|
||||
}
|
||||
|
||||
void ProcessManagement::WaitForQLaunch()
|
||||
{
|
||||
Result rc = 0;
|
||||
std::uint64_t pid = 0;
|
||||
do
|
||||
{
|
||||
rc = pmdmntGetProcessId(&pid, PROCESS_MANAGEMENT_QLAUNCH_TID);
|
||||
svcSleepThread(50 * 1000000ULL); // 50ms
|
||||
} while (R_FAILED(rc));
|
||||
}
|
||||
|
||||
std::uint64_t ProcessManagement::GetCurrentApplicationId()
|
||||
{
|
||||
Result rc = 0;
|
||||
std::uint64_t pid = 0;
|
||||
std::uint64_t tid = 0;
|
||||
rc = pmdmntGetApplicationProcessId(&pid);
|
||||
|
||||
if (rc == IS_QLAUNCH)
|
||||
{
|
||||
return PROCESS_MANAGEMENT_QLAUNCH_TID;
|
||||
namespace {
|
||||
constexpr u64 Qlaunch = 0x0100000000001000ULL;
|
||||
constexpr u32 IsQlaunch = 0x20f;
|
||||
}
|
||||
|
||||
ASSERT_RESULT_OK(rc, "pmdmntGetApplicationProcessId");
|
||||
void Initialize() {
|
||||
Result rc = 0;
|
||||
|
||||
rc = pminfoGetProgramId(&tid, pid);
|
||||
rc = pmdmntInitialize();
|
||||
ASSERT_RESULT_OK(rc, "pmdmntInitialize");
|
||||
|
||||
if (rc == IS_QLAUNCH)
|
||||
{
|
||||
return PROCESS_MANAGEMENT_QLAUNCH_TID;
|
||||
rc = pminfoInitialize();
|
||||
ASSERT_RESULT_OK(rc, "pminfoInitialize");
|
||||
}
|
||||
|
||||
ASSERT_RESULT_OK(rc, "pminfoGetProgramId");
|
||||
void WaitForQLaunch() {
|
||||
|
||||
return tid;
|
||||
}
|
||||
Result rc = 0;
|
||||
u64 pid = 0;
|
||||
do {
|
||||
rc = pmdmntGetProcessId(&pid, Qlaunch);
|
||||
svcSleepThread(50 * 1000000ULL); // 50ms
|
||||
} while (R_FAILED(rc));
|
||||
}
|
||||
|
||||
void ProcessManagement::Exit()
|
||||
{
|
||||
pmdmntExit();
|
||||
pminfoExit();
|
||||
}
|
||||
u64 GetCurrentApplicationId() {
|
||||
Result rc = 0;
|
||||
u64 pid = 0;
|
||||
u64 tid = 0;
|
||||
rc = pmdmntGetApplicationProcessId(&pid);
|
||||
|
||||
if (rc == IsQlaunch) {
|
||||
return Qlaunch;
|
||||
}
|
||||
|
||||
ASSERT_RESULT_OK(rc, "pmdmntGetApplicationProcessId");
|
||||
|
||||
rc = pminfoGetProgramId(&tid, pid);
|
||||
|
||||
if (rc == IsQlaunch) {
|
||||
return Qlaunch;
|
||||
}
|
||||
|
||||
ASSERT_RESULT_OK(rc, "pminfoGetProgramId");
|
||||
|
||||
return tid;
|
||||
}
|
||||
|
||||
void Exit() {
|
||||
pmdmntExit();
|
||||
pminfoExit();
|
||||
}
|
||||
|
||||
}
|
||||
38
Source/rewrite-hoc-clk/sysmodule/src/process_management.hpp
Normal file
38
Source/rewrite-hoc-clk/sysmodule/src/process_management.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
|
||||
namespace processManagement {
|
||||
|
||||
void Initialize();
|
||||
void WaitForQLaunch();
|
||||
u64 GetCurrentApplicationId();
|
||||
void Exit();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user