loader: Move non-error message to debug level
[mesa.git] / src / loader / loader.c
index 001c46d2a1b4dc7a5cc08a4cc901cdf9847a3d7b..9b4752d31385e2cde2a7319c8f4259c650feefa1 100644 (file)
@@ -1,45 +1,7 @@
 /*
  * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
- *
- * This code is derived from the following files.
- *
- * * src/glx/dri3_common.c
- * Copyright © 2013 Keith Packard
- *
- * * src/egl/drivers/dri2/common.c
- * * src/gbm/backends/dri/driver_name.c
- * Copyright © 2011 Intel Corporation
- *
- * Authors:
- *    Kristian Høgsberg <krh@bitplanet.net>
- *    Benjamin Franzke <benjaminfranzke@googlemail.com>
- *
- * * src/gallium/targets/egl-static/egl.c
- * Copyright (C) 2010-2011 LunarG Inc.
- *
- * Authors:
- *    Chia-I Wu <olv@lunarg.com>
- *
- * * src/gallium/state_trackers/egl/drm/native_drm.c
- * Copyright (C) 2010 Chia-I Wu <olv@0xlab.org>
- *
- * * src/egl/drivers/dri2/platform_android.c
- *
- * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
- * Copyright (C) 2010-2011 LunarG Inc.
- *
- * Based on platform_x11, which has
- *
- * Copyright © 2011 Intel Corporation
- *
- * * src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
- * Copyright 2011 Intel Corporation
- * Copyright 2012 Francisco Jerez
- * All Rights Reserved.
- *
- * Authors:
- *    Kristian Høgsberg <krh@bitplanet.net>
- *    Benjamin Franzke <benjaminfranzke@googlemail.com>
+ * Copyright (C) 2014-2016 Emil Velikov <emil.l.velikov@gmail.com>
+ * Copyright (C) 2016 Intel Corporation
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -71,6 +33,8 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
 #ifdef MAJOR_IN_MKDEV
 #include <sys/mkdev.h>
 #endif
@@ -80,8 +44,6 @@
 #include "loader.h"
 
 #ifdef HAVE_LIBDRM
-#include <stdlib.h>
-#include <unistd.h>
 #include <xf86drm.h>
 #ifdef USE_DRICONF
 #include "xmlconfig.h"
@@ -282,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)
 {
@@ -320,7 +282,7 @@ drm_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
          ret = 1;
       }
       else {
-         log_(_LOADER_WARNING, "MESA-LOADER: device is not located on the PCI bus\n");
+         log_(_LOADER_DEBUG, "MESA-LOADER: device is not located on the PCI bus\n");
          ret = 0;
       }
       drmFreeDevice(&device);
@@ -346,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)
@@ -411,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;
@@ -423,13 +340,21 @@ loader_get_device_name_for_fd(int fd)
 }
 
 char *
-loader_get_driver_for_fd(int fd, unsigned driver_types)
+loader_get_driver_for_fd(int fd)
 {
    int vendor_id, chip_id, i, j;
    char *driver = NULL;
 
-   if (!driver_types)
-      driver_types = _LOADER_GALLIUM | _LOADER_DRI;
+   /* Allow an environment variable to force choosing a different driver
+    * binary.  If that driver binary can't survive on this FD, that's the
+    * user's problem, but this allows vc4 simulator to run on an i965 host,
+    * and may be useful for some touch testing of i915 on an i965 host.
+    */
+   if (geteuid() == getuid()) {
+      driver = getenv("MESA_LOADER_DRIVER_OVERRIDE");
+      if (driver)
+         return strdup(driver);
+   }
 
    if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id)) {
 
@@ -455,9 +380,6 @@ loader_get_driver_for_fd(int fd, unsigned driver_types)
       if (vendor_id != driver_map[i].vendor_id)
          continue;
 
-      if (!(driver_types & driver_map[i].driver_types))
-         continue;
-
       if (driver_map[i].predicate && !driver_map[i].predicate(fd))
          continue;
 
@@ -485,3 +407,28 @@ loader_set_logger(void (*logger)(int level, const char *fmt, ...))
 {
    log_ = logger;
 }
+
+/* XXX: Local definition to avoid pulling the heavyweight GL/gl.h and
+ * GL/internal/dri_interface.h
+ */
+
+#ifndef __DRI_DRIVER_GET_EXTENSIONS
+#define __DRI_DRIVER_GET_EXTENSIONS "__driDriverGetExtensions"
+#endif
+
+char *
+loader_get_extensions_name(const char *driver_name)
+{
+   char *name = NULL;
+
+   if (asprintf(&name, "%s_%s", __DRI_DRIVER_GET_EXTENSIONS, driver_name) < 0)
+      return NULL;
+
+   const size_t len = strlen(name);
+   for (size_t i = 0; i < len; i++) {
+          if (name[i] == '-')
+                  name[i] = '_';
+   }
+
+   return name;
+}