diff --git a/nx/include/switch.h b/nx/include/switch.h index cfebdb41..7c43ca47 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -35,6 +35,7 @@ extern "C" { #include #include #include +#include #ifdef __cplusplus } diff --git a/nx/include/switch/gfx/ioctl.h b/nx/include/switch/gfx/ioctl.h new file mode 100644 index 00000000..44d5db27 --- /dev/null +++ b/nx/include/switch/gfx/ioctl.h @@ -0,0 +1,40 @@ +//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 _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 _IOC_NRSHIFT 0 +#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) +#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) +#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) + +/* + * Direction bits. + */ +#define _IOC_NONE 0U +#define _IOC_WRITE 1U +#define _IOC_READ 2U + +#define _IOC(dir,type,nr,size) \ + (((dir) << _IOC_DIRSHIFT) | \ + ((type) << _IOC_TYPESHIFT) | \ + ((nr) << _IOC_NRSHIFT) | \ + ((size) << _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)) + +/* used to decode ioctl numbers.. */ + +#define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK) + diff --git a/nx/include/switch/services/nv.h b/nx/include/switch/services/nv.h index ac33c21b..5a8d974d 100644 --- a/nx/include/switch/services/nv.h +++ b/nx/include/switch/services/nv.h @@ -1,37 +1,3 @@ -//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 _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 _IOC_NRSHIFT 0 -#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) -#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) -#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) - -/* - * Direction bits. - */ -#define _IOC_NONE 0U -#define _IOC_WRITE 1U -#define _IOC_READ 2U - -#define _IOC(dir,type,nr,size) \ - (((dir) << _IOC_DIRSHIFT) | \ - ((type) << _IOC_TYPESHIFT) | \ - ((nr) << _IOC_NRSHIFT) | \ - ((size) << _IOC_SIZESHIFT)) - -/* used to decode ioctl numbers.. */ - -#define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK) - typedef enum { NVSERVTYPE_Default = -1, NVSERVTYPE_Application = 0, diff --git a/nx/source/services/nv.c b/nx/source/services/nv.c index 03a1619c..26272b3d 100644 --- a/nx/source/services/nv.c +++ b/nx/source/services/nv.c @@ -176,9 +176,11 @@ Result nvOpen(u32 *fd, const char *devicepath) { u64 magic; u64 result; u32 fd; + u32 error; } *resp = r.Raw; rc = resp->result; + if (R_SUCCEEDED(rc)) rc = resp->error; if (R_SUCCEEDED(rc)) *fd = resp->fd; } @@ -231,9 +233,11 @@ Result nvIoctl(u32 fd, u32 request, void* argp) { struct { u64 magic; u64 result; + u32 error; } *resp = r.Raw; rc = resp->result; + if (R_SUCCEEDED(rc)) rc = resp->error; } return rc; @@ -263,9 +267,11 @@ Result nvClose(u32 fd) { struct { u64 magic; u64 result; + u32 error; } *resp = r.Raw; rc = resp->result; + if (R_SUCCEEDED(rc)) rc = resp->error; } return rc;