From nobody Sun May 19 09:23:51 2024 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=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1673993238; cv=none; d=zohomail.com; s=zohoarc; b=hyjOuzEctj4DXelTDKI9BP8jH3HOoLRJF3EHfZolRGFMguNmgzfESi/JoVHXWOo/pENwOmykQsDU6e/hZ4+nWIwypmZw9jDbO8d+ZJre+lNj5JOT9knAiEP4fnSALRgb0UYiyjH8oDPGpu0deNM7wfFpHQackaQDEamARBGj+4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673993238; 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=tOFYsve5o6d8zTAgtdtirQp+zyHt7PERoMWWbpIlYIw=; b=GE+yf+wgtKQ8HXno1GfjqNNEpuRCcniM2IYEHkuicsSWzXQbQuS3CAyciU5TWX6v6g6CxbvfP4WJn3O09VcElhPZ10ST8w4IkQNW5zLhxuXl6HGomAzCqa5SKsirvkHliZ+fInrAkVIcWq90NCEE4r3WXcsU4UNwFEBD1zC7gjc= 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 1673993238330606.978008518812; Tue, 17 Jan 2023 14:07:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHu5O-0003eK-1W; Tue, 17 Jan 2023 17:05:42 -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 1pHu5J-0003d3-Kn; Tue, 17 Jan 2023 17:05:40 -0500 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHu5F-0006qr-0s; Tue, 17 Jan 2023 17:05:35 -0500 Received: from localhost.localdomain (unknown [77.64.253.186]) by linux.microsoft.com (Postfix) with ESMTPSA id 5CF6420E09E3; Tue, 17 Jan 2023 14:05:30 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5CF6420E09E3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1673993131; bh=tOFYsve5o6d8zTAgtdtirQp+zyHt7PERoMWWbpIlYIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KVFH5fSL8Du2JleVnKPWn+VxA1MEwJd2IhCsf6fLewVMFRKt8wY3bHsevh3HeepEy nJ+HUGAdrJSM3L4PyESjIAo280Nn13rJC29tn1diQ8cdZnGuiMgRwcoofPAO04bbnK +wfnivom0oKaqxinS4EN8NhIq6iNk0hICv+5PdWw= From: Evgeny Iakovlev To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v2 1/4] hw/char/pl011: refactor FIFO depth handling code Date: Tue, 17 Jan 2023 23:05:20 +0100 Message-Id: <20230117220523.20911-2-eiakovlev@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230117220523.20911-1-eiakovlev@linux.microsoft.com> References: <20230117220523.20911-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+importer=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1673993240295100007 Content-Type: text/plain; charset="utf-8" PL011 can be in either of 2 modes depending guest config: FIFO and single register. The last mode could be viewed as a 1-element-deep FIFO. Current code open-codes a bunch of depth-dependent logic. Refactor FIFO depth handling code to isolate calculating current FIFO depth. One functional (albeit guest-invisible) side-effect of this change is that previously we would always increment s->read_pos in UARTDR read handler even if FIFO was disabled, now we are limiting read_pos to not exceed FIFO depth (read_pos itself is reset to 0 if user disables FIFO). Signed-off-by: Evgeny Iakovlev --- hw/char/pl011.c | 25 +++++++++++++------------ include/hw/char/pl011.h | 5 ++++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index c076813423..329cc6926d 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -81,6 +81,12 @@ static void pl011_update(PL011State *s) } } =20 +static inline unsigned pl011_get_fifo_depth(PL011State *s) +{ + /* Note: FIFO depth is expected to be power-of-2 */ + return s->lcr & 0x10 ? PL011_FIFO_DEPTH : 1; +} + static uint64_t pl011_read(void *opaque, hwaddr offset, unsigned size) { @@ -94,8 +100,7 @@ static uint64_t pl011_read(void *opaque, hwaddr offset, c =3D s->read_fifo[s->read_pos]; if (s->read_count > 0) { s->read_count--; - if (++s->read_pos =3D=3D 16) - s->read_pos =3D 0; + s->read_pos =3D (s->read_pos + 1) & (pl011_get_fifo_depth(s) -= 1); } if (s->read_count =3D=3D 0) { s->flags |=3D PL011_FLAG_RXFE; @@ -273,11 +278,7 @@ static int pl011_can_receive(void *opaque) PL011State *s =3D (PL011State *)opaque; int r; =20 - if (s->lcr & 0x10) { - r =3D s->read_count < 16; - } else { - r =3D s->read_count < 1; - } + r =3D s->read_count < pl011_get_fifo_depth(s); trace_pl011_can_receive(s->lcr, s->read_count, r); return r; } @@ -286,15 +287,15 @@ static void pl011_put_fifo(void *opaque, uint32_t val= ue) { PL011State *s =3D (PL011State *)opaque; int slot; + unsigned pipe_depth; =20 - slot =3D s->read_pos + s->read_count; - if (slot >=3D 16) - slot -=3D 16; + pipe_depth =3D pl011_get_fifo_depth(s); + slot =3D (s->read_pos + s->read_count) & (pipe_depth - 1); s->read_fifo[slot] =3D value; s->read_count++; s->flags &=3D ~PL011_FLAG_RXFE; trace_pl011_put_fifo(value, s->read_count); - if (!(s->lcr & 0x10) || s->read_count =3D=3D 16) { + if (s->read_count =3D=3D pipe_depth) { trace_pl011_put_fifo_full(); s->flags |=3D PL011_FLAG_RXFF; } @@ -359,7 +360,7 @@ static const VMStateDescription vmstate_pl011 =3D { VMSTATE_UINT32(dmacr, PL011State), VMSTATE_UINT32(int_enabled, PL011State), VMSTATE_UINT32(int_level, PL011State), - VMSTATE_UINT32_ARRAY(read_fifo, PL011State, 16), + VMSTATE_UINT32_ARRAY(read_fifo, PL011State, PL011_FIFO_DEPTH), VMSTATE_UINT32(ilpr, PL011State), VMSTATE_UINT32(ibrd, PL011State), VMSTATE_UINT32(fbrd, PL011State), diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h index dc2c90eedc..926322e242 100644 --- a/include/hw/char/pl011.h +++ b/include/hw/char/pl011.h @@ -27,6 +27,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(PL011State, PL011) /* This shares the same struct (and cast macro) as the base pl011 device */ #define TYPE_PL011_LUMINARY "pl011_luminary" =20 +/* Depth of UART FIFO in bytes, when FIFO mode is enabled (else depth =3D= =3D 1) */ +#define PL011_FIFO_DEPTH 16 + struct PL011State { SysBusDevice parent_obj; =20 @@ -39,7 +42,7 @@ struct PL011State { uint32_t dmacr; uint32_t int_enabled; uint32_t int_level; - uint32_t read_fifo[16]; + uint32_t read_fifo[PL011_FIFO_DEPTH]; uint32_t ilpr; uint32_t ibrd; uint32_t fbrd; --=20 2.34.1 From nobody Sun May 19 09:23:51 2024 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=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1673993210; cv=none; d=zohomail.com; s=zohoarc; b=UYgtzxtPrTeloGyHfW5GYedQgY0um7vTRBOaQZJO8VsPXrKDbe2d+vxPMr+xfSCafIM41pa0ahzsNEs6Yn5tL/FbyNE/k5kYvHbY2zkhPQFNaFRsKckg8i+O+796NbwE5mNeA164e0zJJKYW4Rtr0DhP8A5U6V7PstzX88MJtW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673993210; 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=yXi+mt++/YFlHhcyEovyhSOK0vSYyDtMhazv/ZJw/O0=; b=gL9ofCkG0dWGGxN9AqfUDq5xzdAsf1RAPEcMQhZ2n/smze3rjSPn+RZ2V/JShwG+ECA+CC5xhmk5jBLUd8Au2cMBECMU17q4xQ7XmBG57geZSrMu+zZMntV03rGQPXPdMtz6mkr31eK/1ZAnMovR2PYOplTRCjF+iLjxCkEjyhk= 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 167399321060271.75662125701763; Tue, 17 Jan 2023 14:06:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHu5S-0003gC-5P; Tue, 17 Jan 2023 17:05:46 -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 1pHu5J-0003d2-3w; Tue, 17 Jan 2023 17:05:40 -0500 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHu5G-0006rS-3o; Tue, 17 Jan 2023 17:05:35 -0500 Received: from localhost.localdomain (unknown [77.64.253.186]) by linux.microsoft.com (Postfix) with ESMTPSA id A266220E09E4; Tue, 17 Jan 2023 14:05:31 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A266220E09E4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1673993132; bh=yXi+mt++/YFlHhcyEovyhSOK0vSYyDtMhazv/ZJw/O0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yf5mtcSjvn1CL0SvzOuDPtoTJ2Ku8NIeEi+v5VWtizzA3RLTQopUIG/P6X2mq6BmV njetrVVF2OF4EO+eFnXuDTx6iZ/RLm2aOWHVFANkv4ASQyRhAUDAJN0RWViqTQlIOV BGIG8wvqDqQxYGP4cDsXIoCjMAJAu48WDmxb/h/Q= From: Evgeny Iakovlev To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v2 2/4] hw/char/pl011: implement a reset method Date: Tue, 17 Jan 2023 23:05:21 +0100 Message-Id: <20230117220523.20911-3-eiakovlev@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230117220523.20911-1-eiakovlev@linux.microsoft.com> References: <20230117220523.20911-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+importer=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1673993212121100003 Content-Type: text/plain; charset="utf-8" PL011 currently lacks a reset method. Implement it. Signed-off-by: Evgeny Iakovlev Reviewed-by: Peter Maydell --- hw/char/pl011.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 329cc6926d..404d52a3b8 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -397,11 +397,6 @@ static void pl011_init(Object *obj) s->clk =3D qdev_init_clock_in(DEVICE(obj), "clk", pl011_clock_update, = s, ClockUpdate); =20 - s->read_trigger =3D 1; - s->ifl =3D 0x12; - s->cr =3D 0x300; - s->flags =3D 0x90; - s->id =3D pl011_id_arm; } =20 @@ -413,11 +408,37 @@ static void pl011_realize(DeviceState *dev, Error **e= rrp) pl011_event, NULL, s, NULL, true); } =20 +static void pl011_reset(DeviceState *dev) +{ + PL011State *s =3D PL011(dev); + int i; + + s->lcr =3D 0; + s->rsr =3D 0; + s->dmacr =3D 0; + s->int_enabled =3D 0; + s->int_level =3D 0; + 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; + + for (i =3D 0; i < ARRAY_SIZE(s->irq); i++) { + qemu_irq_lower(s->irq[i]); + } +} + static void pl011_class_init(ObjectClass *oc, void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); =20 dc->realize =3D pl011_realize; + dc->reset =3D pl011_reset; dc->vmsd =3D &vmstate_pl011; device_class_set_props(dc, pl011_properties); } --=20 2.34.1 From nobody Sun May 19 09:23:51 2024 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=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1673993244; cv=none; d=zohomail.com; s=zohoarc; b=VWptFqtptZKZw9b/wAQ08YTZRvlHLXLXPv9pI3HR2zfQ/XHpJac09Hw0h+MVQiBhkRJdjsfNqZaJMMGildtbuhTtk2JrpB5G0tjugd/BJ1NxzwVy0VI+lTy9yniabKu3aH2yHuYdcOT4VrsH7Cw/l7+dLqe7qXHkGlSTb4cIq/k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673993244; 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=9TKsC6maeKp1zioEdXA9ySTOmT+xAgkJ3WU17vpuzeo=; b=i2EZfAnzHd3B/Y0guUPtnaSpNVMhYOL/0jymH7QwRD9xC85JNcYX20ffLNm4BrO/jX8nu18I7a3Gs5ShKh5p/E1I8MWP5YaFZRpHoNP400d7gftvAIoappEVVrqxYuEWaXFXU/yG5K/WS+gSaSYvNE+9xBvuPTV48ljy+AJN4cg= 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 167399324417043.70769641024128; Tue, 17 Jan 2023 14:07:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHu5O-0003eJ-1J; Tue, 17 Jan 2023 17:05:42 -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 1pHu5K-0003d4-Be; Tue, 17 Jan 2023 17:05:40 -0500 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHu5H-0006sY-1R; Tue, 17 Jan 2023 17:05:37 -0500 Received: from localhost.localdomain (unknown [77.64.253.186]) by linux.microsoft.com (Postfix) with ESMTPSA id E7C0420E09E5; Tue, 17 Jan 2023 14:05:32 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E7C0420E09E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1673993133; bh=9TKsC6maeKp1zioEdXA9ySTOmT+xAgkJ3WU17vpuzeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pEMhK14xP8LBx4sIozuD4Ek44Qc5tNjiR2g0KQSEMUSEiOJoHnnkpik8qJ7kXRVZS 33N8ai23b4CwC25o9zVTf21lrfde9RS2zPor0f9+3/vpW2x7HcmVM0byQ6vYBUxS/F D2qrk5mrQpWCBMVJguiVL4knBLsbTOVqu7N1nlb8= From: Evgeny Iakovlev To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v2 3/4] hw/char/pl011: better handling of FIFO flags on LCR reset Date: Tue, 17 Jan 2023 23:05:22 +0100 Message-Id: <20230117220523.20911-4-eiakovlev@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230117220523.20911-1-eiakovlev@linux.microsoft.com> References: <20230117220523.20911-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+importer=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1673993246317100001 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 --- hw/char/pl011.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 404d52a3b8..3184949d69 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -87,6 +87,13 @@ static inline unsigned pl011_get_fifo_depth(PL011State *= s) return s->lcr & 0x10 ? PL011_FIFO_DEPTH : 1; } =20 +static inline void pl011_reset_pipe(PL011State *s) +{ + s->read_count =3D 0; + s->read_pos =3D 0; + s->flags =3D PL011_FLAG_RXFE | PL011_FLAG_TXFE; +} + static uint64_t pl011_read(void *opaque, hwaddr offset, unsigned size) { @@ -234,8 +241,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_pipe(s); } if ((s->lcr ^ value) & 0x1) { int break_enable =3D value & 0x1; @@ -421,12 +427,10 @@ 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; + pl011_reset_pipe(s); =20 for (i =3D 0; i < ARRAY_SIZE(s->irq); i++) { qemu_irq_lower(s->irq[i]); --=20 2.34.1 From nobody Sun May 19 09:23:51 2024 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=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1673993207; cv=none; d=zohomail.com; s=zohoarc; b=SfMMHTox/dB58hNNR92yy9UAX1VVoX7VFXkyWwLWv30oxoNnsMadx11ndLW2rDU8MRWB9Yr+pKTigrKgbBSG+10/dkaVm429LpDINT4tDTM0aFeO3j4Wuk9sdKBGfXTJS2AF5yLQLiwdLbPWujnjEaohjAbXYVjKp89rHxC96AM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673993207; 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=8xKBflc6IJYkTg6cf5JZjy/Tiro6yetQ/aEWtsvCihM=; b=QmfuPn6UM4Rls6DqM2Qr9dZceHu/KpKZIvnDenPkNniBJjFd/Rmi5UxBT32AxAf65sAjHy+aJ4o72UJiVUGEyDUR3Ck4Q1P9QNT+rzjv8nV6eHEB50FEZo0OCmWNswWVWIeWQbRBwPG3/qqIoE/ugNSZVlYHbzZS/11Fzo/ygs4= 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 1673993207162164.92287627223766; Tue, 17 Jan 2023 14:06:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHu5S-0003gT-Da; Tue, 17 Jan 2023 17:05:46 -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 1pHu5K-0003d5-SA; Tue, 17 Jan 2023 17:05:40 -0500 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHu5I-0006sj-Sd; Tue, 17 Jan 2023 17:05:38 -0500 Received: from localhost.localdomain (unknown [77.64.253.186]) by linux.microsoft.com (Postfix) with ESMTPSA id 35BA820E09E0; Tue, 17 Jan 2023 14:05:34 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 35BA820E09E0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1673993135; bh=8xKBflc6IJYkTg6cf5JZjy/Tiro6yetQ/aEWtsvCihM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xt/aqXpa9wKJUPWh4lt1zHEp4s3SPEftD0ldZx1km/3z50MkS+sVL9B3QTDG2bjIS pZQ5EZeoUiiLxBGLXKChtqHJQetU7PHZ9VNLtFjmiqW01aMnS5tYhSMTSYjt80T7U6 Ysa/53bQSZrXYoRCZbb1q3Vden2kAJzSI6hIJ3uY= From: Evgeny Iakovlev To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org Subject: [PATCH v2 4/4] hw/char/pl011: check if UART is enabled before RX or TX operation Date: Tue, 17 Jan 2023 23:05:23 +0100 Message-Id: <20230117220523.20911-5-eiakovlev@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230117220523.20911-1-eiakovlev@linux.microsoft.com> References: <20230117220523.20911-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+importer=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1673993208596100001 Content-Type: text/plain; charset="utf-8" UART should be enabled in general and have RX enabled specifically to be able to receive data from peripheral device. Same goes for transmitting data to peripheral device and a TXE flag. Check if UART CR register has EN and RXE or TXE bits enabled before trying to receive or transmit data. Signed-off-by: Evgeny Iakovlev Reviewed-by: Peter Maydell --- hw/char/pl011.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 3184949d69..522f36e4f3 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -54,6 +54,11 @@ #define INT_E (INT_OE | INT_BE | INT_PE | INT_FE) #define INT_MS (INT_RI | INT_DSR | INT_DCD | INT_CTS) =20 +/* UARTCR bits */ +#define PL011_CR_UARTEN (1 << 0) +#define PL011_CR_TXE (1 << 8) +#define PL011_CR_RXE (1 << 9) + static const unsigned char pl011_id_arm[8] =3D { 0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1 }; static const unsigned char pl011_id_luminary[8] =3D @@ -203,6 +208,11 @@ static void pl011_trace_baudrate_change(const PL011Sta= te *s) s->ibrd, s->fbrd); } =20 +static inline bool pl011_can_transmit(PL011State *s) +{ + return s->cr & PL011_CR_UARTEN && s->cr & PL011_CR_TXE; +} + static void pl011_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { @@ -213,7 +223,9 @@ static void pl011_write(void *opaque, hwaddr offset, =20 switch (offset >> 2) { case 0: /* UARTDR */ - /* ??? Check if transmitter is enabled. */ + if (!pl011_can_transmit(s)) { + break; + } ch =3D value; /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ @@ -284,7 +296,11 @@ static int pl011_can_receive(void *opaque) PL011State *s =3D (PL011State *)opaque; int r; =20 - r =3D s->read_count < pl011_get_fifo_depth(s); + if (!(s->cr & PL011_CR_UARTEN) || !(s->cr & PL011_CR_RXE)) { + r =3D 0; + } else { + r =3D s->read_count < pl011_get_fifo_depth(s); + } trace_pl011_can_receive(s->lcr, s->read_count, r); return r; } @@ -429,7 +445,7 @@ static void pl011_reset(DeviceState *dev) s->fbrd =3D 0; s->read_trigger =3D 1; s->ifl =3D 0x12; - s->cr =3D 0x300; + s->cr =3D PL011_CR_RXE | PL011_CR_TXE; pl011_reset_pipe(s); =20 for (i =3D 0; i < ARRAY_SIZE(s->irq); i++) { --=20 2.34.1