1
0
mirror of https://github.com/switchbrew/libnx.git synced 2025-07-09 04:42:15 +02:00
libnx/nx/source/nvidia/gpu/gpu.c
2018-08-31 13:05:22 +02:00

48 lines
1.0 KiB
C

#include <switch.h>
Result nvgpuCreate(NvGpu* g)
{
Result rc;
if (R_FAILED(nvinfoInit()))
return MAKERESULT(Module_Libnx, LibnxError_NvinfoFailedToInitialize);
if (R_FAILED(nvbufInit()))
return MAKERESULT(Module_Libnx, LibnxError_NvbufFailedToInitialize);
rc = nvchannelCreate(&g->gpu_channel, "/dev/nvhost-gpu");
if (R_SUCCEEDED(rc))
rc = nvasCreate(&g->addr_space);
if (R_SUCCEEDED(rc))
rc = nvasReserveFull(&g->addr_space);
if (R_SUCCEEDED(rc))
rc = nvasBindToChannel(&g->addr_space, &g->gpu_channel);
if (R_SUCCEEDED(rc))
rc = nvchannelSetNvmapFd(&g->gpu_channel);
if (R_SUCCEEDED(rc))
rc = nvfifoCreate(&g->gpfifo, &g->gpu_channel);
if (R_SUCCEEDED(rc))
rc = nvzcullCreate(&g->zcull_ctx, g);
if (R_FAILED(rc))
nvgpuClose(g);
return rc;
}
void nvgpuClose(NvGpu* g)
{
nvbufExit();
nvinfoExit();
nvfifoClose(&g->gpfifo);
nvasClose(&g->addr_space);
nvchannelClose(&g->gpu_channel);
}