[Mesa-dev] [PATCH 2/4] loader: add loader_open_render_node(..)
Christian Gmeiner
christian.gmeiner at gmail.com
Thu Aug 9 05:12:22 UTC 2018
This helper is almost a 1:1 copy of tegra_open_render_node().
Signed-off-by: Christian Gmeiner <christian.gmeiner at gmail.com>
---
src/loader/loader.c | 65 +++++++++++++++++++++++++++++++++++++++++++++
src/loader/loader.h | 3 +++
2 files changed, 68 insertions(+)
diff --git a/src/loader/loader.c b/src/loader/loader.c
index 43275484cc..60b5d71083 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -83,6 +83,65 @@ loader_open_device(const char *device_name)
}
#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
@@ -262,6 +321,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;
diff --git a/src/loader/loader.h b/src/loader/loader.h
index 3859b45dc4..7b4dd01144 100644
--- a/src/loader/loader.h
+++ b/src/loader/loader.h
@@ -38,6 +38,9 @@ extern "C" {
int
loader_open_device(const char *);
+int
+loader_open_render_node(const char *name);
+
int
loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id);
--
2.17.1
More information about the mesa-dev
mailing list