mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-22 04:52:39 +02:00
nv wrappers: Handle cacheability settings properly, more details:
- nvAddressSpaceMapBuffer now accepts a flags parameter instead of hardcoding NvMapBufferFlags_IsCacheable. - NvBufferFlags was incorrect and was thus removed. - nvBufferCreate/nvBufferCreateRw replaced with nvBufferCreate, with an extra 'is_cacheable' bool parameter. There's no such thing as a "read-only/read-write" buffer. - nvBufferMakeCpuUncached/nvBufferMakeCpuCached were removed.
This commit is contained in:
parent
f469fa7458
commit
e7ae7ea846
@ -18,7 +18,7 @@ Result nvAddressSpaceReserveAlign(NvAddressSpace* a, NvPageSize align, u32 pages
|
|||||||
Result nvAddressSpaceReserveAtFixedAddr(NvAddressSpace* a, iova_t addr, u32 pages, NvPageSize page_sz);
|
Result nvAddressSpaceReserveAtFixedAddr(NvAddressSpace* a, iova_t addr, u32 pages, NvPageSize page_sz);
|
||||||
Result nvAddressSpaceReserveFull(NvAddressSpace* a);
|
Result nvAddressSpaceReserveFull(NvAddressSpace* a);
|
||||||
|
|
||||||
Result nvAddressSpaceMapBuffer(NvAddressSpace* a, u32 fd, NvKind kind, iova_t* iova_out);
|
Result nvAddressSpaceMapBuffer(NvAddressSpace* a, u32 fd, u32 flags, NvKind kind, iova_t* iova_out);
|
||||||
Result nvAddressSpaceUnmapBuffer(NvAddressSpace* a, iova_t iova);
|
Result nvAddressSpaceUnmapBuffer(NvAddressSpace* a, iova_t iova);
|
||||||
|
|
||||||
struct NvChannel;
|
struct NvChannel;
|
||||||
|
@ -2,10 +2,6 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "address_space.h"
|
#include "address_space.h"
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
NvBufferFlags_Writable=1,
|
|
||||||
} NvBufferFlags;
|
|
||||||
|
|
||||||
typedef struct NvAddressSpace NvAddressSpace;
|
typedef struct NvAddressSpace NvAddressSpace;
|
||||||
|
|
||||||
typedef struct NvBuffer {
|
typedef struct NvBuffer {
|
||||||
@ -17,14 +13,14 @@ typedef struct NvBuffer {
|
|||||||
NvAddressSpace* addr_space;
|
NvAddressSpace* addr_space;
|
||||||
NvKind kind;
|
NvKind kind;
|
||||||
bool has_init;
|
bool has_init;
|
||||||
|
bool is_cacheable;
|
||||||
} NvBuffer;
|
} NvBuffer;
|
||||||
|
|
||||||
Result nvBufferInit(void);
|
Result nvBufferInit(void);
|
||||||
u32 nvBufferGetNvmapFd(void);
|
u32 nvBufferGetNvmapFd(void);
|
||||||
void nvBufferExit(void);
|
void nvBufferExit(void);
|
||||||
|
|
||||||
Result nvBufferCreate(NvBuffer* m, size_t size, u32 align, NvKind kind, NvAddressSpace* as);
|
Result nvBufferCreate(NvBuffer* m, size_t size, u32 align, bool is_cacheable, NvKind kind, NvAddressSpace* as);
|
||||||
Result nvBufferCreateRw(NvBuffer* m, size_t size, u32 align, NvKind kind, NvAddressSpace* as);
|
|
||||||
void nvBufferFree(NvBuffer* m);
|
void nvBufferFree(NvBuffer* m);
|
||||||
|
|
||||||
void* nvBufferGetCpuAddr(NvBuffer* m);
|
void* nvBufferGetCpuAddr(NvBuffer* m);
|
||||||
@ -32,7 +28,3 @@ iova_t nvBufferGetGpuAddr(NvBuffer* m);
|
|||||||
|
|
||||||
Result nvBufferMapAsTexture(NvBuffer* m, NvKind kind);
|
Result nvBufferMapAsTexture(NvBuffer* m, NvKind kind);
|
||||||
iova_t nvBufferGetGpuAddrTexture(NvBuffer* m);
|
iova_t nvBufferGetGpuAddrTexture(NvBuffer* m);
|
||||||
|
|
||||||
Result nvBufferMakeCpuUncached(NvBuffer* m);
|
|
||||||
Result nvBufferMakeCpuCached(NvBuffer* m);
|
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ typedef enum {
|
|||||||
// Used with nvioctlNvhostAsGpu_MapBufferEx().
|
// Used with nvioctlNvhostAsGpu_MapBufferEx().
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NvMapBufferFlags_FixedOffset = 1,
|
NvMapBufferFlags_FixedOffset = 1,
|
||||||
NvMapBufferFlags_IsCachable = 4,
|
NvMapBufferFlags_IsCacheable = 4,
|
||||||
} NvMapBufferFlags;
|
} NvMapBufferFlags;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -56,10 +56,10 @@ Result nvAddressSpaceReserveFull(NvAddressSpace* a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result nvAddressSpaceMapBuffer(
|
Result nvAddressSpaceMapBuffer(
|
||||||
NvAddressSpace* a, u32 fd, NvKind kind,
|
NvAddressSpace* a, u32 fd, u32 flags, NvKind kind,
|
||||||
iova_t* iova_out) {
|
iova_t* iova_out) {
|
||||||
return nvioctlNvhostAsGpu_MapBufferEx(
|
return nvioctlNvhostAsGpu_MapBufferEx(
|
||||||
a->fd, NvMapBufferFlags_IsCachable, kind, fd, 0x10000, 0, 0, 0, iova_out);
|
a->fd, flags, kind, fd, 0x10000, 0, 0, 0, iova_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result nvAddressSpaceUnmapBuffer(NvAddressSpace* a, iova_t iova) {
|
Result nvAddressSpaceUnmapBuffer(NvAddressSpace* a, iova_t iova) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "arm/atomics.h"
|
#include "arm/atomics.h"
|
||||||
|
#include "arm/cache.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"
|
||||||
@ -18,12 +19,12 @@ Result nvBufferInit(void)
|
|||||||
if (atomicIncrement64(&g_refCnt) > 0)
|
if (atomicIncrement64(&g_refCnt) > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
rc = nvOpen(&g_nvmap_fd, "/dev/nvmap");
|
rc = nvOpen(&g_nvmap_fd, "/dev/nvmap");
|
||||||
|
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
atomicDecrement64(&g_refCnt);
|
atomicDecrement64(&g_refCnt);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nvBufferExit(void)
|
void nvBufferExit(void)
|
||||||
@ -41,8 +42,8 @@ u32 nvBufferGetNvmapFd(void) {
|
|||||||
return g_nvmap_fd;
|
return g_nvmap_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result _nvBufferCreate(
|
Result nvBufferCreate(
|
||||||
NvBuffer* m, size_t size, u32 flags, u32 align, NvKind kind,
|
NvBuffer* m, size_t size, u32 align, bool is_cacheable, NvKind kind,
|
||||||
NvAddressSpace* as)
|
NvAddressSpace* as)
|
||||||
{
|
{
|
||||||
Result rc;
|
Result rc;
|
||||||
@ -50,6 +51,7 @@ static Result _nvBufferCreate(
|
|||||||
size = (size + align - 1) & ~(align - 1);
|
size = (size + align - 1) & ~(align - 1);
|
||||||
|
|
||||||
m->has_init = true;
|
m->has_init = true;
|
||||||
|
m->is_cacheable = is_cacheable;
|
||||||
m->size = size;
|
m->size = size;
|
||||||
m->fd = -1;
|
m->fd = -1;
|
||||||
m->cpu_addr = memalign(align, size);
|
m->cpu_addr = memalign(align, size);
|
||||||
@ -64,11 +66,17 @@ static Result _nvBufferCreate(
|
|||||||
rc = nvioctlNvmap_Create(g_nvmap_fd, size, &m->fd);
|
rc = nvioctlNvmap_Create(g_nvmap_fd, size, &m->fd);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
rc = nvioctlNvmap_Alloc(
|
rc = nvioctlNvmap_Alloc(g_nvmap_fd, m->fd,
|
||||||
g_nvmap_fd, m->fd, 0, flags, align, kind, m->cpu_addr);
|
0, is_cacheable ? 1 : 0, align, kind, m->cpu_addr);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc) && !is_cacheable) {
|
||||||
|
armDCacheFlush(m->cpu_addr, m->size);
|
||||||
|
svcSetMemoryAttribute(m->cpu_addr, m->size, 8, 8);
|
||||||
|
}
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
rc = nvAddressSpaceMapBuffer(as, m->fd, 0, &m->gpu_addr);
|
rc = nvAddressSpaceMapBuffer(as, m->fd,
|
||||||
|
is_cacheable ? NvMapBufferFlags_IsCacheable : 0, NvKind_Pitch, &m->gpu_addr);
|
||||||
|
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
nvBufferFree(m);
|
nvBufferFree(m);
|
||||||
@ -76,24 +84,6 @@ static Result _nvBufferCreate(
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result nvBufferCreate(
|
|
||||||
NvBuffer* m, size_t size, u32 align, NvKind kind, NvAddressSpace* as) {
|
|
||||||
return _nvBufferCreate(m, size, 0, align, kind, as);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result nvBufferCreateRw(
|
|
||||||
NvBuffer* m, size_t size, u32 align, NvKind kind, NvAddressSpace* as) {
|
|
||||||
return _nvBufferCreate(m, size, NvBufferFlags_Writable, align, kind, as);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result nvBufferMakeCpuUncached(NvBuffer* m) {
|
|
||||||
return svcSetMemoryAttribute(m->cpu_addr, m->size, 8, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result nvBufferMakeCpuCached(NvBuffer* m) {
|
|
||||||
return svcSetMemoryAttribute(m->cpu_addr, m->size, 8, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void nvBufferFree(NvBuffer* m)
|
void nvBufferFree(NvBuffer* m)
|
||||||
{
|
{
|
||||||
if (!m->has_init)
|
if (!m->has_init)
|
||||||
@ -115,7 +105,9 @@ void nvBufferFree(NvBuffer* m)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m->cpu_addr) {
|
if (m->cpu_addr) {
|
||||||
nvBufferMakeCpuCached(m);
|
if (!m->is_cacheable)
|
||||||
|
svcSetMemoryAttribute(m->cpu_addr, m->size, 8, 0);
|
||||||
|
|
||||||
free(m->cpu_addr);
|
free(m->cpu_addr);
|
||||||
m->cpu_addr = NULL;
|
m->cpu_addr = NULL;
|
||||||
}
|
}
|
||||||
@ -132,7 +124,8 @@ iova_t nvBufferGetGpuAddr(NvBuffer* m) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result nvBufferMapAsTexture(NvBuffer* m, NvKind kind) {
|
Result nvBufferMapAsTexture(NvBuffer* m, NvKind kind) {
|
||||||
return nvAddressSpaceMapBuffer(m->addr_space, m->fd, kind, &m->gpu_addr_texture);
|
return nvAddressSpaceMapBuffer(m->addr_space, m->fd,
|
||||||
|
m->is_cacheable ? NvMapBufferFlags_IsCacheable : 0, kind, &m->gpu_addr_texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
iova_t nvBufferGetGpuAddrTexture(NvBuffer* m) {
|
iova_t nvBufferGetGpuAddrTexture(NvBuffer* m) {
|
||||||
|
@ -22,12 +22,10 @@ Result nvCmdListCreate(NvCmdList* c, NvGpu* parent, size_t max_cmds)
|
|||||||
Result rc;
|
Result rc;
|
||||||
|
|
||||||
rc = nvBufferCreate(
|
rc = nvBufferCreate(
|
||||||
&c->buffer, max_cmds * 4, 0x1000, NvKind_Pitch,
|
&c->buffer, max_cmds * 4, 0x1000, NvKind_Pitch, false,
|
||||||
&parent->addr_space);
|
&parent->addr_space);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
nvBufferMakeCpuUncached(&c->buffer);
|
|
||||||
|
|
||||||
c->offset = 0;
|
c->offset = 0;
|
||||||
c->num_cmds = 0;
|
c->num_cmds = 0;
|
||||||
c->max_cmds = max_cmds;
|
c->max_cmds = max_cmds;
|
||||||
|
@ -24,13 +24,10 @@ Result nvZcullContextCreate(NvZcullContext* z, NvGpu* parent)
|
|||||||
|
|
||||||
z->parent = parent;
|
z->parent = parent;
|
||||||
|
|
||||||
rc = nvBufferCreateRw(
|
rc = nvBufferCreate(
|
||||||
&z->ctx_buf, nvInfoGetZcullCtxSize(), 0x20000, NvKind_Pitch,
|
&z->ctx_buf, nvInfoGetZcullCtxSize(), 0x20000, NvKind_Pitch, true,
|
||||||
&parent->addr_space);
|
&parent->addr_space);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc))
|
|
||||||
rc = nvBufferMapAsTexture(&z->ctx_buf, NvKind_Generic_16BX2);
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
rc = nvioctlChannel_ZCullBind(
|
rc = nvioctlChannel_ZCullBind(
|
||||||
parent->gpu_channel.fd, nvBufferGetGpuAddr(&z->ctx_buf),
|
parent->gpu_channel.fd, nvBufferGetGpuAddr(&z->ctx_buf),
|
||||||
@ -40,6 +37,5 @@ Result nvZcullContextCreate(NvZcullContext* z, NvGpu* parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void nvZcullContextClose(NvZcullContext* z) {
|
void nvZcullContextClose(NvZcullContext* z) {
|
||||||
// TODO: Unmap z->ctx_buf from parent->addr_space?
|
|
||||||
nvBufferFree(&z->ctx_buf);
|
nvBufferFree(&z->ctx_buf);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user