loader: add dri_driver option to override dri driver to load
authorQiang Yu <Qiang.Yu@amd.com>
Mon, 6 Aug 2018 03:19:27 +0000 (11:19 +0800)
committerEmil Velikov <emil.l.velikov@gmail.com>
Fri, 17 Aug 2018 16:16:32 +0000 (17:16 +0100)
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>

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

v3:
  seperate loader_get_kernel_driver_name into another patch
  seperate add kernel_driver attribute into another patch

Suggested-by: Michel Dänzer <michel@daenzer.net>
Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
Acked-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
[v4 Emil: add HAVE_LIBDRM guard around __driConfigOptionsLoader and
loader_get_dri_config_driver]
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
src/loader/loader.c
src/util/xmlpool/t_options.h

index 9480be97fd0d77afdf434a0612228fb624a1ac04..2e37d113b8de04601318449e47e451d73090bc09 100644 (file)
@@ -108,9 +108,33 @@ 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;
+}
+
 static char *loader_get_dri_config_device_id(void)
 {
    driOptionCache defaultInitOptions;
@@ -358,6 +382,12 @@ loader_get_driver_for_fd(int fd)
          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);
       if (driver)
index f0537e965b8a3cda894c51937691a0d5d9504dd4..d4881b334e1b69edd8998fcb239a75d2bca7fe82 100644 (file)
@@ -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
  */