aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Anderson <ascent12@hotmail.com>2017-10-02 21:57:14 +1300
committerScott Anderson <ascent12@hotmail.com>2017-10-02 21:57:14 +1300
commit6cfe47d1d891d31ef3e13deebbf899af27cadb82 (patch)
treefaeeb38ded5144714eec9a71d937196fcb5be560
parentf193623ca11c245e9209a8df40115dbe420bbc22 (diff)
Add explicitly picking GPUs with environment var
-rw-r--r--backend/session/session.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/backend/session/session.c b/backend/session/session.c
index be79c34d..72eb6149 100644
--- a/backend/session/session.c
+++ b/backend/session/session.c
@@ -1,7 +1,8 @@
+#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <stddef.h>
-#include <stdarg.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <libudev.h>
@@ -224,11 +225,44 @@ out_fd:
return -1;
}
+static size_t explicit_find_gpus(struct wlr_session *session,
+ size_t ret_len, int ret[static ret_len], const char *str) {
+ char *gpus = strdup(str);
+ if (!gpus) {
+ wlr_log_errno(L_ERROR, "Allocation failed");
+ return 0;
+ }
+
+ size_t i = 0;
+ char *save;
+ char *ptr = strtok_r(gpus, ":", &save);
+ do {
+ if (i >= ret_len) {
+ break;
+ }
+
+ ret[i] = open_if_kms(session, ptr);
+ if (ret[i] <= 0) {
+ wlr_log(L_ERROR, "Unable to open %s as DRM device", ptr);
+ } else {
+ ++i;
+ }
+ } while ((ptr = strtok_r(NULL, ":", &save)));
+
+ free(ptr);
+ return i;
+}
+
/* Tries to find the primary GPU by checking for the "boot_vga" attribute.
* If it's not found, it returns the first valid GPU it finds.
*/
size_t wlr_session_find_gpus(struct wlr_session *session,
size_t ret_len, int ret[static ret_len]) {
+ const char *explicit = getenv("WLR_DRM_DEVICES");
+ if (explicit) {
+ return explicit_find_gpus(session, ret_len, ret, explicit);
+ }
+
struct udev_enumerate *en = udev_enumerate_new(session->udev);
if (!en) {
wlr_log(L_ERROR, "Failed to create udev enumeration");