Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jLk9e-0007hR-ME for mharc-grub-devel@gnu.org; Tue, 07 Apr 2020 05:04:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55386) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLk9Z-0007fF-3P for grub-devel@gnu.org; Tue, 07 Apr 2020 05:04:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLk9T-0005if-Gw for grub-devel@gnu.org; Tue, 07 Apr 2020 05:04:17 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:47205 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jLk9T-0005i5-DQ for grub-devel@gnu.org; Tue, 07 Apr 2020 05:04:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586250251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jC6PI+KA9wPzIbGF4dJSpNHnnGwAIOq+0spuc3i9oao=; b=SSEoJ17lbBbXT3zmM7Di8to4x3Tn/CQhLcYJiWF0GmwRpBD+ktqsFSBsoDYQ0ENSLnqhD2 2JhWLNMc+rGMhAk5LvM0u/1fxTtPIL4TusLf3LDr3Mwf1Yp40o99zZCmYHdjuQSsUd4NWU UWV8bx4mjGJGbcbnyn0yI0Pc4EHg3q0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-28-4a_doQ6rOwGSM-PnmJqoSw-1; Tue, 07 Apr 2020 05:04:09 -0400 X-MC-Unique: 4a_doQ6rOwGSM-PnmJqoSw-1 Received: by mail-wr1-f72.google.com with SMTP id v14so1422996wrq.13 for ; Tue, 07 Apr 2020 02:04:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6q545ooMW0Ngkkn3N3HTbsj+5cOOdIxKqN80NKEeRrU=; b=hHQ9PdtvA2PKb9V8sWyxYIYzTYN1SDxl8ZQ1rx9V28YPvzwC+rK1xNckGPR3GwJKih QUZe4V1dXlVxPFdcvt4d/DUjh/blUtTYF/0eT0na03EkI4wOXRMYVv0gP6r1NHbptwGL T9YAg5XuAGqoj8N17A6yU4dL5LwCM092o6s1luq2L4ckqXkppN3GVCOYMwqXxB9qH475 f9nWyt6n3nwcjcB9ex6tOjsQOZ4fgcqLwvWOY2R6D+MvaFyIV0Cf4PSSZaBMB17ynpw8 NL9aRg+UhDevWlpU1kLQx4Ow/oX4dOW1KwFpSt0yzG0yk6/PJxvHJ7O1/6h6ZHXFqttT 206A== X-Gm-Message-State: AGi0PuZdzspGxvEJgYPDwc4QKvnw3q2FLo2Awv4GOQVHJQKmDkegx59t Fj64qQnNAouFCzcRS5Meozgn4TunjWJPsTDSRAzGAAXmAcAwfsCK3kboIEZDoLkKGOhLZL1EOPv 834Nc0FLYprQ= X-Received: by 2002:a1c:3c54:: with SMTP id j81mr1288586wma.140.1586250248159; Tue, 07 Apr 2020 02:04:08 -0700 (PDT) X-Google-Smtp-Source: APiQypJu7s2AakDmHUFFkOgpkZ7+JTmYS8alQjS49JOBdCgaFqfEecwAtqsDgax3Hqrw5d+yemm1fw== X-Received: by 2002:a1c:3c54:: with SMTP id j81mr1288560wma.140.1586250247919; Tue, 07 Apr 2020 02:04:07 -0700 (PDT) Received: from minerva.home ([2a01:c50f:ab80:6700:527f:85b3:5615:ff0b]) by smtp.gmail.com with ESMTPSA id o13sm7805444wrm.74.2020.04.07.02.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 02:04:07 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Hans de Goede , Daniel Kiper , Javier Martinez Canillas Subject: [PATCH v2 5/6] efi/console: Do not set text-mode until we actually need it Date: Tue, 7 Apr 2020 11:03:50 +0200 Message-Id: <20200407090351.50921-6-javierm@redhat.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200407090351.50921-1-javierm@redhat.com> References: <20200407090351.50921-1-javierm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Apr 2020 09:04:18 -0000 From: Hans de Goede If we're running with a hidden menu we may never need text mode, so do not change the video-mode to text until we actually need it. This allows to boot a machine without unnecessary graphical transitions and provide a seamless boot experience to users. Signed-off-by: Hans de Goede Signed-off-by: Javier Martinez Canillas --- Changes in v2: None grub-core/term/efi/console.c | 74 +++++++++++++++++++++++------------- include/grub/term.h | 4 +- 2 files changed, 51 insertions(+), 27 deletions(-) diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c index 9c32ca60a1d..f7c9b37e95d 100644 --- a/grub-core/term/efi/console.c +++ b/grub-core/term/efi/console.c @@ -24,6 +24,16 @@ #include #include =20 +typedef enum { + GRUB_TEXT_MODE_UNDEFINED =3D -1, + GRUB_TEXT_MODE_UNAVAILABLE =3D 0, + GRUB_TEXT_MODE_AVAILABLE +} +grub_text_mode; + +static grub_text_mode text_mode =3D GRUB_TEXT_MODE_UNDEFINED; +static grub_term_color_state text_colorstate =3D GRUB_TERM_COLOR_UNDEFINED= ; + static grub_uint32_t map_char (grub_uint32_t c) { @@ -106,15 +116,39 @@ grub_console_setcursor (struct grub_term_output *term= __attribute__ ((unused)), efi_call_2 (o->enable_cursor, o, on); } =20 +static grub_err_t +grub_prepare_for_text_output (struct grub_term_output *term) +{ + if (grub_efi_is_finished) + return GRUB_ERR_BAD_DEVICE; + + if (text_mode !=3D GRUB_TEXT_MODE_UNDEFINED) + return text_mode ? 0 : GRUB_ERR_BAD_DEVICE; + + if (! grub_efi_set_text_mode (1)) + { + /* This really should never happen */ + grub_error (GRUB_ERR_BAD_DEVICE, "cannot set text mode"); + text_mode =3D GRUB_TEXT_MODE_UNAVAILABLE; + return GRUB_ERR_BAD_DEVICE; + } + + grub_console_setcursor (term, 1); + if (text_colorstate !=3D GRUB_TERM_COLOR_UNDEFINED) + grub_console_setcolorstate (term, text_colorstate); + text_mode =3D GRUB_TEXT_MODE_AVAILABLE; + return 0; +} + static void -grub_console_putchar (struct grub_term_output *term __attribute__ ((unused= )), +grub_console_putchar (struct grub_term_output *term, =09=09 const struct grub_unicode_glyph *c) { grub_efi_char16_t str[2 + 30]; grub_efi_simple_text_output_interface_t *o; unsigned i, j; =20 - if (grub_efi_is_finished) + if (grub_prepare_for_text_output (term)) return; =20 o =3D grub_efi_system_table->con_out; @@ -326,14 +360,15 @@ grub_console_getkey (struct grub_term_input *term) } =20 static struct grub_term_coordinate -grub_console_getwh (struct grub_term_output *term __attribute__ ((unused))= ) +grub_console_getwh (struct grub_term_output *term) { grub_efi_simple_text_output_interface_t *o; grub_efi_uintn_t columns, rows; =20 o =3D grub_efi_system_table->con_out; - if (grub_efi_is_finished || efi_call_4 (o->query_mode, o, o->mode->mode, -=09=09=09=09=09 &columns, &rows) !=3D GRUB_EFI_SUCCESS) + if (grub_prepare_for_text_output (term) !=3D GRUB_ERR_NONE || + efi_call_4 (o->query_mode, o, o->mode->mode, +=09=09 &columns, &rows) !=3D GRUB_EFI_SUCCESS) { /* Why does this fail? */ columns =3D 80; @@ -348,7 +383,7 @@ grub_console_getxy (struct grub_term_output *term __att= ribute__ ((unused))) { grub_efi_simple_text_output_interface_t *o; =20 - if (grub_efi_is_finished) + if (grub_efi_is_finished || text_mode !=3D GRUB_TEXT_MODE_AVAILABLE) return (struct grub_term_coordinate) { 0, 0 }; =20 o =3D grub_efi_system_table->con_out; @@ -356,12 +391,12 @@ grub_console_getxy (struct grub_term_output *term __a= ttribute__ ((unused))) } =20 static void -grub_console_gotoxy (struct grub_term_output *term __attribute__ ((unused)= ), +grub_console_gotoxy (struct grub_term_output *term, =09=09 struct grub_term_coordinate pos) { grub_efi_simple_text_output_interface_t *o; =20 - if (grub_efi_is_finished) + if (grub_prepare_for_text_output (term)) return; =20 o =3D grub_efi_system_table->con_out; @@ -374,7 +409,7 @@ grub_console_cls (struct grub_term_output *term __attri= bute__ ((unused))) grub_efi_simple_text_output_interface_t *o; grub_efi_int32_t orig_attr; =20 - if (grub_efi_is_finished) + if (grub_efi_is_finished || text_mode !=3D GRUB_TEXT_MODE_AVAILABLE) return; =20 o =3D grub_efi_system_table->con_out; @@ -384,19 +419,15 @@ grub_console_cls (struct grub_term_output *term __att= ribute__ ((unused))) efi_call_2 (o->set_attributes, o, orig_attr); } =20 -static grub_err_t -grub_efi_console_output_init (struct grub_term_output *term) -{ - grub_efi_set_text_mode (1); - grub_console_setcursor (term, 1); - return 0; -} - static grub_err_t grub_efi_console_output_fini (struct grub_term_output *term) { + if (text_mode !=3D GRUB_TEXT_MODE_AVAILABLE) + return 0; + grub_console_setcursor (term, 0); grub_efi_set_text_mode (0); + text_mode =3D GRUB_TEXT_MODE_UNDEFINED; return 0; } =20 @@ -411,7 +442,6 @@ static struct grub_term_input grub_console_term_input = =3D static struct grub_term_output grub_console_term_output =3D { .name =3D "console", - .init =3D grub_efi_console_output_init, .fini =3D grub_efi_console_output_fini, .putchar =3D grub_console_putchar, .getwh =3D grub_console_getwh, @@ -427,14 +457,6 @@ static struct grub_term_output grub_console_term_outpu= t =3D void grub_console_init (void) { - /* FIXME: it is necessary to consider the case where no console control - is present but the default is already in text mode. */ - if (! grub_efi_set_text_mode (1)) - { - grub_error (GRUB_ERR_BAD_DEVICE, "cannot set text mode"); - return; - } - grub_term_register_output ("console", &grub_console_term_output); grub_term_register_input ("console", &grub_console_term_input); } diff --git a/include/grub/term.h b/include/grub/term.h index c215133383f..9da03dc751e 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -75,9 +75,11 @@ /* These are used to represent the various color states we use. */ typedef enum { + /* Used for uninitialized grub_term_color_state variables */ + GRUB_TERM_COLOR_UNDEFINED =3D -1, /* The color used to display all text that does not use the user defined colors below. */ - GRUB_TERM_COLOR_STANDARD, + GRUB_TERM_COLOR_STANDARD =3D 0, /* The user defined colors for normal text. */ GRUB_TERM_COLOR_NORMAL, /* The user defined colors for highlighted text. */ --=20 2.25.1