[PATCH 2/7] xf86drm: Add function to retrieve char device path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Used to access device controls

Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@xxxxxxx>
---
 xf86drm.c | 23 +++++++++++++++++++++++
 xf86drm.h |  1 +
 2 files changed, 24 insertions(+)

diff --git a/xf86drm.c b/xf86drm.c
index edfeb347..a5ecd323 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -4361,6 +4361,29 @@ drm_public char *drmGetDeviceNameFromFd2(int fd)
 #endif
 }
 
+drm_public char *drmGetCharDeviceFromFd(int fd)
+{
+#ifdef __linux__
+    struct stat sbuf;
+    char path[PATH_MAX + 1];
+    unsigned int maj, min;
+
+    if (fstat(fd, &sbuf))
+        return NULL;
+
+    maj = major(sbuf.st_rdev);
+    min = minor(sbuf.st_rdev);
+
+    if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
+        return NULL;
+
+    snprintf(path, sizeof(path), "/sys/dev/char/%d:%d", maj, min);
+    return strdup(path);
+#else
+    return NULL;
+#endif
+}
+
 drm_public int drmSyncobjCreate(int fd, uint32_t flags, uint32_t *handle)
 {
     struct drm_syncobj_create args;
diff --git a/xf86drm.h b/xf86drm.h
index 9fc06ab8..c172dbc1 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -812,6 +812,7 @@ extern char *drmGetDeviceNameFromFd(int fd);
  */
 extern char *drmGetDeviceNameFromFd2(int fd);
 extern int drmGetNodeTypeFromFd(int fd);
+extern char *drmGetCharDeviceFromFd(int fd);
 
 /* Convert between GEM handles and DMA-BUF file descriptors.
  *
-- 
2.25.1




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux