dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Gray <jsg@jsg.id.au>
To: dri-devel@lists.freedesktop.org
Cc: emil.l.velikov@gmail.com
Subject: [PATCH libdrm 5/5] xf86drm: implement an OpenBSD specific drmGetDevice
Date: Sat, 26 Nov 2016 11:40:34 +1100	[thread overview]
Message-ID: <20161126004034.53376-5-jsg@jsg.id.au> (raw)
In-Reply-To: <20161126004034.53376-1-jsg@jsg.id.au>

This avoids walking all of /dev and directly maps the fd to a path to a
primary node.

Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
---
 xf86drm.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/xf86drm.c b/xf86drm.c
index 2a60b2e..a4b2506 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3175,6 +3175,46 @@ static void drmFoldDuplicatedDevices(drmDevicePtr local_devices[], int count)
  */
 int drmGetDevice(int fd, drmDevicePtr *device)
 {
+#ifdef __OpenBSD__
+    drmDevicePtr d;
+    struct stat sbuf;
+    char node[PATH_MAX + 1];
+    char d_name[PATH_MAX + 1];
+    int maj, min, n;
+    int ret;
+    int max_count = 1;
+
+    if (fd == -1 || device == NULL)
+        return -EINVAL;
+
+    if (fstat(fd, &sbuf))
+        return -errno;
+
+    maj = major(sbuf.st_rdev);
+    min = minor(sbuf.st_rdev);
+
+    if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
+        return -EINVAL;
+
+    n = snprintf(d_name, PATH_MAX, "drm%d", min);
+    if (n == -1 || n >= PATH_MAX)
+      return -errno;
+
+    n = snprintf(node, PATH_MAX, DRM_DEV_NAME, DRM_DIR_NAME, min);
+    if (n == -1 || n >= PATH_MAX)
+      return -errno;
+    if (stat(node, &sbuf))
+        return -EINVAL;
+
+    ret = drmProcessPciDevice(&d, d_name, node, DRM_NODE_PRIMARY,
+			      maj, min, true);
+    if (ret)
+        return ret;
+
+    *device = d;
+
+    return 0;
+#else
     drmDevicePtr *local_devices;
     drmDevicePtr d;
     DIR *sysdir;
@@ -3282,6 +3322,7 @@ free_devices:
 free_locals:
     free(local_devices);
     return ret;
+#endif
 }
 
 /**
-- 
2.10.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2016-11-26  0:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-26  0:40 [PATCH libdrm 1/5] xf86drm: implement drmGetMinorNameForFD for non-sysfs Jonathan Gray
2016-11-26  0:40 ` [PATCH libdrm 2/5] xf86drm: implement drmParseSubsystemType for OpenBSD Jonathan Gray
2016-11-29 19:46   ` Emil Velikov
2016-11-30  0:23     ` Jonathan Gray
2016-11-30 16:23       ` Emil Velikov
2016-11-26  0:40 ` [PATCH libdrm 3/5] xf86drm: implement drmParsePciDeviceInfo " Jonathan Gray
2016-11-29 19:55   ` Emil Velikov
2016-11-30  0:38     ` Jonathan Gray
2016-11-30 16:11       ` Emil Velikov
2016-11-26  0:40 ` [PATCH libdrm 4/5] xf86drm: implement drmParsePciBusInfo " Jonathan Gray
2016-11-26  0:40 ` Jonathan Gray [this message]
2016-11-29 20:03   ` [PATCH libdrm 5/5] xf86drm: implement an OpenBSD specific drmGetDevice Emil Velikov
2016-11-30  0:00     ` Jonathan Gray
2016-11-30 16:32       ` Emil Velikov
2016-11-29 19:22 ` [PATCH libdrm 1/5] xf86drm: implement drmGetMinorNameForFD for non-sysfs Emil Velikov
2016-11-30  0:15   ` Jonathan Gray
2016-11-30 16:16     ` Emil Velikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161126004034.53376-5-jsg@jsg.id.au \
    --to=jsg@jsg.id.au \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emil.l.velikov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox