Commit 03de2b70 authored by Chris Wilson's avatar Chris Wilson 🤔

lib/i915: Open primary sysfs for engine attributes

The engine attributes are only found on the primary sysfs node, not the
render nodes. If we are passed in a render node, we need to find the
corresponding primary node. We can do this by searching the character
devices for a primary minor index for the same exact device.
Signed-off-by: Chris Wilson's avatarChris Wilson <>
Acked-by: default avatarMika Kuoppala <>
parent 6e5c9915
......@@ -347,12 +347,63 @@ static int reopen(int dir, int mode)
return fd;
static int __open_primary(int dir)
int fd, major, minor;
char target[1024];
char device[1024];
char buf[1024];
int len;
fd = openat(dir, "dev", O_RDONLY);
if (fd < 0)
return dir;
len = read(fd, buf, sizeof(buf) - 1);
if (len <= 0)
return dir;
buf[len] = '\0';
sscanf(buf, "%d:%d", &major, &minor);
if (minor < 64)
return dir;
if (readlinkat(dir, "device", target, sizeof(target)) < 0)
return dir;
fd = openat(dir, "..", O_RDONLY);
if (fd < 0)
return dir;
for (minor = 0; minor < 64; minor++) {
sprintf(buf, "/sys/dev/char/%d:%d", major, minor);
dir = openat(fd, buf, O_RDONLY);
if (dir < 0)
if (readlinkat(dir, "device", device, sizeof(device)) > 0 &&
!strcmp(device, target))
dir = -1;
return dir;
static FILE *__open_attr(int dir, const char *mode, ...)
const char *path;
FILE *file;
va_list ap;
/* The attributes are not to be found on render nodes */
dir = __open_primary(dir);
va_start(ap, mode);
while (dir >= 0 && (path = va_arg(ap, const char *))) {
int fd;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment