From: Emil Velikov Date: Thu, 5 Mar 2020 14:41:25 +0000 (+0000) Subject: loader: fallback to kernel name, if PCI fails X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=91478db20d5ccfeb9c35652cf01acdcfcd285414;p=mesa.git loader: fallback to kernel name, if PCI fails 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 Reviewed-by: Adam Jackson Reviewed-by: Eric Engestrom Tested-by: Marge Bot Part-of: --- diff --git a/src/loader/loader.c b/src/loader/loader.c index 38d8752e26e..8548cbdfedb 100644 --- a/src/loader/loader.c +++ b/src/loader/loader.c @@ -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) {