Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jCpeH-0004qI-MA for mharc-grub-devel@gnu.org; Fri, 13 Mar 2020 15:07:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59186) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCpeB-0004kM-W9 for grub-devel@gnu.org; Fri, 13 Mar 2020 15:07:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jCpeA-0001Yu-J7 for grub-devel@gnu.org; Fri, 13 Mar 2020 15:07:03 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:56815 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 1jCpeA-0001Wa-FL for grub-devel@gnu.org; Fri, 13 Mar 2020 15:07:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584126421; 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=JFrm2UCew5MPYQ+qKg4+lOBFajT/TwxS4W8N0suv2t8=; b=DjbVQknKQLC+x54Yo0nTFU0O9hoy2p3wy5ZLle/TqC992uOjZfsgKDyuKqgOy2tjeMGBOh F3xPIcO3EZqWvFypVexdqf78uKKTQ799s7ciK2Z3bDnujGmbVdh+0Jeyu8ZXrGUbPBoyfp ksJvWdmHDZjWCmlPQeKl2LlbUd7JSTA= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-276-DYn7r1m_NA-uHPZ3Aqd1dw-1; Fri, 13 Mar 2020 15:07:00 -0400 X-MC-Unique: DYn7r1m_NA-uHPZ3Aqd1dw-1 Received: by mail-wr1-f71.google.com with SMTP id u18so4711635wrn.11 for ; Fri, 13 Mar 2020 12:06:59 -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=3Mk3pffUDW/S3FPpGJCvtNYRnKJs2is6W0mklOcj4IU=; b=NW+lXd8OPDUWVHBSu29LehvC/HyrqxCHg4QIXOdCti6Od4lJADERatZU3/WAZ+18tV 2M22A9MQR/FabmaTWDetJjmF/fL+YKXA4TcNModjO54Z/9vzP56XNnJdb/kunsgLmONR ix5EpTD7Ak/CkQRW3cy5rpOY2htvAZAXR3BSGyo9GuD36opnVrvgy4My9jKaiYF6IP/c ObeK8fY7ENBRtFF3dvrBmFnG93XgW1BZeKQJ4qmtxFsvutcqFq6cObOgJQS6Br3GCwue zDITHwE3p2uOodRgxl9pTMJ6LxoHZEpkoBJDfs5qZnSef04jAqZ7wjztbYvRZVpELjpf xvFg== X-Gm-Message-State: ANhLgQ2tZ1DaehOcsL597igIWPCvygc+zaGHh7sQHQSjLQr1wNbpLiQa wxCtSEaCOTcBAbkfUNrKybyuUHpDcZGuywjUGXeBzKxsGEtlIoNgvyKZgTDQDble+KyMxJo0kVZ e6xmMAsfOxSg= X-Received: by 2002:a05:600c:618:: with SMTP id o24mr12770098wmm.128.1584126418265; Fri, 13 Mar 2020 12:06:58 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvgp5yADbskbJgyMmQsuGPHNimj3Bs3yJdDBsRbchcBpm2wOVQdS6TyWnazCxC21yHAwRZ/8w== X-Received: by 2002:a05:600c:618:: with SMTP id o24mr12770084wmm.128.1584126417992; Fri, 13 Mar 2020 12:06:57 -0700 (PDT) Received: from minerva.redhat.com ([2a01:c50f:ab80:6700:527f:85b3:5615:ff0b]) by smtp.gmail.com with ESMTPSA id z11sm1919763wmc.30.2020.03.13.12.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2020 12:06:57 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Daniel Kiper , Hans de Goede , Javier Martinez Canillas Subject: [PATCH 03/10] efi/console: Do not set text-mode until we actually need it Date: Fri, 13 Mar 2020 20:06:35 +0100 Message-Id: <20200313190642.822157-4-javierm@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313190642.822157-1-javierm@redhat.com> References: <20200313190642.822157-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.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: Fri, 13 Mar 2020 19:07:06 -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. Signed-off-by: Hans de Goede Signed-off-by: Javier Martinez Canillas --- 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 59d9604472a..16ccd350ee0 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; @@ -264,14 +298,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; @@ -286,7 +321,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; @@ -294,12 +329,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; @@ -312,7 +347,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; @@ -322,19 +357,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 @@ -348,7 +379,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, @@ -364,14 +394,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 8117e2a24da..486b30e7125 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.24.1