This commit is contained in:
XorTroll 2018-07-31 22:52:47 +00:00 committed by GitHub
commit d3c4316809
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,14 @@
/**
* @file bpc.h
* @brief Board power control (bpc) service IPC wrapper.
* @author XorTroll
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
Result bpcInitialize(void);
void bpcExit(void);
Result bpcShutdownSystem(void);
Result bpcRebootSystem(void);

86
nx/source/services/bpc.c Normal file
View File

@ -0,0 +1,86 @@
#include "types.h"
#include "result.h"
#include "arm/atomics.h"
#include "kernel/ipc.h"
#include "services/bpc.h"
#include "services/sm.h"
static Service g_bpcSrv;
static u64 g_refCnt;
Result bpcInitialize(void)
{
atomicIncrement64(&g_refCnt);
if (serviceIsActive(&g_bpcSrv)) return 0;
Result rc = 0;
if(!kernelAbove100()) rc = smGetService(&g_bpcSrv, "bpc:c");
else rc = smGetService(&g_bpcSrv, "bpc");
return rc;
}
void bpcExit(void)
{
if (atomicDecrement64(&g_refCnt) == 0)
{
serviceClose(&g_bpcSrv);
}
}
Result bpcShutdownSystem(void)
{
IpcCommand c;
ipcInitialize(&c);
struct
{
u64 magic;
u64 cmd_id;
} * raw;
raw = ipcPrepareHeader(&c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 0;
Result rc = 0;
rc = serviceIpcDispatch(&g_bpcSrv);
if(R_SUCCEEDED(rc))
{
IpcParsedCommand r;
ipcParse(&r);
struct
{
u64 magic;
u64 result;
} *resp = r.Raw;
rc = resp->result;
}
return rc;
}
Result bpcRebootSystem(void)
{
IpcCommand c;
ipcInitialize(&c);
struct
{
u64 magic;
u64 cmd_id;
} * raw;
raw = ipcPrepareHeader(&c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 1;
Result rc = 0;
rc = serviceIpcDispatch(&g_bpcSrv);
if(R_SUCCEEDED(rc))
{
IpcParsedCommand r;
ipcParse(&r);
struct
{
u64 magic;
u64 result;
} *resp = r.Raw;
rc = resp->result;
}
return rc;
}