From: Octavian Purdila <tavip@google.com>
To: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, stefanst@google.com,
pbonzini@redhat.com, peter.maydell@linaro.org,
marcandre.lureau@redhat.com, berrange@redhat.com,
eduardo@habkost.net, luc@lmichel.fr, damien.hedde@dahe.fr,
alistair@alistair23.me, thuth@redhat.com, philmd@linaro.org,
jsnow@redhat.com, crosa@redhat.com, lvivier@redhat.com
Subject: Re: [PATCH v2 01/25] fifo32: add peek function
Date: Tue, 8 Oct 2024 10:25:29 -0700 [thread overview]
Message-ID: <CAGWr4cT=UWvk_v=908bhdbrg61tz8pgpa14_K+vps0d0sTZTJQ@mail.gmail.com> (raw)
In-Reply-To: <7994769f-efed-4eff-aac7-aa3828f603b7@ilande.co.uk>
On Tue, Oct 8, 2024 at 4:27 AM Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
>
> On 08/10/2024 02:18, Octavian Purdila wrote:
>
> > Add fifo32_peek() that returns the first element from the queue
> > without popping it.
> >
> > Signed-off-by: Octavian Purdila <tavip@google.com>
> > ---
> > include/qemu/fifo32.h | 28 ++++++++++++++++++++++++++++
> > 1 file changed, 28 insertions(+)
> >
> > diff --git a/include/qemu/fifo32.h b/include/qemu/fifo32.h
> > index 4e9fd1b5ef..9de1807375 100644
> > --- a/include/qemu/fifo32.h
> > +++ b/include/qemu/fifo32.h
> > @@ -140,6 +140,34 @@ static inline uint32_t fifo32_pop(Fifo32 *fifo)
> > return ret;
> > }
> >
> > +/**
> > + * fifo32_peek:
> > + * @fifo: fifo to peek at
> > + *
> > + * Returns the value from the FIFO's head without poping it. Behaviour
> > + * is undefined if the FIFO is empty. Clients are responsible for
> > + * checking for emptiness using fifo32_is_empty().
> > + *
> > + * Returns: the value from the FIFO's head
> > + */
> > +
> > +static inline uint32_t fifo32_peek(Fifo32 *fifo)
> > +{
> > + uint32_t ret = 0, num;
> > + const uint8_t *buf;
> > +
> > + buf = fifo8_peek_bufptr(&fifo->fifo, 4, &num);
>
> Are you sure that you want to use fifo8_peek_bufptr() as opposed to fifo8_peek_buf()
> here? The reason for using the latter function (and why fifo8_*_bufptr() functions
> are not generally recommended) is that they will correctly handle the FIFO wraparound
> caused by the drifting head pointer which can occur if you don't empty the entire
> FIFO contents in a single *_pop() or *_pop_buf() operation.
>
I don't think that it matters in this case because the size of the
FIFO is always going to be a multiple of 4 and all push and pop
operations happen with 4 bytes as well. Am I missing something?
In any case, if it makes things more clear / consistent I can switch
to fifo8_peek_buf.
> > + if (num != 4) {
> > + return ret;
> > + }
> > +
> > + for (int i = 0; i < sizeof(uint32_t); i++) {
> > + ret |= buf[i] << (i * 8);
> > + }
> > +
> > + return ret;
> > +}
> > +
> > /**
> > * There is no fifo32_pop_buf() because the data is not stored in the buffer
> > * as a set of native-order words.
>
>
> ATB,
>
> Mark.
>
next prev parent reply other threads:[~2024-10-08 17:26 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-08 1:18 [PATCH v2 00/25] NXP i.MX RT595 Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 01/25] fifo32: add peek function Octavian Purdila
2024-10-08 11:27 ` Mark Cave-Ayland
2024-10-08 17:25 ` Octavian Purdila [this message]
2024-10-09 8:41 ` Mark Cave-Ayland
2024-10-08 1:18 ` [PATCH v2 02/25] tests/unit: add fifo32 tests Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 03/25] scripts: add script to generate C header files from SVD XML files Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 04/25] Add mcux-soc-svd subproject Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 05/25] hw/misc: add support for flexcomm Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 06/25] hw/misc/flexcomm.c: add common fifo functionality Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 07/25] hw/char: add support for flexcomm usart Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 08/25] hw/i2c: add support for flexcomm i2c Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 09/25] hw/ssi: add support for flexcomm spi Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 10/25] hw/misc: add support for RT500's clock controller Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 11/25] hw/ssi: add support for flexspi Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 12/25] hw/misc: add support for RT500's reset controller Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 13/25] hw/arm: add basic support for the RT500 SoC Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 14/25] hw/arm: add RT595-EVK board Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 15/25] tests/qtest: add register access macros and functions Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 16/25] system/qtest: add APIS to check for memory access failures Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 17/25] tests/qtest: add flexcomm tests Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 18/25] tests/qtest: add flexcomm usart tests Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 19/25] hw/misc: add i2c-tester Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 20/25] tests/qtest: add tests for flexcomm i2c Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 21/25] hw/ssi: allow NULL realize callbacks for peripherals Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 22/25] hw/misc: add spi-tester Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 23/25] tests/qtest: add tests for flexcomm spi Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 24/25] systems/qtest: add device clock APIs Octavian Purdila
2024-10-08 1:18 ` [PATCH v2 25/25] tests/qtest: add tests for RT500's clock controller Octavian Purdila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAGWr4cT=UWvk_v=908bhdbrg61tz8pgpa14_K+vps0d0sTZTJQ@mail.gmail.com' \
--to=tavip@google.com \
--cc=alistair@alistair23.me \
--cc=berrange@redhat.com \
--cc=crosa@redhat.com \
--cc=damien.hedde@dahe.fr \
--cc=eduardo@habkost.net \
--cc=jsnow@redhat.com \
--cc=luc@lmichel.fr \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanst@google.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).