From owner-svn-src-head@freebsd.org Mon Aug 29 20:01:54 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D2CD5BC824B; Mon, 29 Aug 2016 20:01:54 +0000 (UTC) (envelope-from jmcneill@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 868A9A7C; Mon, 29 Aug 2016 20:01:54 +0000 (UTC) (envelope-from jmcneill@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7TK1rxh087134; Mon, 29 Aug 2016 20:01:53 GMT (envelope-from jmcneill@FreeBSD.org) Received: (from jmcneill@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7TK1rNN087133; Mon, 29 Aug 2016 20:01:53 GMT (envelope-from jmcneill@FreeBSD.org) Message-Id: <201608292001.u7TK1rNN087133@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jmcneill set sender to jmcneill@FreeBSD.org using -f From: Jared McNeill Date: Mon, 29 Aug 2016 20:01:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r305026 - head/sys/boot/efi/libefi X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Aug 2016 20:01:54 -0000 Author: jmcneill Date: Mon Aug 29 20:01:53 2016 New Revision: 305026 URL: https://svnweb.freebsd.org/changeset/base/305026 Log: When the EFI implementation (like U-Boot) does not support WaitForKey, we can emulate efi_cons_poll(0 with a flag and caching the last key read with ReadKeyStroke. This fixes the loader.efi countdown timer on Pine64 (and other U-Boot + EFI using platforms). Reviewed by: imp, manu Differential Revision: https://reviews.freebsd.org/D7670 Modified: head/sys/boot/efi/libefi/efi_console.c Modified: head/sys/boot/efi/libefi/efi_console.c ============================================================================== --- head/sys/boot/efi/libefi/efi_console.c Mon Aug 29 20:01:49 2016 (r305025) +++ head/sys/boot/efi/libefi/efi_console.c Mon Aug 29 20:01:53 2016 (r305026) @@ -51,6 +51,9 @@ void HO(void); void end_term(void); #endif +static EFI_INPUT_KEY key_cur; +static int key_pending; + static void efi_cons_probe(struct console *); static int efi_cons_init(int); void efi_cons_putchar(int); @@ -436,14 +439,20 @@ efi_cons_getchar() EFI_STATUS status; UINTN junk; - /* Try to read a key stroke. We wait for one if none is pending. */ - status = conin->ReadKeyStroke(conin, &key); - while (status == EFI_NOT_READY) { - /* Some EFI implementation (u-boot for example) do not support WaitForKey */ - if (conin->WaitForKey != NULL) - BS->WaitForEvent(1, &conin->WaitForKey, &junk); + if (key_pending) { + key = key_cur; + key_pending = 0; + } else { + /* Try to read a key stroke. We wait for one if none is pending. */ status = conin->ReadKeyStroke(conin, &key); + while (status == EFI_NOT_READY) { + /* Some EFI implementation (u-boot for example) do not support WaitForKey */ + if (conin->WaitForKey != NULL) + BS->WaitForEvent(1, &conin->WaitForKey, &junk); + status = conin->ReadKeyStroke(conin, &key); + } } + switch (key.ScanCode) { case 0x17: /* ESC */ return (0x1b); /* esc */ @@ -456,9 +465,20 @@ efi_cons_getchar() int efi_cons_poll() { + EFI_INPUT_KEY key; + EFI_STATUS status; + + if (conin->WaitForKey == NULL) { + if (key_pending) + return (1); + status = conin->ReadKeyStroke(conin, &key); + if (status == EFI_SUCCESS) { + key_cur = key; + key_pending = 1; + } + return (key_pending); + } - if (conin->WaitForKey == NULL) - return (1); /* This can clear the signaled state. */ return (BS->CheckEvent(conin->WaitForKey) == EFI_SUCCESS); }