mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-22 13:02:38 +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_Invalid=0xff,
|
||||||
} NvBufferKind;
|
} NvBufferKind;
|
||||||
|
|
||||||
Result nvbufInit();
|
Result nvbufInit(void);
|
||||||
Result nvbufExit();
|
void nvbufExit(void);
|
||||||
|
|
||||||
Result nvbufCreate(NvBuffer* m, size_t size, u32 align, NvBufferKind kind);
|
Result nvbufCreate(NvBuffer* m, size_t size, u32 align, NvBufferKind kind);
|
||||||
Result nvbufCreateRw(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 <malloc.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
|
#include "arm/atomics.h"
|
||||||
#include "services/nv.h"
|
#include "services/nv.h"
|
||||||
#include "nvidia/ioctl.h"
|
#include "nvidia/ioctl.h"
|
||||||
#include "nvidia/buffer.h"
|
#include "nvidia/buffer.h"
|
||||||
|
|
||||||
static u32 g_nvmap_fd;
|
static u32 g_nvmap_fd = -1;
|
||||||
|
static u64 g_refCnt;
|
||||||
|
|
||||||
Result nvbufInit() {
|
Result nvbufInit(void)
|
||||||
return nvOpen(&g_nvmap_fd, "/dev/nvmap");
|
{
|
||||||
|
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() {
|
void nvbufExit(void)
|
||||||
return nvClose(g_nvmap_fd);
|
{
|
||||||
|
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)
|
static Result _nvbufCreate(NvBuffer* m, size_t size, u32 flags, u32 align, NvBufferKind kind)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -8,6 +10,9 @@ Result nvinfoInit()
|
|||||||
{
|
{
|
||||||
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))
|
if (R_FAILED(rc))
|
||||||
@ -27,10 +32,13 @@ Result nvinfoInit()
|
|||||||
|
|
||||||
void nvinfoExit()
|
void nvinfoExit()
|
||||||
{
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 nvinfoGetZcullCtxSize() {
|
u32 nvinfoGetZcullCtxSize() {
|
||||||
|
Loading…
Reference in New Issue
Block a user