All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] efifb: avoid reconfiguration of BAR that covers the framebuffer
@ 2017-03-22 15:30 ` Ard Biesheuvel
  0 siblings, 0 replies; 117+ messages in thread
From: Ard Biesheuvel @ 2017-03-22 15:30 UTC (permalink / raw)
  To: linux-arm-kernel, linux-efi
  Cc: lorenzo.pieralisi, Ard Biesheuvel, matt, linux-pci, heyi.guo,
	pjones, hanjun.guo, bhelgaas, yinghai

On UEFI systems, the PCI subsystem is enumerated by the firmware,
and if a graphical framebuffer is exposed by 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 quirk to the EFI fb driver to find the BAR associated with
the GOP base address, and set the IORESOURCE_PCI_FIXED attribute so
that the PCI core will leave it alone.

Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Peter Jones <pjones@redhat.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
v3: check device is enabled before attempting to claim the resource

 drivers/video/fbdev/efifb.c | 60 +++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
index 8c4dc1e1f94f..88f653864a01 100644
--- a/drivers/video/fbdev/efifb.c
+++ b/drivers/video/fbdev/efifb.c
@@ -10,6 +10,7 @@
 #include <linux/efi.h>
 #include <linux/errno.h>
 #include <linux/fb.h>
+#include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/screen_info.h>
 #include <video/vga.h>
@@ -143,6 +144,9 @@ static struct attribute *efifb_attrs[] = {
 };
 ATTRIBUTE_GROUPS(efifb);
 
+static bool pci_bar_found;	/* did we find a BAR matching the efifb base? */
+static bool pci_dev_disabled;	/* was the device disabled? */
+
 static int efifb_probe(struct platform_device *dev)
 {
 	struct fb_info *info;
@@ -152,7 +156,7 @@ static int efifb_probe(struct platform_device *dev)
 	unsigned int size_total;
 	char *option = NULL;
 
-	if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
+	if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI || pci_dev_disabled)
 		return -ENODEV;
 
 	if (fb_get_options("efifb", &option))
@@ -360,3 +364,57 @@ static struct platform_driver efifb_driver = {
 };
 
 builtin_platform_driver(efifb_driver);
+
+static void claim_efifb_bar(struct pci_dev *dev, int idx)
+{
+	u16 word;
+
+	pci_bar_found = true;
+
+	pci_read_config_word(dev, PCI_COMMAND, &word);
+	if (!(word & PCI_COMMAND_MEMORY)) {
+		pci_dev_disabled = true;
+		dev_err(&dev->dev,
+			"BAR %d: assigned to efifb but device is disabled!\n",
+			idx);
+		return;
+	}
+
+	if (pci_claim_resource(dev, idx)) {
+		pci_dev_disabled = true;
+		dev_err(&dev->dev,
+			"BAR %d: failed to claim resource for efifb!\n", idx);
+		return;
+	}
+
+	dev_info(&dev->dev, "BAR %d: assigned to efifb\n", idx);
+}
+
+static void efifb_fixup_resources(struct pci_dev *dev)
+{
+	u64 base = screen_info.lfb_base;
+	u64 size = screen_info.lfb_size;
+	int i;
+
+	if (pci_bar_found || screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
+		return;
+
+	if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE)
+		base |= (u64)screen_info.ext_lfb_base << 32;
+
+	if (!base)
+		return;
+
+	for (i = 0; i < PCI_STD_RESOURCE_END; i++) {
+		struct resource *res = &dev->resource[i];
+
+		if (!(res->flags & IORESOURCE_MEM))
+			continue;
+
+		if (res->start <= base && res->end >= base + size - 1) {
+			claim_efifb_bar(dev, i);
+			break;
+		}
+	}
+}
+DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, efifb_fixup_resources);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 117+ messages in thread

end of thread, other threads:[~2017-05-20  8:19 UTC | newest]

Thread overview: 117+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-22 15:30 [PATCH v3] efifb: avoid reconfiguration of BAR that covers the framebuffer Ard Biesheuvel
2017-03-22 15:30 ` Ard Biesheuvel
2017-03-22 15:30 ` Ard Biesheuvel
     [not found] ` <1490196629-28088-1-git-send-email-ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2017-03-22 19:31   ` Lukas Wunner
2017-03-22 19:31     ` Lukas Wunner
2017-03-22 19:31     ` Lukas Wunner
2017-03-22 19:32     ` Ard Biesheuvel
2017-03-22 19:32       ` Ard Biesheuvel
2017-03-22 19:32       ` Ard Biesheuvel
     [not found]       ` <CAKv+Gu_X-SEnz7h9J8boqqjOQGHQawwdSAq4haH-OGu8zdfNfA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-23  8:48         ` Lukas Wunner
2017-03-23  8:48           ` Lukas Wunner
2017-03-23  8:48           ` Lukas Wunner
2017-03-23  9:04           ` Ard Biesheuvel
2017-03-23  9:04             ` Ard Biesheuvel
2017-03-23  9:04             ` Ard Biesheuvel
     [not found]             ` <CAKv+Gu93eJ-js3g7M6Jdm6XGMaWMswFmzBG2qNT4rn+3=1+EyA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-23 10:57               ` Lorenzo Pieralisi
2017-03-23 10:57                 ` Lorenzo Pieralisi
2017-03-23 10:57                 ` Lorenzo Pieralisi
2017-03-23 12:25                 ` Ard Biesheuvel
2017-03-23 12:25                   ` Ard Biesheuvel
2017-03-23 12:25                   ` Ard Biesheuvel
2017-03-23 14:31                   ` Lorenzo Pieralisi
2017-03-23 14:31                     ` Lorenzo Pieralisi
2017-03-23 14:31                     ` Lorenzo Pieralisi
2017-03-23 15:15                     ` Ard Biesheuvel
2017-03-23 15:15                       ` Ard Biesheuvel
2017-03-23 15:15                       ` Ard Biesheuvel
2017-03-27 15:37                       ` Ard Biesheuvel
2017-03-27 15:37                         ` Ard Biesheuvel
2017-03-27 15:37                         ` Ard Biesheuvel
2017-03-28 21:27                 ` Sinan Kaya
2017-03-28 21:27                   ` Sinan Kaya
2017-03-28 21:27                   ` Sinan Kaya
2017-03-28 21:39                   ` Ard Biesheuvel
2017-03-28 21:39                     ` Ard Biesheuvel
2017-03-28 21:39                     ` Ard Biesheuvel
     [not found]                     ` <CAKv+Gu9LbwpnJNi1OL25MWvYPxEOfKRHcs2jA2121BPaQWPzow-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-28 21:49                       ` Sinan Kaya
2017-03-28 21:49                         ` Sinan Kaya
2017-03-28 21:49                         ` Sinan Kaya
     [not found]                         ` <27f50de3-721e-e8ec-00c8-b7a9d3cff0d6-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-03-30  8:46                           ` Ard Biesheuvel
2017-03-30  8:46                             ` Ard Biesheuvel
2017-03-30  8:46                             ` Ard Biesheuvel
     [not found]                             ` <CAKv+Gu-qRg8-YRCairppKrEfeLcW+OwVF8qZHp7vxXJA_AwPOw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-30 10:05                               ` Lorenzo Pieralisi
2017-03-30 10:05                                 ` Lorenzo Pieralisi
2017-03-30 10:05                                 ` Lorenzo Pieralisi
2017-03-30 10:09                                 ` Ard Biesheuvel
2017-03-30 10:09                                   ` Ard Biesheuvel
2017-03-30 10:09                                   ` Ard Biesheuvel
2017-03-30 11:42                                   ` okaya
2017-03-30 11:42                                     ` okaya at codeaurora.org
2017-03-30 11:42                                     ` okaya
2017-03-30 13:38                                   ` Ard Biesheuvel
2017-03-30 13:38                                     ` Ard Biesheuvel
2017-03-30 13:38                                     ` Ard Biesheuvel
2017-03-30 13:50                                     ` Sinan Kaya
2017-03-30 13:50                                       ` Sinan Kaya
2017-03-30 13:50                                       ` Sinan Kaya
     [not found]                                       ` <ae87ae28-f50d-095f-576e-f3fd7f96dea2-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-04-02 15:16                                         ` Ard Biesheuvel
2017-04-02 15:16                                           ` Ard Biesheuvel
2017-04-02 15:16                                           ` Ard Biesheuvel
     [not found]                                           ` <CAKv+Gu8x0rQUnTUorknW-mW9LFgrxFYsXyy4LU_w9JbA-m_sjA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-10 15:28                                             ` Ard Biesheuvel
2017-04-10 15:28                                               ` Ard Biesheuvel
2017-04-10 15:28                                               ` Ard Biesheuvel
2017-04-10 16:53                                               ` Lorenzo Pieralisi
2017-04-10 16:53                                                 ` Lorenzo Pieralisi
2017-04-10 16:53                                                 ` Lorenzo Pieralisi
2017-04-10 17:06                                                 ` Sinan Kaya
2017-04-10 17:06                                                   ` Sinan Kaya
2017-04-10 17:06                                                   ` Sinan Kaya
2017-04-10 17:13                                                 ` Ard Biesheuvel
2017-04-10 17:13                                                   ` Ard Biesheuvel
2017-04-10 17:13                                                   ` Ard Biesheuvel
     [not found]                                                   ` <CAKv+Gu-AN-OwnAJG5dt0Qg4GU8HxZBowTSA0H3LhNA3nHfrsQg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-10 17:29                                                     ` Ard Biesheuvel
2017-04-10 17:29                                                       ` Ard Biesheuvel
2017-04-10 17:29                                                       ` Ard Biesheuvel
     [not found]                                                       ` <CAKv+Gu9dS4OhLbBw59yKYQmoJ8SpFexzk9yH=XfXnzn8NJ4mcg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-11 13:16                                                         ` Lorenzo Pieralisi
2017-04-11 13:16                                                           ` Lorenzo Pieralisi
2017-04-11 13:16                                                           ` Lorenzo Pieralisi
2017-04-11 16:06                                                           ` Ard Biesheuvel
2017-04-11 16:06                                                             ` Ard Biesheuvel
2017-04-11 16:06                                                             ` Ard Biesheuvel
2017-04-23  1:45                                                       ` Yinghai Lu
2017-04-23  1:45                                                         ` Yinghai Lu
2017-04-23  1:45                                                         ` Yinghai Lu
     [not found]                                                         ` <20170423014546.GA2704-HmG2f/OLMhfd32I7TRUmRQWg3BAJk+jzdezBB/11ZoCIZ3GwZIjcak9v6f1uFnsJ2SarAXORi/o@public.gmane.org>
2017-04-27 13:55                                                           ` Ard Biesheuvel
2017-04-27 13:55                                                             ` Ard Biesheuvel
2017-04-27 13:55                                                             ` Ard Biesheuvel
     [not found]                                                             ` <CAKv+Gu_n7xP-2RtF44GVzwyoMXDOeF-bR43yStwp2y+oBNs4jg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-28 20:51                                                               ` Yinghai Lu
2017-04-28 20:51                                                                 ` Yinghai Lu
2017-04-28 20:51                                                                 ` Yinghai Lu
2017-03-22 19:36     ` Sinan Kaya
2017-03-22 19:36       ` Sinan Kaya
2017-03-22 19:36       ` Sinan Kaya
2017-03-22 19:41       ` Ard Biesheuvel
2017-03-22 19:41         ` Ard Biesheuvel
2017-03-22 19:41         ` Ard Biesheuvel
2017-03-22 19:49         ` Sinan Kaya
2017-03-22 19:49           ` Sinan Kaya
2017-03-22 19:49           ` Sinan Kaya
2017-03-22 19:52           ` Ard Biesheuvel
2017-03-22 19:52             ` Ard Biesheuvel
2017-03-22 19:52             ` Ard Biesheuvel
2017-03-22 19:57             ` Sinan Kaya
2017-03-22 19:57               ` Sinan Kaya
2017-03-22 19:57               ` Sinan Kaya
     [not found]               ` <4ccb4d92-3830-3980-38c3-7085a3d97734-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-03-22 20:00                 ` Ard Biesheuvel
2017-03-22 20:00                   ` Ard Biesheuvel
2017-03-22 20:00                   ` Ard Biesheuvel
2017-05-03  3:09   ` Heyi Guo
2017-05-03  3:09     ` Heyi Guo
2017-05-03  3:09     ` Heyi Guo
2017-05-18 14:01     ` Bjorn Helgaas
2017-05-18 14:01       ` Bjorn Helgaas
2017-05-18 14:01       ` Bjorn Helgaas
     [not found]       ` <20170518140154.GA24324-1RhO1Y9PlrlHTL0Zs8A6p5iNqAH0jzoTYJqu5kTmcBRl57MIdRCFDg@public.gmane.org>
2017-05-20  8:19         ` Heyi Guo
2017-05-20  8:19           ` Heyi Guo
2017-05-20  8:19           ` Heyi Guo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.