mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 20:42:44 +02:00
Add refcounting to nvidia stuff
This commit is contained in:
parent
e7daaf1e71
commit
f62f6e8b54
@ -249,8 +249,8 @@ typedef enum {
|
||||
NvBufferKind_Invalid=0xff,
|
||||
} NvBufferKind;
|
||||
|
||||
Result nvbufInit();
|
||||
Result nvbufExit();
|
||||
Result nvbufInit(void);
|
||||
void nvbufExit(void);
|
||||
|
||||
Result nvbufCreate(NvBuffer* m, size_t size, u32 align, NvBufferKind kind);
|
||||
Result nvbufCreateRw(NvBuffer* m, size_t size, u32 align, NvBufferKind kind);
|
||||
|
@ -1,18 +1,38 @@
|
||||
#include <malloc.h>
|
||||
#include "types.h"
|
||||
#include "result.h"
|
||||
#include "arm/atomics.h"
|
||||
#include "services/nv.h"
|
||||
#include "nvidia/ioctl.h"
|
||||
#include "nvidia/buffer.h"
|
||||
|
||||
static u32 g_nvmap_fd;
|
||||
static u32 g_nvmap_fd = -1;
|
||||
static u64 g_refCnt;
|
||||
|
||||
Result nvbufInit() {
|
||||
return nvOpen(&g_nvmap_fd, "/dev/nvmap");
|
||||
Result nvbufInit(void)
|
||||
{
|
||||
Result rc;
|
||||
|
||||
if (atomicIncrement64(&g_refCnt) > 0)
|
||||
return 0;
|
||||
|
||||
rc = nvOpen(&g_nvmap_fd, "/dev/nvmap");
|
||||
|
||||
if (R_FAILED(rc))
|
||||
atomicDecrement64(&g_refCnt);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result nvbufExit() {
|
||||
return nvClose(g_nvmap_fd);
|
||||
void nvbufExit(void)
|
||||
{
|
||||
if (atomicDecrement64(&g_refCnt) == 0)
|
||||
{
|
||||
if (g_nvmap_fd != -1)
|
||||
nvClose(g_nvmap_fd);
|
||||
|
||||
g_nvmap_fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static Result _nvbufCreate(NvBuffer* m, size_t size, u32 flags, u32 align, NvBufferKind kind)
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <switch.h>
|
||||
|
||||
static u32 g_ctrlgpu_fd = -1;
|
||||
static u64 g_refCnt;
|
||||
|
||||
static nvioctl_gpu_characteristics g_gpu_characteristics;
|
||||
static u32 g_zcull_ctx_size;
|
||||
|
||||
@ -8,6 +10,9 @@ Result nvinfoInit()
|
||||
{
|
||||
Result rc;
|
||||
|
||||
if (atomicIncrement64(&g_refCnt) > 0)
|
||||
return 0;
|
||||
|
||||
rc = nvOpen(&g_ctrlgpu_fd, "/dev/nvhost-ctrl-gpu");
|
||||
|
||||
if (R_FAILED(rc))
|
||||
@ -27,10 +32,13 @@ Result nvinfoInit()
|
||||
|
||||
void nvinfoExit()
|
||||
{
|
||||
if (g_ctrlgpu_fd != -1)
|
||||
nvClose(g_ctrlgpu_fd);
|
||||
if (atomicDecrement64(&g_refCnt) == 0)
|
||||
{
|
||||
if (g_ctrlgpu_fd != -1)
|
||||
nvClose(g_ctrlgpu_fd);
|
||||
|
||||
g_ctrlgpu_fd = -1;
|
||||
g_ctrlgpu_fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
u32 nvinfoGetZcullCtxSize() {
|
||||
|
Loading…
Reference in New Issue
Block a user