From patchwork Mon May 22 15:31:33 2023 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: 684720 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1261570wrt; Mon, 22 May 2023 08:35:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7a5udkbB9wu1K8QaSCZbk3y/iK6o9+3LBb9kmsn+iWrHbpD6IC799yb7Q6svmuEmp8JkQt X-Received: by 2002:a05:620a:4793:b0:75b:23a1:8316 with SMTP id dt19-20020a05620a479300b0075b23a18316mr1082185qkb.17.1684769744348; Mon, 22 May 2023 08:35:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684769744; cv=none; d=google.com; s=arc-20160816; b=nDMYvoI0eYVXJTY8lLWQDHhhGu6P12IGEb+qiHwEd+OMbng/Xw9pwGvGOLjkCPvcoi 09TiMAl/NTtTbMxz4HUQObp6ym2hOPLDs4z310YvySl9cqaQKbmVQHWwcKDSf7i/Gbfw LoS8NvC5pz7czPftetXO8USiVX0M85Gq8s/5fL9TdBhp/rZ57k9Ha9NITwXf7UavZ4QI rpQk8KyvOR8AOySXFWP1exP7srpzpwGlvYKjWITrvXjIenFgJpRO490PM1+VN5b8+9bw ErWgZdGTVLw5VPiTuuR1GRmVr20YITM/1TFPEuDoI+1xkFPw07FVZQiF6Q0LexbJVUmf d9xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=glXXfgsRplQFxPF2FEdJ5asogB54RtufXxooiyPAR7A=; b=TGLNhWuSy28cb2Vbifo3YwPs77Qt/WVzabstjn6QpkFvCle18mwzSTxI/8ogXwGBD1 6cxNz4MVYEsrIxjLROLO2FBMpnUD95NjUJSb2FG7FYTmgp74TjkAl1v4BF5CgMTw/U3/ DSYJlvWTw3cdCiW9Dq2fIyFo/Jxw7tTWvD0DSDGNfdF7Jg1KILlZA/0hJelqMNwWgRIO g6LXCmWxPhYXVYfZLw/OfI6OF1nULTTFgHFS0mRC/QwizROOYiTWMFtMmlhs+AasHeSB CM7eJ2BF/c6d/NTQsS8NZZuEymEglge3VUuW4PZOUTibgcakIomULc3Kn1lqthUtH06D VhPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N0ERuWsL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k4-20020ae9f104000000b007593da317bcsi3332970qkg.708.2023.05.22.08.35.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 May 2023 08:35:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N0ERuWsL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q17Wb-0007VA-6h; Mon, 22 May 2023 11:32:41 -0400 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 1q17Vr-0007Mr-TM for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:03 -0400 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 1q17Vq-0001Ju-BJ for qemu-devel@nongnu.org; Mon, 22 May 2023 11:31:55 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3f603e0edddso10172285e9.1 for ; Mon, 22 May 2023 08:31:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684769513; x=1687361513; 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=glXXfgsRplQFxPF2FEdJ5asogB54RtufXxooiyPAR7A=; b=N0ERuWsLU6iXzOmNBKOlOpg4dVkGIjpNumO8nlBuo/g3l/21CGfmxDKG1N7GJHIODC xCjmdmKdHuOGQoAkqrhwNkOM6uT88izAuP3FNvvfanq3672NomTXUdILkhUxwC0a/sp9 pn9WJZchyTXwhmGPVJMVCOhemcgIzwWs6X8tVscCiw12/7/1QLhGqWtV/rlzRdmkZsDL K54krVxaFq8L9I28MWlWWq+S0m9wjStStKhVHGEc+Xuroh0ag4vwadyLsW7JN0s/tFFZ /HbGaIxvd+PaBTr+bRLhP/UN7MdfhJW7lvLzTZSuiui4WalCkBefKzxfbp8TjbkbFBME 0YBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684769513; x=1687361513; 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=glXXfgsRplQFxPF2FEdJ5asogB54RtufXxooiyPAR7A=; b=QbeDMYF3dApeplxU9N5D1XyOuXFI3IkMrTPg7E6pamBHljmiFjJt5ndZH/CtJUYg1t M1xjXAz5PznIF+y2GHNMJWT9B0h34xeFzB2/z1UHZph9bzO4kjq2fMFJ+m/BfFfoCQD7 b9uz68vohWvCj1Pbdbr8+aa7pl3PU3LqbK+7uC8TsW/wC0uyulPFEeXifvU3vvUAJq7L faOTQLWkQjWrXP9gLzlSnIoImMdG1Dq2aeHkjOamynj0iNqV5sry6va/qEkBVx1I5jiJ HnFkXQwX+cdYcNGwVNpFwhErf9MBnnQHJMX/vYkyEuVt7f38BZN7sa3LoSSAb9uMSotf 5ZLA== X-Gm-Message-State: AC+VfDzrIaUfHValu8EZitwE1w8HLq9OpGzB/8Q0JN9US9peT8N0aV3V H+Kg/Tg8BZXuFnpToQYdWCIj28p3JQwZTfAwYlI= X-Received: by 2002:a05:600c:220d:b0:3f6:3bc:8562 with SMTP id z13-20020a05600c220d00b003f603bc8562mr3097333wml.1.1684769512764; Mon, 22 May 2023 08:31:52 -0700 (PDT) Received: from localhost.localdomain ([176.176.153.164]) by smtp.gmail.com with ESMTPSA id f15-20020a7bcd0f000000b003f0aefcc457sm11845054wmj.45.2023.05.22.08.31.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 May 2023 08:31:52 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 01/12] util/fifo8: Fix typo in fifo8_push_all() description Date: Mon, 22 May 2023 17:31:33 +0200 Message-Id: <20230522153144.30610-2-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230522153144.30610-1-philmd@linaro.org> References: <20230522153144.30610-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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Francisco Iglesias Reviewed-by: Alex Bennée --- include/qemu/fifo8.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index 28bf2cee57..16be02f361 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -46,7 +46,7 @@ void fifo8_push(Fifo8 *fifo, uint8_t data); * fifo8_push_all: * @fifo: FIFO to push to * @data: data to push - * @size: number of bytes to push + * @num: number of bytes to push * * Push a byte array to the FIFO. Behaviour is undefined if the FIFO is full. * Clients are responsible for checking the space left in the FIFO using From patchwork Mon May 22 15:31:34 2023 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: 684721 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1261759wrt; Mon, 22 May 2023 08:36:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7dURv/TGR+zGeWraiKJiBz0msAjdQxAUpFMiWKndLZxVbJ3KW3w/ugGeTrbN2mwWRg7oKk X-Received: by 2002:a05:620a:1792:b0:75b:23a0:e7e0 with SMTP id ay18-20020a05620a179200b0075b23a0e7e0mr1232247qkb.65.1684769765454; Mon, 22 May 2023 08:36:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684769765; cv=none; d=google.com; s=arc-20160816; b=P7Yn0ufsLlLarfWM4BEkCaAqrkqi5hnH4e1vF79VhFR5g/O7bAu77jc6B0NARe1M4O Bq9L14D3zI7cjh3J7NaElY99U+eLqKOE3PJwJrVTO8sg/Her7xIwLxKyZiVT0iyJPX+g vBuHo5+3/0OZ3E1+owxejaX8+avgmhxQz36jtNH4vb8f4+k9WL9CgUZ4oAo742K+ZK0w 8dVVD/nUmiwM6XD3R99w0TkJ7hunyz8nHUu3E/X7IX+Q7aFrO21eEkaCKQVrmDVgI0jg 7CrWgghd96GAVKoSs/Ld2PlamRHgEq7jZWqqu/7zZL7Z+tPtxvcX60a99baB94fHu8ev CxMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/HFQ4TQ858TQsjYOnqPZRPL59qIZV5loVHcO3ItffVk=; b=013GX2L5rStew7qMhGhNgUSGMGH0mkCcAnmaMqXz2DHYOih/ysYedjdCrT9tca4RKN kSonx8NhoKty2plbuA7cUNCcr2zAsFD2TX6xe7haBnGTZMDJwp9n7ePaSi+IGbn5kfvW aPhelc+d3fos8zMYzDGknP9XHNy1WSo+ffDEItSen2doci+r9/c0DptVdl+GML8sG/EG DJVwMGpsKjtfI3YfRW6gnSVF21EBhuGbdd8GoOnovg4DPzZvV60hiTNpWsY7te3uj8r3 Ue7IIy42ghq30q/4hjobxeGCcc2VUbocvubo7fmXoghyE7rNCDyrwzualJS44N7VhAfg 3Low== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JxZXjjck; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y2-20020a05620a25c200b0074e3111d77bsi3312679qko.636.2023.05.22.08.36.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 May 2023 08:36:05 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JxZXjjck; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q17Wc-0007aA-S6; Mon, 22 May 2023 11:32:42 -0400 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 1q17Vz-0007NB-3K for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:07 -0400 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 1q17Vx-0001Kb-Fu for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:02 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3f60410106cso9527775e9.1 for ; Mon, 22 May 2023 08:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684769518; x=1687361518; 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=/HFQ4TQ858TQsjYOnqPZRPL59qIZV5loVHcO3ItffVk=; b=JxZXjjckkKkgHydUr4Lviu/5YMUz8RRXJdofqyzRla9aFSCih3kMeEDlzc2dZd/rWC FxQ9L2UweED6uJXGa0Y81/Z4T6f6Bz9FKWyYoUC5JttfiFuZhwTETVkLqQ2tit4YqZi+ vFmuLxNql1IRFauW+5HqdfsALBV4Fz44tHok7cwNt7ZL0yYKGBsCRSp7Vz056zNr3vDp ORncD5wf0HsEv+t3uB5Y2g2pFu3lDF8bmNO2c38k4VqqANiwfKywKHHHzQsXFcG+PRK/ Eo7VTZypnqH16KVBJPLkalAdIbuBHex0TrcdF5lc4QeYq2+jB8ewG+lNUujRE3xNcQe2 lDtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684769518; x=1687361518; 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=/HFQ4TQ858TQsjYOnqPZRPL59qIZV5loVHcO3ItffVk=; b=It3wE8MCMCKOatRrUREl+v2PykgBlXK1JCD0kXvexrft1rdrWdfhxYMZ/CjdqOAGWD w6tUpMjFZ3+bs/Qtdsk0mip+grCyCjY3BNIFDST0cw+CeTrTP/CVKoUmZxxnM384GEhD 0a2gB5CmL/KQC5WI1caAYZ9zs0R3Vl6p0SW39NXF7sQ008D0ByeSUoLGFatuTlT7aInh CEaZSFhLXqxG9U4FGjTgGHUc8tLXn03ugcth2WLSFapwSQjj3janJVxwf5uS3WytrxHm KLMhnG5OeIJA93+h2simPrYN9EpQQwQaWbVp0UxtDk1V85D1Xp+Rx+sedl0GCcMdiFSv 7xQA== X-Gm-Message-State: AC+VfDwhe3a8o7Hudb8mB2HIT2mO5+SyGX9K6p11uSHlQLVUSUWyoQ/O g2TLPRIoFVR8wrzJrg1sSV9V1Z9CTcgRaWHW0nw= X-Received: by 2002:a7b:c046:0:b0:3f6:1c0:aa7a with SMTP id u6-20020a7bc046000000b003f601c0aa7amr3844982wmc.29.1684769518388; Mon, 22 May 2023 08:31:58 -0700 (PDT) Received: from localhost.localdomain ([176.176.153.164]) by smtp.gmail.com with ESMTPSA id z20-20020a7bc7d4000000b003f4ecf1fcbcsm11862770wmk.22.2023.05.22.08.31.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 May 2023 08:31:58 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 02/12] util/fifo8: Allow fifo8_pop_buf() to not populate popped length Date: Mon, 22 May 2023 17:31:34 +0200 Message-Id: <20230522153144.30610-3-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230522153144.30610-1-philmd@linaro.org> References: <20230522153144.30610-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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org There might be cases where we know the number of bytes we can pop from the FIFO, or we simply don't care how many bytes is returned. Allow fifo8_pop_buf() to take a NULL numptr. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Francisco Iglesias Reviewed-by: Alex Bennée --- include/qemu/fifo8.h | 10 +++++----- util/fifo8.c | 12 ++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index 16be02f361..d0d02bc73d 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -71,7 +71,7 @@ uint8_t fifo8_pop(Fifo8 *fifo); * fifo8_pop_buf: * @fifo: FIFO to pop from * @max: maximum number of bytes to pop - * @num: actual number of returned bytes + * @numptr: pointer filled with number of bytes returned (can be NULL) * * Pop a number of elements from the FIFO up to a maximum of max. The buffer * containing the popped data is returned. This buffer points directly into @@ -82,16 +82,16 @@ uint8_t fifo8_pop(Fifo8 *fifo); * around in the ring buffer; in this case only a contiguous part of the data * is returned. * - * The number of valid bytes returned is populated in *num; will always return - * at least 1 byte. max must not be 0 or greater than the number of bytes in - * the FIFO. + * The number of valid bytes returned is populated in *numptr; will always + * return at least 1 byte. max must not be 0 or greater than the number of + * bytes in the FIFO. * * Clients are responsible for checking the availability of requested data * using fifo8_num_used(). * * Returns: A pointer to popped data. */ -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num); +const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); /** * fifo8_reset: diff --git a/util/fifo8.c b/util/fifo8.c index d4d1c135e0..032e985440 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -66,16 +66,20 @@ uint8_t fifo8_pop(Fifo8 *fifo) return ret; } -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num) +const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) { uint8_t *ret; + uint32_t num; assert(max > 0 && max <= fifo->num); - *num = MIN(fifo->capacity - fifo->head, max); + num = MIN(fifo->capacity - fifo->head, max); ret = &fifo->data[fifo->head]; - fifo->head += *num; + fifo->head += num; fifo->head %= fifo->capacity; - fifo->num -= *num; + fifo->num -= num; + if (numptr) { + *numptr = num; + } return ret; } From patchwork Mon May 22 15:31:35 2023 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: 684718 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1260754wrt; Mon, 22 May 2023 08:33:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6djy7M9Wc4zrF32pMFLUlFJ6zOD0wGLlFGss7HC3uXx/vjJfz5FQtziZWBuClon7Q/KcD1 X-Received: by 2002:a05:622a:44:b0:3f4:e666:4583 with SMTP id y4-20020a05622a004400b003f4e6664583mr18676909qtw.49.1684769633486; Mon, 22 May 2023 08:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684769633; cv=none; d=google.com; s=arc-20160816; b=hNtxrg42g8eoJoAdM8ltwXKSCCiljkNxMIPndZKm772GpghfBOQFrFVWNmTYpgB891 wCSZ/G1Qf1r0KjnQ2S/xfju21ikVYpHlV/et+ybu2Li10WNJLzWM/wGx07E2lIKFi6cq Ow5GeYvZrf05/ksD4kNxxqO8L3byAr4l8DEcnv5M2DnSVy1rWiq3e8xhwyJ2GtjG1cph IAYjE9K/7YSSQ7I3EWMSI6OgpZritW69LqHPX5TgbQ+si78TAVIADV+MhFiCPA4oSEs5 wuWFJ42GNVICavyUBbFp9F8zd5S3QBDdcDxXe5jWi/cywMeoSLZP9HOoXvaPYVH+z5fq Gf1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D/v69wjcgQjzqhC98DKwcbYpCW+hDbd/3U2ovkdSDfw=; b=goPfjqIF3ITxPbdZofDhlXeeMb5m8mut1KiNM7FYOypSsLW3zY5sviSqB5prtkhkl4 V+/XqNc5W5+T8qdbXRw1kiaHc9eT75+8ccLJB3AVazYLI5n9tYX23mxEB0VlaC4g2siM kWvMVfpodjdUFMYEIcbiWH6Uz8R2+5v3nA4E8x5iPuj3o8mHyM5U0ObxToYBZV71RWtO b4bM5bn7PLrLZi11u543/0VT0Ur01JnEYC3N46Eq4qfa4JoDn+UoFEC9kuDTiIO6Ptig UtHejxRq2fUdSlXyo3RJtraSjrCXABiBbNDPDBTWAPqxV82/YFctnlFmQsVbEhc1FD7E up+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GcIeHWq7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o11-20020a05622a044b00b003f221c60353si3806913qtx.748.2023.05.22.08.33.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 May 2023 08:33:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GcIeHWq7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q17Wb-0007VB-6v; Mon, 22 May 2023 11:32:41 -0400 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 1q17W4-0007NO-6T for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:15 -0400 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 1q17W2-0001Lg-AC for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:07 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3f42b984405so38783925e9.3 for ; Mon, 22 May 2023 08:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684769524; x=1687361524; 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=D/v69wjcgQjzqhC98DKwcbYpCW+hDbd/3U2ovkdSDfw=; b=GcIeHWq7ho6Wb3vxdbkOS5rHBfm+Q2V7gO4V4OinnFC6S0gSjLClHkroxEPcEyBaiu 7MN6KFbKVsg6IS2/mEYBDXvvWGb5hFPXSOYD8BTCxDIs2O3v0Z2hXbxqz/04U0D2XO81 zfmxZ1tI2Kgjtvi4WPDOOwZx+MhlPIzOCmN//oGJgNdRbHG98G30XTWgB4dArEtQHTEs yPZoNvsSaATl7Vpc/dk4BOvEEwPVxp1b6X2mlxkv8eqLchb+TTC1dtkBsUF2CWhh1B0C AXudY0VYO+0Jz0PNoSG0gV0Y410OlUG7MEioweVbxP+FhwaiBT/CsVCVxoCnsld6T4Ej X1Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684769524; x=1687361524; 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=D/v69wjcgQjzqhC98DKwcbYpCW+hDbd/3U2ovkdSDfw=; b=f82gFw7GBNDKrOXc1Qn/DOfzCecOlbwYlv2FRwViaTFNDrkaP8/fnzEVo0+WTDmrHo yb2H/rRrSJgQ4bpfrck2FsMG81U1FVrGDEYbdFVkJGDzYBdGsh6R2DWELivhIIc2o8rQ BjTldXkvECJkd/uVRk6J+Ho+ts3FiwhuEOoLyLYLCh7hWs1F6vPjZRpM7LR2JciTiQNK kM1T0NiVysWS4UYC0cjS2uZ4PtDaBvY8m0xZ99UZlvs9UCtQebI0jv168H2HdN+/JA5g WJz/PsR/LrMtcTZvTLizEue5jUkJfSJy0eFAvOAsgNTTegCmugABKIOCuW5Wsll2LS/Z 8Reg== X-Gm-Message-State: AC+VfDzHbGckKVYMSlLIEGk4FFRaFErVIn22ypKCveL772u5wFFj442r E2LU36hBs3V5O7wunNGaF0kO5xDPyNxCrOQUawY= X-Received: by 2002:a1c:f70e:0:b0:3f4:2b1a:553b with SMTP id v14-20020a1cf70e000000b003f42b1a553bmr7727352wmh.28.1684769524506; Mon, 22 May 2023 08:32:04 -0700 (PDT) Received: from localhost.localdomain ([176.176.153.164]) by smtp.gmail.com with ESMTPSA id o3-20020a1c7503000000b003f09d7b6e20sm8747145wmc.2.2023.05.22.08.32.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 May 2023 08:32:04 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 03/12] util/fifo8: Introduce fifo8_peek_buf() Date: Mon, 22 May 2023 17:31:35 +0200 Message-Id: <20230522153144.30610-4-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230522153144.30610-1-philmd@linaro.org> References: <20230522153144.30610-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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org To be able to poke at FIFO content without popping it, introduce the fifo8_peek_buf() method by factoring common content from fifo8_pop_buf(). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Francisco Iglesias --- include/qemu/fifo8.h | 26 ++++++++++++++++++++++++++ util/fifo8.c | 22 ++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index d0d02bc73d..7acf6d1347 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -93,6 +93,32 @@ uint8_t fifo8_pop(Fifo8 *fifo); */ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); +/** + * fifo8_peek_buf: + * @fifo: FIFO to poke from + * @max: maximum number of bytes to pop + * @numptr: pointer filled with number of bytes returned (can be NULL) + * + * Pop a number of elements from the FIFO up to a maximum of max. The buffer + * containing the popped data is returned. This buffer points directly into + * the FIFO backing store and data is invalidated once any of the fifo8_* APIs + * are called on the FIFO. + * + * The function may return fewer bytes than requested when the data wraps + * around in the ring buffer; in this case only a contiguous part of the data + * is returned. + * + * The number of valid bytes returned is populated in *numptr; will always + * return at least 1 byte. max must not be 0 or greater than the number of + * bytes in the FIFO. + * + * Clients are responsible for checking the availability of requested data + * using fifo8_num_used(). + * + * Returns: A pointer to peekable data. + */ +const uint8_t *fifo8_peek_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); + /** * fifo8_reset: * @fifo: FIFO to reset diff --git a/util/fifo8.c b/util/fifo8.c index 032e985440..e12477843e 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -66,7 +66,8 @@ uint8_t fifo8_pop(Fifo8 *fifo) return ret; } -const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) +static const uint8_t *fifo8_peekpop_buf(Fifo8 *fifo, uint32_t max, + uint32_t *numptr, bool do_pop) { uint8_t *ret; uint32_t num; @@ -74,15 +75,28 @@ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) assert(max > 0 && max <= fifo->num); num = MIN(fifo->capacity - fifo->head, max); ret = &fifo->data[fifo->head]; - fifo->head += num; - fifo->head %= fifo->capacity; - fifo->num -= num; + + if (do_pop) { + fifo->head += num; + fifo->head %= fifo->capacity; + fifo->num -= num; + } if (numptr) { *numptr = num; } return ret; } +const uint8_t *fifo8_peek_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) +{ + return fifo8_peekpop_buf(fifo, max, numptr, false); +} + +const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr) +{ + return fifo8_peekpop_buf(fifo, max, numptr, true); +} + void fifo8_reset(Fifo8 *fifo) { fifo->num = 0; From patchwork Mon May 22 15:31:36 2023 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: 684723 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1262192wrt; Mon, 22 May 2023 08:37:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6k7GVnBL+h7FclZPY40PabV66uxTAUHsw4GazXvQFzDuIal/Um7K24+emJBlNRFIJGEsA+ X-Received: by 2002:ac8:5a93:0:b0:3f6:b505:ec94 with SMTP id c19-20020ac85a93000000b003f6b505ec94mr2119909qtc.17.1684769827504; Mon, 22 May 2023 08:37:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684769827; cv=none; d=google.com; s=arc-20160816; b=bpebzXpp5ElYWxzMk6w/1u/vdefzN6R8z2qRttSDbRGwqFqlnreTl0jDCWelpLkvtf /fJhOzaKhBhDstwQEQ3RH3G2SYhDIlEtBwseBiilfW4E4sscrl97iLhl5Hb7vK+U+v4m 3Ha1TzD0GK+oCarK2PYvTPp0g6qxm4Jwx8Cp+GZIAHFbXuo95XDdcS+xHu6CrqlZBtUW JsFGb6x2AOFMca+L/jqIfZLudRMY1UaptPHTINgcDgCF67weFjHR8qvjQPhyUhNFOTfl aOk0LlG+VIaHwDRf2ZpoG1BpdEvIab/fu85yWXC8r29cqhGd9ZbEBjjLJTmd++juRqlT m0jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DeXq+k+iZcDwEahQV3X8F7cWs5VQQu6bE5Hamux2tak=; b=gnJN7mkGIFW9zuNgD12x9PUdAp/c5xkF2ZbvBiSfoS36laL2Ius64OwqkgI1dmT8TD yGssop6QIB3LHXzrteAX2aXigXZPUp6PkXq/16SxvtvqFjsnCCRF0Qw/oCTOcA5Yco1U j3w4Vv3NubPi2UbeCk/5806ab1x3O0pIA3OVsVBPGSEzSkMoOUjX4VOVhNBPFN4ZhANF B3lMsOdmV78+QuzV0qT0M3lduVjJbt7f3jiH9mYsgVmm/GxHKO7LzBiZ1PfdDCY76b2d /pAg3+HATCuaj54Mec9FgQQNkcrEI0YrtO3IfrKbZFQP42imb1Q3FzVPYPaK4As9B3Pq K1TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TlsPvy9M; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b15-20020a05622a020f00b003eadeb54286si3890402qtx.458.2023.05.22.08.37.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 May 2023 08:37:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TlsPvy9M; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q17Wf-0007dg-GJ; Mon, 22 May 2023 11:32:45 -0400 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 1q17WE-0007Oj-8G for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:21 -0400 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 1q17WB-0001Mf-JT for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:17 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-30a95ec7744so726655f8f.3 for ; Mon, 22 May 2023 08:32:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684769530; x=1687361530; 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=DeXq+k+iZcDwEahQV3X8F7cWs5VQQu6bE5Hamux2tak=; b=TlsPvy9MfS9Tl92mIBU70ctzv29X3LgoBlOL++96iLZmUChBKbFkNb4FhlMw9Ko8XX VmhrgBgpOLJmx1zCjuei/gyAsgRORwDzeHJ63CTjc0lI3AGWPs8idGHISVwrl29eYYy9 b0wzJRFQAsamkNncWQGwxF1bW92OpNs3IcIOAofaJRX6XgAM+TTZs9OZOSJKYJbYKx26 gR6Y5TnwlYJOsaLYTPHqflzOPMRnmgS040pLIDqWt/PaOwdBB5Pk/vwgi68c2Zw58onS +fLGq/LmYkM2H3+SFcWpUAgUn3bRHtm/Q49xR7NjC0UEwyZ/anaVhbA1koOTnxheND04 T6mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684769530; x=1687361530; 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=DeXq+k+iZcDwEahQV3X8F7cWs5VQQu6bE5Hamux2tak=; b=b3tvrVa///k8AdJxfTwGVVbHLJa/B88+VqIDJuORrB8dIp7MxukmJ/8onh4kXzRzUi m4dsLluCjrG+UEuPoiJDmcY+4NoyL0hqmdwFQEhIssKcvu7zO/E2NH+Yq2d68PJETwkj 6GACzuwHZ0XtsrlkncDoIA1zNF5Z9eVyfLl8/sRuAq/QYqlrFZiJ4iI6Iw3Vbr8fqraa IoaQTGCldkki+zgo/6gxV28AlcJYBTtB6E/dhCrafqoSqG0ka+UnWHzy79RoROrYdl8m JdjGsseQxWlP/p1oTFo400y3lbDHiMXdwq2vbzjVFHiF4VtR36lcTgUJ13+EY8PVxSxX pPVA== X-Gm-Message-State: AC+VfDyAXuG921ttGfvRZhtfDWNnK6F37usmrrc9heoiVtCYfpKwvluY F95eGkXmjMmO5ZqNv1lG0MyGW+kNh5+ia5RAJXA= X-Received: by 2002:adf:ce08:0:b0:309:4d12:64e7 with SMTP id p8-20020adfce08000000b003094d1264e7mr9228156wrn.31.1684769530067; Mon, 22 May 2023 08:32:10 -0700 (PDT) Received: from localhost.localdomain ([176.176.153.164]) by smtp.gmail.com with ESMTPSA id y21-20020a7bcd95000000b003f4e8530696sm8629406wmj.46.2023.05.22.08.32.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 May 2023 08:32:09 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 04/12] hw/char/pl011: Display register name in trace events Date: Mon, 22 May 2023 17:31:36 +0200 Message-Id: <20230522153144.30610-5-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230522153144.30610-1-philmd@linaro.org> References: <20230522153144.30610-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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org To avoid knowing the register addresses by heart, display their name along in the trace events. Since the MMIO region is 4K wide (0x1000 bytes), displaying the address with 3 digits is enough, so reduce the address format. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- hw/char/pl011.c | 25 ++++++++++++++++++++++--- hw/char/trace-events | 4 ++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 77bbc2a982..274e48003f 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -51,6 +51,7 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr) #define PL011_INT_TX 0x20 #define PL011_INT_RX 0x10 +/* Flag Register, UARTFR */ #define PL011_FLAG_TXFE 0x80 #define PL011_FLAG_RXFF 0x40 #define PL011_FLAG_TXFF 0x20 @@ -76,6 +77,24 @@ static const unsigned char pl011_id_arm[8] = static const unsigned char pl011_id_luminary[8] = { 0x11, 0x00, 0x18, 0x01, 0x0d, 0xf0, 0x05, 0xb1 }; +static const char *pl011_regname(hwaddr offset) +{ + static const char *const rname[] = { + [0] = "DR", [1] = "RSR", [6] = "FR", [8] = "ILPR", [9] = "IBRD", + [10] = "FBRD", [11] = "LCRH", [12] = "CR", [13] = "IFLS", [14] = "IMSC", + [15] = "RIS", [16] = "MIS", [17] = "ICR", [18] = "DMACR", + }; + unsigned idx = offset >> 2; + + if (idx < ARRAY_SIZE(rname) && rname[idx]) { + return rname[idx]; + } + if (idx >= 0x3f8 && idx <= 0x400) { + return "ID"; + } + return "UNKN"; +} + /* Which bits in the interrupt status matter for each outbound IRQ line ? */ static const uint32_t irqmask[] = { INT_E | INT_MS | INT_RT | INT_TX | INT_RX, /* combined IRQ */ @@ -191,7 +210,7 @@ static uint64_t pl011_read(void *opaque, hwaddr offset, break; } - trace_pl011_read(offset, r); + trace_pl011_read(offset, r, pl011_regname(offset)); return r; } @@ -234,7 +253,7 @@ static void pl011_write(void *opaque, hwaddr offset, PL011State *s = (PL011State *)opaque; unsigned char ch; - trace_pl011_write(offset, value); + trace_pl011_write(offset, value, pl011_regname(offset)); switch (offset >> 2) { case 0: /* UARTDR */ @@ -252,7 +271,7 @@ static void pl011_write(void *opaque, hwaddr offset, case 6: /* UARTFR */ /* Writes to Flag register are ignored. */ break; - case 8: /* UARTUARTILPR */ + case 8: /* UARTILPR */ s->ilpr = value; break; case 9: /* UARTIBRD */ diff --git a/hw/char/trace-events b/hw/char/trace-events index 2ecb36232e..babf4d35ea 100644 --- a/hw/char/trace-events +++ b/hw/char/trace-events @@ -54,9 +54,9 @@ escc_sunmouse_event(int dx, int dy, int buttons_state) "dx=%d dy=%d buttons=0x%0 # pl011.c pl011_irq_state(int level) "irq state %d" -pl011_read(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" +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_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" +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_put_fifo(uint32_t c, int read_count) "new char 0x%x read_count now %d" pl011_put_fifo_full(void) "FIFO now full, RXFF set" From patchwork Mon May 22 15:31:37 2023 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: 684727 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1262493wrt; Mon, 22 May 2023 08:37:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7sR0sWoF4K/t6L1qn6fI/UhRhI7ln9MQxGtfYYJtmbHInyvo0fDJlGKeElC+GIuHejaV7R X-Received: by 2002:ad4:5f87:0:b0:621:78a:dd84 with SMTP id jp7-20020ad45f87000000b00621078add84mr22783446qvb.47.1684769863159; Mon, 22 May 2023 08:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684769863; cv=none; d=google.com; s=arc-20160816; b=laxYvKCWkVpb4PmecXYwm+TcZ2Vowd1tSZAbC/dLRtsxTz/n6w2oUHcanKIBOkWehe ZAywMQBEeFQNCmVcVsbRzTcsQh6ShONznOeuwlHGDwY9VdWeakZDMl96ZNE5h43MUrDT vRMP25IgR++d44bEzDLyVrf2uOd3/bHep57EDjq3zrw632MB+qy43HsFUgiBm/KMQd8Y BYHKGrCkwzcKhqE9xj7mho4MC6alslmkD2c0LR3k/9k25MxHuq29GyiF7VfEWkU7xkar Nixf7BqS7vHk1hApl18BO7Bysy7aYLneiWBtdyyOu10Vv81hNVTB3e1FWNvfzcUyxLBW +LGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tnpVE0KcY4+JRcfuSFzjf1/8d9/S4c9dHftftoYjEBk=; b=NCeUuS+sGg/HC1dxHLq4R8wRt+iIU5ECY2+VZEM6FWvRl21h7n5kDs2tNoc9D6Q9WW xFjRfu4uwVnHjNBqbPuTz2iIb2WrIfRZqiztbUfV8LClJIqX85PsQ2rmy8FCgaGXzi4i D4L6duJ829FGkAAzE6RSygdHJ9fD+PraCRWY/JNBqx/CUixRIP+i7dgy66aGsD6admBs EymrLp5wa7Kl6PyV8x4n0FnLQRuqivZ7inwEeiDVNFdcT3fWOJMIVcXs8p2hzF0LLLRt Dzs6v9mdZLUB9wmyu7OqTOJI88EwANTS2O0HCfhl4n1V/GQF7fa7PjD/ENC0CAZIFd33 bFfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wrPfWhfA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w9-20020a05622a190900b003f6868f8d6csi3832764qtc.353.2023.05.22.08.37.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 May 2023 08:37:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wrPfWhfA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q17Wd-0007bC-Eu; Mon, 22 May 2023 11:32:43 -0400 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 1q17WG-0007QU-TE for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:21 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q17WD-0001Nb-Bx for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:20 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f41d087a84so26344355e9.1 for ; Mon, 22 May 2023 08:32:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684769535; x=1687361535; 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=tnpVE0KcY4+JRcfuSFzjf1/8d9/S4c9dHftftoYjEBk=; b=wrPfWhfARqAZEI26T8s2j5R4+TGHe7B/jSYVvOJNK4gsHgEG6HV9e2eXDLZsT71Jm3 ODoxO7HsYFmg+bgZbiPQGBuxMnmsKfOp6fax0jrPepxdlA3f4rVuRrg6ouctiQ2XmZcm yLNScv4q91N8KvsU4f8RDA3pS9XYR7JCI4JDMv91dyLmtDkOyD54QigtvAJrz3LdgcIe ufPkfT9D2YnIu6/f1TKGetyJ+zImBnwN/heNu6+2RHZXPrWHpLbhBKa5IM9kcWwowD2s AN1CzLtixljLrASPCMmelwfMLD9kgWTVcGmaKtR8+ADS7sFGZaE60Gf7YyAujI3qBL5s Cyfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684769535; x=1687361535; 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=tnpVE0KcY4+JRcfuSFzjf1/8d9/S4c9dHftftoYjEBk=; b=NdPDFKTe0COgOfq48DzfVdNR7IJglEt1dGS/f18gvw/clL5LIbpJRfOob0nmmkf9qE 6CvTzFQzgUBkz/UhXyS6wpTaE2OmgXBvONvUPAFQ+pecGXpuskstgTTtSJftaTyURLPR yRDn5AAhlcl67eDbbamG508YJqqx15eExJ3gaj6LIwPWnSXugiq7xUFDZcPDZzqMTV35 RQVnv3oQYFAulUtnzLk6L4wW3eenRKLdtwx8MKJ6dMHGLB6wv/uPkpQYnxBkILQMJEbt WkJzTEW8kPdJW3JJgVTeGjTNSoR7aZ+dsAVZmOUiOr4EauCTmjMNtURbURqs2t4pR5pH m8rQ== X-Gm-Message-State: AC+VfDxP8bN/WPR8tfhOeO91fseDptcXKGaZno9O0lsbCptnen0ZewGI G7B5z4njkc92hT7XZDNe9qLIW65nq/ms9V91gh8= X-Received: by 2002:a05:600c:3146:b0:3f4:ed2a:4347 with SMTP id h6-20020a05600c314600b003f4ed2a4347mr7854105wmo.16.1684769535492; Mon, 22 May 2023 08:32:15 -0700 (PDT) Received: from localhost.localdomain ([176.176.153.164]) by smtp.gmail.com with ESMTPSA id h19-20020a05600c28d300b003f427cba193sm11884546wmd.41.2023.05.22.08.32.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 May 2023 08:32:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 05/12] hw/char/pl011: Remove duplicated PL011_INT_[RT]X definitions Date: Mon, 22 May 2023 17:31:37 +0200 Message-Id: <20230522153144.30610-6-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230522153144.30610-1-philmd@linaro.org> References: <20230522153144.30610-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=philmd@linaro.org; helo=mail-wm1-x32f.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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org PL011_INT_TX duplicates INT_TX, and PL011_INT_RX INT_RX. Follow other register fields definitions from this file, keep the shorter form. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- hw/char/pl011.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 274e48003f..93e19b2c40 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -48,9 +48,6 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr) return dev; } -#define PL011_INT_TX 0x20 -#define PL011_INT_RX 0x10 - /* Flag Register, UARTFR */ #define PL011_FLAG_TXFE 0x80 #define PL011_FLAG_RXFF 0x40 @@ -157,7 +154,7 @@ static uint64_t pl011_read(void *opaque, hwaddr offset, s->flags |= PL011_FLAG_RXFE; } if (s->read_count == s->read_trigger - 1) - s->int_level &= ~ PL011_INT_RX; + s->int_level &= ~ INT_RX; trace_pl011_read_fifo(s->read_count); s->rsr = c >> 8; pl011_update(s); @@ -262,7 +259,7 @@ static void pl011_write(void *opaque, hwaddr offset, /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ qemu_chr_fe_write_all(&s->chr, &ch, 1); - s->int_level |= PL011_INT_TX; + s->int_level |= INT_TX; pl011_update(s); break; case 1: /* UARTRSR/UARTECR */ @@ -350,7 +347,7 @@ static void pl011_put_fifo(void *opaque, uint32_t value) s->flags |= PL011_FLAG_RXFF; } if (s->read_count == s->read_trigger) { - s->int_level |= PL011_INT_RX; + s->int_level |= INT_RX; pl011_update(s); } } From patchwork Mon May 22 15:31:38 2023 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: 684716 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1260578wrt; Mon, 22 May 2023 08:33:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5mQN+JTsEc6G1BWjETxDAAXO5ND33FBskS8X0Fque+3Xq1IMPRjYMj0zx/RKUIn6p2SZLH X-Received: by 2002:a05:622a:3ce:b0:3f6:b218:deb9 with SMTP id k14-20020a05622a03ce00b003f6b218deb9mr3493714qtx.33.1684769608330; Mon, 22 May 2023 08:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684769608; cv=none; d=google.com; s=arc-20160816; b=fvLLf2Xs/jn9UCgbZ+Vs7y3y/YS6RY6NSpONKLBkU3bq1c9zcl7FKSrqLQI2g7pW/p LBEyIx8US4Hh8fuYDrXnTYnmKE24Np+D+RqKwXVIdvPCesvCr6rWKNPRn09/Mjcrfu0J VO1OBmxWwa0skkYumtKA+1ojNiKdRBByqYOq8NWfz/gmh0aYzH1yqjCOYGHflkyUvzuQ mTFSxnTy/1vHHV3dA+BA74mHc99BHyy99XALgHeRdXyvLSC69ZRorhWWjgrGvy9bZdrB d3lH1Jy3egbZMbiVpC4LbWAeQeSQnbEiXPS/v4sp9DMtsev5APGcql8gWfq3RT9HE4F2 RCrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PcPyr1Hd/Zw7pAX4B7gZfLX+zfoHJG12lzmzj0tU/xY=; b=xGb0T/zf+YOH0SxjVcMf4daKZLIvq2pA1wTMO3W0UdPqSwsA4DNZSlnH6zJzFSV0kI hO7owmMKDhBOck+Q6DV1JhNbV18SXi4w8usxnaNOcP4gtgkP0GBDLuXwaYXc4ECuOGQM RDc+5hXL9qWA4uox5BLG2tpfNNbsecw9/NghyGwycyKj+UysRQg0+4xYVTBhqkROS6go JfEdUcF2mwyraaDAV5DVuQU1v8j49EVKTrgx9IC+9ZDN670IJ4QZcldqRH0hvC+k6y1f f8UM5SDqbNHMhlePNAFEzRZlDHBvZ9TgGy0DT1V4r6CFQmnOzZrmgAWhLfXr8sDLuwYZ 4Dvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hrPWDhgP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b22-20020a05622a021600b003f53624729bsi3891547qtx.57.2023.05.22.08.33.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 May 2023 08:33:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hrPWDhgP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q17We-0007bz-Bw; Mon, 22 May 2023 11:32:44 -0400 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 1q17WS-0007Sp-4U for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:40 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q17WJ-0001QG-Rp for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:31 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3f475366514so42744295e9.2 for ; Mon, 22 May 2023 08:32:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684769541; x=1687361541; 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=PcPyr1Hd/Zw7pAX4B7gZfLX+zfoHJG12lzmzj0tU/xY=; b=hrPWDhgPUFiBuAMhA5CDRbl9BVs8bETJD7pwCAZ5uhag+rdaBUug4RgowQqjaEhxuM +fSrM+tvfbW9e5Cr3eJIY9N0rjM0VQpSrg6QkPETPvt5EWGG5+jGeeLghnx4DzymM+Nu lR/BBDrel+DVWDmU2r/3TLcPzBDppUkfo/pccf/BWPWf+lxGSaDP2hBKILuouM9OuJLc arCCSLhFVSFQMASuCGNHxBnTBBj4ccKzOM2rCsCFMN3Pmpi5CbZh2ypz5pDkPkUlb5sb YLLcYqiwj28v1nUE8NpWeohdHCcnv8yOGJsNuvGG+y4Dke4tQBnRJYZF2ShR+WQBmIfr yN/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684769541; x=1687361541; 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=PcPyr1Hd/Zw7pAX4B7gZfLX+zfoHJG12lzmzj0tU/xY=; b=PgiEgunFpSVbtpxOiom0IiMx9t1hyg9fTmz17as1jrYkaMWGR0BUWC7BRQRMjf0nj4 ifYziSv0pY7XSyC9oiVguQtPED9sIMKkd2ExUkf9QCPOoD1hrRrxbmiUkoEcEMar46b8 3mz8U8Xq9M0zWCt3XKjFbY9+Y6jAigQIFf83nmdlUTKWmCIO71Sk+2sr1+vrMEWJZSKL ERK9HNg4UOiWxNDoCSC+bBMf8BnAIOLEMA6VeRx7r0mH8eKfCOM+AnKQV8KvM/dFp1tp mlWoQrnDVTSbOLH4chWKMFHyzG8JW3WK2c9F47hc0xk7LUj3TGOEZsf6nN4U4Hx5oSCx BxZw== X-Gm-Message-State: AC+VfDyWhhTSDY5UGgmo5coKeQI/RCOJcb/tQfjM3cbyqaLkoQB685cz uc5EnhGlWXldXHXQQ0WJaO2xb235NxtW+KPFHCo= X-Received: by 2002:a05:600c:220a:b0:3f0:b1c9:25d4 with SMTP id z10-20020a05600c220a00b003f0b1c925d4mr7732831wml.21.1684769541121; Mon, 22 May 2023 08:32:21 -0700 (PDT) Received: from localhost.localdomain ([176.176.153.164]) by smtp.gmail.com with ESMTPSA id f20-20020a7bcd14000000b003f17848673fsm8688467wmj.27.2023.05.22.08.32.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 May 2023 08:32:20 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 06/12] hw/char/pl011: Replace magic values by register field definitions Date: Mon, 22 May 2023 17:31:38 +0200 Message-Id: <20230522153144.30610-7-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230522153144.30610-1-philmd@linaro.org> References: <20230522153144.30610-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=philmd@linaro.org; helo=mail-wm1-x32b.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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 0x400 is Data Register Break Error (DR_BE), 0x10 is Line Control Register Fifo Enabled (LCR_FEN) and 0x1 is Send Break (LCR_BRK). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- hw/char/pl011.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 93e19b2c40..98c5268388 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -54,6 +54,9 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr) #define PL011_FLAG_TXFF 0x20 #define PL011_FLAG_RXFE 0x10 +/* Data Register, UARTDR */ +#define DR_BE (1 << 10) + /* Interrupt status bits in UARTRIS, UARTMIS, UARTIMSC */ #define INT_OE (1 << 10) #define INT_BE (1 << 9) @@ -69,6 +72,10 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr) #define INT_E (INT_OE | INT_BE | INT_PE | INT_FE) #define INT_MS (INT_RI | INT_DSR | INT_DCD | INT_CTS) +/* Line Control Register, UARTLCR_H */ +#define LCR_FEN (1 << 4) +#define LCR_BRK (1 << 0) + static const unsigned char pl011_id_arm[8] = { 0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1 }; static const unsigned char pl011_id_luminary[8] = @@ -116,7 +123,7 @@ static void pl011_update(PL011State *s) static bool pl011_is_fifo_enabled(PL011State *s) { - return (s->lcr & 0x10) != 0; + return (s->lcr & LCR_FEN) != 0; } static inline unsigned pl011_get_fifo_depth(PL011State *s) @@ -218,7 +225,7 @@ static void pl011_set_read_trigger(PL011State *s) the threshold. However linux only reads the FIFO in response to an interrupt. Triggering the interrupt when the FIFO is non-empty seems to make things work. */ - if (s->lcr & 0x10) + if (s->lcr & LCR_FEN) s->read_trigger = (s->ifl >> 1) & 0x1c; else #endif @@ -281,11 +288,11 @@ static void pl011_write(void *opaque, hwaddr offset, break; case 11: /* UARTLCR_H */ /* Reset the FIFO state on FIFO enable or disable */ - if ((s->lcr ^ value) & 0x10) { + if ((s->lcr ^ value) & LCR_FEN) { pl011_reset_fifo(s); } - if ((s->lcr ^ value) & 0x1) { - int break_enable = value & 0x1; + if ((s->lcr ^ value) & LCR_BRK) { + int break_enable = value & LCR_BRK; qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_BREAK, &break_enable); } @@ -359,8 +366,9 @@ static void pl011_receive(void *opaque, const uint8_t *buf, int size) static void pl011_event(void *opaque, QEMUChrEvent event) { - if (event == CHR_EVENT_BREAK) - pl011_put_fifo(opaque, 0x400); + if (event == CHR_EVENT_BREAK) { + pl011_put_fifo(opaque, DR_BE); + } } static void pl011_clock_update(void *opaque, ClockEvent event) From patchwork Mon May 22 15:31:39 2023 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: 684724 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1262304wrt; Mon, 22 May 2023 08:37:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7QLLvayibRz3B0x5XwthV8+4nlJXmqZIULuYJeOPzQJBXQpus3J36TjONyY9vMeyckHcPd X-Received: by 2002:a05:6214:413:b0:616:5f27:b96a with SMTP id z19-20020a056214041300b006165f27b96amr22368156qvx.27.1684769841542; Mon, 22 May 2023 08:37:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684769841; cv=none; d=google.com; s=arc-20160816; b=AcUhLXGHLvrmHvdNA+6vPbkMjon5lWJCzpzCO2Ql29Sb7sdOoLuLuJfrTPd3mYVIr2 CkiSVyP4gsg5ZYnvv4H9AOom0MEn72EfBaFn4P2wkjMLTFErtL11yw3mPgeqvoD3ksg2 9kTOW9qet9rlNMAWKsPOZdrWxihqg7rF1A0KMdQnqpp55U4Hy5rZgugdL46tXZyunDO0 tBHU5CEKe8WnfoUP5JD1ABQeFimB4WvAwOQGR1uPawvFe0v6YcTvNlsBXjO5CdF2/OPF 9XSqNKgCwhW7gMs4k8D/G5brHNo86FO39bk0n2AxHeWNsURfzL/aIfHR9N78gXSy5af3 FtLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=256qRxVoRgmn8ZQNw96BSPjzs8Oo5GL3PGwhSL7cRNw=; b=HD8NbR/jvYLXG82Z2EKsuEZqWlC2ZbBos0IryK7y3yBQh2SJszE1lv0093uXFLVPlf BmpQuWffH6NEQo7gITLS2HkK7Wd13q0XOoiPPDXpzT6xwEJET7aDKmSQQ1dz4bxcgaUd srC8jhop1RZ8reQBlz2i4b+gYjIaOomCxet3iWRrENYxWOplRpFE27HzhbJXFd5/RmHq m0PjqXa/b43JXD4ZBzVLAJFtQD3DRB/qpdqIZ+lL6PzwKzIbAOI2APGsQpfNI9E8Rc3x Wz6RekFHj+ikws9KOwvhraHGrERMbhoWFFz9uFc/2xo6UHhM85QDnKAi9qkh3p9NAQBN a2sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="C/t7JMkQ"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d8-20020a05622a100800b003ea63719f0fsi3750806qte.611.2023.05.22.08.37.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 May 2023 08:37:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="C/t7JMkQ"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q17We-0007cB-Gj; Mon, 22 May 2023 11:32:44 -0400 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 1q17Wa-0007Uu-WD for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:41 -0400 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 1q17WP-0001RU-J8 for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:36 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f606912ebaso9303235e9.3 for ; Mon, 22 May 2023 08:32:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684769546; x=1687361546; 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=256qRxVoRgmn8ZQNw96BSPjzs8Oo5GL3PGwhSL7cRNw=; b=C/t7JMkQsTbjpIgJ59MHwv63ucFDE2WtK1AE0dsf4JCAAsNUrp1pDlOCrmtxwNAj+C oceIXdKSpx4vUBXmKDLfyQ+5HS+At35HtKg2gvcngba7a/Lzav1Jvpv7XGm969IfTPKc lh2eTjhN3LR5TiRFc3LSSFTVtFhLGmUPEmwd7xIC+rcCrEjG46BtGVY9L3KlhU26iMxw JCv4Lu5Xx+PjGfWP86KsSoMROJ14gykSKxfg4Jkbvcv1xGpblT1+KdtLfCwft61nCPVX n/NBbkh4uHNUUC/CjtuAokQbW7UQTZu7tv9rUWGkpX3Px2K1MiFXZEzchZTE26af3RZy k57w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684769546; x=1687361546; 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=256qRxVoRgmn8ZQNw96BSPjzs8Oo5GL3PGwhSL7cRNw=; b=jGa+kwnUivsN0UlyBum8r609n9WLig9jdOPFvRJAfm22xRXoClQPLyl8bDk/Lx1xMK FXRlQx0HuPNpktlC3Q+vL93BzyA3wA/qkcZNBvXS8+eCSwPwOUGrcCWZRwiOd46nmn1y RAffMP1FwcbZG9b8XCH7Cjuvf/M8C37MKCVOk0t6xQgK69SllvklM2gHHcQHFjjT8ik+ iBEkwACzEsrEnx2g5CEVmHWvCKdSB4sjCa2Vtp6LXHZfZbCjYkrxGQi1CyUCYBGIawM6 +b4PrtqhUt2pbtSPJFvmTjroqOQdFD5iZNapufjjW0/qRVqLuH3Fibhu8beN3uQueTgO HwGw== X-Gm-Message-State: AC+VfDxWpH476QPo/LHGZtZMQ6h6jv2mtYsxYeXnaJxzUjcCj6QdGfbB jEZZMQR3aYZBl022SI4BLyh8ciuft8/VOeLIi7c= X-Received: by 2002:a7b:cc8e:0:b0:3f6:89a:94c8 with SMTP id p14-20020a7bcc8e000000b003f6089a94c8mr658221wma.24.1684769546718; Mon, 22 May 2023 08:32:26 -0700 (PDT) Received: from localhost.localdomain ([176.176.153.164]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c229200b003f42d8dd7d1sm12078857wmf.7.2023.05.22.08.32.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 May 2023 08:32:26 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 07/12] hw/char/pl011: Split RX/TX path of pl011_reset_fifo() Date: Mon, 22 May 2023 17:31:39 +0200 Message-Id: <20230522153144.30610-8-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230522153144.30610-1-philmd@linaro.org> References: <20230522153144.30610-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_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org To be able to reset the RX or TX FIFO separately, split pl011_reset_fifo() in two. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- hw/char/pl011.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 98c5268388..f0b305e5d7 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -132,14 +132,21 @@ static inline unsigned pl011_get_fifo_depth(PL011State *s) return pl011_is_fifo_enabled(s) ? PL011_FIFO_DEPTH : 1; } -static inline void pl011_reset_fifo(PL011State *s) +static inline void pl011_reset_rx_fifo(PL011State *s) { s->read_count = 0; s->read_pos = 0; /* Reset FIFO flags */ - s->flags &= ~(PL011_FLAG_RXFF | PL011_FLAG_TXFF); - s->flags |= PL011_FLAG_RXFE | PL011_FLAG_TXFE; + s->flags &= ~PL011_FLAG_RXFF; + s->flags |= PL011_FLAG_RXFE; +} + +static inline void pl011_reset_tx_fifo(PL011State *s) +{ + /* Reset FIFO flags */ + s->flags &= ~PL011_FLAG_TXFF; + s->flags |= PL011_FLAG_TXFE; } static uint64_t pl011_read(void *opaque, hwaddr offset, @@ -289,7 +296,8 @@ 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) & LCR_FEN) { - pl011_reset_fifo(s); + pl011_reset_rx_fifo(s); + pl011_reset_tx_fifo(s); } if ((s->lcr ^ value) & LCR_BRK) { int break_enable = value & LCR_BRK; @@ -504,7 +512,8 @@ static void pl011_reset(DeviceState *dev) s->ifl = 0x12; s->cr = 0x300; s->flags = 0; - pl011_reset_fifo(s); + pl011_reset_rx_fifo(s); + pl011_reset_tx_fifo(s); } static void pl011_class_init(ObjectClass *oc, void *data) From patchwork Mon May 22 15:31:40 2023 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: 684719 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1261559wrt; Mon, 22 May 2023 08:35:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4nMZUIOa0ECQLNq83lZ/JYs4Fq06GBAKVEpQprVHEguLNXGxIl6olM3Dk8fllx3pHApr2A X-Received: by 2002:a37:f614:0:b0:75b:23a1:433 with SMTP id y20-20020a37f614000000b0075b23a10433mr1026482qkj.73.1684769743347; Mon, 22 May 2023 08:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684769743; cv=none; d=google.com; s=arc-20160816; b=dEPz/A3dH6fO10CrMQ9qEnYyZXFf+Z2UvFcapkM0dKAYrdG+kOyYV9q244J7pW6Y+N /wsCKn41IbPLyzRFDaffwfhL8nHXAjoN6wMy+bhtogKtDynWoh3uQblIhJiQI/jsDdS/ qC2+ge2OXW8W5Z6a0inOv36ABIAJ7A8wUKLudUzUJKJmxBzzWj+N7I2ITac+teq2aMBv FX1gm92Ak3/6XwG/fQXTISE0Cq0gdD2b2xOOzpcZeP2ng5hRktjCXCKKifXT0CjwPjR+ xCsXzsfKciR+w93dT0fNPsMq5dSu9QQt0WH5kCzgqoOv/mLSZ2bLhtwQDGAw+jtW1b4q uRUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9q108c2Lliqjn2JXt6hPBTH1oW++ckhJeDwIAiOICrs=; b=Gm+LQN4yC5XQZOdKn2HEBSkhW836fURLe1j41fWwDynSP0JQXhHg3upQdWP3dhZBb3 Ul3y7DY3DfxoDy5AZd78bc8oYBAg0SQ1NvMbh2bmIyBT1MSn+A0Z62s7UAiM8iw5Tc5d n/FmPRVr55+A4HFDhCa9MQB73Havkh4ZzR/OF+2iovZlkVFc62xEfHQ8Wc9QvkigKcnW ZyuPob/I5lQJ/Mjzw5kW/p0rvrUOjWfmj3QOf8rISAamCAg0A4GS1NJ20F6sdz3Ygaey mF0QTUy6nx+bhl7MpcP9MFejUfCqLFd6691F2boR05YWof40JcStEcDWpepC7JFexs9o 8SAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IMHyvW6b; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m11-20020a05620a13ab00b0075533d216c1si3583621qki.57.2023.05.22.08.35.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 May 2023 08:35:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IMHyvW6b; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q17Wh-0007fH-0Z; Mon, 22 May 2023 11:32:47 -0400 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 1q17WV-0007TB-LU for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:40 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q17WU-0001Sb-2G for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:35 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f42c86543bso40693915e9.3 for ; Mon, 22 May 2023 08:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684769552; x=1687361552; 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=9q108c2Lliqjn2JXt6hPBTH1oW++ckhJeDwIAiOICrs=; b=IMHyvW6b41w7xSQpLSpQKb/8I2BRZydodmSpCk/NRscgvzIhUtZMGKq5KcvWaFEhOk Kq70ExoxrZc3in+/b0WTJVRJTql9fCnKjgwxk4UTIBsCmo/ZqBTLH/PGLV9bspkR7JCU QucW5H14V+L+xxo2ZQnmqRjlxK7vHItTLcDcyrYvBAtTI3fmQEs+ZFEVvJCGDV7F2SH4 NcXQLKdGt6NfS5pCmdLaVvxNp82i5dkrT6AtUuyRlBW3pxd++Km/O4C9lG9/bC3sbco+ K/0d97xu9qcqWdRqZ+z/QdH9D1XUPeSqJAu8WUoEDLCbpYnZD5c2NowZnrPpSDZC1weZ xLZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684769552; x=1687361552; 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=9q108c2Lliqjn2JXt6hPBTH1oW++ckhJeDwIAiOICrs=; b=Th8hVQ5flf9+2tDFVQutLUh2zJErXMMNZiIhYdY1WhzHa+JZjYRJ+elw1WLtWYCkQf HbyAqvg2lAcCULmmKxBxBMhH5ttqqdu4wVCoMwhG+/7/OWUD/MDhm3sbzGroM9aU+qEg Y3yDZxlwuxqJzeSSUYavpE6i3hgeaq1HQQygYhTxryXUR4oaGb7zcipcmBkUdVV7ajO5 DCUl0zzPHWb9yvhij18NPkG59U8EkfTUWc7mIPpRjtJntntHqlHOvqfpg5TP70LKaqPB p5j962SqVrRdVwO+vLg0H1ZjE/GIbCQceTqJ1UwPvty1yMRSprnMoXoPE1dVtx0nmQdo OxSg== X-Gm-Message-State: AC+VfDwfF8hmxnUhv39QVk2b/aC80SURN5uLfnsv/a7JTvJ/VqdV8wnQ Wl+9sHf1+oDlg3mVTPGZ0MDvgnXwFPFeF5Ue7PM= X-Received: by 2002:adf:dcc7:0:b0:309:32d1:59d8 with SMTP id x7-20020adfdcc7000000b0030932d159d8mr7907619wrm.64.1684769552397; Mon, 22 May 2023 08:32:32 -0700 (PDT) Received: from localhost.localdomain ([176.176.153.164]) by smtp.gmail.com with ESMTPSA id o14-20020a5d670e000000b003062b2c5255sm7999526wru.40.2023.05.22.08.32.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 May 2023 08:32:32 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 08/12] hw/char/pl011: Extract pl011_write_tx() from pl011_write() Date: Mon, 22 May 2023 17:31:40 +0200 Message-Id: <20230522153144.30610-9-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230522153144.30610-1-philmd@linaro.org> References: <20230522153144.30610-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org When implementing FIFO, this code will become more complex. Start by factoring it out to a new pl011_write_tx() function. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- hw/char/pl011.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index f0b305e5d7..c55ef41fbf 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -149,6 +149,17 @@ static inline void pl011_reset_tx_fifo(PL011State *s) s->flags |= PL011_FLAG_TXFE; } +static void pl011_write_tx(PL011State *s, const uint8_t *buf, int length) +{ + /* ??? Check if transmitter is enabled. */ + + /* XXX this blocks entire thread. Rewrite to use + * qemu_chr_fe_write and background I/O callbacks */ + qemu_chr_fe_write_all(&s->chr, buf, 1); + s->int_level |= INT_TX; + pl011_update(s); +} + static uint64_t pl011_read(void *opaque, hwaddr offset, unsigned size) { @@ -262,19 +273,12 @@ static void pl011_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { PL011State *s = (PL011State *)opaque; - unsigned char ch; trace_pl011_write(offset, value, pl011_regname(offset)); switch (offset >> 2) { case 0: /* UARTDR */ - /* ??? Check if transmitter is enabled. */ - ch = value; - /* XXX this blocks entire thread. Rewrite to use - * qemu_chr_fe_write and background I/O callbacks */ - qemu_chr_fe_write_all(&s->chr, &ch, 1); - s->int_level |= INT_TX; - pl011_update(s); + pl011_write_tx(s, (uint8_t *) &value, 1); break; case 1: /* UARTRSR/UARTECR */ s->rsr = 0; From patchwork Mon May 22 15:31:41 2023 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: 684728 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1262501wrt; Mon, 22 May 2023 08:37:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Vuelk7bsRSnEfAgS3uGypUpp1lc0tz3Wfdigrh0NJMc7mRellfiQkrQ8mE7ZRaB4eBpt1 X-Received: by 2002:ac8:5a93:0:b0:3f6:b505:ec94 with SMTP id c19-20020ac85a93000000b003f6b505ec94mr2122331qtc.17.1684769863647; Mon, 22 May 2023 08:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684769863; cv=none; d=google.com; s=arc-20160816; b=Lj8e5NaTGI4wAwFkKRpsdbadfsXMGu0vRD6uVJ8fiq3JZ+S7SlMDeCWnJTDDNos+iv cTWHdGWENlkYMEgirEa0fRxwNEextT1xDhhs1D9vyJvYxSPDIjU6M5vqG7AiNIHs4f2G 5Hgx+3yjTW9WTWi8n5uKVGxEqGYnIHV9RUS7Nbv7pL/AzUTTcLBCva0teTKnmRML8d/m Lb6MtPgwLVaFLhOZxhCme74OwdZbuFfGVUqlWLJ/fes64ZnU3KgLb6strrhcKENjj1+f pPVjVc8t7colYDqSQrn4qs7Hg1PfsuwWhxdxBU9HsYW36JBVg7/r2TNba2afZnIO0V7P jmMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zbYgJ/CF6X8oXk1c18I3fiTWkENuu1esnlnJzdOgw0U=; b=xo7phwQ++8oU+4Le+0S+FTE9WNJ1qEGj0PhL3tnV1a14yXo0fHAaBq/kcBYswo7L61 a/D7q1qsWTE18MFswyC0Up4f3yY9VnbobjTkr7QRPWhmixlLDk/0rb/Nu2qw64Us5G/h wyY87s+BlsI9HEVj13FgLBC+DBFLVP33wQXR6MsMvIyflab7c5Z3qL567ulM6V8T39fR QEHAY6nvxO4INQtl8BpOIkeZgeT+ysULWExadbX1O8cPhBscGcJEbNlqu7cVR958BV2D HaHufAzrnqTBNtXiYPD03yNVrM9upc1BI7nxDBcu7vGGX3BRDNkYv/J+1BF77SW+KOJT ecJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sQTsuO1+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d8-20020a05622a100800b003ea63719f0fsi3751250qte.611.2023.05.22.08.37.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 May 2023 08:37:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sQTsuO1+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q17Wd-0007bF-HK; Mon, 22 May 2023 11:32:43 -0400 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 1q17Wc-0007Z7-6b for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:42 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q17Wa-0001Tm-H5 for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:41 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3078d1c8828so5996737f8f.3 for ; Mon, 22 May 2023 08:32:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684769558; x=1687361558; 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=zbYgJ/CF6X8oXk1c18I3fiTWkENuu1esnlnJzdOgw0U=; b=sQTsuO1+IR3wG1880nFla6zQQ4pT1gMu2cJlzad94PzBKPVJQZ1U+TWNTTNFvSXnEk S5E+9kvIAUfjTOolpryQJJLDJaL4mkJ5AK3rL5Gd1X3q+j1KYU/ivJH5OScWV+fEDSvv /IWAEWg/EpFl/t/nb1SmEBVCbuqMW7cEKesoiLB1uF1B2iJczBnDt+bzz3tBXpu0WM9R Thwuq0eIgb36ABh/BtBlJYuMSM+pYVEsjStML30tSr7ngWXXZ5tHnQB+z3Lx10VhZUW7 qhQylGRGA5IJT1WBRbw1Atx4k0whDA2qDQM7BrQiPDZfgDRkVNyylKwexiX121ORirQ2 v1Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684769558; x=1687361558; 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=zbYgJ/CF6X8oXk1c18I3fiTWkENuu1esnlnJzdOgw0U=; b=MTXd2qiItqTS0RAUX8OxAPNCQ04yDqvtcL7BsUlQy+6G0W2WNhD9TwISwZhcXnlDbG ZidpUS+6Z/AmuH8udgdGt3QzEhbN6o/4R3W3c88XwftacositUZmRZa0N8FjVHbTMkP+ FtkGbg9FPA6PrrO/9ohd69n5V8u9jB+KidZY8uDOroTP8mNCFuo3Fr63syNfk+Lq7zP5 gs4tFeQSpPN3uvWALRqii6SaWTD4JvpiKO4itGLm7G54qBrQ1oe44yaRO/bHmBUpDwx3 8x48TEGEQcqg3FlGw1p3/AFacYBDwabzh8px9nJMxELeZ2OfI5uVs3jJQWsElM9b5mjz MaZw== X-Gm-Message-State: AC+VfDzEIkI85/82ONlsRa6awuJtExRCiHxTT883nnqw1gvM6FG5Qyjl yO+sxwTlJ/PPqOVcKzO8sLlpI47aATC/oOxW3ss= X-Received: by 2002:a5d:44cf:0:b0:309:54b6:33b0 with SMTP id z15-20020a5d44cf000000b0030954b633b0mr7758639wrr.44.1684769557960; Mon, 22 May 2023 08:32:37 -0700 (PDT) Received: from localhost.localdomain ([176.176.153.164]) by smtp.gmail.com with ESMTPSA id f15-20020a0560001b0f00b00307acec258esm8082350wrz.3.2023.05.22.08.32.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 May 2023 08:32:37 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 09/12] hw/char/pl011: Check if transmitter is enabled Date: Mon, 22 May 2023 17:31:41 +0200 Message-Id: <20230522153144.30610-10-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230522153144.30610-1-philmd@linaro.org> References: <20230522153144.30610-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=philmd@linaro.org; helo=mail-wr1-x435.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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Do not transmit characters when UART or transmitter are disabled. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- hw/char/pl011.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index c55ef41fbf..30bedeac15 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -76,6 +76,10 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr) #define LCR_FEN (1 << 4) #define LCR_BRK (1 << 0) +/* Control Register, UARTCR */ +#define CR_TXE (1 << 8) +#define CR_UARTEN (1 << 0) + static const unsigned char pl011_id_arm[8] = { 0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1 }; static const unsigned char pl011_id_luminary[8] = @@ -151,7 +155,9 @@ static inline void pl011_reset_tx_fifo(PL011State *s) static void pl011_write_tx(PL011State *s, const uint8_t *buf, int length) { - /* ??? Check if transmitter is enabled. */ + if (!(s->cr & (CR_UARTEN | CR_TXE))) { + return; + } /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ From patchwork Mon May 22 15:31:42 2023 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: 684722 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1261964wrt; Mon, 22 May 2023 08:36:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ70n0N+gn6NwcsPfPGSNvb2a7wn8UkoUTwbiBxfEn6ndi92NoWZ4wjakv6VudjJ8MMg/huN X-Received: by 2002:a05:622a:64e:b0:3e3:7e6f:423c with SMTP id a14-20020a05622a064e00b003e37e6f423cmr18130127qtb.34.1684769794914; Mon, 22 May 2023 08:36:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684769794; cv=none; d=google.com; s=arc-20160816; b=szpsA4HyIQRG9/lscWIyd1DVXFgjk0EHvHvHnfwJcpk4JKdSS5khg7dhSiXDSGCNy0 wk2jmzqr80XQsBh8EMV24ifwFbS3o++bzTuQfxKS4opNUvTExqptulL+/OwEDiZDw7YE 8WHaEmXpjCPoEjupnzSH1A6cbYnlJoWb2Y/SXEmXr5tKrSP8JUGlBsIkiMSy3ktvYgtG vH1RF/w6wu5wmuE5i9mrZWOW3MOiwWdm8yBA6Ok9oDouZ/uNBQnEm+6dPviEYcC44ydh nkDofq5DyBbIctM2+0Z7RtS3zUmdE+8oImiujxaiAHOyjrzjNELCAqdwWo/wxtnReoVE TPxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0Cw30KRr0qwwjcjVLXiu2a6Jw/GDPIIDdtlKN9G+WEg=; b=w98W44GSWW+RiMH/8dLI8d+uEU4FaxluhVgkrH5f+JwNXUbRhNNjs7AEOpDeG+Q1Mt NSfnAskijjXJj9NocfHKgJyrJXoUhJAdQ7CcaqI+63+Q2wyV/fd/wLXc6x9VVut/r7bQ ZaaqXFXKmwH3VowO+CZsIjIf9qmLpFE0aszOMPcvGIF/13Dk138oXbys/MLXAImQM3Ic W7sVUtQKAZbeCqNh+wC9TBwhkCTgwIuf9upa/WNcpxKfFW7BorZDebs7dg9A4qFr9lhl ZwGGuVwnDocSfccDN3iFcOj5WkSWZGjjFCXg44ajP7zIdK6hYaw1lqdKrHRlTtFCpQeC x4OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jZVIhtxg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y8-20020a05622a164800b003f43703b305si3746507qtj.714.2023.05.22.08.36.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 May 2023 08:36:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jZVIhtxg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q17Wi-0007hu-CD; Mon, 22 May 2023 11:32:48 -0400 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 1q17Wh-0007fR-0B for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:47 -0400 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 1q17Wf-0001W1-5N for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:46 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3f606a89795so8951065e9.2 for ; Mon, 22 May 2023 08:32:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684769563; x=1687361563; 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=0Cw30KRr0qwwjcjVLXiu2a6Jw/GDPIIDdtlKN9G+WEg=; b=jZVIhtxgsZKCPAyVJ1rubFhXRwSyB8yBf951IXSK22A8pvhlLdv9fEUSwo8Md8NWYg Fdgor+NAr64RrgZ+I653NYWxogB3UAB0pJQVVpsKh1gBDJqW3az+RCeMONd8U/cI8z+h SyS0IGSDNWx5h0Wdg5PaTsEsmUgg0gLB2GomrRRN9Pq4kIExCWsgDrRFhH/YFIw9234z BJYmoNeW8LkTcQ/xWT4BE1pLU6XpJMKTmZgdVfNmZrrGibgtwqMLOC4KlQkvHCU+yDd/ giRI1DsGTdZp9YkuRb3sVO7arCM0qlqHOfZwBKEQW+CueT00kbQxWyEsWqQThmwYnepE Jraw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684769563; x=1687361563; 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=0Cw30KRr0qwwjcjVLXiu2a6Jw/GDPIIDdtlKN9G+WEg=; b=jgwOXxmTIa3H8AiwChXtXaxvWHFR3dMb0YXHYWW9NuVtLEFhAzsU1j8mIb8N2rzgZb hSsrBQgK8AJVAncja4rkb4ehCpiXHRmoYe4Yboz8wnG1yKja+aHxZff1X1GCWqHsumth FN7G59gdQwZqNLm4lfmIUWsrS55xTTFD/7hZsR5KRaK42XhHiPy2DkLVoAcUMHsJyPwp +0jYOfpSwHK/9uYdMzCnM22bdlbTh69tMIWaa3zklaJncdjCrNrkNJp8+oSBI2Id/4vE cqLuFUELCbYJ/5BIt7s2k2uZO7yMK15LNp23eMBNTGF2dOzYttq12eGam1ATDOWTnII/ yh7A== X-Gm-Message-State: AC+VfDwRu48L5XrmVHf7jrORldPV76SKIk4itYw0Bz1pAsiPec0P19VA HepdClA/XzHPNdLuhcJEcykKs64mpw0YMZTp8cg= X-Received: by 2002:a05:600c:22d7:b0:3f6:8f5:f9e4 with SMTP id 23-20020a05600c22d700b003f608f5f9e4mr200948wmg.35.1684769563339; Mon, 22 May 2023 08:32:43 -0700 (PDT) Received: from localhost.localdomain ([176.176.153.164]) by smtp.gmail.com with ESMTPSA id j17-20020adfea51000000b003063938bf7bsm8019037wrn.86.2023.05.22.08.32.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 May 2023 08:32:43 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 10/12] hw/char/pl011: Check if receiver is enabled Date: Mon, 22 May 2023 17:31:42 +0200 Message-Id: <20230522153144.30610-11-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230522153144.30610-1-philmd@linaro.org> References: <20230522153144.30610-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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Do not receive characters when UART or receiver are disabled. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- hw/char/pl011.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 30bedeac15..1ec102d8de 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -77,6 +77,7 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr) #define LCR_BRK (1 << 0) /* Control Register, UARTCR */ +#define CR_RXE (1 << 9) #define CR_TXE (1 << 8) #define CR_UARTEN (1 << 0) @@ -348,9 +349,11 @@ static void pl011_write(void *opaque, hwaddr offset, static int pl011_can_receive(void *opaque) { PL011State *s = (PL011State *)opaque; - int r; + int r = 0; - r = s->read_count < pl011_get_fifo_depth(s); + if (s->cr & (CR_UARTEN | CR_RXE)) { + r = s->read_count < pl011_get_fifo_depth(s); + } trace_pl011_can_receive(s->lcr, s->read_count, r); return r; } From patchwork Mon May 22 15:31:43 2023 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: 684725 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1262339wrt; Mon, 22 May 2023 08:37:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Al8+0leIS4lpac2QYrJPhe4DR+jJLE9tvSewuPrVGAGTDUWoY1n2YNZ/TBAo1wfnQ0lUk X-Received: by 2002:a05:6214:2aac:b0:621:53d1:3c69 with SMTP id js12-20020a0562142aac00b0062153d13c69mr17661843qvb.20.1684769845052; Mon, 22 May 2023 08:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684769845; cv=none; d=google.com; s=arc-20160816; b=AdrExzkDKBC4BFoP0KW75aBUPKfpgUYCVU1rKhoAJ97No6o241rPRjifXDR5sGA6Hk c+h0DbLfACVxQjje0CbI/qCz+l8ixfRp5n6KURY0mLNdOiw+Xfh70YitVSqMly+LnF8l XhdY7ZR/1OLCXDrY0tA9fW9FVSakWszC3WGsgdx46+WmUJ5jA4FbQZ+AhOl2Drq4nRK7 5ZZeJSFejbi6GL6q2h4YlfXP0tYUW+izK0VYbdVymgCJDtkVRYgpOfPmyvTfJXi2B2/d NuCPMVZMIxIlDD/7Xi62AkxZfeDnDKhn6yG6LhR7esoqC63TdiqemKgZNpRm12U9FVwf 8l+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=A4NEdvvVpuVzw0Qn5uC2iypDr0fWHEDLqqeZGtVwP7o=; b=uQNQb1EhWf06tXZqI7byTbmBB6uCgijc3g4/m3TCTU1WwnCs+sTaO5WN9cD+uU1pYY u12TIz7lxRLGCa/lxl1vG/b6Rwb1McOtGJXQIE+eDkjfKEdOHQSK3hL75+zG1WDw/zS+ G2hvX/QqDTCAVdp0sz9NjzYMMR2ykUK/JIlFUfqjhnKn000fvQb6TNo4kbHk6DXSrBUX sQm8OMV5VM+rj+Lm9HoV38nmXBIOClbMUjaisHXhZsxY9s3P6Ww6EkcaXd+d1IzD5Unx txdyNS+AhXublhXUeQT5/iLmjiUUfX9Ac7uHHajMVkbufcw1rHABqwkPq50WGwK8SW9j N32A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="bb/CPJDl"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id pt15-20020a056214048f00b005a295abc1bbsi3878056qvb.333.2023.05.22.08.37.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 May 2023 08:37:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="bb/CPJDl"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q17Ws-0007l6-8a; Mon, 22 May 2023 11:32:58 -0400 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 1q17Wo-0007kN-8T for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:54 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q17Wk-0001WZ-HW for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:53 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3078cc99232so5978155f8f.3 for ; Mon, 22 May 2023 08:32:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684769569; x=1687361569; 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=A4NEdvvVpuVzw0Qn5uC2iypDr0fWHEDLqqeZGtVwP7o=; b=bb/CPJDlZE3O8+Gr6hYx0FTiPCVvThuj/wbwKpHTQ6taKkcCafnD0RUUdXqgOQdTfP vZCL5mKUV0TGhagPeetazHKAhjwh94/TFmOWrB8v4jzILm0YXtNmfob0TPTIXiuoGWWE 7n77wj/R4gFxkF0YA9mygsxMHho1a6ZQYDJjiKJmktaGifNR2O8yKOxE28imuCglHntg xmm0obzCX/wASoYmjRYiDAY2IicsVSfmsI13NXleKZ2tWDi0O2+Mq12rk7xK3Gbplm2M zK5ykPaLQZzpoH++aPOQ5vr4TmnuqgYpmAwQBGmy3e12PRbVB6yakD7jCmm11a3suFbr mWaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684769569; x=1687361569; 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=A4NEdvvVpuVzw0Qn5uC2iypDr0fWHEDLqqeZGtVwP7o=; b=dbiCkvMc+2VzJxfnPw/t9aaefKhzg6tdm2JEe/d2RxFIYcUHlVUrDZjJN8SEr853dc Imm1Lj5CxmxGHpC+hVeW987HbGONp5J4wq33dErJFbWaZJx1T86n284DCG2UoJiy5zy8 89mxg0R+2Rul5EZWFWQRqYvR9tz++DCODIdJ4LAIyaJcM0NCCOYUcsubzBFamd6a/KHu XKzJDT/AOaX89fvsX4VLZcvYXHSe9GFEgWl/qPDuyicKfwRoHpKseU+9nl0c0DRj7Yxm JPa8HHBTGZJ6nAt7LN4JfsXc1CGbeRomXu6d/f18wieOmaxu77G7G+YYcecumtxxBjxx cz8g== X-Gm-Message-State: AC+VfDxf6GrD8Rs7Q15Yhgizp0xIapblhMjV2/fPBc3h+XcXkWN1O1KL /qkfyL85uyL5PeuCivGwIEv7jEEgkiO0oCp64y4= X-Received: by 2002:adf:cf11:0:b0:306:36b5:8ada with SMTP id o17-20020adfcf11000000b0030636b58adamr7958771wrj.29.1684769568907; Mon, 22 May 2023 08:32:48 -0700 (PDT) Received: from localhost.localdomain ([176.176.153.164]) by smtp.gmail.com with ESMTPSA id y11-20020adff6cb000000b003063a1cdaf2sm8046868wrp.48.2023.05.22.08.32.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 May 2023 08:32:48 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 11/12] hw/char/pl011: Rename RX FIFO methods Date: Mon, 22 May 2023 17:31:43 +0200 Message-Id: <20230522153144.30610-12-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230522153144.30610-1-philmd@linaro.org> References: <20230522153144.30610-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=philmd@linaro.org; helo=mail-wr1-x431.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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In preparation of having a TX FIFO, rename the RX FIFO methods. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- hw/char/pl011.c | 10 +++++----- hw/char/trace-events | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 1ec102d8de..03c006199e 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -358,7 +358,7 @@ static int pl011_can_receive(void *opaque) return r; } -static void pl011_put_fifo(void *opaque, uint32_t value) +static void pl011_fifo_rx_put(void *opaque, uint32_t value) { PL011State *s = (PL011State *)opaque; int slot; @@ -369,9 +369,9 @@ static void pl011_put_fifo(void *opaque, uint32_t value) s->read_fifo[slot] = value; s->read_count++; s->flags &= ~PL011_FLAG_RXFE; - trace_pl011_put_fifo(value, s->read_count); + trace_pl011_fifo_rx_put(value, s->read_count); if (s->read_count == pipe_depth) { - trace_pl011_put_fifo_full(); + trace_pl011_fifo_rx_full(); s->flags |= PL011_FLAG_RXFF; } if (s->read_count == s->read_trigger) { @@ -382,13 +382,13 @@ static void pl011_put_fifo(void *opaque, uint32_t value) static void pl011_receive(void *opaque, const uint8_t *buf, int size) { - pl011_put_fifo(opaque, *buf); + pl011_fifo_rx_put(opaque, *buf); } static void pl011_event(void *opaque, QEMUChrEvent event) { if (event == CHR_EVENT_BREAK) { - pl011_put_fifo(opaque, DR_BE); + pl011_fifo_rx_put(opaque, DR_BE); } } diff --git a/hw/char/trace-events b/hw/char/trace-events index babf4d35ea..9fd40e3aae 100644 --- a/hw/char/trace-events +++ b/hw/char/trace-events @@ -58,8 +58,8 @@ pl011_read(uint32_t addr, uint32_t value, const char *regname) "addr 0x%03x valu pl011_read_fifo(int read_count) "FIFO read, read_count now %d" 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_put_fifo(uint32_t c, int read_count) "new char 0x%x read_count now %d" -pl011_put_fifo_full(void) "FIFO now full, RXFF set" +pl011_fifo_rx_put(uint32_t c, int read_count) "new char 0x%02x read_count now %d" +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 ")" # cmsdk-apb-uart.c From patchwork Mon May 22 15:31:44 2023 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: 684726 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1262381wrt; Mon, 22 May 2023 08:37:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6AzHzbvCk6HVgGeV60FFWqub3QVn4973omk+iHm/Z4WO53fonf9wywWs8vkSdMUwkB/gOP X-Received: by 2002:a37:644d:0:b0:75b:23a1:448 with SMTP id y74-20020a37644d000000b0075b23a10448mr1148021qkb.14.1684769848563; Mon, 22 May 2023 08:37:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684769848; cv=none; d=google.com; s=arc-20160816; b=zKjB5bsYLeDxbhTYkHHa5FKiaFKiuwoxODqDlAAPzls5iJXBnp/36EsY6xsByHtkT5 fhN0RZkiIqFGkPw+akHTmophN3vwk9vhPQ9Ah5XkMg92sSDlL3zVcMFlkVywzwsHU8jb 7wXiDB/nuXtbjioD9TMh8DZ6kAsP22EGHNJDqDRzHMz2eDhfVXJViZW83wo389NHe+cj WORcW0oIZne6avoGQAyWhXudESgbYHK5UuC21Q5jf2LwI/D9t6vBWFiL/EaCxuQ7KgGh 0MtCOFW8WnKiJzhyKsUh2/QuqLv5AGHWLJY1hyDWjQElAua85AsqH2LIWOpP+L4N+zMZ ChrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lE3AFLRBDeHmAd75tRobhpSnEmgT2M+g2etmHg9JWDI=; b=B9tbRvhXdvSK1fmKLhIZ1IwZli9WLSggKPVacKVe/4eBuebMM6Fw6OLRdUuWX2LYDi T3Cwr450zkn+3gVXNDXYFp8W27EyNkwHzaj3+zbDOx3qHC1FadxelO6S76tNkmcSwt5W JBE2YEmUC2FPr1g+z+KHPjVM4WrDr7nJx7vjFDEE29LK0RHbSjaFzie3bvIj7qmj4hwK 7Fth+O9dUaBdwLuqKWkIAdkhQij5nC17FZoLOM5SEUFkaMuNKk52W9skHbLDmCxKhG4N xTU4BxiB63WiObnYy9RchvNJah1hQfgMn0jrQZoAfn+5M1xs+PBB+o0mR9wRLn3IQhfq kNkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q9nke18z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z25-20020a05620a101900b0074fc1cfb2c9si3344056qkj.685.2023.05.22.08.37.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 May 2023 08:37:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q9nke18z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q17Wv-0007o3-2l; Mon, 22 May 2023 11:33:01 -0400 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 1q17Ws-0007m1-UN for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:59 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q17Wp-0001Sb-Vh for qemu-devel@nongnu.org; Mon, 22 May 2023 11:32:58 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f42c86543bso40698035e9.3 for ; Mon, 22 May 2023 08:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684769575; x=1687361575; 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=lE3AFLRBDeHmAd75tRobhpSnEmgT2M+g2etmHg9JWDI=; b=q9nke18z0/+Mg9Q+nIwUINvI+Yse7bF2z1947OEzoTG6vk5SHi95KEIBqw0TvQe6jS XKhcRyQ83B7ClLUigsD+gZa9JqHpC6tQNnaf801rZni4UaPbJIj3ENK9aY4ztv1Il4RJ 1d4eqYP5pkX/7yn3oodHvzzPgY0Nhp+6ge+AEYD3kYcLDb8eKIYSKDBNTzdnA+1C2E4i AhgDDRR6bjr9Anw2b3rSn0Q0dDCKYtHn1y9c4gCJJH+8/1kpNhPHSjePq0MTmYwiNAeY AoG2FSksrIyFC0IEfQwlB3HNTfcp105k4zXS7ZJDuAS70Blsnk31qJUbuUlWkfWN3Gc5 1VrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684769575; x=1687361575; 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=lE3AFLRBDeHmAd75tRobhpSnEmgT2M+g2etmHg9JWDI=; b=AxncAzDsKcOGjdvKPFu2fMrfccPx7wXJjVsn3eYMYT4T+fVTYm9K6nK/899w3Ixn/P 29ZF6BWZ17sAaELAd76z9NxS2+LnhnBUXaaMgGzkIjVZQ91oBEmRpJAo8moXclGo+Au6 MU38Ijt35e1gW8hud5MLMGdo6PnZrMKHpXIPLpog+4lpSzRzwnhTJz6QZsOOPr62eS9y F2AoTlgH6FaWvUWoYkgNuYa25XHzx6p5kDHz4hFki5vfEF3GfZL4ikG7/lZuPTvKyMmh vcTOLjUYky3eLE4WIfRAw+bqydpuL3gRrF4/v010lkIc098jOfwn8MCtW+HbbMK1CFPu Zf7A== X-Gm-Message-State: AC+VfDxpfed1vEVapBMP5UGMoWmx3iYNJSrZaK+JU1eVUvUNTpqh/wvn 1LXHndFkctVJhJfKPSgYp4mpeiwslYTQjy8//lM= X-Received: by 2002:a7b:c390:0:b0:3f4:2805:c3a with SMTP id s16-20020a7bc390000000b003f428050c3amr8063059wmj.21.1684769574891; Mon, 22 May 2023 08:32:54 -0700 (PDT) Received: from localhost.localdomain ([176.176.153.164]) by smtp.gmail.com with ESMTPSA id o3-20020a05600c378300b003f4f8cc4285sm8674869wmr.17.2023.05.22.08.32.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 22 May 2023 08:32:54 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-arm@nongnu.org, =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Evgeny Iakovlev , =?utf-8?q?Marc-Andr=C3=A9_?= =?utf-8?q?Lureau?= , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Mikko Rapeli Subject: [PATCH 12/12] hw/char/pl011: Implement TX FIFO Date: Mon, 22 May 2023 17:31:44 +0200 Message-Id: <20230522153144.30610-13-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230522153144.30610-1-philmd@linaro.org> References: <20230522153144.30610-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org If the UART back-end chardev doesn't drain data as fast as stdout does or blocks, buffer in the TX FIFO to try again later. This avoids having the IO-thread busy waiting on chardev back-ends, reported recently when testing the Trusted Reference Stack and using the socket backend: https://linaro.atlassian.net/browse/TRS-149?focusedCommentId=149574 Implement registering a front-end 'watch' callback on back-end events, so we can resume transmitting when the back-end is writable again, not blocking the main loop. Similarly to the RX FIFO path, FIFO level selection is not implemented (interrupt is triggered when a single byte is available in the FIFO). Due to the addition of the TX FIFO in the instance state, increase the migration stream version. Reported-by: Mikko Rapeli Suggested-by: Alex Bennée Signed-off-by: Philippe Mathieu-Daudé --- RFC because I'm pretty sure I got the migration code wrong. After writing this I noticed the hw/char/cmsdk-apb-uart.c model is much more complete. Instead of copy/pasting its code, I'd rather try to extract some generic/bstract "FIFO based chardev" QOM class; but this is beyond the scope of this series. --- include/hw/char/pl011.h | 2 + hw/char/pl011.c | 105 +++++++++++++++++++++++++++++++++++++--- hw/char/trace-events | 4 ++ 3 files changed, 105 insertions(+), 6 deletions(-) diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h index d853802132..20898f43a6 100644 --- a/include/hw/char/pl011.h +++ b/include/hw/char/pl011.h @@ -18,6 +18,7 @@ #include "hw/sysbus.h" #include "chardev/char-fe.h" #include "qom/object.h" +#include "qemu/fifo8.h" #define TYPE_PL011 "pl011" OBJECT_DECLARE_SIMPLE_TYPE(PL011State, PL011) @@ -53,6 +54,7 @@ struct PL011State { Clock *clk; bool migrate_clk; const unsigned char *id; + Fifo8 xmit_fifo; }; DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr); diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 03c006199e..a957138405 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -57,6 +57,9 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr) /* Data Register, UARTDR */ #define DR_BE (1 << 10) +/* Receive Status Register/Error Clear Register, UARTRSR/UARTECR */ +#define RSR_OE (1 << 3) + /* Interrupt status bits in UARTRIS, UARTMIS, UARTIMSC */ #define INT_OE (1 << 10) #define INT_BE (1 << 9) @@ -152,19 +155,94 @@ static inline void pl011_reset_tx_fifo(PL011State *s) /* Reset FIFO flags */ s->flags &= ~PL011_FLAG_TXFF; s->flags |= PL011_FLAG_TXFE; + + fifo8_reset(&s->xmit_fifo); +} + +static gboolean pl011_drain_tx(PL011State *s) +{ + trace_pl011_fifo_tx_drain(fifo8_num_used(&s->xmit_fifo)); + pl011_reset_tx_fifo(s); + s->rsr &= ~RSR_OE; + return FALSE; +} + +static gboolean pl011_xmit(void *do_not_use, GIOCondition cond, void *opaque) +{ + PL011State *s = opaque; + int ret; + const uint8_t *buf; + uint32_t buflen; + uint32_t count; + + if (!qemu_chr_fe_backend_connected(&s->chr)) { + /* Instant drain the fifo when there's no back-end */ + return pl011_drain_tx(s); + } + + count = fifo8_num_used(&s->xmit_fifo); + if (!count) { + return FALSE; + } + if (!(s->cr & CR_UARTEN)) { + /* Allow completing the current FIFO character before stopping. */ + count = 1; + } + + /* Transmit as much data as we can */ + buf = fifo8_peek_buf(&s->xmit_fifo, count, &buflen); + ret = qemu_chr_fe_write(&s->chr, buf, buflen); + if (ret >= 0) { + /* Pop the data we could transmit */ + trace_pl011_fifo_tx_xmit(ret); + fifo8_pop_buf(&s->xmit_fifo, ret, NULL); + s->int_level |= INT_TX; + } + + if ((s->cr & CR_UARTEN) && !fifo8_is_empty(&s->xmit_fifo)) { + /* Reschedule another transmission if we couldn't transmit all */ + guint r = qemu_chr_fe_add_watch(&s->chr, G_IO_OUT | G_IO_HUP, + pl011_xmit, s); + if (!r) { + return pl011_drain_tx(s); + } + } + + pl011_update(s); + + return FALSE; } static void pl011_write_tx(PL011State *s, const uint8_t *buf, int length) { if (!(s->cr & (CR_UARTEN | CR_TXE))) { + if (!fifo8_is_empty(&s->xmit_fifo)) { + /* + * If the UART is disabled in the middle of transmission + * or reception, it completes the current character before + * stopping. + */ + pl011_xmit(NULL, G_IO_OUT, s); + } return; } - /* XXX this blocks entire thread. Rewrite to use - * qemu_chr_fe_write and background I/O callbacks */ - qemu_chr_fe_write_all(&s->chr, buf, 1); - s->int_level |= INT_TX; - pl011_update(s); + if (length > fifo8_num_free(&s->xmit_fifo)) { + /* + * The FIFO contents remain valid because no more data is + * written when the FIFO is full, only the contents of the + * shift register are overwritten. The CPU must now read + * the data, to empty the FIFO. + */ + trace_pl011_fifo_tx_overrun(); + s->rsr |= RSR_OE; + return; + } + + trace_pl011_fifo_tx_put(length); + fifo8_push_all(&s->xmit_fifo, buf, length); + + pl011_xmit(NULL, G_IO_OUT, s); } static uint64_t pl011_read(void *opaque, hwaddr offset, @@ -444,12 +522,17 @@ static int pl011_post_load(void *opaque, int version_id) s->read_pos = 0; } + if (version_id >= 3 && !fifo8_is_empty(&s->xmit_fifo)) { + /* Reschedule another transmission */ + qemu_chr_fe_add_watch(&s->chr, G_IO_OUT | G_IO_HUP, pl011_xmit, s); + } + return 0; } static const VMStateDescription vmstate_pl011 = { .name = "pl011", - .version_id = 2, + .version_id = 3, .minimum_version_id = 2, .post_load = pl011_post_load, .fields = (VMStateField[]) { @@ -462,6 +545,7 @@ static const VMStateDescription vmstate_pl011 = { VMSTATE_UINT32(int_enabled, PL011State), VMSTATE_UINT32(int_level, PL011State), VMSTATE_UINT32_ARRAY(read_fifo, PL011State, PL011_FIFO_DEPTH), + VMSTATE_FIFO8(xmit_fifo, PL011State), VMSTATE_UINT32(ilpr, PL011State), VMSTATE_UINT32(ibrd, PL011State), VMSTATE_UINT32(fbrd, PL011State), @@ -505,10 +589,18 @@ static void pl011_realize(DeviceState *dev, Error **errp) { PL011State *s = PL011(dev); + fifo8_create(&s->xmit_fifo, PL011_FIFO_DEPTH); qemu_chr_fe_set_handlers(&s->chr, pl011_can_receive, pl011_receive, pl011_event, NULL, s, NULL, true); } +static void pl011_unrealize(DeviceState *dev) +{ + PL011State *s = PL011(dev); + + fifo8_destroy(&s->xmit_fifo); +} + static void pl011_reset(DeviceState *dev) { PL011State *s = PL011(dev); @@ -534,6 +626,7 @@ static void pl011_class_init(ObjectClass *oc, void *data) DeviceClass *dc = DEVICE_CLASS(oc); dc->realize = pl011_realize; + dc->unrealize = pl011_unrealize; dc->reset = pl011_reset; dc->vmsd = &vmstate_pl011; device_class_set_props(dc, pl011_properties); diff --git a/hw/char/trace-events b/hw/char/trace-events index 9fd40e3aae..4c25564066 100644 --- a/hw/char/trace-events +++ b/hw/char/trace-events @@ -60,6 +60,10 @@ pl011_write(uint32_t addr, uint32_t value, const char *regname) "addr 0x%03x val 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_fifo_rx_full(void) "RX FIFO now full, RXFF set" +pl011_fifo_tx_put(int count) "TX FIFO push %d" +pl011_fifo_tx_xmit(int count) "TX FIFO pop %d" +pl011_fifo_tx_overrun(void) "TX FIFO overrun" +pl011_fifo_tx_drain(unsigned drained) "TX FIFO draining %u" 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 ")" # cmsdk-apb-uart.c