summaryrefslogtreecommitdiff
path: root/lib/igt_device.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/igt_device.c')
-rw-r--r--lib/igt_device.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/igt_device.c b/lib/igt_device.c
index 5b3722c8..08f39c8b 100644
--- a/lib/igt_device.c
+++ b/lib/igt_device.c
@@ -22,6 +22,8 @@
*
*/
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
#include "igt.h"
#include "igt_device.h"
@@ -84,3 +86,20 @@ void igt_device_drop_master(int fd)
"Failed to drop DRM master.\n");
}
}
+
+/**
+ * igt_device_get_card_index:
+ * @fd: the device
+ *
+ * Returns:
+ * Index (N) of /dev/dri/cardN or /dev/dri/renderDN corresponding with fd.
+ *
+ */
+int igt_device_get_card_index(int fd)
+{
+ struct stat st;
+
+ igt_fail_on(fstat(fd, &st) || !S_ISCHR(st.st_mode));
+
+ return minor(st.st_rdev);
+}