Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jOfFw-00078W-L3 for mharc-grub-devel@gnu.org; Wed, 15 Apr 2020 06:26:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43702) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOfFs-00070h-MW for grub-devel@gnu.org; Wed, 15 Apr 2020 06:26:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOfFm-0005i1-SW for grub-devel@gnu.org; Wed, 15 Apr 2020 06:26:52 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:41919 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOfFm-0005hm-Oc for grub-devel@gnu.org; Wed, 15 Apr 2020 06:26:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586946406; 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=9ziPGJL2avslhWY0Rvo1/Qk+1VQApCTSgVVQEO55Sog=; b=MwXexTUkKxc8Tnxu9d/23ADkCsK9g6Bm8C71bjObsKDIvdXNYdplmYVzztBtJ10tw+9Bj1 /uddKtdnlNo0UI13pEGeepU6UBHspCaOtQpvKUxRCXHBLj/UawMhFUyKtcsH2PkDbL/jmr bA1ufJfmNp42SUEoGm3qA4Y+LxxHPQc= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-459-KjSrShGnOX60NpO9ZaO5kg-1; Wed, 15 Apr 2020 06:26:45 -0400 X-MC-Unique: KjSrShGnOX60NpO9ZaO5kg-1 Received: by mail-wr1-f70.google.com with SMTP id h95so10302530wrh.11 for ; Wed, 15 Apr 2020 03:26:44 -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=86o3dvNtzLayXY1UQpIeYR0t1f6aY22edVn+ZeJi9OI=; b=BbW7OtWOOMKMde3HQMs5Kj44KZOqHX/0f71ycxA3wPcQP3OPMXxzmhFKBbERNSVcp4 KU5PJDQAI/aJLrT54Z8Cu8n1sxvRb5R61hgbTlVxVNXto35ylWgGoTvMp0ZEITBjatAK n8aUQUDtQ2Ys3/9Ugdqh+L9k7OOfCH2vvpFuW+CItGhsg0+jVBalPZUmxzVStHVYXA1L yUXS6jBpan4m+o1BB5CT7Xv/v0S0xSFUmJElQZvMDWMqMyH9RM8OqzfQ8onlEMyZdP1k rCKuIyzzaKPwBaOjjh4Xf6cAigfz70qT84njJAhRuoVGamS55DvZUChoAlHuPTPBXoOw p7Cw== X-Gm-Message-State: AGi0PuaPyiRp7eXh4h8WmS84lHMDm/ZVlTea3K3pmEdtfVdZmJvRpgKa YDDSx2EKuNVaTYk8ZvXat32R8Te68kDBCpJfqiT8sQqDnVtzCZYSWoSjbbw4HGwx8Yd0vaHYIMN SM0ljakDvj7U= X-Received: by 2002:adf:ed46:: with SMTP id u6mr1142673wro.327.1586946403539; Wed, 15 Apr 2020 03:26:43 -0700 (PDT) X-Google-Smtp-Source: APiQypJwBzwpa8ewo4M8Fv/pIESGKSkZmTsNzIzdLIdTPziGY9WMBdHbJw93t75QLxFp0wCncVp3CQ== X-Received: by 2002:adf:ed46:: with SMTP id u6mr1142649wro.327.1586946403224; Wed, 15 Apr 2020 03:26:43 -0700 (PDT) Received: from minerva.redhat.com ([2a01:c50f:ab80:6700:527f:85b3:5615:ff0b]) by smtp.gmail.com with ESMTPSA id n124sm22803517wma.11.2020.04.15.03.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 03:26:42 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Hans de Goede , Daniel Kiper , Javier Martinez Canillas Subject: [PATCH v3 5/6] efi/console: Do not set text-mode until we actually need it Date: Wed, 15 Apr 2020 12:26:21 +0200 Message-Id: <20200415102622.1890550-6-javierm@redhat.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200415102622.1890550-1-javierm@redhat.com> References: <20200415102622.1890550-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] [fuzzy] X-Received-From: 207.211.31.120 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: Wed, 15 Apr 2020 10:26:54 -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 Reviewed-by: Daniel Kiper --- Changes in v3: - Make grub_prepare_for_text_output() return GRUB_ERR_NONE instead of 0. 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 64591b90aad..2f1ae85ba7d 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 ? GRUB_ERR_NONE : 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 GRUB_ERR_NONE; +} + 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) !=3D GRUB_ERR_NONE) return; =20 o =3D grub_efi_system_table->con_out; @@ -327,14 +361,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; @@ -349,7 +384,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; @@ -357,12 +392,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) !=3D GRUB_ERR_NONE) return; =20 o =3D grub_efi_system_table->con_out; @@ -375,7 +410,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; @@ -385,19 +420,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 @@ -412,7 +443,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, @@ -428,14 +458,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