[Mesa-dev] [PATCH v2 3/3] loader: add drirc option to override dri driver to load
Qiang Yu
Qiang.Yu at amd.com
Fri Aug 3 08:19:32 UTC 2018
v2:
add kernel_driver device attribute to specify kernel
driver name instead of reuse driver attribute.
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>
Suggested-by: Michel Dänzer <michel at daenzer.net>
Signed-off-by: Qiang Yu <Qiang.Yu at amd.com>
---
src/gallium/auxiliary/pipe-loader/pipe_loader.c | 2 +-
src/gallium/targets/d3dadapter9/drm.c | 2 +-
src/loader/loader.c | 75 +++++++++++++++++++------
src/mesa/drivers/dri/common/dri_util.c | 2 +-
src/mesa/drivers/dri/i915/intel_context.c | 2 +-
src/mesa/drivers/dri/i965/brw_context.c | 3 +-
src/mesa/drivers/dri/i965/intel_screen.c | 2 +-
src/mesa/drivers/dri/r200/r200_context.c | 2 +-
src/mesa/drivers/dri/radeon/radeon_context.c | 2 +-
src/util/xmlconfig.c | 10 +++-
src/util/xmlconfig.h | 3 +-
src/util/xmlpool/t_options.h | 5 ++
12 files changed, 82 insertions(+), 28 deletions(-)
diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.c b/src/gallium/auxiliary/pipe-loader/pipe_loader.c
index e7cf9f8..6fd1552 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.c
@@ -108,7 +108,7 @@ pipe_loader_load_options(struct pipe_loader_device *dev)
driParseOptionInfo(&dev->option_info, xml_options);
driParseConfigFiles(&dev->option_cache, &dev->option_info, 0,
- dev->driver_name);
+ dev->driver_name, NULL);
}
char *
diff --git a/src/gallium/targets/d3dadapter9/drm.c b/src/gallium/targets/d3dadapter9/drm.c
index 9c5bd8a..85b3e10 100644
--- a/src/gallium/targets/d3dadapter9/drm.c
+++ b/src/gallium/targets/d3dadapter9/drm.c
@@ -252,7 +252,7 @@ drm_create_adapter( int fd,
ctx->base.throttling = FALSE;
driParseOptionInfo(&defaultInitOptions, __driConfigOptionsNine);
- driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "nine");
+ driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "nine", NULL);
if (driCheckOption(&userInitOptions, "throttle_value", DRI_INT)) {
throttling_value_user = driQueryOptioni(&userInitOptions, "throttle_value");
if (throttling_value_user == -1)
diff --git a/src/loader/loader.c b/src/loader/loader.c
index 4327548..3ad6b36 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -82,15 +82,63 @@ 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 *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);
+
+ if (kernel_driver)
+ 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;
@@ -98,7 +146,7 @@ static char *loader_get_dri_config_device_id(void)
char *prime = NULL;
driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader);
- driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "loader");
+ driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "loader", NULL);
if (driCheckOption(&userInitOptions, "device_id", DRI_STRING))
prime = strdup(driQueryOptionstr(&userInitOptions, "device_id"));
driDestroyOptionCache(&userInitOptions);
@@ -338,23 +386,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/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c
index d257cb6..4649096 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -146,7 +146,7 @@ driCreateNewScreen2(int scrn, int fd,
/* Option parsing before ->InitScreen(), as some options apply there. */
driParseOptionInfo(&psp->optionInfo, __dri2ConfigOptions);
- driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum, "dri2");
+ driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum, "dri2", NULL);
*driver_configs = psp->driver->InitScreen(psp);
if (*driver_configs == NULL) {
diff --git a/src/mesa/drivers/dri/i915/intel_context.c b/src/mesa/drivers/dri/i915/intel_context.c
index f22ebbd..9a6e49d 100644
--- a/src/mesa/drivers/dri/i915/intel_context.c
+++ b/src/mesa/drivers/dri/i915/intel_context.c
@@ -448,7 +448,7 @@ intelInitContext(struct intel_context *intel,
0, sizeof(ctx->TextureFormatSupported));
driParseConfigFiles(&intel->optionCache, &intelScreen->optionCache,
- sPriv->myNum, "i915");
+ sPriv->myNum, "i915", NULL);
intel->maxBatchSize = 4096;
/* Estimate the size of the mappable aperture into the GTT. There's an
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 968fc1d..0f65438 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -788,7 +788,8 @@ brw_process_driconf_options(struct brw_context *brw)
driOptionCache *options = &brw->optionCache;
driParseConfigFiles(options, &brw->screen->optionCache,
- brw->driContext->driScreenPriv->myNum, "i965");
+ brw->driContext->driScreenPriv->myNum,
+ "i965", NULL);
int bo_reuse_mode = driQueryOptioni(options, "bo_reuse");
switch (bo_reuse_mode) {
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index cb35741..b630848 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -2442,7 +2442,7 @@ __DRIconfig **intelInitScreen2(__DRIscreen *dri_screen)
memset(&options, 0, sizeof(options));
driParseOptionInfo(&options, brw_config_options.xml);
- driParseConfigFiles(&screen->optionCache, &options, dri_screen->myNum, "i965");
+ driParseConfigFiles(&screen->optionCache, &options, dri_screen->myNum, "i965", NULL);
driDestroyOptionCache(&options);
screen->driScrnPriv = dri_screen;
diff --git a/src/mesa/drivers/dri/r200/r200_context.c b/src/mesa/drivers/dri/r200/r200_context.c
index 9417dfc..cfdc9b8 100644
--- a/src/mesa/drivers/dri/r200/r200_context.c
+++ b/src/mesa/drivers/dri/r200/r200_context.c
@@ -216,7 +216,7 @@ GLboolean r200CreateContext( gl_api api,
* the default textures.
*/
driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache,
- screen->driScreen->myNum, "r200");
+ screen->driScreen->myNum, "r200", NULL);
rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache,
"def_max_anisotropy");
diff --git a/src/mesa/drivers/dri/radeon/radeon_context.c b/src/mesa/drivers/dri/radeon/radeon_context.c
index 28ced81..e1e8764 100644
--- a/src/mesa/drivers/dri/radeon/radeon_context.c
+++ b/src/mesa/drivers/dri/radeon/radeon_context.c
@@ -183,7 +183,7 @@ r100CreateContext( gl_api api,
* the default textures.
*/
driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache,
- screen->driScreen->myNum, "radeon");
+ screen->driScreen->myNum, "radeon", NULL);
rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache,
"def_max_anisotropy");
diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c
index 120c6cf..c0578b8 100644
--- a/src/util/xmlconfig.c
+++ b/src/util/xmlconfig.c
@@ -690,6 +690,7 @@ struct OptConfData {
driOptionCache *cache;
int screenNum;
const char *driverName, *execName;
+ const char *kernelDriverName;
uint32_t ignoringDevice;
uint32_t ignoringApp;
uint32_t inDriConf;
@@ -714,14 +715,17 @@ static void
parseDeviceAttr(struct OptConfData *data, const XML_Char **attr)
{
uint32_t i;
- const XML_Char *driver = NULL, *screen = NULL;
+ const XML_Char *driver = NULL, *screen = NULL, *kernel = NULL;
for (i = 0; attr[i]; i += 2) {
if (!strcmp (attr[i], "driver")) driver = attr[i+1];
else if (!strcmp (attr[i], "screen")) screen = attr[i+1];
+ else if (!strcmp (attr[i], "kernel_driver")) kernel = attr[i+1];
else XML_WARNING("unknown device attribute: %s.", attr[i]);
}
if (driver && strcmp (driver, data->driverName))
data->ignoringDevice = data->inDevice;
+ else if (kernel && (!data->kernelDriverName || strcmp (kernel, data->kernelDriverName)))
+ data->ignoringDevice = data->inDevice;
else if (screen) {
driOptionValue screenNum;
if (!parseValue (&screenNum, DRI_INT, screen))
@@ -974,7 +978,8 @@ parseConfigDir(struct OptConfData *data, const char *dirname)
void
driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
- int screenNum, const char *driverName)
+ int screenNum, const char *driverName,
+ const char *kernelDriverName)
{
char *home;
struct OptConfData userData;
@@ -984,6 +989,7 @@ driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
userData.cache = cache;
userData.screenNum = screenNum;
userData.driverName = driverName;
+ userData.kernelDriverName = kernelDriverName;
userData.execName = util_get_process_name();
parseConfigDir(&userData, DATADIR "/drirc.d");
diff --git a/src/util/xmlconfig.h b/src/util/xmlconfig.h
index f7683a6..68e8171 100644
--- a/src/util/xmlconfig.h
+++ b/src/util/xmlconfig.h
@@ -105,7 +105,8 @@ void driParseOptionInfo (driOptionCache *info,
* To be called in <driver>CreateContext. screenNum and driverName select
* device sections. */
void driParseConfigFiles (driOptionCache *cache, const driOptionCache *info,
- int screenNum, const char *driverName);
+ int screenNum, const char *driverName,
+ const char *kernelDriverName);
/** \brief Destroy option info
*
* To be called in <driver>DestroyScreen */
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