From: Thomas Huth <thuth@redhat.com>
To: Tyler Ng <tkng@rivosinc.com>
Cc: "open list:RISC-V" <qemu-riscv@nongnu.org>,
"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
Alistair Francis <Alistair.Francis@wdc.com>,
Bin Meng <bin.meng@windriver.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Laurent Vivier <lvivier@redhat.com>
Subject: Re: [PATCH v2 1/3] hw/watchdog: wdt_ibex_aon.c: Implement the watchdog for the OpenTitan
Date: Tue, 27 Sep 2022 08:31:17 +0200 [thread overview]
Message-ID: <c2773c56-2710-ae39-5009-a8d11bddb81f@redhat.com> (raw)
In-Reply-To: <CAB88-qO7vw4gC6JNuX=CcnXmYznPdwdhv_nJNrejVzFXSoLQnQ@mail.gmail.com>
Hi Tyler!
On 27/09/2022 01.03, Tyler Ng wrote:
> Hi Thomas,
>
> On Thu, Sep 22, 2022 at 9:17 AM Thomas Huth <thuth@redhat.com
> <mailto:thuth@redhat.com>> wrote:
>
> On 22/09/2022 17.58, Tyler Ng wrote:
> > This commit adds most of an implementation of the OpenTitan Always-On
> > Timer. The documentation for this timer is found here:
> >
> > https://docs.opentitan.org/hw/ip/aon_timer/doc/
> <https://docs.opentitan.org/hw/ip/aon_timer/doc/>
> >
> > Using commit 217a0168ba118503c166a9587819e3811eeb0c0c
> >
> > The implementation includes most of the watchdog features; it does not
> > implement the wakeup timer.
> >
> > An important note: the OpenTitan board uses the sifive_plic. The plic
> > will not be able to claim the bark interrupt (159) because the sifive
> > plic sets priority[159], but checks priority[158] for the priority, so
> > it thinks that the interrupt's priority is 0 (effectively disabled).
> ...
> > diff --git a/tests/qtest/ibex-aon-timer-test.c
> > b/tests/qtest/ibex-aon-timer-test.c
> > new file mode 100644
> > index 0000000000..af33feac39
> > --- /dev/null
> > +++ b/tests/qtest/ibex-aon-timer-test.c
> > @@ -0,0 +1,189 @@
> > +/*
> > + * Testing the OpenTitan AON Timer
> > + *
> > + * Copyright (c) 2022 Rivos Inc.
> > + *
> > + * Permission is hereby granted, free of charge, to any person
> obtaining a copy
> > + * of this software and associated documentation files (the
> > "Software"), to deal
> > + * in the Software without restriction, including without limitation
> the rights
> > + * to use, copy, modify, merge, publish, distribute, sublicense,
> and/or sell
> > + * copies of the Software, and to permit persons to whom the Software is
> > + * furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be
> included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
> SHALL
> > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
> OR OTHER
> > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> > ARISING FROM,
> > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> DEALINGS IN
> > + * THE SOFTWARE.
>
> Could you maybe add a SPDX license identifier at the beginning of the
> comment, so that it's easier to identify the license at a first glance?
> (also in the other new files)
>
> Will do, was actually thinking of switching over to GPL-2.0-or-later as
> opposed to MIT.
Yes, that would be the best fit for QEMU, I think.
> > + */
> > +
> > +#include "qemu/osdep.h"
> > +#include "libqtest.h"
> > +#include "qapi/qmp/qdict.h"
> > +
> > +#define AON_BASE_ADDR (0x40470000ul)
> > +#define AON_ADDR(addr) (AON_BASE_ADDR + addr)
> > +#define AON_WKUP_IRQ 158
> > +#define AON_BARK_IRQ 159
> > +#define AON_FREQ 200000 /* 200 KHz */
> > +#define AON_PERIOD_NS 5000
> > +#define NANOS_PER_SECOND 1000000000LL
> > +/* Test that reads work, and that the regs get reset to the correct
> value */
> > +static void test_reads(void)
> > +{
> > + QTestState *test = qtest_init("-M opentitan");
> > + g_assert(qtest_readl(test, AON_ADDR(0x00)) == 0);
> > + g_assert(qtest_readl(test, AON_ADDR(0x04)) == 0);
> > + g_assert(qtest_readl(test, AON_ADDR(0x08)) == 0);
> > + g_assert(qtest_readl(test, AON_ADDR(0x0c)) == 0);
> > + g_assert(qtest_readl(test, AON_ADDR(0x10)) == 1); > +
> g_assert(qtest_readl(test, AON_ADDR(0x14)) == 0);
> > + g_assert(qtest_readl(test, AON_ADDR(0x18)) == 0);
> > + g_assert(qtest_readl(test, AON_ADDR(0x1c)) == 0);
> > + g_assert(qtest_readl(test, AON_ADDR(0x20)) == 0);
> > + g_assert(qtest_readl(test, AON_ADDR(0x24)) == 0);
> > + g_assert(qtest_readl(test, AON_ADDR(0x28)) == 0);
> > + g_assert(qtest_readl(test, AON_ADDR(0x2c)) == 0);
>
> The read tests that check for 0 could maybe be simplified with a for-loop
> (or two).
>
> I'm not entirely sure about what benefit this would bring after writing it out.
Mostly a matter of taste. Keep it in the current shape if you prefer that.
> > + qtest_quit(test);
> > +}
> > +
> > +static void test_writes(void)
> > +{
> > + /* Test that writes worked, while the config is unlocked */
> > + QTestState *test = qtest_init("-M opentitan");
> > +
> > +
> > + qtest_writel(test, AON_ADDR(0x18), (1 << 19)); /* WDOG_BARK_THOLD */
> > + g_assert_cmpuint(qtest_readl(test, AON_ADDR(0x18)),
> > + ==, (1 << 19));
> > +
> > + qtest_writel(test, AON_ADDR(0x1c), (1 << 20)); /* WDOG_BITE_THOLD */
> > + g_assert_cmpuint(qtest_readl(test, AON_ADDR(0x1c)),
> > + ==, (1 << 20));
> > +
> > + qtest_writel(test, AON_ADDR(0x14), 0x1); /* WDOG_CTRL enable */
> > + g_assert_cmpuint(qtest_readl(test, AON_ADDR(0x14)),
> > + ==, 0x1);
> > +
> > + qtest_writel(test, AON_ADDR(0x10), 0x0); /* WDOG_REGWEN enable */
> > + g_assert_cmpuint(qtest_readl(test, AON_ADDR(0x10)), ==, 0x0);
>
> I think the above code would be better readable if you'd provide a helper
> function like this:
>
> static void writel_and_assert(QTestState qts, int addr, int val)
> {
> qtest_writel(qts, AON_ADDR(addr), val);
> g_assert_cmpuint(qtest_readl(qts, AON_ADDR(addr)), val);
> }
>
> Thanks for the suggestion. I decided to go with a macro instead though,
> because it makes it easier to distinguish where an assertion failed without
> a debugger.
That's a good idea, indeed!
Thomas
next prev parent reply other threads:[~2022-09-27 7:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-22 15:58 [PATCH v2 1/3] hw/watchdog: wdt_ibex_aon.c: Implement the watchdog for the OpenTitan Tyler Ng
2022-09-22 16:17 ` Thomas Huth
2022-09-26 23:03 ` Tyler Ng
2022-09-27 6:31 ` Thomas Huth [this message]
2022-09-26 20:46 ` Dong, Eddie
2022-09-26 23:24 ` Tyler Ng
2022-09-27 22:04 ` Dong, Eddie
2022-09-28 0:13 ` Tyler Ng
2022-09-28 18:25 ` Dong, Eddie
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=c2773c56-2710-ae39-5009-a8d11bddb81f@redhat.com \
--to=thuth@redhat.com \
--cc=Alistair.Francis@wdc.com \
--cc=bin.meng@windriver.com \
--cc=lvivier@redhat.com \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=tkng@rivosinc.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).