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 <manu@FreeBSD.org>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
main
Emmanuel Vadot 2020-01-21 17:42:44 +01:00 committed by Emmanuel Vadot
parent 1f8ada8023
commit 1c8d2b73a6
1 changed files with 14 additions and 0 deletions

View File

@ -59,6 +59,10 @@
#endif #endif
#include <math.h> #include <math.h>
#if defined(__FreeBSD__)
#include <sys/param.h>
#endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
/* Not all systems have MAP_FAILED defined */ /* 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", snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device/drm",
maj, min); maj, min);
return stat(path, &sbuf) == 0; 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 #else
return maj == DRM_MAJOR; return maj == DRM_MAJOR;
#endif #endif