tegra: make use loader_open_render_node(..) helper
authorChristian Gmeiner <christian.gmeiner@gmail.com>
Thu, 2 Aug 2018 18:04:45 +0000 (20:04 +0200)
committerChristian Gmeiner <christian.gmeiner@gmail.com>
Fri, 31 Aug 2018 19:46:32 +0000 (21:46 +0200)
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/gallium/drivers/tegra/tegra_screen.c

index 73fdc632933f27ebb76d0fa9e0750d83bcb10c7f..243bdde8d2c5729f7a1038ffa7ef1c9ee3c49618 100644 (file)
@@ -32,6 +32,7 @@
 #include <tegra_drm.h>
 #include <xf86drm.h>
 
+#include "loader/loader.h"
 #include "pipe/p_state.h"
 #include "util/u_debug.h"
 #include "util/u_inlines.h"
@@ -163,64 +164,6 @@ tegra_screen_can_create_resource(struct pipe_screen *pscreen,
    return screen->gpu->can_create_resource(screen->gpu, template);
 }
 
-static int tegra_open_render_node(void)
-{
-   drmDevicePtr *devices, device;
-   int err, render = -ENOENT, fd;
-   unsigned int num, i;
-
-   err = drmGetDevices2(0, NULL, 0);
-   if (err < 0)
-      return err;
-
-   num = err;
-
-   devices = calloc(num, sizeof(*devices));
-   if (!devices)
-      return -ENOMEM;
-
-   err = drmGetDevices2(0, devices, num);
-   if (err < 0) {
-      render = err;
-      goto free;
-   }
-
-   for (i = 0; i < num; i++) {
-      device = devices[i];
-
-      if ((device->available_nodes & (1 << DRM_NODE_RENDER)) &&
-          (device->bustype == DRM_BUS_PLATFORM)) {
-         drmVersionPtr version;
-
-         fd = open(device->nodes[DRM_NODE_RENDER], O_RDWR | O_CLOEXEC);
-         if (fd < 0)
-            continue;
-
-         version = drmGetVersion(fd);
-         if (!version) {
-            close(fd);
-            continue;
-         }
-
-         if (strcmp(version->name, "nouveau") != 0) {
-            drmFreeVersion(version);
-            close(fd);
-            continue;
-         }
-
-         drmFreeVersion(version);
-         render = fd;
-         break;
-      }
-   }
-
-   drmFreeDevices(devices, num);
-
-free:
-   free(devices);
-   return render;
-}
-
 static int tegra_screen_import_resource(struct tegra_screen *screen,
                                         struct tegra_resource *resource)
 {
@@ -594,7 +537,7 @@ tegra_screen_create(int fd)
 
    screen->fd = fd;
 
-   screen->gpu_fd = tegra_open_render_node();
+   screen->gpu_fd = loader_open_render_node("nouveau");
    if (screen->gpu_fd < 0) {
       if (errno != ENOENT)
          fprintf(stderr, "failed to open GPU device: %s\n", strerror(errno));