summaryrefslogtreecommitdiff
path: root/xf86drm.c
diff options
context:
space:
mode:
authorThomas Hellstrom <thellstrom@vmware.com>2018-08-31 13:47:05 +0200
committerThomas Hellstrom <thellstrom@vmware.com>2018-10-09 14:47:09 +0200
commitf8392583418aef5e27bfed9989aeb601e20cc96d (patch)
tree8a6f5780aaec11efaca803d5d03fe1fae77b9b9e /xf86drm.c
parent4f1c76539692253247fd2022111873601e50b1d9 (diff)
downloadlibdrm-f8392583418aef5e27bfed9989aeb601e20cc96d.tar.gz
libdrm-f8392583418aef5e27bfed9989aeb601e20cc96d.tar.bz2
libdrm-f8392583418aef5e27bfed9989aeb601e20cc96d.zip
libdrm: Allow dynamic drm majors on linux
To determine whether a device node is a drm device node or not, the code currently compares the node's major number to the static drm major device number. This breaks the standalone vmwgfx driver on XWayland dri clients, https://cgit.freedesktop.org/mesa/vmwgfx and any future attempt to introduce dynamic device numbers for drm. So instead of checking for the device major, instead check for the presence of the /sys/dev/char/<major>:<minor>/device/drm directory. Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Eric Engestrom <eric.engestrom@intel.com> Acked-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'xf86drm.c')
-rw-r--r--xf86drm.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/xf86drm.c b/xf86drm.c
index 49150d74..10df682b 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2767,6 +2767,20 @@ drm_public char *drmGetDeviceNameFromFd(int fd)
return strdup(name);
}
+static bool drmNodeIsDRM(int maj, int min)
+{
+#ifdef __linux__
+ char path[64];
+ struct stat sbuf;
+
+ snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device/drm",
+ maj, min);
+ return stat(path, &sbuf) == 0;
+#else
+ return maj == DRM_MAJOR;
+#endif
+}
+
drm_public int drmGetNodeTypeFromFd(int fd)
{
struct stat sbuf;
@@ -2778,7 +2792,7 @@ drm_public int drmGetNodeTypeFromFd(int fd)
maj = major(sbuf.st_rdev);
min = minor(sbuf.st_rdev);
- if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) {
+ if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) {
errno = EINVAL;
return -1;
}
@@ -2844,7 +2858,7 @@ static char *drmGetMinorNameForFD(int fd, int type)
maj = major(sbuf.st_rdev);
min = minor(sbuf.st_rdev);
- if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
+ if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
return NULL;
snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/device/drm", maj, min);
@@ -2878,7 +2892,7 @@ static char *drmGetMinorNameForFD(int fd, int type)
maj = major(sbuf.st_rdev);
min = minor(sbuf.st_rdev);
- if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
+ if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
return NULL;
switch (type) {
@@ -3729,7 +3743,7 @@ process_device(drmDevicePtr *device, const char *d_name,
maj = major(sbuf.st_rdev);
min = minor(sbuf.st_rdev);
- if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
+ if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
return -1;
subsystem_type = drmParseSubsystemType(maj, min);
@@ -3843,7 +3857,7 @@ drm_public int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
maj = major(sbuf.st_rdev);
min = minor(sbuf.st_rdev);
- if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
+ if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
return -EINVAL;
node_type = drmGetMinorType(min);
@@ -3909,7 +3923,7 @@ drm_public int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
maj = major(sbuf.st_rdev);
min = minor(sbuf.st_rdev);
- if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
+ if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
return -EINVAL;
subsystem_type = drmParseSubsystemType(maj, min);
@@ -4070,7 +4084,7 @@ drm_public char *drmGetDeviceNameFromFd2(int fd)
maj = major(sbuf.st_rdev);
min = minor(sbuf.st_rdev);
- if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
+ if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
return NULL;
snprintf(path, sizeof(path), "/sys/dev/char/%d:%d", maj, min);
@@ -4096,7 +4110,7 @@ drm_public char *drmGetDeviceNameFromFd2(int fd)
maj = major(sbuf.st_rdev);
min = minor(sbuf.st_rdev);
- if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
+ if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
return NULL;
node_type = drmGetMinorType(min);