[Mesa-dev] [PATCH 2/2] loader: add dri_driver drirc option to override dri driver to load
Qiang Yu
Qiang.Yu at amd.com
Wed Aug 1 11:10:08 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 driver="k:kernel_driver_name">
<option name="dri_driver" value="new_dri_driver" />
</device>
Signed-off-by: Qiang Yu <Qiang.Yu at amd.com>
---
src/loader/loader.c | 75 ++++++++++++++++++++++++++++++++++----------
src/util/xmlpool/t_options.h | 5 +++
2 files changed, 64 insertions(+), 16 deletions(-)
diff --git a/src/loader/loader.c b/src/loader/loader.c
index 4327548..8c78096 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -82,15 +82,65 @@ loader_open_device(const char *device_name)
return fd;
}
-#if defined(HAVE_LIBDRM)
+static char *loader_get_kernel_driver_name(int fd)
+{
+#if HAVE_LIBDRM
+ char *driver;
+ drmVersionPtr version = drmGetVersion(fd);
+
+ if (!version) {
+ log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd);
+ return NULL;
+ }
+
+ driver = strndup(version->name, version->name_len);
+
+ drmFreeVersion(version);
+ return driver;
+#else
+ return NULL;
+#endif
+}
+
#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 driver[32] = "k:null";
+ char *dri_driver = NULL;
+ char *kernel_driver = loader_get_kernel_driver_name(fd);
+
+ if (kernel_driver) {
+ snprintf(driver, 32, "k:%s", kernel_driver);
+ free(kernel_driver);
+ }
+
+ driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader);
+ driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, 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);
+
+ return dri_driver;
+}
+#endif
+
+#if defined(HAVE_LIBDRM)
+#ifdef USE_DRICONF
static char *loader_get_dri_config_device_id(void)
{
driOptionCache defaultInitOptions;
@@ -338,23 +388,16 @@ loader_get_driver_for_fd(int fd)
return strdup(driver);
}
- if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id)) {
-
-#if HAVE_LIBDRM
- /* fallback to drmGetVersion(): */
- drmVersionPtr version = drmGetVersion(fd);
-
- if (!version) {
- log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd);
- return NULL;
- }
-
- driver = strndup(version->name, version->name_len);
- log_(_LOADER_INFO, "using driver %s for %d\n", driver, fd);
-
- drmFreeVersion(version);
+#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)
+ log_(_LOADER_INFO, "using driver %s for %d\n", driver, fd);
return 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