linux-efi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arvind Sankar <nivedita@alum.mit.edu>
To: Ard Biesheuvel <ardb@kernel.org>, linux-efi@vger.kernel.org
Subject: [PATCH v3] efi/gop: Allow automatically choosing the best mode
Date: Sat, 28 Mar 2020 12:06:01 -0400	[thread overview]
Message-ID: <20200328160601.378299-2-nivedita@alum.mit.edu> (raw)
In-Reply-To: <20200328160601.378299-1-nivedita@alum.mit.edu>

Add the ability to automatically pick the highest resolution video mode
(defined as the product of vertical and horizontal resolution) by using
a command-line argument of the form
	video=efifb:auto

If there are multiple modes with the highest resolution, pick one with
the highest color depth.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
---
 Documentation/fb/efifb.rst         |  6 +++
 drivers/firmware/efi/libstub/gop.c | 84 +++++++++++++++++++++++++++++-
 2 files changed, 89 insertions(+), 1 deletion(-)

diff --git a/Documentation/fb/efifb.rst b/Documentation/fb/efifb.rst
index eca38466487a..519550517fd4 100644
--- a/Documentation/fb/efifb.rst
+++ b/Documentation/fb/efifb.rst
@@ -57,4 +57,10 @@ mode=n
         "rgb" or "bgr" to match specifically those pixel formats, or a number
         for a mode with matching bits per pixel.
 
+auto
+        The EFI stub will choose the mode with the highest resolution (product
+        of horizontal and vertical resolution). If there are multiple modes
+        with the highest resolution, it will choose one with the highest color
+        depth.
+
 Edgar Hucek <gimli@dark-green.com>
diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libstub/gop.c
index 848cb605a9c4..fa05a0b0adfd 100644
--- a/drivers/firmware/efi/libstub/gop.c
+++ b/drivers/firmware/efi/libstub/gop.c
@@ -18,7 +18,8 @@
 enum efi_cmdline_option {
 	EFI_CMDLINE_NONE,
 	EFI_CMDLINE_MODE_NUM,
-	EFI_CMDLINE_RES
+	EFI_CMDLINE_RES,
+	EFI_CMDLINE_AUTO
 };
 
 static struct {
@@ -86,6 +87,19 @@ static bool parse_res(char *option, char **next)
 	return true;
 }
 
+static bool parse_auto(char *option, char **next)
+{
+	if (!strstarts(option, "auto"))
+		return false;
+	option += strlen("auto");
+	if (*option && *option++ != ',')
+		return false;
+	cmdline.option = EFI_CMDLINE_AUTO;
+
+	*next = option;
+	return true;
+}
+
 void efi_parse_option_graphics(char *option)
 {
 	while (*option) {
@@ -93,6 +107,8 @@ void efi_parse_option_graphics(char *option)
 			continue;
 		if (parse_res(option, &option))
 			continue;
+		if (parse_auto(option, &option))
+			continue;
 
 		while (*option && *option++ != ',')
 			;
@@ -211,6 +227,69 @@ static u32 choose_mode_res(efi_graphics_output_protocol_t *gop)
 	return cur_mode;
 }
 
+static u32 choose_mode_auto(efi_graphics_output_protocol_t *gop)
+{
+	efi_status_t status;
+
+	efi_graphics_output_protocol_mode_t *mode;
+	efi_graphics_output_mode_info_t *info;
+	unsigned long info_size;
+
+	u32 max_mode, cur_mode, best_mode, area;
+	u8 depth;
+	int pf;
+	efi_pixel_bitmask_t pi;
+	u32 m, w, h, a;
+	u8 d;
+
+	mode = efi_table_attr(gop, mode);
+
+	cur_mode = efi_table_attr(mode, mode);
+	max_mode = efi_table_attr(mode, max_mode);
+
+	info = efi_table_attr(mode, info);
+
+	pf = info->pixel_format;
+	pi = info->pixel_information;
+	w  = info->horizontal_resolution;
+	h  = info->vertical_resolution;
+
+	best_mode = cur_mode;
+	area = w * h;
+	depth = pixel_bpp(pf, pi);
+
+	for (m = 0; m < max_mode; m++) {
+		if (m == cur_mode)
+			continue;
+
+		status = efi_call_proto(gop, query_mode, m,
+					&info_size, &info);
+		if (status != EFI_SUCCESS)
+			continue;
+
+		pf = info->pixel_format;
+		pi = info->pixel_information;
+		w  = info->horizontal_resolution;
+		h  = info->vertical_resolution;
+
+		efi_bs_call(free_pool, info);
+
+		if (pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX)
+			continue;
+		a = w * h;
+		if (a < area)
+			continue;
+		d = pixel_bpp(pf, pi);
+		if (a > area || d > depth) {
+			best_mode = m;
+			area = a;
+			depth = d;
+		}
+	}
+
+	return best_mode;
+}
+
 static void set_mode(efi_graphics_output_protocol_t *gop)
 {
 	efi_graphics_output_protocol_mode_t *mode;
@@ -223,6 +302,9 @@ static void set_mode(efi_graphics_output_protocol_t *gop)
 	case EFI_CMDLINE_RES:
 		new_mode = choose_mode_res(gop);
 		break;
+	case EFI_CMDLINE_AUTO:
+		new_mode = choose_mode_auto(gop);
+		break;
 	default:
 		return;
 	}
-- 
2.24.1


  reply	other threads:[~2020-03-28 16:06 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-19 19:28 [PATCH 00/14] efi/gop: Refactoring + mode-setting feature Arvind Sankar
2020-03-19 19:28 ` [PATCH 01/14] efi/gop: Remove redundant current_fb_base Arvind Sankar
2020-03-19 19:28 ` [PATCH 02/14] efi/gop: Move check for framebuffer before con_out Arvind Sankar
2020-03-19 19:28 ` [PATCH 03/14] efi/gop: Get mode information outside the loop Arvind Sankar
2020-03-19 19:28 ` [PATCH 04/14] efi/gop: Factor out locating the gop into a function Arvind Sankar
2020-03-19 19:28 ` [PATCH 05/14] efi/gop: Slightly re-arrange logic of find_gop Arvind Sankar
2020-03-19 19:28 ` [PATCH 06/14] efi/gop: Move variable declarations into loop block Arvind Sankar
2020-03-19 19:28 ` [PATCH 07/14] efi/gop: Use helper macros for populating lfb_base Arvind Sankar
2020-03-19 19:28 ` [PATCH 08/14] efi/gop: Use helper macros for find_bits Arvind Sankar
2020-03-19 19:28 ` [PATCH 09/14] efi/gop: Remove unreachable code from setup_pixel_info Arvind Sankar
2020-03-19 19:28 ` [PATCH 10/14] efi/gop: Add prototypes for query_mode and set_mode Arvind Sankar
2020-03-19 19:28 ` [PATCH 11/14] efi/gop: Allow specifying mode number on command line Arvind Sankar
2020-03-19 22:53   ` kbuild test robot
2020-03-20  1:09   ` kbuild test robot
2020-03-20 14:36   ` Dan Carpenter
2020-03-20 17:51     ` Arvind Sankar
2020-03-19 19:28 ` [PATCH 12/14] efi/gop: Allow specifying mode by <xres>x<yres> Arvind Sankar
2020-03-19 19:28 ` [PATCH 13/14] efi/gop: Allow specifying depth as well as resolution Arvind Sankar
2020-03-19 19:28 ` [PATCH 14/14] efi/gop: Allow automatically choosing the best mode Arvind Sankar
2020-03-19 20:02 ` [PATCH 00/14] efi/gop: Refactoring + mode-setting feature Ard Biesheuvel
2020-03-20  2:00 ` [PATCH v2 " Arvind Sankar
2020-03-25 16:41   ` Ard Biesheuvel
2020-03-25 22:10     ` Arvind Sankar
2020-03-25 23:36       ` Ard Biesheuvel
2020-03-26 10:41         ` Ard Biesheuvel
2020-03-28 16:06           ` efi/gop: skip cur_mode in choose_mode_auto Arvind Sankar
2020-03-28 16:06             ` Arvind Sankar [this message]
2020-03-29  7:47             ` Ard Biesheuvel
2020-03-26 23:56         ` [PATCH v2 00/14] efi/gop: Refactoring + mode-setting feature Arvind Sankar
2020-03-28 15:43           ` Ard Biesheuvel
2020-03-25 16:50   ` Hans de Goede
2020-03-25 22:13     ` Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 01/14] efi/gop: Remove redundant current_fb_base Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 02/14] efi/gop: Move check for framebuffer before con_out Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 03/14] efi/gop: Get mode information outside the loop Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 04/14] efi/gop: Factor out locating the gop into a function Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 05/14] efi/gop: Slightly re-arrange logic of find_gop Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 06/14] efi/gop: Move variable declarations into loop block Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 07/14] efi/gop: Use helper macros for populating lfb_base Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 08/14] efi/gop: Use helper macros for find_bits Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 09/14] efi/gop: Remove unreachable code from setup_pixel_info Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 10/14] efi/gop: Add prototypes for query_mode and set_mode Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 11/14] efi/gop: Allow specifying mode number on command line Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 12/14] efi/gop: Allow specifying mode by <xres>x<yres> Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 13/14] efi/gop: Allow specifying depth as well as resolution Arvind Sankar
2020-03-20  2:00 ` [PATCH v2 14/14] efi/gop: Allow automatically choosing the best mode Arvind Sankar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200328160601.378299-2-nivedita@alum.mit.edu \
    --to=nivedita@alum.mit.edu \
    --cc=ardb@kernel.org \
    --cc=linux-efi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).