From 23c1f4de932cd4fadcd8580cd9720cf34ad739b4 Mon Sep 17 00:00:00 2001 From: averne Date: Tue, 17 Sep 2024 21:40:29 +0200 Subject: [PATCH] Detect display availability via mmio --- Makefile | 2 +- sysmodule/config.json | 9 ++++++ sysmodule/src/main.cpp | 4 --- sysmodule/src/profile.cpp | 30 +++++-------------- sysmodule/src/profile.hpp | 6 ++-- .../src/{disp1_regs.hpp => t210_regs.hpp} | 27 +++++++++++++++++ 6 files changed, 47 insertions(+), 31 deletions(-) rename sysmodule/src/{disp1_regs.hpp => t210_regs.hpp} (69%) diff --git a/Makefile b/Makefile index d64908f..ea1ed45 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -export FZ_VERSION = 2.5.4 +export FZ_VERSION = 2.5.5 export FZ_COMMIT = $(shell git rev-parse --short HEAD) export FZ_TID = 0100000000000F12 diff --git a/sysmodule/config.json b/sysmodule/config.json index ad0e171..5f97f95 100644 --- a/sysmodule/config.json +++ b/sysmodule/config.json @@ -140,6 +140,15 @@ "is_ro" : false, "is_io" : true } + }, + { + "type" : "map", + "value" : { + "address" : "0x60006000", + "size" : "0x1000", + "is_ro" : true, + "is_io" : true + } } ] } diff --git a/sysmodule/src/main.cpp b/sysmodule/src/main.cpp index c35d864..970456b 100644 --- a/sysmodule/src/main.cpp +++ b/sysmodule/src/main.cpp @@ -83,9 +83,6 @@ void __appInit(void) { if (auto rc = nvInitialize(); R_FAILED(rc)) diagAbortWithResult(rc); - if (auto rc = pscmInitialize(); R_FAILED(rc)) - diagAbortWithResult(rc); - if (auto rc = ommInitialize(); R_FAILED(rc)) diagAbortWithResult(rc); @@ -103,7 +100,6 @@ void __appInit(void) { void __appExit(void) { nvExit(); - pscmExit(); ommExit(); insrExit(); diff --git a/sysmodule/src/profile.cpp b/sysmodule/src/profile.cpp index 90cfa0a..6e9987c 100644 --- a/sysmodule/src/profile.cpp +++ b/sysmodule/src/profile.cpp @@ -22,7 +22,7 @@ #include #include -#include "disp1_regs.hpp" +#include "t210_regs.hpp" #include "nvdisp.hpp" #include "profile.hpp" @@ -87,7 +87,10 @@ void ProfileManager::transition_thread_func(void *args) { // CMU resets if (!need_apply) { - mutexLock(&self->commit_mutex); + if (!(READ(self->clock_va_base + CLK_RST_CONTROLLER_CLK_OUT_ENB_L_0) & (CLK_ENB_DISP1 | CLK_ENB_DISP2)) || + !mutexTryLock(&self->commit_mutex)) + goto cmu_end; + FZ_SCOPEGUARD([self] { mutexUnlock(&self->commit_mutex); }); // Poll DISPLAY_A in handheld mode, DISPLAY_B in docked mode @@ -96,9 +99,6 @@ void ProfileManager::transition_thread_func(void *args) { auto &shadow = is_handheld ? self->context.cmu_shadow_internal : self->context.cmu_shadow_external; auto &csc = shadow.csc; - if (!self->mmio_available) - goto cmu_end; - // There is a race when waking from reset, where the configuration // sometimes gets applied before nvdrv internally disables the CMU if (!(READ(iobase + DC_DISP_DISP_COLOR_CONTROL) & CMU_ENABLE)) { @@ -167,7 +167,6 @@ void ProfileManager::event_monitor_thread_func(void *args) { auto rc = waitMulti(&idx, UINT64_MAX, waiterForEvent(&self->operation_mode_event), waiterForEvent(&self->activity_event), - waiterForEvent(&self->psc_module.event), waiterForUEvent(&self->thread_exit_event)); if (R_FAILED(rc)) return; @@ -181,15 +180,7 @@ void ProfileManager::event_monitor_thread_func(void *args) { insrGetLastTick(ins_evt_id, &self->activity_tick); break; } - case 2: { - PscPmState state; - if (R_SUCCEEDED(pscPmModuleGetRequest(&self->psc_module, &state, nullptr))) - self->mmio_available = state == PscPmState_Awake; - - pscPmModuleAcknowledge(&self->psc_module, state); - break; - } - case 3: + case 2: default: return; } @@ -198,11 +189,10 @@ void ProfileManager::event_monitor_thread_func(void *args) { Result ProfileManager::initialize() { std::uint64_t size; - if (auto rc = svcQueryMemoryMapping(&this->disp_va_base, &size, DISP_IO_BASE, DISP_IO_SIZE); R_FAILED(rc)) + if (auto rc = svcQueryMemoryMapping(&this->clock_va_base, &size, CLOCK_IO_BASE, CLOCK_IO_SIZE); R_FAILED(rc)) diagAbortWithResult(rc); - std::array deps = { u32(PscPmModuleId_Display) }; - if (auto rc = pscmGetPmModule(&this->psc_module, PscPmModuleId(125), deps.data(), deps.size(), true); R_FAILED(rc)) + if (auto rc = svcQueryMemoryMapping(&this->disp_va_base, &size, DISP_IO_BASE, DISP_IO_SIZE); R_FAILED(rc)) diagAbortWithResult(rc); if (auto rc = ommGetOperationModeChangeEvent(&this->operation_mode_event, false); R_FAILED(rc)) @@ -245,10 +235,6 @@ Result ProfileManager::finalize() { threadClose(&this->event_monitor_thread); threadClose(&this->transition_thread); - pscPmModuleFinalize(&this->psc_module); - pscPmModuleClose(&this->psc_module); - eventClose(&this->psc_module.event); - eventClose(&this->operation_mode_event); return 0; diff --git a/sysmodule/src/profile.hpp b/sysmodule/src/profile.hpp index 31a64b1..c1806d0 100644 --- a/sysmodule/src/profile.hpp +++ b/sysmodule/src/profile.hpp @@ -47,15 +47,13 @@ class ProfileManager { Context &context; DisplayController &disp; + std::uint64_t clock_va_base = 0, disp_va_base = 0; + UEvent thread_exit_event = {}; Thread transition_thread = {}, event_monitor_thread = {}; std::uint8_t transition_thread_stack[0x2000] alignas(0x1000) = {}, event_monitor_thread_stack[0x1000] alignas(0x1000) = {}; - PscPmModule psc_module = {}; - bool mmio_available = true; - std::uint64_t disp_va_base = 0; - Event operation_mode_event = {}; AppletOperationMode operation_mode = {}; diff --git a/sysmodule/src/disp1_regs.hpp b/sysmodule/src/t210_regs.hpp similarity index 69% rename from sysmodule/src/disp1_regs.hpp rename to sysmodule/src/t210_regs.hpp index be3d66b..1727b11 100644 --- a/sysmodule/src/disp1_regs.hpp +++ b/sysmodule/src/t210_regs.hpp @@ -17,6 +17,33 @@ #include +#define CLOCK_IO_BASE 0x60006000 +#define CLOCK_IO_SIZE (0x1000) + +#define CLK_RST_CONTROLLER_CLK_OUT_ENB_L 0x10 +# define CLK_ENB_ISPB (1 << 3) +# define CLK_ENB_RTC (1 << 4) +# define CLK_ENB_TMR (1 << 5) +# define CLK_ENB_UARTA (1 << 6) +# define CLK_ENB_UARTB (1 << 7) +# define CLK_ENB_GPIO (1 << 8) +# define CLK_ENB_SDMMC2 (1 << 9) +# define CLK_ENB_SPDIF (1 << 10) +# define CLK_ENB_I2S2 (1 << 11) +# define CLK_ENB_I2C1 (1 << 12) +# define CLK_ENB_SDMMC1 (1 << 14) +# define CLK_ENB_SDMMC4 (1 << 15) +# define CLK_ENB_PWM (1 << 17) +# define CLK_ENB_I2S3 (1 << 18) +# define CLK_ENB_VI (1 << 20) +# define CLK_ENB_USBD (1 << 22) +# define CLK_ENB_ISP (1 << 23) +# define CLK_ENB_DISP2 (1 << 26) +# define CLK_ENB_DISP1 (1 << 27) +# define CLK_ENB_HOST1X (1 << 28) +# define CLK_ENB_I2S (1 << 30) +# define CLK_ENB_CACHE2 (1 << 31) + #define DISP_IO_BASE 0x54200000 #define DISP_IO_SIZE (0x80000)