This commit is contained in:
hanai3Bi
2023-04-01 01:49:31 +03:00
committed by hanabbi
parent 63bbde2f58
commit 3db0b9b380
210 changed files with 1286 additions and 48394 deletions

View File

@@ -1,26 +0,0 @@
/*
sys-clk manager, a sys-clk frontend homebrew
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
Copyright (C) 2019 m4xw
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "ipc.h"
#include <sysclk.h>
#include <sysclk/client/ipc.h>

View File

@@ -1,43 +0,0 @@
/*
sys-clk manager, a sys-clk frontend homebrew
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
Copyright (C) 2019 m4xw
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "types.h"
#ifdef __SWITCH__
#ifdef __cplusplus
extern "C" {
#endif
#include <switch.h>
#ifdef __cplusplus
}
#endif
#else
#include "pc_shim/nacp.h"
#include "pc_shim/ns.h"
#include "pc_shim/types.h"
#endif

View File

@@ -1,313 +0,0 @@
/*
sys-clk manager, a sys-clk frontend homebrew
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
Copyright (C) 2019 m4xw
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that 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 <https://www.gnu.org/licenses/>.
*/
#include "client.h"
#include <string.h>
#include <stdlib.h>
static SysClkShimServer* g_server = NULL;
bool sysclkIpcRunning()
{
return true;
}
Result sysclkIpcInitialize()
{
if(!g_server)
{
g_server = new SysClkShimServer();
g_server->SetContextApplicationId(0x0100000000001000ULL);
g_server->SetContextHz(SysClkModule_CPU, 1020000000);
g_server->SetContextHz(SysClkModule_GPU, 307200000);
g_server->SetContextHz(SysClkModule_MEM, 1065600000);
g_server->SetContextTemp(SysClkThermalSensor_PCB, 45700);
g_server->SetContextTemp(SysClkThermalSensor_SOC, 48200);
g_server->SetContextEnabled(true);
g_server->SetProfile(0x010000000000F002, SysClkModule_CPU, SysClkProfile_Docked, 1224);
g_server->SetProfile(0x010000000000F002, SysClkModule_GPU, SysClkProfile_Docked, 921);
g_server->SetProfile(0x010000000000F002, SysClkModule_MEM, SysClkProfile_Docked, 1600);
g_server->SetProfile(0x010000000000F002, SysClkModule_CPU, SysClkProfile_Handheld, 1224);
g_server->SetProfile(0x010000000000F002, SysClkModule_MEM, SysClkProfile_Handheld, 1600);
g_server->SetConfigValue(SysClkConfigValue_CsvWriteIntervalMs, 5000);
}
return 0;
}
void sysclkIpcExit()
{
if(g_server)
delete g_server;
}
Result sysclkIpcGetAPIVersion(u32* out_ver)
{
*out_ver = SYSCLK_IPC_API_VERSION;
return 0;
}
Result sysclkIpcGetVersionString(char* out, size_t len)
{
strncpy(out, "- shim server -", len-1);
return 0;
}
Result sysclkIpcGetCurrentContext(SysClkContext* out_context)
{
g_server->CopyContext(out_context);
return 0;
}
Result sysclkIpcGetProfileCount(u64 tid, u8* out_count)
{
*out_count = g_server->CountProfiles(tid);
return 0;
}
Result sysclkIpcGetProfiles(u64 tid, SysClkTitleProfileList* out_profiles)
{
g_server->GetProfiles(tid, out_profiles);
return 0;
}
Result sysclkIpcSetProfiles(u64 tid, SysClkTitleProfileList* profiles)
{
g_server->SetProfiles(tid, profiles);
return 0;
}
Result sysclkIpcSetEnabled(bool enabled)
{
g_server->SetContextEnabled(enabled);
if(enabled)
{
g_server->SetContextTemp(SysClkThermalSensor_PCB, 45700);
g_server->SetContextTemp(SysClkThermalSensor_SOC, 48200);
}
else
{
g_server->SetContextTemp(SysClkThermalSensor_PCB, 34200);
g_server->SetContextTemp(SysClkThermalSensor_SOC, 42800);
}
return 0;
}
Result sysclkIpcExitCmd()
{
return 0;
}
Result sysclkIpcSetOverride(SysClkModule module, u32 hz)
{
g_server->SetContextOverride(module, hz);
return 0;
}
Result sysclkIpcGetConfigValues(SysClkConfigValueList* out_configValues)
{
g_server->GetConfigValues(out_configValues);
return 0;
}
Result sysclkIpcSetConfigValues(SysClkConfigValueList* configValues)
{
g_server->SetConfigValues(configValues);
return 0;
}
SysClkShimServer::SysClkShimServer()
{
this->store = std::map<std::tuple<u64, SysClkModule, SysClkProfile>, u32>();
this->SetContextApplicationId(0);
this->SetContextHz(SysClkModule_CPU, 0);
this->SetContextHz(SysClkModule_GPU, 0);
this->SetContextHz(SysClkModule_MEM, 0);
this->SetContextOverride(SysClkModule_CPU, 0);
this->SetContextOverride(SysClkModule_GPU, 0);
this->SetContextOverride(SysClkModule_MEM, 0);
this->SetContextTemp(SysClkThermalSensor_PCB, 0);
this->SetContextTemp(SysClkThermalSensor_SOC, 0);
this->SetContextProfile(SysClkProfile_Handheld);
this->SetContextEnabled(false);
for(int kval = 0; kval < SysClkConfigValue_EnumMax; kval++)
{
this->configValues[kval] = sysclkDefaultConfigValue((SysClkConfigValue)kval);
}
}
void SysClkShimServer::SetContextApplicationId(u64 tid)
{
this->context.applicationId = tid;
}
void SysClkShimServer::SetContextHz(SysClkModule module, u32 hz)
{
if(module < SysClkModule_EnumMax)
{
this->context.freqs[module] = hz;
}
}
void SysClkShimServer::SetContextTemp(SysClkThermalSensor sensor, u32 temp)
{
if(sensor < SysClkThermalSensor_EnumMax)
{
this->context.temps[sensor] = temp;
}
}
void SysClkShimServer::CopyContext(SysClkContext* out_context)
{
memcpy(out_context, &this->context, sizeof(SysClkContext));
}
void SysClkShimServer::SetContextProfile(SysClkProfile profile)
{
if(profile < SysClkProfile_EnumMax)
{
this->context.profile = profile;
}
}
void SysClkShimServer::SetContextEnabled(bool enabled)
{
this->context.enabled = enabled;
}
void SysClkShimServer::SetProfile(uint64_t applicationId, SysClkModule module, SysClkProfile profile, u32 mhz)
{
std::tuple<u64, SysClkModule, SysClkProfile> key = std::make_tuple(applicationId, module, profile);
if(mhz > 0)
{
this->store[key] = mhz;
}
else
{
this->store.erase(key);
}
}
u32 SysClkShimServer::GetProfileMhz(uint64_t applicationId, SysClkModule module, SysClkProfile profile)
{
std::tuple<u64, SysClkModule, SysClkProfile> key = std::make_tuple(applicationId, module, profile);
std::map<std::tuple<u64, SysClkModule, SysClkProfile>, u32>::iterator it = this->store.find(key);
if(it != this->store.end())
{
return it->second;
}
return 0;
}
void SysClkShimServer::GetProfiles(u64 applicationId, SysClkTitleProfileList* out_profiles)
{
for(unsigned int profile = 0; profile < SysClkProfile_EnumMax; profile++)
{
for(unsigned int module = 0; module < SysClkModule_EnumMax; module++)
{
out_profiles->mhzMap[profile][module] = this->GetProfileMhz(applicationId, (SysClkModule)module, (SysClkProfile)profile);
}
}
}
void SysClkShimServer::SetProfiles(u64 applicationId, SysClkTitleProfileList* profiles)
{
for(unsigned int profile = 0; profile < SysClkProfile_EnumMax; profile++)
{
for(unsigned int module = 0; module < SysClkModule_EnumMax; module++)
{
this->SetProfile(applicationId, (SysClkModule)module, (SysClkProfile)profile, profiles->mhzMap[profile][module]);
}
}
}
u8 SysClkShimServer::CountProfiles(u64 applicationId)
{
return std::accumulate(
std::begin(this->store),
std::end(this->store),
0,
[applicationId] (u8 value, const std::map<std::tuple<u64, SysClkModule, SysClkProfile>, u32>::value_type& p)
{
if(std::get<0>(p.first) == applicationId)
{
value++;
}
return value;
}
);
}
void SysClkShimServer::SetContextOverride(SysClkModule module, u32 hz)
{
if(SYSCLK_ENUM_VALID(SysClkModule, module))
{
this->context.overrideFreqs[module] = hz;
}
}
u64 SysClkShimServer::GetConfigValue(SysClkConfigValue kval)
{
if(SYSCLK_ENUM_VALID(SysClkConfigValue, kval))
{
return this->configValues[kval];
}
return 0;
}
void SysClkShimServer::SetConfigValue(SysClkConfigValue kval, u64 val)
{
if(SYSCLK_ENUM_VALID(SysClkConfigValue, kval))
{
if(sysclkValidConfigValue(kval, this->configValues[kval]))
{
this->configValues[kval] = val;
}
else
{
this->configValues[kval] = sysclkDefaultConfigValue(kval);
}
}
}
void SysClkShimServer::GetConfigValues(SysClkConfigValueList* out_configValues)
{
for(unsigned int kval = 0; kval < SysClkConfigValue_EnumMax; kval++)
{
out_configValues->values[kval] = this->GetConfigValue((SysClkConfigValue)kval);
}
}
void SysClkShimServer::SetConfigValues(SysClkConfigValueList* configValues)
{
for(unsigned int kval = 0; kval < SysClkConfigValue_EnumMax; kval++)
{
this->SetConfigValue((SysClkConfigValue)kval, configValues->values[kval]);
}
}

View File

@@ -1,52 +0,0 @@
/*
sys-clk manager, a sys-clk frontend homebrew
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
Copyright (C) 2019 m4xw
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <map>
#include <numeric>
#include "../client.h"
class SysClkShimServer
{
public:
SysClkShimServer();
void SetContextApplicationId(u64 tid);
void SetContextHz(SysClkModule module, u32 hz);
void SetContextTemp(SysClkThermalSensor sensor, u32 temp);
void SetContextProfile(SysClkProfile profile);
void SetContextEnabled(bool enabled);
void SetContextOverride(SysClkModule module, u32 hz);
void CopyContext(SysClkContext* out_context);
void SetProfile(uint64_t applicationId, SysClkModule module, SysClkProfile profile, u32 mhz);
u32 GetProfileMhz(uint64_t applicationId, SysClkModule module, SysClkProfile profile);
void GetProfiles(u64 applicationId, SysClkTitleProfileList* out_profiles);
void SetProfiles(u64 applicationId, SysClkTitleProfileList* profiles);
u8 CountProfiles(u64 applicationId);
u64 GetConfigValue(SysClkConfigValue kval);
void SetConfigValue(SysClkConfigValue kval, u64 val);
void GetConfigValues(SysClkConfigValueList* out_configValues);
void SetConfigValues(SysClkConfigValueList* configValues);
protected:
SysClkContext context;
std::map<std::tuple<u64, SysClkModule, SysClkProfile>, u32> store;
u64 configValues[SysClkConfigValue_EnumMax];
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

View File

@@ -1,44 +0,0 @@
/*
sys-clk manager, a sys-clk frontend homebrew
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
Copyright (C) 2019 m4xw
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "types.h"
typedef struct
{
char name[0x200];
} NacpLanguageEntry;
typedef struct
{
NacpLanguageEntry entry;
} NacpStruct;
static inline Result nacpGetLanguageEntry(NacpStruct* nacp, NacpLanguageEntry** langentry)
{
if(nacp && langentry)
{
*langentry = &nacp->entry;
return 0;
}
return 0xBAD;
}

View File

@@ -1,120 +0,0 @@
/*
sys-clk manager, a sys-clk frontend homebrew
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
Copyright (C) 2019 m4xw
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that 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 <https://www.gnu.org/licenses/>.
*/
#include "ns.h"
#include "types.h"
#include <string.h>
#include <stdlib.h>
#define GAME_ICON_PATH "src/ipc/pc_shim/game.jpg"
static NsShimStore* g_store = NULL;
Result nsInitialize()
{
if(!g_store)
{
g_store = new NsShimStore();
g_store->AddRecord(0x010000000000F001ULL, "Secret Maryo Chronicles", GAME_ICON_PATH);
g_store->AddRecord(0x010000000000F002ULL, "Zelda: Mystery of Solarus", GAME_ICON_PATH);
g_store->AddRecord(0x010000000000F003ULL, "AM2R", GAME_ICON_PATH);
g_store->AddRecord(0x010000000000F004ULL, "Mother 4", GAME_ICON_PATH);
g_store->AddRecord(0x01007EF00011E000ULL, "Wrath of the Wild", GAME_ICON_PATH);
}
return 0;
}
void nsExit()
{
if(g_store)
delete g_store;
}
Result nsListApplicationRecord(NsApplicationRecord* out_records, s32 size, s32 offset, s32* out_count)
{
return g_store->ListRecord(out_records, size, offset, out_count) ? 0 : 0xBAD;
}
Result nsGetApplicationControlData(NsApplicationControlSource flag, u64 titleID, NsApplicationControlData* out_data, size_t size, u64* out_size)
{
return g_store->GetControlData(out_data, size, titleID, out_size) ? 0 : 0xBAD;
}
NsShimStore::NsShimStore()
{
this->store = std::map<u64, std::pair<std::string, std::string>>();
}
void NsShimStore::AddRecord(u64 titleID, std::string name, std::string iconPath)
{
this->store[titleID] = std::make_pair(name, iconPath);
}
bool NsShimStore::ListRecord(NsApplicationRecord* out_records, s32 size, s32 offset, s32* out_count)
{
if(!out_records || !out_count)
{
return false;
}
size_t left = size;
size_t count = 0;
std::map<u64, std::pair<std::string, std::string>>::iterator it = this->store.begin();
std::advance(it, offset);
while(left >= sizeof(NsApplicationRecord) && it != this->store.end())
{
out_records->application_id = it->first;
left -= sizeof(NsApplicationRecord);
out_records++;
count++;
std::advance(it, 1);
}
*out_count = count;
return true;
}
bool NsShimStore::GetControlData(NsApplicationControlData* out_data, size_t size, u64 tid, size_t* out_size)
{
if(!out_data || !out_size || size != sizeof(NsApplicationControlData))
{
return false;
}
std::map<u64, std::pair<std::string, std::string>>::iterator it = this->store.find(tid);
if(it == this->store.end())
{
return false;
}
memset(out_data, 0, size);
strncpy(out_data->nacp.entry.name, it->second.first.c_str(), sizeof(out_data->nacp.entry.name)-1);
FILE* f = fopen(it->second.second.c_str(), "rb");
if(!f)
{
printf("[NsShimStore] Could not open file '%s'\n", it->second.second.c_str());
return false;
}
*out_size = fread(out_data->icon, sizeof(out_data->icon), 1, f);
fclose(f);
return true;
}

View File

@@ -1,60 +0,0 @@
/*
sys-clk manager, a sys-clk frontend homebrew
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
Copyright (C) 2019 m4xw
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <map>
#include <string>
#include "../types.h"
#include "types.h"
#include "nacp.h"
typedef enum
{
NsApplicationControlSource_Storage = 1
} NsApplicationControlSource;
typedef struct
{
u64 application_id;
} NsApplicationRecord;
typedef struct
{
NacpStruct nacp;
NsApplicationIcon icon;
} NsApplicationControlData;
Result nsInitialize();
Result nsListApplicationRecord(NsApplicationRecord* out_records, s32 size, s32 offset, s32* out_count);
Result nsGetApplicationControlData(NsApplicationControlSource flag, u64 titleID, NsApplicationControlData* out_data, size_t size, u64* out_size);
void nsExit();
class NsShimStore
{
public:
NsShimStore();
void AddRecord(u64 titleID, std::string name, std::string iconPath);
bool ListRecord(NsApplicationRecord* out_records, s32 size, s32 offset, s32* out_count);
bool GetControlData(NsApplicationControlData* out_data, size_t size, u64 titleID, size_t* out_size);
protected:
std::map<u64, std::pair<std::string, std::string>> store;
};

View File

@@ -1,32 +0,0 @@
/*
sys-clk manager, a sys-clk frontend homebrew
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
Copyright (C) 2019 m4xw
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstdint>
#define R_FAILED(res) ((res) != 0)
#define R_SUCCEEDED(res) ((res) == 0)
typedef std::uint32_t Result;
typedef std::uint32_t u32;
typedef std::int32_t s32;
typedef std::uint64_t u64;
typedef std::uint8_t u8;

View File

@@ -1,26 +0,0 @@
/*
sys-clk manager, a sys-clk frontend homebrew
Copyright (C) 2019 natinusala
Copyright (C) 2019 p-sam
Copyright (C) 2019 m4xw
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdint.h>
typedef char NsApplicationName[0x201];
typedef uint8_t NsApplicationIcon[0x20000];