Revert "hoc-clk: add live vdd2, live boost clock and basic pwm dimming"

This reverts commit 15b7df8ef1.
This commit is contained in:
souldbminersmwc
2025-11-09 16:14:52 -05:00
parent 22ec140738
commit 21a3f953d7
3804 changed files with 435 additions and 570162 deletions

View File

@@ -1,142 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#define NX_SERVICE_ASSUME_NON_DOMAIN
#include "../service_guard.h"
#include "sm_ams.os.horizon.h"
static Result _smAtmosphereCmdHas(bool *out, SmServiceName name, u32 cmd_id) {
u8 tmp = 0;
Result rc = tipcDispatchInOut(smGetServiceSessionTipc(), cmd_id, name, tmp);
if (R_SUCCEEDED(rc) && out) *out = tmp & 1;
return rc;
}
static Result _smAtmosphereCmdInServiceNameNoOut(SmServiceName name, TipcService *srv, u32 cmd_id) {
return tipcDispatchIn(srv, cmd_id, name);
}
static Result _smAtmosphereDetachClient(TipcService *srv) {
return tipcDispatch(srv, 4, .in_send_pid = true);
}
Result smAtmosphereHasService(bool *out, SmServiceName name) {
return _smAtmosphereCmdHas(out, name, 65100);
}
Result smAtmosphereWaitService(SmServiceName name) {
return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSessionTipc(), 65101);
}
Result smAtmosphereHasMitm(bool *out, SmServiceName name) {
return _smAtmosphereCmdHas(out, name, 65004);
}
Result smAtmosphereWaitMitm(SmServiceName name) {
return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSessionTipc(), 65005);
}
static TipcService g_smAtmosphereMitmSrv;
NX_GENERATE_SERVICE_GUARD(smAtmosphereMitm);
Result _smAtmosphereMitmInitialize(void) {
return smAtmosphereOpenSession(&g_smAtmosphereMitmSrv);
}
void _smAtmosphereMitmCleanup(void) {
smAtmosphereCloseSession(&g_smAtmosphereMitmSrv);
}
TipcService* smAtmosphereMitmGetServiceSession(void) {
return &g_smAtmosphereMitmSrv;
}
Result smAtmosphereOpenSession(TipcService *out) {
Handle sm_handle;
Result rc = svcConnectToNamedPort(&sm_handle, "sm:");
while (R_VALUE(rc) == KERNELRESULT(NotFound)) {
svcSleepThread(50000000ul);
rc = svcConnectToNamedPort(&sm_handle, "sm:");
}
if (R_SUCCEEDED(rc)) {
tipcCreate(out, sm_handle);
}
if (R_SUCCEEDED(rc)) {
rc = tipcDispatch(out, 0, .in_send_pid = true);
}
return rc;
}
void smAtmosphereCloseSession(TipcService *srv) {
Result rc = _smAtmosphereDetachClient(srv);
if (R_FAILED(rc)) {
svcBreak(BreakReason_Panic, (uintptr_t)&rc, sizeof(rc));
}
tipcClose(srv);
}
Result smAtmosphereMitmInstall(TipcService *fwd_srv, Handle *handle_out, Handle *query_out, SmServiceName name) {
Handle tmp_handles[2];
Result rc = tipcDispatchIn(fwd_srv, 65000, name,
.out_handle_attrs = { SfOutHandleAttr_HipcMove, SfOutHandleAttr_HipcMove },
.out_handles = tmp_handles,
);
if (R_SUCCEEDED(rc)) {
*handle_out = tmp_handles[0];
*query_out = tmp_handles[1];
}
return rc;
}
Result smAtmosphereMitmUninstall(SmServiceName name) {
return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSessionTipc(), 65001);
}
Result smAtmosphereMitmDeclareFuture(SmServiceName name) {
return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSessionTipc(), 65006);
}
Result smAtmosphereMitmClearFuture(SmServiceName name) {
return _smAtmosphereCmdInServiceNameNoOut(name, smGetServiceSessionTipc(), 65007);
}
Result smAtmosphereMitmAcknowledgeSession(Service *srv_out, void *_out, SmServiceName name) {
struct {
u64 process_id;
u64 program_id;
u64 keys_held;
u64 flags;
} *out = _out;
_Static_assert(sizeof(*out) == 0x20, "sizeof(*out) == 0x20");
Handle tmp_handle;
Result rc = tipcDispatchInOut(&g_smAtmosphereMitmSrv, 65003, name, *out,
.out_handle_attrs = { SfOutHandleAttr_HipcMove },
.out_handles = &tmp_handle,
);
if (R_SUCCEEDED(rc)) {
serviceCreate(srv_out, tmp_handle);
}
return rc;
}

View File

@@ -1,39 +0,0 @@
/**
* @file sm_ams.h
* @brief Service manager (sm) IPC wrapper for Atmosphere extensions.
* @author SciresM
* @copyright libnx Authors
*/
#pragma once
#if defined(ATMOSPHERE_OS_HORIZON)
#include <switch.h>
#ifdef __cplusplus
extern "C" {
#endif
Result smAtmosphereHasService(bool *out, SmServiceName name);
Result smAtmosphereWaitService(SmServiceName name);
Result smAtmosphereHasMitm(bool *out, SmServiceName name);
Result smAtmosphereWaitMitm(SmServiceName name);
Result smAtmosphereMitmInitialize(void);
void smAtmosphereMitmExit(void);
TipcService *smAtmosphereMitmGetServiceSession();
Result smAtmosphereOpenSession(TipcService *out);
void smAtmosphereCloseSession(TipcService *srv);
Result smAtmosphereMitmInstall(TipcService *fwd_srv, Handle *handle_out, Handle *query_out, SmServiceName name);
Result smAtmosphereMitmUninstall(SmServiceName name);
Result smAtmosphereMitmDeclareFuture(SmServiceName name);
Result smAtmosphereMitmClearFuture(SmServiceName name);
Result smAtmosphereMitmAcknowledgeSession(Service *srv_out, void *info_out, SmServiceName name);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,106 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "sm_utils.hpp"
namespace ams::sm {
#if defined(ATMOSPHERE_OS_HORIZON)
namespace {
constinit int g_ref_count = 0;
constinit os::SdkMutex g_mutex;
}
/* Initialization. */
Result Initialize() {
std::scoped_lock lk(g_mutex);
if (g_ref_count > 0) {
++g_ref_count;
} else {
R_TRY(::smInitialize());
g_ref_count = 1;
}
R_SUCCEED();
}
Result Finalize() {
/* NOTE: Nintendo does nothing here. */
R_SUCCEED();
}
/* Ordinary SM API. */
Result GetServiceHandle(os::NativeHandle *out, ServiceName name) {
R_RETURN(smGetServiceOriginal(out, impl::ConvertName(name)));
}
Result RegisterService(os::NativeHandle *out, ServiceName name, size_t max_sessions, bool is_light) {
R_RETURN(smRegisterService(out, impl::ConvertName(name), is_light, static_cast<int>(max_sessions)));
}
Result UnregisterService(ServiceName name) {
R_RETURN(smUnregisterService(impl::ConvertName(name)));
}
/* Atmosphere extensions. */
Result HasService(bool *out, ServiceName name) {
R_RETURN(smAtmosphereHasService(out, impl::ConvertName(name)));
}
Result WaitService(ServiceName name) {
R_RETURN(smAtmosphereWaitService(impl::ConvertName(name)));
}
#else
Result Initialize() {
R_SUCCEED();
}
Result Finalize() {
R_SUCCEED();
}
/* Ordinary SM API. */
Result GetServiceHandle(os::NativeHandle *out, ServiceName name) {
AMS_UNUSED(out, name);
AMS_ABORT("TODO?");
}
Result RegisterService(os::NativeHandle *out, ServiceName name, size_t max_sessions, bool is_light) {
AMS_UNUSED(out, name, max_sessions, is_light);
AMS_ABORT("TODO?");
}
Result UnregisterService(ServiceName name) {
AMS_UNUSED(name);
AMS_ABORT("TODO?");
}
/* Atmosphere extensions. */
Result HasService(bool *out, ServiceName name) {
AMS_UNUSED(out, name);
AMS_ABORT("TODO?");
}
Result WaitService(ServiceName name) {
AMS_UNUSED(name);
AMS_ABORT("TODO?");
}
#endif
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "sm_utils.hpp"
#if defined(ATMOSPHERE_OS_HORIZON)
#include "smm_ams.os.horizon.h"
#endif
namespace ams::sm::manager {
#if defined(ATMOSPHERE_OS_HORIZON)
/* Manager API. */
Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus status, const void *acid, size_t acid_size, const void *aci, size_t aci_size) {
static_assert(sizeof(status) == sizeof(CfgOverrideStatus), "CfgOverrideStatus definition");
R_RETURN(smManagerAtmosphereRegisterProcess(static_cast<u64>(process_id), static_cast<u64>(program_id), reinterpret_cast<const CfgOverrideStatus *>(std::addressof(status)), acid, acid_size, aci, aci_size));
}
Result UnregisterProcess(os::ProcessId process_id) {
R_RETURN(smManagerUnregisterProcess(static_cast<u64>(process_id)));
}
/* Atmosphere extensions. */
Result EndInitialDefers() {
R_RETURN(smManagerAtmosphereEndInitialDefers());
}
Result HasMitm(bool *out, ServiceName name) {
R_RETURN(smManagerAtmosphereHasMitm(out, impl::ConvertName(name)));
}
#endif
}

View File

@@ -1,58 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "sm_utils.hpp"
namespace ams::sm::mitm {
#if defined(ATMOSPHERE_OS_HORIZON)
#if AMS_SF_MITM_SUPPORTED
/* Mitm API. */
Result InstallMitm(os::NativeHandle *out_port, os::NativeHandle *out_query, ServiceName name) {
R_RETURN(impl::DoWithPerThreadSession([&](TipcService *fwd) {
R_RETURN(smAtmosphereMitmInstall(fwd, out_port, out_query, impl::ConvertName(name)));
}));
}
Result UninstallMitm(ServiceName name) {
R_RETURN(smAtmosphereMitmUninstall(impl::ConvertName(name)));
}
Result DeclareFutureMitm(ServiceName name) {
R_RETURN(smAtmosphereMitmDeclareFuture(impl::ConvertName(name)));
}
Result ClearFutureMitm(ServiceName name) {
R_RETURN(smAtmosphereMitmClearFuture(impl::ConvertName(name)));
}
Result AcknowledgeSession(Service *out_service, MitmProcessInfo *out_info, ServiceName name) {
return impl::DoWithMitmAcknowledgementSession([&]() {
R_RETURN(smAtmosphereMitmAcknowledgeSession(out_service, reinterpret_cast<void *>(out_info), impl::ConvertName(name)));
});
}
Result HasMitm(bool *out, ServiceName name) {
R_RETURN(smAtmosphereHasMitm(out, impl::ConvertName(name)));
}
Result WaitMitm(ServiceName name) {
R_RETURN(smAtmosphereWaitMitm(impl::ConvertName(name)));
}
#endif
#endif
}

View File

@@ -1,38 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "sm_utils.hpp"
namespace ams::sm::impl {
namespace {
/* Globals. */
constinit os::SdkRecursiveMutex g_mitm_ack_session_mutex;
constinit os::SdkRecursiveMutex g_per_thread_session_mutex;
}
/* Utilities. */
os::SdkRecursiveMutex &GetMitmAcknowledgementSessionMutex() {
return g_mitm_ack_session_mutex;
}
os::SdkRecursiveMutex &GetPerThreadSessionMutex() {
return g_per_thread_session_mutex;
}
}

View File

@@ -1,61 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
#if defined(ATMOSPHERE_OS_HORIZON)
#include "sm_ams.os.horizon.h"
#endif
namespace ams::sm::impl {
#if defined(ATMOSPHERE_OS_HORIZON)
/* Utilities. */
os::SdkRecursiveMutex &GetMitmAcknowledgementSessionMutex();
os::SdkRecursiveMutex &GetPerThreadSessionMutex();
template<typename F>
Result DoWithMitmAcknowledgementSession(F f) {
std::scoped_lock lk(GetMitmAcknowledgementSessionMutex());
{
R_ABORT_UNLESS(smAtmosphereMitmInitialize());
ON_SCOPE_EXIT { smAtmosphereMitmExit(); };
R_RETURN(f());
}
}
template<typename F>
Result DoWithPerThreadSession(F f) {
TipcService srv;
{
std::scoped_lock lk(GetPerThreadSessionMutex());
R_ABORT_UNLESS(smAtmosphereOpenSession(std::addressof(srv)));
}
{
ON_SCOPE_EXIT { smAtmosphereCloseSession(std::addressof(srv)); };
R_RETURN(f(std::addressof(srv)));
}
}
constexpr ALWAYS_INLINE SmServiceName ConvertName(sm::ServiceName name) {
static_assert(sizeof(SmServiceName) == sizeof(sm::ServiceName));
return std::bit_cast<SmServiceName>(name);
}
#endif
}

View File

@@ -1,49 +0,0 @@
/*
* Copyright (c) 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 <http://www.gnu.org/licenses/>.
*/
#include "smm_ams.os.horizon.h"
Result smManagerAtmosphereEndInitialDefers(void) {
return tipcDispatch(smManagerTipcGetServiceSession(), 65000);
}
Result smManagerAtmosphereRegisterProcess(u64 pid, u64 tid, const CfgOverrideStatus *status, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size) {
const struct {
u64 pid;
u64 tid;
CfgOverrideStatus status;
} in = { pid, tid, *status };
return tipcDispatchIn(smManagerTipcGetServiceSession(), 65002, in,
.buffer_attrs = {
SfBufferAttr_In | SfBufferAttr_HipcMapAlias,
SfBufferAttr_In | SfBufferAttr_HipcMapAlias,
},
.buffers = {
{ acid_sac, acid_sac_size },
{ aci_sac, aci_sac_size },
},
);
}
static Result _smManagerAtmosphereCmdHas(bool *out, SmServiceName name, u32 cmd_id) {
u8 tmp;
Result rc = tipcDispatchInOut(smManagerTipcGetServiceSession(), cmd_id, name, tmp);
if (R_SUCCEEDED(rc) && out) *out = tmp & 1;
return rc;
}
Result smManagerAtmosphereHasMitm(bool *out, SmServiceName name) {
return _smManagerAtmosphereCmdHas(out, name, 65001);
}

View File

@@ -1,30 +0,0 @@
/**
* @file smm_ams.h
* @brief Service manager manager (sm:m) IPC wrapper for Atmosphere extensions.
* @author SciresM
* @copyright libnx Authors
*/
#pragma once
#if defined(ATMOSPHERE_OS_HORIZON)
#include <switch.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
u64 keys_held;
u64 flags;
} CfgOverrideStatus;
Result smManagerAtmosphereEndInitialDefers(void);
Result smManagerAtmosphereRegisterProcess(u64 pid, u64 tid, const CfgOverrideStatus *status, const void *acid_sac, size_t acid_sac_size, const void *aci_sac, size_t aci_sac_size);
Result smManagerAtmosphereHasMitm(bool *out, SmServiceName name);
#ifdef __cplusplus
}
#endif
#endif