From nobody Sat May 18 21:16:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699558196; cv=none; d=zohomail.com; s=zohoarc; b=WJKgqa3Ktyz71izBAJRZd2dyuf6MKGm6WJZDf1mJOTAwWwcjvqKVFx2n7LHOvPi7zsGAcRxY8gBxHuiCmBd8WqnlUh1Dx+I8KKD+v2tT0q2nSkCrqAJ1mTBQXoxcDNfFWlUQByCLhunWGDJah/PukvDEe3WyEreT1cyMvDRidVo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699558196; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tAZvf0/lxzzRafQirPbdSKogeoxVhHxgjxTZIWfzoxQ=; b=Qx05tCEkZmd+XzPG5VhDoZJL6dtv2TLZP4C62EvsfNWV4Qd5N6Z729kvk7Dhu4G8CrfkgVc7Ww+bE4MU5w1CYR+vUNuIg/G4LmimgrX+L41jm58Ot146LfMfvkE1bP0lBd/MmCoIC3F/WG+ZjWT9sFUCdO1XX1oZNSDCC45U4Lc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699558196001453.10449113848233; Thu, 9 Nov 2023 11:29:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1AhY-000515-5q; Thu, 09 Nov 2023 14:28:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1AhW-0004uf-L1 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:26 -0500 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1AhU-0005G0-W3 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:26 -0500 Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5440f25dcc7so2027472a12.0 for ; Thu, 09 Nov 2023 11:28:24 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id z3-20020a5096c3000000b00544f8271b5fsm189937eda.8.2023.11.09.11.28.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558103; x=1700162903; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tAZvf0/lxzzRafQirPbdSKogeoxVhHxgjxTZIWfzoxQ=; b=NqaF7rDg+cNy598mq7WXsKuET9YrMQV/LJ+ncqMhJIQKLSGfQzymsTq6CqTB4SX5bb CmmVJzVDaU4PP3Tmi8Qwq/HzoLLLxk5pomwuswp5KFanblWn6M2F/6rrAh00MzcwKvGj I6DQU4lti/xy7ZGYLoWxT30dx+2a7PmIqLdphYaNut2XAJFNqGikyMoxbKAmvj7MS4az tVSBX+IcUMQffeqF6pBXOACheGA5dY/2XJAoHiegylbyFdufs76UT9kO1yQCPBYjFFwx yMCct2a2xvaadTvFzFOncHlMys5MzmBFvJn8pvA38CHtjYvGIIDxmtKjdmXeeaLcxNAP 8eLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558103; x=1700162903; 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=tAZvf0/lxzzRafQirPbdSKogeoxVhHxgjxTZIWfzoxQ=; b=BblOfxbZr9cyPnFaZfUszuczkLf/ZFNQXPscuNyPJ8jkDwD9VbEJR+yo2i1ZNm6Jri Bw3oJjQlIEy3dqNUamjjr0iel7Y9q1dYNaoefeCYhvVm3XR4u2/ELqLv2yrdjH+2z56I XOZ9lw7NBKnRJRuc4EBqM+AwlJOYFu/IpUt7Kv41dL5IYrvSuS6DNOSuIR85bXBwYWBX zOmNU70kZJbo9iGUqIIb41sxkB25KFNePaS0yRVTycOTuOOIdGOKBzVcxvTjnVe9a8qc 2oGT6efpP8Ns28MT542AY7dXBo9uUQR3Vk6OKSHf4kIy7ySVk9MpPYfUpo2LaD7Z4RMh H7Fg== X-Gm-Message-State: AOJu0YwpA+xLs5656TCrwVOqr0YzekgNZkzZtmzpToMNEGYoFearlF1j eyI06pg7OVoAoKj8YrapUF5+sXq/ZdFr1Us31kXssQ== X-Google-Smtp-Source: AGHT+IGpPcJ3Xf7zLqTm3djhkxKHFhbHSxJ+qioykBUXmykUoXU8maRNfXen/gfl7USeEY2cT3/uDA== X-Received: by 2002:a50:8d0b:0:b0:53e:37d1:a31f with SMTP id s11-20020a508d0b000000b0053e37d1a31fmr5226900eds.28.1699558103375; Thu, 09 Nov 2023 11:28:23 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gavin Shan , Paolo Bonzini , Mark Cave-Ayland , Peter Maydell , Evgeny Iakovlev , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Francisco Iglesias Subject: [PATCH-for-8.2 v4 01/10] util/fifo8: Allow fifo8_pop_buf() to not populate popped length Date: Thu, 9 Nov 2023 20:28:05 +0100 Message-ID: <20231109192814.95977-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109192814.95977-1-philmd@linaro.org> References: <20231109192814.95977-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52f; envelope-from=philmd@linaro.org; helo=mail-ed1-x52f.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699558196560100001 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=C3=A9 Reviewed-by: Francisco Iglesias Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Tested-by: Alex Benn=C3=A9e --- 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 buff= er * 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 d= ata * is returned. * - * The number of valid bytes returned is populated in *num; will always re= turn - * 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); =20 /** * 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; } =20 -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; =20 assert(max > 0 && max <=3D fifo->num); - *num =3D MIN(fifo->capacity - fifo->head, max); + num =3D MIN(fifo->capacity - fifo->head, max); ret =3D &fifo->data[fifo->head]; - fifo->head +=3D *num; + fifo->head +=3D num; fifo->head %=3D fifo->capacity; - fifo->num -=3D *num; + fifo->num -=3D num; + if (numptr) { + *numptr =3D num; + } return ret; } =20 --=20 2.41.0 From nobody Sat May 18 21:16:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699558181; cv=none; d=zohomail.com; s=zohoarc; b=PFvQBMu2MwA/Oenmpryw5dfPSTxuSetMu+ow/Mx+kzH51oa9ztGlVk+iZfoL2LRoJVjqhByFy2RWoy/8XY8CEzHuotmTcfmfwwtXENgJYIhmBgKBe4plNXPYI9jenP5X4X5JR5EqHvjG1L+dRyZT/ZjFB889GavTH9UlFPbtM8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699558181; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BO0D2WVoS2EP+jLak3Jz2oTxKuP2p7K6nXjgv8ItBfQ=; b=mSzgMwBi+hsoMVL83hcUGMDOQTYqBUYsT5nHUxXW+gt5bd6OD7FMpWHsQnDcWjgTAQQxXCzLtS/AOudIUf0puCNmLvYLG5h6PqYmMxPn0W7bXUV5KJf53QKH5rVjspO6NSkdmtOhEbMiCBEJVWLKu3L8nbV6s3f9NTbi664kQFc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699558181051268.43050759132063; Thu, 9 Nov 2023 11:29:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1Ahf-00054S-Dq; Thu, 09 Nov 2023 14:28:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1Ahd-00053k-Tj for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:33 -0500 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ahc-0005GV-8r for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:33 -0500 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-9d267605ceeso209734566b.2 for ; Thu, 09 Nov 2023 11:28:30 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id qh23-20020a170906ecb700b009a19701e7b5sm2954549ejb.96.2023.11.09.11.28.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558109; x=1700162909; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BO0D2WVoS2EP+jLak3Jz2oTxKuP2p7K6nXjgv8ItBfQ=; b=tfNv+2mjSdiHuj6izxKvhPqyNSpT00DzsUACdTaTi/LgitchUy9nGEVrqdU4KvHnfH sSPVwyGRVULCB+c24BZbwimRyY+8tXKAoKpMfgSer/d2J/EAQvn+KsN8bXvXtQcN4GoB eYS3mkDHFQpN/DDcRwmXlBZa5UmYZ9wr7PUlTj6wDcL/F9tu5mVhiTV6SYOG49IK57VI OaV3KjisNz+TJqoFK86fdRP1J6NfRsMHPlBZmrge+nV5oJKn+Sz6mrSD7B8dInVevfgf Uzrymg0h9Ep5lr+MW3qzQLE4UP+GLr4SDvki8yuB+0i63AvJRrr4VUh1T7WS0aiqYD3I tpIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558109; x=1700162909; 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=BO0D2WVoS2EP+jLak3Jz2oTxKuP2p7K6nXjgv8ItBfQ=; b=RrsrkKzlNUQgA4wqOKK5hXR3429bu1j5U0lUGv15Vpg6HamjF0WF2nYfTKfFUpUo+O ZlRrb+sZK50QUlfzsmGDgd1cp4YlrS61NyQazQcCDcjW+DH3k4vNGgNAikhi24KpiFLu sb44tDcLUGXELNlfg/yssqZ2KxX9t9LD1rvix98W0WE0qqcmBkFn0SpqhDKG335Dp/5n JD2D9vjKE430QWYdCVP5ub+hOoBivvJ5V2dqOuoV5evW1FExBvEs0CIDe2R2ExflfPxk XsFhJ+5qFD7RbNqpcY4LSyopoW6xjvWMmupTzX8co1/WIa0vX3Ulld2URNlQCDh9SThe 1KMw== X-Gm-Message-State: AOJu0Yx7VGTO4s1YapLH3plkNKuxZeRkMwZeGnYdk7QtA6kh4YqmCJz4 2MPb3f2KQSLHxSr/D6ko+k7JLd7kU3WtCU7ycOL+hQ== X-Google-Smtp-Source: AGHT+IErozPHp4wXVfvM31ctOVenAXpEfiALK8Ch0iN8zfmFu4saFlT+Vx/fZ+gXY7mkQxuDuPS/fQ== X-Received: by 2002:a17:907:7faa:b0:9e0:5f68:143c with SMTP id qk42-20020a1709077faa00b009e05f68143cmr5572161ejc.35.1699558109337; Thu, 09 Nov 2023 11:28:29 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gavin Shan , Paolo Bonzini , Mark Cave-Ayland , Peter Maydell , Evgeny Iakovlev , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Francisco Iglesias Subject: [PATCH-for-8.2 v4 02/10] util/fifo8: Introduce fifo8_peek_buf() Date: Thu, 9 Nov 2023 20:28:06 +0100 Message-ID: <20231109192814.95977-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109192814.95977-1-philmd@linaro.org> References: <20231109192814.95977-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=philmd@linaro.org; helo=mail-ej1-x62b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699558182476100002 To be able to peek at FIFO content without popping it, introduce the fifo8_peek_buf() method by factoring common content from fifo8_pop_buf(). Reviewed-by: Francisco Iglesias Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Tested-by: Alex Benn=C3=A9e --- include/qemu/fifo8.h | 27 +++++++++++++++++++++++++++ util/fifo8.c | 22 ++++++++++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index d0d02bc73d..c6295c6ff0 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -93,6 +93,33 @@ uint8_t fifo8_pop(Fifo8 *fifo); */ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr); =20 +/** + * fifo8_peek_buf: read upto max bytes from the fifo + * @fifo: FIFO to read from + * @max: maximum number of bytes to peek + * @numptr: pointer filled with number of bytes returned (can be NULL) + * + * Peek into a number of elements from the FIFO up to a maximum of max. + * The buffer containing the data peeked into is returned. This buffer poi= nts + * directly into the FIFO backing store. Since data is invalidated once any + * of the fifo8_* APIs are called on the FIFO, it is the caller responsibi= lity + * to access it before doing further API calls. + * + * 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 d= ata + * 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; } =20 -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 <=3D fifo->num); num =3D MIN(fifo->capacity - fifo->head, max); ret =3D &fifo->data[fifo->head]; - fifo->head +=3D num; - fifo->head %=3D fifo->capacity; - fifo->num -=3D num; + + if (do_pop) { + fifo->head +=3D num; + fifo->head %=3D fifo->capacity; + fifo->num -=3D num; + } if (numptr) { *numptr =3D num; } return ret; } =20 +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 =3D 0; --=20 2.41.0 From nobody Sat May 18 21:16:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699558183; cv=none; d=zohomail.com; s=zohoarc; b=TzyAARuxrIEurj2PYgJGqG7Y9rz2LRRLeb8+r/x/Qpq01FR+SQsIBHpw1z/CyDJBnFF1bec6zUzlUiGWZMIdnHZjMYqgg7jyDTUpPF6w+oVZcZiF7tzViYZA4RIihWDwlsSAJEOOEKqU7ECBsPbO6G0TlI8jCgRtR+dMtsdZ7yw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699558183; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mP8e7F+MNf59pa1iU6FTfmv7Sb18zKeyajADdz6BZOc=; b=YqRyTAHl3Eewr0GnH1AE1CxEE+yMNDWG9iAA7vGZb0YqxHnNVn7+nARgm7fLe4ADhR6pHo0DcY0jKv780vq9lsCPC8ttV+HKNiOHxoZKYmsD8bAaejbAdViM3xmmogRVkvo3HdNhRXkNKyXWL1lNxEoCv+VSZxF55WesMkF/bm8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699558183192731.6100313239602; Thu, 9 Nov 2023 11:29:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1Ahk-00055w-Hc; Thu, 09 Nov 2023 14:28:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1Ahi-00055K-PC for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:38 -0500 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ahh-0005Gv-7J for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:38 -0500 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-53e2308198eso2022864a12.1 for ; Thu, 09 Nov 2023 11:28:36 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id bw25-20020a170906c1d900b009bd9ac83a9fsm2946023ejb.152.2023.11.09.11.28.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558115; x=1700162915; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mP8e7F+MNf59pa1iU6FTfmv7Sb18zKeyajADdz6BZOc=; b=yUA8Lh9vnAqKuqVclqo4i3ETE3k3VEdY79vtFZFifhM6esPzTL+Sc1vbf6GCBFyaTt Y62vlH/CLoCuJaA7twdJw3h36m+WNZ2DmiKq2R3l4N1CC4WCpYBSx8pwPLbTrM/nKttr SQflwdGaeuFjcdqJW7kXLF5p5PTfX9qGgYS2pZUcckqSETQQR64s0h2avoLPApes/e1n 7S2mjFt5kmJBnhYbhsXkAksFPBLAXlAhMSb9Msj0uSmI/A/qcegHa7xD2dRgDtDeyqmD /zFoId7TjiraCPJmILdUVa4QpONPtym7ZCmNLQ7PVxO9RWIRaIJ2p+c0EaSIBbbP74NF VOZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558115; x=1700162915; 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=mP8e7F+MNf59pa1iU6FTfmv7Sb18zKeyajADdz6BZOc=; b=nV8gVbj3FKIJoJ8gtBap4VIG+lvstfdbWtS8XmA792aYG/QbDbDIS0HGXEhFpkwOaN zs+gzGWwIwhNwcvvnbpgKPBB9kcgsQiL4wnrmmBwL9NBLECShh5OEEU4FGbwXUbNatX+ fHZD/DUAx8BOoOUTzS03PvzGL6nY6TO4eCZZ5uuidkKzJk6z10cWoGjzdPSROfJT/1TT qYVw4fH+z8GzmCKtL8ZwrdLkPOxGghzPyHmIhsob+yPjHt26KWsQO0UaclpmRSYcDns/ HlUtzBPZ1UwmsqkGaDsykJxTmu+MFkhU6u8Xt3EdiS2Z7ABap2/qiDOb0u6/Ihbi3SIQ Ze7g== X-Gm-Message-State: AOJu0YxYMeo1X0kAiDtYaauqBBrF935RMUsiKzRV5PlQULi/l3ZQ75ay FFLxbpl37nrVQwXg0Ae4SfcBqmdMZCWGDfRiTu71Mw== X-Google-Smtp-Source: AGHT+IGGos6RV93WgveC47MImoD//dBkcUR/VbX7MCdBOWuHJ/5fD+3r55VEGS5yvqHl0EYy1uU3kQ== X-Received: by 2002:a17:906:d9dd:b0:9e5:21d9:3ba6 with SMTP id qk29-20020a170906d9dd00b009e521d93ba6mr712372ejb.9.1699558115130; Thu, 09 Nov 2023 11:28:35 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gavin Shan , Paolo Bonzini , Mark Cave-Ayland , Peter Maydell , Evgeny Iakovlev , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH-for-8.2 v4 03/10] hw/char/pl011: Split RX/TX path of pl011_reset_fifo() Date: Thu, 9 Nov 2023 20:28:07 +0100 Message-ID: <20231109192814.95977-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109192814.95977-1-philmd@linaro.org> References: <20231109192814.95977-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=philmd@linaro.org; helo=mail-ed1-x530.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699558184393100005 To be able to reset the RX or TX FIFO separately, split pl011_reset_fifo() in two. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Tested-by: Alex Benn=C3=A9e --- 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 58edeb9ddb..1f07c7b021 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -132,14 +132,21 @@ static inline unsigned pl011_get_fifo_depth(PL011Stat= e *s) return pl011_is_fifo_enabled(s) ? PL011_FIFO_DEPTH : 1; } =20 -static inline void pl011_reset_fifo(PL011State *s) +static inline void pl011_reset_rx_fifo(PL011State *s) { s->read_count =3D 0; s->read_pos =3D 0; =20 /* Reset FIFO flags */ - s->flags &=3D ~(PL011_FLAG_RXFF | PL011_FLAG_TXFF); - s->flags |=3D PL011_FLAG_RXFE | PL011_FLAG_TXFE; + s->flags &=3D ~PL011_FLAG_RXFF; + s->flags |=3D PL011_FLAG_RXFE; +} + +static inline void pl011_reset_tx_fifo(PL011State *s) +{ + /* Reset FIFO flags */ + s->flags &=3D ~PL011_FLAG_TXFF; + s->flags |=3D PL011_FLAG_TXFE; } =20 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 =3D value & LCR_BRK; @@ -506,7 +514,8 @@ static void pl011_reset(DeviceState *dev) s->ifl =3D 0x12; s->cr =3D 0x300; s->flags =3D 0; - pl011_reset_fifo(s); + pl011_reset_rx_fifo(s); + pl011_reset_tx_fifo(s); } =20 static void pl011_class_init(ObjectClass *oc, void *data) --=20 2.41.0 From nobody Sat May 18 21:16:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699558236; cv=none; d=zohomail.com; s=zohoarc; b=RjFB6C35ERObIJkxw37b+1JVz139S5p6vUseY7yNG6EkIxPKu+sTMjPSi0yYp0V4430Fdu2yenf7E2Aq+EqDQ0aTpTk1gnOvq3nYBJq6Nn6WxD5znXJ0i9uWAo5kdLXaawtxg8qSqjEXI37eJwE3GRerMnteXWjJqdUuneH1GAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699558236; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4RcEaeq0Z+56TpsJGBFP08HsnS3amqPkJQB4mf707C8=; b=m07tD0GhKLSoFiMr+832RncUx+xEz0nu8aj8vCDxi9UfyrzVRP96jMguiHlQjTrT/ZWwLtwOsgh+faJjV2bw8LH41Iywj/I0T62Z64I1mJpPP8X6NObUsEMs7tQU0jLqo8tbo2F82ILujK7maA0UlxqF+6RKw9xJrbsbAEQP3Hk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699558236203871.8700072881567; Thu, 9 Nov 2023 11:30:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1Ahs-0005FY-4u; Thu, 09 Nov 2023 14:28:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1Ahp-0005Ez-Ae for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:45 -0500 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ahm-0005HS-H9 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:43 -0500 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-54553e4888bso1752534a12.2 for ; Thu, 09 Nov 2023 11:28:42 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id n18-20020a05640204d200b0054554a7bbedsm181784edw.24.2023.11.09.11.28.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558121; x=1700162921; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4RcEaeq0Z+56TpsJGBFP08HsnS3amqPkJQB4mf707C8=; b=aZ1o6QiNBdtXS2EHkgqglPT6KqQ7ZPqlUY/+jTJP8kvgZJ0PMZwuTzBQE8OCxZNPHr gVuuN/MXif6I+a2X49syDP+LOidM3rUMkNX8rbh+QcjWgx2kOLk8z4Uj5m0tnu2ylQCw vIpTn6c1StNYCnWhJJfo/vjrw2ldBFuQejOoHtmTT5U6GK74NrjMzE0QcwzFzQ1kkjiK N4x7qbjw0n3dkwvdYOdMtaTh77EH1uptHdrfPIVtNlXuMgN205sev3acaF+BFVaIWVR5 cLqfWsOlnu/Nmp12d5plTIDI0q6JwoYJE6I5FKU0EKbr++WUkG9cBoe8FRM6jQ2VwytJ 5X3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558121; x=1700162921; 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=4RcEaeq0Z+56TpsJGBFP08HsnS3amqPkJQB4mf707C8=; b=lk+shYdnytl7WjuhcxiIOCwKn4YyV+z9/TSacSmOuWVGbEsxBANGlVM/e7XhghHbWf t2aAZolqeBOyirNhukzWHSIsOAxJOSVDnt91lsQzouVWlz+uiTYP732nfzeMk97Jqu34 4EWu+cSvkeH4jy11UcXBkq/R0kZErQRNvE+s1+Bgb0E7WYqEtjEUDaDwPJSA+td2P9Jl wAB3JPWsCaLDRc9D508bnZSG/JiDKmZ0vkmR3t35M9wJHhF5SqVSEbrxmN1qnEP4EikE oKqRmhOR75HtJu/5HiD59udkSTnvIRiH4hO1uX5KxzR7YsN8S3J323DhapJPZ+c/VwFk X65A== X-Gm-Message-State: AOJu0YwJJHx1lBRnKfhgQL5Wy5rXz4cRV551VuDXpwy9b41WIep7qAOx 18+0H1H0Phi+ln4taGCunHjBSwAQZieWCaQgdI7r/w== X-Google-Smtp-Source: AGHT+IHlHZunX7/OzM/Hq8gtZQVZaha5htzE2nm4Itn4uRqrEmWxmG+hAyGrESaQi+hKc8p2UqA6hQ== X-Received: by 2002:a05:6402:358c:b0:545:5601:4148 with SMTP id y12-20020a056402358c00b0054556014148mr3310692edc.7.1699558120928; Thu, 09 Nov 2023 11:28:40 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gavin Shan , Paolo Bonzini , Mark Cave-Ayland , Peter Maydell , Evgeny Iakovlev , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-8.2 v4 04/10] hw/char/pl011: Extract pl011_write_txdata() from pl011_write() Date: Thu, 9 Nov 2023 20:28:08 +0100 Message-ID: <20231109192814.95977-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109192814.95977-1-philmd@linaro.org> References: <20231109192814.95977-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=philmd@linaro.org; helo=mail-ed1-x536.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699558236687100001 When implementing FIFO, this code will become more complex. Start by factoring it out to a new pl011_write_txdata() function. No functional change intended. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Tested-by: Alex Benn=C3=A9e --- hw/char/pl011.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 1f07c7b021..1cb9015ea2 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 |=3D PL011_FLAG_TXFE; } =20 +static void pl011_write_txdata(PL011State *s, uint8_t data) +{ + /* ??? 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, &data, 1); + s->int_level |=3D INT_TX; + pl011_update(s); +} + static uint64_t pl011_read(void *opaque, hwaddr offset, unsigned size) { @@ -262,19 +273,13 @@ static void pl011_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { PL011State *s =3D (PL011State *)opaque; - unsigned char ch; =20 trace_pl011_write(offset, value, pl011_regname(offset)); =20 switch (offset >> 2) { case 0: /* UARTDR */ - /* ??? Check if transmitter is enabled. */ - ch =3D 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 |=3D INT_TX; - pl011_update(s); + s->readbuff =3D value; + pl011_write_txdata(s, value); break; case 1: /* UARTRSR/UARTECR */ s->rsr =3D 0; --=20 2.41.0 From nobody Sat May 18 21:16:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699558183; cv=none; d=zohomail.com; s=zohoarc; b=frAqPHOUdNIIUYLYl93sWozL6PMIPbHFONEJXd7HiSevo+UFWd+hKpLyFdf5PcweEpQ59Lj4KpolySJ8ZM1B61gM9WK6xjLip/sNBooQJ4u3s0ERGG8vdEJGQjL/jMNGapBaV3cQ0vGKZVWNjy0QVLT0/Yk/+XzBin+MQSQuyqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699558183; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5g0UHLmrzpBXUAHJbDdjYHH8dsW06tpS080WDx/2FO0=; b=B9ZxoEwDSHdTDDF4xe3FaT39yQk5FrQXJ9Sn5dzqm6m1kyLb/RrtNUZRAgNPCBWX7FqMfe1IYWZdbs2k3qJuP1vgS7LZ6kCRMwN9qr7ce0XfMvEZ7YpP7ldOFkcaZcnGTT9Ll2iL9HNttmfp6C3YgVKUGXyRyet/UZM6ripiqgo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699558183219116.47875092547588; Thu, 9 Nov 2023 11:29:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1AiL-0005l9-Uo; Thu, 09 Nov 2023 14:29:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1Ahw-0005Hf-7R for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:57 -0500 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ahs-0005Hs-N0 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:51 -0500 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9c53e8b7cf4so211265866b.1 for ; Thu, 09 Nov 2023 11:28:48 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id qx11-20020a170906fccb00b009b2f2451381sm2930998ejb.182.2023.11.09.11.28.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558127; x=1700162927; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5g0UHLmrzpBXUAHJbDdjYHH8dsW06tpS080WDx/2FO0=; b=IF0YNX5h+jeFnwz/GDjs7O7/0TnAwwqWMVtRuFm+oxr74QPr2tw1DvFQoNPk7IikKD +GtO0/yFn9XZLMnak2KqH84pgIs28uCQTIydjRvVoKw18luZoqqcx+FLeDyAAhVxLTJ2 7kmE4BHG6/y/AM89G/PnzA9nWIw6X983rzRvknc8VyLssgUDe5iP6Lj9IZCu8x2qIihp B82uKDAPqNhRypiKJesmFuqLIdxQhlPNK6iEB6XZBVeq3dWLzMKuXWulbYIxZ9M/69vN Ufgp6fslRTQzZNy/yHz4AMMf7H04UuiAeXbboebDsOUFCBUa6q+6PziHK1VXIVYTG/Eo s4aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558127; x=1700162927; 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=5g0UHLmrzpBXUAHJbDdjYHH8dsW06tpS080WDx/2FO0=; b=rD7GhHDMmD4cGnAZxhrPHYtcsBLieYtVSLAIZunYwTc9wDQVLmNU1f/8UQnX9aj1Gw YKf9HRW5vSD94koj5+wwfWpyL7pU43ABhY07LATG91CAoUbn2z+WfVQ+kzP0uK/EqVEV jNxAIMtHhoWd86B0HrC08ez+yXduIW/eixMqyGYA+/FIo6jJvslxCm/aeKgPUkftJ1x6 TLH4jtqk5bkoTbwM3z34ftiHa7699l7C3K8h58FKp0LNS6nFV+YUWl/C0Dipe5hJkEDg N1SKijk5atun2HBcGwP94Yd2k2Tw2vZ7zwC2uyliir9PrjQvlgspfxaICXMWWCdIdKpC EAgw== X-Gm-Message-State: AOJu0YyVJRyIpU074O/MGdOPqASkEndDe2ObuzTsLcTr93zcp/I61Wf6 UEsKVJYIQpfrUR3E6T2GP93gPw4N9uv4mUrppkeGgg== X-Google-Smtp-Source: AGHT+IG1mIB1epOkXgJaPMduGKGeTPr6W+PS0WSWibBTbSNphDMXSkK+WfnOF/yBf0DY9R9lsFpDqg== X-Received: by 2002:a17:907:26c9:b0:9d2:ab03:a22d with SMTP id bp9-20020a17090726c900b009d2ab03a22dmr4450766ejc.73.1699558126739; Thu, 09 Nov 2023 11:28:46 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gavin Shan , Paolo Bonzini , Mark Cave-Ayland , Peter Maydell , Evgeny Iakovlev , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH-for-8.2 v4 05/10] hw/char/pl011: Extract pl011_read_rxdata() from pl011_read() Date: Thu, 9 Nov 2023 20:28:09 +0100 Message-ID: <20231109192814.95977-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109192814.95977-1-philmd@linaro.org> References: <20231109192814.95977-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=philmd@linaro.org; helo=mail-ej1-x629.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699558186379100013 To keep MemoryRegionOps read/write handlers with similar logic, factor pl011_read_txdata() out of pl011_read(), similar to what the previous commit did to pl011_write(). No functional change intended. Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Alex Benn=C3=A9e --- hw/char/pl011.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 1cb9015ea2..30309337b1 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -160,31 +160,38 @@ static void pl011_write_txdata(PL011State *s, uint8_t= data) pl011_update(s); } =20 +static uint32_t pl011_read_rxdata(PL011State *s) +{ + uint32_t c; + + s->flags &=3D ~PL011_FLAG_RXFF; + c =3D s->read_fifo[s->read_pos]; + if (s->read_count > 0) { + s->read_count--; + s->read_pos =3D (s->read_pos + 1) & (pl011_get_fifo_depth(s) - 1); + } + if (s->read_count =3D=3D 0) { + s->flags |=3D PL011_FLAG_RXFE; + } + if (s->read_count =3D=3D s->read_trigger - 1) { + s->int_level &=3D ~ INT_RX; + } + trace_pl011_read_fifo(s->read_count); + s->rsr =3D c >> 8; + pl011_update(s); + qemu_chr_fe_accept_input(&s->chr); + return c; +} + static uint64_t pl011_read(void *opaque, hwaddr offset, unsigned size) { PL011State *s =3D (PL011State *)opaque; - uint32_t c; uint64_t r; =20 switch (offset >> 2) { case 0: /* UARTDR */ - s->flags &=3D ~PL011_FLAG_RXFF; - c =3D s->read_fifo[s->read_pos]; - if (s->read_count > 0) { - s->read_count--; - s->read_pos =3D (s->read_pos + 1) & (pl011_get_fifo_depth(s) -= 1); - } - if (s->read_count =3D=3D 0) { - s->flags |=3D PL011_FLAG_RXFE; - } - if (s->read_count =3D=3D s->read_trigger - 1) - s->int_level &=3D ~ INT_RX; - trace_pl011_read_fifo(s->read_count); - s->rsr =3D c >> 8; - pl011_update(s); - qemu_chr_fe_accept_input(&s->chr); - r =3D c; + r =3D pl011_read_rxdata(s); break; case 1: /* UARTRSR */ r =3D s->rsr; --=20 2.41.0 From nobody Sat May 18 21:16:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699558342; cv=none; d=zohomail.com; s=zohoarc; b=DvWv8p6tNiTma9zsAS3/bUR99Wb0rl2i1oVKXwL+GUwVJqCLm8Nw11f46ukzyP+/P5C2XhOG6CH7nk27imTxOLa4GkLdLaNeOIqSkpjwsKEbF0yVovYqoWeCCEmjQL64GxHyIUjchcPDlUEUk6ExJvNirgIu8qd3K1+W4sZu2JI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699558342; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TEZCH3t9203jXT8Ca8hiOxWdvxGRGRt32KSzy33l+nU=; b=k65r6vKG9/I2quSFU8mynfgYOuH0DJNn/a2DEaDTN7wCrery/8ktquurESmAlCSy02B1df67tn5ZNEIA4FYaE8NEGnPWsPhC8H+NdA9YwnLsEIuklQHU/mZaTlBKUgEID29+ZCcHkG3X3TjWEyWOM0jg6xot2f+jW+1Tc6mpYkQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699558342747990.7515376991192; Thu, 9 Nov 2023 11:32:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1AiQ-0005yE-AO; Thu, 09 Nov 2023 14:29:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1Ai2-0005RW-B4 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:02 -0500 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ahy-0005IO-JJ for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:28:57 -0500 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9dd6dc9c00cso216021466b.3 for ; Thu, 09 Nov 2023 11:28:54 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id g2-20020a1709064e4200b009b2c9476726sm2904753ejw.21.2023.11.09.11.28.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558133; x=1700162933; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TEZCH3t9203jXT8Ca8hiOxWdvxGRGRt32KSzy33l+nU=; b=bmUkq/QiqQsVxBIPg6upwJ3HanE2T6z3MuOJU7EAhURTKDz+A8kASIlZvFgIf/2orm 99JsS8K6Jt14ckG8Po+nRQSlCqGQtNXk7srx/mVspcrJwbHEOMj0Hzryb7Q3R4WuWRXR md5OGIAGP1z8vcl5j6ZtS9ntO7EmbeClB9+z1CEEHhQBiW1kwtYoSgafe9ujlwCSi9Rm Dq+SgUuICnsQbeo/s+JX7W8ZjtlahgqwzXfIDVX8j1r7cwiQT/VkN8F65huo06+SqBBK F08nR4RGH24P7bYnbgUYsrytZkqxKMI7ISquOsIJEXpfsneQiOVOAdTl9lEpnVlJ6Yab dgGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558133; x=1700162933; 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=TEZCH3t9203jXT8Ca8hiOxWdvxGRGRt32KSzy33l+nU=; b=SZ/CLP+53GUX4awM4Gnm6SUGkvKNqKGMn3czyzCEvINF6t6Szhf9R5DCaPSgcfaI7F 2t59B3PblHTXz4+p49DUj0rpQ+hzXBx3VpRyZEf+zruHXJolnEU4V9BKdh6m9NRPPlm8 0KCHgISkaW4dwjj+WS7VzCuPEmIlK//7/puRLFj+ot+Lsbi9tlVGvPi31/9WiRTynLYf WIxijmhGq1RkfZoeEmKU7OsQAqTe5SYpbi5xe5np9Nny+yIRflbzGnrr9rH9b+CCWBPf R/8Pjo3Y1h04UPhMQiBodpMZeOUdCxaDNl8GneWf0EIHzkGU5YFwlgq4nOr0nsx+1Zre qiGw== X-Gm-Message-State: AOJu0YwgPdPHcfdwJ9kIF2qGs8kqprtgnWpbTK/vee6FXMlPj2BGTvBU AoSzrzbU3szKYmwUp4xhyD5oiw/cWB7uWu5KFbeRmg== X-Google-Smtp-Source: AGHT+IE4Zyn8KXdktvGc4uyvoiOmwlNKr8f7had+FoLm5D9aXdTdHbdq3c31AhUYwDgoJSY7N+NY1w== X-Received: by 2002:a17:907:a0b:b0:9bf:9c58:e91e with SMTP id bb11-20020a1709070a0b00b009bf9c58e91emr4392989ejc.56.1699558132912; Thu, 09 Nov 2023 11:28:52 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gavin Shan , Paolo Bonzini , Mark Cave-Ayland , Peter Maydell , Evgeny Iakovlev , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH-for-8.2 v4 06/10] hw/char/pl011: Warn when using disabled transmitter Date: Thu, 9 Nov 2023 20:28:10 +0100 Message-ID: <20231109192814.95977-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109192814.95977-1-philmd@linaro.org> References: <20231109192814.95977-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=philmd@linaro.org; helo=mail-ej1-x62d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699558343387100001 We shouldn't transmit characters when the full UART or its transmitter is disabled. However we don't want to break the possibly incomplete "my first bare metal assembly program"s, so we choose to simply display a warning when this occurs. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Tested-by: Alex Benn=C3=A9e --- hw/char/pl011.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 30309337b1..9c43cb47bf 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -76,6 +76,10 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Cha= rdev *chr) #define LCR_FEN (1 << 4) #define LCR_BRK (1 << 0) =20 +/* Control Register, UARTCR */ +#define CR_TXE (1 << 8) +#define CR_UARTEN (1 << 0) + static const unsigned char pl011_id_arm[8] =3D { 0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1 }; static const unsigned char pl011_id_luminary[8] =3D @@ -151,7 +155,12 @@ static inline void pl011_reset_tx_fifo(PL011State *s) =20 static void pl011_write_txdata(PL011State *s, uint8_t data) { - /* ??? Check if transmitter is enabled. */ + if (!(s->cr & CR_UARTEN)) { + qemu_log_mask(LOG_GUEST_ERROR, "PL011 data written to disabled UAR= T\n"); + } + if (!(s->cr & CR_TXE)) { + qemu_log_mask(LOG_GUEST_ERROR, "PL011 data written to disabled TX = UART\n"); + } =20 /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ --=20 2.41.0 From nobody Sat May 18 21:16:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699558336; cv=none; d=zohomail.com; s=zohoarc; b=eWXbHQPbjAfgWFN3bdA5eIz+zS/hiK2uk6NxT5Ie7cNcTQGJ1v/7OyKOxMZti3n+jqxnT48xZTUxcHkEAQvzI/Oliqj8xD0+9QLdFe2pP/CHZHXgVCAsFsEebYQBNvn/uEC3iRRXBt/Ce7Gv3p4wRQT7PJAjDN+B2Jb+jCAiMLo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699558336; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SyyFM5rojPE+uJBRWUA1uUis15hpR5uGCcF147lyuU8=; b=P19bg0LbteR+nBDhETrw9P3/tzwdgNIiSc0cMp/y/N4H5fYGE6+FMfoLSxhUxvVtY9o+7DNZ/gpI1MBi72wD4nDjHzIlqIq6pQcnD0jejs+aUv8XCOFzKrCPNPTC9CR5vfBn8lG/zRPpNJ/Ru+K2aQxA0ehRxQTe7c0WGkaAoRw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699558336885150.23895939855197; Thu, 9 Nov 2023 11:32:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1AiQ-0005wf-5E; Thu, 09 Nov 2023 14:29:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1Ai6-0005Ru-MA for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:04 -0500 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ai5-0005J3-58 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:02 -0500 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9c2a0725825so216555366b.2 for ; Thu, 09 Nov 2023 11:29:00 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id s3-20020a1709067b8300b009adc77fe164sm2938523ejo.66.2023.11.09.11.28.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:28:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558138; x=1700162938; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SyyFM5rojPE+uJBRWUA1uUis15hpR5uGCcF147lyuU8=; b=ceWJJSVTDqh3rVWtpr6FLID8/EGtwSPZfOCpxla5lqrYQx5o8LuqgVLsuI+x9kWjfm tDUiNPz1AsI0xqahGzAeKR7UoUT22pE1lh2Lzs+mHwgcJ20qRWtHHAZggxQoUcF9mN6N f/Ay6ySseUgVFULW6LSOeWLkNRdXFW9Zs/7UvVgtZIgJqO+msBUoE5xirzO+TSbAuIdT T89g69M3uNaLF7g9JMYKBQmwYWvi2VwDGkDXCseUgIdxqjIZgmPzBFawoNED1+jh7+Vl Y4BOZnq6dGKytEU/CHJxwGdD5cyrYpWjOaSoFdoCDSditHlKy/yMd1BaHv5+UbsqEgVG DjLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558138; x=1700162938; 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=SyyFM5rojPE+uJBRWUA1uUis15hpR5uGCcF147lyuU8=; b=pOYEqV/7pvC15swAJObP1fwqYMJR4bD99PBknWT0keOhYg+83NEfoL2vRkyofImcKv DILEilAFtH8WtoIVhBiQ80XyXTG6QTg8JIfWkyt9eCFEQmmUKsemIEE5QB6oezub9FyO qWFK4cnBVesx8krdjcI1ZNQojJQCw376mLtQyHiROTfGQ34/KLICBimLDfAYrTjuf8Wm Gi4c4wHOvNvEARUwtplSzwAQFXU0DwokGfYv84Fn70WtrBIRa/BoNuBKGR8b8cnPhICc Zu5bwhmJE/eTVi86O1JBh2PIZX1wYgHlmmI9ZjR9FO5wZxlQ+BJMqP/HIG2LYfXARx22 z4kg== X-Gm-Message-State: AOJu0Ywhc/RYpkpZ7kjlvavtGK6LIx14nda+F8XwqW1Bm4PXX388966v AoEXXw6C1qWjzsVQfhslE0tUqY3tVFMF6kwY6EiQFg== X-Google-Smtp-Source: AGHT+IEEqqr7N64ypg881HZQy8Pe4TRT0j60Rt1LHwaHNJh1J82Hmd1+KXR5zRxwESQEg12Z5PsU9A== X-Received: by 2002:a17:907:96a5:b0:9c5:7f8b:bafc with SMTP id hd37-20020a17090796a500b009c57f8bbafcmr5691609ejc.22.1699558138606; Thu, 09 Nov 2023 11:28:58 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gavin Shan , Paolo Bonzini , Mark Cave-Ayland , Peter Maydell , Evgeny Iakovlev , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH-for-8.2 v4 07/10] hw/char/pl011: Check if receiver is enabled Date: Thu, 9 Nov 2023 20:28:11 +0100 Message-ID: <20231109192814.95977-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109192814.95977-1-philmd@linaro.org> References: <20231109192814.95977-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=philmd@linaro.org; helo=mail-ej1-x629.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699558337370100001 Do not receive characters when UART or receiver are disabled. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Tested-by: Alex Benn=C3=A9e --- 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 9c43cb47bf..ca931be139 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -77,6 +77,7 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Char= dev *chr) #define LCR_BRK (1 << 0) =20 /* Control Register, UARTCR */ +#define CR_RXE (1 << 9) #define CR_TXE (1 << 8) #define CR_UARTEN (1 << 0) =20 @@ -359,9 +360,11 @@ static void pl011_write(void *opaque, hwaddr offset, static int pl011_can_receive(void *opaque) { PL011State *s =3D (PL011State *)opaque; - int r; + int r =3D 0; =20 - r =3D s->read_count < pl011_get_fifo_depth(s); + if ((s->cr & CR_UARTEN) && (s->cr & CR_RXE)) { + r =3D s->read_count < pl011_get_fifo_depth(s); + } trace_pl011_can_receive(s->lcr, s->read_count, r); return r; } --=20 2.41.0 From nobody Sat May 18 21:16:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699558343; cv=none; d=zohomail.com; s=zohoarc; b=kyG1MZErtLdovw8ySqiyPyzjLelHm8z0m25axzf6FHkXk1XhqRQ5Bz3O7frueceP2qPqXfJ8Uv1i8aybP7WvaB+xTkB5sLZ124Rnfmo4UEfWUWF7D6RNB937ftEM73pdYo1tlaXyNxjpBaoSlxCe9hyc30E/SdXsF/Hhau6QLdc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699558343; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RHS4Z4THTDrdonuMomFxK3JmiClhr4y8badmiGx38uU=; b=jvOVtXDAhPlxTGtg1i20r6O3Dhfrv9GSMk1bBkuxryEShxhDqORKaCkMe4qc984E6BYDUYpqHhi+CaRjEItb1qUezf0r6Ajbh3Ma5Mlag8HHOtAutXpNdoSp2j0u2fQRloOqrTk2aNFLOPSBZBFgrDGaaEx2L5Jt7WBMjtkI/FU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16995583433691006.8454710038179; Thu, 9 Nov 2023 11:32:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1AiQ-0005yb-CJ; Thu, 09 Nov 2023 14:29:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1AiC-0005Zw-HD for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:13 -0500 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1AiA-0005Nk-BZ for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:08 -0500 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9e213f198dfso217183666b.2 for ; Thu, 09 Nov 2023 11:29:05 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id l22-20020a17090612d600b009c3828fec06sm2914829ejb.81.2023.11.09.11.29.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:29:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558145; x=1700162945; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RHS4Z4THTDrdonuMomFxK3JmiClhr4y8badmiGx38uU=; b=srhFSKYFdWB0BPPj3McGWeBEDt1J5YjW8dFWpWiphF45b8D2hC4I20hFhnQGv+hEs0 YlF38S6XfE9Oz5A2LtyLZI19U6UiTDQI0C+NCOr1ZOOckmx5NhZtTWq+JOqIWTFDHIs4 q5iBSYHtn0RhTuJHMHwMRdni3fJkJTKe69jys+vPAel/y5Ujv7ZFaT2jKBM8d67ORb+S b4gNnvvxAhdMBk2rouzly41OFeLvbZSW8KkWHwUxmmn9PKcBAZ1PbL5/dXeqV7GBP9vm 5JC9UwsIrvVjIpfPp6WvzBMm3sXm5ld27DwxSTCavLccXIydT+57sPpqwkDqoTYlX2ah eqSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558145; x=1700162945; 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=RHS4Z4THTDrdonuMomFxK3JmiClhr4y8badmiGx38uU=; b=D57OKciEPsUuZqK9I9Uqdeq5WtUur+EE/EYIRfx46Z0fbbg+xvHGf2OrjdhxVSVAbH CZjQp1lVfhzlsW5+j3tcyEzb+Ucn0P3CH/84cP+TxGHsOJtsiwIS2aMMqnAggZzAHg0t 3S7JTvGVdoqqHCfU15HWgvFT0tMAKamrnfeFQdaA9IXWwCc7u2u7fy7vg+L8QiweCK1G JfNn3NATKW6+rFEBenYmgG7zdL8/pSQW5RMW7uA8IHFvv/60O5l11qBwEEOnUdlh/FHt cyAnqzNbIcaxxwQy6R9tbhQOWp0gxg9Br0gC+PFaLIDdiDFpxFiGsHX161yBCX+81tYE 17LQ== X-Gm-Message-State: AOJu0YzrRCwKyLQiE5pB7Wiip/J2nxCysGqcm4f3WDUL9y0G3GWSjVqC ZLvWdSfJ2nUFcJuE1QjYirJiRnvaWIHTOtJRutVyJg== X-Google-Smtp-Source: AGHT+IHXkY9UsEk1pUD7sRTwEoyz3cZAuo+O1RcB0EcPzc4SAAb7hsOUbik4GhbKjbYbhKz1aDV7YQ== X-Received: by 2002:a17:907:9304:b0:9c7:5186:de1a with SMTP id bu4-20020a170907930400b009c75186de1amr5108548ejc.8.1699558144629; Thu, 09 Nov 2023 11:29:04 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gavin Shan , Paolo Bonzini , Mark Cave-Ayland , Peter Maydell , Evgeny Iakovlev , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH-for-8.2 v4 08/10] hw/char/pl011: Rename RX FIFO methods Date: Thu, 9 Nov 2023 20:28:12 +0100 Message-ID: <20231109192814.95977-9-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109192814.95977-1-philmd@linaro.org> References: <20231109192814.95977-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=philmd@linaro.org; helo=mail-ej1-x62d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699558345405100007 In preparation of having a TX FIFO, rename the RX FIFO methods. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Tested-by: Alex Benn=C3=A9e --- 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 ca931be139..727decd428 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -369,7 +369,7 @@ static int pl011_can_receive(void *opaque) return r; } =20 -static void pl011_put_fifo(void *opaque, uint32_t value) +static void pl011_fifo_rx_put(void *opaque, uint32_t value) { PL011State *s =3D (PL011State *)opaque; int slot; @@ -380,9 +380,9 @@ static void pl011_put_fifo(void *opaque, uint32_t value) s->read_fifo[slot] =3D value; s->read_count++; s->flags &=3D ~PL011_FLAG_RXFE; - trace_pl011_put_fifo(value, s->read_count); + trace_pl011_fifo_rx_put(value, s->read_count); if (s->read_count =3D=3D pipe_depth) { - trace_pl011_put_fifo_full(); + trace_pl011_fifo_rx_full(); s->flags |=3D PL011_FLAG_RXFF; } if (s->read_count =3D=3D s->read_trigger) { @@ -393,13 +393,13 @@ static void pl011_put_fifo(void *opaque, uint32_t val= ue) =20 static void pl011_receive(void *opaque, const uint8_t *buf, int size) { - pl011_put_fifo(opaque, *buf); + pl011_fifo_rx_put(opaque, *buf); } =20 static void pl011_event(void *opaque, QEMUChrEvent event) { if (event =3D=3D CHR_EVENT_BREAK) { - pl011_put_fifo(opaque, DR_BE); + pl011_fifo_rx_put(opaque, DR_BE); } } =20 diff --git a/hw/char/trace-events b/hw/char/trace-events index 7a398c82a5..bc9e84261f 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 *reg= name) "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%0= 3x value 0x%08x reg %s" pl011_can_receive(uint32_t lcr, int read_count, int r) "LCR 0x%08x read_co= unt %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 ", f= brd: %" PRIu32 ")" =20 # cmsdk-apb-uart.c --=20 2.41.0 From nobody Sat May 18 21:16:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699558185; cv=none; d=zohomail.com; s=zohoarc; b=VCVkK1nb6s3V6WpKTVqU3NRfM8ZIE6UyN4JoargAiG6/HPKf8Hbcc6lDL9n0mDizWTkhhCmXEB+DmePDkpsjtisQCNzQzZbRjHfmuLnbol+1YdJI2m28/V+nruk2SJH6u4C23dTWptXsTR+MvkZgzx0amK+RH33BNK3En6KPO8k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699558185; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VbCASInnNu6Q9uFgn8bNgw0dLduM6GSUn61bZ+goPO8=; b=AAg37uqrDgnW7IzYngFlpjYCno7lj7oNtF6pn/6jRrbSKOSPKwMcOOGC8YBHEbhCZVG2KmFa2/yoqhxeDXBQb4t4lICUDc7MW7Z117VW7W36p0tXwGwSuYuEUdKMKuM8dLiy9EDWL2WuU98uvyBEcVwXnmwGXrYY8YDjifwmFXA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699558185099319.57234716689914; Thu, 9 Nov 2023 11:29:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1AiU-0006f5-LI; Thu, 09 Nov 2023 14:29:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1AiJ-0005lZ-Px for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:17 -0500 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1AiH-0005OE-CT for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:14 -0500 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5437269a661so4805900a12.0 for ; Thu, 09 Nov 2023 11:29:12 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id dv16-20020a170906b81000b009a1c05bd672sm2902807ejb.127.2023.11.09.11.29.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:29:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558150; x=1700162950; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VbCASInnNu6Q9uFgn8bNgw0dLduM6GSUn61bZ+goPO8=; b=aPz1kT8tU/br4Ec1wAGjYyD4QDrp3n3D6WhvdD2rWaRtqEU5d28fgvFtYu9jCQ1sg8 sfgVeC6Jd8MYr/B+8yKOwnY9zSfUNSunRXY+SkX08lsXi1QPSBuCIxf5upybT3IjPOh3 XV00CW8P7TLqzTNElYZwPdbSX9ZytJY4P9DinM30KfZugI9+0my51V4ayq3rjkjSuwdu muqZhj0z5FrDHUB+W8Url9kGmjyrUWNYRPUhIrb0/uTrJO3zQxb5BOvXGZ/siIyuKdtQ aAf45h+y2hDxj+yAdNVdaNYZUpth9bKi66xXcDfV37dxtpWg570UF+wo6z8LcvJbcXpF KWSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558150; x=1700162950; 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=VbCASInnNu6Q9uFgn8bNgw0dLduM6GSUn61bZ+goPO8=; b=o2/Ua4JmBxj+1WARDmWYPBaurlk8f036joflcwZlE2doQ67tGhXABaw2NgcgfpyZpH akJfyGL+T/EpdkytFR3muuyZHBTMRkMat1CNbLdvaITpzyIMU21Ihw+uZ3Eg5x/qkHkU mTugOKP5asKVWNRTWSjKLDSR6I9f3CiheEo4ssybpSYT+Gk6MHfoIn7dWjAiyw2uBKu+ ueCFkCw6YAeytwiYp/7QD3F5a/OlTLzT5j26OIatfG0MM8uQblIicleojvyjes2Q/CHy dLO+jCZZgy7Tr72EKqiZ52ujZAJrJ8Sk489W7d1NW0t7VQ74kHWtyO86nZxwy3o0JL0z d92g== X-Gm-Message-State: AOJu0YytUcBVP4UrOP3lvmq/+EujbJFz9vSQxOGLDtbXlkq6ItpuN5Nb EhYDWh+B83CeVvCYt+pikh4ox2RKkJiQfdblEQpL9A== X-Google-Smtp-Source: AGHT+IFZ9OQdhANq1bPsek6/gcE7FIRaEr3Po/5bXioUHPDEhyNKFqMYWYTc+1BMRXX3iJGYg1lXtg== X-Received: by 2002:a17:906:bc85:b0:9b2:bdbb:f145 with SMTP id lv5-20020a170906bc8500b009b2bdbbf145mr190299ejb.34.1699558150739; Thu, 09 Nov 2023 11:29:10 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gavin Shan , Paolo Bonzini , Mark Cave-Ayland , Peter Maydell , Evgeny Iakovlev , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-8.2 v4 09/10] hw/char/pl011: Add transmit FIFO to PL011State Date: Thu, 9 Nov 2023 20:28:13 +0100 Message-ID: <20231109192814.95977-10-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109192814.95977-1-philmd@linaro.org> References: <20231109192814.95977-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=philmd@linaro.org; helo=mail-ed1-x534.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699558186408100014 In order to make the next commit easier to review, introduce the transmit FIFO, but do not yet use it. When migrating from new to old VM: - if the fifo is empty, migration will still work because of the subsection. - if the fifo is not empty, the subsection will be ignored, with the only consequence being that some characters will be dropped. Uninline pl011_reset_tx_fifo(). Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Alex Benn=C3=A9e --- include/hw/char/pl011.h | 2 ++ hw/char/pl011.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 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" =20 #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; }; =20 DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr); diff --git a/hw/char/pl011.c b/hw/char/pl011.c index 727decd428..f474f56780 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -147,11 +147,13 @@ static inline void pl011_reset_rx_fifo(PL011State *s) s->flags |=3D PL011_FLAG_RXFE; } =20 -static inline void pl011_reset_tx_fifo(PL011State *s) +static void pl011_reset_tx_fifo(PL011State *s) { /* Reset FIFO flags */ s->flags &=3D ~PL011_FLAG_TXFF; s->flags |=3D PL011_FLAG_TXFE; + + fifo8_reset(&s->xmit_fifo); } =20 static void pl011_write_txdata(PL011State *s, uint8_t data) @@ -436,6 +438,24 @@ static const VMStateDescription vmstate_pl011_clock = =3D { } }; =20 +static bool pl011_xmit_fifo_state_needed(void *opaque) +{ + PL011State* s =3D opaque; + + return !fifo8_is_empty(&s->xmit_fifo); +} + +static const VMStateDescription vmstate_pl011_xmit_fifo =3D { + .name =3D "pl011/xmit_fifo", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D pl011_xmit_fifo_state_needed, + .fields =3D (VMStateField[]) { + VMSTATE_FIFO8(xmit_fifo, PL011State), + VMSTATE_END_OF_LIST() + } +}; + static int pl011_post_load(void *opaque, int version_id) { PL011State* s =3D opaque; @@ -487,7 +507,11 @@ static const VMStateDescription vmstate_pl011 =3D { .subsections =3D (const VMStateDescription * []) { &vmstate_pl011_clock, NULL - } + }, + .subsections =3D (const VMStateDescription * []) { + &vmstate_pl011_xmit_fifo, + NULL + }, }; =20 static Property pl011_properties[] =3D { @@ -502,6 +526,7 @@ static void pl011_init(Object *obj) PL011State *s =3D PL011(obj); int i; =20 + fifo8_create(&s->xmit_fifo, PL011_FIFO_DEPTH); memory_region_init_io(&s->iomem, OBJECT(s), &pl011_ops, s, "pl011", 0x= 1000); sysbus_init_mmio(sbd, &s->iomem); for (i =3D 0; i < ARRAY_SIZE(s->irq); i++) { @@ -514,6 +539,13 @@ static void pl011_init(Object *obj) s->id =3D pl011_id_arm; } =20 +static void pl011_finalize(Object *obj) +{ + PL011State *s =3D PL011(obj); + + fifo8_destroy(&s->xmit_fifo); +} + static void pl011_realize(DeviceState *dev, Error **errp) { PL011State *s =3D PL011(dev); @@ -557,6 +589,7 @@ static const TypeInfo pl011_arm_info =3D { .parent =3D TYPE_SYS_BUS_DEVICE, .instance_size =3D sizeof(PL011State), .instance_init =3D pl011_init, + .instance_finalize =3D pl011_finalize, .class_init =3D pl011_class_init, }; =20 --=20 2.41.0 From nobody Sat May 18 21:16:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699558177; cv=none; d=zohomail.com; s=zohoarc; b=nb+MQU+zTG4xPxMysx8iS0nldFG6YZWbaV9Z1ZEZKMIQmETaXMPRTot31/7Cbjw43bRxWPnluluusj0uYPeWDf95W/eZgmWDBdUjKzK2tt/5Y9WS9Gt1ec3oyb+ibXLDtUXNnZyZeA+GizqWHPfKwdY3fR4CT0XtjNE8lWUvgts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699558177; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=L0ZgfFAgA7ypETy4OWUsXUiUb+FjTb/S73XLff6YN2Y=; b=HYSk7QB+yuecJyNb/CY+BopMvwoQViTMYCFMBs4/7d+uUqXctEsdkMcpGNCUVWuw+LOAJtiZv/SsbwpbdcmE0mBRESyYTRFow7TNb205xdhysuE5OH6IJYHonwcAD3ZZKde6cq+yPXxRixT/lm75wJry6J+HAeKVM5yv62GNzik= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699558177781823.1453980529518; Thu, 9 Nov 2023 11:29:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1AiS-0006LR-Hi; Thu, 09 Nov 2023 14:29:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r1AiP-0005rH-Ej for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:21 -0500 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1AiM-0005Os-P0 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 14:29:20 -0500 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9dd6dc9c00cso216087366b.3 for ; Thu, 09 Nov 2023 11:29:18 -0800 (PST) Received: from m1x-phil.lan ([176.187.199.161]) by smtp.gmail.com with ESMTPSA id f4-20020a170906048400b00988e953a586sm2933836eja.61.2023.11.09.11.29.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 09 Nov 2023 11:29:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699558157; x=1700162957; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L0ZgfFAgA7ypETy4OWUsXUiUb+FjTb/S73XLff6YN2Y=; b=v3mqpWyBsXXej/2han14VNwj7ZGHEFIRdaiWj0FRkbUWrH6SlEDfkky/bVDJZor1EV dlivelR41Btds7kJLU3GtWq/OLC9PWOR0Ij7tHBuk5lmN1gs1vJv0q9d8C87hVlJc6+r 44OdAIFhDVfRiUmPcRxb1BpGnnmqpgbUMIqBQkjBYW7tiAADH2Z3M2Cq8RlFh0ri7953 z4H92+iJSydoxA93hHvVPalTu+cP/iHgznBLl99C9CpJ18+95fO76CwHybKBLh7RIcSG dqTZZ0PVr82sSF5B7dG+wKOPcPUEZ3Sd8GRLMs6BQKLxU91kR106rMqgT3qFjjAL5BfH Ymig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699558157; x=1700162957; 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=L0ZgfFAgA7ypETy4OWUsXUiUb+FjTb/S73XLff6YN2Y=; b=AYTMAVb8aHOWfH5FRC9KNI1jFjG8Jke5D4D11fqoxAhf0T4B4laUiZ2nEhthL2nbHy bfa49Eye5XWFsTs0VDiOOWpcZOhGSxKaSUt0pRE5NZ6Zm2WvQb4sxvO+SHc89GIYaEjy dGVBnQtO4gkECjerRnTrBhUclHKRHaXpQ3KuAL9sDzP4FgmknUUHPhMI1ilxEbFz4vDI f0BgSD1IquGdXTD6C6epEJTngd9TBFJDbK9UfO/rsY17I+kWik0OhK/kC3V/4fiKCCFZ rBkT3PG+QH7lATUfPtQNGNut3e3aEUbJkmfBbGrJXXqi4N4QKfSLESvGD1CbBluc7JhL FD3w== X-Gm-Message-State: AOJu0YwhUlF0SHag5UFGu/YUtf90gE6l+YcHb+SmybXdmVkDi4xA3qBy jBapiV9r+KAxg4IbH4uMpZ2KAozKQOAEVr4JA8M5CQ== X-Google-Smtp-Source: AGHT+IFrycDbYp1brEZyLTehDLKygp53lllF/hswUqBO3IWUSyid/9YWQor0+3ILzSpUZO2vnonAPQ== X-Received: by 2002:a17:907:3e1c:b0:9b2:d554:da0e with SMTP id hp28-20020a1709073e1c00b009b2d554da0emr5818301ejc.69.1699558157027; Thu, 09 Nov 2023 11:29:17 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gavin Shan , Paolo Bonzini , Mark Cave-Ayland , Peter Maydell , Evgeny Iakovlev , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Mikko Rapeli Subject: [PATCH-for-8.2 v4 10/10] hw/char/pl011: Implement TX FIFO Date: Thu, 9 Nov 2023 20:28:14 +0100 Message-ID: <20231109192814.95977-11-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109192814.95977-1-philmd@linaro.org> References: <20231109192814.95977-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=philmd@linaro.org; helo=mail-ej1-x629.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699558178543100003 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=3D149574 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). We only migrate the TX FIFO if it is in use. Reported-by: Mikko Rapeli Suggested-by: Alex Benn=C3=A9e Signed-off-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Alex Benn=C3=A9e --- hw/char/pl011.c | 107 ++++++++++++++++++++++++++++++++++++++++--- hw/char/trace-events | 4 ++ 2 files changed, 105 insertions(+), 6 deletions(-) diff --git a/hw/char/pl011.c b/hw/char/pl011.c index f474f56780..a14ece4f07 100644 --- a/hw/char/pl011.c +++ b/hw/char/pl011.c @@ -57,6 +57,9 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Char= dev *chr) /* Data Register, UARTDR */ #define DR_BE (1 << 10) =20 +/* 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) @@ -156,6 +159,68 @@ static void pl011_reset_tx_fifo(PL011State *s) fifo8_reset(&s->xmit_fifo); } =20 +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 &=3D ~RSR_OE; + return G_SOURCE_REMOVE; +} + +static gboolean pl011_xmit(void *do_not_use, GIOCondition cond, void *opaq= ue) +{ + PL011State *s =3D opaque; + int ret; + const uint8_t *buf; + uint32_t buflen; + uint32_t count; + bool tx_enabled; + + tx_enabled =3D (s->cr & CR_UARTEN) && (s->cr & CR_TXE); + if (!tx_enabled) { + /* + * If TX is disabled, nothing to do. + * Keep the potentially used FIFO as is. + */ + return G_SOURCE_REMOVE; + } + + if (!qemu_chr_fe_backend_connected(&s->chr)) { + /* Instant drain the fifo when there's no back-end */ + return pl011_drain_tx(s); + } + + count =3D fifo8_num_used(&s->xmit_fifo); + if (count < 1) { + /* FIFO empty */ + return G_SOURCE_REMOVE; + } + + /* Transmit as much data as we can */ + buf =3D fifo8_peek_buf(&s->xmit_fifo, count, &buflen); + ret =3D qemu_chr_fe_write(&s->chr, buf, buflen); + if (ret >=3D 0) { + /* Pop the data we could transmit */ + trace_pl011_fifo_tx_xmit(ret); + fifo8_pop_buf(&s->xmit_fifo, ret, NULL); + s->int_level |=3D INT_TX; + } + + if (!fifo8_is_empty(&s->xmit_fifo)) { + /* Reschedule another transmission if we couldn't transmit all */ + guint r =3D qemu_chr_fe_add_watch(&s->chr, G_IO_OUT | G_IO_HUP, + pl011_xmit, s); + if (!r) { + /* Error in back-end? */ + return pl011_drain_tx(s); + } + } + + pl011_update(s); + + return G_SOURCE_REMOVE; +} + static void pl011_write_txdata(PL011State *s, uint8_t data) { if (!(s->cr & CR_UARTEN)) { @@ -165,11 +230,25 @@ static void pl011_write_txdata(PL011State *s, uint8_t= data) qemu_log_mask(LOG_GUEST_ERROR, "PL011 data written to disabled TX = UART\n"); } =20 - /* XXX this blocks entire thread. Rewrite to use - * qemu_chr_fe_write and background I/O callbacks */ - qemu_chr_fe_write_all(&s->chr, &data, 1); - s->int_level |=3D INT_TX; - pl011_update(s); + if (fifo8_is_full(&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 |=3D RSR_OE; + return; + } + + trace_pl011_fifo_tx_put(data); + fifo8_push(&s->xmit_fifo, data); + if (fifo8_is_full(&s->xmit_fifo)) { + s->flags |=3D PL011_FLAG_TXFF; + } + + pl011_xmit(NULL, G_IO_OUT, s); } =20 static uint32_t pl011_read_rxdata(PL011State *s) @@ -331,10 +410,21 @@ static void pl011_write(void *opaque, hwaddr offset, s->lcr =3D value; pl011_set_read_trigger(s); break; - case 12: /* UARTCR */ + case 12: /* UARTCR */ { + uint16_t en_bits =3D s->cr & (CR_UARTEN | CR_TXE | CR_RXE); + uint16_t dis_bits =3D value & (CR_UARTEN | CR_TXE | CR_RXE); + if (en_bits ^ dis_bits && !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); + } /* ??? Need to implement the enable and loopback bits. */ s->cr =3D value; break; + } case 13: /* UARTIFS */ s->ifl =3D value; pl011_set_read_trigger(s); @@ -477,6 +567,11 @@ static int pl011_post_load(void *opaque, int version_i= d) s->read_pos =3D 0; } =20 + if (!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; } =20 diff --git a/hw/char/trace-events b/hw/char/trace-events index bc9e84261f..ee00af0c66 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 *r= egname) "addr 0x%03x val pl011_can_receive(uint32_t lcr, int read_count, int r) "LCR 0x%08x read_co= unt %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(uint8_t byte) "TX FIFO push [0x%02x]" +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 ", f= brd: %" PRIu32 ")" =20 # cmsdk-apb-uart.c --=20 2.41.0