From: Frank Binns <frank.binns@imgtec.com>
To: Emil Velikov <emil.l.velikov@gmail.com>, dri-devel@lists.freedesktop.org
Cc: David Herrmann <dh.herrmann@googlemail.com>,
Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: Re: [PATCH 2/2] libdrm: add drmGetNodeType() helper
Date: Fri, 13 Feb 2015 10:50:41 +0000 [thread overview]
Message-ID: <54DDD701.90906@imgtec.com> (raw)
In-Reply-To: <1422836095-8547-3-git-send-email-emil.l.velikov@gmail.com>
Hi Emil,
On 02/02/15 00:14, Emil Velikov wrote:
> The add a simple helper which returns the node type of the opened fd.
> Likely to be used in conjunction with the previous two helpers.
>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: David Herrmann <dh.herrmann@googlemail.com>
> Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
> ---
> xf86drm.c | 43 +++++++++++++++++++++++++++++++++++++++----
> xf86drm.h | 7 +++++++
> 2 files changed, 46 insertions(+), 4 deletions(-)
>
> diff --git a/xf86drm.c b/xf86drm.c
> index 6af7ac0..a70c0dd 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -85,10 +85,6 @@
>
> #define DRM_MSG_VERBOSITY 3
>
> -#define DRM_NODE_CONTROL 0
> -#define DRM_NODE_PRIMARY 1
> -#define DRM_NODE_RENDER 2
> -
> static drmServerInfoPtr drm_server_info;
>
> void drmSetServerInfo(drmServerInfoPtr info)
> @@ -2607,6 +2603,45 @@ int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle)
> return 0;
> }
>
> +int drmGetNodeType(int fd, drmNodeType *type)
> +{
> + struct stat sbuf;
> + char name[64];
> + dev_t d;
> + int i;
> +
> + if (!fstat(fd, &sbuf))
> + return -errno;
> +
> + d = sbuf.st_rdev;
> +
> + for (i = 0; i < DRM_MAX_MINOR; i++) {
> + snprintf(name, sizeof(name), DRM_DEV_NAME, DRM_DIR_NAME, i);
> + if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d) {
> + *type = DRM_NODE_PRIMARY;
> + return 0;
> + }
> + }
> +
> + for (i = 64; i < (64 + DRM_MAX_MINOR); i++) {
> + snprintf(name, sizeof(name), DRM_CONTROL_DEV_NAME, DRM_DIR_NAME, i);
> + if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d) {
> + *type = DRM_NODE_CONTROL;
> + return 0;
> + }
> + }
> +
> + for (i = 128; i < (128 + DRM_MAX_MINOR); i++) {
> + snprintf(name, sizeof(name), DRM_RENDER_DEV_NAME, DRM_DIR_NAME, i);
> + if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d) {
> + *type = DRM_NODE_RENDER;
> + return 0;
> + }
> + }
It would seem easier (and faster) to use minor(sbuf.st_rdev) to
determine the type of node.
I'm not sure what the etiquette is here but I've prepared a patch that
does it this way instead, which will follow this email. Please feel free
to add your own signed-off-by, suggested-by, etc as I don't want to
steal all your credit :)
Thanks
Frank
> +
> + return -EINVAL;
> +}
> +
> char *drmGetDeviceNameFromRenderFD(int fd)
> {
>
> diff --git a/xf86drm.h b/xf86drm.h
> index bca5887..7d67df9 100644
> --- a/xf86drm.h
> +++ b/xf86drm.h
> @@ -740,6 +740,13 @@ extern char *drmGetDeviceNameFromFd(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);
>
> +typedef enum _drmNodeType {
> + DRM_NODE_CONTROL = 0,
> + DRM_NODE_PRIMARY = 1,
> + DRM_NODE_RENDER = 2
> +} drmNodeType, *drmNodeTypePtr;
> +
> +extern int drmGetNodeType(int fd, drmNodeType *type);
> extern char *drmGetRenderNameFromDeviceFD(int fd);
> extern char *drmGetDeviceNameFromRenderFD(int fd);
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2015-02-13 10:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-02 0:14 [RFC PATCH 0/2] libdrm: Add master <> render node helpers Emil Velikov
2015-02-02 0:14 ` [PATCH 1/2] drm: add drmGet{Device, Render}NameFrom{Render, Device}Fd helpers Emil Velikov
2015-02-13 11:07 ` Frank Binns
2015-02-23 12:22 ` [PATCH libdrm v2] drm: add drmGet(Master|Render)NameFrom(Render|Master)FD functions Emil Velikov
2015-02-23 14:35 ` Frank Binns
2015-02-23 15:03 ` Emil Velikov
2015-03-07 0:58 ` [PATCH libdrm v3] " Emil Velikov
2015-03-07 1:08 ` Emil Velikov
2015-02-02 0:14 ` [PATCH 2/2] libdrm: add drmGetNodeType() helper Emil Velikov
2015-02-13 10:50 ` Frank Binns [this message]
2015-02-10 22:37 ` [RFC PATCH 0/2] libdrm: Add master <> render node helpers Emil Velikov
2015-02-10 23:32 ` Jonathan Gray
2015-02-12 18:21 ` David Herrmann
2015-02-13 9:18 ` Emil Velikov
2015-02-13 11:18 ` Frank Binns
2015-02-13 18:19 ` 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=54DDD701.90906@imgtec.com \
--to=frank.binns@imgtec.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dh.herrmann@googlemail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.