[Mesa-dev] [PATCH 03/18] Don't use libudev for glx/dri3

Keith Packard keithp at keithp.com
Fri Dec 13 17:25:15 PST 2013


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 <keithp at keithp.com>
---
 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 >= $DRI2PROTO_REQUIRED])
         GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV libdrm >= $LIBDRM_REQUIRED"
         if test x"$enable_dri3" = xyes; then
-            if test x"$have_libudev" != xyes; then
-              AC_MSG_ERROR([DRI3 requires libudev >= $LIBUDEV_REQUIRED])
-            fi
             PKG_CHECK_MODULES([DRI3PROTO], [dri3proto >= $DRI3PROTO_REQUIRED])
             PKG_CHECK_MODULES([PRESENTPROTO], [presentproto >= $PRESENTPROTO_REQUIRED])
         fi
@@ -850,11 +847,6 @@ xyesno)
     X11_INCLUDES="$X11_INCLUDES $DRIGL_CFLAGS"
     GL_LIB_DEPS="$DRIGL_LIBS"
 
-    if test x"$enable_dri3$have_libudev" = xyesyes; then
-        X11_INCLUDES="$X11_INCLUDES $LIBUDEV_CFLAGS"
-        GL_LIB_DEPS="$GL_LIB_DEPS $LIBUDEV_LIBS"
-    fi
-
     # need DRM libs, $PTHREAD_LIBS, etc.
     GL_LIB_DEPS="$GL_LIB_DEPS $LIBDRM_LIBS -lm $PTHREAD_LIBS $DLOPEN_LIBS"
     GL_PC_LIB_PRIV="-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:
- * 
+ *
  * Copyright © 2011 Intel Corporation
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -67,62 +67,80 @@
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <sys/time.h>
+#include <stdbool.h>
 #include "xf86drm.h"
 #include "dri_common.h"
 #include "dri3_priv.h"
 
 #define DRIVER_MAP_DRI3_ONLY
-#include "pci_ids/pci_id_driver_map.h"
 
-#include <libudev.h>
+#include "pci_ids/pci_id_driver_map.h"
 
-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;
 
    if (fstat(fd, &buf) < 0) {
       ErrorMessageF("DRI3: failed to stat fd %d", fd);
-      return NULL;
+      return 0;
    }
+   return buf.st_rdev;
+}
 
-   device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev);
-   if (device == 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 about
+ * symbols, so just avoid using it until some glorious future when the udev
+ * developers figure out how to not break things
+ */
 
-   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 = fopen(path,"r");
+   if (f == NULL)
+      return false;
+
+   r = fscanf(f, "0x%x\n", value);
+   fclose(f);
+   if (r != 1)
+      return false;
+   return true;
+}
+
+static bool
+dri3_get_pci_id_from_fd(int fd, int *vendorp, int *chipp)
+{
+   dev_t        rdev = 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;
 }
 
 char *
 dri3_get_driver_for_fd(int fd)
 {
-   struct udev *udev;
-   struct udev_device *device, *parent;
-   const char *pci_id;
    char *driver = NULL;
    int vendor_id, chip_id, i, j;
 
-   udev = udev_new();
-   device = dri3_udev_device_new_from_fd(udev, fd);
-   if (device == NULL)
+   if (!dri3_get_pci_id_from_fd(fd, &vendor_id, &chip_id))
       return NULL;
 
-   parent = udev_device_get_parent(device);
-   if (parent == NULL) {
-      ErrorMessageF("DRI3: could not get parent device");
-      goto out;
-   }
-
-   pci_id = udev_device_get_property_value(parent, "PCI_ID");
-   if (pci_id == NULL ||
-       sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) != 2) {
-      ErrorMessageF("DRI3: malformed or no PCI ID");
-      goto out;
-   }
-
    for (i = 0; driver_map[i].driver; i++) {
       if (vendor_id != driver_map[i].vendor_id)
          continue;
@@ -139,8 +157,5 @@ dri3_get_driver_for_fd(int fd)
    }
 
 out:
-   udev_device_unref(device);
-   udev_unref(udev);
-
    return driver;
 }
-- 
1.8.4.4



More information about the mesa-dev mailing list