Skip to content

Commit

Permalink
Fix NV ioctl nameclashes...
Browse files Browse the repository at this point in the history
...with bsd ioctls (coming soon) & C++ stdlib
  • Loading branch information
TuxSH authored and plutooo committed Feb 10, 2018
1 parent 7ef7311 commit 507bf71
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 132 deletions.
64 changes: 32 additions & 32 deletions nx/include/switch/gfx/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@

//The below defines are from Linux kernel ioctl.h.

#define _IOC_NRBITS 8
#define _IOC_TYPEBITS 8
#define _IOC_SIZEBITS 14
#define _IOC_DIRBITS 2
#define _NV_IOC_NRBITS 8
#define _NV_IOC_TYPEBITS 8
#define _NV_IOC_SIZEBITS 14
#define _NV_IOC_DIRBITS 2

#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
#define _NV_IOC_NRMASK ((1 << _NV_IOC_NRBITS)-1)
#define _NV_IOC_TYPEMASK ((1 << _NV_IOC_TYPEBITS)-1)
#define _NV_IOC_SIZEMASK ((1 << _NV_IOC_SIZEBITS)-1)
#define _NV_IOC_DIRMASK ((1 << _NV_IOC_DIRBITS)-1)

#define _IOC_NRSHIFT 0
#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
#define _NV_IOC_NRSHIFT 0
#define _NV_IOC_TYPESHIFT (_NV_IOC_NRSHIFT+_NV_IOC_NRBITS)
#define _NV_IOC_SIZESHIFT (_NV_IOC_TYPESHIFT+_NV_IOC_TYPEBITS)
#define _NV_IOC_DIRSHIFT (_NV_IOC_SIZESHIFT+_NV_IOC_SIZEBITS)

/*
* Direction bits.
*/
#define _IOC_NONE 0U
#define _IOC_WRITE 1U
#define _IOC_READ 2U
#define _NV_IOC_NONE 0U
#define _NV_IOC_WRITE 1U
#define _NV_IOC_READ 2U

#define _IOC(dir,type,nr,size) \
(((dir) << _IOC_DIRSHIFT) | \
((type) << _IOC_TYPESHIFT) | \
((nr) << _IOC_NRSHIFT) | \
((size) << _IOC_SIZESHIFT))
#define _NV_IOC(dir,type,nr,size) \
(((dir) << _NV_IOC_DIRSHIFT) | \
((type) << _NV_IOC_TYPESHIFT) | \
((nr) << _NV_IOC_NRSHIFT) | \
((size) << _NV_IOC_SIZESHIFT))

/* used to create numbers */
#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
#define _NV_IO(type,nr) _NV_IOC(_NV_IOC_NONE,(type),(nr),0)
#define _NV_IOR(type,nr,size) _NV_IOC(_NV_IOC_READ,(type),(nr),sizeof(size))
#define _NV_IOW(type,nr,size) _NV_IOC(_NV_IOC_WRITE,(type),(nr),sizeof(size))
#define _NV_IOWR(type,nr,size) _NV_IOC(_NV_IOC_READ|_NV_IOC_WRITE,(type),(nr),sizeof(size))

/* used to decode ioctl numbers.. */
#define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
#define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
#define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
#define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)

#define _in_
#define _out_
#define _inout_
#define _NV_IOC_DIR(nr) (((nr) >> _NV_IOC_DIRSHIFT) & _NV_IOC_DIRMASK)
#define _NV_IOC_TYPE(nr) (((nr) >> _NV_IOC_TYPESHIFT) & _NV_IOC_TYPEMASK)
#define _NV_IOC_NR(nr) (((nr) >> _NV_IOC_NRSHIFT) & _NV_IOC_NRMASK)
#define _NV_IOC_SIZE(nr) (((nr) >> _NV_IOC_SIZESHIFT) & _NV_IOC_SIZEMASK)

#define __nv_in
#define __nv_out
#define __nv_inout
64 changes: 32 additions & 32 deletions nx/source/gfx/ioctl/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

Result nvioctlChannel_SetNvmapFd(u32 fd, u32 nvmap_fd) {
struct {
_in_ u32 fd;
__nv_in u32 fd;
} data;

memset(&data, 0, sizeof(data));
data.fd = nvmap_fd;

return nvIoctl(fd, _IOW(0x48, 0x01, data), &data);
return nvIoctl(fd, _NV_IOW(0x48, 0x01, data), &data);
}

Result nvioctlChannel_SubmitGpfifo(u32 fd, nvioctl_gpfifo_entry *entries, u32 num_entries, u32 flags, nvioctl_fence *fence_out) {
Expand All @@ -24,11 +24,11 @@ Result nvioctlChannel_SubmitGpfifo(u32 fd, nvioctl_gpfifo_entry *entries, u32 nu
return MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);

struct {
_in_ u64 gpfifo; // (ignored) pointer to gpfifo entry structs
_in_ u32 num_entries; // number of entries being submitted
_in_ u32 flags;
_out_ nvioctl_fence fence_out; // returned new fence object for others to wait on
_in_ nvioctl_gpfifo_entry entries[num_entries]; // depends on num_entries
__nv_in u64 gpfifo; // (ignored) pointer to gpfifo entry structs
__nv_in u32 num_entries; // number of entries being submitted
__nv_in u32 flags;
__nv_out nvioctl_fence fence_out; // returned new fence object for others to wait on
__nv_in nvioctl_gpfifo_entry entries[num_entries]; // depends on num_entries
} data;


Expand All @@ -38,7 +38,7 @@ Result nvioctlChannel_SubmitGpfifo(u32 fd, nvioctl_gpfifo_entry *entries, u32 nu
data.flags = flags;
memcpy(data.entries, entries, sizeof(data.entries));

rc = nvIoctl(fd, _IOWR(0x48, 0x08, data), &data);
rc = nvIoctl(fd, _NV_IOWR(0x48, 0x08, data), &data);

if (R_SUCCEEDED(rc) && fence_out) {
memcpy(fence_out, &data.fence_out, sizeof(data.fence_out));
Expand All @@ -49,38 +49,38 @@ Result nvioctlChannel_SubmitGpfifo(u32 fd, nvioctl_gpfifo_entry *entries, u32 nu

Result nvioctlChannel_AllocObjCtx(u32 fd, u32 class_num, u32 flags) {
struct {
_in_ u32 class_num;
_in_ u32 flags;
_in_ u64 obj_id; // (ignored) used for FREE_OBJ_CTX ioctl, which is not supported
__nv_in u32 class_num;
__nv_in u32 flags;
__nv_in u64 obj_id; // (ignored) used for FREE_OBJ_CTX ioctl, which is not supported
} data;

memset(&data, 0, sizeof(data));
data.class_num = class_num;
data.flags = flags;
data.obj_id = 0xDEADBEEF;

return nvIoctl(fd, _IOWR(0x48, 0x09, data), &data);
return nvIoctl(fd, _NV_IOWR(0x48, 0x09, data), &data);
}

Result nvioctlChannel_ZCullBind(u32 fd, u64 gpu_va, u32 mode) {
struct {
_in_ u64 gpu_va;
_in_ u32 mode;
_in_ u32 padding;
__nv_in u64 gpu_va;
__nv_in u32 mode;
__nv_in u32 padding;
} data;

memset(&data, 0, sizeof(data));
data.gpu_va = gpu_va;
data.mode = mode;

return nvIoctl(fd, _IOWR(0x48, 0x0B, data), &data);
return nvIoctl(fd, _NV_IOWR(0x48, 0x0B, data), &data);
}

Result nvioctlChannel_SetErrorNotifier(u32 fd, u64 offset, u64 size, u32 nvmap_handle) {
struct {
_in_ u64 offset;
_in_ u64 size;
_in_ u32 nvmap_handle;
__nv_in u64 offset;
__nv_in u64 size;
__nv_in u32 nvmap_handle;
u32 padding;
} data;

Expand All @@ -89,31 +89,31 @@ Result nvioctlChannel_SetErrorNotifier(u32 fd, u64 offset, u64 size, u32 nvmap_h
data.size = size;
data.nvmap_handle = nvmap_handle;

return nvIoctl(fd, _IOWR(0x48, 0x0C, data), &data);
return nvIoctl(fd, _NV_IOWR(0x48, 0x0C, data), &data);
}

Result nvioctlChannel_SetPriority(u32 fd, u32 priority) {
struct {
_in_ u32 priority; // 0x32 is low, 0x64 is medium and 0x96 is high
__nv_in u32 priority; // 0x32 is low, 0x64 is medium and 0x96 is high
} data;

memset(&data, 0, sizeof(data));
data.priority = priority;

return nvIoctl(fd, _IOW(0x48, 0x0D, data), &data);
return nvIoctl(fd, _NV_IOW(0x48, 0x0D, data), &data);
}

Result nvioctlChannel_AllocGpfifoEx2(u32 fd, u32 num_entries, u32 flags, u32 unk0, u32 unk1, u32 unk2, u32 unk3, nvioctl_fence *fence_out) {
Result rc=0;

struct {
_in_ u32 num_entries;
_in_ u32 flags;
_in_ u32 unk0; // (1 works)
_out_ nvioctl_fence fence_out;
_in_ u32 unk1;
_in_ u32 unk2;
_in_ u32 unk3;
__nv_in u32 num_entries;
__nv_in u32 flags;
__nv_in u32 unk0; // (1 works)
__nv_out nvioctl_fence fence_out;
__nv_in u32 unk1;
__nv_in u32 unk2;
__nv_in u32 unk3;
} data;

memset(&data, 0, sizeof(data));
Expand All @@ -124,7 +124,7 @@ Result nvioctlChannel_AllocGpfifoEx2(u32 fd, u32 num_entries, u32 flags, u32 unk
data.unk2 = unk2;
data.unk3 = unk3;

rc = nvIoctl(fd, _IOWR(0x48, 0x1A, data), &data);
rc = nvIoctl(fd, _NV_IOWR(0x48, 0x1A, data), &data);

if (R_SUCCEEDED(rc) && fence_out) {
memcpy(fence_out, &data.fence_out, sizeof(data.fence_out));
Expand All @@ -135,11 +135,11 @@ Result nvioctlChannel_AllocGpfifoEx2(u32 fd, u32 num_entries, u32 flags, u32 unk

Result nvioctlChannel_SetUserData(u32 fd, void* addr) {
struct {
_in_ u64 addr;
__nv_in u64 addr;
} data;

memset(&data, 0, sizeof(data));
data.addr = (u64)addr;

return nvIoctl(fd, _IOW(0x47, 0x14, data), &data);
return nvIoctl(fd, _NV_IOW(0x47, 0x14, data), &data);
}
54 changes: 27 additions & 27 deletions nx/source/gfx/ioctl/nvhost-as-gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

Result nvioctlNvhostAsGpu_BindChannel(u32 fd, u32 channel_fd) {
struct {
_in_ u32 fd;
__nv_in u32 fd;
} data;

memset(&data, 0, sizeof(data));
data.fd = channel_fd;

return nvIoctl(fd, _IOW(0x41, 0x01, data), &data);
return nvIoctl(fd, _NV_IOW(0x41, 0x01, data), &data);
}

Result nvioctlNvhostAsGpu_AllocSpace(u32 fd, u32 pages, u32 page_size, u32 flags, u64 align, u64 *offset) {
Result rc = 0;

struct {
_in_ u32 pages;
_in_ u32 page_size;
_in_ u32 flags;
__nv_in u32 pages;
__nv_in u32 page_size;
__nv_in u32 flags;
u32 pad;
union {
_out_ u64 offset;
_in_ u64 align;
__nv_out u64 offset;
__nv_in u64 align;
};
} data;

Expand All @@ -36,7 +36,7 @@ Result nvioctlNvhostAsGpu_AllocSpace(u32 fd, u32 pages, u32 page_size, u32 flags
data.flags = flags;
data.align = align;

rc = nvIoctl(fd, _IOWR(0x41, 0x02, data), &data);
rc = nvIoctl(fd, _NV_IOWR(0x41, 0x02, data), &data);
if (R_FAILED(rc)) return rc;

*offset = data.offset;
Expand All @@ -51,13 +51,13 @@ Result nvioctlNvhostAsGpu_MapBufferEx(
Result rc = 0;

struct {
_in_ u32 flags; // bit0: fixed_offset, bit2: cacheable
_in_ u32 kind; // -1 is default
_in_ u32 nvmap_handle;
_inout_ u32 page_size; // 0 means don't care
_in_ u64 buffer_offset;
_in_ u64 mapping_size;
_inout_ u64 offset;
__nv_in u32 flags; // bit0: fixed_offset, bit2: cacheable
__nv_in u32 kind; // -1 is default
__nv_in u32 nvmap_handle;
__nv_inout u32 page_size; // 0 means don't care
__nv_in u64 buffer_offset;
__nv_in u64 mapping_size;
__nv_inout u64 offset;
} data;

memset(&data, 0, sizeof(data));
Expand All @@ -69,7 +69,7 @@ Result nvioctlNvhostAsGpu_MapBufferEx(
data.mapping_size = mapping_size;
data.offset = input_offset;

rc = nvIoctl(fd, _IOWR(0x41, 0x06, data), &data);
rc = nvIoctl(fd, _NV_IOWR(0x41, 0x06, data), &data);

if (R_SUCCEEDED(rc) && offset) {
*offset = data.offset;
Expand All @@ -83,15 +83,15 @@ Result nvioctlNvhostAsGpu_GetVARegions(u32 fd, nvioctl_va_region regions[2]) {

struct {
u64 not_used; // contained output user ptr on linux, ignored
_inout_ u32 bufsize; // forced to 2*sizeof(struct va_region)
__nv_inout u32 bufsize; // forced to 2*sizeof(struct va_region)
u32 pad;
_out_ nvioctl_va_region regions[2];
__nv_out nvioctl_va_region regions[2];
} data;

memset(&data, 0, sizeof(data));
data.bufsize = sizeof(data.regions);

rc = nvIoctl(fd, _IOWR(0x41, 0x08, data), &data);
rc = nvIoctl(fd, _NV_IOWR(0x41, 0x08, data), &data);

if (R_SUCCEEDED(rc)) {
memcpy(regions, data.regions, sizeof(data.regions));
Expand All @@ -102,18 +102,18 @@ Result nvioctlNvhostAsGpu_GetVARegions(u32 fd, nvioctl_va_region regions[2]) {

Result nvioctlNvhostAsGpu_InitializeEx(u32 fd, u32 big_page_size, u32 flags) {
struct {
_in_ u32 big_page_size; // depends on GPU's available_big_page_sizes; 0=default
_in_ s32 as_fd; // ignored; passes 0
_in_ u32 flags; // ignored; passes 0
_in_ u32 reserved; // ignored; passes 0
_in_ u64 unk0;
_in_ u64 unk1;
_in_ u64 unk2;
__nv_in u32 big_page_size; // depends on GPU's available_big_page_sizes; 0=default
__nv_in s32 as_fd; // ignored; passes 0
__nv_in u32 flags; // ignored; passes 0
__nv_in u32 reserved; // ignored; passes 0
__nv_in u64 unk0;
__nv_in u64 unk1;
__nv_in u64 unk2;
} data;

memset(&data, 0, sizeof(data));
data.big_page_size = big_page_size;
data.flags = flags;

return nvIoctl(fd, _IOW(0x41, 0x09, data), &data);
return nvIoctl(fd, _NV_IOW(0x41, 0x09, data), &data);
}
Loading

0 comments on commit 507bf71

Please sign in to comment.