summaryrefslogtreecommitdiff
path: root/xf86drm.c
diff options
context:
space:
mode:
authorEmmanuel Vadot <manu@FreeBSD.Org>2020-01-21 17:53:07 +0100
committerEmmanuel Vadot <manu@FreeBSD.org>2020-04-21 19:26:54 +0200
commit57c50cfc45f8c4f95bffff88ec7bcc056d3b23be (patch)
tree101b340178750b5eb79d520b4cd7489873d55e9c /xf86drm.c
parent6818a50b1215081d6a7b7b710f504a6b182320c8 (diff)
downloadlibdrm-57c50cfc45f8c4f95bffff88ec7bcc056d3b23be.tar.gz
libdrm-57c50cfc45f8c4f95bffff88ec7bcc056d3b23be.tar.bz2
libdrm-57c50cfc45f8c4f95bffff88ec7bcc056d3b23be.zip
libdrm: drmGetMinorNameForFD: Add FreeBSD variant
Use the FreeBSD variant function to obtain the minor name and the device node. Return the correct path based on where the node is (drm/ versus dri/). Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org> Reviewed-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Diffstat (limited to 'xf86drm.c')
-rw-r--r--xf86drm.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/xf86drm.c b/xf86drm.c
index e6f6a890..e7f441eb 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2938,6 +2938,38 @@ static char *drmGetMinorNameForFD(int fd, int type)
closedir(sysdir);
return NULL;
+#elif __FreeBSD__
+ struct stat sbuf;
+ char dname[SPECNAMELEN];
+ const char *mname;
+ char name[SPECNAMELEN];
+ int id, 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;
+
+ if (!devname_r(sbuf.st_rdev, S_IFCHR, dname, sizeof(dname)))
+ return NULL;
+
+ /* Handle both /dev/drm and /dev/dri
+ * FreeBSD on amd64/i386/powerpc external kernel modules create node in
+ * in /dev/drm/ and links in /dev/dri while a WIP in kernel driver creates
+ * only device nodes in /dev/dri/ */
+ mname = drmGetMinorName(type);
+ if (sscanf(dname, "drm/%d", &id) != 1) {
+ snprintf(name, sizeof(name), "dri/%s", mname);
+ if (strncmp(name, dname, strlen(name)) != 0)
+ return NULL;
+ snprintf(name, sizeof(name), "/dev/%s", dname);
+ } else
+ snprintf(name, sizeof(name), DRM_DIR_NAME "/%s%d", mname, id);
+ return strdup(name);
#else
struct stat sbuf;
char buf[PATH_MAX + 1];