From nobody Tue Oct 18 06:03:11 2022 X-Original-To: dev-commits-src-all@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 4Ms3FC2Jdfz4g840; Tue, 18 Oct 2022 06:03:11 +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 4Ms3FC1WgBz3blx; Tue, 18 Oct 2022 06:03:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666072991; 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=6V7MdFYaf+YCQssxrCdRY2cEXwr4cHje4tgHEkXxTOw=; b=YcqC9Sb7zJ04KnPFLcg9kZlZUe8Lw2LGKADCaihe/I5zuziqVX9TtsfrOpTzQ9K8Jm6Cd3 +3bY1Okvj1Fm8thkgaQHCmAh52wOug2ORx25wz0W2fBfdBkUSjxegLbOX5h0pEMIhGFxW4 ODLIOgiJVtSBMDJ2EfIOzFL69b8tndbBMHgriyCpg1gr+eGW0p45fhykVVFXVe5QZzPqnC vFUYosvcXL874DAc2N0PFM8qzQpkH8UMukEt8tqTd62oh7Viue+FCHnOnzSPNqxTUPEspa 9ew8QREqwv+OLL5YVIjzDKZO203JYd6EsBVcfpLsFw76WhVR1MawY9AOeDs4wA== 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 4Ms3FC0c9Tz150y; Tue, 18 Oct 2022 06:03:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29I63BlT097410; Tue, 18 Oct 2022 06:03:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29I63BNF097409; Tue, 18 Oct 2022 06:03:11 GMT (envelope-from git) Date: Tue, 18 Oct 2022 06:03:11 GMT Message-Id: <202210180603.29I63BNF097409@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Colin Percival Subject: git: c4b68e7e53bb - main - ns8250: Check if flush via FCR succeeded List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c4b68e7e53bb352be3fa16995b99764c03097e66 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666072991; 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=6V7MdFYaf+YCQssxrCdRY2cEXwr4cHje4tgHEkXxTOw=; b=r311Mlz88nnBNw7SpPlbh8WhcESgGpdVUUEix1zZlVu4IDKx0W4EEK6hmSXVIh31t30end LMvIuO/KoAM8m1UmA9SisNWxvPvMDzvj0dhS+OCeuP7sqH59QAO4UbTD03U5PLBTka+Yvf dr+5nu7QuobPDlyUvV1HiKY1qRWjY4TTe2bm/h9aePsdhdIHxppszRC5UgnYHg2rCrKjVg nzXYqhR04iPkhlhYElv/xvMOV2AnzBZ3AWpDBGjzuOo/cVV3iLDGu3DrSVP6ue1YWHolnW rR02bvtlQu80siNpAKx5Jgp85v1DskRKGby/+VFzAgFfWxO5ex1gysi3E/5+ww== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666072991; a=rsa-sha256; cv=none; b=JLnFGP6rbJ3bO2hcHo93LlFjKIO954qdYikSWmryew8wlU7t24SSvFSm3GwIPK341tWIr5 vG74Ro2Q4HYMPR+16+Unmk0BqpXTNLfdbt2rt+Aft22rwW9DSIySCjVaa0cgPjUMCAtxiM IpInbmfw9vJXAm3yebaD6rEj+o01BOnmQ8V8cLas5WXAQWmOd/5JSRe9X9WyYNTWKqEwEZ 4bJLwxuVmGRcuDyhmtgCrEZftHnz/VAI0XgkVzQyNJH/PBUS9sg6yTtJxapUuRMKjutgkv GJOYvIZqV0DvP0Wd2ZwgBQjG14XaBnM2dEYsZPIjb8LoVPOtYduSLX38HLh7EA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=c4b68e7e53bb352be3fa16995b99764c03097e66 commit c4b68e7e53bb352be3fa16995b99764c03097e66 Author: Colin Percival AuthorDate: 2022-10-13 18:01:03 +0000 Commit: Colin Percival CommitDate: 2022-10-18 06:02:21 +0000 ns8250: Check if flush via FCR succeeded The emulated UART in the Firecracker VMM (aka the implementation in the rust-vmm/vm-superio project) includes FIFOs but does not implement the FCR register, which is used by ns8250_flush to flush the FIFOs. Check the LSR to see if there is still data in the FIFOs and call ns8250_drain if necessary. Discussed with: emaste, imp, jrtc27 Sponsored by: https://patreon.com/cperciva Differential Revision: https://reviews.freebsd.org/D36979 --- sys/dev/uart/uart_dev_ns8250.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c index 182831da7611..d0eadeded943 100644 --- a/sys/dev/uart/uart_dev_ns8250.c +++ b/sys/dev/uart/uart_dev_ns8250.c @@ -210,6 +210,8 @@ static void ns8250_flush(struct uart_bas *bas, int what) { uint8_t fcr; + uint8_t lsr; + int drain = 0; fcr = FCR_ENABLE; #ifdef CPU_XBURST @@ -221,6 +223,23 @@ ns8250_flush(struct uart_bas *bas, int what) fcr |= FCR_RCV_RST; uart_setreg(bas, REG_FCR, fcr); uart_barrier(bas); + + /* + * Detect and work around emulated UARTs which don't implement the + * FCR register; on these systems we need to drain the FIFO since + * the flush we request doesn't happen. One such system is the + * Firecracker VMM, aka. the rust-vmm/vm-superio emulation code: + * https://github.com/rust-vmm/vm-superio/issues/83 + */ + lsr = uart_getreg(bas, REG_LSR); + if ((lsr & LSR_TEMT) && (what & UART_FLUSH_TRANSMITTER)) + drain |= UART_DRAIN_TRANSMITTER; + if ((lsr & LSR_RXRDY) && (what & UART_FLUSH_RECEIVER)) + drain |= UART_DRAIN_RECEIVER; + if (drain != 0) { + printf("ns8250: UART FCR is broken\n"); + ns8250_drain(bas, drain); + } } static int