Bug 103283 - drm_get_device_name_for_fd is broken on FreeBSD
Summary: drm_get_device_name_for_fd is broken on FreeBSD
Alias: None
Product: Mesa
Classification: Unclassified
Component: Other (show other bugs)
Version: 17.2
Hardware: Other FreeBSD
: medium normal
Assignee: mesa-dev
QA Contact: mesa-dev
Depends on:
Reported: 2017-10-15 14:05 UTC by Greg V
Modified: 2017-10-26 14:48 UTC (History)
0 users

See Also:
i915 platform:
i915 features:

patch-src_loader_loader.c (540 bytes, text/x-csrc)
2017-10-15 14:05 UTC, Greg V

Description Greg V 2017-10-15 14:05:18 UTC
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?
Comment 1 Pekka Paalanen 2017-10-16 06:28:05 UTC
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:

commit 28e3ae344be1c49f50a521792966e0d98510075c
Author: Jonathan Gray <jsg@jsg.id.au>
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:

commit 37d790f7d449874d0bf199d9ca9871d12b4d599a
Author: Emil Velikov <emil.velikov@collabora.com>
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.

Comment 2 Emil Velikov 2017-10-16 12:10:39 UTC
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
Comment 3 Emil Velikov 2017-10-16 12:22:38 UTC
Greg, when you have some time please go through the remaining FreeBSD patches [1] and send them upstream (with commit message, etc.). Thanks.

[1] https://github.com/freebsd/freebsd-ports-graphics/tree/master/graphics/mesa-dri/files

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.