From nobody Sun Nov 24 06:47:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=ilande.co.uk Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724847948581897.5834578748028; Wed, 28 Aug 2024 05:25:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjHhs-0006PS-Ks; Wed, 28 Aug 2024 08:23:25 -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 1sjHhm-0006OD-JI for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:18 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjHhl-0001AA-7a for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:18 -0400 Received: from [2a02:8012:c93d:0:260e:bf57:a4e9:8142] (helo=cheesecake.fritz.box) by mail.ilande.co.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sjHhR-000B8d-BO; Wed, 28 Aug 2024 13:23:01 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ilande.co.uk; s=20220518; h=Subject:Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=hB6ok8jCC61uJuqfFDuAoy++TNZ8tvK5rSvS1kFCYBI=; b=YUyyFCpSIlSbh2h/wPUD+TyFkt vjrZo9ItGM/iFQS9zDJNkEGXBMhWTTljo3zlM145ZCMRUedgH0wAgS2DsTgjJn+FmLjO1PX6Ay4BC SpFND1WnBc7ypVDFlQqwPBD2mde8yap+wncCrXxEcLt3M8VSRrMudA9Q7H4oSYQr2bIlskgk6SW2Z A/wf+pPGNianJ5jAgaSGrfzl8AhMyhD0W3kWZQ5C3R/MV8ylzfcCPNtEzx8oydLywlDb/g7+2wT72 rTOK3ysuXorbRkc/1ecc3nI0fvij9sLzZfit0eRL4Q8NXsn/m68QmMNHMyzxnIohMRLsIl0ehPuXk QiuHCUbc3CrLMOJC9QKBt7d/F8Sr/tFd2ZXSyUuir0b1ppXljbtL26f5JacdG/kzl4MhYcEcSdGQV Ftf5K2qiiqaiW5Wdgg8LPoN6SgeYF1qmNI+XvxwBAeLbNEQkfRhzhJD4r1volB1fLAmhdFi4jpU/F rjZbyhRo12Y446slHPkrnqt6Im/XggQBavjPNNuwZxZdRhYtVrSB9LrETErINEhhaz4RT8pIOy9e+ qfXo7WRZSuHsAzsmNy2L341hvYoWh/YwHx2kEXv3Yx4QF2KRovWhjGHfg9tDK4z4dVQusivKWyzlY tGreRrZnZBHH91USuS0gqdTrXHlLRQ1/BgjblCOKI=; From: Mark Cave-Ayland To: philmd@linaro.org, Alistair.Francis@wdc.com, tavip@google.com, qemu-devel@nongnu.org Date: Wed, 28 Aug 2024 13:22:50 +0100 Message-Id: <20240828122258.928947-2-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> References: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a02:8012:c93d:0:260e:bf57:a4e9:8142 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH 1/9] fifo8: rename fifo8_peekpop_buf() to fifo8_peekpop_bufptr() X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.ilande.co.uk) 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=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.ilande.co.uk 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, 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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724847948903116600 Content-Type: text/plain; charset="utf-8" This is to emphasise that the function returns a pointer to the internal FI= FO buffer. Signed-off-by: Mark Cave-Ayland Reviewed-by: Alistair Francis Reviewed-by: Octavian Purdila Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- util/fifo8.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/fifo8.c b/util/fifo8.c index 1ffa19d900..61bce9d9a0 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -71,8 +71,8 @@ uint8_t fifo8_pop(Fifo8 *fifo) return ret; } =20 -static const uint8_t *fifo8_peekpop_buf(Fifo8 *fifo, uint32_t max, - uint32_t *numptr, bool do_pop) +static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo, uint32_t max, + uint32_t *numptr, bool do_pop) { uint8_t *ret; uint32_t num; @@ -94,12 +94,12 @@ static const uint8_t *fifo8_peekpop_buf(Fifo8 *fifo, ui= nt32_t max, =20 const uint8_t *fifo8_peek_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *nump= tr) { - return fifo8_peekpop_buf(fifo, max, numptr, false); + return fifo8_peekpop_bufptr(fifo, max, numptr, false); } =20 const uint8_t *fifo8_pop_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numpt= r) { - return fifo8_peekpop_buf(fifo, max, numptr, true); + return fifo8_peekpop_bufptr(fifo, max, numptr, true); } =20 uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen) --=20 2.39.2 From nobody Sun Nov 24 06:47:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=ilande.co.uk Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724847850151488.15526274283786; Wed, 28 Aug 2024 05:24:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjHhu-0006Rc-TZ; Wed, 28 Aug 2024 08:23:26 -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 1sjHhq-0006P4-0n for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:22 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjHho-0001Ae-HU for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:21 -0400 Received: from [2a02:8012:c93d:0:260e:bf57:a4e9:8142] (helo=cheesecake.fritz.box) by mail.ilande.co.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sjHhV-000B8d-Kv; Wed, 28 Aug 2024 13:23:05 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ilande.co.uk; s=20220518; h=Subject:Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Whi/OJqkMAmmCjgxXKWJaew88JUq9AzmR4knGJiiXTY=; b=UVFLvsTnoazAzV0jbwjpVU7y5T CM0NUKsNXco+lFY4Cc+1WFTiuPNjFfKoOFpvaKSyBQZOlnh6s/Elb9ihCwisMqMSkeXcayoth8KyM 0qg33CeeVvAFapEsvYvHJGlJy00BLroNlACS+cz8Qm2CbxnyvTNsmZiGyAWsLqDBtS8WXLJNx2eQw ZY2iVvJiR9p004EcoZO1lo30fE35IRbIXBp5rOIrX4ociS2x+aBKMhi/2C6rInVCw3Y0hMTGf8Q6U 9kA/LYY0hKPvkKKghq+rO0JG7XdFqv9dqP5HuR/ODUP1YA2hNQP05j9ploR7wq02U7zFiHd2+qFaF 7t6AHRU0oFOIotZ+LZVEhpWvov6iI/xwYEllks9FAy1jtFtg2C4sOpzTfUb2RYSclWY5AA1ILjhS0 3Aj7fYWmoZoFI9dMilpUVPjxstSVjX17GWeGDvsgstxXGA6k4lVhFkRkY61rZ2Kyxbxo87AKhf7Ph gpPrGh+Io8fDgt2Kn70p8u9WgH/jC6CTxRupymjFtfw/cJvnM7pWxhC9z1Ip0wG2W4RXID4ShIRGG +9Qp2VKEAMOEc51oPXemcHtDimdwQ9/x8Y/nXUafI7efI3Cg8FmpINETFH5WxImr6eakFstQamjVt 8SymRxrbPWTsvnW26l2Q1QJmFLlzaJATizFmwawxg=; From: Mark Cave-Ayland To: philmd@linaro.org, Alistair.Francis@wdc.com, tavip@google.com, qemu-devel@nongnu.org Date: Wed, 28 Aug 2024 13:22:51 +0100 Message-Id: <20240828122258.928947-3-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> References: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a02:8012:c93d:0:260e:bf57:a4e9:8142 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH 2/9] fifo8: introduce head variable for fifo8_peekpop_bufptr() X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.ilande.co.uk) 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=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.ilande.co.uk 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, 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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724847850938116600 Content-Type: text/plain; charset="utf-8" Rather than operate on fifo->head directly, introduce a new head variable w= hich is set to the value of fifo->head and use it instead. This is to allow future adjustment of the head position within the internal FIFO buffer. Signed-off-by: Mark Cave-Ayland Reviewed-by: Alistair Francis Reviewed-by: Octavian Purdila Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- util/fifo8.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/util/fifo8.c b/util/fifo8.c index 61bce9d9a0..5faa814a6e 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -75,11 +75,12 @@ static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo,= uint32_t max, uint32_t *numptr, bool do_pop) { uint8_t *ret; - uint32_t num; + uint32_t num, head; =20 assert(max > 0 && max <=3D fifo->num); - num =3D MIN(fifo->capacity - fifo->head, max); - ret =3D &fifo->data[fifo->head]; + head =3D fifo->head; + num =3D MIN(fifo->capacity - head, max); + ret =3D &fifo->data[head]; =20 if (do_pop) { fifo->head +=3D num; --=20 2.39.2 From nobody Sun Nov 24 06:47:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=ilande.co.uk Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724847906171397.98032598674615; Wed, 28 Aug 2024 05:25:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjHhv-0006Uv-Lj; Wed, 28 Aug 2024 08:23:27 -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 1sjHhu-0006QG-8T for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:26 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjHhs-0001B3-Pg for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:25 -0400 Received: from [2a02:8012:c93d:0:260e:bf57:a4e9:8142] (helo=cheesecake.fritz.box) by mail.ilande.co.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sjHhZ-000B8d-Uj; Wed, 28 Aug 2024 13:23:10 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ilande.co.uk; s=20220518; h=Subject:Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=amnbiaESMVkGu73EcfVAhp7lxkz3+iitVygR2r/zkrI=; b=zs3ZP1YeVDDdkBxkTN2nXbYxo2 +DTJCZzUYLFGVFm9X3Xz06YGnrPvO5h88yF0Jz7zphb5rX0DWbTRITsoIgnjiGPf8GSW5jFNCos1v vWAlyq4XWrn9P9cPubL3afdiURUlo99GRuekEbhcBmnpvCNT0TcSYjGFU6LiV3GeOVs6gzA4p8bFT G2UaXn2Z/YpfNM5o/Fw83c6zH8n3r7Rhgs9bp4/Pqv+B0vB+z+zGwiagoTKw2RkZ0lMVRsuSOuSSG 3dUfazbUmgl67nRY2N+haVOMBWW0SxmBIGpVmsxgbAdPeKsycScpXmfo3dBykvdB74YCBFZWuaYWZ lz2fkD7w2fvVrA4jvKOYv2tKW4oXGcOr2xwUjlB+5KEpHDjxYE9O1VXeP4dmQZfoc2V82J9Qxn8fa qGQkNor5M02Mslxq4sltuPRMJPdVidOPVpktXertAbfsD5jfadY/Z3rXLLNmyVeDrkM91w3N8Gfgi WJZJrVu93gakG6Tag4G5WVMi4QkdqLBbt3BT/MviK+o2wAOzob7SRWqVxFknbrrkNwRXSPaSH1eqv 9xYE++yXJ+55IuRRxrVB28ShbrXQ+kHeJBrKbUsdIbA3prb3cYYTbe/vjNjcB5cj8B9Z0j+BeoM9H 8jiv00SsTsoh73P5k/gnDkXVC9yWPtKZdMyAdAkrs=; From: Mark Cave-Ayland To: philmd@linaro.org, Alistair.Francis@wdc.com, tavip@google.com, qemu-devel@nongnu.org Date: Wed, 28 Aug 2024 13:22:52 +0100 Message-Id: <20240828122258.928947-4-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> References: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a02:8012:c93d:0:260e:bf57:a4e9:8142 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH 3/9] fifo8: add skip parameter to fifo8_peekpop_bufptr() X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.ilande.co.uk) 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=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.ilande.co.uk 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, 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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724847906838116600 Content-Type: text/plain; charset="utf-8" The skip parameter specifies the number of bytes to be skipped from the cur= rent FIFO head before the peek or pop operation. Signed-off-by: Mark Cave-Ayland Reviewed-by: Alistair Francis Reviewed-by: Octavian Purdila Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- util/fifo8.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/util/fifo8.c b/util/fifo8.c index 5faa814a6e..62d6430b05 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -72,18 +72,20 @@ uint8_t fifo8_pop(Fifo8 *fifo) } =20 static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo, uint32_t max, - uint32_t *numptr, bool do_pop) + uint32_t skip, uint32_t *numptr, + bool do_pop) { uint8_t *ret; uint32_t num, head; =20 assert(max > 0 && max <=3D fifo->num); - head =3D fifo->head; + assert(skip <=3D fifo->num); + head =3D (fifo->head + skip) % fifo->capacity; num =3D MIN(fifo->capacity - head, max); ret =3D &fifo->data[head]; =20 if (do_pop) { - fifo->head +=3D num; + fifo->head =3D head + num; fifo->head %=3D fifo->capacity; fifo->num -=3D num; } @@ -95,12 +97,12 @@ static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo,= uint32_t max, =20 const uint8_t *fifo8_peek_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *nump= tr) { - return fifo8_peekpop_bufptr(fifo, max, numptr, false); + return fifo8_peekpop_bufptr(fifo, max, 0, numptr, false); } =20 const uint8_t *fifo8_pop_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numpt= r) { - return fifo8_peekpop_bufptr(fifo, max, numptr, true); + return fifo8_peekpop_bufptr(fifo, max, 0, numptr, true); } =20 uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen) --=20 2.39.2 From nobody Sun Nov 24 06:47:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=ilande.co.uk Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172484795367835.460654828487236; Wed, 28 Aug 2024 05:25:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjHi0-0006nZ-B1; Wed, 28 Aug 2024 08:23:32 -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 1sjHhx-0006eB-Rv for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:29 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjHhw-0001BI-El for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:29 -0400 Received: from [2a02:8012:c93d:0:260e:bf57:a4e9:8142] (helo=cheesecake.fritz.box) by mail.ilande.co.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sjHhe-000B8d-5E; Wed, 28 Aug 2024 13:23:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ilande.co.uk; s=20220518; h=Subject:Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=vGpfbNq2Of1XusU1luTkApo6WOYeX4WUm8cX9OwaBRI=; b=Uz0vGsRR4OzggowHrkjjlfiVLY Ru9XPhDKn3Y3mW6DGreleIxFP+/o5ILqKhR7N+wuXcPUYpS/ReL3u4NqAEAzPWxwPLQUDQpxOpf1v EgMl6snJlfVne/phXJM2h+f8P5UFeCuWvMvmjplsSlrTW5XjbmahY2f1yAF2P0h3ZU+xn8fBM+3nw E44TqYvzSN4k/xIImpJZ8AWicjezIwBqpErHBLft1g/yaDQqw1wKn48OSDBi7Aven85Cd8ZClAzP+ CE6lq5BTtzpmU9G047MADDP+w5y6CgmaNhrIfh3NB7KD7N6SdJsn53OpnWrYmCBc2PziZ4i1TFPI9 DmKSwMPvG4JjwwVfXgnGpVS7IT8e0Y139iACTXfwKhGcNhBl9DYu2nlNryF/D4Pm5yan6lK2MIkQR ecdWiSWfKQ1TAxpD1W5sUayaq7FYDE8ttsIjRxfCaSFQVbC+wzzTh3AcIu3ueeNgmuJUTMbbxxsk1 /jQQYrfMqRszxtu2DmvEj8RRVrssSWPKIgH1CfAjRsKmHsfq4QXIGHU2fExGN0KybovORLIS/F1j4 eZ+HLzz3wn3usEGm+bN+bjsAYpO+sIEkmVRonvemdZcYUqey2oykHkCBS6ar+Wo59aLvQ03utbMZz A93q/jHwHCHmf0GF3BP0/y1lmY+lAk/sjJc99OK+Y=; From: Mark Cave-Ayland To: philmd@linaro.org, Alistair.Francis@wdc.com, tavip@google.com, qemu-devel@nongnu.org Date: Wed, 28 Aug 2024 13:22:53 +0100 Message-Id: <20240828122258.928947-5-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> References: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a02:8012:c93d:0:260e:bf57:a4e9:8142 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH 4/9] fifo8: replace fifo8_pop_bufptr() with fifo8_peekpop_bufptr() in fifo8_pop_buf() X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.ilande.co.uk) 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=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.ilande.co.uk 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, 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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724847955163116600 Content-Type: text/plain; charset="utf-8" The upcoming peek functionality will require passing a non-zero value to fifo8_peekpop_bufptr(). Signed-off-by: Mark Cave-Ayland Reviewed-by: Alistair Francis Reviewed-by: Octavian Purdila Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- util/fifo8.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/fifo8.c b/util/fifo8.c index 62d6430b05..efe0117b1f 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -116,7 +116,7 @@ uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint= 32_t destlen) } =20 len =3D destlen; - buf =3D fifo8_pop_bufptr(fifo, len, &n1); + buf =3D fifo8_peekpop_bufptr(fifo, len, 0, &n1, true); if (dest) { memcpy(dest, buf, n1); } @@ -125,7 +125,7 @@ uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint= 32_t destlen) len -=3D n1; len =3D MIN(len, fifo8_num_used(fifo)); if (len) { - buf =3D fifo8_pop_bufptr(fifo, len, &n2); + buf =3D fifo8_peekpop_bufptr(fifo, len, 0, &n2, true); if (dest) { memcpy(&dest[n1], buf, n2); } --=20 2.39.2 From nobody Sun Nov 24 06:47:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=ilande.co.uk Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172484792819878.33211747293615; Wed, 28 Aug 2024 05:25:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjHi4-000746-MM; Wed, 28 Aug 2024 08:23:36 -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 1sjHi2-0006ua-3a for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:34 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjHi0-0001Bn-Kv for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:33 -0400 Received: from [2a02:8012:c93d:0:260e:bf57:a4e9:8142] (helo=cheesecake.fritz.box) by mail.ilande.co.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sjHhi-000B8d-EZ; Wed, 28 Aug 2024 13:23:18 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ilande.co.uk; s=20220518; h=Subject:Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=kf9Ve67a1UgUxcnM/R9AUK9NzEj+yPiW0W7QQ3PtyCM=; b=gNZexQRKV24C/BfydNKs6dyBdU dzZNib4N7p74yeBBXcbfwetGcnUeUshOq91wt9y4YgVURfkQ+4Xt5+gShzPP03WiehXxHVyVEoLpT g8Lkn5D/T/FUL6+6zbJv1VFes7ICkG8czYDCWhTNayeW/7lTa84hF92AFh9NRBSQkLbHmEeffGYdC vVAYi8cnjjVs/L1EL2AxRbxrofRxctuxD0sMeV1i0dVk0KwBw2uuuTmD6H4+GBxUaGCGXwElzJHrX Y91Jhp7MCXr7UOP8HtxzCtzH8HJldNhn3XxDXdnnU7U1BZ3QHZtjo8a1dWXEmMMQdpQG7+Y7Q0WS5 r3/mMPgTj4d4Q/g4IWkCjFFwSAHmC2Po/zTfsbCWZl7ZX7ghlEviChU/WF3wrhIxqMqwjugYJVFCb RGf2q7ZrOzaw3K0jtYALjiYZ3raWkHETYftUUNQDk/b6BHU8hqCPgEFMgj/VDwk52ox3tQ1scgySN oYUNBSHdVnspnN2BqEnEp4+sa/E4lJhJFQZeyzBjVtX5FQWb2qF8D0UPFdwlOo6wFlWWuOUsCp3+x hTaBwtKW1usaDfQRXllDduBoNC8oNIlO058dJ8Jz3dmjcuS7570v6vNMIK3ACjfiB7/2FRPkjkPHj EanZ5peBeWmg0H41EdRbE5GB9Xn89RcuxE+lhkUEo=; From: Mark Cave-Ayland To: philmd@linaro.org, Alistair.Francis@wdc.com, tavip@google.com, qemu-devel@nongnu.org Date: Wed, 28 Aug 2024 13:22:54 +0100 Message-Id: <20240828122258.928947-6-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> References: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a02:8012:c93d:0:260e:bf57:a4e9:8142 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH 5/9] fifo8: rename fifo8_pop_buf() to fifo8_peekpop_buf() X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.ilande.co.uk) 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=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.ilande.co.uk 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, 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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724847928844116600 Content-Type: text/plain; charset="utf-8" The fifo8_pop_buf() function will soon also be used for peek operations, so= rename the function accordingly. Create a new fifo8_pop_buf() wrapper function tha= t can be used by existing callers. Signed-off-by: Mark Cave-Ayland Reviewed-by: Alistair Francis Reviewed-by: Octavian Purdila Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- util/fifo8.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/util/fifo8.c b/util/fifo8.c index efe0117b1f..5453cbc1b0 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -105,7 +105,8 @@ const uint8_t *fifo8_pop_bufptr(Fifo8 *fifo, uint32_t m= ax, uint32_t *numptr) return fifo8_peekpop_bufptr(fifo, max, 0, numptr, true); } =20 -uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen) +static uint32_t fifo8_peekpop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t des= tlen, + bool do_pop) { const uint8_t *buf; uint32_t n1, n2 =3D 0; @@ -134,6 +135,11 @@ uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uin= t32_t destlen) return n1 + n2; } =20 +uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen) +{ + return fifo8_peekpop_buf(fifo, dest, destlen, true); +} + void fifo8_drop(Fifo8 *fifo, uint32_t len) { len -=3D fifo8_pop_buf(fifo, NULL, len); --=20 2.39.2 From nobody Sun Nov 24 06:47:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=ilande.co.uk Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724847856726840.7348648191385; Wed, 28 Aug 2024 05:24:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjHi9-0007MF-8t; Wed, 28 Aug 2024 08:23: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 1sjHi6-0007BE-92 for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:38 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjHi4-0001CB-PF for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:38 -0400 Received: from [2a02:8012:c93d:0:260e:bf57:a4e9:8142] (helo=cheesecake.fritz.box) by mail.ilande.co.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sjHhm-000B8d-L4; Wed, 28 Aug 2024 13:23:22 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ilande.co.uk; s=20220518; h=Subject:Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Ez0rcljDHngw2opcQWQvPxakBFq+td5nNgWaWj++x6U=; b=OWrtKi8gPCdisTcHiz0XgKQV4X Tkpnxx8MCkklCaO/RLpq6NN8n5eJySR6LKb/MszTcD0vyTRL/F+jMpBg1jhQSfdbBgHlVE2bP+PuL cKn24Pickmzl7ST+WwQBmx0DhQMGdkhJl0Vbpvy1JSBWPnwMNaK9zb0dTW0dd1AnDmi9WPg5qxhsh URfQ0rRlA3evt+OOL8aXV5vduY62o+bAmPBr9lcEmym44vogc2vxxmWleyQKwEtEIn1G9uvAL9mSp JOHaONxMi6fKeBVPn40KLqDEOf/3WNCOwj/rJu/s8TCwwqcqk4nGn9cWh1Qz/MpyutjKhDcXQJ/6W kQXIznti2FZ9gUCHyHznKwBva6wmOZRy1ebVBAA/hiLKAYf7ET1+HDKpjqD2HC724E8EyfPpLOuvA yO6zQhEHY6ODxNx/xdJcXmwQ8cR5Qwh+M4JV55mz4YSoB2H7OI234WWRS5QVDnk9dPaFZEIh6+uo2 FLo1EgJi5npwDtY2rjEDhw2IUe5Bey8j2hOICFJEmAjzWzcIn5jCLtnZRLqyty3eU2lEhLLO9HdsQ yDMeb+Y5iwMyVsobGPTXHiH8OMjVYB4Fkye5UNFjwo87C0TgYUPn4+l55A1Vfvohi8y2lqEHaIBqK 4lvNZN30xOUhscCSIQXbX0HbxktXOprVmqfi5iCL0=; From: Mark Cave-Ayland To: philmd@linaro.org, Alistair.Francis@wdc.com, tavip@google.com, qemu-devel@nongnu.org Date: Wed, 28 Aug 2024 13:22:55 +0100 Message-Id: <20240828122258.928947-7-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> References: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a02:8012:c93d:0:260e:bf57:a4e9:8142 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH 6/9] fifo8: honour do_pop argument in fifo8_peekpop_buf() X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.ilande.co.uk) 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=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.ilande.co.uk 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, 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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724847858594116600 Content-Type: text/plain; charset="utf-8" Pass the do_pop value from fifo8_peekpop_buf() to fifo8_peekpop_bufptr() to allow peeks to the FIFO buffer, including adjusting the skip parameter to handle the case where the internal FIFO buffer wraps around. Signed-off-by: Mark Cave-Ayland Reviewed-by: Alistair Francis Reviewed-by: Octavian Purdila Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- util/fifo8.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/fifo8.c b/util/fifo8.c index 5453cbc1b0..1031ffbe7e 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -117,7 +117,7 @@ static uint32_t fifo8_peekpop_buf(Fifo8 *fifo, uint8_t = *dest, uint32_t destlen, } =20 len =3D destlen; - buf =3D fifo8_peekpop_bufptr(fifo, len, 0, &n1, true); + buf =3D fifo8_peekpop_bufptr(fifo, len, 0, &n1, do_pop); if (dest) { memcpy(dest, buf, n1); } @@ -126,7 +126,7 @@ static uint32_t fifo8_peekpop_buf(Fifo8 *fifo, uint8_t = *dest, uint32_t destlen, len -=3D n1; len =3D MIN(len, fifo8_num_used(fifo)); if (len) { - buf =3D fifo8_peekpop_bufptr(fifo, len, 0, &n2, true); + buf =3D fifo8_peekpop_bufptr(fifo, len, do_pop ? 0 : n1, &n2, do_p= op); if (dest) { memcpy(&dest[n1], buf, n2); } --=20 2.39.2 From nobody Sun Nov 24 06:47:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=ilande.co.uk Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724847923528749.1158070214971; Wed, 28 Aug 2024 05:25:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjHiG-0007YY-3i; Wed, 28 Aug 2024 08:23: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 1sjHiA-0007S8-J9 for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:42 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjHi9-0001CW-53 for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:42 -0400 Received: from [2a02:8012:c93d:0:260e:bf57:a4e9:8142] (helo=cheesecake.fritz.box) by mail.ilande.co.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sjHhq-000B8d-RS; Wed, 28 Aug 2024 13:23:26 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ilande.co.uk; s=20220518; h=Subject:Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=iDYp5gaIqo5J6zZ1j+lA7kex8q6EDB2TjHYn/k4kYzg=; b=a90FM8UQIokhtJjW6rY/VneWto +rVb0LxtKHzBql7hXC9TrWklNMkIeRcEeGK1iiAKxpAUNN1VK/B8kdf2fx+VV1tndz3t/ZfzpfltB 0GNVqmTni2cwOjjqn8hb/tZrgO4WlnDbPk58S9P2+53dWGqP9Evgar1rvy5ct0ziZTZZ9YROne1fw K1cN0dNl/egywluwFbJ8eKTHLY/w7OaWTKWee63BpnY3Dp1L6XaiHt1FoK6FY222QsHeRtCFR9xCq Hegmve8BdYL8UFSshDdPV1k04CjtAZIxTjY6rAo9ZBd24YnEWzUvP0bhMGcfPaM7H3OpoNQr2xYZV IXXk97b/JzUrzv2QeJOLa/v40xDMuFEQ29+83cEkRhHUBCiGXDYms7uYV1l2SboISYo9J/mwcVh9e GDU6pIyhy2t3PupTyNSYyr9bYdHDrEPEUX6dppTu5QDZn5psl54C/feaR5ZFmFgiG0crE7iz/TQiI 2UDbjVDBMIIWszWqtl2cCdR55p88Xdllejc4PW1yKF5XR7N3xky/2FwVipH6TpQwzWr8lU8HyEtLK D38MO7Mo4w5OHetTGYa1p445rNxJ4CzTVw7WO5wnU+D3P7qKNRkQpCsKSfENCHqmnE6DRjtb2P4Ip PPGAZfX9rgIPYDQ0PxeDvkOUNgqevHYP48Y6ZnN8c=; From: Mark Cave-Ayland To: philmd@linaro.org, Alistair.Francis@wdc.com, tavip@google.com, qemu-devel@nongnu.org Date: Wed, 28 Aug 2024 13:22:56 +0100 Message-Id: <20240828122258.928947-8-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> References: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a02:8012:c93d:0:260e:bf57:a4e9:8142 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH 7/9] fifo8: add fifo8_peek_buf() function X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.ilande.co.uk) 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=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.ilande.co.uk 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, 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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724847924918116600 Content-Type: text/plain; charset="utf-8" This is a wrapper function around fifo8_peekpop_buf() that allows the calle= r to peek into FIFO, including handling the case where there is a wraparound of = the internal FIFO buffer. Signed-off-by: Mark Cave-Ayland Reviewed-by: Alistair Francis Reviewed-by: Octavian Purdila Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/fifo8.h | 14 ++++++++++++++ util/fifo8.c | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index d1d06754d8..d09984b146 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -76,6 +76,20 @@ uint8_t fifo8_pop(Fifo8 *fifo); */ uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen); =20 +/** + * fifo8_peek_buf: + * @fifo: FIFO to read from + * @dest: the buffer to write the data into (can be NULL) + * @destlen: size of @dest and maximum number of bytes to peek + * + * Peek a number of elements from the FIFO up to a maximum of @destlen. + * The peeked data is copied into the @dest buffer. + * Care is taken when the data wraps around in the ring buffer. + * + * Returns: number of bytes peeked. + */ +uint32_t fifo8_peek_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen); + /** * fifo8_pop_bufptr: * @fifo: FIFO to pop from diff --git a/util/fifo8.c b/util/fifo8.c index 1031ffbe7e..a8f5cea158 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -140,6 +140,11 @@ uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uin= t32_t destlen) return fifo8_peekpop_buf(fifo, dest, destlen, true); } =20 +uint32_t fifo8_peek_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen) +{ + return fifo8_peekpop_buf(fifo, dest, destlen, false); +} + void fifo8_drop(Fifo8 *fifo, uint32_t len) { len -=3D fifo8_pop_buf(fifo, NULL, len); --=20 2.39.2 From nobody Sun Nov 24 06:47:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=ilande.co.uk Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724847973363360.1061177864576; Wed, 28 Aug 2024 05:26:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjHiL-0007j8-0l; Wed, 28 Aug 2024 08:23:53 -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 1sjHiH-0007f3-Ph for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:49 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjHiG-0001DO-BC for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:49 -0400 Received: from [2a02:8012:c93d:0:260e:bf57:a4e9:8142] (helo=cheesecake.fritz.box) by mail.ilande.co.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sjHhv-000B8d-1O; Wed, 28 Aug 2024 13:23:31 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ilande.co.uk; s=20220518; h=Subject:Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=8A2FICmUmjowEj9RLWXSg7/Kx8EQAw4oc04eFwo72Js=; b=rSZEKM8DBeC5Slg1ILZ2eBVoNg p6jsOBm6e4VQe3tAlI7sC75ihGSkJ3ncO/BIiYCaYDd9jwHpCwok+lstzaPJhSZ9C7bNwP3upJSSS XIOpXJ/NVYwxvmrlBDDdUcVlG9HrbzFAap34aE/r2LLXTet8ePJZhhoxQKG2w4sztJDbcDK43+q2y 9EeaKWfnun8B/6eefn2A/hlcyv8PbZgZ1Joow7onAdTp0xyjo4hewSyQIVruM12/TMcCmNNpMPvLq 8apwfXUffFCTuHtqQo8xppbDbyjAW+vz7D49r7IPJLklttxo7//XBum973i7vrrlwLyVp6veYOxVF sQ7f9DKXMZ/5GO83PTLCwJGZzTZ7Fc26DjjB60T4FshrtrwInMOy8NS0srznWu30i8lsJ0KPETDWH cGCGeYgn64J1nkSkQs3yY1a6ai4x0R9pjurVO9F6KiQniJWPVvoPXta8mf3tmQqSeD0nW3HmEZV+M oG0hX0QmOP1BcLYEeNdLRL2JAlMYkyyj2vR6Fi2qv6HLc0A8Udx4LlVTYhTak3I23nsmIMJWit6HJ 8/PFUZCs/1XMNfyqGfoC4UrZyDYcDFtKfJyyXPHM0ibK4VgMy58YQVp51Uv+DxXKnq2o7657xCECO 554uBduUFf8S9g8EBRFeuke7HTFyNvWPBLd52T394=; From: Mark Cave-Ayland To: philmd@linaro.org, Alistair.Francis@wdc.com, tavip@google.com, qemu-devel@nongnu.org Date: Wed, 28 Aug 2024 13:22:57 +0100 Message-Id: <20240828122258.928947-9-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> References: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a02:8012:c93d:0:260e:bf57:a4e9:8142 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH 8/9] fifo8: introduce fifo8_peek() function X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.ilande.co.uk) 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=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.ilande.co.uk 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, 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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724847974976116600 Content-Type: text/plain; charset="utf-8" This allows uses to peek the byte at the current head of the FIFO. Signed-off-by: Mark Cave-Ayland Reviewed-by: Alistair Francis Reviewed-by: Octavian Purdila Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/fifo8.h | 11 +++++++++++ util/fifo8.c | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/include/qemu/fifo8.h b/include/qemu/fifo8.h index d09984b146..4f768d4ee3 100644 --- a/include/qemu/fifo8.h +++ b/include/qemu/fifo8.h @@ -62,6 +62,17 @@ void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, ui= nt32_t num); */ uint8_t fifo8_pop(Fifo8 *fifo); =20 +/** + * fifo8_peek: + * @fifo: fifo to peek from + * + * Peek the data byte at the current head of the FIFO. Clients are respons= ible + * for checking for emptyness using fifo8_is_empty(). + * + * Returns: The peeked data byte. + */ +uint8_t fifo8_peek(Fifo8 *fifo); + /** * fifo8_pop_buf: * @fifo: FIFO to pop from diff --git a/util/fifo8.c b/util/fifo8.c index a8f5cea158..a26da66ad2 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -71,6 +71,12 @@ uint8_t fifo8_pop(Fifo8 *fifo) return ret; } =20 +uint8_t fifo8_peek(Fifo8 *fifo) +{ + assert(fifo->num > 0); + return fifo->data[fifo->head]; +} + static const uint8_t *fifo8_peekpop_bufptr(Fifo8 *fifo, uint32_t max, uint32_t skip, uint32_t *numptr, bool do_pop) --=20 2.39.2 From nobody Sun Nov 24 06:47:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=ilande.co.uk Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724847990297470.7627437517576; Wed, 28 Aug 2024 05:26:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjHiL-0007n8-VK; Wed, 28 Aug 2024 08:23:53 -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 1sjHiJ-0007iH-9t for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:51 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjHiH-0001Da-CM for qemu-devel@nongnu.org; Wed, 28 Aug 2024 08:23:51 -0400 Received: from [2a02:8012:c93d:0:260e:bf57:a4e9:8142] (helo=cheesecake.fritz.box) by mail.ilande.co.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sjHhz-000B8d-6b; Wed, 28 Aug 2024 13:23:35 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ilande.co.uk; s=20220518; h=Subject:Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=yqZV3N3qjRopbwCand9K9Y8Kskn89ms5iiMIBgf6KxM=; b=P3eK36dYFvJBh/5LIi0wV2Ep/B o67g5AWhbBVTguWJHRela/K1Nw1DcfGTHFmx0GjitWOD/Ej7icfcjApXclrUvDqCc0hoyKWTcXSNS GU9pwl7/EA4i0dMmqUnTeE7+H1zK8V5UHJD1lvqwoXfs3/0cgAqrojE3UAujXgV5EAT5cPo/AHQTE h0hz1FIYBeLQIdKn+0MFi8WMXyL7YDM6WynC+4eIOkmSSlVTv0S04O2264ZbZMPsqfHiIfscKLUJv V6Nog9HitmTApykIm17zj+lG99VwSezFFppyVyOGT9LdYZw3gKOQIaXAvpSqUplC1+bH86W81odml nUhJLYihiDXDRbI45QsjyMzAHqy1jvYLPGcKeik4nzvw18KLXCL5u1qnWQLg528r+AtNBBzQMbjDY x4nnjChi2VihK33AJrMIW7ol7GXs+6g630MnteoP62Q+CuEqWSyj0Fvs2Rhjq15Y72Nkovrj7dJaJ bjFlWTURoEiJ+/XmilKLtjochwg+wI/xn+zZKRsKA4hokd3aQfIBffVGeLne/RQTh1qmYxwpMccTy ukN3nfv2H9wmH7J9qsw8tQ0DlTF4byP5WM/zLnJyCxYHOdd3f3GxlA5MzqTsdgN1Mw3nKX15sAOpe 31ArbmVfyFhFim5oBCkGLIu/AadhXvqHJxwuXdDaQ=; From: Mark Cave-Ayland To: philmd@linaro.org, Alistair.Francis@wdc.com, tavip@google.com, qemu-devel@nongnu.org Date: Wed, 28 Aug 2024 13:22:58 +0100 Message-Id: <20240828122258.928947-10-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> References: <20240828122258.928947-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a02:8012:c93d:0:260e:bf57:a4e9:8142 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH 9/9] tests/unit: add test-fifo unit test X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.ilande.co.uk) 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=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.ilande.co.uk 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, 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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724847991156116600 Content-Type: text/plain; charset="utf-8" This tests the Fifo8 implementation for basic operations as well as testing= for the correct *_bufptr() including handling wraparound of the internal FIFO b= uffer. Signed-off-by: Mark Cave-Ayland Acked-by: Alistair Francis Reviewed-by: Octavian Purdila Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- tests/unit/meson.build | 1 + tests/unit/test-fifo.c | 256 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100644 tests/unit/test-fifo.c diff --git a/tests/unit/meson.build b/tests/unit/meson.build index 490ab8182d..89f9633cd6 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -47,6 +47,7 @@ tests =3D { 'test-logging': [], 'test-qapi-util': [], 'test-interval-tree': [], + 'test-fifo': [], } =20 if have_system or have_tools diff --git a/tests/unit/test-fifo.c b/tests/unit/test-fifo.c new file mode 100644 index 0000000000..1e54cde871 --- /dev/null +++ b/tests/unit/test-fifo.c @@ -0,0 +1,256 @@ +/* + * Fifo8 tests + * + * Copyright 2024 Mark Cave-Ayland + * + * Authors: + * Mark Cave-Ayland + * + * This work is licensed under the terms of the GNU LGPL, version 2 or lat= er. + * See the COPYING.LIB file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "migration/vmstate.h" +#include "qemu/fifo8.h" + +const VMStateInfo vmstate_info_uint32; +const VMStateInfo vmstate_info_buffer; + + +static void test_fifo8_pop_bufptr_wrap(void) +{ + Fifo8 fifo; + uint8_t data_in1[] =3D { 0x1, 0x2, 0x3, 0x4 }; + uint8_t data_in2[] =3D { 0x5, 0x6, 0x7, 0x8, 0x1, 0x2 }; + const uint8_t *buf; + uint32_t count; + + fifo8_create(&fifo, 8); + + fifo8_push_all(&fifo, data_in1, sizeof(data_in1)); + buf =3D fifo8_pop_bufptr(&fifo, 2, &count); + g_assert(count =3D=3D 2); + g_assert(buf[0] =3D=3D 0x1 && buf[1] =3D=3D 0x2); + + fifo8_push_all(&fifo, data_in2, sizeof(data_in2)); + buf =3D fifo8_pop_bufptr(&fifo, 8, &count); + g_assert(count =3D=3D 6); + g_assert(buf[0] =3D=3D 0x3 && buf[1] =3D=3D 0x4 && buf[2] =3D=3D 0x5 && + buf[3] =3D=3D 0x6 && buf[4] =3D=3D 0x7 && buf[5] =3D=3D 0x8); + + g_assert(fifo8_num_used(&fifo) =3D=3D 2); + fifo8_destroy(&fifo); +} + +static void test_fifo8_pop_bufptr(void) +{ + Fifo8 fifo; + uint8_t data_in[] =3D { 0x1, 0x2, 0x3, 0x4 }; + const uint8_t *buf; + uint32_t count; + + fifo8_create(&fifo, 8); + + fifo8_push_all(&fifo, data_in, sizeof(data_in)); + buf =3D fifo8_pop_bufptr(&fifo, 2, &count); + g_assert(count =3D=3D 2); + g_assert(buf[0] =3D=3D 0x1 && buf[1] =3D=3D 0x2); + + g_assert(fifo8_num_used(&fifo) =3D=3D 2); + fifo8_destroy(&fifo); +} + +static void test_fifo8_peek_bufptr_wrap(void) +{ + Fifo8 fifo; + uint8_t data_in1[] =3D { 0x1, 0x2, 0x3, 0x4 }; + uint8_t data_in2[] =3D { 0x5, 0x6, 0x7, 0x8, 0x1, 0x2 }; + const uint8_t *buf; + uint32_t count; + + fifo8_create(&fifo, 8); + + fifo8_push_all(&fifo, data_in1, sizeof(data_in1)); + buf =3D fifo8_peek_bufptr(&fifo, 2, &count); + g_assert(count =3D=3D 2); + g_assert(buf[0] =3D=3D 0x1 && buf[1] =3D=3D 0x2); + + buf =3D fifo8_pop_bufptr(&fifo, 2, &count); + g_assert(count =3D=3D 2); + g_assert(buf[0] =3D=3D 0x1 && buf[1] =3D=3D 0x2); + fifo8_push_all(&fifo, data_in2, sizeof(data_in2)); + + buf =3D fifo8_peek_bufptr(&fifo, 8, &count); + g_assert(count =3D=3D 6); + g_assert(buf[0] =3D=3D 0x3 && buf[1] =3D=3D 0x4 && buf[2] =3D=3D 0x5 && + buf[3] =3D=3D 0x6 && buf[4] =3D=3D 0x7 && buf[5] =3D=3D 0x8); + + g_assert(fifo8_num_used(&fifo) =3D=3D 8); + fifo8_destroy(&fifo); +} + +static void test_fifo8_peek_bufptr(void) +{ + Fifo8 fifo; + uint8_t data_in[] =3D { 0x1, 0x2, 0x3, 0x4 }; + const uint8_t *buf; + uint32_t count; + + fifo8_create(&fifo, 8); + + fifo8_push_all(&fifo, data_in, sizeof(data_in)); + buf =3D fifo8_peek_bufptr(&fifo, 2, &count); + g_assert(count =3D=3D 2); + g_assert(buf[0] =3D=3D 0x1 && buf[1] =3D=3D 0x2); + + g_assert(fifo8_num_used(&fifo) =3D=3D 4); + fifo8_destroy(&fifo); +} + +static void test_fifo8_pop_buf_wrap(void) +{ + Fifo8 fifo; + uint8_t data_in1[] =3D { 0x1, 0x2, 0x3, 0x4 }; + uint8_t data_in2[] =3D { 0x5, 0x6, 0x7, 0x8, 0x1, 0x2, 0x3, 0x4 }; + uint8_t data_out[4]; + int count; + + fifo8_create(&fifo, 8); + + fifo8_push_all(&fifo, data_in1, sizeof(data_in1)); + fifo8_pop_buf(&fifo, NULL, 4); + + fifo8_push_all(&fifo, data_in2, sizeof(data_in2)); + count =3D fifo8_pop_buf(&fifo, NULL, 4); + g_assert(count =3D=3D 4); + count =3D fifo8_pop_buf(&fifo, data_out, 4); + g_assert(count =3D=3D 4); + g_assert(data_out[0] =3D=3D 0x1 && data_out[1] =3D=3D 0x2 && + data_out[2] =3D=3D 0x3 && data_out[3] =3D=3D 0x4); + + g_assert(fifo8_num_used(&fifo) =3D=3D 0); + fifo8_destroy(&fifo); +} + +static void test_fifo8_pop_buf(void) +{ + Fifo8 fifo; + uint8_t data_in[] =3D { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8 }; + uint8_t data_out[] =3D { 0xff, 0xff, 0xff, 0xff }; + int count; + + fifo8_create(&fifo, 8); + + fifo8_push_all(&fifo, data_in, sizeof(data_in)); + count =3D fifo8_pop_buf(&fifo, NULL, 4); + g_assert(count =3D=3D 4); + count =3D fifo8_pop_buf(&fifo, data_out, 4); + g_assert(data_out[0] =3D=3D 0x5 && data_out[1] =3D=3D 0x6 && + data_out[2] =3D=3D 0x7 && data_out[3] =3D=3D 0x8); + + g_assert(fifo8_num_used(&fifo) =3D=3D 0); + fifo8_destroy(&fifo); +} + +static void test_fifo8_peek_buf_wrap(void) +{ + Fifo8 fifo; + uint8_t data_in1[] =3D { 0x1, 0x2, 0x3, 0x4 }; + uint8_t data_in2[] =3D { 0x5, 0x6, 0x7, 0x8, 0x1, 0x2, 0x3, 0x4 }; + uint8_t data_out[4]; + int count; + + fifo8_create(&fifo, 8); + + fifo8_push_all(&fifo, data_in1, sizeof(data_in1)); + fifo8_pop_buf(&fifo, NULL, 4); + + fifo8_push_all(&fifo, data_in2, sizeof(data_in2)); + count =3D fifo8_peek_buf(&fifo, NULL, 4); + g_assert(count =3D=3D 4); + count =3D fifo8_peek_buf(&fifo, data_out, 4); + g_assert(count =3D=3D 4); + g_assert(data_out[0] =3D=3D 0x5 && data_out[1] =3D=3D 0x6 && + data_out[2] =3D=3D 0x7 && data_out[3] =3D=3D 0x8); + + g_assert(fifo8_num_used(&fifo) =3D=3D 8); + fifo8_destroy(&fifo); +} + +static void test_fifo8_peek_buf(void) +{ + Fifo8 fifo; + uint8_t data_in[] =3D { 0x1, 0x2, 0x3, 0x4 }; + uint8_t data_out[] =3D { 0xff, 0xff, 0xff, 0xff }; + int count; + + fifo8_create(&fifo, 8); + + fifo8_push_all(&fifo, data_in, sizeof(data_in)); + count =3D fifo8_peek_buf(&fifo, NULL, 4); + g_assert(count =3D=3D 4); + g_assert(data_out[0] =3D=3D 0xff && data_out[1] =3D=3D 0xff && + data_out[2] =3D=3D 0xff && data_out[3] =3D=3D 0xff); + + count =3D fifo8_peek_buf(&fifo, data_out, 4); + g_assert(count =3D=3D 4); + g_assert(data_out[0] =3D=3D 0x1 && data_out[1] =3D=3D 0x2 && + data_out[2] =3D=3D 0x3 && data_out[3] =3D=3D 0x4); + + g_assert(fifo8_num_used(&fifo) =3D=3D 4); + fifo8_destroy(&fifo); +} + +static void test_fifo8_peek(void) +{ + Fifo8 fifo; + uint8_t c; + + fifo8_create(&fifo, 8); + fifo8_push(&fifo, 0x1); + fifo8_push(&fifo, 0x2); + + c =3D fifo8_peek(&fifo); + g_assert(c =3D=3D 0x1); + fifo8_pop(&fifo); + c =3D fifo8_peek(&fifo); + g_assert(c =3D=3D 0x2); + + g_assert(fifo8_num_used(&fifo) =3D=3D 1); + fifo8_destroy(&fifo); +} + +static void test_fifo8_pushpop(void) +{ + Fifo8 fifo; + uint8_t c; + + fifo8_create(&fifo, 8); + fifo8_push(&fifo, 0x1); + fifo8_push(&fifo, 0x2); + + c =3D fifo8_pop(&fifo); + g_assert(c =3D=3D 0x1); + c =3D fifo8_pop(&fifo); + g_assert(c =3D=3D 0x2); + + g_assert(fifo8_num_used(&fifo) =3D=3D 0); + fifo8_destroy(&fifo); +} + +int main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); + g_test_add_func("/fifo8/pushpop", test_fifo8_pushpop); + g_test_add_func("/fifo8/peek", test_fifo8_peek); + g_test_add_func("/fifo8/peek_buf", test_fifo8_peek_buf); + g_test_add_func("/fifo8/peek_buf_wrap", test_fifo8_peek_buf_wrap); + g_test_add_func("/fifo8/pop_buf", test_fifo8_pop_buf); + g_test_add_func("/fifo8/pop_buf_wrap", test_fifo8_pop_buf_wrap); + g_test_add_func("/fifo8/peek_bufptr", test_fifo8_peek_bufptr); + g_test_add_func("/fifo8/peek_bufptr_wrap", test_fifo8_peek_bufptr_wrap= ); + g_test_add_func("/fifo8/pop_bufptr", test_fifo8_pop_bufptr); + g_test_add_func("/fifo8/pop_bufptr_wrap", test_fifo8_pop_bufptr_wrap); + return g_test_run(); +} --=20 2.39.2