[Mesa-dev] [PATCH] pipe_loader: Try to make a connection with the X server before probing pciids
Francisco Jerez
currojerez at riseup.net
Wed Jul 18 06:01:35 PDT 2012
Tom Stellard <tstellar at gmail.com> writes:
> When X is running it is neccesary for pipe_loader to authenticate with
> DRM, in order to be able to use the device.
>
> This makes it possible to run OpenCL programs while X is running.
Looks good to me. Just two nitpicks: can you factor out the DRI2
authentication to a separate procedure and try to avoid C++-style
comments in C code?
> ---
> configure.ac | 6 ++
> .../auxiliary/pipe-loader/pipe_loader_drm.c | 57 ++++++++++++++++++++
> 2 files changed, 63 insertions(+), 0 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 10216a3..35cc579 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -2084,6 +2084,12 @@ if test "x$enable_gallium_loader" = xyes; then
>
> if test "x$enable_gallium_drm_loader" = xyes; then
> GALLIUM_PIPE_LOADER_DEFINES="$GALLIUM_PIPE_LOADER_DEFINES -DHAVE_PIPE_LOADER_DRM"
> + PKG_CHECK_MODULES([GALLIUM_PIPE_LOADER_XCB], [x11-xcb xcb-dri2],
> + pipe_loader_have_xcb=yes, pipe_loader_have_xcb=no)
> + if test "x$pipe_loader_have_xcb" = xyes; then
> + GALLIUM_PIPE_LOADER_DEFINES="$GALLIUM_PIPE_LOADER_DEFINES -DPIPE_LOADER_HAVE_XCB"
> + GALLIUM_PIPE_LOADER_LIBS="$GALLIUM_PIPE_LOADER_LIBS $GALLIUM_PIPE_LOADER_XCB_LIBS $LIBDRM_LIBS"
> + fi
> fi
>
> AC_SUBST([GALLIUM_PIPE_LOADER_DEFINES])
> diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
> index 518f3da..6af455c 100644
> --- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
> +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
> @@ -35,6 +35,13 @@
> #include <libudev.h>
> #include <xf86drm.h>
>
> +#ifdef PIPE_LOADER_HAVE_XCB
> +
> +#include <X11/Xlib-xcb.h>
> +#include <xcb/dri2.h>
> +
> +#endif
> +
> #include "state_tracker/drm_driver.h"
> #include "pipe_loader_priv.h"
>
> @@ -132,6 +139,56 @@ pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd)
> {
> struct pipe_loader_drm_device *ddev = CALLOC_STRUCT(pipe_loader_drm_device);
>
> +#if PIPE_LOADER_HAVE_XCB
> + // Try authenticate with the X server to give us access to devices that X
> + // is running on.
> + Display *disp;
> + xcb_connection_t *xcb_conn;
> + xcb_screen_iterator_t s;
> + xcb_dri2_connect_cookie_t connect_cookie;
> + xcb_dri2_connect_reply_t *connect;
> + drm_magic_t magic;
> + xcb_dri2_authenticate_cookie_t authenticate_cookie;
> + xcb_dri2_authenticate_reply_t *authenticate;
> +
> + disp = XOpenDisplay(NULL);
> +
> + if (!disp)
> + goto done;
> +
> + xcb_conn = XGetXCBConnection(disp);
> +
> + if(!xcb_conn)
> + goto done;
> +
> + s = xcb_setup_roots_iterator(xcb_get_setup(xcb_conn));
> + connect_cookie = xcb_dri2_connect_unchecked(xcb_conn, s.data->root,
> + XCB_DRI2_DRIVER_TYPE_DRI);
> + connect = xcb_dri2_connect_reply(xcb_conn, connect_cookie, NULL);
> +
> + if (!connect || connect->driver_name_length
> + + connect->device_name_length == 0) {
> +
> + goto free_connect;
> + }
> +
> + if (drmGetMagic(fd, &magic))
> + goto free_connect;
> +
> + authenticate_cookie = xcb_dri2_authenticate_unchecked(xcb_conn,
> + s.data->root,
> + magic);
> + authenticate = xcb_dri2_authenticate_reply(xcb_conn,
> + authenticate_cookie,
> + NULL);
> +
> + FREE(authenticate);
> +free_connect:
> + FREE(connect);
> +done:
> +
> +#endif
> +
> ddev->base.type = PIPE_LOADER_DEVICE_PCI;
> ddev->base.ops = &pipe_loader_drm_ops;
> ddev->fd = fd;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 229 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20120718/eacafa09/attachment.pgp>
More information about the mesa-dev
mailing list