diff --git a/nx/include/switch.h b/nx/include/switch.h index af60b40e..5b8eda8e 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -76,6 +76,8 @@ extern "C" { #include "switch/nvidia/address_space.h" #include "switch/nvidia/channel.h" #include "switch/nvidia/info.h" +#include "switch/nvidia/gpu/gpfifo.h" +#include "switch/nvidia/gpu/zcull_ctx.h" #include "switch/nvidia/gpu/gpu.h" #include "switch/audio/driver.h" diff --git a/nx/include/switch/nvidia/gpu/gpfifo.h b/nx/include/switch/nvidia/gpu/gpfifo.h new file mode 100644 index 00000000..44d9b06d --- /dev/null +++ b/nx/include/switch/nvidia/gpu/gpfifo.h @@ -0,0 +1,9 @@ +#pragma once + +typedef struct { + NvChannel* parent; + nvioctl_fence fifo_fence; +} NvGpfifo; + +Result nvfifoCreate(NvGpfifo* f, NvChannel* parent); +void nvfifoClose(); diff --git a/nx/include/switch/nvidia/gpu/gpu.h b/nx/include/switch/nvidia/gpu/gpu.h index b699b1df..79357899 100644 --- a/nx/include/switch/nvidia/gpu/gpu.h +++ b/nx/include/switch/nvidia/gpu/gpu.h @@ -1,8 +1,10 @@ #pragma once -typedef struct { +typedef struct NvGpu { NvAddressSpace addr_space; NvChannel gpu_channel; + NvGpfifo gpfifo; + NvZcullContext zcull_ctx; } NvGpu; Result nvgpuCreate(NvGpu* g); diff --git a/nx/include/switch/nvidia/gpu/zcull_ctx.h b/nx/include/switch/nvidia/gpu/zcull_ctx.h new file mode 100644 index 00000000..197b70db --- /dev/null +++ b/nx/include/switch/nvidia/gpu/zcull_ctx.h @@ -0,0 +1,10 @@ +#pragma once + +typedef struct NvGpu NvGpu; + +typedef struct { + NvGpu* parent; +} NvZcullContext; + +Result nvzcullCreate(NvZcullContext* z, NvGpu* parent); +void nvzcullClose(NvZcullContext* z); diff --git a/nx/source/nvidia/address_space.c b/nx/source/nvidia/address_space.c index 502c92f1..ee0211ec 100644 --- a/nx/source/nvidia/address_space.c +++ b/nx/source/nvidia/address_space.c @@ -47,6 +47,14 @@ Result nvasMapBuffer(NvAddressSpace* a, NvBuffer* buffer, NvBufferKind kind, iov return nvioctlNvhostAsGpu_MapBufferEx(a->fd, 0, kind, buffer->fd, 0, 0, buffer->size, 0, iova_out); } -Result nvasBindToChannel(NvAddressSpace* a, NvChannel* channel) { - return nvioctlNvhostAsGpu_BindChannel(a->fd, channel->fd); +Result nvasBindToChannel(NvAddressSpace* a, NvChannel* channel) +{ + Result rc; + + rc = nvioctlNvhostAsGpu_BindChannel(a->fd, channel->fd); + + if (R_SUCCEEDED(rc)) + rc = nvioctlChannel_SetNvmapFd(channel->fd, a->fd); + + return rc; } diff --git a/nx/source/nvidia/gpu/gpfifo.c b/nx/source/nvidia/gpu/gpfifo.c new file mode 100644 index 00000000..5b88a7fa --- /dev/null +++ b/nx/source/nvidia/gpu/gpfifo.c @@ -0,0 +1,15 @@ +#include + +#define DEFAULT_FIFO_ENTRIES 0x800 + +Result nvfifoCreate(NvGpfifo* f, NvChannel* parent) +{ + f->parent = parent; + + return nvioctlChannel_AllocGpfifoEx2( + parent->fd, DEFAULT_FIFO_ENTRIES, 1, 0, 0, 0, 0, &f->fifo_fence); +} + +void nvfifoClose() { + /**/ +} diff --git a/nx/source/nvidia/gpu/gpu.c b/nx/source/nvidia/gpu/gpu.c index 726c0396..f47cdbcd 100644 --- a/nx/source/nvidia/gpu/gpu.c +++ b/nx/source/nvidia/gpu/gpu.c @@ -15,6 +15,12 @@ Result nvgpuCreate(NvGpu* g) if (R_SUCCEEDED(rc)) rc = nvasBindToChannel(&g->addr_space, &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); @@ -23,6 +29,7 @@ Result nvgpuCreate(NvGpu* g) void nvgpuClose(NvGpu* g) { + nvfifoClose(&g->gpfifo); nvasClose(&g->addr_space); nvchannelClose(&g->gpu_channel); } diff --git a/nx/source/nvidia/gpu/zcull_ctx.c b/nx/source/nvidia/gpu/zcull_ctx.c new file mode 100644 index 00000000..e8f0e46d --- /dev/null +++ b/nx/source/nvidia/gpu/zcull_ctx.c @@ -0,0 +1,11 @@ +#include + +Result nvzcullCreate(NvZcullContext* z, NvGpu* parent) +{ + z->parent = parent; + return 0; +} + +void nvzcullClose(NvZcullContext* z) { + /**/ +}