From: Andrey Grodzovsky <andrey.grodzovsky@amd.com> To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Alexander.Deucher@amd.com, ckoenig.leichtzumerken@gmail.com Subject: [PATCH 2/7] xf86drm: Add function to retrieve char device path Date: Tue, 1 Jun 2021 16:16:57 -0400 [thread overview] Message-ID: <20210601201702.23316-3-andrey.grodzovsky@amd.com> (raw) In-Reply-To: <20210601201702.23316-1-andrey.grodzovsky@amd.com> Used to access device controls Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com> --- xf86drm.c | 23 +++++++++++++++++++++++ xf86drm.h | 1 + 2 files changed, 24 insertions(+) diff --git a/xf86drm.c b/xf86drm.c index edfeb347..a5ecd323 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -4361,6 +4361,29 @@ drm_public char *drmGetDeviceNameFromFd2(int fd) #endif } +drm_public char *drmGetCharDeviceFromFd(int fd) +{ +#ifdef __linux__ + struct stat sbuf; + char path[PATH_MAX + 1]; + unsigned int maj, min; + + if (fstat(fd, &sbuf)) + return NULL; + + maj = major(sbuf.st_rdev); + min = minor(sbuf.st_rdev); + + if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) + return NULL; + + snprintf(path, sizeof(path), "/sys/dev/char/%d:%d", maj, min); + return strdup(path); +#else + return NULL; +#endif +} + drm_public int drmSyncobjCreate(int fd, uint32_t flags, uint32_t *handle) { struct drm_syncobj_create args; diff --git a/xf86drm.h b/xf86drm.h index 9fc06ab8..c172dbc1 100644 --- a/xf86drm.h +++ b/xf86drm.h @@ -812,6 +812,7 @@ extern char *drmGetDeviceNameFromFd(int fd); */ extern char *drmGetDeviceNameFromFd2(int fd); extern int drmGetNodeTypeFromFd(int fd); +extern char *drmGetCharDeviceFromFd(int fd); /* Convert between GEM handles and DMA-BUF file descriptors. * -- 2.25.1
WARNING: multiple messages have this Message-ID (diff)
From: Andrey Grodzovsky <andrey.grodzovsky@amd.com> To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Alexander.Deucher@amd.com, ckoenig.leichtzumerken@gmail.com, Andrey Grodzovsky <andrey.grodzovsky@amd.com> Subject: [PATCH 2/7] xf86drm: Add function to retrieve char device path Date: Tue, 1 Jun 2021 16:16:57 -0400 [thread overview] Message-ID: <20210601201702.23316-3-andrey.grodzovsky@amd.com> (raw) In-Reply-To: <20210601201702.23316-1-andrey.grodzovsky@amd.com> Used to access device controls Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com> --- xf86drm.c | 23 +++++++++++++++++++++++ xf86drm.h | 1 + 2 files changed, 24 insertions(+) diff --git a/xf86drm.c b/xf86drm.c index edfeb347..a5ecd323 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -4361,6 +4361,29 @@ drm_public char *drmGetDeviceNameFromFd2(int fd) #endif } +drm_public char *drmGetCharDeviceFromFd(int fd) +{ +#ifdef __linux__ + struct stat sbuf; + char path[PATH_MAX + 1]; + unsigned int maj, min; + + if (fstat(fd, &sbuf)) + return NULL; + + maj = major(sbuf.st_rdev); + min = minor(sbuf.st_rdev); + + if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) + return NULL; + + snprintf(path, sizeof(path), "/sys/dev/char/%d:%d", maj, min); + return strdup(path); +#else + return NULL; +#endif +} + drm_public int drmSyncobjCreate(int fd, uint32_t flags, uint32_t *handle) { struct drm_syncobj_create args; diff --git a/xf86drm.h b/xf86drm.h index 9fc06ab8..c172dbc1 100644 --- a/xf86drm.h +++ b/xf86drm.h @@ -812,6 +812,7 @@ extern char *drmGetDeviceNameFromFd(int fd); */ extern char *drmGetDeviceNameFromFd2(int fd); extern int drmGetNodeTypeFromFd(int fd); +extern char *drmGetCharDeviceFromFd(int fd); /* Convert between GEM handles and DMA-BUF file descriptors. * -- 2.25.1 _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next prev parent reply other threads:[~2021-06-01 20:17 UTC|newest] Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-01 20:16 [PATCH 0/7] libdrm tests for hot-unplug feature Andrey Grodzovsky 2021-06-01 20:16 ` Andrey Grodzovsky 2021-06-01 20:16 ` [PATCH 1/7] tests/amdgpu: Fix valgrind warning Andrey Grodzovsky 2021-06-01 20:16 ` Andrey Grodzovsky 2021-06-01 20:16 ` Andrey Grodzovsky [this message] 2021-06-01 20:16 ` [PATCH 2/7] xf86drm: Add function to retrieve char device path Andrey Grodzovsky 2021-06-02 9:16 ` Simon Ser 2021-06-02 9:16 ` Simon Ser 2021-06-02 14:25 ` Andrey Grodzovsky 2021-06-02 14:25 ` Andrey Grodzovsky 2021-06-01 20:16 ` [PATCH 3/7] test/amdgpu: Add helper functions for hot unplug Andrey Grodzovsky 2021-06-01 20:16 ` Andrey Grodzovsky 2021-06-01 20:16 ` [PATCH 4/7] test/amdgpu/hotunplug: Add test suite for GPU unplug Andrey Grodzovsky 2021-06-01 20:16 ` Andrey Grodzovsky 2021-06-01 20:17 ` [PATCH 5/7] test/amdgpu/hotunplug: Add basic test Andrey Grodzovsky 2021-06-01 20:17 ` Andrey Grodzovsky 2021-06-01 20:17 ` [PATCH 6/7] tests/amdgpu/hotunplug: Add unplug with cs test Andrey Grodzovsky 2021-06-01 20:17 ` Andrey Grodzovsky 2021-06-01 20:17 ` [PATCH 7/7] tests/amdgpu/hotunplug: Add hotunplug with exported bo test Andrey Grodzovsky 2021-06-01 20:17 ` Andrey Grodzovsky 2021-06-02 7:59 ` [PATCH 0/7] libdrm tests for hot-unplug feature Daniel Vetter 2021-06-02 7:59 ` Daniel Vetter 2021-06-02 14:20 ` Andrey Grodzovsky 2021-06-02 14:20 ` Andrey Grodzovsky 2021-06-03 14:22 ` Andrey Grodzovsky 2021-06-03 14:22 ` Andrey Grodzovsky 2021-06-03 21:11 ` Daniel Vetter 2021-06-03 21:11 ` Daniel Vetter 2021-06-03 21:20 ` Alex Deucher 2021-06-03 21:20 ` Alex Deucher 2021-06-03 21:20 ` Alex Deucher 2021-06-03 21:20 ` Alex Deucher 2021-06-03 22:02 ` [PATCH 0/7] libdrm tests for hot-unplug fe goature Grodzovsky, Andrey 2021-06-03 22:02 ` Grodzovsky, Andrey 2021-06-04 2:26 ` Alex Deucher 2021-06-04 2:26 ` Alex Deucher 2021-06-07 14:29 ` Andrey Grodzovsky 2021-06-07 14:29 ` Andrey Grodzovsky 2021-06-04 1:37 ` [PATCH 0/7] libdrm tests for hot-unplug feature Dave Airlie 2021-06-04 1:37 ` Dave Airlie 2021-06-04 2:53 ` Alex Deucher 2021-06-04 2:53 ` Alex Deucher 2021-06-04 3:31 ` Andrey Grodzovsky 2021-06-04 3:31 ` Andrey Grodzovsky
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=20210601201702.23316-3-andrey.grodzovsky@amd.com \ --to=andrey.grodzovsky@amd.com \ --cc=Alexander.Deucher@amd.com \ --cc=amd-gfx@lists.freedesktop.org \ --cc=ckoenig.leichtzumerken@gmail.com \ --cc=dri-devel@lists.freedesktop.org \ /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: linkBe 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.