From nobody Sun Mar 22 15:46:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1773962790; cv=none; d=zohomail.com; s=zohoarc; b=FpOk21l3oFvynXbjwDiTzRkx309WiF8CWKwGHKh8SU4D6WOkbc/VGjErEa3mrmmQVCKchfM+kWr+5orw5Exm8/WE5FUsVTivWgtc5p7F2/Xx0xpxFm4V5wIhlC1jbcd2ekrSiBfUetVvadHVz8dhNoIV304bofFyo0472EXMQIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773962790; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FSL75QHFg495FNiNbzzE12kqDvsWACd2HsK7ER6Leyc=; b=gFsLHkmmVtwnw/4it4EGBUlZioI7ZITSzNkC3yMo1Zu6ICKEqNkbgjlQ4ZBEI/mQqrYeZwe1EJBUpkbdp6EVsfVHY1UgB9cIk3sh2Hrk6X0323I1g2woMc1Ub+yxtxdS6axh+e5agaEhc70ZlXKCA3paY/l7Vsv39yKZ1QMTWc8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177396279009175.43643021659989; Thu, 19 Mar 2026 16:26:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w3Mkt-0000sI-Kq; Thu, 19 Mar 2026 19:26:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w3Mks-0000rw-B3 for qemu-devel@nongnu.org; Thu, 19 Mar 2026 19:26:18 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w3Mkq-0007hS-Nt for qemu-devel@nongnu.org; Thu, 19 Mar 2026 19:26:18 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-c742824e1d3so527095a12.1 for ; Thu, 19 Mar 2026 16:26:16 -0700 (PDT) Received: from toolbx.alistair23.me ([2403:581e:fdf9:0:6209:4521:6813:45b7]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b083516ae1sm2979165ad.13.2026.03.19.16.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 16:26:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773962775; x=1774567575; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FSL75QHFg495FNiNbzzE12kqDvsWACd2HsK7ER6Leyc=; b=FjrpJeY9+0uUzdRhftlTXkqY/cM+h0O5uirNpTcXuApnpPd6usix6BNnJnKprM0xqB 8c4Xi43FCr685lxnmZfDsod4Sb9B6alDkKseVKJ3muD2fsaRhCqcwpqxUMUgP3D9/FXL QgpMOaoKV//4W460eRUidChQvwD7BF7A0rSSFnCQc3D1LnuGRhePbzcPEHmH56EUHSvc OERhDjDcTMYUigW4XvANmsVleFkJDKdI7VK0R31w8E/62VQze4e0ZekdqFxZrGmqTGd+ hPkQkxEiSFQNMgGv7Hyv6Q5aIlGRHAm7cw4RWjTQxLIBqjB+lFfDBiQd0iOqYpxcivU7 lBZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773962775; x=1774567575; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=FSL75QHFg495FNiNbzzE12kqDvsWACd2HsK7ER6Leyc=; b=m034fHQDkVVisdph5ESxJMXNyxKXeOWIgjsm/WPhuBCPbdWpiWo56dKkm+6WB9pd8W lph458+tK899cmnrI5rEo2ewDUMl/dusJ35/9Ssu1dmbsVMqpk8k50AneaZlM7ICawLU PqncoVga6XqU8VGgcqyAX2aSwXrgntJ/IQxohy++aph/R7KbFkyA0AAuI0dWATr3O0Ul yqqaLLYT5afYo5kH7RmhGERg5c+ho9ImTAYgMZlQz5RweMGNHLFdQedrWlNt3FUkvhZv bCI85Ze71EIKCZIscxJtUPTC+DMK6BNxvconSiCQIm4mmMgTMuIk4iUBbveX14u/VMw5 a8Hw== X-Gm-Message-State: AOJu0YwmFJT7lQB7XLEfxnk4pLTDRmR+ghWRhogEMxNfRtWgYJvAT5p0 IJ8m5w19t3FjWghDAOZ+a98Y5hcbg1nlI2cTTRone15KGrVYY+uU8HZXBK0LRw== X-Gm-Gg: ATEYQzzFFye6EXzVqbB7xY61oKWMKips5ct62zPN2rQwtDZJoHluGODq8xyy9TorFyW +oPDC7iMKne8A/dU3bAxW6+DXydXRN/FetvcZ+A3A/WmhyfcG3Pig2N8Ej8e476uk820qi5w8yM 0ptsXdmz/QWc4UxgJoNH5Au2jIKAPQzrmIrQFEUN6LbL9UKbdz6F/4amK2tD1Ne7PV1KrZ6bbcK BN+W9T9K0aKwxx2SdnJmCmdbyf53nAU3dai74/vEy4Fy3HhspPg8AO2HgDIdAEJJZCUJHVLViY4 xENm2OlbQE20N56JJI92tfyJjc7rwshco/5ukwsiMg8nXC46F48nKVzvToRU0pH8tebXFMAUjAY jKWXPcnqxtfFSBWAv842DVAK8WwGdn7IoHFiQHiiwVBK0ipmpfBeriFsZ4ihgPtpbj0ZXmqv1Iu 9iZ4Wm+hOfTzj969gOryJcwC82DOHDulkDabD22YYKInunEVtMGuJ+ X-Received: by 2002:a17:903:2449:b0:2b0:5ec1:97c1 with SMTP id d9443c01a7336-2b0827107e7mr9200765ad.7.1773962774647; Thu, 19 Mar 2026 16:26:14 -0700 (PDT) From: alistair23@gmail.com X-Google-Original-From: alistair.francis@wdc.com To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Frank Chang , Alistair Francis Subject: [PULL 11/17] hw/char: sifive_uart: Implement txctrl.txen and rxctrl.rxen Date: Fri, 20 Mar 2026 09:25:16 +1000 Message-ID: <20260319232522.1867400-12-alistair.francis@wdc.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260319232522.1867400-1-alistair.francis@wdc.com> References: <20260319232522.1867400-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=alistair23@gmail.com; helo=mail-pg1-x531.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1773962791971158500 Content-Type: text/plain; charset="utf-8" From: Frank Chang Implement txctrl.txen and rxctrl.rxen as follows: * txctrl.txen The txen bit controls whether the Tx channel is active. When cleared, transmission of Tx FIFO contents is suppressed, and the txd pin is driven high. * rxctrl.rxen: The rxen bit controls whether the Rx channel is active. When cleared, the state of the rxd pin is ignored, and no characters will be enqueued into the Rx FIFO. Therefore, the Tx FIFO should not be dequeued when txctrl.txen is cleared, and the Rx FIFO should not be enqueued when rxctrl.rxen is cleared. Signed-off-by: Frank Chang Reviewed-by: Alistair Francis Message-ID: <20260312033201.1619554-2-frank.chang@sifive.com> Signed-off-by: Alistair Francis --- include/hw/char/sifive_uart.h | 2 ++ hw/char/sifive_uart.c | 27 ++++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/hw/char/sifive_uart.h b/include/hw/char/sifive_uart.h index 414564b026..c78d9bd1fc 100644 --- a/include/hw/char/sifive_uart.h +++ b/include/hw/char/sifive_uart.h @@ -51,6 +51,8 @@ enum { =20 #define SIFIVE_UART_TXFIFO_FULL 0x80000000 =20 +#define SIFIVE_UART_TXEN(txctrl) (txctrl & 0x1) +#define SIFIVE_UART_RXEN(rxctrl) (rxctrl & 0x1) #define SIFIVE_UART_GET_TXCNT(txctrl) ((txctrl >> 16) & 0x7) #define SIFIVE_UART_GET_RXCNT(rxctrl) ((rxctrl >> 16) & 0x7) =20 diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c index af17cf9a6c..3ce6a4ee76 100644 --- a/hw/char/sifive_uart.c +++ b/hw/char/sifive_uart.c @@ -78,6 +78,11 @@ static gboolean sifive_uart_xmit(void *do_not_use, GIOCo= ndition cond, return G_SOURCE_REMOVE; } =20 + /* Don't pop the FIFO if transmit is disabled. */ + if (!SIFIVE_UART_TXEN(s->txctrl)) { + return G_SOURCE_REMOVE; + } + /* Don't pop the FIFO in case the write fails */ characters =3D fifo8_peek_bufptr(&s->tx_fifo, fifo8_num_used(&s->tx_fifo), &numptr); @@ -106,11 +111,19 @@ static gboolean sifive_uart_xmit(void *do_not_use, GI= OCondition cond, return G_SOURCE_REMOVE; } =20 -static void sifive_uart_write_tx_fifo(SiFiveUARTState *s, const uint8_t *b= uf, - int size) +static void sifive_uart_trigger_tx_fifo(SiFiveUARTState *s) { uint64_t current_time =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); =20 + if (!timer_pending(s->fifo_trigger_handle)) { + timer_mod(s->fifo_trigger_handle, current_time + + TX_INTERRUPT_TRIGGER_DELAY_NS); + } +} + +static void sifive_uart_write_tx_fifo(SiFiveUARTState *s, const uint8_t *b= uf, + int size) +{ if (size > fifo8_num_free(&s->tx_fifo)) { size =3D fifo8_num_free(&s->tx_fifo); qemu_log_mask(LOG_GUEST_ERROR, "sifive_uart: TX FIFO overflow.\n"); @@ -124,10 +137,7 @@ static void sifive_uart_write_tx_fifo(SiFiveUARTState = *s, const uint8_t *buf, s->txfifo |=3D SIFIVE_UART_TXFIFO_FULL; } =20 - if (!timer_pending(s->fifo_trigger_handle)) { - timer_mod(s->fifo_trigger_handle, current_time + - TX_INTERRUPT_TRIGGER_DELAY_NS); - } + sifive_uart_trigger_tx_fifo(s); } =20 static uint64_t @@ -184,6 +194,9 @@ sifive_uart_write(void *opaque, hwaddr addr, return; case SIFIVE_UART_TXCTRL: s->txctrl =3D val64; + if (SIFIVE_UART_TXEN(s->txctrl) && !fifo8_is_empty(&s->tx_fifo)) { + sifive_uart_trigger_tx_fifo(s); + } return; case SIFIVE_UART_RXCTRL: s->rxctrl =3D val64; @@ -231,7 +244,7 @@ static int sifive_uart_can_rx(void *opaque) { SiFiveUARTState *s =3D opaque; =20 - return s->rx_fifo_len < sizeof(s->rx_fifo); + return SIFIVE_UART_RXEN(s->rxctrl) && (s->rx_fifo_len < sizeof(s->rx_f= ifo)); } =20 static void sifive_uart_event(void *opaque, QEMUChrEvent event) --=20 2.53.0