From nobody Sun Feb 8 20:13:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629684635610112.8197912470165; Sun, 22 Aug 2021 19:10:35 -0700 (PDT) Received: from localhost ([::1]:33090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mHzQ2-0006q3-L4 for importer@patchew.org; Sun, 22 Aug 2021 22:10:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHzNz-0004Fd-Iv; Sun, 22 Aug 2021 22:08:27 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:42745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mHzNy-0005qL-16; Sun, 22 Aug 2021 22:08:27 -0400 Received: by mail-pg1-x535.google.com with SMTP id o2so15238732pgr.9; Sun, 22 Aug 2021 19:08:25 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id e26sm13804358pfj.46.2021.08.22.19.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Aug 2021 19:08:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rAAxJDG5E05zDmlgEF2APiVr8Kl3NTFeFkQ9Psjo6MM=; b=um7SXWrD0tpzrZQz81dLxIVYWGkKnOoxsPEhUERE9MmxztDGJ+d0UJbhfpJwbB8s6g Vo+ixF1syYf31WYKbei3RpryAsiWgRoPsez0W9F2W21Bm2xAV03C0toqSFf3WLOME7WT 8QrHLJ1ipl/AV7lBOQ37j2Nz2BXRH18Wmeg1klfX/AQH7iZhWwKv61P4YSwBfEdVOIbv T1Z9k2TkNHiwrDQStR0TzfFAzhFHXvBEIlI/NeNJVeNxPVCNheFFUhNHm2Hrt7e5gjAf h54lno37Jdj6hkiJ8nJGSVvHykDzFbk6EgadeMFEHlXwP8g2hsoIBwr956Z16k7ABY+C jApg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rAAxJDG5E05zDmlgEF2APiVr8Kl3NTFeFkQ9Psjo6MM=; b=SaFvA0BNcmoY7NgNUOxXJJ/BFFkn7wbF6srjEvsDkHiKNWxahNcWFOcFUkSxpmNc6s 0PpJ1T79QnjB7rHq55LAyUkwfisqngrpmeCUkigu4MobcuyS9sVJkUiEUKjig16dwwx7 IaGvBoOEYe1vRzrxWFGImTv1Gs80xRKUf6JDo4XFD/HpcMUUuqQG7vV4JnBmDlULAlXs bvTpr1s1v/bo+P4zMzNBWs2ABM2tiIqJnhbX/2qYVLLwbOz6QUwCQx5TwmSJto+SIlCV Bm0oeIRAU0p7c7gg4+doWNaDpeQ4RVvSGD1SKqex6y0B3H9yaambkN0/lRtBqgLai/Ud EVuw== X-Gm-Message-State: AOAM533dbfo4DON0rk5PlfwjhIhjp2beYFUA+1YhWW4jtQlZm97lsnh6 b+U5Gf1tcUAyIYmzqBHVfdk= X-Google-Smtp-Source: ABdhPJx41lEOoPQjqtrGTTXjtEEBjUTSLYDRGpqDMcmbjQeXsoIi37y1hzBagCz446Us5XxiHypJWg== X-Received: by 2002:a05:6a00:7cc:b029:3e0:e9f3:5835 with SMTP id n12-20020a056a0007ccb02903e0e9f35835mr30505595pfu.66.1629684504366; Sun, 22 Aug 2021 19:08:24 -0700 (PDT) From: Bin Meng To: Damien Hedde , "Edgar E . Iglesias" , Alistair Francis , Peter Maydell Subject: [PATCH 1/3] hw/misc: zynq_slcr: Correctly compute output clocks in the reset exit phase Date: Mon, 23 Aug 2021 10:08:11 +0800 Message-Id: <20210823020813.25192-2-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210823020813.25192-1-bmeng.cn@gmail.com> References: <20210823020813.25192-1-bmeng.cn@gmail.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::535; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1629684637392100001 Content-Type: text/plain; charset="utf-8" As of today, when booting upstream U-Boot for Xilinx Zynq, the UART does not receive anything. Debugging shows that the UART input clock frequency is zero which prevents the UART from receiving anything as per the logic in uart_receive(). From zynq_slcr_reset_exit() comment, it intends to compute output clocks according to ps_clk and registers. zynq_slcr_compute_clocks() is called to accomplish the task, inside which device_is_in_reset() is called to actually make the attempt in vain. Rework reset_hold() and reset_exit() so that in the reset exit phase, the logic can really compute output clocks in reset_exit(). With this change, upstream U-Boot boots properly again with: $ qemu-system-arm -M xilinx-zynq-a9 -m 1G -display none -serial null -seria= l stdio \ -device loader,file=3Du-boot-dtb.bin,addr=3D0x4000000,cpu-num=3D0 Fixes: 38867cb7ec90 ("hw/misc/zynq_slcr: add clock generation for uarts") Signed-off-by: Bin Meng Acked-by: Alistair Francis Reviewed-by: Edgar E. Iglesias --- hw/misc/zynq_slcr.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/hw/misc/zynq_slcr.c b/hw/misc/zynq_slcr.c index 5086e6b7ed..8b70285961 100644 --- a/hw/misc/zynq_slcr.c +++ b/hw/misc/zynq_slcr.c @@ -269,6 +269,21 @@ static uint64_t zynq_slcr_compute_clock(const uint64_t= periods[], zynq_slcr_compute_clock((plls), (state)->regs[reg], \ reg ## _ ## enable_field ## _SHIFT) =20 +static void zynq_slcr_compute_clocks_internal(ZynqSLCRState *s, uint64_t p= s_clk) +{ + uint64_t io_pll =3D zynq_slcr_compute_pll(ps_clk, s->regs[R_IO_PLL_CTR= L]); + uint64_t arm_pll =3D zynq_slcr_compute_pll(ps_clk, s->regs[R_ARM_PLL_C= TRL]); + uint64_t ddr_pll =3D zynq_slcr_compute_pll(ps_clk, s->regs[R_DDR_PLL_C= TRL]); + + uint64_t uart_mux[4] =3D {io_pll, io_pll, arm_pll, ddr_pll}; + + /* compute uartX reference clocks */ + clock_set(s->uart0_ref_clk, + ZYNQ_COMPUTE_CLK(s, uart_mux, R_UART_CLK_CTRL, CLKACT0)); + clock_set(s->uart1_ref_clk, + ZYNQ_COMPUTE_CLK(s, uart_mux, R_UART_CLK_CTRL, CLKACT1)); +} + /** * Compute and set the ouputs clocks periods. * But do not propagate them further. Connected clocks @@ -283,17 +298,7 @@ static void zynq_slcr_compute_clocks(ZynqSLCRState *s) ps_clk =3D 0; } =20 - uint64_t io_pll =3D zynq_slcr_compute_pll(ps_clk, s->regs[R_IO_PLL_CTR= L]); - uint64_t arm_pll =3D zynq_slcr_compute_pll(ps_clk, s->regs[R_ARM_PLL_C= TRL]); - uint64_t ddr_pll =3D zynq_slcr_compute_pll(ps_clk, s->regs[R_DDR_PLL_C= TRL]); - - uint64_t uart_mux[4] =3D {io_pll, io_pll, arm_pll, ddr_pll}; - - /* compute uartX reference clocks */ - clock_set(s->uart0_ref_clk, - ZYNQ_COMPUTE_CLK(s, uart_mux, R_UART_CLK_CTRL, CLKACT0)); - clock_set(s->uart1_ref_clk, - ZYNQ_COMPUTE_CLK(s, uart_mux, R_UART_CLK_CTRL, CLKACT1)); + zynq_slcr_compute_clocks_internal(s, ps_clk); } =20 /** @@ -416,7 +421,7 @@ static void zynq_slcr_reset_hold(Object *obj) ZynqSLCRState *s =3D ZYNQ_SLCR(obj); =20 /* will disable all output clocks */ - zynq_slcr_compute_clocks(s); + zynq_slcr_compute_clocks_internal(s, 0); zynq_slcr_propagate_clocks(s); } =20 @@ -425,7 +430,7 @@ static void zynq_slcr_reset_exit(Object *obj) ZynqSLCRState *s =3D ZYNQ_SLCR(obj); =20 /* will compute output clocks according to ps_clk and registers */ - zynq_slcr_compute_clocks(s); + zynq_slcr_compute_clocks_internal(s, clock_get(s->ps_clk)); zynq_slcr_propagate_clocks(s); } =20 --=20 2.25.1 From nobody Sun Feb 8 20:13:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629684739602269.35421043611063; Sun, 22 Aug 2021 19:12:19 -0700 (PDT) Received: from localhost ([::1]:37218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mHzRi-0001Hi-Ig for importer@patchew.org; Sun, 22 Aug 2021 22:12:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHzO1-0004L1-SQ; Sun, 22 Aug 2021 22:08:29 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:33296) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mHzO0-0005sI-EG; Sun, 22 Aug 2021 22:08:29 -0400 Received: by mail-pg1-x52d.google.com with SMTP id c17so15238514pgc.0; Sun, 22 Aug 2021 19:08:27 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id e26sm13804358pfj.46.2021.08.22.19.08.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Aug 2021 19:08:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oKc66ttHB9slCrTYhnV9lkrcgvTcl8unFAGn2ufnt3E=; b=nBUL9HtH1vd2z4jqXFxXyri7pfmzk28CGhANrUhhLhkCW1QepWH4DxEo0dZ2i8MCQK dlpEjWWN2q8u57/GIe8tho3hJDKWBnvgr+sBp4RejhmUPWJSda4A35ciIBFb+LBQmgjM L4R5l4p5GdYunn4CzU+wHS5ZzaU1mu2QYSXpxKODrmJVL+tejsR/SIPXa7NctZpZ3LEh ln0QFQP5+3zN9ZKWX3xdjO8bsk6s8jbzrkk+ZnWxzm0kOvvRLLk1GM6rttkegOm6xS5y 0pAD4aXfg3Nh2QFfFKIe63bgwoTj0q774m90HKwf1qM3EFpN9VJv8kZbYi8Bm0BAdYJx FRbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oKc66ttHB9slCrTYhnV9lkrcgvTcl8unFAGn2ufnt3E=; b=MlpkZFmUYZ1QULWYwSsa3CKBJRn+e7P4TY0X/uCNIz1iFa1TMufcnWUJ480ak4YerR 4gacF+IDVrqGjcZqXEs7ph7gTwchImu0Pne8Wbi0+jxI4riJU9raZk8H1v/zQbd2npKG nf56YqfFPnEzgUPIwxbcXPNFq/RdrzWI0GH02mupF0zZMCEJiZTxpxRWGGh14mbvyh2g p6o+5BA2JyNkzvSty+8bHb8n1galutz1R1QEgQ8pSyA+2UEEkbrCkp0fJjjlxdhFOD56 zpIzcKuxLz8HdupvkPZBUVxbFlceKoFgH4XkFCvV550THuEF42lDnKClh+/f/ZfeE1mi A9yw== X-Gm-Message-State: AOAM531Q7OsB6Siea9fC7TN90b65AzdQdLyZz3UdH6Ej78ryw/uXjB7b AzpNc+Ea+lH8wq9PSdWYnZQ= X-Google-Smtp-Source: ABdhPJyqqh+4DMm616K4AE228vYL/LZf22aG8+uvqy7l20EkKGNKFc356+I/F91iDhZPW7xwxyKijg== X-Received: by 2002:a62:78d0:0:b029:3dd:8fc1:2797 with SMTP id t199-20020a6278d00000b02903dd8fc12797mr31318902pfc.65.1629684506681; Sun, 22 Aug 2021 19:08:26 -0700 (PDT) From: Bin Meng To: Damien Hedde , "Edgar E . Iglesias" , Alistair Francis , Peter Maydell Subject: [PATCH 2/3] hw/char: cadence_uart: Disable transmit when input clock is disabled Date: Mon, 23 Aug 2021 10:08:12 +0800 Message-Id: <20210823020813.25192-3-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210823020813.25192-1-bmeng.cn@gmail.com> References: <20210823020813.25192-1-bmeng.cn@gmail.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::52d; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x52d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1629684740997100001 Content-Type: text/plain; charset="utf-8" At present when input clock is disabled, any character transmitted to tx fifo can still show on the serial line, which is wrong. Fixes: b636db306e06 ("hw/char/cadence_uart: add clock support") Signed-off-by: Bin Meng Reviewed-by: Alistair Francis --- hw/char/cadence_uart.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c index b4b5e8a3ee..154be34992 100644 --- a/hw/char/cadence_uart.c +++ b/hw/char/cadence_uart.c @@ -327,6 +327,11 @@ static gboolean cadence_uart_xmit(void *do_not_use, GI= OCondition cond, static void uart_write_tx_fifo(CadenceUARTState *s, const uint8_t *buf, int size) { + /* ignore characters when unclocked or in reset */ + if (!clock_is_enabled(s->refclk) || device_is_in_reset(DEVICE(s))) { + return; + } + if ((s->r[R_CR] & UART_CR_TX_DIS) || !(s->r[R_CR] & UART_CR_TX_EN)) { return; } --=20 2.25.1 From nobody Sun Feb 8 20:13:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629684637710475.9533624023376; Sun, 22 Aug 2021 19:10:37 -0700 (PDT) Received: from localhost ([::1]:33216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mHzQ4-0006uw-IL for importer@patchew.org; Sun, 22 Aug 2021 22:10:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHzO4-0004UK-Ax; Sun, 22 Aug 2021 22:08:32 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:45954) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mHzO2-0005td-JU; Sun, 22 Aug 2021 22:08:32 -0400 Received: by mail-pj1-x102d.google.com with SMTP id f11-20020a17090aa78b00b0018e98a7cddaso653869pjq.4; Sun, 22 Aug 2021 19:08:29 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id e26sm13804358pfj.46.2021.08.22.19.08.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Aug 2021 19:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hy7Ff52qHjcDuSbVdO/SFd5G6FprlXnCV76MTgKBecE=; b=OB0QI6VUiB++ENtQOwLSN6XuD8Uxi12SKUaT8ZmxEaL3byb6Jd1CBN1WCVvggYNFNh wczFFVwhBy/1RvLe1ixKvQjv/nW0uT1gntYdUCR/ZJZ9FxLppb9pTo0IB1k1tfxU7YsM scsI9/s370YWIlPqjEr2TAR1qoPS5pKeRikiHT7qf+xvtWSKyLL32ac8yNx3H9RPqNAP gp3qsU/RxRUUcHyGSI3WOlfSZJU+y2+X0Gz3pEPcyrj5AbMp8iB9rDdZdfa7nhddWtbA Gcw0MifBNH6ABuQHL1yMTYjAe1D6TQJ+Z0dQo1PvupMOtmDUGOzpVHxfaexbofIKRgo3 1H4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hy7Ff52qHjcDuSbVdO/SFd5G6FprlXnCV76MTgKBecE=; b=iY5I9aTGlrqW94pGl7U6RbP5L8Tei5djZdtO6ALGyc82GLfGl6F47izrqBLXt2EtWR B3fc1zZKiGA0sLl+Xz6LffRI5htWJx/5PYoIuPQVDdM2w2ROR+94Kn/J95N8QiPNaCk4 kV4bsDjLV+4z6ZKnPrlKJWPrdKgVDp8+5lmzLdIlbcYl3gEtFuFhCVT/hzTKT3+DiXaN 3BvrIHIo66/i3PSxEl9PDwSJG6xqIju92wdnKmyILZwSWZq09kxRuPscZGtatmSR98Wq aTVQO/1jUUF/cCQFy1WiU4gfWIzJc2pJQOz98v3rLWrf8Tf+XMTNpfjL2JZjRa6qK4rZ EQug== X-Gm-Message-State: AOAM5304BMPfQLtRhKT42XL4r6PxN33fUYnOEGQpG0wgvJOJayughYwR niSs4lnfsUPRHU531Zl+s0I= X-Google-Smtp-Source: ABdhPJyf4QN8eZoDhCCwCVqgC4biYLuODpjcNeFQM4p2BpghIH3Akiorw1iMVd0PE9e9lOZ5v9XCKg== X-Received: by 2002:a17:90a:d686:: with SMTP id x6mr17469269pju.227.1629684509018; Sun, 22 Aug 2021 19:08:29 -0700 (PDT) From: Bin Meng To: Damien Hedde , "Edgar E . Iglesias" , Alistair Francis , Peter Maydell Subject: [PATCH 3/3] hw/char: cadence_uart: Move clock/reset check to uart_can_receive() Date: Mon, 23 Aug 2021 10:08:13 +0800 Message-Id: <20210823020813.25192-4-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210823020813.25192-1-bmeng.cn@gmail.com> References: <20210823020813.25192-1-bmeng.cn@gmail.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::102d; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1629684639235100003 Content-Type: text/plain; charset="utf-8" Currently the clock/reset check is done in uart_receive(), but we can move the check to uart_can_receive() which is earlier. Signed-off-by: Bin Meng --- hw/char/cadence_uart.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c index 154be34992..7326445385 100644 --- a/hw/char/cadence_uart.c +++ b/hw/char/cadence_uart.c @@ -235,6 +235,12 @@ static void uart_parameters_setup(CadenceUARTState *s) static int uart_can_receive(void *opaque) { CadenceUARTState *s =3D opaque; + + /* ignore characters when unclocked or in reset */ + if (!clock_is_enabled(s->refclk) || device_is_in_reset(DEVICE(s))) { + return 0; + } + int ret =3D MAX(CADENCE_UART_RX_FIFO_SIZE, CADENCE_UART_TX_FIFO_SIZE); uint32_t ch_mode =3D s->r[R_MR] & UART_MR_CHMODE; =20 @@ -358,11 +364,6 @@ static void uart_receive(void *opaque, const uint8_t *= buf, int size) CadenceUARTState *s =3D opaque; uint32_t ch_mode =3D s->r[R_MR] & UART_MR_CHMODE; =20 - /* ignore characters when unclocked or in reset */ - if (!clock_is_enabled(s->refclk) || device_is_in_reset(DEVICE(s))) { - return; - } - if (ch_mode =3D=3D NORMAL_MODE || ch_mode =3D=3D ECHO_MODE) { uart_write_rx_fifo(opaque, buf, size); } --=20 2.25.1