From c490f5091deb5927a9b4ca8b2f0a265822c59ba6 Mon Sep 17 00:00:00 2001 From: Lightos1 <124387232+Lightos1@users.noreply.github.com> Date: Sun, 28 Jun 2026 20:18:23 +0200 Subject: [PATCH 1/5] clkrst: add clkrstSetMinVClockRate and clkrstGetDvfsTable --- nx/include/switch/services/clkrst.h | 2 ++ nx/source/services/clkrst.c | 33 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/nx/include/switch/services/clkrst.h b/nx/include/switch/services/clkrst.h index 761d42ea06..98b91ed983 100644 --- a/nx/include/switch/services/clkrst.h +++ b/nx/include/switch/services/clkrst.h @@ -28,3 +28,5 @@ void clkrstCloseSession(ClkrstSession* session); Result clkrstSetClockRate(ClkrstSession* session, u32 hz); Result clkrstGetClockRate(ClkrstSession* session, u32 *out_hz); Result clkrstGetPossibleClockRates(ClkrstSession *session, u32 *rates, s32 max_count, PcvClockRatesListType *out_type, s32 *out_count); +Result clkrstGetDvfsTable(ClkrstSession *session, u32 *freq_table, s32 freq_count, u32 *voltage_table, s32 voltage_count, s32 *out_count); +Result clkrstSetMinVClockRate(ClkrstSession *session, u32 hz); \ No newline at end of file diff --git a/nx/source/services/clkrst.c b/nx/source/services/clkrst.c index b90914378e..4ed93a7cd3 100644 --- a/nx/source/services/clkrst.c +++ b/nx/source/services/clkrst.c @@ -61,3 +61,36 @@ Result clkrstGetPossibleClockRates(ClkrstSession *session, u32 *rates, s32 max_c return rc; } + +Result clkrstGetDvfsTable(ClkrstSession *session, u32 *freq_table, s32 freq_count, u32 *voltage_table, s32 voltage_count, s32 *out_count) { + if (hosversionBefore(3,0,0)) { + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + } + + const struct { + s32 freq_count; + s32 voltage_count; + } in = { freq_count, voltage_count }; + + s32 out = 0; + Result rc = serviceDispatchInOut(&session->s, 11, in, out, + .buffer_attrs = { + SfBufferAttr_Out | (hosversionAtLeast(7,0,0) ? SfBufferAttr_HipcAutoSelect : SfBufferAttr_HipcPointer), + SfBufferAttr_Out | (hosversionAtLeast(7,0,0) ? SfBufferAttr_HipcAutoSelect : SfBufferAttr_HipcPointer), + }, + .buffers = { + { freq_table, freq_count * sizeof(u32) }, + { voltage_table, voltage_count * sizeof(u32) }, + }, + ); + + if (R_SUCCEEDED(rc) && out_count) { + *out_count = out; + } + + return rc; +} + +Result clkrstSetMinVClockRate(ClkrstSession *session, u32 hz) { + return serviceDispatchIn(&session->s, 9, hz); +} From 69c322684a6f0821683a487e26f438bc5342bf41 Mon Sep 17 00:00:00 2001 From: Lightos1 <124387232+Lightos1@users.noreply.github.com> Date: Sun, 28 Jun 2026 20:41:38 +0200 Subject: [PATCH 2/5] change names --- nx/include/switch/services/clkrst.h | 2 +- nx/source/services/clkrst.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nx/include/switch/services/clkrst.h b/nx/include/switch/services/clkrst.h index 98b91ed983..9d0ad0aefa 100644 --- a/nx/include/switch/services/clkrst.h +++ b/nx/include/switch/services/clkrst.h @@ -28,5 +28,5 @@ void clkrstCloseSession(ClkrstSession* session); Result clkrstSetClockRate(ClkrstSession* session, u32 hz); Result clkrstGetClockRate(ClkrstSession* session, u32 *out_hz); Result clkrstGetPossibleClockRates(ClkrstSession *session, u32 *rates, s32 max_count, PcvClockRatesListType *out_type, s32 *out_count); -Result clkrstGetDvfsTable(ClkrstSession *session, u32 *freq_table, s32 freq_count, u32 *voltage_table, s32 voltage_count, s32 *out_count); +Result clkrstGetDvfsTable(ClkrstSession *session, u32 *out_rate_table, s32 in_rate_count, u32 *out_voltage_table, s32 in_voltage_count, s32 *out_count); Result clkrstSetMinVClockRate(ClkrstSession *session, u32 hz); \ No newline at end of file diff --git a/nx/source/services/clkrst.c b/nx/source/services/clkrst.c index 4ed93a7cd3..66671ebb29 100644 --- a/nx/source/services/clkrst.c +++ b/nx/source/services/clkrst.c @@ -62,15 +62,15 @@ Result clkrstGetPossibleClockRates(ClkrstSession *session, u32 *rates, s32 max_c return rc; } -Result clkrstGetDvfsTable(ClkrstSession *session, u32 *freq_table, s32 freq_count, u32 *voltage_table, s32 voltage_count, s32 *out_count) { +Result clkrstGetDvfsTable(ClkrstSession *session, u32 *out_rate_table, s32 in_rate_count, u32 *out_voltage_table, s32 in_voltage_count, s32 *out_count) { if (hosversionBefore(3,0,0)) { return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); } const struct { - s32 freq_count; + s32 rate_count; s32 voltage_count; - } in = { freq_count, voltage_count }; + } in = { in_rate_count, in_voltage_count }; s32 out = 0; Result rc = serviceDispatchInOut(&session->s, 11, in, out, @@ -79,8 +79,8 @@ Result clkrstGetDvfsTable(ClkrstSession *session, u32 *freq_table, s32 freq_coun SfBufferAttr_Out | (hosversionAtLeast(7,0,0) ? SfBufferAttr_HipcAutoSelect : SfBufferAttr_HipcPointer), }, .buffers = { - { freq_table, freq_count * sizeof(u32) }, - { voltage_table, voltage_count * sizeof(u32) }, + { out_rate_table, in_rate_count * sizeof(u32) }, + { out_voltage_table, in_voltage_count * sizeof(u32) }, }, ); From c3b184e3ed535a31bd53ed60a8146790fc3502ac Mon Sep 17 00:00:00 2001 From: Lightos1 <124387232+Lightos1@users.noreply.github.com> Date: Tue, 30 Jun 2026 11:02:58 +0200 Subject: [PATCH 3/5] Change function order/names --- nx/include/switch/services/clkrst.h | 2 +- nx/source/services/clkrst.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nx/include/switch/services/clkrst.h b/nx/include/switch/services/clkrst.h index 9d0ad0aefa..e329254740 100644 --- a/nx/include/switch/services/clkrst.h +++ b/nx/include/switch/services/clkrst.h @@ -28,5 +28,5 @@ void clkrstCloseSession(ClkrstSession* session); Result clkrstSetClockRate(ClkrstSession* session, u32 hz); Result clkrstGetClockRate(ClkrstSession* session, u32 *out_hz); Result clkrstGetPossibleClockRates(ClkrstSession *session, u32 *rates, s32 max_count, PcvClockRatesListType *out_type, s32 *out_count); +Result clkrstSetMinimumVoltageClockRate(ClkrstSession *session, u32 hz); Result clkrstGetDvfsTable(ClkrstSession *session, u32 *out_rate_table, s32 in_rate_count, u32 *out_voltage_table, s32 in_voltage_count, s32 *out_count); -Result clkrstSetMinVClockRate(ClkrstSession *session, u32 hz); \ No newline at end of file diff --git a/nx/source/services/clkrst.c b/nx/source/services/clkrst.c index 66671ebb29..ec98f79069 100644 --- a/nx/source/services/clkrst.c +++ b/nx/source/services/clkrst.c @@ -45,6 +45,10 @@ Result clkrstGetClockRate(ClkrstSession* session, u32 *out_hz) { return serviceDispatchOut(&session->s, 8, *out_hz); } +Result clkrstSetMinimumVoltageClockRate(ClkrstSession *session, u32 hz) { + return serviceDispatchIn(&session->s, 9, hz); +} + Result clkrstGetPossibleClockRates(ClkrstSession *session, u32 *rates, s32 max_count, PcvClockRatesListType *out_type, s32 *out_count) { struct { s32 type; @@ -90,7 +94,3 @@ Result clkrstGetDvfsTable(ClkrstSession *session, u32 *out_rate_table, s32 in_ra return rc; } - -Result clkrstSetMinVClockRate(ClkrstSession *session, u32 hz) { - return serviceDispatchIn(&session->s, 9, hz); -} From c5b49b274d7c0c5d5b48f2c51890140056ec8d8f Mon Sep 17 00:00:00 2001 From: Lightos1 <124387232+Lightos1@users.noreply.github.com> Date: Tue, 30 Jun 2026 11:03:59 +0200 Subject: [PATCH 4/5] correct function order in header --- nx/include/switch/services/clkrst.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nx/include/switch/services/clkrst.h b/nx/include/switch/services/clkrst.h index e329254740..57d3502c53 100644 --- a/nx/include/switch/services/clkrst.h +++ b/nx/include/switch/services/clkrst.h @@ -27,6 +27,6 @@ Result clkrstOpenSession(ClkrstSession* session_out, PcvModuleId module_id, u32 void clkrstCloseSession(ClkrstSession* session); Result clkrstSetClockRate(ClkrstSession* session, u32 hz); Result clkrstGetClockRate(ClkrstSession* session, u32 *out_hz); -Result clkrstGetPossibleClockRates(ClkrstSession *session, u32 *rates, s32 max_count, PcvClockRatesListType *out_type, s32 *out_count); Result clkrstSetMinimumVoltageClockRate(ClkrstSession *session, u32 hz); +Result clkrstGetPossibleClockRates(ClkrstSession *session, u32 *rates, s32 max_count, PcvClockRatesListType *out_type, s32 *out_count); Result clkrstGetDvfsTable(ClkrstSession *session, u32 *out_rate_table, s32 in_rate_count, u32 *out_voltage_table, s32 in_voltage_count, s32 *out_count); From 315d1e063b028a32f109f77d28febf9adb918b71 Mon Sep 17 00:00:00 2001 From: Lightos1 <124387232+Lightos1@users.noreply.github.com> Date: Tue, 30 Jun 2026 21:22:46 +0200 Subject: [PATCH 5/5] clkrstGetDvfsTable: remove reduntant firmware version checks --- nx/source/services/clkrst.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/nx/source/services/clkrst.c b/nx/source/services/clkrst.c index ec98f79069..54984c77b3 100644 --- a/nx/source/services/clkrst.c +++ b/nx/source/services/clkrst.c @@ -67,10 +67,6 @@ Result clkrstGetPossibleClockRates(ClkrstSession *session, u32 *rates, s32 max_c } Result clkrstGetDvfsTable(ClkrstSession *session, u32 *out_rate_table, s32 in_rate_count, u32 *out_voltage_table, s32 in_voltage_count, s32 *out_count) { - if (hosversionBefore(3,0,0)) { - return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - } - const struct { s32 rate_count; s32 voltage_count; @@ -79,8 +75,8 @@ Result clkrstGetDvfsTable(ClkrstSession *session, u32 *out_rate_table, s32 in_ra s32 out = 0; Result rc = serviceDispatchInOut(&session->s, 11, in, out, .buffer_attrs = { - SfBufferAttr_Out | (hosversionAtLeast(7,0,0) ? SfBufferAttr_HipcAutoSelect : SfBufferAttr_HipcPointer), - SfBufferAttr_Out | (hosversionAtLeast(7,0,0) ? SfBufferAttr_HipcAutoSelect : SfBufferAttr_HipcPointer), + SfBufferAttr_Out | SfBufferAttr_HipcAutoSelect, + SfBufferAttr_Out | SfBufferAttr_HipcAutoSelect, }, .buffers = { { out_rate_table, in_rate_count * sizeof(u32) },