summaryrefslogtreecommitdiffstats
path: root/src/loader/loader.c
diff options
context:
space:
mode:
authorChristian Gmeiner <[email protected]>2018-08-09 07:12:22 +0200
committerChristian Gmeiner <[email protected]>2018-08-31 21:46:03 +0200
commitab348885ebbc669f5dec032851147bd64a2d5e26 (patch)
treeb9486a4cfa0b85fc8c2994079c06f5694cfe9cf1 /src/loader/loader.c
parentd0b09e2dfe7e42a542d6430426c584d74a5bd66e (diff)
loader: add loader_open_render_node(..)
This helper is almost a 1:1 copy of tegra_open_render_node(). Signed-off-by: Christian Gmeiner <[email protected]> Reviewed-by: Emil Velikov <[email protected]>
Diffstat (limited to 'src/loader/loader.c')
-rw-r--r--src/loader/loader.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/loader/loader.c b/src/loader/loader.c
index 2e37d113b8d..461f96aa6a4 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -103,6 +103,65 @@ static char *loader_get_kernel_driver_name(int fd)
}
#if defined(HAVE_LIBDRM)
+int
+loader_open_render_node(const char *name)
+{
+ 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, name) != 0) {
+ drmFreeVersion(version);
+ close(fd);
+ continue;
+ }
+
+ drmFreeVersion(version);
+ render = fd;
+ break;
+ }
+ }
+
+ drmFreeDevices(devices, num);
+
+free:
+ free(devices);
+ return render;
+}
+
#ifdef USE_DRICONF
static const char __driConfigOptionsLoader[] =
DRI_CONF_BEGIN
@@ -306,6 +365,12 @@ int loader_get_user_preferred_fd(int default_fd, bool *different_device)
return default_fd;
}
#else
+int
+loader_open_render_node(const char *name)
+{
+ return -1;
+}
+
int loader_get_user_preferred_fd(int default_fd, bool *different_device)
{
*different_device = false;