2018-11-10 11:05:14 +00:00
|
|
|
/*
|
2021-10-04 20:59:10 +01:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2018-11-10 11:05:14 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2020-05-11 23:02:10 +01:00
|
|
|
#include <stratosphere.hpp>
|
2018-11-10 11:05:14 +00:00
|
|
|
#include "fatal_task_clock.hpp"
|
|
|
|
|
2019-10-24 10:30:10 +01:00
|
|
|
namespace ams::fatal::srv {
|
2019-04-25 00:36:35 +01:00
|
|
|
|
|
|
|
|
2019-07-19 03:09:35 +01:00
|
|
|
namespace {
|
2019-04-25 00:36:35 +01:00
|
|
|
|
2019-07-19 03:09:35 +01:00
|
|
|
/* Task definition. */
|
2019-10-19 04:31:15 +01:00
|
|
|
class AdjustClockTask : public ITaskWithDefaultStack {
|
2019-07-19 03:09:35 +01:00
|
|
|
private:
|
|
|
|
Result AdjustClockForModule(PcvModule module, u32 hz);
|
|
|
|
Result AdjustClock();
|
|
|
|
public:
|
|
|
|
virtual Result Run() override;
|
|
|
|
virtual const char *GetName() const override {
|
|
|
|
return "AdjustClockTask";
|
|
|
|
}
|
|
|
|
};
|
2018-11-10 11:05:14 +00:00
|
|
|
|
2019-07-19 03:09:35 +01:00
|
|
|
/* Task global. */
|
|
|
|
AdjustClockTask g_adjust_clock_task;
|
2019-04-25 00:36:35 +01:00
|
|
|
|
2019-07-19 03:09:35 +01:00
|
|
|
/* Task implementation. */
|
|
|
|
Result AdjustClockTask::AdjustClockForModule(PcvModule module, u32 hz) {
|
2020-04-14 06:19:44 +01:00
|
|
|
if (hos::GetVersion() >= hos::Version_8_0_0) {
|
2019-07-19 03:09:35 +01:00
|
|
|
/* On 8.0.0+, convert to module id + use clkrst API. */
|
|
|
|
PcvModuleId module_id;
|
2021-10-09 22:49:53 +01:00
|
|
|
R_TRY(pcvGetModuleId(std::addressof(module_id), module));
|
2019-04-25 00:36:35 +01:00
|
|
|
|
2019-07-19 03:09:35 +01:00
|
|
|
ClkrstSession session;
|
2021-10-09 22:49:53 +01:00
|
|
|
R_TRY(clkrstOpenSession(std::addressof(session), module_id, 3));
|
|
|
|
ON_SCOPE_EXIT { clkrstCloseSession(std::addressof(session)); };
|
2019-07-19 03:09:35 +01:00
|
|
|
|
2021-10-09 22:49:53 +01:00
|
|
|
R_TRY(clkrstSetClockRate(std::addressof(session), hz));
|
2019-07-19 03:09:35 +01:00
|
|
|
} else {
|
|
|
|
/* On 1.0.0-7.0.1, use pcv API. */
|
|
|
|
R_TRY(pcvSetClockRate(module, hz));
|
|
|
|
}
|
|
|
|
|
2022-03-26 07:14:36 +00:00
|
|
|
R_SUCCEED();
|
2019-07-19 03:09:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result AdjustClockTask::AdjustClock() {
|
|
|
|
/* Fatal sets the CPU to 1020MHz, the GPU to 307 MHz, and the EMC to 1331MHz. */
|
|
|
|
constexpr u32 CPU_CLOCK_1020MHZ = 0x3CCBF700L;
|
|
|
|
constexpr u32 GPU_CLOCK_307MHZ = 0x124F8000L;
|
|
|
|
constexpr u32 EMC_CLOCK_1331MHZ = 0x4F588000L;
|
|
|
|
|
|
|
|
R_TRY(AdjustClockForModule(PcvModule_CpuBus, CPU_CLOCK_1020MHZ));
|
|
|
|
R_TRY(AdjustClockForModule(PcvModule_GPU, GPU_CLOCK_307MHZ));
|
|
|
|
R_TRY(AdjustClockForModule(PcvModule_EMC, EMC_CLOCK_1331MHZ));
|
|
|
|
|
2022-03-26 07:14:36 +00:00
|
|
|
R_SUCCEED();
|
2019-07-19 03:09:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result AdjustClockTask::Run() {
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(AdjustClock());
|
2019-07-19 03:09:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ITask *GetAdjustClockTask(const ThrowContext *ctx) {
|
|
|
|
g_adjust_clock_task.Initialize(ctx);
|
2021-10-09 22:49:53 +01:00
|
|
|
return std::addressof(g_adjust_clock_task);
|
2019-07-19 03:09:35 +01:00
|
|
|
}
|
2018-11-10 11:05:14 +00:00
|
|
|
|
2019-06-18 00:41:03 +01:00
|
|
|
}
|