mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
nvFence/nvGpu/nvMap: use service guard instead of unsafe atomic refcnt
This commit is contained in:
parent
91b4efb6f5
commit
2c19f13f74
@ -1,6 +1,4 @@
|
|||||||
#include "types.h"
|
#include "../services/service_guard.h"
|
||||||
#include "result.h"
|
|
||||||
#include "arm/atomics.h"
|
|
||||||
#include "kernel/svc.h"
|
#include "kernel/svc.h"
|
||||||
#include "kernel/event.h"
|
#include "kernel/event.h"
|
||||||
#include "runtime/hosversion.h"
|
#include "runtime/hosversion.h"
|
||||||
@ -8,11 +6,13 @@
|
|||||||
#include "nvidia/fence.h"
|
#include "nvidia/fence.h"
|
||||||
|
|
||||||
static u32 g_ctrl_fd = -1;
|
static u32 g_ctrl_fd = -1;
|
||||||
static u64 g_refCnt;
|
|
||||||
|
|
||||||
static u64 g_NvEventUsedMask;
|
static u64 g_NvEventUsedMask;
|
||||||
static Event g_NvEvents[64];
|
static Event g_NvEvents[64];
|
||||||
|
|
||||||
|
#define nvFenceInitialize nvFenceInit
|
||||||
|
NX_GENERATE_SERVICE_GUARD(nvFence);
|
||||||
|
|
||||||
static int _nvGetEventSlot(void)
|
static int _nvGetEventSlot(void)
|
||||||
{
|
{
|
||||||
int slot;
|
int slot;
|
||||||
@ -66,28 +66,18 @@ static void _nvFreeEvent(int event_id)
|
|||||||
nvioctlNvhostCtrl_EventUnregister(g_ctrl_fd, event_id);
|
nvioctlNvhostCtrl_EventUnregister(g_ctrl_fd, event_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result nvFenceInit(void)
|
Result _nvFenceInitialize(void)
|
||||||
{
|
{
|
||||||
Result rc;
|
return nvOpen(&g_ctrl_fd, "/dev/nvhost-ctrl");
|
||||||
|
|
||||||
if (atomicIncrement64(&g_refCnt) > 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
rc = nvOpen(&g_ctrl_fd, "/dev/nvhost-ctrl");
|
|
||||||
|
|
||||||
if (R_FAILED(rc))
|
|
||||||
g_ctrl_fd = -1;
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void nvFenceExit(void)
|
void _nvFenceCleanup(void)
|
||||||
{
|
{
|
||||||
if (atomicDecrement64(&g_refCnt) == 0) {
|
for (int i = 0; i < 64; i ++)
|
||||||
for (int i = 0; i < 64; i ++)
|
_nvFreeEvent(i);
|
||||||
_nvFreeEvent(i);
|
|
||||||
if (g_ctrl_fd != -1)
|
if (g_ctrl_fd != -1) {
|
||||||
nvClose(g_ctrl_fd);
|
nvClose(g_ctrl_fd);
|
||||||
g_ctrl_fd = -1;
|
g_ctrl_fd = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "types.h"
|
#include "../services/service_guard.h"
|
||||||
#include "result.h"
|
|
||||||
#include "arm/atomics.h"
|
|
||||||
#include "kernel/svc.h"
|
#include "kernel/svc.h"
|
||||||
#include "services/nv.h"
|
#include "services/nv.h"
|
||||||
#include "nvidia/ioctl.h"
|
#include "nvidia/ioctl.h"
|
||||||
@ -11,25 +9,21 @@
|
|||||||
#define NUM_TPC_MASKS 1
|
#define NUM_TPC_MASKS 1
|
||||||
|
|
||||||
static u32 g_ctrlgpu_fd = -1;
|
static u32 g_ctrlgpu_fd = -1;
|
||||||
static u64 g_refCnt;
|
|
||||||
|
|
||||||
static nvioctl_gpu_characteristics g_gpu_characteristics;
|
static nvioctl_gpu_characteristics g_gpu_characteristics;
|
||||||
static u32 g_zcull_ctx_size;
|
static u32 g_zcull_ctx_size;
|
||||||
static nvioctl_zcull_info g_zcull_info;
|
static nvioctl_zcull_info g_zcull_info;
|
||||||
static u32 g_tpc_masks[NUM_TPC_MASKS];
|
static u32 g_tpc_masks[NUM_TPC_MASKS];
|
||||||
|
|
||||||
Result nvGpuInit(void)
|
#define nvGpuInitialize nvGpuInit
|
||||||
|
NX_GENERATE_SERVICE_GUARD(nvGpu);
|
||||||
|
|
||||||
|
Result _nvGpuInitialize(void)
|
||||||
{
|
{
|
||||||
Result rc;
|
Result rc;
|
||||||
|
|
||||||
if (atomicIncrement64(&g_refCnt) > 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
rc = nvOpen(&g_ctrlgpu_fd, "/dev/nvhost-ctrl-gpu");
|
rc = nvOpen(&g_ctrlgpu_fd, "/dev/nvhost-ctrl-gpu");
|
||||||
|
|
||||||
if (R_FAILED(rc))
|
|
||||||
g_ctrlgpu_fd = -1;
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
rc = nvioctlNvhostCtrlGpu_GetCharacteristics(g_ctrlgpu_fd, &g_gpu_characteristics);
|
rc = nvioctlNvhostCtrlGpu_GetCharacteristics(g_ctrlgpu_fd, &g_gpu_characteristics);
|
||||||
|
|
||||||
@ -42,18 +36,13 @@ Result nvGpuInit(void)
|
|||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
rc = nvioctlNvhostCtrlGpu_GetTpcMasks(g_ctrlgpu_fd, g_tpc_masks, sizeof(g_tpc_masks));
|
rc = nvioctlNvhostCtrlGpu_GetTpcMasks(g_ctrlgpu_fd, g_tpc_masks, sizeof(g_tpc_masks));
|
||||||
|
|
||||||
if (R_FAILED(rc))
|
|
||||||
nvGpuExit();
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nvGpuExit(void)
|
void _nvGpuCleanup(void)
|
||||||
{
|
{
|
||||||
if (atomicDecrement64(&g_refCnt) == 0) {
|
if (g_ctrlgpu_fd != -1) {
|
||||||
if (g_ctrlgpu_fd != -1)
|
nvClose(g_ctrlgpu_fd);
|
||||||
nvClose(g_ctrlgpu_fd);
|
|
||||||
|
|
||||||
g_ctrlgpu_fd = -1;
|
g_ctrlgpu_fd = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "types.h"
|
#include "../services/service_guard.h"
|
||||||
#include "result.h"
|
|
||||||
#include "arm/atomics.h"
|
|
||||||
#include "arm/cache.h"
|
#include "arm/cache.h"
|
||||||
#include "kernel/svc.h"
|
#include "kernel/svc.h"
|
||||||
#include "services/nv.h"
|
#include "services/nv.h"
|
||||||
@ -9,30 +7,19 @@
|
|||||||
#include "nvidia/map.h"
|
#include "nvidia/map.h"
|
||||||
|
|
||||||
static u32 g_nvmap_fd = -1;
|
static u32 g_nvmap_fd = -1;
|
||||||
static u64 g_refCnt;
|
|
||||||
|
|
||||||
Result nvMapInit(void)
|
#define nvMapInitialize nvMapInit
|
||||||
|
NX_GENERATE_SERVICE_GUARD(nvMap);
|
||||||
|
|
||||||
|
Result _nvMapInitialize(void)
|
||||||
{
|
{
|
||||||
Result rc;
|
return nvOpen(&g_nvmap_fd, "/dev/nvmap");
|
||||||
|
|
||||||
if (atomicIncrement64(&g_refCnt) > 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
rc = nvOpen(&g_nvmap_fd, "/dev/nvmap");
|
|
||||||
|
|
||||||
if (R_FAILED(rc))
|
|
||||||
atomicDecrement64(&g_refCnt);
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void nvMapExit(void)
|
void _nvMapCleanup(void)
|
||||||
{
|
{
|
||||||
if (atomicDecrement64(&g_refCnt) == 0)
|
if (g_nvmap_fd != -1) {
|
||||||
{
|
nvClose(g_nvmap_fd);
|
||||||
if (g_nvmap_fd != -1)
|
|
||||||
nvClose(g_nvmap_fd);
|
|
||||||
|
|
||||||
g_nvmap_fd = -1;
|
g_nvmap_fd = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user