[Mesa-dev] [PATCH 12/16] loader: remove final sysfs codepath in loader_get_device_name_for_fd()

Emil Velikov emil.l.velikov at gmail.com
Tue Oct 11 18:31:56 UTC 2016


From: Emil Velikov <emil.velikov at collabora.com>

Effectively everyone with actual hardware and/or requesting the
"device_name" requires a working libdrm. Thus they could/should already
be using the (now only) codepath.

Apart from the code simplification, we can slim down our configure.ac
even further. But that will be done in separate patch(es).

Cc: Gary Wong <gtw at gnu.org>
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
Gary, I believe that nuking sysfs is perfectly reasonable but if there
are any technical reasons/obstacles why it must stay please shout.

Furthermore, if you and/or a fellow Gnu developers/users can prep some
patches for mesa [1], libdrm [2] and/or other graphics stack packages
that will be amazing.

>From a quick look all the changes are ok for upstreaming.

[1]
http://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/gl.scm#n251
[2]
http://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/patches/libdrm-symbol-check.patch
---
 configure.ac        | 20 ++++----------------
 src/loader/loader.c | 47 +----------------------------------------------
 2 files changed, 5 insertions(+), 62 deletions(-)

diff --git a/configure.ac b/configure.ac
index 017b872..10cf7ca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1356,13 +1356,6 @@ linux*)
     need_pci_id=no ;;
 esac
 
-AC_ARG_ENABLE([sysfs],
-    [AS_HELP_STRING([--enable-sysfs],
-        [enable /sys PCI identification @<:@default=disabled@:>@])],
-    [have_sysfs="$enableval"],
-    [have_sysfs=no]
-)
-
 if test "x$enable_dri" = xyes; then
     if test "$enable_static" = yes; then
         AC_MSG_ERROR([Cannot use static libraries for DRI drivers])
@@ -1452,11 +1445,6 @@ xdri)
 esac
 
 have_pci_id=no
-if test "$have_sysfs" = yes; then
-    DEFINES="$DEFINES -DHAVE_SYSFS"
-    have_pci_id=yes
-fi
-
 if test "$have_libdrm" = yes; then
     have_pci_id=yes
 fi
@@ -1570,7 +1558,7 @@ if test "x$enable_dri" = xyes; then
         fi
 
         if test "x$have_pci_id" != xyes; then
-            AC_MSG_ERROR([sysfs or libdrm >= $LIBDRM_REQUIRED required for building DRI])
+            AC_MSG_ERROR([libdrm >= $LIBDRM_REQUIRED required for building DRI])
         fi
 
         case "$host_cpu" in
@@ -1788,7 +1776,7 @@ if test "x$enable_gbm" = xauto; then
 fi
 if test "x$enable_gbm" = xyes; then
     if test "x$need_pci_id$have_pci_id" = xyesno; then
-        AC_MSG_ERROR([gbm requires sysfs or libdrm >= $LIBDRM_REQUIRED])
+        AC_MSG_ERROR([gbm requires libdrm >= $LIBDRM_REQUIRED])
     fi
 
     if test "x$enable_dri" = xyes; then
@@ -2102,7 +2090,7 @@ for plat in $egl_platforms; do
 
         case "$plat$need_pci_id$have_pci_id" in
                 waylandyesno|drmyesno)
-                    AC_MSG_ERROR([cannot build $plat platform without sysfs or libdrm >= $LIBDRM_REQUIRED]) ;;
+                    AC_MSG_ERROR([cannot build $plat platform without libdrm >= $LIBDRM_REQUIRED]) ;;
         esac
 done
 
@@ -2340,7 +2328,7 @@ gallium_require_llvm() {
 
 gallium_require_drm_loader() {
     if test "x$need_pci_id$have_pci_id" = xyesno; then
-        AC_MSG_ERROR([Gallium drm loader requires sysfs or libdrm >= $LIBDRM_REQUIRED])
+        AC_MSG_ERROR([Gallium drm loader requires libdrm >= $LIBDRM_REQUIRED])
     fi
 }
 
diff --git a/src/loader/loader.c b/src/loader/loader.c
index 9785f1b..a18c2ca 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -244,7 +244,7 @@ int loader_get_user_preferred_fd(int default_fd, int *different_device)
 }
 #endif
 
-#if defined(HAVE_SYSFS) || defined(HAVE_LIBDRM)
+#if defined(HAVE_LIBDRM)
 static int
 dev_node_from_fd(int fd, unsigned int *maj, unsigned int *min)
 {
@@ -308,47 +308,6 @@ loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
 }
 
 
-#if HAVE_SYSFS
-static char *
-sysfs_get_device_name_for_fd(int fd)
-{
-   char *device_name = NULL;
-   unsigned int maj, min;
-   FILE *f;
-   char buf[0x40];
-   static const char match[9] = "\nDEVNAME=";
-   int expected = 1;
-
-   if (dev_node_from_fd(fd, &maj, &min) < 0)
-      return NULL;
-
-   snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/uevent", maj, min);
-   if (!(f = fopen(buf, "r")))
-       return NULL;
-
-   while (expected < sizeof(match)) {
-      int c = getc(f);
-
-      if (c == EOF) {
-         fclose(f);
-         return NULL;
-      } else if (c == match[expected] )
-         expected++;
-      else
-         expected = 0;
-   }
-
-   strcpy(buf, "/dev/");
-   if (fgets(buf + 5, sizeof(buf) - 5, f)) {
-      buf[strcspn(buf, "\n")] = '\0';
-      device_name = strdup(buf);
-   }
-
-   fclose(f);
-   return device_name;
-}
-#endif
-
 #if defined(HAVE_LIBDRM)
 static char *
 drm_get_device_name_for_fd(int fd)
@@ -373,10 +332,6 @@ loader_get_device_name_for_fd(int fd)
 {
    char *result = NULL;
 
-#if HAVE_SYSFS
-   if ((result = sysfs_get_device_name_for_fd(fd)))
-      return result;
-#endif
 #if HAVE_LIBDRM
    if ((result = drm_get_device_name_for_fd(fd)))
       return result;
-- 
2.10.0



More information about the mesa-dev mailing list