From patchwork Wed Sep 13 22:05:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 813651 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="p19Gjsn9"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xswzG1kg8z9s76 for ; Thu, 14 Sep 2017 08:18:18 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 021A5C22739; Wed, 13 Sep 2017 22:11:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8353BC22440; Wed, 13 Sep 2017 22:09:19 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 293F4C22649; Wed, 13 Sep 2017 22:07:00 +0000 (UTC) Received: from mail-qk0-f193.google.com (mail-qk0-f193.google.com [209.85.220.193]) by lists.denx.de (Postfix) with ESMTPS id 23125C222F6 for ; Wed, 13 Sep 2017 22:06:57 +0000 (UTC) Received: by mail-qk0-f193.google.com with SMTP id g128so957656qke.0 for ; Wed, 13 Sep 2017 15:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tTjJNgm+knfE2IVXbgcSZPd7Q9s0s6Q4yiWNU5LVgTo=; b=p19Gjsn94q8hJs1Xa1e60A1TEdRggJDYW4/tjg5KNI+WXmBIDg69dJHSv5vg9qVqyk 1swG+00Mm1XRKUrayK7c+dhRH1w+uQAI8iTGsybpDDEwOI34BggMaO13Xg7PHSjX1G0R 24kED1+O/e/7IvWW8UAmBiGqGws6BpZg4CNEzwIWhfaDxysFr26DISc1gR+sWnDGizbC ZYL7w8/wDhNWlMd8OAvkbb93PccezIDl0MBhuwWsBkZqnq+11Zp8zsd3PNVFPovQMvp2 5pENu/Y8WbWLKmJJavNtOR4z05ltwErLhVhkk6dMWd1Ph8jDcQnFWmPQHB3rBCVVY1Qb jo3Q== 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; bh=tTjJNgm+knfE2IVXbgcSZPd7Q9s0s6Q4yiWNU5LVgTo=; b=c8HcUQiVDfqnG0BpVi1cdALXvBcSAPVrVXTr9qyo5vtDcIx5Hwd4BpzDPx8483kEFD 2tcirt8ES1bGcpBB48Hwzrk7TDHJQ05HtOwwPIfE7BQtlRRGk1c27mOeWf3fASeDhhVG a6OT7w0gATPNqgX1mSwD0+h9Lz3bPt3l0Gab26u/0KocZMVoWiNo1iilybUBpjY/reKK cp797hnlW70DHEJd/KgIbe2YYhXe6uQNnRPeKrhX+SfmTJburQzA1Sr9J4xZGwHDYkUr 9WRzv0zJUNyi8aViEbP8c8Ij30Ohh0DMU+Krio7yF3EC3Wgkedzhw13id7AQP7nPGIQG 75dg== X-Gm-Message-State: AHPjjUiP2byD/mAlDDZ2e5Mjh/b0IgblXojyxgjLq8i2aeagseYl6VtI upIz6p1yFt2av6I79DU= X-Google-Smtp-Source: AOwi7QAgQ2WMpVM6BL8QwKJkWqUvVnw/9ycqdDqC95Qin0teqklmoO7YOnQn2VRsqP8FvBxYjj+XEA== X-Received: by 10.55.98.18 with SMTP id w18mr27728572qkb.163.1505340415863; Wed, 13 Sep 2017 15:06:55 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id c7sm6554168qtg.30.2017.09.13.15.06.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Sep 2017 15:06:54 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Wed, 13 Sep 2017 18:05:44 -0400 Message-Id: <20170913220546.19560-22-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170913220546.19560-1-robdclark@gmail.com> References: <20170913220546.19560-1-robdclark@gmail.com> Cc: Heinrich Schuchardt , Peter Jones Subject: [U-Boot] [PATCH v3 21/21] efi_loader: Some console improvements for vidconsole X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 1) use fputs() to reduce cache flushes from once-per-char to once-per-string 2) handle \r, \t, and \b in addition to just \n for tracking cursor position 3) cursor row/col are zero based, not one based Signed-off-by: Rob Clark --- include/efi_api.h | 6 +++-- lib/efi_loader/efi_console.c | 58 ++++++++++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index 604c5b7ec4..c3b9032a48 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -29,6 +29,8 @@ enum efi_timer_delay { }; #define UINTN size_t +typedef long INTN; +typedef uint16_t *efi_string_t; #define EVT_TIMER 0x80000000 #define EVT_RUNTIME 0x40000000 @@ -427,10 +429,10 @@ struct efi_simple_text_output_protocol { void *reset; efi_status_t (EFIAPI *output_string)( struct efi_simple_text_output_protocol *this, - const unsigned short *str); + const efi_string_t str); efi_status_t (EFIAPI *test_string)( struct efi_simple_text_output_protocol *this, - const unsigned short *str); + const efi_string_t str); efi_status_t(EFIAPI *query_mode)( struct efi_simple_text_output_protocol *this, unsigned long mode_number, unsigned long *columns, diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c index 9048a8d32c..afc725a2c7 100644 --- a/lib/efi_loader/efi_console.c +++ b/lib/efi_loader/efi_console.c @@ -140,34 +140,46 @@ static efi_status_t EFIAPI efi_cout_reset( return EFI_EXIT(EFI_UNSUPPORTED); } -static void print_unicode_in_utf8(u16 c) -{ - char utf8[MAX_UTF8_PER_UTF16] = { 0 }; - utf16_to_utf8((u8 *)utf8, &c, 1); - puts(utf8); -} - static efi_status_t EFIAPI efi_cout_output_string( struct efi_simple_text_output_protocol *this, - const unsigned short *string) + const efi_string_t string) { - struct cout_mode *mode; - u16 ch; + struct simple_text_output_mode *con = &efi_con_mode; + struct cout_mode *mode = &efi_cout_modes[con->mode]; - mode = &efi_cout_modes[efi_con_mode.mode]; EFI_ENTRY("%p, %p", this, string); - for (;(ch = *string); string++) { - print_unicode_in_utf8(ch); - efi_con_mode.cursor_column++; - if (ch == '\n') { - efi_con_mode.cursor_column = 1; - efi_con_mode.cursor_row++; - } else if (efi_con_mode.cursor_column > mode->columns) { - efi_con_mode.cursor_column = 1; - efi_con_mode.cursor_row++; + + unsigned n16 = utf16_strlen(string); + char buf[MAX_UTF8_PER_UTF16 * n16 + 1]; + char *p; + + *utf16_to_utf8((u8 *)buf, string, n16) = '\0'; + + fputs(stdout, buf); + + for (p = buf; *p; p++) { + switch (*p) { + case '\r': /* carriage-return */ + con->cursor_column = 0; + break; + case '\n': /* newline */ + con->cursor_column = 0; + con->cursor_row++; + break; + case '\t': /* tab, assume 8 char align */ + break; + case '\b': /* backspace */ + con->cursor_column = max(0, con->cursor_column - 1); + break; + default: + con->cursor_column++; + break; + } + if (con->cursor_column >= mode->columns) { + con->cursor_column = 0; + con->cursor_row++; } - if (efi_con_mode.cursor_row > mode->rows) - efi_con_mode.cursor_row = mode->rows; + con->cursor_row = min(con->cursor_row, (s32)mode->rows - 1); } return EFI_EXIT(EFI_SUCCESS); @@ -175,7 +187,7 @@ static efi_status_t EFIAPI efi_cout_output_string( static efi_status_t EFIAPI efi_cout_test_string( struct efi_simple_text_output_protocol *this, - const unsigned short *string) + const efi_string_t string) { EFI_ENTRY("%p, %p", this, string); return EFI_EXIT(EFI_SUCCESS);