All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arvind Sankar <nivedita@alum.mit.edu>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Hans de Goede <hdegoede@redhat.com>,
	linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 13/14] efi/gop: Allow specifying depth as well as resolution
Date: Thu, 19 Mar 2020 22:00:27 -0400	[thread overview]
Message-ID: <20200320020028.1936003-14-nivedita@alum.mit.edu> (raw)
In-Reply-To: <20200319192855.29876-1-nivedita@alum.mit.edu>

Extend the video mode argument to handle an optional color depth
specification of the form
	video=efifb:<xres>x<yres>[-(rgb|bgr|<bpp>)]

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

diff --git a/Documentation/fb/efifb.rst b/Documentation/fb/efifb.rst
index 635275071307..eca38466487a 100644
--- a/Documentation/fb/efifb.rst
+++ b/Documentation/fb/efifb.rst
@@ -50,9 +50,11 @@ mode=n
         The EFI stub will set the mode of the display to mode number n if
         possible.
 
-<xres>x<yres>
+<xres>x<yres>[-(rgb|bgr|<bpp>)]
         The EFI stub will search for a display mode that matches the specified
-        horizontal and vertical resolution, and set the mode of the display to
-        it if one is found.
+        horizontal and vertical resolution, and optionally bit depth, and set
+        the mode of the display to it if one is found. The bit depth can either
+        "rgb" or "bgr" to match specifically those pixel formats, or a number
+        for a mode with matching bits per pixel.
 
 Edgar Hucek <gimli@dark-green.com>
diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libstub/gop.c
index cc84e6a82f54..848cb605a9c4 100644
--- a/drivers/firmware/efi/libstub/gop.c
+++ b/drivers/firmware/efi/libstub/gop.c
@@ -27,6 +27,8 @@ static struct {
 		u32 mode;
 		struct {
 			u32 width, height;
+			int format;
+			u8 depth;
 		} res;
 	};
 } cmdline __efistub_global = { .option = EFI_CMDLINE_NONE };
@@ -50,7 +52,8 @@ static bool parse_modenum(char *option, char **next)
 
 static bool parse_res(char *option, char **next)
 {
-	u32 w, h;
+	u32 w, h, d = 0;
+	int pf = -1;
 
 	if (!isdigit(*option))
 		return false;
@@ -58,11 +61,26 @@ static bool parse_res(char *option, char **next)
 	if (*option++ != 'x' || !isdigit(*option))
 		return false;
 	h = simple_strtoull(option, &option, 10);
+	if (*option == '-') {
+		option++;
+		if (strstarts(option, "rgb")) {
+			option += strlen("rgb");
+			pf = PIXEL_RGB_RESERVED_8BIT_PER_COLOR;
+		} else if (strstarts(option, "bgr")) {
+			option += strlen("bgr");
+			pf = PIXEL_BGR_RESERVED_8BIT_PER_COLOR;
+		} else if (isdigit(*option))
+			d = simple_strtoull(option, &option, 10);
+		else
+			return false;
+	}
 	if (*option && *option++ != ',')
 		return false;
 	cmdline.option     = EFI_CMDLINE_RES;
 	cmdline.res.width  = w;
 	cmdline.res.height = h;
+	cmdline.res.format = pf;
+	cmdline.res.depth  = d;
 
 	*next = option;
 	return true;
@@ -123,6 +141,18 @@ static u32 choose_mode_modenum(efi_graphics_output_protocol_t *gop)
 	return cmdline.mode;
 }
 
+static u8 pixel_bpp(int pixel_format, efi_pixel_bitmask_t pixel_info)
+{
+	if (pixel_format == PIXEL_BIT_MASK) {
+		u32 mask = pixel_info.red_mask | pixel_info.green_mask |
+			   pixel_info.blue_mask | pixel_info.reserved_mask;
+		if (!mask)
+			return 0;
+		return __fls(mask) - __ffs(mask) + 1;
+	} else
+		return 32;
+}
+
 static u32 choose_mode_res(efi_graphics_output_protocol_t *gop)
 {
 	efi_status_t status;
@@ -133,16 +163,21 @@ static u32 choose_mode_res(efi_graphics_output_protocol_t *gop)
 
 	u32 max_mode, cur_mode;
 	int pf;
+	efi_pixel_bitmask_t pi;
 	u32 m, w, h;
 
 	mode = efi_table_attr(gop, mode);
 
 	cur_mode = efi_table_attr(mode, mode);
 	info = efi_table_attr(mode, info);
-	w = info->horizontal_resolution;
-	h = info->vertical_resolution;
+	pf = info->pixel_format;
+	pi = info->pixel_information;
+	w  = info->horizontal_resolution;
+	h  = info->vertical_resolution;
 
-	if (w == cmdline.res.width && h == cmdline.res.height)
+	if (w == cmdline.res.width && h == cmdline.res.height &&
+	    (cmdline.res.format < 0 || cmdline.res.format == pf) &&
+	    (!cmdline.res.depth || cmdline.res.depth == pixel_bpp(pf, pi)))
 		return cur_mode;
 
 	max_mode = efi_table_attr(mode, max_mode);
@@ -157,6 +192,7 @@ static u32 choose_mode_res(efi_graphics_output_protocol_t *gop)
 			continue;
 
 		pf = info->pixel_format;
+		pi = info->pixel_information;
 		w  = info->horizontal_resolution;
 		h  = info->vertical_resolution;
 
@@ -164,7 +200,9 @@ static u32 choose_mode_res(efi_graphics_output_protocol_t *gop)
 
 		if (pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX)
 			continue;
-		if (w == cmdline.res.width && h == cmdline.res.height)
+		if (w == cmdline.res.width && h == cmdline.res.height &&
+		    (cmdline.res.format < 0 || cmdline.res.format == pf) &&
+		    (!cmdline.res.depth || cmdline.res.depth == pixel_bpp(pf, pi)))
 			return m;
 	}
 
-- 
2.24.1


  parent reply	other threads:[~2020-03-20  2:00 UTC|newest]

Thread overview: 50+ 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-19 22:53     ` kbuild test robot
2020-03-20  1:09   ` kbuild test robot
2020-03-20  1:09     ` kbuild test robot
2020-03-20 14:36   ` Dan Carpenter
2020-03-20 14:36     ` Dan Carpenter
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             ` [PATCH v3] efi/gop: Allow automatically choosing the best mode Arvind Sankar
2020-03-29  7:47             ` efi/gop: skip cur_mode in choose_mode_auto 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 ` Arvind Sankar [this message]
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=20200320020028.1936003-14-nivedita@alum.mit.edu \
    --to=nivedita@alum.mit.edu \
    --cc=ardb@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@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 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.