sys-clk: deprecate
This commit is contained in:
13
Source/sys-clk-OC/sysmodule/lib/nxExt/.gitignore
vendored
13
Source/sys-clk-OC/sysmodule/lib/nxExt/.gitignore
vendored
@@ -1,13 +0,0 @@
|
||||
# Editor files
|
||||
*.swp
|
||||
*~
|
||||
|
||||
# Objects
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Lib
|
||||
lib
|
||||
release
|
||||
debug
|
||||
@@ -1,132 +0,0 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITPRO)),)
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
||||
endif
|
||||
|
||||
include $(DEVKITPRO)/libnx/switch_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
SOURCES := src
|
||||
DATA := data
|
||||
INCLUDES := include
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec
|
||||
|
||||
CFLAGS := -g -Wall -Werror \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
$(ARCH) \
|
||||
$(BUILD_CFLAGS)
|
||||
|
||||
CFLAGS += $(INCLUDE)
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(PORTLIBS) $(LIBNX)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
||||
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
.PHONY: clean all lib/lib$(TARGET).a lib/lib$(TARGET)d.a
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: lib/lib$(TARGET).a lib/lib$(TARGET)d.a
|
||||
|
||||
lib:
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
|
||||
release:
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
|
||||
debug:
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
|
||||
lib/lib$(TARGET).a : lib release $(SOURCES) $(INCLUDES)
|
||||
@$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \
|
||||
BUILD_CFLAGS="-DNDEBUG=1 -O2" \
|
||||
DEPSDIR=$(CURDIR)/release \
|
||||
--no-print-directory -C release \
|
||||
-f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr release debug lib
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT) : $(OFILES)
|
||||
|
||||
$(OFILES_SRC) : $(HFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%_bin.h %.bin.o : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
@@ -1,15 +0,0 @@
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "nxExt/apm_ext.h"
|
||||
#include "nxExt/ipc_server.h"
|
||||
#include "nxExt/cpp/lockable_mutex.h"
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
Result apmExtInitialize(void);
|
||||
void apmExtExit(void);
|
||||
|
||||
// Silently fail
|
||||
Result apmExtSysRequestPerformanceMode(u32 mode);
|
||||
Result apmExtSysSetCpuBoostMode(u32 mode);
|
||||
|
||||
Result apmExtGetPerformanceMode(u32 *out_mode);
|
||||
Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf);
|
||||
|
||||
inline bool apmExtIsCPUBoosted(u32 conf_id) { // CPU boosted to 1785 MHz
|
||||
return (conf_id == 0x92220009 || conf_id == 0x9222000A);
|
||||
};
|
||||
inline bool apmExtIsBoostMode(u32 conf_id) { // GPU throttled to 76.8 MHz
|
||||
return (conf_id >= 0x92220009 && conf_id <= 0x9222000C);
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <mutex>
|
||||
#include <switch.h>
|
||||
|
||||
class LockableMutex
|
||||
{
|
||||
public:
|
||||
LockableMutex()
|
||||
{
|
||||
mutexInit(&this->m);
|
||||
}
|
||||
|
||||
virtual ~LockableMutex() {}
|
||||
|
||||
void Lock()
|
||||
{
|
||||
mutexLock(&this->m);
|
||||
}
|
||||
|
||||
bool TryLock()
|
||||
{
|
||||
return mutexTryLock(&this->m);
|
||||
}
|
||||
|
||||
void Unlock()
|
||||
{
|
||||
mutexUnlock(&this->m);
|
||||
}
|
||||
|
||||
// snake_case aliases in order to implement Lockable
|
||||
|
||||
void lock()
|
||||
{
|
||||
this->Lock();
|
||||
}
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
return this->TryLock();
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
this->Unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
Mutex m;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#define IPC_SERVER_EXT_RESPONSE_MAX_DATA_SIZE (0x100 - 0x10 - sizeof(IpcServerRawHeader))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u64 magic;
|
||||
union
|
||||
{
|
||||
u64 cmdId;
|
||||
u64 result;
|
||||
};
|
||||
} IpcServerRawHeader;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SmServiceName srvName;
|
||||
Handle handles[MAX_WAIT_OBJECTS];
|
||||
u32 max;
|
||||
u32 count;
|
||||
} IpcServer;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u64 cmdId;
|
||||
void* ptr;
|
||||
size_t size;
|
||||
} IpcServerRequestData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
HipcParsedRequest hipc;
|
||||
IpcServerRequestData data;
|
||||
} IpcServerRequest;
|
||||
|
||||
typedef Result (*IpcServerRequestHandler)(void* userdata, const IpcServerRequest* r, u8* out_data, size_t* out_dataSize);
|
||||
|
||||
Result ipcServerInit(IpcServer* server, const char* name, u32 max_sessions);
|
||||
Result ipcServerExit(IpcServer* server);
|
||||
Result ipcServerProcess(IpcServer* server, IpcServerRequestHandler handler, void* userdata);
|
||||
Result ipcServerParseCommand(const IpcServerRequest* r, size_t *out_datasize, void** out_data, u64* out_cmd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "nxExt/apm_ext.h"
|
||||
|
||||
#include <stdatomic.h>
|
||||
|
||||
static Service g_apmSrv;
|
||||
static Service g_apmSysSrv;
|
||||
static atomic_size_t g_refCnt;
|
||||
|
||||
Result apmExtInitialize(void)
|
||||
{
|
||||
g_refCnt++;
|
||||
|
||||
if (serviceIsActive(&g_apmSrv))
|
||||
return 0;
|
||||
|
||||
Result rc = smGetService(&g_apmSrv, "apm");
|
||||
|
||||
if(R_SUCCEEDED(rc))
|
||||
rc = smGetService(&g_apmSysSrv, "apm:sys");
|
||||
|
||||
if (R_FAILED(rc))
|
||||
apmExtExit();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void apmExtExit(void)
|
||||
{
|
||||
if (--g_refCnt == 0)
|
||||
{
|
||||
serviceClose(&g_apmSrv);
|
||||
serviceClose(&g_apmSysSrv);
|
||||
}
|
||||
}
|
||||
|
||||
Result apmExtSysSetCpuBoostMode(u32 mode)
|
||||
{
|
||||
return serviceDispatchIn(&g_apmSysSrv, 6, mode);
|
||||
}
|
||||
|
||||
Result apmExtGetPerformanceMode(u32 *out_mode)
|
||||
{
|
||||
return serviceDispatchOut(&g_apmSrv, 1, *out_mode);
|
||||
}
|
||||
|
||||
Result apmExtSysRequestPerformanceMode(u32 mode)
|
||||
{
|
||||
return serviceDispatchIn(&g_apmSysSrv, 0, mode);
|
||||
}
|
||||
|
||||
Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf)
|
||||
{
|
||||
return serviceDispatchOut(&g_apmSysSrv, 7, *out_conf);
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
/*
|
||||
* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "nxExt/ipc_server.h"
|
||||
#include <string.h>
|
||||
|
||||
Result ipcServerInit(IpcServer* server, const char* name, u32 max_sessions)
|
||||
{
|
||||
if(max_sessions < 1 || max_sessions > (MAX_WAIT_OBJECTS - 1))
|
||||
{
|
||||
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
|
||||
}
|
||||
|
||||
server->srvName = smEncodeName(name);
|
||||
server->max = max_sessions + 1;
|
||||
server->count = 0;
|
||||
|
||||
Result rc = smRegisterService(&server->handles[0], server->srvName, false, max_sessions);
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
server->count = 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result ipcServerExit(IpcServer* server)
|
||||
{
|
||||
for(u32 i = 0; i < server->count; i++)
|
||||
{
|
||||
svcCloseHandle(server->handles[i]);
|
||||
}
|
||||
server->count = 0;
|
||||
return smUnregisterService(server->srvName);
|
||||
}
|
||||
|
||||
static Result _ipcServerAddSession(IpcServer* server, Handle session)
|
||||
{
|
||||
if(server->count >= server->max)
|
||||
{
|
||||
return MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
|
||||
}
|
||||
|
||||
server->handles[server->count] = session;
|
||||
server->count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Result _ipcServerDeleteSession(IpcServer* server, u32 index)
|
||||
{
|
||||
if(!index || index >= server->count)
|
||||
{
|
||||
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
|
||||
}
|
||||
|
||||
svcCloseHandle(server->handles[index]);
|
||||
|
||||
for(u32 j = index; j < (server->count - 1); j++)
|
||||
{
|
||||
server->handles[j] = server->handles[j + 1];
|
||||
}
|
||||
server->count--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Result _ipcServerParseRequest(IpcServerRequest* r)
|
||||
{
|
||||
u8* base = armGetTls();
|
||||
|
||||
r->hipc = hipcParseRequest(base);
|
||||
r->data.cmdId = 0;
|
||||
r->data.size = 0;
|
||||
r->data.ptr = NULL;
|
||||
|
||||
if(r->hipc.meta.type == CmifCommandType_Request)
|
||||
{
|
||||
IpcServerRawHeader* header = cmifGetAlignedDataStart(r->hipc.data.data_words, base);
|
||||
size_t dataSize = r->hipc.meta.num_data_words * 4;
|
||||
|
||||
if(!header || dataSize < sizeof(IpcServerRawHeader) || header->magic != CMIF_IN_HEADER_MAGIC)
|
||||
{
|
||||
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
|
||||
}
|
||||
|
||||
r->data.cmdId = header->cmdId;
|
||||
if(dataSize > sizeof(IpcServerRawHeader))
|
||||
{
|
||||
r->data.size = dataSize - sizeof(IpcServerRawHeader);
|
||||
r->data.ptr = ((u8*)header) + sizeof(IpcServerRawHeader);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _ipcServerPrepareResponse(Result rc, void* data, size_t dataSize)
|
||||
{
|
||||
u8* base = armGetTls();
|
||||
HipcRequest hipc = hipcMakeRequestInline(base,
|
||||
.type = CmifCommandType_Request,
|
||||
.num_data_words = (sizeof(IpcServerRawHeader) + dataSize + 0x10) / 4,
|
||||
);
|
||||
|
||||
IpcServerRawHeader* rawHeader = cmifGetAlignedDataStart(hipc.data_words, base);
|
||||
rawHeader->magic = CMIF_OUT_HEADER_MAGIC;
|
||||
rawHeader->result = rc;
|
||||
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
memcpy(((u8*)rawHeader) + sizeof(IpcServerRawHeader), data, dataSize);
|
||||
}
|
||||
}
|
||||
|
||||
static Result _ipcServerProcessNewSession(IpcServer* server)
|
||||
{
|
||||
Handle session;
|
||||
Result rc = svcAcceptSession(&session, server->handles[0]);
|
||||
if(R_SUCCEEDED(rc) && R_FAILED(rc = _ipcServerAddSession(server, session)))
|
||||
{
|
||||
svcCloseHandle(session);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _ipcServerProcessSession(IpcServer* server, IpcServerRequestHandler handler, void* userdata, u32 handleIndex)
|
||||
{
|
||||
s32 unusedIndex;
|
||||
IpcServerRequest r;
|
||||
size_t dataSize = 0;
|
||||
u8 data[IPC_SERVER_EXT_RESPONSE_MAX_DATA_SIZE];
|
||||
bool close = false;
|
||||
|
||||
Result rc = svcReplyAndReceive(&unusedIndex, &server->handles[handleIndex], 1, 0, UINT64_MAX);
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
rc = _ipcServerParseRequest(&r);
|
||||
}
|
||||
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
switch(r.hipc.meta.type)
|
||||
{
|
||||
case CmifCommandType_Request:
|
||||
_ipcServerPrepareResponse(
|
||||
handler(userdata, &r, data, &dataSize),
|
||||
data,
|
||||
dataSize
|
||||
);
|
||||
break;
|
||||
case CmifCommandType_Close:
|
||||
_ipcServerPrepareResponse(0, NULL, 0);
|
||||
close = true;
|
||||
break;
|
||||
default:
|
||||
_ipcServerPrepareResponse(MAKERESULT(11, 403), NULL, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
rc = svcReplyAndReceive(&unusedIndex, &server->handles[handleIndex], 0, server->handles[handleIndex], 0);
|
||||
if(rc == KERNELRESULT(TimedOut))
|
||||
{
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(R_FAILED(rc) || close)
|
||||
{
|
||||
_ipcServerDeleteSession(server, handleIndex);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result ipcServerProcess(IpcServer* server, IpcServerRequestHandler handler, void* userdata)
|
||||
{
|
||||
s32 handleIndex = -1;
|
||||
Result rc = svcWaitSynchronization(&handleIndex, server->handles, server->count, UINT64_MAX);
|
||||
|
||||
if(R_SUCCEEDED(rc) && (handleIndex < 0 || handleIndex >= server->count))
|
||||
{
|
||||
rc = MAKERESULT(Module_Libnx, LibnxError_NotFound);
|
||||
}
|
||||
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
if(handleIndex)
|
||||
{
|
||||
rc = _ipcServerProcessSession(server, handler, userdata, handleIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = _ipcServerProcessNewSession(server);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user