summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Jones <jajones@nvidia.com>2021-03-18 15:36:07 -0700
committerMarge Bot <eric+marge@anholt.net>2021-07-06 16:58:00 +0000
commit21ce1ca846698527093b0f8b95a57c550f984ab1 (patch)
tree772fb3357cf2cbbe84ddd546c295de1079b9bbab
parent68902822d6e0133f3e51f08b9ce86c86b34bc651 (diff)
gbm: Load backend based on DRM device driver name
After attempting to use the GBM backend specified by the user via an environment variable, if any, but before falling back to the built-in GBM backends, attempt to dlopen libg<DRM driver name>_gbm.so in the GBM backend library search path (Defaults to "$libdir/gbm") and initialize a device using it. This enables automatic backend discovery for devices that do not provide a DRI driver. Signed-off-by: James Jones <jajones@nvidia.com> Reviewed-by: Michel Dänzer <mdaenzer@redhat.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9902>
-rw-r--r--src/gbm/main/backend.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/gbm/main/backend.c b/src/gbm/main/backend.c
index b628c403faa..974d0a76a4e 100644
--- a/src/gbm/main/backend.c
+++ b/src/gbm/main/backend.c
@@ -34,6 +34,7 @@
#include <limits.h>
#include <assert.h>
#include <dlfcn.h>
+#include <xf86drm.h>
#include "loader.h"
#include "backend.h"
@@ -53,6 +54,7 @@ static const struct gbm_backend_desc builtin_backends[] = {
{ "dri", &gbm_dri_backend },
};
+#define BACKEND_LIB_SUFFIX "_gbm"
static const char *backend_search_path_vars[] = {
"GBM_BACKENDS_PATH",
NULL
@@ -161,7 +163,7 @@ find_backend(const char *name, int fd)
}
if (name && !dev) {
- lib = loader_open_driver_lib(name, "_gbm",
+ lib = loader_open_driver_lib(name, BACKEND_LIB_SUFFIX,
backend_search_path_vars,
DEFAULT_BACKENDS_PATH,
true);
@@ -186,6 +188,29 @@ override_backend(int fd)
return dev;
}
+static struct gbm_device *
+backend_from_driver_name(int fd)
+{
+ struct gbm_device *dev = NULL;
+ drmVersionPtr v = drmGetVersion(fd);
+ void *lib;
+
+ if (!v)
+ return NULL;
+
+ lib = loader_open_driver_lib(v->name, BACKEND_LIB_SUFFIX,
+ backend_search_path_vars,
+ DEFAULT_BACKENDS_PATH,
+ false);
+
+ if (lib)
+ dev = load_backend(lib, fd, v->name);
+
+ drmFreeVersion(v);
+
+ return dev;
+}
+
struct gbm_device *
_gbm_create_device(int fd)
{
@@ -194,6 +219,9 @@ _gbm_create_device(int fd)
dev = override_backend(fd);
if (!dev)
+ dev = backend_from_driver_name(fd);
+
+ if (!dev)
dev = find_backend(NULL, fd);
return dev;