loader: fallback to kernel name, if PCI fails
authorEmil Velikov <emil.velikov@collabora.com>
Thu, 5 Mar 2020 14:41:25 +0000 (14:41 +0000)
committerEmil Velikov <emil.l.velikov@gmail.com>
Wed, 1 Apr 2020 15:57:22 +0000 (16:57 +0100)
Currently, if the PCI machinery fails, we return a NULL driver name.
In the past this has resulted in various workarounds.

To avoid those, fallback to loader_get_kernel_driver_name(). It's not
perfect, yet perfectly reasonable.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4084>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4084>

src/loader/loader.c

index 38d8752e26e6c9eca9b801fd685a05d08be74874..8548cbdfedb369b7e855adb603e6f2275d8543aa 100644 (file)
@@ -428,33 +428,14 @@ loader_get_device_name_for_fd(int fd)
    return result;
 }
 
-char *
-loader_get_driver_for_fd(int fd)
+static char *
+loader_get_pci_driver(int fd)
 {
    int vendor_id, chip_id, i, j;
    char *driver = NULL;
 
-   /* Allow an environment variable to force choosing a different driver
-    * binary.  If that driver binary can't survive on this FD, that's the
-    * user's problem, but this allows vc4 simulator to run on an i965 host,
-    * and may be useful for some touch testing of i915 on an i965 host.
-    */
-   if (geteuid() == getuid()) {
-      driver = getenv("MESA_LOADER_DRIVER_OVERRIDE");
-      if (driver)
-         return strdup(driver);
-   }
-
-#if defined(HAVE_LIBDRM) && defined(USE_DRICONF)
-   driver = loader_get_dri_config_driver(fd);
-   if (driver)
-      return driver;
-#endif
-
-   if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id)) {
-      driver = loader_get_kernel_driver_name(fd);
-      return driver;
-   }
+   if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id))
+      return NULL;
 
    for (i = 0; i < ARRAY_SIZE(driver_map); i++) {
       if (vendor_id != driver_map[i].vendor_id)
@@ -482,6 +463,35 @@ out:
    return driver;
 }
 
+char *
+loader_get_driver_for_fd(int fd)
+{
+   char *driver;
+
+   /* Allow an environment variable to force choosing a different driver
+    * binary.  If that driver binary can't survive on this FD, that's the
+    * user's problem, but this allows vc4 simulator to run on an i965 host,
+    * and may be useful for some touch testing of i915 on an i965 host.
+    */
+   if (geteuid() == getuid()) {
+      driver = getenv("MESA_LOADER_DRIVER_OVERRIDE");
+      if (driver)
+         return strdup(driver);
+   }
+
+#if defined(HAVE_LIBDRM) && defined(USE_DRICONF)
+   driver = loader_get_dri_config_driver(fd);
+   if (driver)
+      return driver;
+#endif
+
+   driver = loader_get_pci_driver(fd);
+   if (!driver)
+      driver = loader_get_kernel_driver_name(fd);
+
+   return driver;
+}
+
 void
 loader_set_logger(loader_logger *logger)
 {