838818e
From c4220b3f747ae6dd28171137d85fba0eab64e36d Mon Sep 17 00:00:00 2001
838818e
From: Hans de Goede <hdegoede@redhat.com>
838818e
Date: Tue, 24 Jul 2018 19:11:28 +0200
838818e
Subject: [PATCH 7/7] efifb: BGRT: Do not copy the boot graphics for non native
838818e
 resolutions
838818e
838818e
On x86 some firmwares use a low non native resolution for the display when
838818e
they have shown some text messages. While keeping the bgrt filled with info
838818e
for the native resolution. If the bgrt image intended for the native
838818e
resolution still fits, it will be displayed very close to the right edge of
838818e
the display looking quite bad.
838818e
838818e
This commits adds a (heuristics based) checks for this and makes efifb
838818e
not show the boot graphics when this is the case.
838818e
838818e
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
838818e
Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
838818e
---
838818e
 drivers/video/fbdev/efifb.c | 43 +++++++++++++++++++++++++++++++++++++
838818e
 1 file changed, 43 insertions(+)
838818e
838818e
diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c
838818e
index fa01eecc0a55..52bf39f93888 100644
838818e
--- a/drivers/video/fbdev/efifb.c
838818e
+++ b/drivers/video/fbdev/efifb.c
838818e
@@ -111,6 +111,46 @@ static void efifb_copy_bmp(u8 *src, u32 *dst, int width, struct screen_info *si)
838818e
 	}
838818e
 }
838818e
 
838818e
+#ifdef CONFIG_X86
838818e
+/*
838818e
+ * On x86 some firmwares use a low non native resolution for the display when
838818e
+ * they have shown some text messages. While keeping the bgrt filled with info
838818e
+ * for the native resolution. If the bgrt image intended for the native
838818e
+ * resolution still fits, it will be displayed very close to the right edge of
838818e
+ * the display looking quite bad. This function checks for this.
838818e
+ */
838818e
+static bool efifb_bgrt_sanity_check(struct screen_info *si, u32 bmp_width)
838818e
+{
838818e
+	static const int default_resolutions[][2] = {
838818e
+		{  800,  600 },
838818e
+		{ 1024,  768 },
838818e
+		{ 1280, 1024 },
838818e
+	};
838818e
+	u32 i, right_margin;
838818e
+
838818e
+	for (i = 0; i < ARRAY_SIZE(default_resolutions); i++) {
838818e
+		if (default_resolutions[i][0] == si->lfb_width &&
838818e
+		    default_resolutions[i][1] == si->lfb_height)
838818e
+			break;
838818e
+	}
838818e
+	/* If not a default resolution used for textmode, this should be fine */
838818e
+	if (i >= ARRAY_SIZE(default_resolutions))
838818e
+		return true;
838818e
+
838818e
+	/* If the right margin is 5 times smaller then the left one, reject */
838818e
+	right_margin = si->lfb_width - (bgrt_tab.image_offset_x + bmp_width);
838818e
+	if (right_margin < (bgrt_tab.image_offset_x / 5))
838818e
+		return false;
838818e
+
838818e
+	return true;
838818e
+}
838818e
+#else
838818e
+static bool efifb_bgrt_sanity_check(struct screen_info *si, u32 bmp_width)
838818e
+{
838818e
+	return true;
838818e
+}
838818e
+#endif
838818e
+
838818e
 static void efifb_show_boot_graphics(struct fb_info *info)
838818e
 {
838818e
 	u32 bmp_width, bmp_height, bmp_pitch, screen_pitch, dst_x, y, src_y;
838818e
@@ -169,6 +209,9 @@ static void efifb_show_boot_graphics(struct fb_info *info)
838818e
 	    (bgrt_tab.image_offset_y + bmp_height) > si->lfb_height)
838818e
 		goto error;
838818e
 
838818e
+	if (!efifb_bgrt_sanity_check(si, bmp_width))
838818e
+		goto error;
838818e
+
838818e
 	pr_info("efifb: showing boot graphics\n");
838818e
 
838818e
 	for (y = 0; y < si->lfb_height; y++, dst += si->lfb_linelength) {
838818e
-- 
838818e
2.18.0
838818e