summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gray <jsg@jsg.id.au>2016-04-19 12:29:36 +1000
committerEmil Velikov <emil.l.velikov@gmail.com>2016-05-05 11:46:44 +0100
commitdd5dd62c34bf9c91023d87e8eae9671ad70ce9dc (patch)
treef4424d74796b48a4767f4716a9c2108bae00cf07
parentef4e4fb445ebd9ab98bcfb7fe0f0c6c3a0371754 (diff)
egl/x11: authenticate before doing chipset id ioctls
For systems without udev or sysfs that use drm ioctls in the loader drm authentication must take place earlier or the loader will fail "MESA-LOADER: failed to get param for i915". Patch from Mark Kettenis. Cc: "11.2 11.1" <mesa-stable@lists.freedesktop.org> Signed-off-by: Mark Kettenis <kettenis@openbsd.org> Signed-off-by: Jonathan Gray <jsg@jsg.id.au> [Emil Velikov: remove gratuitous white-space] Reviewed-by: Emil Velikov <emil.velikov@collabora.com> (cherry picked from commit 9bbf3737f9c96377bee65b947da3e63adaa58d58) Squashed with commit egl/x11: resolve "initialization from incompatible pointer type" warning With earlier commit we've moved a few functions and changing the argument type from _EGLDisplay * to struct dri2_egl_display *. The latter is effectively a wrapper around the former, thus functionality was preserved, although GCC rightfully warned us about the misuse. Add a simple wrapper that casts and propagates the correct type. Fixes: 9bbf3737f9c ("egl/x11: authenticate before doing chipset id ioctls") Cc: "11.2 11.1" <mesa-stable@lists.freedesktop.org> Reported-by: Matt Turner <mattst88@gmail.com> Signed-off-by: Emil Velikov <emil.velikov@collabora.com> (cherry picked from commit b8e59292e6a19673ca34a8aaeeb26d75dca23f3f)
-rw-r--r--src/egl/drivers/dri2/platform_x11.c104
1 files changed, 57 insertions, 47 deletions
diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c
index 3ab91886e01..c0a4005d08e 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -542,6 +542,55 @@ dri2_x11_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
#endif
}
+static int
+dri2_x11_do_authenticate(struct dri2_egl_display *dri2_dpy, uint32_t id)
+{
+ xcb_dri2_authenticate_reply_t *authenticate;
+ xcb_dri2_authenticate_cookie_t authenticate_cookie;
+ xcb_screen_iterator_t s;
+ xcb_screen_t *screen;
+ int ret = 0;
+
+ s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
+
+ screen = get_xcb_screen(s, dri2_dpy->screen);
+ if (!screen) {
+ _eglLog(_EGL_WARNING, "DRI2: failed to get xcb screen");
+ return -1;
+ }
+
+ authenticate_cookie =
+ xcb_dri2_authenticate_unchecked(dri2_dpy->conn, screen->root, id);
+ authenticate =
+ xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL);
+
+ if (authenticate == NULL || !authenticate->authenticated)
+ ret = -1;
+
+ free(authenticate);
+
+ return ret;
+}
+
+static EGLBoolean
+dri2_x11_local_authenticate(struct dri2_egl_display *dri2_dpy)
+{
+#ifdef HAVE_LIBDRM
+ drm_magic_t magic;
+
+ if (drmGetMagic(dri2_dpy->fd, &magic)) {
+ _eglLog(_EGL_WARNING, "DRI2: failed to get drm magic");
+ return EGL_FALSE;
+ }
+
+ if (dri2_x11_do_authenticate(dri2_dpy, magic) < 0) {
+ _eglLog(_EGL_WARNING, "DRI2: failed to authenticate");
+ return EGL_FALSE;
+ }
+#endif
+ return EGL_TRUE;
+}
+
static EGLBoolean
dri2_x11_connect(struct dri2_egl_display *dri2_dpy)
{
@@ -630,6 +679,13 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy)
return EGL_FALSE;
}
+ if (!dri2_x11_local_authenticate(dri2_dpy)) {
+ close(dri2_dpy->fd);
+ free(dri2_dpy->device_name);
+ free(connect);
+ return EGL_FALSE;
+ }
+
driver_name = xcb_dri2_connect_driver_name (connect);
/* If Mesa knows about the appropriate driver for this fd, then trust it.
@@ -660,51 +716,8 @@ static int
dri2_x11_authenticate(_EGLDisplay *disp, uint32_t id)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- xcb_dri2_authenticate_reply_t *authenticate;
- xcb_dri2_authenticate_cookie_t authenticate_cookie;
- xcb_screen_iterator_t s;
- xcb_screen_t *screen;
- int ret = 0;
-
- s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
-
- screen = get_xcb_screen(s, dri2_dpy->screen);
- if (!screen) {
- _eglLog(_EGL_WARNING, "DRI2: failed to get xcb screen");
- return -1;
- }
-
- authenticate_cookie =
- xcb_dri2_authenticate_unchecked(dri2_dpy->conn, screen->root, id);
- authenticate =
- xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL);
-
- if (authenticate == NULL || !authenticate->authenticated)
- ret = -1;
-
- free(authenticate);
-
- return ret;
-}
-
-static EGLBoolean
-dri2_x11_local_authenticate(_EGLDisplay *disp)
-{
-#ifdef HAVE_LIBDRM
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- drm_magic_t magic;
- if (drmGetMagic(dri2_dpy->fd, &magic)) {
- _eglLog(_EGL_WARNING, "DRI2: failed to get drm magic");
- return EGL_FALSE;
- }
-
- if (dri2_x11_authenticate(disp, magic) < 0) {
- _eglLog(_EGL_WARNING, "DRI2: failed to authenticate");
- return EGL_FALSE;
- }
-#endif
- return EGL_TRUE;
+ return dri2_x11_do_authenticate(dri2_dpy, id);
}
static EGLBoolean
@@ -1390,9 +1403,6 @@ dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp)
if (!dri2_x11_connect(dri2_dpy))
goto cleanup_conn;
- if (!dri2_x11_local_authenticate(disp))
- goto cleanup_fd;
-
if (!dri2_load_driver(disp))
goto cleanup_fd;