From nobody Thu Nov 26 11:35:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=baylibre.com ARC-Seal: i=1; a=rsa-sha256; t=1795544582; cv=none; d=zohomail.com; s=zohoarc; b=j8xfzjNVMkJVt6RQyLv9CxJ1vHWeGVjbrXMqEHS/HOOkTUfYJFESTZnGcKCWpuzbdGAFJXnzdy3soARLRgh7Grk89FYj2Stml6c8UDjjmgmWpiHrnNfx8W76eQd9w7J66He5PigxyTXid/yKTT2XhXkUHlz3D9/+w0f37HNaUio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795544582; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GkLo8KNHatVyEzmy+WAcfcbrVOPUa6Auy0tec9083fg=; b=nafx3gGUrUlOY4kpv+FJbQgNHHrSm7esF6gUILK06PtZbCeomOb+zD2I1TVJPLRJMIu7L8dhaYOS4+0txIkCSedkmJcR4HWma0GDMU/epWgFaXAPsxF1lZH3IQWfJHQBhOzrK7IQeKKSMVV+usXuJj0DP7Iw0zj1WELEtg34vJg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1795544582680995.9154792727411; Tue, 24 Nov 2026 10:23:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1501386.1697488 (Exim 4.92) (envelope-from ) id 1xVvA5-0005p0-VT; Tue, 24 Nov 2026 18:22:37 +0000 Received: by outflank-mailman (output) from mailman id 1501386.1697488; Tue, 24 Nov 2026 18:22:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xVvA5-0005nt-Nh; Tue, 24 Nov 2026 18:22:37 +0000 Received: by outflank-mailman (input) for mailman id 1501386; Tue, 24 Nov 2026 17:31:47 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xVuMs-00050i-US for xen-devel@lists.xenproject.org; Tue, 24 Nov 2026 17:31:47 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xVuMs-004J4Q-Ap for xen-devel@lists.xenproject.org; Tue, 24 Nov 2026 18:31:46 +0100 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b05c9f2-bab6-0a2a0a5309dd-0a2a4504e6cc-42 for ; Tue, 24 Nov 2026 18:31:46 +0100 Received: from [209.85.222.42] (helo=mail-ua1-f42.google.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b05ca01-b57f-0a2a45040019-d155de2abca8-3 for ; Tue, 24 Nov 2026 18:31:46 +0100 Received: by mail-ua1-f42.google.com with SMTP id a1e0cc1a2514c-9905d61449cso1286184241.0 for ; Tue, 24 Nov 2026 09:31:45 -0800 (PST) Received: from [127.0.0.1] ([2804:7f0:7543:4532:5471:ddc9:4fc9:5]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5ee8b6641d6sm14760703e0c.17.2026.11.24.09.31.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 09:31:44 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=baylibre.com header.i="@baylibre.com" header.h="Cc:To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre.com; s=google; t=1795541505; x=1796146305; darn=lists.xenproject.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GkLo8KNHatVyEzmy+WAcfcbrVOPUa6Auy0tec9083fg=; b=G00D1RLZrL/kjIGtkgNidzItDbfK2pJcncU2p1wZufXBltsxpsfo23XxWsCoQ1az9N ZL56k7vRFdDC50gKS4ngFQicTlMuiTKCmuzcSVRjgJ/RQQ4zhiPYufuE+sdQgXDGioti qAi0fuOEMVUaB7uzBf2lVLdPCvVHRJGxc/BBzkec9LMpI29bTFmrM57/Dj9+HhY269oK GVPvRs/HOAQJ5UnruStkm5Mflera8omDDk0AMq9UZmvvCqHELiA27XfwdROXa9Fv4MX+ WIMqj02Jr7IVnMjo9HeS3BwQ4wsuVitWMfGzylG/9uF1GGFwZ/NrKpLjGc64S7Q1E3N3 1DwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795541505; x=1796146305; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GkLo8KNHatVyEzmy+WAcfcbrVOPUa6Auy0tec9083fg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jqrjR rTcY2LOuzNpN3A8SESWizGw1bg== X-Received: by 2002:a05:6122:488e:b0:5ec:2c33:f782 with SMTP id 71dfb90a1353d-5ee8af71019mr8362715e0c.22.1795541504703; Tue, 24 Nov 2026 09:31:44 -0800 (PST) From: Ronaldo Nunez Date: Tue, 24 Nov 2026 14:30:54 -0300 Subject: [PATCH v4 1/2] xen/ns16550: preserve XScale UUE bit in IER writes MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261124-v4-uart-harndover-v4-1-90c4412cb95e@baylibre.com> References: <20261124-v4-uart-harndover-v4-0-90c4412cb95e@baylibre.com> In-Reply-To: <20261124-v4-uart-harndover-v4-0-90c4412cb95e@baylibre.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Zhang Zheng , Ronaldo Nunez X-Mailer: b4 0.14.2 X-purgate-ID: tlsNG-ebf023/1795541506-536C2B50-0283CB20/0/0 X-purgate-type: clean X-purgate-size: 5188 X-ZohoMail-DKIM: pass (identity @baylibre.com) X-ZM-MESSAGEID: 1795544584694047900 From: Zhang Zheng XScale-like UARTs are enabled by setting UART unit enable (UUE) bit in the IER register. Clearing IER to mask interrupts therefore also disables the UART, breaking both interrupt-driven and polled operation, and prevents Xen from taking control of the UART from the SBI (RISC-V IP variants). Introduce ns_write_ier() to set UART_IER_UUE whenever the port is flagged as an XScale device, and route all XScale-related IER writes through it. The flag is determined by matching "intel,xscale-uart", and that compatible is added to the DT match table so such UARTs are probed. Signed-off-by: Zhang Zheng Co-developed-by: Ronaldo Nunez Signed-off-by: Ronaldo Nunez --- xen/drivers/char/ns16550.c | 23 ++++++++++++++++++----- xen/include/xen/8250-uart.h | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c index be388c8e6582ec7f28a5926baae2c397fc984e77..01a55d2737d18b1985ba10488e9= 8ac82ef8a9c8c 100644 --- a/xen/drivers/char/ns16550.c +++ b/xen/drivers/char/ns16550.c @@ -64,6 +64,7 @@ static struct ns16550 { bool intr_works; bool force_polling; bool dw_usr_bsy; + bool xscale; #ifdef NS16550_PCI /* PCI card parameters. */ bool pb_bdf_enable; /* if =3D1, pb-bdf effective, port behind brid= ge */ @@ -168,6 +169,15 @@ static void ns_write_reg(const struct ns16550 *uart, u= nsigned int reg, u8 c) } } =20 +static void ns_write_ier(const struct ns16550 *uart, u8 ier) +{ + /* XScale-like UART IP depends on the UUE bit being set */ + if ( uart->xscale ) + ier |=3D UART_IER_UUE; + + ns_write_reg(uart, UART_IER, ier); +} + static int ns16550_ioport_invalid(struct ns16550 *uart) { return ns_read_reg(uart, UART_IER) =3D=3D 0xff; @@ -218,7 +228,7 @@ static void cf_check ns16550_interrupt(int irq, void *d= ev_id) =20 /* Disable interrupt generation on the device and arm the time= r. */ uart->force_polling =3D true; - ns_write_reg(uart, UART_IER, 0); + ns_write_ier(uart, 0); set_timer(&uart->timer, now + MILLISECS(uart->timeout_ms)); printk(XENLOG_WARNING "uart interrupt taking more than %ums, switched to poll= ing\n", @@ -350,7 +360,7 @@ static void ns16550_setup_preirq(struct ns16550 *uart) lcr =3D (uart->data_bits - 5) | ((uart->stop_bits - 1) << 2) | uart->p= arity; =20 /* No interrupts. */ - ns_write_reg(uart, UART_IER, 0); + ns_write_ier(uart, 0); =20 /* Handle the DesignWare 8250 'busy-detect' quirk. */ handle_dw_usr_busy_quirk(uart); @@ -446,7 +456,7 @@ static void ns16550_setup_postirq(struct ns16550 *uart) UART_MCR, UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS= ); =20 /* Enable receive interrupts. */ - ns_write_reg(uart, UART_IER, UART_IER_ERDAI); + ns_write_ier(uart, UART_IER_ERDAI); } =20 if ( uart->irq >=3D 0 ) @@ -654,7 +664,7 @@ static void cf_check ns16550_start_tx(struct serial_por= t *port) =20 /* Unmask transmit holding register empty interrupt if currently maske= d. */ if ( !(ier & UART_IER_ETHREI) ) - ns_write_reg(uart, UART_IER, ier | UART_IER_ETHREI); + ns_write_ier(uart, ier | UART_IER_ETHREI); } =20 static void cf_check ns16550_stop_tx(struct serial_port *port) @@ -664,7 +674,7 @@ static void cf_check ns16550_stop_tx(struct serial_port= *port) =20 /* Mask off transmit holding register empty interrupt if currently unm= asked. */ if ( ier & UART_IER_ETHREI ) - ns_write_reg(uart, UART_IER, ier & ~UART_IER_ETHREI); + ns_write_ier(uart, ier & ~UART_IER_ETHREI); } =20 #ifdef CONFIG_ARM @@ -2034,6 +2044,8 @@ static int __init ns16550_uart_dt_init(struct dt_devi= ce_node *dev, =20 uart->dw_usr_bsy =3D dt_device_is_compatible(dev, "snps,dw-apb-uart"); =20 + uart->xscale =3D dt_device_is_compatible(dev, "intel,xscale-uart"); + #ifdef CONFIG_ARM uart->vuart.base_addr =3D uart->io_base; uart->vuart.size =3D uart->io_size; @@ -2055,6 +2067,7 @@ static const struct dt_device_match ns16550_dt_match[= ] __initconst =3D DT_MATCH_COMPATIBLE("ns16550"), DT_MATCH_COMPATIBLE("ns16550a"), DT_MATCH_COMPATIBLE("snps,dw-apb-uart"), + DT_MATCH_COMPATIBLE("intel,xscale-uart"), DT_MATCH_COMPATIBLE("brcm,bcm2835-aux-uart"), { /* sentinel */ }, }; diff --git a/xen/include/xen/8250-uart.h b/xen/include/xen/8250-uart.h index d13352940c13c50bac17d4cdf2f3bf584380776a..a9b567cb2e0cf00dc4804251824= e07a00ea9e022 100644 --- a/xen/include/xen/8250-uart.h +++ b/xen/include/xen/8250-uart.h @@ -42,6 +42,7 @@ #define UART_IER_ETHREI 0x02 /* tx reg. empty */ #define UART_IER_ELSI 0x04 /* rx line status */ #define UART_IER_EMSI 0x08 /* MODEM status */ +#define UART_IER_UUE 0x40 /* UART unit enable (XScale) */ =20 /* Interrupt Identification Register */ #define UART_IIR_NOINT 0x01 /* no interrupt pending */ --=20 2.53.0 From nobody Thu Nov 26 11:35:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=baylibre.com ARC-Seal: i=1; a=rsa-sha256; t=1795544576; cv=none; d=zohomail.com; s=zohoarc; b=BtY1r27Mpeko3D52+VnAviF49MW9P0v2eNAb0QYeuohVqKmRTNCXFS0OSbDawansiLlyExcNJmMLL99IeSZZ5KwTBjrCncwO3ic74JEefYhZ4BvfHk3Zc6M5PjbANXSfIce91eAT6iKNORGDeZt5H4O8GZozpOEAE+eE4rnKoRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795544576; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sWRLgfQRkqBL4w9rJ+jG6ILf7KQHCHvGFt9ZwCqlp9g=; b=Yp+KcipHi79eU9OxVLpwIrM/RsjK6xnMmixaeWVRA1Ot2WnUICk9jA1mjr0c6enu8CBWPWnQma1zILHNsp2a08zdaGyiaMC8UaEuUwkVIlEwSOB6FCETRqbdo7LcHdOUNalPRamF2K+v+W4bXhzpTTYZ7VpVlBVk2xk0F4ZrEN0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1795544576229717.5034677854347; Tue, 24 Nov 2026 10:22:56 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1501388.1697493 (Exim 4.92) (envelope-from ) id 1xVvA6-0005t0-3z; Tue, 24 Nov 2026 18:22:38 +0000 Received: by outflank-mailman (output) from mailman id 1501388.1697493; Tue, 24 Nov 2026 18:22:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xVvA5-0005sL-V1; Tue, 24 Nov 2026 18:22:37 +0000 Received: by outflank-mailman (input) for mailman id 1501388; Tue, 24 Nov 2026 17:32:01 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xVuN7-00051a-7r for xen-devel@lists.xenproject.org; Tue, 24 Nov 2026 17:32:01 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xVuN6-004J7s-Kc for xen-devel@lists.xenproject.org; Tue, 24 Nov 2026 18:32:00 +0100 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b05ca04-bab6-0a2a0a5309dd-0a2a450ccea6-30 for ; Tue, 24 Nov 2026 18:32:00 +0100 Received: from [209.85.160.178] (helo=mail-qt1-f178.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b05ca0f-f479-0a2a450c0019-d155a0b2a465-3 for ; Tue, 24 Nov 2026 18:32:00 +0100 Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-53639b8903bso58493131cf.0 for ; Tue, 24 Nov 2026 09:32:00 -0800 (PST) Received: from [127.0.0.1] ([2804:7f0:7543:4532:5471:ddc9:4fc9:5]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5ee8b6641d6sm14760703e0c.17.2026.11.24.09.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 09:31:47 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=baylibre.com header.i="@baylibre.com" header.h="Cc:To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre.com; s=google; t=1795541519; x=1796146319; darn=lists.xenproject.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=sWRLgfQRkqBL4w9rJ+jG6ILf7KQHCHvGFt9ZwCqlp9g=; b=ihgR9sv9uk5lWyOUcf7JWvHcrMIESYvNvUnHuxRjv85/Pn4jAYN1IqzHfPDhcVq02t 1dkV+qVXpZ92M0MjyK1AbRh5o8Vq+e7B7SQ/aPaCRPsWIW81geMtu1PzrwDXDUFQgNe3 YvfSVtJI/JVrO2y+GZyNuFVhTb8SJEcddB/3tVS6+gKMwSxKihWO6ekfvfIf+vT7JjE7 TwlFWccDYTjo8dEcy6T/A6TxvPVQIl2ZMq77A+Xg0HipSkj0+GC5TVG/7+0IjSpJ8LTe Nhd8W2vNJljrTx2pecJBCcRn7gzReam4L1UC8UKbDoTDGBW2Gnpe5HK8OchbCTR/d/NU P7gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795541519; x=1796146319; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=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zzQeTn7kh0JKyfe3m3B3zG5xnvGMcFkd5T12BFuU0PgOfiiFPu11yl/a3xkcLV1Ih khj+j/nAZatyj7zPb2+z/xmfFw== X-Received: by 2002:a05:6122:4681:b0:5e9:6d96:a7cc with SMTP id 71dfb90a1353d-5ee8af52ee6mr5666070e0c.9.1795541507974; Tue, 24 Nov 2026 09:31:47 -0800 (PST) From: Ronaldo Nunez Date: Tue, 24 Nov 2026 14:30:55 -0300 Subject: [PATCH v4 2/2] xen/ns16550: drain TX before reinitializing UART MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261124-v4-uart-harndover-v4-2-90c4412cb95e@baylibre.com> References: <20261124-v4-uart-harndover-v4-0-90c4412cb95e@baylibre.com> In-Reply-To: <20261124-v4-uart-harndover-v4-0-90c4412cb95e@baylibre.com> To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Zhang Zheng , Ronaldo Nunez X-Mailer: b4 0.14.2 X-purgate-ID: tlsNG-d25034/1795541520-018C5A5B-8DD06CB0/0/0 X-purgate-type: clean X-purgate-size: 1981 X-ZohoMail-DKIM: pass (identity @baylibre.com) X-ZM-MESSAGEID: 1795544578499047901 From: Zhang Zheng Drain pending output before resetting FIFOs. Bound the wait to avoid hanging boot if the UART never reports empty. Wait for TEMT (which already implies THRE on a 16550) to ensure transmission has finished before reconfiguration. uart->lsr_mask normally checks only THRE, which indicates room for more output. Signed-off-by: Zhang Zheng Co-developed-by: Ronaldo Nunez Signed-off-by: Ronaldo Nunez --- xen/drivers/char/ns16550.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c index 01a55d2737d18b1985ba10488e98ac82ef8a9c8c..6ac5e7c97c446ef2fe8122bc4ed= 4f368072450ed 100644 --- a/xen/drivers/char/ns16550.c +++ b/xen/drivers/char/ns16550.c @@ -411,6 +411,12 @@ static void ns16550_setup_preirq(struct ns16550 *uart) static void __init cf_check ns16550_init_preirq(struct serial_port *port) { struct ns16550 *uart =3D port->uart; + cycles_t start; + /* + * Assume system time counters (CSR for RISC-V and CNTPCT for ARM) run= ning + * at 50MHz and waits for 50 million ticks (~1-5s on typical hardware). + */ + cycles_t timeout_ticks =3D 50ULL * 1000 * 1000; =20 #ifdef CONFIG_HAS_IOPORTS /* I/O ports are distinguished by their size (16 bits). */ @@ -428,6 +434,15 @@ static void __init cf_check ns16550_init_preirq(struct= serial_port *port) #endif } =20 + /* + * Drain firmware/early-console output before changing line settings or + * resetting FIFOs. Wait for TEMT so the shift register is empty too. + */ + start =3D get_cycles(); + while ( !(ns_read_reg(uart, UART_LSR) & UART_LSR_TEMT) && + get_cycles() - start < timeout_ticks ) + cpu_relax(); + ns16550_setup_preirq(uart); =20 /* Check this really is a 16550+. Otherwise we have no FIFOs. */ --=20 2.53.0