Currently most places assume reliable primary <> render node mapping. Although this may work in some cases, it is not correct. Add a couple of helpers that hide the details and safes all the guesswork for the user. Cc: Daniel Vetter <daniel.vetter@xxxxxxxx> Cc: David Herrmann <dh.herrmann@xxxxxxxxxxxxxx> Signed-off-by: Emil Velikov <emil.l.velikov@xxxxxxxxx> --- xf86drm.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ xf86drm.h | 3 +++ 2 files changed, 57 insertions(+) diff --git a/xf86drm.c b/xf86drm.c index 345325a..6af7ac0 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -2607,3 +2607,57 @@ int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle) return 0; } +char *drmGetDeviceNameFromRenderFD(int fd) +{ + + struct stat sbuf; + char name[64], buf[64]; + int maj, min, i; + + if (!fstat(fd, &sbuf)) + return NULL; + + if (!S_ISCHR(sbuf.st_mode)) + return NULL; + + maj = major(sbuf.st_rdev); + min = minor(sbuf.st_rdev); + + snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/device/drm", maj, min); + + for (i = 0; i < DRM_MAX_MINOR; i++) { + snprintf(name, sizeof(name), DRM_DEV_NAME, buf, i); + if (stat(name, &sbuf) == 0) { + snprintf(name, sizeof(name), DRM_DEV_NAME, DRM_DIR_NAME, i); + return strdup(name); + } + } + return NULL; +} + +char *drmGetRenderNameFromDeviceFD(int fd) +{ + struct stat sbuf; + char name[64], buf[64]; + int maj, min, i; + + if (!fstat(fd, &sbuf)) + return NULL; + + if (!S_ISCHR(sbuf.st_mode)) + return NULL; + + maj = major(sbuf.st_rdev); + min = minor(sbuf.st_rdev); + + snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/device/drm", maj, min); + + for (i = 128; i < (128 + DRM_MAX_MINOR); i++) { + snprintf(name, sizeof(name), DRM_DEV_NAME, buf, i); + if (stat(name, &sbuf) == 0) { + snprintf(name, sizeof(name), DRM_RENDER_DEV_NAME, DRM_DIR_NAME, i); + return strdup(name); + } + } + return NULL; +} diff --git a/xf86drm.h b/xf86drm.h index bfd0670..bca5887 100644 --- a/xf86drm.h +++ b/xf86drm.h @@ -740,6 +740,9 @@ 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); +extern char *drmGetRenderNameFromDeviceFD(int fd); +extern char *drmGetDeviceNameFromRenderFD(int fd); + #if defined(__cplusplus) || defined(c_plusplus) } #endif -- 2.2.2 _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/dri-devel