drmGetDevice will always return the first device it find under /dev/dri/. This is not true for multi GPU situation. Change-Id: I2a85a8a4feba8a5cc517ad75c6afb532fa07c53d Signed-off-by: Qiang Yu <Qiang.Yu@xxxxxxx> --- xf86drm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 6689f7c..19001db 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -3087,6 +3087,7 @@ int drmGetDevice(int fd, drmDevicePtr *device) int maj, min; int ret, i, node_count; int max_count = 16; + dev_t find_rdev; if (fd == -1 || device == NULL) return -EINVAL; @@ -3094,6 +3095,7 @@ int drmGetDevice(int fd, drmDevicePtr *device) if (fstat(fd, &sbuf)) return -errno; + find_rdev = sbuf.st_rdev; maj = major(sbuf.st_rdev); min = minor(sbuf.st_rdev); @@ -3154,17 +3156,24 @@ int drmGetDevice(int fd, drmDevicePtr *device) local_devices = temp; } - local_devices[i] = d; + /* store target at local_devices[0] for ease to use below */ + if (find_rdev == sbuf.st_rdev && i) { + local_devices[i] = local_devices[0]; + local_devices[0] = d; + } + else + local_devices[i] = d; i++; } node_count = i; - /* Fold nodes into a single device if they share the same bus info */ + /* Fold nodes into a single device if they share the same bus info + * and nodes with same bus info will be merged into the first node + * position in local_devices */ drmFoldDuplicatedDevices(local_devices, node_count); *device = local_devices[0]; - for (i = 1; i < node_count && local_devices[i]; i++) - drmFreeDevice(&local_devices[i]); + drmFreeDevices(&local_devices[1], node_count - 1); closedir(sysdir); free(local_devices); -- 1.9.1 _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel