From nobody Fri Oct 20 22:10:12 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SBzKd0LXRz4yHbs; Fri, 20 Oct 2023 22:10:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SBzKc6ghsz3DLP; Fri, 20 Oct 2023 22:10:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697839812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iEVRuWJK6y1sBVM7jjODvGcbR9CzP7MmrI6SenDi9vU=; b=ExXX/41fr9Kwc2wj3H8T1lMiMlm38AafBJfcouKbdj0Ply8hozXaI0PdCg/5cABQv+9Ca1 ihHcOJvPUhMqjTldTQpoUiXdkKFv/G9apxBFITQ8zfXdWLiO7g5KvnRbgCn/j+cWTmOYz6 wCmmTG7UoxMt32C4hb7NthGPd3bHzu4L19YCCLTcf5T8mK3o3m1vQHlh7VCWZSd0dwcmvs i2nuSBosxnb2YnbViiW0pk0MPu94eQ1sZCWaI941TZxAnceIewYsHhn9BAGAl7rjPyXlGB 0H19yGOiVEY0/OV1aKZBPCfhOncxd2G/eJiLFbEktqRriw8FVBj6QhA3XOj7sw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697839812; a=rsa-sha256; cv=none; b=JdPYp7w76YwA+qIgE+uoUwmK92/i/lHpiT31NdC4K/WLcFOmPpoTA+kw1NAYqeD9jjt3gs k3xwJi4woGMafB4pgUod2sAnxrNcodtq4t58V5UF+JrRwIDD0d4qjwMfU593iZFpOwBH0X OdAr+0tvoPLZNEVz4bVUHMa2FigyO9QPwQwjA7cVi5DuoLy1e4UnM4RyTSMCav9eBXGluc 8c8N0mwX9dQNNq8OE5wLTnSFSeaAPK1sUuHt6n8hb/jbxcK3fymBpCJL4tnOjnWdBW9pg9 ia4FwxkaKn447tDJt0s4hSZ1hRHseeOUXw03ej0OgSNl7fkkQLLC6NLyEAolBA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697839812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iEVRuWJK6y1sBVM7jjODvGcbR9CzP7MmrI6SenDi9vU=; b=QNuFqole24wXh0WE+Mj6MgVi2IEfFABkb5ulkiyj5iWsJ49ZtC0rq0oYcnkSPnatW5zNvu cVj7oTV/kOG7Pf3Ul0wVY3fE1KwDWuu9v4sSr7Iz6rxOXbSRNJ8uwwDWZwzVe5N2dVZFx3 fqpMrBzrz52qkCj8VOvCFFRnV5mHpRcYo8S0rOe83nwnXw1TqATcWuL7eUijxielUvfxs4 RO12Fm/UUePAzIpeOA8ULcWm8A9iKfF31PuWKv/OGNoJ0BeQMgUqxuoszLsaaDW4CZOFA9 I2XeXU10LIfOwOoy2YJwVV+14yshSbg9pgFFJ+0yEMZgM/hpkqlhL/wf0RO09A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SBzKc5lGKzqMM; Fri, 20 Oct 2023 22:10:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39KMACbU046205; Fri, 20 Oct 2023 22:10:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39KMACDq046193; Fri, 20 Oct 2023 22:10:12 GMT (envelope-from git) Date: Fri, 20 Oct 2023 22:10:12 GMT Message-Id: <202310202210.39KMACDq046193@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: a113f9dd9886 - main - uart: Support EARLY_PRINTF on x86 for port-mapped COM ports List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a113f9dd9886e48914ba48b1f02ecf3ad0fc00d3 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=a113f9dd9886e48914ba48b1f02ecf3ad0fc00d3 commit a113f9dd9886e48914ba48b1f02ecf3ad0fc00d3 Author: Warner Losh AuthorDate: 2023-10-20 22:07:03 +0000 Commit: Warner Losh CommitDate: 2023-10-20 22:07:24 +0000 uart: Support EARLY_PRINTF on x86 for port-mapped COM ports Support early printf for the ns8250 uart driver. Adding options UART_NS8250_EARLY_PORT=0xYYY options EARLY_PRINTF to your kernel config will enable it. The code is rather simple minded, so caveat emptor. This will enable printf before cninit. cninit automatically disables this and switches to the real routine. It only works for port-mapped COM ports, and only if you know the port's address at compile time. It's intended for be a debugging aide, not a general purpose thing. Sponsored by: Netflix Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D42306 --- sys/conf/options.amd64 | 3 +++ sys/conf/options.i386 | 3 +++ sys/dev/uart/uart_dev_ns8250.c | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/sys/conf/options.amd64 b/sys/conf/options.amd64 index 8402c89640f7..df18abfa8e1e 100644 --- a/sys/conf/options.amd64 +++ b/sys/conf/options.amd64 @@ -65,3 +65,6 @@ NO_LEGACY_PCIB opt_cpu.h # Compatibility with Linux MP table bugs. MPTABLE_LINUX_BUG_COMPAT + +# x86 specific uart options +UART_NS8250_EARLY_PORT opt_uart.h diff --git a/sys/conf/options.i386 b/sys/conf/options.i386 index c827e0bb7a69..b98591a2a7da 100644 --- a/sys/conf/options.i386 +++ b/sys/conf/options.i386 @@ -109,3 +109,6 @@ NO_LEGACY_PCIB opt_cpu.h # Compatibility with Linux MP table bugs. MPTABLE_LINUX_BUG_COMPAT + +# x86 specific uart options +UART_NS8250_EARLY_PORT opt_uart.h diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c index de9b67c6bef1..3787c6ed4c9b 100644 --- a/sys/dev/uart/uart_dev_ns8250.c +++ b/sys/dev/uart/uart_dev_ns8250.c @@ -78,6 +78,27 @@ static int broken_txfifo = 0; SYSCTL_INT(_hw, OID_AUTO, broken_txfifo, CTLFLAG_RWTUN, &broken_txfifo, 0, "UART FIFO has QEMU emulation bug"); +/* + * To use early printf on x86, add the following to your kernel config: + * + * options UART_NS8250_EARLY_PORT=0x3f8 + * options EARLY_PRINTF +*/ +#if defined(EARLY_PRINTF) && (defined(__amd64__) || defined(__i386__)) +static void +uart_ns8250_early_putc(int c) +{ + u_int stat = UART_NS8250_EARLY_PORT + REG_LSR; + u_int tx = UART_NS8250_EARLY_PORT + REG_DATA; + int limit = 10000; /* 10ms is plenty of time */ + + while ((inb(stat) & LSR_THRE) == 0 && --limit > 0) + continue; + outb(tx, c); +} +early_putc_t *early_putc = uart_ns8250_early_putc; +#endif /* EARLY_PRINTF */ + /* * Clear pending interrupts. THRE is cleared by reading IIR. Data * that may have been received gets lost here.