Created attachment 134848 [details]
The function drm_get_device_name_for_fd in src/loader/loader.c uses dev_node_from_fd which uses Linux-specific major/minor stuff, which does not work correctly on FreeBSD.
Because of this, Wayland EGL clients on FreeBSD receive /dev/dri/card408 instead of /dev/dri/card0 as the device path, and fall back to software rendering :D
The attached patch replaces the code with a call to drmGetDeviceNameFromFd2, which is patched in our packages to work correctly (https://github.com/freebsd/freebsd-ports/blob/master/graphics/libdrm/files/patch-xf86drm.c). (dev_node_from_fd is probably dead code after this patch)
Why wasn't drmGetDeviceNameFromFd2 used in the first place? Why was libdrm's functionality duplicated?
This seems to be some shared code in Mesa, not specific to the EGL Wayland platform, and I'm not sure it's specific to EGL even. Not sure any of the components match, so picking "other".
The code in question was added by:
Author: Jonathan Gray <email@example.com>
Date: Mon Dec 21 16:39:55 2015 +1100
loader: add a libdrm case for loader_get_device_name_for_fd
However, the very first appearance of drmGetDeviceNameFromFd2 in libdrm was:
Author: Emil Velikov <firstname.lastname@example.org>
Date: Thu Nov 10 17:26:50 2016 +0000
xf86drm: introduce drmGetDeviceNameFromFd2
I believe the answer to "why" is that the latter did not exist when the former was written.
Precisely as Pekka said - former's been around in Mesa for ages, while the latter is a recent introduction.
The goal is to have the platform specifics in a smallish piece of software. That plus you can simply bump libdrm requirement and keep using the same Mesa (say because newer one breaks A).
Greg, please send patches to the list for review
Greg, when you have some time please go through the remaining FreeBSD patches  and send them upstream (with commit message, etc.). Thanks.
Fixed by https://cgit.freedesktop.org/mesa/mesa/commit/?id=db8519a369261cdedda50852facc45616d4eba28