diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2014-03-07 19:44:07 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2014-03-10 22:19:25 +0000 |
commit | d10a5abcbd7c751adc08e24d9f4bdc33596b6f12 (patch) | |
tree | 3dd2e615aa0be0ad2caa8d1bb83ba15327f12ace | |
parent | 28cab948f50b1d67468edbd9c8e10d3d696155f5 (diff) |
intel: Supply a fallback guess for the device path
If for some reason we have an fd, but no device path, use the likely
default path (derived from and validated against the major/minor of the
open device fd).
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r-- | src/intel_device.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/intel_device.c b/src/intel_device.c index 38b57e20..bd66ae69 100644 --- a/src/intel_device.c +++ b/src/intel_device.c @@ -190,6 +190,26 @@ static int __intel_open_device(const struct pci_device *pci, char **path) return fd; } +static char *find_master_node(int fd) +{ + struct stat st, master; + char buf[128]; + + if (fstat(fd, &st)) + return NULL; + + if (!S_ISCHR(st.st_mode)) + return NULL; + + sprintf(buf, "/dev/dri/card%d", (int)(st.st_rdev & 0x7f)); + if (stat(buf, &master) == 0 && + st.st_mode == master.st_mode && + (st.st_rdev & 0x7f) == master.st_rdev) + return strdup(buf); + + return NULL; +} + static char *find_render_node(int fd) { #if defined(USE_RENDERNODE) @@ -283,6 +303,12 @@ int intel_open_device(int entity_num, master_count = 0; } + if (local_path == NULL) { + local_path = find_master_node(fd); + if (local_path == NULL) + goto err_close; + } + if (!__intel_check_device(fd)) goto err_close; |