Skip to content

Commit

Permalink
Detect display availability via mmio
Browse files Browse the repository at this point in the history
  • Loading branch information
averne committed Sep 17, 2024
1 parent 93e114b commit 23c1f4d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 9 additions & 0 deletions sysmodule/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@
"is_ro" : false,
"is_io" : true
}
},
{
"type" : "map",
"value" : {
"address" : "0x60006000",
"size" : "0x1000",
"is_ro" : true,
"is_io" : true
}
}
]
}
4 changes: 0 additions & 4 deletions sysmodule/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -103,7 +100,6 @@ void __appInit(void) {

void __appExit(void) {
nvExit();
pscmExit();
ommExit();
insrExit();

Expand Down
30 changes: 8 additions & 22 deletions sysmodule/src/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <common.hpp>
#include <omm.h>

#include "disp1_regs.hpp"
#include "t210_regs.hpp"
#include "nvdisp.hpp"

#include "profile.hpp"
Expand Down Expand Up @@ -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
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions sysmodule/src/profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down
27 changes: 27 additions & 0 deletions sysmodule/src/disp1_regs.hpp → sysmodule/src/t210_regs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,33 @@

#include <cstdint>

#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)

Expand Down

0 comments on commit 23c1f4d

Please sign in to comment.