All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glenn Washburn <development@efficientek.com>
To: grub-devel@gnu.org, Daniel Kiper <dkiper@net-space.pl>
Cc: Glenn Washburn <development@efficientek.com>
Subject: [PATCH] efi: Set text-mode console resolution to maximum supported
Date: Fri,  6 May 2022 04:46:17 -0500	[thread overview]
Message-ID: <20220506094617.1258175-1-development@efficientek.com> (raw)

On some buggy EFI firmwares, GRUB is started with the console resolution
set to the maximum but the output console EFI object has the mode set as
0, which is the minimum supported mode of 80x25 characters. This causes
strange behavior at the GRUB shell where output can fill the screen, but
the prompt is at line 80 in the middle of the screen.

When initializing the EFI console, find the largest console resolution
supported by area and set that as the current output mode. This works around
the buggy firmware and provides a GRUB shell that displays correctly.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 grub-core/term/efi/console.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c
index a3622e4fe..06da5548f 100644
--- a/grub-core/term/efi/console.c
+++ b/grub-core/term/efi/console.c
@@ -141,6 +141,10 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)),
 static grub_err_t
 grub_prepare_for_text_output (struct grub_term_output *term)
 {
+  grub_efi_simple_text_output_interface_t *o;
+  grub_efi_uintn_t columns, columns_max, rows, rows_max;
+  grub_efi_int32_t i, mode_max;
+
   if (grub_efi_is_finished)
     return GRUB_ERR_BAD_DEVICE;
 
@@ -155,6 +159,16 @@ grub_prepare_for_text_output (struct grub_term_output *term)
       return GRUB_ERR_BAD_DEVICE;
     }
 
+  /* Set text-mode resolution to maximum supported */
+  o = grub_efi_system_table->con_out;
+  for (i=0, columns_max=0, rows_max=0, mode_max=0; i < o->mode->max_mode; i++)
+    if (GRUB_EFI_SUCCESS == efi_call_4 (o->query_mode, o, o->mode->mode,
+                                       &columns, &rows)
+       && (columns_max * rows_max) < (columns * rows))
+      mode_max = i;
+
+  efi_call_2 (o->set_mode, o, mode_max);
+
   if (cursor_mode != GRUB_CURSOR_MODE_UNDEFINED)
     grub_console_setcursor (term, cursor_mode);
   if (text_colorstate != GRUB_TERM_COLOR_UNDEFINED)
-- 
2.34.1



             reply	other threads:[~2022-05-06  9:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06  9:46 Glenn Washburn [this message]
2022-05-06 10:39 ` [PATCH] efi: Set text-mode console resolution to maximum supported Gerd Hoffmann
2022-05-07  0:59   ` Glenn Washburn
2022-05-10 11:57     ` Gerd Hoffmann
2022-05-12  1:43       ` Glenn Washburn
2022-05-12 12:59         ` Gerd Hoffmann

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=20220506094617.1258175-1-development@efficientek.com \
    --to=development@efficientek.com \
    --cc=dkiper@net-space.pl \
    --cc=grub-devel@gnu.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.