Skip to content

Commit 55d728a

Browse files
Ard BiesheuvelIngo Molnar
authored andcommitted
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: 9822504 ("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>
1 parent 540f4c0 commit 55d728a

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

drivers/video/fbdev/efifb.c

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/efi.h>
1111
#include <linux/errno.h>
1212
#include <linux/fb.h>
13+
#include <linux/pci.h>
1314
#include <linux/platform_device.h>
1415
#include <linux/screen_info.h>
1516
#include <video/vga.h>
@@ -143,6 +144,8 @@ static struct attribute *efifb_attrs[] = {
143144
};
144145
ATTRIBUTE_GROUPS(efifb);
145146

147+
static bool pci_dev_disabled; /* FB base matches BAR of a disabled device */
148+
146149
static int efifb_probe(struct platform_device *dev)
147150
{
148151
struct fb_info *info;
@@ -152,7 +155,7 @@ static int efifb_probe(struct platform_device *dev)
152155
unsigned int size_total;
153156
char *option = NULL;
154157

155-
if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
158+
if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI || pci_dev_disabled)
156159
return -ENODEV;
157160

158161
if (fb_get_options("efifb", &option))
@@ -360,3 +363,64 @@ static struct platform_driver efifb_driver = {
360363
};
361364

362365
builtin_platform_driver(efifb_driver);
366+
367+
#if defined(CONFIG_PCI) && !defined(CONFIG_X86)
368+
369+
static bool pci_bar_found; /* did we find a BAR matching the efifb base? */
370+
371+
static void claim_efifb_bar(struct pci_dev *dev, int idx)
372+
{
373+
u16 word;
374+
375+
pci_bar_found = true;
376+
377+
pci_read_config_word(dev, PCI_COMMAND, &word);
378+
if (!(word & PCI_COMMAND_MEMORY)) {
379+
pci_dev_disabled = true;
380+
dev_err(&dev->dev,
381+
"BAR %d: assigned to efifb but device is disabled!\n",
382+
idx);
383+
return;
384+
}
385+
386+
if (pci_claim_resource(dev, idx)) {
387+
pci_dev_disabled = true;
388+
dev_err(&dev->dev,
389+
"BAR %d: failed to claim resource for efifb!\n", idx);
390+
return;
391+
}
392+
393+
dev_info(&dev->dev, "BAR %d: assigned to efifb\n", idx);
394+
}
395+
396+
static void efifb_fixup_resources(struct pci_dev *dev)
397+
{
398+
u64 base = screen_info.lfb_base;
399+
u64 size = screen_info.lfb_size;
400+
int i;
401+
402+
if (pci_bar_found || screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
403+
return;
404+
405+
if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE)
406+
base |= (u64)screen_info.ext_lfb_base << 32;
407+
408+
if (!base)
409+
return;
410+
411+
for (i = 0; i < PCI_STD_RESOURCE_END; i++) {
412+
struct resource *res = &dev->resource[i];
413+
414+
if (!(res->flags & IORESOURCE_MEM))
415+
continue;
416+
417+
if (res->start <= base && res->end >= base + size - 1) {
418+
claim_efifb_bar(dev, i);
419+
break;
420+
}
421+
}
422+
}
423+
DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY,
424+
16, efifb_fixup_resources);
425+
426+
#endif

0 commit comments

Comments
 (0)