[Mesa-dev] [PATCH v3 6/6] loader: add dri_driver option to override dri driver to load

Qiang Yu Qiang.Yu at amd.com
Mon Aug 6 03:19:27 UTC 2018


drirc implementation of MESA_LOADER_DRIVER_OVERRIDE which can be
used to override dri driver to load.

Usage:

override dri driver for device with spec kernel driver name:

<device kernel_driver="kernel_driver_name">
  <option name="dri_driver" value="new_dri_driver" />
</device>

or

<device driver="loader" kernel_driver="kernel_driver_name">
  <option name="dri_driver" value="new_dri_driver" />
</device>

v3:
  1. seperate loader_get_kernel_driver_name into another patch
  2. seperate add kernel_driver attribute into another patch

v2:
  add kernel_driver device attribute to specify kernel
  driver name instead of reuse driver attribute

Suggested-by: Michel Dänzer <michel at daenzer.net>
Signed-off-by: Qiang Yu <Qiang.Yu at amd.com>
---
 src/loader/loader.c          | 34 +++++++++++++++++++++++++++++++++-
 src/util/xmlpool/t_options.h |  5 +++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/src/loader/loader.c b/src/loader/loader.c
index 39db094..f9adbe8 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -102,15 +102,41 @@ static char *loader_get_kernel_driver_name(int fd)
 #endif
 }
 
-#if defined(HAVE_LIBDRM)
 #ifdef USE_DRICONF
 static const char __driConfigOptionsLoader[] =
 DRI_CONF_BEGIN
     DRI_CONF_SECTION_INITIALIZATION
         DRI_CONF_DEVICE_ID_PATH_TAG()
+        DRI_CONF_DRI_DRIVER()
     DRI_CONF_SECTION_END
 DRI_CONF_END;
 
+static char *loader_get_dri_config_driver(int fd)
+{
+   driOptionCache defaultInitOptions;
+   driOptionCache userInitOptions;
+   char *dri_driver = NULL;
+   char *kernel_driver = loader_get_kernel_driver_name(fd);
+
+   driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader);
+   driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0,
+                       "loader", kernel_driver);
+   if (driCheckOption(&userInitOptions, "dri_driver", DRI_STRING)) {
+      char *opt = driQueryOptionstr(&userInitOptions, "dri_driver");
+      /* not an empty string */
+      if (*opt)
+         dri_driver = strdup(opt);
+   }
+   driDestroyOptionCache(&userInitOptions);
+   driDestroyOptionInfo(&defaultInitOptions);
+
+   free(kernel_driver);
+   return dri_driver;
+}
+#endif
+
+#if defined(HAVE_LIBDRM)
+#ifdef USE_DRICONF
 static char *loader_get_dri_config_device_id(void)
 {
    driOptionCache defaultInitOptions;
@@ -358,6 +384,12 @@ loader_get_driver_for_fd(int fd)
          return strdup(driver);
    }
 
+#ifdef 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);
       if (driver)
diff --git a/src/util/xmlpool/t_options.h b/src/util/xmlpool/t_options.h
index f0537e9..d4881b3 100644
--- a/src/util/xmlpool/t_options.h
+++ b/src/util/xmlpool/t_options.h
@@ -411,6 +411,11 @@ DRI_CONF_OPT_BEGIN(device_id, string, def) \
         DRI_CONF_DESC(en,gettext("Define the graphic device to use if possible")) \
 DRI_CONF_OPT_END
 
+#define DRI_CONF_DRI_DRIVER(def) \
+DRI_CONF_OPT_BEGIN(dri_driver, string, def) \
+        DRI_CONF_DESC(en,gettext("Override the DRI driver to load")) \
+DRI_CONF_OPT_END
+
 /**
  * \brief Gallium-Nine specific configuration options
  */
-- 
2.7.4



More information about the mesa-dev mailing list