[Mesa-dev] [PATCH] loader: Allow a non-udev linux fallback
Lauri Kasanen
cand at gmx.com
Fri Jan 31 03:14:55 PST 2014
It's important not to break existing uses. There is no need to require
udev for 3d. This is an alternative to Stéphane Marchesin's patch
"loader: Make drmGetVersion logic conditional on non-pci devices".
Signed-off-by: Lauri Kasanen <cand at gmx.com>
---
src/egl/drivers/dri2/platform_android.c | 2 +-
src/egl/drivers/dri2/platform_wayland.c | 2 +-
.../auxiliary/pipe-loader/pipe_loader_drm.c | 2 +-
src/gallium/targets/egl-static/egl.c | 2 +-
src/gbm/backends/dri/gbm_dri.c | 2 +-
src/glx/dri2_glx.c | 2 +-
src/glx/dri3_glx.c | 2 +-
src/loader/loader.c | 41 ++++++++++++++++++++--
src/loader/loader.h | 2 +-
9 files changed, 47 insertions(+), 10 deletions(-)
diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
index 4a201c8..65f6a74 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -674,7 +674,7 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
goto cleanup_display;
}
- dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd, 0);
+ dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd, 0, NULL);
if (dri2_dpy->driver_name == NULL) {
err = "DRI2: failed to get driver name";
goto cleanup_device;
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index 50750a9..ac837e6 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -1009,7 +1009,7 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
if (roundtrip(dri2_dpy) < 0 || !dri2_dpy->authenticated)
goto cleanup_fd;
- dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd, 0);
+ dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd, 0, NULL);
if (dri2_dpy->driver_name == NULL) {
_eglError(EGL_BAD_ALLOC, "DRI2: failed to get driver name");
goto cleanup_fd;
diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
index d6869fd..1b5de37 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
@@ -130,7 +130,7 @@ pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd)
pipe_loader_drm_x_auth(fd);
- ddev->base.driver_name = loader_get_driver_for_fd(fd, _LOADER_GALLIUM);
+ ddev->base.driver_name = loader_get_driver_for_fd(fd, _LOADER_GALLIUM, NULL);
if (!ddev->base.driver_name)
goto fail;
diff --git a/src/gallium/targets/egl-static/egl.c b/src/gallium/targets/egl-static/egl.c
index f19f024..b3cd452 100644
--- a/src/gallium/targets/egl-static/egl.c
+++ b/src/gallium/targets/egl-static/egl.c
@@ -61,7 +61,7 @@ create_drm_screen(const char *constname, int fd)
char *name = (char *)constname;
if (!name) {
- name = loader_get_driver_for_fd(fd, _LOADER_GALLIUM);
+ name = loader_get_driver_for_fd(fd, _LOADER_GALLIUM, NULL);
if (!name)
return NULL;
}
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index e013980..900930a 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -272,7 +272,7 @@ dri_screen_create(struct gbm_dri_device *dri)
const __DRIextension **extensions;
int ret = 0;
- dri->base.driver_name = loader_get_driver_for_fd(dri->base.base.fd, 0);
+ dri->base.driver_name = loader_get_driver_for_fd(dri->base.base.fd, 0, NULL);
if (dri->base.driver_name == NULL)
return -1;
diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index 0a0dac9..d1a44f2 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -1197,7 +1197,7 @@ dri2CreateScreen(int screen, struct glx_display * priv)
/* If Mesa knows about the appropriate driver for this fd, then trust it.
* Otherwise, default to the server's value.
*/
- loader_driverName = loader_get_driver_for_fd(psc->fd, 0);
+ loader_driverName = loader_get_driver_for_fd(psc->fd, 0, deviceName);
if (loader_driverName) {
free(driverName);
driverName = loader_driverName;
diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c
index 2a9f0b7..85a8f33 100644
--- a/src/glx/dri3_glx.c
+++ b/src/glx/dri3_glx.c
@@ -1597,7 +1597,7 @@ dri3_create_screen(int screen, struct glx_display * priv)
}
deviceName = NULL;
- driverName = loader_get_driver_for_fd(psc->fd, 0);
+ driverName = loader_get_driver_for_fd(psc->fd, 0, NULL);
if (!driverName) {
ErrorMessageF("No driver found\n");
goto handle_error;
diff --git a/src/loader/loader.c b/src/loader/loader.c
index ee4c1e0..696d338 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -66,6 +66,8 @@
#include <stdarg.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
#include <string.h>
#ifdef HAVE_LIBUDEV
#include <assert.h>
@@ -268,6 +270,40 @@ loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
#endif
+static int
+loader_get_pci_id_for_device(const char *name, int *vendor_id, int *chip_id)
+{
+#ifdef __linux__
+ const char *card = strrchr(name, '/');
+ if (!card) return 0;
+ card++;
+
+ char buf[PATH_MAX];
+ snprintf(buf, PATH_MAX, "/sys/class/drm/%s/device/vendor", card);
+
+ FILE *f = fopen(buf, "r");
+ if (!f) return 0;
+ fgets(buf, PATH_MAX, f);
+ fclose(f);
+
+ int vendor_tmp = strtol(buf, NULL, 16);
+
+ snprintf(buf, PATH_MAX, "/sys/class/drm/%s/device/device", card);
+
+ f = fopen(buf, "r");
+ if (!f) return 0;
+ fgets(buf, PATH_MAX, f);
+ fclose(f);
+
+ int chip_tmp = strtol(buf, NULL, 16);
+
+ *vendor_id = vendor_tmp;
+ *chip_id = chip_tmp;
+ return 1;
+
+#endif
+ return 0;
+}
char *
loader_get_device_name_for_fd(int fd)
@@ -302,7 +338,7 @@ out:
}
char *
-loader_get_driver_for_fd(int fd, unsigned driver_types)
+loader_get_driver_for_fd(int fd, unsigned driver_types, const char *device_name)
{
int vendor_id, chip_id, i, j;
char *driver = NULL;
@@ -310,7 +346,8 @@ loader_get_driver_for_fd(int fd, unsigned driver_types)
if (!driver_types)
driver_types = _LOADER_GALLIUM | _LOADER_DRI;
- if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id)) {
+ if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id) &&
+ !loader_get_pci_id_for_device(device_name, &vendor_id, &chip_id)) {
#ifndef __NOT_HAVE_DRM_H
/* fallback to drmGetVersion(): */
diff --git a/src/loader/loader.h b/src/loader/loader.h
index dfd77ba..a29de28 100644
--- a/src/loader/loader.h
+++ b/src/loader/loader.h
@@ -36,7 +36,7 @@ int
loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id);
char *
-loader_get_driver_for_fd(int fd, unsigned driver_types);
+loader_get_driver_for_fd(int fd, unsigned driver_types, const char *device_name);
char *
loader_get_device_name_for_fd(int fd);
--
1.8.3.1
More information about the mesa-dev
mailing list