[PATCH 2/2] libdrm: add drmGetNodeType() helper
Emil Velikov
emil.l.velikov at gmail.com
Sun Feb 1 16:14:55 PST 2015
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 at ffwll.ch>
Cc: David Herrmann <dh.herrmann at googlemail.com>
Signed-off-by: Emil Velikov <emil.l.velikov at 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;
+ }
+ }
+
+ 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);
--
2.2.2
More information about the dri-devel
mailing list