From 3ad7e030cedc49bf2540ffcd8b1db6c58a058c80 Mon Sep 17 00:00:00 2001 From: stefan11111 Date: Sun, 15 Mar 2026 12:12:55 +0200 Subject: [PATCH] modesetting: find the first compatible dri device as default This change replaces the default "/dev/dri/card0" by a loop which searches for the first compatible device. This change avoids the error below which happens on some ARM boards: (EE) No devices detected. (EE) Fatal server error: (EE) no screens found(EE) (EE) Signed-off-by: Patrick Lerda Part-of: ---------------------------------------------------------------------------- modesetting: Plug seatd suppport into the dynamic dri node detection Extended dynamic detection to 32 /dev nodes Signed-off-by: stefan11111 --- hw/xfree86/drivers/video/modesetting/driver.c | 55 ++++++++++++++----- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/hw/xfree86/drivers/video/modesetting/driver.c b/hw/xfree86/drivers/video/modesetting/driver.c index a10abc48dc..5332fab1ad 100644 --- a/hw/xfree86/drivers/video/modesetting/driver.c +++ b/hw/xfree86/drivers/video/modesetting/driver.c @@ -236,6 +236,27 @@ get_passed_fd(void) return -1; } +static int +ms_try_open(const char *dev) +{ + int fd = -1; + + if (!dev) { + return -1; + } + + fd = open(dev, O_RDWR | O_CLOEXEC, 0); + if (fd >= 0) { + return fd; + } + +#ifdef SEATD_LIBSEAT + return seatd_libseat_open_graphics(dev); +#else + return -1; +#endif +} + static int open_hw(const char *dev) { @@ -245,23 +266,27 @@ open_hw(const char *dev) return fd; if (dev){ - fd = open(dev, O_RDWR | O_CLOEXEC, 0); - #ifdef SEATD_LIBSEAT - /* try to open dev node via libseat */ - if (fd == -1) { - fd = seatd_libseat_open_graphics(dev); - } - #endif + fd = ms_try_open(dev); } else { dev = getenv("KMSDEVICE"); - if ((NULL == dev) || ((fd = open(dev, O_RDWR | O_CLOEXEC, 0)) == -1)) { - dev = "/dev/dri/card0"; - fd = open(dev, O_RDWR | O_CLOEXEC, 0); - #ifdef SEATD_LIBSEAT - if (fd == -1){ - fd = seatd_libseat_open_graphics(dev); - } - #endif + if ((NULL == dev) || ((fd = ms_try_open(dev)) < 0)) { + int i; + char buf[] = "/dev/dri/cardxx"; + + for (i = 0; i < 32; i++) { + sprintf(buf, "/dev/dri/card%d", i); + + if ((fd = ms_try_open(buf)) >= 0) { + uint64_t check_dumb = 0; + + if (drmGetCap(fd, DRM_CAP_DUMB_BUFFER, &check_dumb) >= 0 && check_dumb) { + break; + } + + close(fd); + fd = -1; + } + } } } if (fd == -1) {