mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-23 21:32:39 +02:00
Add pcvGetClockRate/pcvSetClockRate
This commit is contained in:
parent
27936900d0
commit
8cb9004a2f
@ -51,6 +51,7 @@ extern "C" {
|
|||||||
#include "switch/services/hwopus.h"
|
#include "switch/services/hwopus.h"
|
||||||
#include "switch/services/csrng.h"
|
#include "switch/services/csrng.h"
|
||||||
#include "switch/services/bpc.h"
|
#include "switch/services/bpc.h"
|
||||||
|
#include "switch/services/pcv.h"
|
||||||
#include "switch/services/psm.h"
|
#include "switch/services/psm.h"
|
||||||
#include "switch/services/spsm.h"
|
#include "switch/services/spsm.h"
|
||||||
//#include "switch/services/bsd.h" Use switch/runtime/devices/socket.h instead
|
//#include "switch/services/bsd.h" Use switch/runtime/devices/socket.h instead
|
||||||
|
20
nx/include/switch/services/pcv.h
Normal file
20
nx/include/switch/services/pcv.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* @file pcv.h
|
||||||
|
* @brief PCV service IPC wrapper.
|
||||||
|
* @author SciresM
|
||||||
|
* @copyright libnx Authors
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include "../types.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PcvModule_Cpu = 0,
|
||||||
|
PcvModule_Gpu = 1,
|
||||||
|
PcvModule_Emc = 56,
|
||||||
|
} PcvModule;
|
||||||
|
|
||||||
|
Result pcvInitialize(void);
|
||||||
|
void pcvExit(void);
|
||||||
|
|
||||||
|
Result pcvGetClockRate(PcvModule module, u32 *out_hz);
|
||||||
|
Result pcvSetClockRate(PcvModule module, u32 hz);
|
106
nx/source/services/pcv.c
Normal file
106
nx/source/services/pcv.c
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
#include "types.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "arm/atomics.h"
|
||||||
|
#include "kernel/ipc.h"
|
||||||
|
#include "kernel/detect.h"
|
||||||
|
#include "services/pcv.h"
|
||||||
|
#include "services/sm.h"
|
||||||
|
|
||||||
|
static Service g_pcvSrv;
|
||||||
|
static u64 g_refCnt;
|
||||||
|
|
||||||
|
Result pcvInitialize(void) {
|
||||||
|
Result rc = 0;
|
||||||
|
|
||||||
|
atomicIncrement64(&g_refCnt);
|
||||||
|
|
||||||
|
if (serviceIsActive(&g_pcvSrv))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
rc = smGetService(&g_pcvSrv, "pcv");
|
||||||
|
|
||||||
|
if (R_FAILED(rc)) pcvExit();
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pcvExit(void) {
|
||||||
|
if (atomicDecrement64(&g_refCnt) == 0) {
|
||||||
|
serviceClose(&g_pcvSrv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result pcvSetClockRate(PcvModule module, u32 hz) {
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
u32 module;
|
||||||
|
u32 hz;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
raw = serviceIpcPrepareHeader(&g_pcvSrv, &c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 2;
|
||||||
|
raw->module = module;
|
||||||
|
raw->hz = hz;
|
||||||
|
|
||||||
|
Result rc = serviceIpcDispatch(&g_pcvSrv);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcParsedCommand r;
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp;
|
||||||
|
|
||||||
|
serviceIpcParse(&g_pcvSrv, &r, sizeof(*resp));
|
||||||
|
resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result pcvGetClockRate(PcvModule module, u32 *out_hz) {
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
u32 module;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
|
raw = serviceIpcPrepareHeader(&g_pcvSrv, &c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 3;
|
||||||
|
raw->module = module;
|
||||||
|
|
||||||
|
Result rc = serviceIpcDispatch(&g_pcvSrv);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcParsedCommand r;
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
u32 hz;
|
||||||
|
} *resp;
|
||||||
|
|
||||||
|
serviceIpcParse(&g_pcvSrv, &r, sizeof(*resp));
|
||||||
|
resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
*out_hz = resp->hz;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user