From 1c8d2b73a681e4d9b65fda101e05f9770d5e4e82 Mon Sep 17 00:00:00 2001 From: Emmanuel Vadot Date: Tue, 21 Jan 2020 17:42:44 +0100 Subject: [PATCH] libdrm: drmNodeIsDRM: Add FreeBSD variant FreeBSD devfs have on the gly generated major minor so we cannot use them to test if the device is a drm node. Instead get the devfs node name and test if it is in a subdirectory "drm/" or "dri/". Historycally DRM device on FreeBSD are created in /dev/drm/ and link are present in /dev/dri/ for compatibility reason. Signed-off-by: Emmanuel Vadot Reviewed-by: Eric Engestrom Reviewed-by: Emil Velikov --- xf86drm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/xf86drm.c b/xf86drm.c index d240f95b..63ba1ede 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -59,6 +59,10 @@ #endif #include +#if defined(__FreeBSD__) +#include +#endif + #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) /* Not all systems have MAP_FAILED defined */ @@ -2777,6 +2781,16 @@ static bool drmNodeIsDRM(int maj, int min) snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device/drm", maj, min); return stat(path, &sbuf) == 0; +#elif __FreeBSD__ + char name[SPECNAMELEN]; + + if (!devname_r(makedev(maj, min), S_IFCHR, name, sizeof(name))) + return 0; + /* Handle drm/ and dri/ as both are present in different FreeBSD version + * 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/ */ + return (!strncmp(name, "drm/", 4) || !strncmp(name, "dri/", 4)); #else return maj == DRM_MAJOR; #endif