From: Frank Binns <frank.binns@imgtec.com>
To: dri-devel@lists.freedesktop.org, emil.l.velikov@gmail.com
Cc: rufus.hamade@imgtec.com
Subject: [PATCH libdrm] Add new drmGetNodeTypeFromFd function
Date: Fri, 13 Feb 2015 10:51:15 +0000 [thread overview]
Message-ID: <1423824675-12460-1-git-send-email-frank.binns@imgtec.com> (raw)
Add a helper function that returns the type of device node from an fd.
Signed-off-by: Frank Binns <frank.binns@imgtec.com>
---
xf86drm.c | 39 +++++++++++++++++++++++++++++++++++++++
xf86drm.h | 1 +
2 files changed, 40 insertions(+)
diff --git a/xf86drm.c b/xf86drm.c
index d85115c..e117bc6 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -505,6 +505,23 @@ static int drmGetMinorBase(int type)
};
}
+static int drmGetMinorType(int minor)
+{
+ int type = minor >> 6;
+
+ if (minor < 0)
+ return -1;
+
+ switch (type) {
+ case DRM_NODE_PRIMARY:
+ case DRM_NODE_CONTROL:
+ case DRM_NODE_RENDER:
+ return type;
+ default:
+ return -1;
+ }
+}
+
/**
* Open the device by bus ID.
*
@@ -2667,6 +2684,28 @@ char *drmGetDeviceNameFromFd(int fd)
return strdup(name);
}
+int drmGetNodeTypeFromFd(int fd)
+{
+ struct stat sbuf;
+ int maj, min, type;
+
+ if (fstat(fd, &sbuf))
+ return -1;
+
+ maj = major(sbuf.st_rdev);
+ min = minor(sbuf.st_rdev);
+
+ if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ type = drmGetMinorType(min);
+ if (type == -1)
+ errno = ENODEV;
+ return type;
+}
+
int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd)
{
struct drm_prime_handle args;
diff --git a/xf86drm.h b/xf86drm.h
index 77937eb..afd38a1 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -744,6 +744,7 @@ typedef struct _drmEventContext {
extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
extern char *drmGetDeviceNameFromFd(int fd);
+extern int drmGetNodeTypeFromFd(int fd);
extern int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd);
extern int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle);
--
1.8.5.4.gfdaaaa2
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next reply other threads:[~2015-02-13 10:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-13 10:51 Frank Binns [this message]
2015-02-13 16:38 ` [PATCH libdrm] Add new drmGetNodeTypeFromFd function Emil Velikov
2015-02-17 16:10 ` Frank Binns
2015-02-23 9:37 ` 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=1423824675-12460-1-git-send-email-frank.binns@imgtec.com \
--to=frank.binns@imgtec.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=emil.l.velikov@gmail.com \
--cc=rufus.hamade@imgtec.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