From nobody Thu Jul 10 07:48:38 2025 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1674491031; cv=none; d=zohomail.com; s=zohoarc; b=O5r1/zMzvj9sPdAOomQuvUZIa28EkW1C5qzx07pOYlIdIwuStOWfJk7j8Lq2Eyw8VyJuACwiouyHwsLxQDzEBkK+QLPAfVUiLUQB1EiBeuMbrj9X0talq/mAVHvfYlKK3x4rNBZ87GzZwHUBYFP3D6KHk6zo/fy0W8zvxQHaF+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674491031; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=C+EScrM/BlF+L0aCDcrNncH4RADSJ3Df3ccUc0bOkbE=; b=BpT85L3dWuGeXhmZOxGMDujUBGMe7W0vCWP9zq50LmbubinR/1tCw/6ms5ip2VmIESxDOYrLRHAWi8Jq7S4kVRsjmjZQJW4DPbjEqLu/FyFV45/39N21mFBul3Ca4SRtGXYT/RqUHLL0LSf56ICE6pWUi+CT0sJ6YjQHWXQmnNE= 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+importer2=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 1674491031729285.38794912186904; Mon, 23 Jan 2023 08:23:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pJzbN-0007fJ-SH; Mon, 23 Jan 2023 11:23:21 -0500 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 1pJzbL-0007du-Aw; Mon, 23 Jan 2023 11:23:19 -0500 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pJzbJ-0003bQ-Ot; Mon, 23 Jan 2023 11:23:19 -0500 Received: from localhost.localdomain (unknown [77.64.253.114]) by linux.microsoft.com (Postfix) with ESMTPSA id 84FA320E1ABA; Mon, 23 Jan 2023 08:23:15 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 84FA320E1ABA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1674490996; bh=C+EScrM/BlF+L0aCDcrNncH4RADSJ3Df3ccUc0bOkbE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RDaN6vK0qainpzsagd4sNqdQLynkm5UKnpd1H35XSHJoEnz52H0A1dbSZRUmJxJzS sGVOQZ6kWUx3oP9lKzX0ii4qnJwdB+xZcHDk8mShWql+gJm51prxUPjDMorty++Qff xlm+U06kmDvhw4xURy7DFpysEqCCP8/oMdm6HElA= From: Evgeny Iakovlev To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, philmd@linaro.org Subject: [PATCH v4 4/5] hw/char/pl011: better handling of FIFO flags on LCR reset Date: Mon, 23 Jan 2023 17:23:03 +0100 Message-Id: <20230123162304.26254-5-eiakovlev@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123162304.26254-1-eiakovlev@linux.microsoft.com> References: <20230123162304.26254-1-eiakovlev@linux.microsoft.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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=eiakovlev@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -197 X-Spam_score: -19.8 X-Spam_bar: ------------------- X-Spam_report: (-19.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1674491033768100005 Content-Type: text/plain; charset="utf-8" Current FIFO handling code does not reset RXFE/RXFF flags when guest resets FIFO by writing to UARTLCR register, although internal FIFO state is reset to 0 read count. Actual guest-visible flag update will happen only on next data read or write attempt. As a result of that any guest that expects RXFE flag to be set (and RXFF to be cleared) after resetting FIFO will never see that happen. Signed-off-by: Evgeny Iakovlev Reviewed-by: Peter Maydell --- hw/char/pl011.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index ca7537d8ed..c15cb7af20 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -92,6 +92,16 @@ static inline unsigned pl011_get_fifo_depth(PL011State *= s) return pl011_is_fifo_enabled(s) ? PL011_FIFO_DEPTH : 1; } =20 +static inline void pl011_reset_fifo(PL011State *s) +{ + s->read_count =3D 0; + s->read_pos =3D 0; + + /* Reset FIFO flags */ + s->flags &=3D ~(PL011_FLAG_RXFF | PL011_FLAG_TXFF); + s->flags |=3D PL011_FLAG_RXFE | PL011_FLAG_TXFE; +} + static uint64_t pl011_read(void *opaque, hwaddr offset, unsigned size) { @@ -239,8 +249,7 @@ static void pl011_write(void *opaque, hwaddr offset, case 11: /* UARTLCR_H */ /* Reset the FIFO state on FIFO enable or disable */ if ((s->lcr ^ value) & 0x10) { - s->read_count =3D 0; - s->read_pos =3D 0; + pl011_reset_fifo(s); } if ((s->lcr ^ value) & 0x1) { int break_enable =3D value & 0x1; @@ -450,12 +459,11 @@ static void pl011_reset(DeviceState *dev) s->ilpr =3D 0; s->ibrd =3D 0; s->fbrd =3D 0; - s->read_pos =3D 0; - s->read_count =3D 0; s->read_trigger =3D 1; s->ifl =3D 0x12; s->cr =3D 0x300; - s->flags =3D 0x90; + s->flags =3D 0; + pl011_reset_fifo(s); } =20 static void pl011_class_init(ObjectClass *oc, void *data) --=20 2.34.1