From patchwork Wed Feb 19 21:08:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13983005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24C94C021B0 for ; Wed, 19 Feb 2025 21:10:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkrJO-0001mj-Hh; Wed, 19 Feb 2025 16:08:54 -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 1tkrJM-0001mC-NV for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:08:52 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkrJL-0008Ud-66 for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:08:52 -0500 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-43996e95114so1159785e9.3 for ; Wed, 19 Feb 2025 13:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739999329; x=1740604129; 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=pnDfQ0pDNHjagyoidO1nQy0wbrzE23spPhP9nSEJCp0=; b=vBLZ1eD/MQanhYw83jq+bbRduIN0Y7xLqD3aOhQJ1ImC+yS3pj021HFrUecMntM1Av A/CAXJPfP/a4jw0T5hAgJ6MJeKnITnQFKTR8mf0cmQH7SvR+yqStu49QwSqTN49hiKzg 43GI2hdohHoAfuoTe8zQL+uKj+pCsrQ6SCbqo+5z+pqQUB+9zrxJ4kkkvW9CVykjl53D cAxbuz+O00rYnjMBv8s45r9ujrtfDtRgV8Z+Nc2+aJd3I9NFuxAYag0tR4ACB0LBq8IN 5u8Sohkc2sqOugSBHzhWrYtOFnuQGuEd/yVdx9qbVwx+nmNZpABDRr9FBO14aVgWgFlu U7TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739999329; x=1740604129; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pnDfQ0pDNHjagyoidO1nQy0wbrzE23spPhP9nSEJCp0=; b=mojrPp37fns/+ScsEHQHTzhcDioCnUkhVI+kS35Qj+FtVA170psXrsFhEN7ABjZXoP f1FQooNzYMsyBorPhzj1rV7iVN7ITLuz5XDa78cnn5eFLuSHu5PeTHSwwIIvgGqC7tQV oeCfvciYqrFqJHBX4xeHQQqi376/9A8h3Y0P5zNNbM42ViyEa6SghGjx+wQWpg9ZJSDw cgV4/P01dYjqoIc0zK3YRPliex2PQGd2iUc1L3Wq5frzwvTBEqDRWAnoxcspguaRQxRA bFPVIwHa+fIxE0x02pYicj+Xt5HvkpX+REM2HyufYGHtL7emUxoiJYT2+n6OuM0amMoE u1mA== X-Forwarded-Encrypted: i=1; AJvYcCWrnggGxvQ40jCD1nHpePnElgVfMWe8kphafn/iJLvYl+MUfbgDbqH43/wvj+XGU5BlisMAzdyAjBye@nongnu.org X-Gm-Message-State: AOJu0YwtVSgSCaUt3EYgEL7K7EXjpkUsDGdAUfzxLzyiGF6sIvpRC+Kg SpgAFtqQgqwyQHYn64coAW69t8RlmUJQ+dwu2Nmcc0N2baRYyqlm8uopLIWwGLU= X-Gm-Gg: ASbGncsuzTyG/VwmJ3IVwfSEmMexlEoxYXUPpoynZWXs7I+HVGAHV8LJRi9bC9qiZmR SoVzrgEiJMkwYHreChvEua/ypHv8WH4JkN4gCWWfB8XxeSTyNAex2Iuk5+p47uGyiFY/f1mV0jn 0a9srhGNLWtEiTxkavYvw/rnwShdDdNFXb6sOYpC2J1gDbCxLwY0TdyQD1JL9jMajahO6ytXk04 V6AhJZ5ESgWcP3V0U1E9XJ6oDFSRjakkR6V+uWHQsqA3p5S0/qtFafRsoqQf7dwxjbe4AWYBnr2 tWb76VlQK225XePhPXcumItLg8iT9V12uEXBQ5E84A/CNnimYaX4eVEIv6MAcE9hfg== X-Google-Smtp-Source: AGHT+IFkA47+n1j1DG2COTtp0KDSYC++hjSRKaos4pqLnwlps7JbruZUJquCqI0DxmNT/FpiZUB9lQ== X-Received: by 2002:a05:600c:1ca8:b0:439:8a44:1e65 with SMTP id 5b1f17b1804b1-4398a441f98mr114220365e9.7.1739999329390; Wed, 19 Feb 2025 13:08:49 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4399b430912sm30933125e9.0.2025.02.19.13.08.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Feb 2025 13:08:48 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Cc: Evgeny Iakovlev , Rayhan Faizel , Luc Michel , Paolo Bonzini , Yoshinori Sato , Magnus Damm , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Shin'ichiro Kawasaki , =?utf-8?q?Philippe_Math?= =?utf-8?q?ieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Richard Henderson Subject: [PATCH 1/9] hw/char/pl011: Warn when using disabled receiver Date: Wed, 19 Feb 2025 22:08:33 +0100 Message-ID: <20250219210841.94797-2-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250219210841.94797-1-philmd@linaro.org> References: <20250219210841.94797-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We shouldn't receive characters when the full UART or its receiver is disabled. However we don't want to break the possibly incomplete "my first bare metal assembly program"s, so we choose to simply display a warning when this occurs. Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé --- hw/char/pl011.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 06ce851044d..60cea1d9a16 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -85,6 +85,7 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr) #define CR_OUT1 (1 << 12) #define CR_RTS (1 << 11) #define CR_DTR (1 << 10) +#define CR_RXE (1 << 9) #define CR_TXE (1 << 8) #define CR_LBE (1 << 7) #define CR_UARTEN (1 << 0) @@ -487,6 +488,12 @@ static int pl011_can_receive(void *opaque) PL011State *s = (PL011State *)opaque; int r; + if (!(s->cr & CR_UARTEN)) { + qemu_log_mask(LOG_GUEST_ERROR, "PL011 reading data on disabled UART\n"); + } + if (!(s->cr & CR_RXE)) { + qemu_log_mask(LOG_GUEST_ERROR, "PL011 reading data on disabled TX UART\n"); + } r = s->read_count < pl011_get_fifo_depth(s); trace_pl011_can_receive(s->lcr, s->read_count, r); return r; From patchwork Wed Feb 19 21:08:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13983017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 62C6BC021AA for ; Wed, 19 Feb 2025 21:12:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkrJT-0001o2-I8; Wed, 19 Feb 2025 16:08:59 -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 1tkrJR-0001nB-Dm for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:08:57 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkrJP-0008VB-So for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:08:57 -0500 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-38a8b17d7a7so114627f8f.2 for ; Wed, 19 Feb 2025 13:08:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739999334; x=1740604134; 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=3+Molro6lB3lK8nnwO97GajMQTSCSuF9fx6fEvtnGg8=; b=Nny2HWAtohv/y3AB5m1ASstm3LKEyS3Ln8Sm30xNYPCtUWnDd8AYAhpuJfLXNM3sOd kJfb7DR3D3EPgqF+/PzQlZzFeXKDBzHWbR/5q3Z0xiAoG+5ZVpbVxdrSzeGpAph9P1HB J1aKXqgRWizEjSTMtxGH3tpVMX4cIYMg5uwubUtsAAM+yr6PmzgdyRz3teUo4aKyPf9s RfPp0EEZwIcbk6LO+DfdwZDtDqtCbzjFCQ7b12hFuRyRJy6SKEuJuH3+LxvfqfNvQUUX 2SFgxm3HoDVNffJBw00HcQdUhfjcAjKRM6YgBQYuZu5lYq7ugEURbvoB3UDeUcO/vlgO JzKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739999334; x=1740604134; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3+Molro6lB3lK8nnwO97GajMQTSCSuF9fx6fEvtnGg8=; b=jvG+O3TNpCs9OAeIyV3sepZbKPDr8Jk9K1rdlIKBxB7CJ1I3bMdqGxgmTj0y2gXOSH 18tgHH3Nf+ElId+KX0P/eHyNBn70ETmnOBWdniJ5BY9xxYU7EhGOvTTinsSBonpPhQEw Y2GH+84cViRyHB6d9iln5VbNHzgl9MM/mVBPfntGEJTZLr74K9tg/FoltFVOoeHXD9/X EgEMZIooFXPIHWpDuICOG2HQMfQ/Ac/6/5u0AvnS5njzaTqVoQL4WWeTS1NY+k5cfHig iBwiPMElAeWdBqnVHuGiotRQwXP7mvUJn2ZBF6rwbx2AOl68QcILtj+nSAapK0XydEHS vcDA== X-Forwarded-Encrypted: i=1; AJvYcCUv0x9RbXqpSln29HjjKCaMg3rPrMDuOXYbi2fnkGc9T3sU69zVfxWFsvHwVbGMl/x4HhlLnD6jnabU@nongnu.org X-Gm-Message-State: AOJu0YyvrlBwItmoZVcJgl+A6VhXzpCXo38l2/zCT1QJp07QKdWf96gj 4FRc2euQ+d47It1BTN4o6VVu1L658n6JJpcy0rXCJSQRCvLk1Ziy/CVCV/Cvqu4= X-Gm-Gg: ASbGncsTAkciy2bYDa6U/8PasHBcP/BsEjqkR1uTq6TFxISq6B2Vr4I/jXSYoo97qEf Hw2/7RU7dr61hEgYp0ksw87EcVRZZ3Asavh+80L9yeKmXxGfPzsuDJPHKoyGKVcPrehVDJ3hyy+ D7Ahaymm2jNT4ifqbKNoObNLtQF9vhtWBffvVG5m/pcOzHZKTBZhC3GKSvaE2tRNUyi+zDwx5fo 1+pSZEi3oicsF9ITaQogTWOQ7XTiSZSuZ2iNSh/3hb9+WBhRbpk597OYxdvsdKWKZPTmHj5/aX2 P+ZHt9Z/gMkr0MP4Kbi/+g1oAnI5KHmAMbQ/drn6/JUBhg2F1FMMCtnY0oa2stprjw== X-Google-Smtp-Source: AGHT+IGwngY8yxWMhLwq/KgWntpSf7HRF5XmQjKuJRImATuaSWrYG1I+/eCKEZFC6hsjO91u0/Tffw== X-Received: by 2002:a5d:47ac:0:b0:38d:e15e:17e9 with SMTP id ffacd0b85a97d-38f587e4e64mr5506069f8f.35.1739999334316; Wed, 19 Feb 2025 13:08:54 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259d5655sm18812959f8f.77.2025.02.19.13.08.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Feb 2025 13:08:53 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Cc: Evgeny Iakovlev , Rayhan Faizel , Luc Michel , Paolo Bonzini , Yoshinori Sato , Magnus Damm , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Shin'ichiro Kawasaki , =?utf-8?q?Philippe_Math?= =?utf-8?q?ieu-Daud=C3=A9?= , qemu-arm@nongnu.org Subject: [PATCH 2/9] hw/char/pl011: Simplify a bit pl011_can_receive() Date: Wed, 19 Feb 2025 22:08:34 +0100 Message-ID: <20250219210841.94797-3-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250219210841.94797-1-philmd@linaro.org> References: <20250219210841.94797-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=philmd@linaro.org; helo=mail-wr1-x42b.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, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Introduce 'fifo_depth' and 'fifo_available' local variables to better express the 'r' variable use. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Luc Michel --- hw/char/pl011.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 60cea1d9a16..bcd516d682d 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -486,7 +486,9 @@ static void pl011_write(void *opaque, hwaddr offset, static int pl011_can_receive(void *opaque) { PL011State *s = (PL011State *)opaque; - int r; + unsigned fifo_depth = pl011_get_fifo_depth(s); + unsigned fifo_available = fifo_depth - s->read_count; + int r = fifo_available ? 1 : 0; if (!(s->cr & CR_UARTEN)) { qemu_log_mask(LOG_GUEST_ERROR, "PL011 reading data on disabled UART\n"); @@ -494,7 +496,6 @@ static int pl011_can_receive(void *opaque) if (!(s->cr & CR_RXE)) { qemu_log_mask(LOG_GUEST_ERROR, "PL011 reading data on disabled TX UART\n"); } - r = s->read_count < pl011_get_fifo_depth(s); trace_pl011_can_receive(s->lcr, s->read_count, r); return r; } From patchwork Wed Feb 19 21:08:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13983016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC4E7C021AA for ; Wed, 19 Feb 2025 21:12:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkrJa-0001va-6X; Wed, 19 Feb 2025 16:09:06 -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 1tkrJX-0001sY-Ez for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:03 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkrJV-0008Vj-Nf for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:03 -0500 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4393dc02b78so1202525e9.3 for ; Wed, 19 Feb 2025 13:09:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739999340; x=1740604140; 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=4FHsuKvW5lxqHnKhRd7Yijx1j/tjAzvjfWfwUFBfXHI=; b=AI6drNCz+OCGWjvsJ1ELqWheL4gN7Wzs1Bu97iNgZrjU5E5w6o9cqdRwQlhbXQEhA8 5jbS1GY9pqwtmFOPnPc29miT5yTomY3Me3bs9Zg3MulUpe+wtK092iP07eUE3vo9SFsQ tnvNqAjn32miITLYjuoyyzkmM0hJFw4ga3CehxQd6WqcH9oB1KPEfnVffA3VKaGSddBL CmK1c7Gn8xqijJTUsgFvGMc8p0dDwOqdhbT+vqzSB9Bs49eOYIq5ZZUEzgLDHNDNj5gE sajESgQ7tRCU8hqpUlP/nig3RGCIzSoWIEeD9dC1oGSlcPJ06BfvZO0voL5xc2W/aHzy SWuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739999340; x=1740604140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4FHsuKvW5lxqHnKhRd7Yijx1j/tjAzvjfWfwUFBfXHI=; b=N/2WC8IRjJEXbdh3lwiRw2I9Si7O+Ih3HLG3tXxdOBySMGw8/YE/6iXNNghXzTEtcS Dw48umHcqImbT+ZKLKpDVki7rUMWXtSUxflIbJdU+XNe7Pw5sYzJigLy0pAUfwChkkZz NLaiRLGKgr8NGRAEtLmrCr2xpb26WcYz7QdM12HvsbGHIskQWhSvBXJPduz7AZV+JoWH +pKnRvRpQBYrwVoCCHPg42NBTxU4Ub/iggG4hE0aEejZbYXiLVYFInFi/DUBi0HGo6i6 K5UpUmLvtCZSEhAWinMiNdtEdAsNkemz5kYMJZjKDAreFhhwqaOnU8ybZeDDOpIs3TjQ dMpQ== X-Forwarded-Encrypted: i=1; AJvYcCXwaHmIBJnTxDa5uSpWeyEpVKfRnT/NFfBcGESmHrn55uDPZ3HRFMx7syQC0otsBQKyLwyUxRavz4ZJ@nongnu.org X-Gm-Message-State: AOJu0YyHYqYUhbbRtcfPxykSizBI2shOKrxNEs+iiJaDixRKPMtnI99+ 59rVpObIwwXPRd5v7bgHsPb6mzRpc+Jw7O/r5++MBTDTeQDi5a+wr0WrbjwD/82E6DvL8M/Sb0Y ImzQ= X-Gm-Gg: ASbGncvh1qoTCQSlVRZje7xuMLXuhS8aTZA6AKji6oDgaFjQl37MVJJmpvy4wuWIGlU brPnwiVXeAu/l7aCJbb+1kXQbvNpEylzOfgXSJLmv0sFGuzXK61Zo8uiJYV8922znZHSDDWQtWm Sgw16OqmebIF06pj4iZIvwdS1b6rUkpjSklbZvw6AsyKY56agJfFGAccKZN/N8hBsNVAu8w6kR7 DwcmuqkuDZBNcOGl95gF2hH7gaWBZ3H5mtddqJf/2I7jQtv4uGKTQP7pMnkriQALwew9GZTRK4f F5mpKn2KxwR+u1QIlS1+cVDE3dM0WzuMuDFrgakV/zVdSUZi6gvTviusrw/tnoDw6g== X-Google-Smtp-Source: AGHT+IERTR1XiiAxvQUqcL7HgCAWEcqCxi9fc99r9lHG3vrUskwUdQLOHiIzY3gm4LBo+mMusZ7Jww== X-Received: by 2002:a05:600c:3b1a:b0:439:9274:81ed with SMTP id 5b1f17b1804b1-439927483e2mr72162935e9.1.1739999340068; Wed, 19 Feb 2025 13:09:00 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259f8730sm19267996f8f.93.2025.02.19.13.08.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Feb 2025 13:08:59 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Cc: Evgeny Iakovlev , Rayhan Faizel , Luc Michel , Paolo Bonzini , Yoshinori Sato , Magnus Damm , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Shin'ichiro Kawasaki , =?utf-8?q?Philippe_Math?= =?utf-8?q?ieu-Daud=C3=A9?= , qemu-arm@nongnu.org Subject: [PATCH 3/9] hw/char/pl011: Improve RX flow tracing events Date: Wed, 19 Feb 2025 22:08:35 +0100 Message-ID: <20250219210841.94797-4-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250219210841.94797-1-philmd@linaro.org> References: <20250219210841.94797-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=philmd@linaro.org; helo=mail-wm1-x334.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Log FIFO use (availability and depth). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée Reviewed-by: Luc Michel --- hw/char/pl011.c | 10 ++++++---- hw/char/trace-events | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index bcd516d682d..148a7d0dc60 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -185,7 +185,7 @@ static void pl011_fifo_rx_put(void *opaque, uint32_t value) s->read_fifo[slot] = value; s->read_count++; s->flags &= ~PL011_FLAG_RXFE; - trace_pl011_fifo_rx_put(value, s->read_count); + trace_pl011_fifo_rx_put(value, s->read_count, pipe_depth); if (s->read_count == pipe_depth) { trace_pl011_fifo_rx_full(); s->flags |= PL011_FLAG_RXFF; @@ -248,12 +248,13 @@ static void pl011_write_txdata(PL011State *s, uint8_t data) static uint32_t pl011_read_rxdata(PL011State *s) { uint32_t c; + unsigned fifo_depth = pl011_get_fifo_depth(s); s->flags &= ~PL011_FLAG_RXFF; c = s->read_fifo[s->read_pos]; if (s->read_count > 0) { s->read_count--; - s->read_pos = (s->read_pos + 1) & (pl011_get_fifo_depth(s) - 1); + s->read_pos = (s->read_pos + 1) & (fifo_depth - 1); } if (s->read_count == 0) { s->flags |= PL011_FLAG_RXFE; @@ -261,7 +262,7 @@ static uint32_t pl011_read_rxdata(PL011State *s) if (s->read_count == s->read_trigger - 1) { s->int_level &= ~INT_RX; } - trace_pl011_read_fifo(s->read_count); + trace_pl011_read_fifo(s->read_count, fifo_depth); s->rsr = c >> 8; pl011_update(s); qemu_chr_fe_accept_input(&s->chr); @@ -496,12 +497,13 @@ static int pl011_can_receive(void *opaque) if (!(s->cr & CR_RXE)) { qemu_log_mask(LOG_GUEST_ERROR, "PL011 reading data on disabled TX UART\n"); } - trace_pl011_can_receive(s->lcr, s->read_count, r); + trace_pl011_can_receive(s->lcr, s->read_count, fifo_depth, fifo_available); return r; } static void pl011_receive(void *opaque, const uint8_t *buf, int size) { + trace_pl011_receive(size); /* * In loopback mode, the RX input signal is internally disconnected * from the entire receiving logics; thus, all inputs are ignored, diff --git a/hw/char/trace-events b/hw/char/trace-events index b2e3d25ae34..05a33036c12 100644 --- a/hw/char/trace-events +++ b/hw/char/trace-events @@ -60,12 +60,13 @@ imx_serial_put_data(const char *chrname, uint32_t value) "%s: 0x%" PRIx32 # pl011.c pl011_irq_state(int level) "irq state %d" pl011_read(uint32_t addr, uint32_t value, const char *regname) "addr 0x%03x value 0x%08x reg %s" -pl011_read_fifo(int read_count) "FIFO read, read_count now %d" +pl011_read_fifo(unsigned rx_fifo_used, size_t rx_fifo_depth) "RX FIFO read, used %u/%zu" pl011_write(uint32_t addr, uint32_t value, const char *regname) "addr 0x%03x value 0x%08x reg %s" -pl011_can_receive(uint32_t lcr, int read_count, int r) "LCR 0x%08x read_count %d returning %d" -pl011_fifo_rx_put(uint32_t c, int read_count) "new char 0x%02x read_count now %d" +pl011_can_receive(uint32_t lcr, unsigned rx_fifo_used, size_t rx_fifo_depth, unsigned rx_fifo_available) "LCR 0x%02x, RX FIFO used %u/%zu, can_receive %u chars" +pl011_fifo_rx_put(uint32_t c, unsigned read_count, size_t rx_fifo_depth) "RX FIFO push char [0x%02x] %d/%zu depth used" pl011_fifo_rx_full(void) "RX FIFO now full, RXFF set" pl011_baudrate_change(unsigned int baudrate, uint64_t clock, uint32_t ibrd, uint32_t fbrd) "new baudrate %u (clk: %" PRIu64 "hz, ibrd: %" PRIu32 ", fbrd: %" PRIu32 ")" +pl011_receive(int size) "recv %d chars" # cmsdk-apb-uart.c cmsdk_apb_uart_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB UART read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" From patchwork Wed Feb 19 21:08:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13983003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40511C021AA for ; Wed, 19 Feb 2025 21:09:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkrJg-00020T-Bn; Wed, 19 Feb 2025 16:09:13 -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 1tkrJd-0001wV-84 for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:09 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkrJb-00004u-Dl for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:08 -0500 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-38f2cb1ba55so182299f8f.3 for ; Wed, 19 Feb 2025 13:09:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739999346; x=1740604146; 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=fSZGsSKza9FznsLK+BKXxumGhe4yyrC/EclHmT2ykjo=; b=S4cwFKccf3iM87a3oolHfT9KUL99dAyHKSV7Ulpl4G33Fzpnfno7J7RRqcg6g47QkD Dq1oxFfcFtoHUuze45ndyTq1JfETrIA/TG4zsoEsT4z6BYY2qbcPjFl2umpKoGo6JMgv iv5frpGcAlJFN7KdmsEYLDYXzRbo0SyVnjSi7NSZNKy3uGO3IK0E4kbycqzr1bIj+R8b nSbvXoJNEJbxt6BqAlsMU3sIzlvNqOx+GFH/kHTXAsaVHgiDIxgL4t4DpnOyCpsF5quz zlWbh5YiHa/8FMXCtOd6T4dGwCSIvRFCfVOBNlSFwxvQPfbFcf6XuyPEnw0UYnQILhXU acZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739999346; x=1740604146; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fSZGsSKza9FznsLK+BKXxumGhe4yyrC/EclHmT2ykjo=; b=n7IoA0UieiCrHA6WUG83G+LcKUJQPGIahn5ggUmaH7QZM+/qlevv/9YHIJymJuBblo Pf1rUIARWRRSaMwwatHYBlI8nAeuJmfHZesXkP+94HkliieRjmzXeueEh9ifYPxq7JPi 4ms46d7bDhZo8Y4W1QPc4dAHybHVst6jtwM23LsVYBXyB67Lz8pDbNr7xYbOpurdk/KN MQ2kuPRdrPvgCDHX1UqXXkZYIYgaIzTZhUs0Nradzx9cVbqzYBSL8tW3QpHPC2kjxFKv +x9T/YwfxrLNpUJhTcplttEiu/ac/mKlKEyZAisv7Rb/7KHF9LEfgrUH0NOOrYCWGQyP iTuA== X-Forwarded-Encrypted: i=1; AJvYcCUVJW0CrqdZlFFpDVWdrMrubdAbKj98bI7kXc5JlvPI+MPlpmItW7F2czRAxWC97Q00kohE4Avi60p5@nongnu.org X-Gm-Message-State: AOJu0Yy8O9kKEzPCkRoDrQuQOsTBuvwbLpImpDOvjesQu3iB4b3CBk8T nvYCWU52AJInHTNT4UNCdfSgZBVlXzasMS2s4dHF0R9UwDaPdSivazlmb6ObrQ4= X-Gm-Gg: ASbGnctxkov9LsslKXgdR5ADK6XcG79VQREv+7uGZhGUgpuq47mfL9zKd1RjYdNptlz 3CsZY0X8XWPocmAiZUVxZe+Ig3/KwPGZXsTBN0fMShOqgD1wCSuQ5ErdZ06sQdd2eoFggAVVSPl NB1pFL5Wl+BZvDbDPNlQpUseidcLg7b9Mi7p8YN3+tOOjiTo/LMybeEwUFrKdwh3omdaQjBO73e wi/llq/AvtUo6G3qPWhJ/A71E+ctHt8UzVskAPRYq8TuytpOVGOarfC+uGMO5PZkUvwP4e1mZ5J RdyacKxqi6ogadOnZAhQiKgFDcqPl9GH89CiN7TMOYD5CKaTS7OCLhYjhZVmFtDjVg== X-Google-Smtp-Source: AGHT+IH8vWve1zzP4GhRmEIzBXAdPoQ6GxQ483+xddSgCnCPWr2rFU7i87czS1ardmTIRDJw8prvFA== X-Received: by 2002:a05:6000:196b:b0:38a:8ec6:f46f with SMTP id ffacd0b85a97d-38f587f184cmr4267743f8f.53.1739999345774; Wed, 19 Feb 2025 13:09:05 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43992ad82cfsm64238765e9.37.2025.02.19.13.09.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Feb 2025 13:09:04 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Cc: Evgeny Iakovlev , Rayhan Faizel , Luc Michel , Paolo Bonzini , Yoshinori Sato , Magnus Damm , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Shin'ichiro Kawasaki , =?utf-8?q?Philippe_Math?= =?utf-8?q?ieu-Daud=C3=A9?= , qemu-arm@nongnu.org Subject: [PATCH 4/9] hw/char/pl011: Really use RX FIFO depth Date: Wed, 19 Feb 2025 22:08:36 +0100 Message-ID: <20250219210841.94797-5-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250219210841.94797-1-philmd@linaro.org> References: <20250219210841.94797-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=philmd@linaro.org; helo=mail-wr1-x432.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, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org While we model a 16-elements RX FIFO since the PL011 model was introduced in commit cdbdb648b7c ("ARM Versatile Platform Baseboard emulation"), we only read 1 char at a time! Have the IOCanReadHandler handler return how many elements are available, and use that in the IOReadHandler handler. Example of FIFO better used by enabling the pl011 tracing events and running the tests/functional/test_aarch64_virt.py tests: pl011_can_receive LCR 0x70, RX FIFO used 0/16, can_receive 16 chars pl011_receive recv 5 chars pl011_fifo_rx_put RX FIFO push char [0x72] 1/16 depth used pl011_irq_state irq state 1 pl011_fifo_rx_put RX FIFO push char [0x6f] 2/16 depth used pl011_fifo_rx_put RX FIFO push char [0x6f] 3/16 depth used pl011_fifo_rx_put RX FIFO push char [0x74] 4/16 depth used pl011_fifo_rx_put RX FIFO push char [0x0d] 5/16 depth used pl011_can_receive LCR 0x70, RX FIFO used 5/16, can_receive 11 chars pl011_can_receive LCR 0x70, RX FIFO used 5/16, can_receive 11 chars pl011_write addr 0x038 value 0x00000050 reg IMSC pl011_irq_state irq state 1 pl011_can_receive LCR 0x70, RX FIFO used 5/16, can_receive 11 chars pl011_read addr 0x03c value 0x00000030 reg RIS pl011_write addr 0x044 value 0x00000000 reg ICR pl011_irq_state irq state 1 pl011_read addr 0x018 value 0x00000080 reg FR pl011_read_fifo RX FIFO read, used 4/16 pl011_irq_state irq state 1 pl011_read addr 0x000 value 0x00000072 reg DR pl011_can_receive LCR 0x70, RX FIFO used 4/16, can_receive 12 chars pl011_read addr 0x018 value 0x00000080 reg FR pl011_read_fifo RX FIFO read, used 3/16 pl011_irq_state irq state 1 pl011_read addr 0x000 value 0x0000006f reg DR pl011_can_receive LCR 0x70, RX FIFO used 3/16, can_receive 13 chars pl011_read addr 0x018 value 0x00000080 reg FR pl011_read_fifo RX FIFO read, used 2/16 pl011_irq_state irq state 1 pl011_read addr 0x000 value 0x0000006f reg DR pl011_can_receive LCR 0x70, RX FIFO used 2/16, can_receive 14 chars pl011_read addr 0x018 value 0x00000080 reg FR pl011_read_fifo RX FIFO read, used 1/16 pl011_irq_state irq state 1 pl011_read addr 0x000 value 0x00000074 reg DR pl011_can_receive LCR 0x70, RX FIFO used 1/16, can_receive 15 chars pl011_read addr 0x018 value 0x00000080 reg FR pl011_read_fifo RX FIFO read, used 0/16 pl011_irq_state irq state 0 pl011_read addr 0x000 value 0x0000000d reg DR pl011_can_receive LCR 0x70, RX FIFO used 0/16, can_receive 16 chars pl011_read addr 0x018 value 0x00000090 reg FR pl011_read addr 0x03c value 0x00000020 reg RIS pl011_write addr 0x038 value 0x00000050 reg IMSC pl011_irq_state irq state 0 pl011_can_receive LCR 0x70, RX FIFO used 0/16, can_receive 16 chars pl011_can_receive LCR 0x70, RX FIFO used 0/16, can_receive 16 chars pl011_read addr 0x018 value 0x00000090 reg FR pl011_write addr 0x000 value 0x00000072 reg DR Inspired-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Luc Michel --- hw/char/pl011.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 148a7d0dc60..57d293d1e3a 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -489,7 +489,6 @@ static int pl011_can_receive(void *opaque) PL011State *s = (PL011State *)opaque; unsigned fifo_depth = pl011_get_fifo_depth(s); unsigned fifo_available = fifo_depth - s->read_count; - int r = fifo_available ? 1 : 0; if (!(s->cr & CR_UARTEN)) { qemu_log_mask(LOG_GUEST_ERROR, "PL011 reading data on disabled UART\n"); @@ -498,7 +497,8 @@ static int pl011_can_receive(void *opaque) qemu_log_mask(LOG_GUEST_ERROR, "PL011 reading data on disabled TX UART\n"); } trace_pl011_can_receive(s->lcr, s->read_count, fifo_depth, fifo_available); - return r; + + return fifo_available; } static void pl011_receive(void *opaque, const uint8_t *buf, int size) @@ -513,7 +513,9 @@ static void pl011_receive(void *opaque, const uint8_t *buf, int size) return; } - pl011_fifo_rx_put(opaque, *buf); + for (int i = 0; i < size; i++) { + pl011_fifo_rx_put(opaque, buf[i]); + } } static void pl011_event(void *opaque, QEMUChrEvent event) From patchwork Wed Feb 19 21:08:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13983000 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74D50C021B0 for ; Wed, 19 Feb 2025 21:09:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkrJq-00025u-MI; Wed, 19 Feb 2025 16:09:22 -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 1tkrJi-00021f-VV for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:16 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkrJh-00007O-7A for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:14 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-439350f1a0bso1672195e9.0 for ; Wed, 19 Feb 2025 13:09:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739999351; x=1740604151; 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=JhwkxvyKpTQZAt9mirHnFUfpe4JfORLzfwmDQNOghTo=; b=UKbdE6q47vKyzx8BxWVf2/iEOXagu9xtHPhXkyT3a5o/87nMVkTbKXDdjHcYcLS0T8 rgfT5aRd1PTaw5q6xS/csfWIJvZmo++9zsvM+nQ6PrpCxI4UiMIGczr3x6bvQEXx/u3T 02cQqQwW7XpZyuBD7bGlNxfgEKiy7aMq7ITfHVtiEqL2fZnqDdgb1yVxc+FXsr/cdCe5 7pO9nuSvYKzbawcrXUApdxr+owcUwe1dnbc3jV6YTGJRaO8hvFusnIPV0slBo5tKP+So cB7El1n/POo7rVW9LsjswKN/xrX8sI17W0kFs22xl9OBrW7NfXLQM1i0CS1KK9vJ1ow+ H8uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739999351; x=1740604151; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JhwkxvyKpTQZAt9mirHnFUfpe4JfORLzfwmDQNOghTo=; b=DDkNfZPXJgG7OR3YjN5+X75ShuJPXrRB3oFNoWfbZjp/X4zcg09ffug5jIxKAWg2lp 2mDfCx2P/CxOEUaKsbA873k4ejs4bML784jPRkdHI8M0pslZh/0lSzpaeGTzHqAkR77n +qhPZ5Iw7qJ1rU2i6Ta9GjGjHqtulDrNPKoPTrw0ragCoX27Q0a/wKZD9MCvxj3Ve4J6 +Fymrxv3b2lUSqJCIH2mzmbJFamUcSW4jnyd4nbm943OEWBQebD6QdZv5SYFdhqyU/l+ Akeify96nQ7VR7wJ3r1HhLcQN5DTZX57rY6UT4QXRNp8BtJr032lT/cvF9o+fkuLG6MP xX/g== X-Forwarded-Encrypted: i=1; AJvYcCXU1s9N2wKPoZY7V79hWvpZUiYpCcbsHawF97imkFo11y/z2njhPwD0+msYgnr5IZw+VMplH1Ih2J+W@nongnu.org X-Gm-Message-State: AOJu0YzGZ7Bxzui/ohrmYhgU3qYn2l0uInToFdTyVhYHfNKbkV1hKK3U OawPKScqEZaDcA/O0fhosjXCC05pire+ch5TfcMx9/PYn+qsxaXLnzUGofMLlkg= X-Gm-Gg: ASbGnct2W2QzSWJyct8ybNZx45K2qdFSBy7cbOE0Q/iQKQV0NqAmpIStKeiNl5lXwdT ugct6ZBL/iSs6MazFilB7Qj3DpOczuj4j/2qOf9ld1ik+aciruuyN9XV2EcSEyOJ/2sY7hzmAsZ R/LQH7ys4QrRZlhNscMmhhdu50zcUFbN9pn0ejy7ZZvpVQqDHhuGHXVBiDCZpgqoFUpvLuCRH2d Rk8TdWmsM6f2IvifCCg7miJaYn6GcNZTCbGe84tvR4H24l5xhM7hdSf3/AnbikIJp5prsh069o4 AIf5nBFMbH+iuDzVbby/QNTlJO2nF1b7uDYHj1fYg2qYPc7zBKO0M0pBIy0L40nubw== X-Google-Smtp-Source: AGHT+IEI16QFgqjS4YLiNsbF7FC5EAyrAmAmr5Kq4LgCYvD6TfwsSDQwGj/4TwXMSh/XFWbKXqJFiQ== X-Received: by 2002:a05:600c:4e8d:b0:439:892c:dfd0 with SMTP id 5b1f17b1804b1-439a30e91femr5924815e9.14.1739999351505; Wed, 19 Feb 2025 13:09:11 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43986320899sm93060315e9.38.2025.02.19.13.09.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Feb 2025 13:09:11 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Cc: Evgeny Iakovlev , Rayhan Faizel , Luc Michel , Paolo Bonzini , Yoshinori Sato , Magnus Damm , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Shin'ichiro Kawasaki , =?utf-8?q?Philippe_Math?= =?utf-8?q?ieu-Daud=C3=A9?= , qemu-arm@nongnu.org Subject: [PATCH 5/9] hw/char/bcm2835_aux: Really use RX FIFO depth Date: Wed, 19 Feb 2025 22:08:37 +0100 Message-ID: <20250219210841.94797-6-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250219210841.94797-1-philmd@linaro.org> References: <20250219210841.94797-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=philmd@linaro.org; helo=mail-wm1-x335.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, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org While we model a 8-elements RX FIFO since the PL011 model was introduced in commit 97398d900ca ("bcm2835_aux: add emulation of BCM2835 AUX block") we only read 1 char at a time! Have the IOCanReadHandler handler return how many elements are available, and use that in the IOReadHandler handler. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Luc Michel --- hw/char/bcm2835_aux.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/char/bcm2835_aux.c b/hw/char/bcm2835_aux.c index 73ad5934067..c6e7eccf7dd 100644 --- a/hw/char/bcm2835_aux.c +++ b/hw/char/bcm2835_aux.c @@ -221,7 +221,7 @@ static int bcm2835_aux_can_receive(void *opaque) { BCM2835AuxState *s = opaque; - return s->read_count < BCM2835_AUX_RX_FIFO_LEN; + return BCM2835_AUX_RX_FIFO_LEN - s->read_count; } static void bcm2835_aux_put_fifo(void *opaque, uint8_t value) @@ -243,7 +243,9 @@ static void bcm2835_aux_put_fifo(void *opaque, uint8_t value) static void bcm2835_aux_receive(void *opaque, const uint8_t *buf, int size) { - bcm2835_aux_put_fifo(opaque, *buf); + for (int i = 0; i < size; i++) { + bcm2835_aux_put_fifo(opaque, buf[i]); + } } static const MemoryRegionOps bcm2835_aux_ops = { From patchwork Wed Feb 19 21:08:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13983004 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0B9E4C021B1 for ; Wed, 19 Feb 2025 21:10:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkrJw-0002Ew-Di; Wed, 19 Feb 2025 16:09:28 -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 1tkrJp-00026N-9Z for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:22 -0500 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkrJm-00008k-QT for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:21 -0500 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4397dff185fso1656255e9.2 for ; Wed, 19 Feb 2025 13:09:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739999357; x=1740604157; 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=3COjV92AMlpj3jvv9iQTT0YQlZwWPXgOl76J5cO1OMU=; b=n7pKNf+JhAXKhINkvUkjqsaFXn/wK9Dp9ql/j3tEPJZOzElLQpCOPctx93I8U0zQBn MMYL+HKhS5w4HLlivX3Ayrg29UHfLH/D3Iglc2g4CyJRVQsQE0uPpGiHgZ1laGUeLzfv q8MMjFyOdwhq/WbQW0HuBGcaDhzV4VhwxyTUff6VfntW90JZ4BlgE30dUXbDVTmVHumJ eYURpDODFLnGcikr+ICrxDq1+LmJBbqglUFg8u/axrGRtIZEoWvGIXPjIjRmzAznFcn5 pwhjOOmTAwmcS8c6qXGQcqSurDjhnW5bvYHPckXdM7bbRWcDPGU0yNsm0juf9oCIQJ5n mrXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739999357; x=1740604157; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3COjV92AMlpj3jvv9iQTT0YQlZwWPXgOl76J5cO1OMU=; b=qqAsVkrPqymvJAWyGxGmM6cKjU4lF5/NmRoOLXckhQmJtde6oojnT6rFBVFF/d8GXg NJLq7ES0KAy0tMycYI7lBfVmXMHdqv16GRONX/Vm3EVcbyLouqDUgh1fBjGcgZldFKjC AWGUWeKEgS9QJ4Avi66YXSIWpQt/xusWWkwF1UXrkF7nSRY7BA1pdJDaAkBy5FAF2v/m YY2Qr0WL0NAlBR29W441G2eC1tNTeyfLu746GLOkYX9Su1fz+57d9dlaJ15/l8CYwXqy KbGy3lpYnifBwhPexQfPTo/XMGqXZX6I60mhKb8HVpeRdv5RYAwVPWqmrfli3a37fJ5B gglA== X-Forwarded-Encrypted: i=1; AJvYcCUiNXslxgUVYYYVclTSTbWwf4mtFzvZaKjwgcFWdWvSTJTPXvL2xYstvbSQ9MIllEoOl7wdCgaBMM7K@nongnu.org X-Gm-Message-State: AOJu0Yza7lKXnGCpcms8yn/UnK4LUMBFJgNH3LTdcUEecWlnQ8s1zOIW T0NuDoH/ChgkoS1G1311se//liiqoiNzgtr91KSvy9CSiY9jqbLac/a9oySbaAE= X-Gm-Gg: ASbGncsJ3ItVZmfjK4D9FNyG8Sz0eX85sTs7BeXL6Rc2hqTWRpHVFDACEQsE6k22PNL 2Nly1n0XQfedL0UK0OUjpbtzgg6tLASNZfp0rgXFqg50ypdXV+/IJG9iM8YlGUiHc5EsEi2ciQr AjFTj55wU8G/nvCuZxMvjD4vfTncRpDTw/Ek1SOaDLK89cyvWH8oaV91Led3jokVGi4u8KxDUxg H08t2c5+m0OoRY//Xtr26rfQIxlMH4hajL385MZzLaQR61d3MHSEdsmp1ugHV+0UZyhBDlDe1pf iepo8c5UGPnhyW1Ext7AY8fUAYhYFgqUgJ+DgBYSyXnmd2XfF2SDTE6JkYqDOY/Crg== X-Google-Smtp-Source: AGHT+IHU4eUr3Yoqi1s4C3qI/7nZusOV3MFaTyZkQ5og19oJJ4B22TP2W9HKt5um3KFZ4b6STAOwHA== X-Received: by 2002:a05:600c:1c1a:b0:439:9274:81dd with SMTP id 5b1f17b1804b1-43999d72b69mr42422485e9.1.1739999357169; Wed, 19 Feb 2025 13:09:17 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4399600257asm55374655e9.4.2025.02.19.13.09.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Feb 2025 13:09:15 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Cc: Evgeny Iakovlev , Rayhan Faizel , Luc Michel , Paolo Bonzini , Yoshinori Sato , Magnus Damm , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Shin'ichiro Kawasaki , =?utf-8?q?Philippe_Math?= =?utf-8?q?ieu-Daud=C3=A9?= , qemu-arm@nongnu.org Subject: [PATCH 6/9] hw/char/imx_serial: Really use RX FIFO depth Date: Wed, 19 Feb 2025 22:08:38 +0100 Message-ID: <20250219210841.94797-7-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250219210841.94797-1-philmd@linaro.org> References: <20250219210841.94797-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=philmd@linaro.org; helo=mail-wm1-x333.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org While we model a 32-elements RX FIFO since the PL011 model was introduced in commit 988f2442971 ("hw/char/imx_serial: Implement receive FIFO and ageing timer") we only read 1 char at a time! Have the IOCanReadHandler handler return how many elements are available, and use that in the IOReadHandler handler. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Luc Michel --- hw/char/imx_serial.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/char/imx_serial.c b/hw/char/imx_serial.c index 38b4865157e..6f14f8403a9 100644 --- a/hw/char/imx_serial.c +++ b/hw/char/imx_serial.c @@ -386,7 +386,8 @@ static void imx_serial_write(void *opaque, hwaddr offset, static int imx_can_receive(void *opaque) { IMXSerialState *s = (IMXSerialState *)opaque; - return s->ucr2 & UCR2_RXEN && fifo32_num_used(&s->rx_fifo) < FIFO_SIZE; + + return s->ucr2 & UCR2_RXEN ? fifo32_num_free(&s->rx_fifo) : 0; } static void imx_put_data(void *opaque, uint32_t value) @@ -417,7 +418,10 @@ static void imx_receive(void *opaque, const uint8_t *buf, int size) IMXSerialState *s = (IMXSerialState *)opaque; s->usr2 |= USR2_WAKE; - imx_put_data(opaque, *buf); + + for (int i = 0; i < size; i++) { + imx_put_data(opaque, buf[i]); + } } static void imx_event(void *opaque, QEMUChrEvent event) From patchwork Wed Feb 19 21:08:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13983002 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 298B4C021B1 for ; Wed, 19 Feb 2025 21:09:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkrJy-0002Js-Q5; Wed, 19 Feb 2025 16:09:30 -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 1tkrJu-0002CH-L4 for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:26 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkrJs-00009L-H0 for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:25 -0500 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-43998deed24so1776215e9.2 for ; Wed, 19 Feb 2025 13:09:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739999362; x=1740604162; 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=ncwU6cIOgR/ePA4sESjtym4cDIkeSMiSmL8ykeDbSSE=; b=Y7AaV4qWY/zxIhtF4RQMYrMPX7b3vlZTMWMA8ZLfeh6sVorHRr+n44gto9Dcdcuers b/rzQSbG7obgNX1HvifJQqxqUa9nprzu17hGCqgRZjAo1QqNxxggQiVCIW+x95oyQAg6 f8qe75p0ehKN+NNOYEks0tqKu92XnUlApQdoiWcvSJWAkjTQLnI9/GBSkQQfMlVS5EzM 7my4wAe/96hJEhhcg4SiOWCaPS558MBteYLfbm19xYq7SG+239asKVsSnedXSBYW0DpD htjmPRfMXvIflaPkdPsg20OLVYDXA0Y4d0mlmBjaWIIOESnAbJ/qQu1S4vmSPxvVskVA KuaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739999362; x=1740604162; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ncwU6cIOgR/ePA4sESjtym4cDIkeSMiSmL8ykeDbSSE=; b=TotPkx0izTtv01nb2kRYAqG9ybdpW8H6C8DB3+90VJeiMrEy+WwQEb64Q1/d5jhbun QkGXF0omTBhFNM3jE9DO2nPsiaKK0YkAuIW1xylMCn7oxNnnCs2ttuBraMPZZY2PI4n9 RBLEbDkfvcdDq9c4UPod3vYGvW3BlteIo25hEAO8OITwvQP2baYDjTfkll4h3t5SI+p5 +f5PGGY6ABpjlzhOHgc0QzQRO3/X8fojl+AqknEgh9sjux/uu84brhpej0wSxg1F+dYx LrmdBeVyLpo7Xbevy3qpZIsWAW0jQwlo0oAlBuBGpVIq6VpWWOpBg9ZZ7AkjAFzAD7BI 0Ydw== X-Forwarded-Encrypted: i=1; AJvYcCW5d2XLebYzJHzhhOdT8F/rWhfCZ0QDVMTBKZam5tSxqiBC4+/mksAPu23LH5kIhy0iCm+EBSorrhN3@nongnu.org X-Gm-Message-State: AOJu0YzWZnNpXRALdWaK7dYTTTMzx/cKUUMbU15e9H/dZaaUURJ0Fh85 2U0ovbqjoLuvn5T82o5KQ0eZfbmscuTZRhJuQ/MPQ1EZuh52COthSCsql3KRSpU= X-Gm-Gg: ASbGnctmW48sh5D7d2c4q+e9fNIzDhNZqalHMccW50U7jClP9szem5UnXs0o+/HvYnB V9zlTdBt+rFHyBSg/w4y3QYhQLT8wLzv3w6ev8mLmoXsHQBwyRvNWW2ywZNoRY4aeauueTeGeWL 7sUBlRlMhrO2qK72nxUFsJ4NrM44e+5V1WEttT77pi5/AVZwy5Iz09TgQ8jqQsXAvQ/O/fhIJNU vxa92MQyIi2TqKAI0W4zf33CA4q8hnr1H8sOxPQ030qDcwvfE4rCqQTtV9ESh4YbEQKu/bJMvtW dXlpWHfXKL/RpiE8565otsbk+KxHaTQVG8c4593F+h1+xMZ++s5zP3cYE3pufq+89A== X-Google-Smtp-Source: AGHT+IHLn2DhGG+7Yh/k913XG4CFtz456lhGRiGEqJ6Nc1tDG2VfSs35DS+XKl2GKFUDG/NXJIFQaQ== X-Received: by 2002:a05:600c:3591:b0:439:969e:d80f with SMTP id 5b1f17b1804b1-439969edc14mr76162405e9.31.1739999361993; Wed, 19 Feb 2025 13:09:21 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f259f7987sm18500465f8f.87.2025.02.19.13.09.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Feb 2025 13:09:21 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Cc: Evgeny Iakovlev , Rayhan Faizel , Luc Michel , Paolo Bonzini , Yoshinori Sato , Magnus Damm , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Shin'ichiro Kawasaki , =?utf-8?q?Philippe_Math?= =?utf-8?q?ieu-Daud=C3=A9?= , qemu-arm@nongnu.org Subject: [PATCH 7/9] hw/char/mcf_uart: Use FIFO_DEPTH definition instead of magic values Date: Wed, 19 Feb 2025 22:08:39 +0100 Message-ID: <20250219210841.94797-8-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250219210841.94797-1-philmd@linaro.org> References: <20250219210841.94797-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=philmd@linaro.org; helo=mail-wm1-x329.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, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Defines FIFO_DEPTH and use it, fixing coding style. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Luc Michel --- hw/char/mcf_uart.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/char/mcf_uart.c b/hw/char/mcf_uart.c index 980a12fcb7d..95f269ee9b7 100644 --- a/hw/char/mcf_uart.c +++ b/hw/char/mcf_uart.c @@ -17,6 +17,8 @@ #include "chardev/char-fe.h" #include "qom/object.h" +#define FIFO_DEPTH 4 + struct mcf_uart_state { SysBusDevice parent_obj; @@ -27,7 +29,7 @@ struct mcf_uart_state { uint8_t imr; uint8_t bg1; uint8_t bg2; - uint8_t fifo[4]; + uint8_t fifo[FIFO_DEPTH]; uint8_t tb; int current_mr; int fifo_len; @@ -247,14 +249,16 @@ static void mcf_uart_reset(DeviceState *dev) static void mcf_uart_push_byte(mcf_uart_state *s, uint8_t data) { /* Break events overwrite the last byte if the fifo is full. */ - if (s->fifo_len == 4) + if (s->fifo_len == FIFO_DEPTH) { s->fifo_len--; + } s->fifo[s->fifo_len] = data; s->fifo_len++; s->sr |= MCF_UART_RxRDY; - if (s->fifo_len == 4) + if (s->fifo_len == FIFO_DEPTH) { s->sr |= MCF_UART_FFULL; + } mcf_uart_update(s); } From patchwork Wed Feb 19 21:08:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13983014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C1B7EC021B0 for ; Wed, 19 Feb 2025 21:11:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkrK0-0002O0-KN; Wed, 19 Feb 2025 16:09:32 -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 1tkrJy-0002Ju-7j for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:30 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkrJw-00009t-Df for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:29 -0500 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4399a1eada3so1690335e9.2 for ; Wed, 19 Feb 2025 13:09:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739999367; x=1740604167; 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=1M+9N1O1172KT1xmekfC3o1CG3P7IIUgC0GICjqwA8E=; b=BeIxtc6ATc0K8SxIJCBYczOFq43fkGrX8B9ZB4YEpCaTPt5NGuqlQpHAD/0r2qgAiW NOx/axiSfNdVgojvX0a7M0GRp4tGHaXgMdogoCpK3rcd0h5aJD028z3XaF8UoV4sxhFt RgR8xEoVdVqGtz7XpMLjVehmDic58QRlV+SHaeN/dLfqpGMdOgrjQ8S9hErQa3/W19NF 3TIb8szCmngzzY6OeYqm36qi4xt3Z0N2FmBAbb+S4zA0qGIUHR3+jT22LJUEpAbOweq2 i8SHdVKHtfPUkIDJQa4mGP6h4aYoxadyGteWq+xrOO0yBMtPCT+6RSVsh1fdnLMjWm9s /ueQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739999367; x=1740604167; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1M+9N1O1172KT1xmekfC3o1CG3P7IIUgC0GICjqwA8E=; b=ppsdpjqI8VJinnKLLiHPPmQGnMe/xkMEqT1t0JPoITcVItaIhchhLfA/mlBKgJqvDD Hncbps71vcWXRF45H+VdFz7BA6BTrqLLOAlE6Gv1iyud62+pIiqA6IyiLt950vlP4SVF a/2cu/di633WrogOHKIuups4ffDRyuHEzBTB9VxIyzT9MKH0JbE1leOYjiiRUa0roLo+ sYpiW8vEVtkPBcHxzEvknmo87qA0avAzhWFqKps/Qxj/iz5/+uYqERoE28oaSkcnI4UP BPHz1eHQpXceJqhx0wD5JPyfOqmgPsr6CuU89cv6Rbew7oCuMADrsNKN06i4zNEz5Fxv twiQ== X-Forwarded-Encrypted: i=1; AJvYcCXlckREoULmsVeiLVfCTRXqUlAqIgIbys4WP+2TCUhsSr0PW7Qq4oHZI8cjT8Lo4Y/v37sPPjuFxcmE@nongnu.org X-Gm-Message-State: AOJu0Yw9cxdxBkep7R8BfB0AxXEVUTlAgYIfZkDwWM6MmAhtoEaQc19j wm8UdOgi1zgp1qPF4vbGU1qAJBx1lPEfb3n1lEeHDLI8yVLV0qKtmXV2Io2843A= X-Gm-Gg: ASbGncvzjVHCj2pV3IJLXQl4GbPUzB4B9N/Op1JI9gT96AbDp5yrUWjPFIe3lloDr3T AtK65HJeWkepae9C2HqSUMh8amci39ZGSd4cgDtmXOyllloWMaZ2l7gW21YeiLTVfOTuEeb4VSh /KL1SXjuQAa8918nr33j8UlwomobWjBz9Q6Y6+ihuh/zHsBV7bGqC+d6JAbVNZKRYh/oigSxirA DC5/e4jrc2BltYRL/c0isGMv+/7ok08VZBEHlgnDQtPdKgJYkEmaJ7kflW8d0TMsvf5E3G5rj/6 ELEqu/+CZb5biQveYq0s0XRT2cbUFxVxKwTmW/8NbLmKkZAoLysExDQYTdPbQRM06g== X-Google-Smtp-Source: AGHT+IHgQjtyqw6XWw6SOlJ72y8SLFeZ4PIEzvT9q1McUWRWY3RDiPIVRF2x3LtvdBdqtutQZFDrLw== X-Received: by 2002:a05:600c:458a:b0:439:3d5c:8bfb with SMTP id 5b1f17b1804b1-43999dd11d6mr47685055e9.22.1739999366853; Wed, 19 Feb 2025 13:09:26 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4395a04f208sm221457235e9.6.2025.02.19.13.09.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Feb 2025 13:09:26 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Cc: Evgeny Iakovlev , Rayhan Faizel , Luc Michel , Paolo Bonzini , Yoshinori Sato , Magnus Damm , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Shin'ichiro Kawasaki , =?utf-8?q?Philippe_Math?= =?utf-8?q?ieu-Daud=C3=A9?= , qemu-arm@nongnu.org Subject: [PATCH 8/9] hw/char/mcf_uart: Really use RX FIFO depth Date: Wed, 19 Feb 2025 22:08:40 +0100 Message-ID: <20250219210841.94797-9-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250219210841.94797-1-philmd@linaro.org> References: <20250219210841.94797-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org While we model a 4-elements RX FIFO since the PL011 model was introduced in commit 20dcee94833 ("MCF5208 emulation"), we only read 1 char at a time! Have the IOCanReadHandler handler return how many elements are available, and use that in the IOReadHandler handler. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Luc Michel --- hw/char/mcf_uart.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/char/mcf_uart.c b/hw/char/mcf_uart.c index 95f269ee9b7..529c26be93a 100644 --- a/hw/char/mcf_uart.c +++ b/hw/char/mcf_uart.c @@ -281,14 +281,16 @@ static int mcf_uart_can_receive(void *opaque) { mcf_uart_state *s = (mcf_uart_state *)opaque; - return s->rx_enabled && (s->sr & MCF_UART_FFULL) == 0; + return s->rx_enabled ? FIFO_DEPTH - s->fifo_len : 0; } static void mcf_uart_receive(void *opaque, const uint8_t *buf, int size) { mcf_uart_state *s = (mcf_uart_state *)opaque; - mcf_uart_push_byte(s, buf[0]); + for (int i = 0; i < size; i++) { + mcf_uart_push_byte(s, buf[i]); + } } static const MemoryRegionOps mcf_uart_ops = { From patchwork Wed Feb 19 21:08:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13983015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97E1AC021AA for ; Wed, 19 Feb 2025 21:11:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkrK6-0002Xu-BS; Wed, 19 Feb 2025 16:09:38 -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 1tkrK4-0002Ul-62 for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:36 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkrK2-0000Af-07 for qemu-devel@nongnu.org; Wed, 19 Feb 2025 16:09:35 -0500 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-439a2780b44so1228625e9.1 for ; Wed, 19 Feb 2025 13:09:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739999372; x=1740604172; 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=XnXac85husRSdcAW6ArahXIi1CSZu6CjUp+G23JJFB0=; b=pDCbVahvKOj9yytNBiDMrAtCcJzffY2jZUHwMkL8A0h8mPJFyz/6QQ8TuB554Ah61N YOnr65K5xq6nAejL6P1FPan+K2pPBCagRy/l1TPo997KsiAC9MJFkmLHkyu2vpyQ9gJ2 PV6/cgSZTc6Kio/k/BP4F/lxnF2Bc0MbPjIxDrwEb5RDgfKplqPkQf6tfaWNrI4o5Lbd CEI1hlzMLbiYp/3OfMtmLQ2YPPHLk3S7AsiCybsNWmatjMPAM3qPv4Ixzi1+9DM0Pifx A5bitkLiJRvM0sk7NXpDJ12QI3PAUfLHbb4K92ZkasEtJcyTPaYAZ3Ajrk1Ipxltarre IFuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739999372; x=1740604172; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XnXac85husRSdcAW6ArahXIi1CSZu6CjUp+G23JJFB0=; b=ij06o85rx/iS1o4t/m+u7+XJmD3FcZuNK4PudoXO850aKcUr6DlBDutVNqWPbeV5cU UT20uUlA6h9n8DkxgAVqMu4/hAq2kbqQ2tbbxgQF4Fd/TRINw3wGDuofeERg6VA1oRBW 0umUlzcN6oxvMfls5gNNVtt6w/xUDv7hD6dOC3zxgy3bRwU1YJi13lB8XS6BkuD2jLFp eGUgMV9I2HE3iO0W0QH3goyUga+nR8zi31SI0+5tgiX23UECRG3X5uW1x40CqM9Fn5Ly JRZQ+Jt8ajmVtQLrAJjVrVSpqGOI5uNBUYqZZmXSj2fNbD/f18aCkAxInLKzCP45ocaq TWIA== X-Forwarded-Encrypted: i=1; AJvYcCXnDpJPF3Vs/dzFyaqic95/7dspiAzKvEp5zj2zYVv0SfJBwZG4Mn4rgatg06KpPKYaGBq5e58IFw8z@nongnu.org X-Gm-Message-State: AOJu0Yw6HX1bpmyNpGnQX37JNg53sVvrXIuBOeQPHL3zmexRJRpMkUCL ktIHE8bt5PiF2RJW5AGeYpYsLpARBs6hAPyx58iPLosv9tQERvUkSbZ01i8Z2q8= X-Gm-Gg: ASbGncsHFO+pivqddUC3L7a0ly7dR9tUib4MJEWt/NoVdk/oIUEkwGnHNuYFWBICRm3 NXi4CtS7GzWw3wvJSX0HTEOV25q3Okj0v1r3BLG9pr04i4TPYhbLyARriiwcoZpN6OyN/jV9zWT vHmwXDdLNRlRGpZq1E6bAXHikvyN5oa1enZvzzc9ZNPEaXgSFHsNmIMQfokjelFXddm9/FqsQ+w QOY6cTCrNQ0fEqPMoLGjiyPaP6QKcFie2BTRdy8j8wJdAHqCxu1ZtMFW345yGS3Jg3BDfEpCCgU +TiUvkYUTt0RAk1qa9jEsd0gq0LkwPzdhbfZhm1RxC1/BT0705JWPmFzKNBWd/uZvw== X-Google-Smtp-Source: AGHT+IE4Byg70J4EWT04Rr2EIOcLaDr6jugN8hJq25PFZ4HSMwrAbXNiUeRQpkmbDJFI9DGkfshlOg== X-Received: by 2002:a05:600c:3b26:b0:439:31e0:d9a5 with SMTP id 5b1f17b1804b1-43999dd1e1cmr44430935e9.22.1739999371753; Wed, 19 Feb 2025 13:09:31 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439a0cc11c6sm13165315e9.16.2025.02.19.13.09.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Feb 2025 13:09:31 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Cc: Evgeny Iakovlev , Rayhan Faizel , Luc Michel , Paolo Bonzini , Yoshinori Sato , Magnus Damm , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Shin'ichiro Kawasaki , =?utf-8?q?Philippe_Math?= =?utf-8?q?ieu-Daud=C3=A9?= , qemu-arm@nongnu.org Subject: [PATCH 9/9] hw/char/sh_serial: Return correct number of empty RX FIFO elements Date: Wed, 19 Feb 2025 22:08:41 +0100 Message-ID: <20250219210841.94797-10-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250219210841.94797-1-philmd@linaro.org> References: <20250219210841.94797-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=philmd@linaro.org; helo=mail-wm1-x32c.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In the IOCanReadHandler sh_serial_can_receive(), if the Serial Control Register 'Receive Enable' bit is set (bit 4), then we returns a size of (1 << 4) which happens to be equal to 16, so effectively SH_RX_FIFO_LENGTH. The IOReadHandler, sh_serial_receive1() takes care to receive multiple chars, but if the FIFO is partly filled, we only process the number of free slots in the FIFO, discarding the other chars! Fix by returning how many elements the FIFO can queue in the IOCanReadHandler, so we don't have to process more than that in the IOReadHandler, thus not discarding anything. Remove the now unnecessary check on 's->rx_cnt < SH_RX_FIFO_LENGTH' in IOReadHandler, reducing the block indentation. Fixes: 63242a007a1 ("SH4: Serial controller improvement") Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Luc Michel --- hw/char/sh_serial.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/hw/char/sh_serial.c b/hw/char/sh_serial.c index 247aeb071ac..41c8175a638 100644 --- a/hw/char/sh_serial.c +++ b/hw/char/sh_serial.c @@ -320,7 +320,7 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs, static int sh_serial_can_receive(SHSerialState *s) { - return s->scr & (1 << 4); + return s->scr & (1 << 4) ? SH_RX_FIFO_LENGTH - s->rx_head : 0; } static void sh_serial_receive_break(SHSerialState *s) @@ -353,22 +353,20 @@ static void sh_serial_receive1(void *opaque, const uint8_t *buf, int size) if (s->feat & SH_SERIAL_FEAT_SCIF) { int i; for (i = 0; i < size; i++) { - if (s->rx_cnt < SH_RX_FIFO_LENGTH) { - s->rx_fifo[s->rx_head++] = buf[i]; - if (s->rx_head == SH_RX_FIFO_LENGTH) { - s->rx_head = 0; - } - s->rx_cnt++; - if (s->rx_cnt >= s->rtrg) { - s->flags |= SH_SERIAL_FLAG_RDF; - if (s->scr & (1 << 6) && s->rxi) { - timer_del(&s->fifo_timeout_timer); - qemu_set_irq(s->rxi, 1); - } - } else { - timer_mod(&s->fifo_timeout_timer, - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 15 * s->etu); + s->rx_fifo[s->rx_head++] = buf[i]; + if (s->rx_head == SH_RX_FIFO_LENGTH) { + s->rx_head = 0; + } + s->rx_cnt++; + if (s->rx_cnt >= s->rtrg) { + s->flags |= SH_SERIAL_FLAG_RDF; + if (s->scr & (1 << 6) && s->rxi) { + timer_del(&s->fifo_timeout_timer); + qemu_set_irq(s->rxi, 1); } + } else { + timer_mod(&s->fifo_timeout_timer, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 15 * s->etu); } } } else {