Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

efi/fb: Avoid reconfiguration of BAR that covers the framebuffer

On UEFI systems, the PCI subsystem is enumerated by the firmware,
and if a graphical framebuffer is exposed via a PCI device, its base
address and size are exposed to the OS via the Graphics Output
Protocol (GOP).

On arm64 PCI systems, the entire PCI hierarchy is reconfigured from
scratch at boot. This may result in the GOP framebuffer address to
become stale, if the BAR covering the framebuffer is modified. This
will cause the framebuffer to become unresponsive, and may in some
cases result in unpredictable behavior if the range is reassigned to
another device.

So add a non-x86 quirk to the EFI fb driver to find the BAR associated
with the GOP base address, and claim the BAR resource so that the PCI
core will not move it.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: <stable@vger.kernel.org> # v4.7+
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Peter Jones <pjones@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: leif.lindholm@linaro.org
Cc: linux-efi@vger.kernel.org
Cc: lorenzo.pieralisi@arm.com
Fixes: 9822504c1fa5 ("efifb: Enable the efi-framebuffer platform driver ...")
Link: http://lkml.kernel.org/r/20170404152744.26687-3-ard.biesheuvel@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Ard Biesheuvel and committed by
Ingo Molnar
55d728a4 540f4c0e

+65 -1
+65 -1
drivers/video/fbdev/efifb.c
··· 10 10 #include <linux/efi.h> 11 11 #include <linux/errno.h> 12 12 #include <linux/fb.h> 13 + #include <linux/pci.h> 13 14 #include <linux/platform_device.h> 14 15 #include <linux/screen_info.h> 15 16 #include <video/vga.h> ··· 144 143 }; 145 144 ATTRIBUTE_GROUPS(efifb); 146 145 146 + static bool pci_dev_disabled; /* FB base matches BAR of a disabled device */ 147 + 147 148 static int efifb_probe(struct platform_device *dev) 148 149 { 149 150 struct fb_info *info; ··· 155 152 unsigned int size_total; 156 153 char *option = NULL; 157 154 158 - if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI) 155 + if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI || pci_dev_disabled) 159 156 return -ENODEV; 160 157 161 158 if (fb_get_options("efifb", &option)) ··· 363 360 }; 364 361 365 362 builtin_platform_driver(efifb_driver); 363 + 364 + #if defined(CONFIG_PCI) && !defined(CONFIG_X86) 365 + 366 + static bool pci_bar_found; /* did we find a BAR matching the efifb base? */ 367 + 368 + static void claim_efifb_bar(struct pci_dev *dev, int idx) 369 + { 370 + u16 word; 371 + 372 + pci_bar_found = true; 373 + 374 + pci_read_config_word(dev, PCI_COMMAND, &word); 375 + if (!(word & PCI_COMMAND_MEMORY)) { 376 + pci_dev_disabled = true; 377 + dev_err(&dev->dev, 378 + "BAR %d: assigned to efifb but device is disabled!\n", 379 + idx); 380 + return; 381 + } 382 + 383 + if (pci_claim_resource(dev, idx)) { 384 + pci_dev_disabled = true; 385 + dev_err(&dev->dev, 386 + "BAR %d: failed to claim resource for efifb!\n", idx); 387 + return; 388 + } 389 + 390 + dev_info(&dev->dev, "BAR %d: assigned to efifb\n", idx); 391 + } 392 + 393 + static void efifb_fixup_resources(struct pci_dev *dev) 394 + { 395 + u64 base = screen_info.lfb_base; 396 + u64 size = screen_info.lfb_size; 397 + int i; 398 + 399 + if (pci_bar_found || screen_info.orig_video_isVGA != VIDEO_TYPE_EFI) 400 + return; 401 + 402 + if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) 403 + base |= (u64)screen_info.ext_lfb_base << 32; 404 + 405 + if (!base) 406 + return; 407 + 408 + for (i = 0; i < PCI_STD_RESOURCE_END; i++) { 409 + struct resource *res = &dev->resource[i]; 410 + 411 + if (!(res->flags & IORESOURCE_MEM)) 412 + continue; 413 + 414 + if (res->start <= base && res->end >= base + size - 1) { 415 + claim_efifb_bar(dev, i); 416 + break; 417 + } 418 + } 419 + } 420 + DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY, 421 + 16, efifb_fixup_resources); 422 + 423 + #endif