diff options
author | Simon Ser <contact@emersion.fr> | 2019-06-11 21:45:41 +0300 |
---|---|---|
committer | Scott Anderson <ascent12@hotmail.com> | 2019-06-11 22:33:52 +0000 |
commit | 869e789a645b92a99e592a230fe39b0c59a2cd7d (patch) | |
tree | 7420b4cabaf7f26e77b42aab6534908bf587d98f | |
parent | 602a3c20357cca7f87ed71bf5d24e29aad9fa457 (diff) | |
download | external_drm_info-869e789a645b92a99e592a230fe39b0c59a2cd7d.tar.gz external_drm_info-869e789a645b92a99e592a230fe39b0c59a2cd7d.tar.bz2 external_drm_info-869e789a645b92a99e592a230fe39b0c59a2cd7d.zip |
Use drmGetDevices to list nodes
There's no guarantee that DRM primary nodes start at card0. I've run into a
system where the first card is card1 (probably because the driver has been
unloaded/reloaded?). Because of this drm_info wasn't dumping any data.
Instead, we can use drmGetDevices which returns a list of DRM devices and nodes
available on the system.
-rw-r--r-- | json.c | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -628,18 +628,28 @@ struct json_object *drm_info(char *paths[]) /* Print everything by default */ if (!paths[0]) { - char path[PATH_MAX]; - for (int i = 0;; ++i) { - snprintf(path, sizeof path, DRM_DEV_NAME, DRM_DIR_NAME, i); - if (access(path, R_OK) < 0) - break; + drmDevice *devices[64]; + int n = drmGetDevices(devices, sizeof(devices) / sizeof(devices[0])); + if (n < 0) { + perror("drmGetDevices"); + json_object_put(obj); + return NULL; + } - struct json_object *dev = node_info(path); - if (!dev) + for (int i = 0; i < n; ++i) { + drmDevice *dev = devices[i]; + if (!(dev->available_nodes & (1 << DRM_NODE_PRIMARY))) continue; - json_object_object_add(obj, path, dev); + const char *path = dev->nodes[DRM_NODE_PRIMARY]; + struct json_object *dev_obj = node_info(path); + if (!dev_obj) + continue; + + json_object_object_add(obj, path, dev_obj); } + + drmFreeDevices(devices, n); } else { for (char **path = paths; *path; ++path) { struct json_object *dev = node_info(*path); |