summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Binns <frank.binns@imgtec.com>2015-02-13 10:51:15 +0000
committerEmil Velikov <emil.l.velikov@gmail.com>2015-02-23 09:29:19 +0000
commit1f73578df32f895a678a41758f6c563f49484347 (patch)
tree4370fb5ecf5b2446045c62e6353d91ad77a0abdd
parent5c1c09e0d28cde4341777b966c21568fd9b51516 (diff)
Add new drmGetNodeTypeFromFd function
Add a helper function that returns the type of device node from an fd. Signed-off-by: Frank Binns <frank.binns@imgtec.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
-rw-r--r--xf86drm.c39
-rw-r--r--xf86drm.h1
2 files changed, 40 insertions, 0 deletions
diff --git a/xf86drm.c b/xf86drm.c
index d85115ca..e117bc63 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -505,6 +505,23 @@ static int drmGetMinorBase(int type)
};
}
+static int drmGetMinorType(int minor)
+{
+ int type = minor >> 6;
+
+ if (minor < 0)
+ return -1;
+
+ switch (type) {
+ case DRM_NODE_PRIMARY:
+ case DRM_NODE_CONTROL:
+ case DRM_NODE_RENDER:
+ return type;
+ default:
+ return -1;
+ }
+}
+
/**
* Open the device by bus ID.
*
@@ -2667,6 +2684,28 @@ char *drmGetDeviceNameFromFd(int fd)
return strdup(name);
}
+int drmGetNodeTypeFromFd(int fd)
+{
+ struct stat sbuf;
+ int maj, min, type;
+
+ if (fstat(fd, &sbuf))
+ return -1;
+
+ maj = major(sbuf.st_rdev);
+ min = minor(sbuf.st_rdev);
+
+ if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ type = drmGetMinorType(min);
+ if (type == -1)
+ errno = ENODEV;
+ return type;
+}
+
int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd)
{
struct drm_prime_handle args;
diff --git a/xf86drm.h b/xf86drm.h
index 77937eb9..afd38a10 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -744,6 +744,7 @@ typedef struct _drmEventContext {
extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
extern char *drmGetDeviceNameFromFd(int fd);
+extern int drmGetNodeTypeFromFd(int fd);
extern int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd);
extern int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle);