drm: Branch 'master' - 3 commits

[email protected] (Emil Velikov)
Newsgroups gmane.comp.video.dri.patches
Message-ID <[email protected]>
 xf86drm.c |   64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 56 insertions(+), 8 deletions(-)

New commits:
commit eebefaf72c55fd2116f4c983ec6724a4d66ab413
Author: Jonathan Gray <[email protected]>
Date:   Sat Dec 17 16:09:53 2016 +1100

    xf86drm: don't fatal on per device error in drmGetDevice[s]2
    
    When iterating over all the device nodes if drmProcessPciDevice()
    returned an error for any node the function would return an error,
    ignoring any valid nodes.
    
    The result of this on OpenBSD where drmProcessPciDevice() results in
    device nodes being opened to issue ioctls to get pci data
    was that data obtained from /dev/drm0 would be ignored if /dev/drm1
    could not be opened.
    
    Reviewed-by: Emil Velikov <[email protected]>
    Signed-off-by: Jonathan Gray <[email protected]>

diff --git a/xf86drm.c b/xf86drm.c
index f684c01..7d7df18 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3383,7 +3383,7 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
         case DRM_BUS_PCI:
             ret = drmProcessPciDevice(&d, node, node_type, maj, min, true, flags);
             if (ret)
-                goto free_devices;
+                continue;
 
             break;
         default:
@@ -3514,7 +3514,7 @@ int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices)
             ret = drmProcessPciDevice(&device, node, node_type,
                                       maj, min, devices != NULL, flags);
             if (ret)
-                goto free_devices;
+                continue;
 
             break;
         default:
commit e2e766d5acdbb826f1cfe5643669db54ee86f456
Author: Jonathan Gray <[email protected]>
Date:   Sat Dec 17 16:09:52 2016 +1100

    xf86drm: add a non-sysfs version of drmGetDeviceNameFromFd2
    
    Implement a generic drmGetDeviceNameFromFd2() to use on non-linux
    systems without sysfs.
    
    v2: remove min < base test as requested by Emil
    
    Reviewed-by: Emil Velikov <[email protected]>
    Signed-off-by: Jonathan Gray <[email protected]>

diff --git a/xf86drm.c b/xf86drm.c
index f6850aa..f684c01 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3627,7 +3627,47 @@ char *drmGetDeviceNameFromFd2(int fd)
     fclose(f);
     return device_name;
 #else
-#warning "Missing implementation of drmGetDeviceNameFromFd2"
-    return NULL;
+    struct stat      sbuf;
+    char             node[PATH_MAX + 1];
+    const char      *dev_name;
+    int              node_type;
+    int              maj, min, n, base;
+
+    if (fstat(fd, &sbuf))
+        return NULL;
+
+    maj = major(sbuf.st_rdev);
+    min = minor(sbuf.st_rdev);
+
+    if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
+        return NULL;
+
+    node_type = drmGetMinorType(min);
+    if (node_type == -1)
+        return NULL;
+
+    switch (node_type) {
+    case DRM_NODE_PRIMARY:
+        dev_name = DRM_DEV_NAME;
+        break;
+    case DRM_NODE_CONTROL:
+        dev_name = DRM_CONTROL_DEV_NAME;
+        break;
+    case DRM_NODE_RENDER:
+        dev_name = DRM_RENDER_DEV_NAME;
+        break;
+    default:
+        return NULL;
+    };
+
+    base = drmGetMinorBase(node_type);
+    if (base < 0)
+        return NULL;
+
+    n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min - base);
+    if (n == -1 || n >= PATH_MAX)
+      return NULL;
+
+    return strdup(node);
 #endif
 }
commit d5cf3f98314c1b9d87216e00c30c9fef06ff24c3
Author: Jonathan Gray <[email protected]>
Date:   Sat Dec 17 16:09:51 2016 +1100

    xf86drm: adjust device node path for minor base
    
    When constructing a path to a device node the minor number retrieved
    from fstat needs to have the offset of the node type subtracted from it.
    Control and render node types have the same major as the primary node
    but each has their own block of minor types at fixed offsets.
    
    v2: remove min < base test as requested by Emil
    
    Reviewed-by: Emil Velikov <[email protected]>
    Signed-off-by: Jonathan Gray <[email protected]>

diff --git a/xf86drm.c b/xf86drm.c
index b5eeeb0..f6850aa 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2838,7 +2838,7 @@ out_close_dir:
     char buf[PATH_MAX + 1];
     const char *dev_name;
     unsigned int maj, min;
-    int n;
+    int n, base;
 
     if (fstat(fd, &sbuf))
         return NULL;
@@ -2863,7 +2863,11 @@ out_close_dir:
         return NULL;
     };
 
-    n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min);
+    base = drmGetMinorBase(type);
+    if (base < 0)
+        return NULL;
+
+    n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min - base);
     if (n == -1 || n >= sizeof(buf))
         return NULL;
 
@@ -3262,7 +3266,7 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
     char             node[PATH_MAX + 1];
     const char      *dev_name;
     int              node_type, subsystem_type;
-    int              maj, min, n, ret;
+    int              maj, min, n, ret, base;
 
     if (fd == -1 || device == NULL)
         return -EINVAL;
@@ -3294,7 +3298,11 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
         return -EINVAL;
     };
 
-    n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min);
+    base = drmGetMinorBase(node_type);
+    if (base < 0)
+        return -EINVAL;
+
+    n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min - base);
     if (n == -1 || n >= PATH_MAX)
       return -errno;
     if (stat(node, &sbuf))

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
--
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.