Skip to contentSkip to conversation

Add new drmGetNodeTypeFromFd function

PATCH Applied Frank Binns 2 participants 4 messages Feb 13, 2015 – Feb 23, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add new drmGetNodeTypeFromFd function

Add a helper function that returns the type of device node from an fd.

---
 xf86drm.c | 39 +++++++++++++++++++++++++++++++++++++++
 xf86drm.h |  1 +
 2 files changed, 40 insertions(+)
xf86drm.c +39 -0
index d85115c..e117bc6 100644
@@ -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;
xf86drm.h +1 -0
index 77937eb..afd38a1 100644
@@ -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);
Signature · 6 lines
1.8.5.4.gfdaaaa2

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Hi Emil,

Quoted 11 lines · Emil Velikov

Hi Frank,

Quoted 3 lines · Frank Binns

Add a helper function that returns the type of device node from an fd.

Thank you for getting rid of the silly file probing that I went with initially.

-Emil

Would you mind pushing this as I don't have commit access.

Thanks
Frank
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

Applied
#3 lore raw
Quoted 8 lines · Frank Binns

Hi Emil,

Quoted 5 lines · Emil Velikov

Hi Frank,

Quoted 3 lines · Frank Binns

Add a helper function that returns the type of device node from an fd.

Quoted 9 lines
Quoted 6 lines

Thank you for getting rid of the silly file probing that I went with initially.

-Emil

Would you mind pushing this as I don't have commit access.

Hi Frank,

Wanted to give some extra time for people to take a look and comment. dri-devel has been quite busy lately :-)

Pushed to master, now let's respin the other helpers (using readdir_r).

Cheers,
Emil
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel