From 6233fa8b9f94de0245da0a49123d7687a95d4060 Mon Sep 17 00:00:00 2001 From: stefan11111 Date: Mon, 14 Jul 2025 00:27:01 +0300 Subject: [PATCH] xfree86: fbdevhw: use the fbdev passed by the user, if there is one The fbdev pci probe doesn't use the fbdev passed by the user, and instead tries to guess what framebuffer the user wants to use. Only if that fails, fbdev falls back to the option passed by the user. This is backwards, if the user explicitly passes a framebuffer device to use, the X server should use that, and fall back on guessing if that fails. Signed-off-by: stefan11111 --- hw/xfree86/fbdevhw/fbdevhw.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/hw/xfree86/fbdevhw/fbdevhw.c b/hw/xfree86/fbdevhw/fbdevhw.c index 54c13a3fbb..2a8b267550 100644 --- a/hw/xfree86/fbdevhw/fbdevhw.c +++ b/hw/xfree86/fbdevhw/fbdevhw.c @@ -239,12 +239,29 @@ fbdev2xfree_timing(struct fb_var_screeninfo *var, DisplayModePtr mode) * Try to find the framebuffer device for a given PCI device */ static int -fbdev_open_pci(struct pci_device *pPci, char **namep) +fbdev_open_pci(struct pci_device *pPci, char *device, char **namep) { struct fb_fix_screeninfo fix; char filename[256]; int fd, i; + /* try argument (from XF86Config) first */ + if (device) { + fd = open(device, O_RDWR); + } + else { + /* second: environment variable */ + device = getenv("FRAMEBUFFER"); + fd = device ? open(device, O_RDWR) : -1; + } + + if (fd != -1) { + /* fbdev was provided by the user instead of guessed, skip pci check */ + if (namep) + *namep = NULL; + return fd; + } + for (i = 0; i < 8; i++) { snprintf(filename, sizeof(filename), "/sys/bus/pci/devices/%04x:%02x:%02x.%d/graphics/fb%d", @@ -389,7 +406,7 @@ fbdevHWProbe(struct pci_device *pPci, const char *device, char **namep) int fd; if (pPci) - fd = fbdev_open_pci(pPci, namep); + fd = fbdev_open_pci(pPci, device, namep); else fd = fbdev_open(-1, device, namep); @@ -409,7 +426,7 @@ fbdevHWInit(ScrnInfoPtr pScrn, struct pci_device *pPci, const char *device) /* open device */ if (pPci) - fPtr->fd = fbdev_open_pci(pPci, NULL); + fPtr->fd = fbdev_open_pci(pPci, device, NULL); else fPtr->fd = fbdev_open(pScrn->scrnIndex, device, NULL); if (-1 == fPtr->fd) {