From e96eaa3d7cfe9f2ac056be3ccad2a5e1e22ad9ae Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 10 Nov 2018 03:05:14 -0800 Subject: [PATCH] fatal: Implement AdjustClockTask --- stratosphere/fatal/source/fatal_main.cpp | 6 +++ stratosphere/fatal/source/fatal_task.cpp | 3 +- .../fatal/source/fatal_task_clock.cpp | 45 +++++++++++++++++++ .../fatal/source/fatal_task_clock.hpp | 31 +++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 stratosphere/fatal/source/fatal_task_clock.cpp create mode 100644 stratosphere/fatal/source/fatal_task_clock.hpp diff --git a/stratosphere/fatal/source/fatal_main.cpp b/stratosphere/fatal/source/fatal_main.cpp index e01cbd7e8..d537eff42 100644 --- a/stratosphere/fatal/source/fatal_main.cpp +++ b/stratosphere/fatal/source/fatal_main.cpp @@ -77,6 +77,11 @@ void __appInit(void) { std::abort(); } + rc = pcvInitialize(); + if (R_FAILED(rc)) { + std::abort(); + } + rc = psmInitialize(); if (R_FAILED(rc)) { std::abort(); @@ -94,6 +99,7 @@ void __appExit(void) { /* Cleanup services. */ spsmExit(); psmExit(); + pcvExit(); bpcExit(); pminfoExit(); setsysExit(); diff --git a/stratosphere/fatal/source/fatal_task.cpp b/stratosphere/fatal/source/fatal_task.cpp index 43108e88b..1c474fa0f 100644 --- a/stratosphere/fatal/source/fatal_task.cpp +++ b/stratosphere/fatal/source/fatal_task.cpp @@ -19,6 +19,7 @@ #include "fatal_task.hpp" #include "fatal_task_error_report.hpp" +#include "fatal_task_clock.hpp" #include "fatal_task_power.hpp" @@ -56,7 +57,7 @@ void RunFatalTasks(FatalContext *ctx, u64 title_id, bool error_report, Event *er /* TODO: RunTask(new ShowFatalTask(ctx, title_id, battery_event)); */ /* TODO: RunTask(new StopSoundTask(ctx, title_id)); */ /* TODO: RunTask(new BacklightControlTask(ctx, title_id)); */ - /* TODO: RunTask(new AdjustClockTask(ctx, title_id)); */ + RunTask(new AdjustClockTask(ctx, title_id)); RunTask(new PowerButtonObserveTask(ctx, title_id, erpt_event)); RunTask(new StateTransitionStopTask(ctx, title_id)); } diff --git a/stratosphere/fatal/source/fatal_task_clock.cpp b/stratosphere/fatal/source/fatal_task_clock.cpp new file mode 100644 index 000000000..fe1bf93d7 --- /dev/null +++ b/stratosphere/fatal/source/fatal_task_clock.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Atmosphère-NX + * + * 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 . + */ + +#include +#include "fatal_task_clock.hpp" + + +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; + Result rc = 0; + + if (R_FAILED((rc = pcvSetClockRate(PcvModule_Cpu, CPU_CLOCK_1020MHZ)))) { + return rc; + } + + if (R_FAILED((rc = pcvSetClockRate(PcvModule_Gpu, GPU_CLOCK_307MHZ)))) { + return rc; + } + + if (R_FAILED((rc = pcvSetClockRate(PcvModule_Emc, EMC_CLOCK_1331MHZ)))) { + return rc; + } + + return rc; +} + +Result AdjustClockTask::Run() { + return AdjustClock(); +} \ No newline at end of file diff --git a/stratosphere/fatal/source/fatal_task_clock.hpp b/stratosphere/fatal/source/fatal_task_clock.hpp new file mode 100644 index 000000000..8ceba6945 --- /dev/null +++ b/stratosphere/fatal/source/fatal_task_clock.hpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018 Atmosphère-NX + * + * 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 . + */ + +#pragma once +#include +#include +#include "fatal_task.hpp" + +class AdjustClockTask : public IFatalTask { + private: + Result AdjustClock(); + public: + AdjustClockTask(FatalContext *ctx, u64 title_id) : IFatalTask(ctx, title_id) { } + virtual Result Run() override; + virtual const char *GetName() const override { + return "AdjustClockTask"; + } +}; \ No newline at end of file