From patchwork Mon Nov 18 00:55:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 3195211 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A2695C045B for ; Mon, 18 Nov 2013 00:55:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9DD93206B3 for ; Mon, 18 Nov 2013 00:55:48 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5DBBF205EA for ; Mon, 18 Nov 2013 00:55:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4452FFD313 for ; Sun, 17 Nov 2013 16:55:45 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from keithp.com (home.keithp.com [63.227.221.253]) by gabe.freedesktop.org (Postfix) with ESMTP id 2C0CFFD30F; Sun, 17 Nov 2013 16:55:26 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by keithp.com (Postfix) with ESMTP id C39E11488005; Sun, 17 Nov 2013 16:55:25 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from keithp.com ([127.0.0.1]) by localhost (keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id MdPC0QXTL4QB; Sun, 17 Nov 2013 16:55:22 -0800 (PST) Received: by keithp.com (Postfix, from userid 1033) id 32DBD1488002; Sun, 17 Nov 2013 16:55:21 -0800 (PST) Received: from miki.keithp.com (localhost [127.0.0.1]) by keithp.com (Postfix) with ESMTP id A396F148C005; Sun, 17 Nov 2013 16:55:21 -0800 (PST) Received: by miki.keithp.com (Postfix, from userid 1001) id 4D0D6B05; Mon, 18 Nov 2013 09:55:21 +0900 (KST) From: Keith Packard To: mesa-dev@lists.freedesktop.org Subject: [PATCH] Don't use libudev for glx/dri3 Date: Sun, 17 Nov 2013 16:55:12 -0800 Message-Id: <1384736112-6023-1-git-send-email-keithp@keithp.com> X-Mailer: git-send-email 1.8.4.2 Cc: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY, URIBL_BLACK autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP libudev doesn't have a stable API/ABI, and if the application wants to use one version, we'd best not load another into libGL. Signed-off-by: Keith Packard --- configure.ac | 5 +-- src/glx/dri3_common.c | 106 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 94 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 63c2973..10e9e0f 100644 --- a/configure.ac +++ b/configure.ac @@ -821,7 +821,6 @@ xyesno) GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV libdrm >= $LIBDRM_REQUIRED" PKG_CHECK_MODULES([DRI3PROTO], [dri3proto >= $DRI3PROTO_REQUIRED]) PKG_CHECK_MODULES([PRESENTPROTO], [presentproto >= $PRESENTPROTO_REQUIRED]) - PKG_CHECK_MODULES([LIBUDEV], [libudev >= $LIBUDEV_REQUIRED]) fi # find the DRI deps for libGL @@ -835,8 +834,8 @@ xyesno) PKG_CHECK_MODULES([DRIGL], [$dri_modules]) GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV $dri_modules" - X11_INCLUDES="$X11_INCLUDES $DRIGL_CFLAGS $LIBUDEV_CFLAGS" - GL_LIB_DEPS="$DRIGL_LIBS $LIBUDEV_LIBS" + X11_INCLUDES="$X11_INCLUDES $DRIGL_CFLAGS" + GL_LIB_DEPS="$DRIGL_LIBS" # need DRM libs, $PTHREAD_LIBS, etc. GL_LIB_DEPS="$GL_LIB_DEPS $LIBDRM_LIBS -lm $PTHREAD_LIBS $DLOPEN_LIBS" diff --git a/src/glx/dri3_common.c b/src/glx/dri3_common.c index c758f96..01c9d09 100644 --- a/src/glx/dri3_common.c +++ b/src/glx/dri3_common.c @@ -72,22 +72,41 @@ #include "dri3_priv.h" #define DRIVER_MAP_DRI3_ONLY + #include "pci_ids/pci_id_driver_map.h" +static dev_t +dri3_rdev_from_fd(int fd) +{ + struct stat buf; + + if (fstat(fd, &buf) < 0) { + ErrorMessageF("DRI3: failed to stat fd %d", fd); + return 0; + } + return buf.st_rdev; +} + +/* + * There are multiple udev library versions, and they aren't polite about + * symbols, so just avoid using it until some glorious future when the udev + * developers figure out how to not break things + */ + +#define USE_UDEV 0 +#if USE_UDEV #include static struct udev_device * dri3_udev_device_new_from_fd(struct udev *udev, int fd) { struct udev_device *device; - struct stat buf; + dev_t rdev = dri3_rdev_from_fd(fd); - if (fstat(fd, &buf) < 0) { - ErrorMessageF("DRI3: failed to stat fd %d", fd); + if (rdev == 0) return NULL; - } - device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev); + device = udev_device_new_from_devnum(udev, 'c', rdev); if (device == NULL) { ErrorMessageF("DRI3: could not create udev device for fd %d", fd); return NULL; @@ -96,19 +115,20 @@ dri3_udev_device_new_from_fd(struct udev *udev, int fd) return device; } -char * -dri3_get_driver_for_fd(int fd) +static int +dri3_get_pci_id_from_fd(int fd, int *vendorp, int *chipp) { struct udev *udev; struct udev_device *device, *parent; const char *pci_id; - char *driver = NULL; - int vendor_id, chip_id, i, j; + int ret = 0; udev = udev_new(); + if (!udev) + goto no_udev; device = dri3_udev_device_new_from_fd(udev, fd); if (device == NULL) - return NULL; + goto no_dev; parent = udev_device_get_parent(device); if (parent == NULL) { @@ -118,10 +138,71 @@ dri3_get_driver_for_fd(int fd) pci_id = udev_device_get_property_value(parent, "PCI_ID"); if (pci_id == NULL || - sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) != 2) { + sscanf(pci_id, "%x:%x", vendorp, chipp) != 2) { ErrorMessageF("DRI3: malformed or no PCI ID"); goto out; } + ret = 1; + +out: + udev_device_unref(device); +no_dev: + udev_unref(udev); +no_udev: + return ret; +} +#else + +#define SYS_PATH_MAX 256 + +static int +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); + + printf ("path %s\n", path); + + f = fopen(path,"r"); + if (f == NULL) + return 0; + + r = fscanf(f, "0x%x\n", value); + fclose(f); + if (r != 1) + return 0; + return 1; +} + +static int +dri3_get_pci_id_from_fd(int fd, int *vendorp, int *chipp) +{ + dev_t rdev = dri3_rdev_from_fd(fd); + + if (!rdev) + return 0; + + if (!dri3_read_hex(rdev, "vendor", vendorp)) + return 0; + if (!dri3_read_hex(rdev, "device", chipp)) + return 0; + return 1; +} + +#endif + +char * +dri3_get_driver_for_fd(int fd) +{ + char *driver = NULL; + int vendor_id, chip_id, i, j; + + if (!dri3_get_pci_id_from_fd(fd, &vendor_id, &chip_id)) + return NULL; for (i = 0; driver_map[i].driver; i++) { if (vendor_id != driver_map[i].vendor_id) @@ -139,8 +220,5 @@ dri3_get_driver_for_fd(int fd) } out: - udev_device_unref(device); - udev_unref(udev); - return driver; }