[Mesa-dev] [PATCH 2/2] egl: Don't add hardware device if there is no render node.

Mathias.Froehlich at gmx.net Mathias.Froehlich at gmx.net
Thu Jun 6 11:10:48 UTC 2019


From: Mathias Fröhlich <Mathias.Froehlich at gmx.net>

Do not offer a hardware drm backed egl device if no render node
is available. The current implementation will fail on this
egl device. On top it issues a warning that is actually missleading.
There are finally more error paths that can fail on the way to a
hardware backed egl device. Fixing all of them would kind of require
opening the drm device and see if there is a usable driver associated
with the device. The taken approach avoids a full probe and fixes at
least this kind of problem on kvm virtualization hosts I observe here.

Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
---
 src/egl/main/egldevice.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/egl/main/egldevice.c b/src/egl/main/egldevice.c
index 76b8960fa5b..6b791383af5 100644
--- a/src/egl/main/egldevice.c
+++ b/src/egl/main/egldevice.c
@@ -105,12 +105,16 @@ _EGLDevice _eglSoftwareDevice = {
  * Negative value on error, zero if newly added, one if already in list.
  */
 static int
-_eglAddDRMDevice(drmDevicePtr device, _EGLDevice **out_dev)
+_eglAddDRMDevice(drmDevicePtr device, bool also_primary, _EGLDevice **out_dev)
 {
    _EGLDevice *dev;
+   int wanted_nodes = 1 << DRM_NODE_RENDER;

-   if ((device->available_nodes & (1 << DRM_NODE_PRIMARY |
-                                   1 << DRM_NODE_RENDER)) == 0)
+   /* In case we have an fd given initially, we can accept a primary node */
+   if (also_primary)
+      wanted_nodes |= 1 << DRM_NODE_PRIMARY;
+
+   if ((device->available_nodes & wanted_nodes) == 0)
       return -1;

    dev = _eglGlobal.DeviceList;
@@ -176,7 +180,7 @@ _eglAddDevice(int fd, bool software)
    }

    /* Device is not added - error or already present */
-   if (_eglAddDRMDevice(device, &dev) != 0)
+   if (_eglAddDRMDevice(device, true, &dev) != 0)
       drmFreeDevice(&device);
 #else
    _eglLog(_EGL_FATAL, "Driver bug: Built without libdrm, yet looking for HW device");
@@ -273,7 +277,7 @@ _eglRefreshDeviceList(void)

    num_devs = drmGetDevices2(0, devices, ARRAY_SIZE(devices));
    for (int i = 0; i < num_devs; i++) {
-      ret = _eglAddDRMDevice(devices[i], NULL);
+      ret = _eglAddDRMDevice(devices[i], false, NULL);

       /* Device is not added - error or already present */
       if (ret != 0)
--
2.21.0



More information about the mesa-dev mailing list