From nobody Mon Feb 9 20:30:58 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=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