From mboxrd@z Thu Jan 1 00:00:00 1970 From: Keith Packard Subject: [PATCH 03/18] Don't use libudev for glx/dri3 Date: Fri, 13 Dec 2013 17:25:15 -0800 Message-ID: <1386984330-26074-4-git-send-email-keithp@keithp.com> References: <1386984330-26074-1-git-send-email-keithp@keithp.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1100982202==" Return-path: In-Reply-To: <1386984330-26074-1-git-send-email-keithp@keithp.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: mesa-dev-bounces@lists.freedesktop.org Errors-To: mesa-dev-bounces@lists.freedesktop.org To: mesa-dev@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org --===============1100982202== Content-Type: text/plain; charset=a Content-Transfer-Encoding: quoted-printable libudev doesn't have a stable API/ABI, and if the application wants to us= e one version, we'd best not load another into libGL. Signed-off-by: Keith Packard --- configure.ac | 8 ----- src/glx/dri3_common.c | 85 ++++++++++++++++++++++++++++++---------------= ------ 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/configure.ac b/configure.ac index c14d39a..1193cff 100644 --- a/configure.ac +++ b/configure.ac @@ -824,9 +824,6 @@ xyesno) PKG_CHECK_MODULES([DRI2PROTO], [dri2proto >=3D $DRI2PROTO_REQUIR= ED]) GL_PC_REQ_PRIV=3D"$GL_PC_REQ_PRIV libdrm >=3D $LIBDRM_REQUIRED" if test x"$enable_dri3" =3D xyes; then - if test x"$have_libudev" !=3D xyes; then - AC_MSG_ERROR([DRI3 requires libudev >=3D $LIBUDEV_REQUIRED= ]) - fi PKG_CHECK_MODULES([DRI3PROTO], [dri3proto >=3D $DRI3PROTO_RE= QUIRED]) PKG_CHECK_MODULES([PRESENTPROTO], [presentproto >=3D $PRESEN= TPROTO_REQUIRED]) fi @@ -850,11 +847,6 @@ xyesno) X11_INCLUDES=3D"$X11_INCLUDES $DRIGL_CFLAGS" GL_LIB_DEPS=3D"$DRIGL_LIBS" =20 - if test x"$enable_dri3$have_libudev" =3D xyesyes; then - X11_INCLUDES=3D"$X11_INCLUDES $LIBUDEV_CFLAGS" - GL_LIB_DEPS=3D"$GL_LIB_DEPS $LIBUDEV_LIBS" - fi - # need DRM libs, $PTHREAD_LIBS, etc. GL_LIB_DEPS=3D"$GL_LIB_DEPS $LIBDRM_LIBS -lm $PTHREAD_LIBS $DLOPEN_L= IBS" GL_PC_LIB_PRIV=3D"-lm $PTHREAD_LIBS $DLOPEN_LIBS" diff --git a/src/glx/dri3_common.c b/src/glx/dri3_common.c index c758f96..511fbc8 100644 --- a/src/glx/dri3_common.c +++ b/src/glx/dri3_common.c @@ -23,7 +23,7 @@ /* * This code is derived from src/egl/drivers/dri2/common.c which * carries the following copyright: - *=20 + * * Copyright =C2=A9 2011 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining= a @@ -67,62 +67,80 @@ #include #include #include +#include #include "xf86drm.h" #include "dri_common.h" #include "dri3_priv.h" =20 #define DRIVER_MAP_DRI3_ONLY -#include "pci_ids/pci_id_driver_map.h" =20 -#include +#include "pci_ids/pci_id_driver_map.h" =20 -static struct udev_device * -dri3_udev_device_new_from_fd(struct udev *udev, int fd) +static dev_t +dri3_rdev_from_fd(int fd) { - struct udev_device *device; struct stat buf; =20 if (fstat(fd, &buf) < 0) { ErrorMessageF("DRI3: failed to stat fd %d", fd); - return NULL; + return 0; } + return buf.st_rdev; +} =20 - device =3D udev_device_new_from_devnum(udev, 'c', buf.st_rdev); - if (device =3D=3D NULL) { - ErrorMessageF("DRI3: could not create udev device for fd %d", fd); - return NULL; - } +/* + * There are multiple udev library versions, and they aren't polite abou= t + * symbols, so just avoid using it until some glorious future when the u= dev + * developers figure out how to not break things + */ =20 - return device; +#define SYS_PATH_MAX 256 + +static bool +dri3_read_hex(dev_t rdev, char *entry, int *value) +{ + char path[SYS_PATH_MAX]; + FILE *f; + int r; + + snprintf(path, sizeof (path), "/sys/dev/char/%u:%u/device/%s", + major(rdev), minor(rdev), entry); + + f =3D fopen(path,"r"); + if (f =3D=3D NULL) + return false; + + r =3D fscanf(f, "0x%x\n", value); + fclose(f); + if (r !=3D 1) + return false; + return true; +} + +static bool +dri3_get_pci_id_from_fd(int fd, int *vendorp, int *chipp) +{ + dev_t rdev =3D dri3_rdev_from_fd(fd); + + if (!rdev) + return false; + + if (!dri3_read_hex(rdev, "vendor", vendorp)) + return false; + if (!dri3_read_hex(rdev, "device", chipp)) + return false; + return true; } =20 char * dri3_get_driver_for_fd(int fd) { - struct udev *udev; - struct udev_device *device, *parent; - const char *pci_id; char *driver =3D NULL; int vendor_id, chip_id, i, j; =20 - udev =3D udev_new(); - device =3D dri3_udev_device_new_from_fd(udev, fd); - if (device =3D=3D NULL) + if (!dri3_get_pci_id_from_fd(fd, &vendor_id, &chip_id)) return NULL; =20 - parent =3D udev_device_get_parent(device); - if (parent =3D=3D NULL) { - ErrorMessageF("DRI3: could not get parent device"); - goto out; - } - - pci_id =3D udev_device_get_property_value(parent, "PCI_ID"); - if (pci_id =3D=3D NULL || - sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) !=3D 2) { - ErrorMessageF("DRI3: malformed or no PCI ID"); - goto out; - } - for (i =3D 0; driver_map[i].driver; i++) { if (vendor_id !=3D driver_map[i].vendor_id) continue; @@ -139,8 +157,5 @@ dri3_get_driver_for_fd(int fd) } =20 out: - udev_device_unref(device); - udev_unref(udev); - return driver; } --=20 1.8.4.4 --===============1100982202== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev --===============1100982202==--