qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Havard Skinnemoen <hskinnemoen@google.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Hao Wu" <wuhaotsh@google.com>,
	"CS20 KFTing" <kfting@nuvoton.com>,
	qemu-arm <qemu-arm@nongnu.org>, "Cédric Le Goater" <clg@kaod.org>,
	"IS20 Avi Fishman" <Avi.Fishman@nuvoton.com>
Subject: Re: [PATCH 3/6] hw/timer: Adding watchdog for NPCM7XX Timer.
Date: Tue, 20 Oct 2020 13:55:17 +0100	[thread overview]
Message-ID: <CAFEAcA9gkSbQsP_sUJfXEdUQYrqGsq6SAb_0O8qWEV2iSRi1Mg@mail.gmail.com> (raw)
In-Reply-To: <20201008232154.94221-4-hskinnemoen@google.com>

On Fri, 9 Oct 2020 at 00:22, Havard Skinnemoen <hskinnemoen@google.com> wrote:
>
> From: Hao Wu <wuhaotsh@google.com>
>
> The watchdog is part of NPCM7XX's timer module. Its behavior is
> controlled by the WTCR register in the timer.
>
> When enabled, the watchdog issues an interrupt signal after a pre-set
> amount of cycles, and issues a reset signal shortly after that.
>
> Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
> Signed-off-by: Hao Wu <wuhaotsh@google.com>
> Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
> ---
>  include/hw/misc/npcm7xx_clk.h             |   9 +
>  include/hw/timer/npcm7xx_timer.h          |  43 ++-
>  hw/arm/npcm7xx.c                          |  11 +
>  hw/misc/npcm7xx_clk.c                     |  20 ++
>  hw/timer/npcm7xx_timer.c                  | 275 +++++++++++++++----
>  tests/qtest/npcm7xx_watchdog_timer-test.c | 313 ++++++++++++++++++++++
>  MAINTAINERS                               |   1 +
>  tests/qtest/meson.build                   |   1 +
>  8 files changed, 620 insertions(+), 53 deletions(-)
>  create mode 100644 tests/qtest/npcm7xx_watchdog_timer-test.c
>
> diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h
> index cdcc9e8534..483028cf63 100644
> --- a/include/hw/misc/npcm7xx_clk.h
> +++ b/include/hw/misc/npcm7xx_clk.h
> @@ -42,6 +42,15 @@ typedef struct NPCM7xxCLKState {
>      int64_t ref_ns;
>  } NPCM7xxCLKState;
>
> +/**
> + * npcm7xx_clk_perform_watchdog_reset - Perform watchdog reset action generated
> + * by a watchdog event.
> + * @clk: The clock module that connects to the watchdog.
> + * @watchdog_index: The index of the watchdog that triggered the reset action.
> + */
> +void npcm7xx_clk_perform_watchdog_reset(NPCM7xxCLKState *clk,
> +        int watchdog_index);

It looks like you're using this as a mechanism for having the
watchdog module signal to the clock module that it needs to
do a reset. The usual way I'd implement a cross-device
link like that would be to use a qemu_irq for it -- the
receiving end creates a named GPIO input, the sending end
has a named GPIO output, and the SoC that creates both devices
also wires the GPIO link from one to the other. (You can
send an arbitrary integer down a qemu_irq, not just an
on/off, so you could do this either with an array of N
GPIOs, one per watchdog, or with just one that you send
an index value down.)

I have a handful of nits below but other than the above issue
this patch looks good.

> +static void npcm7xx_watchdog_timer_reset_cycles(NPCM7xxWatchdogTimer *t,
> +        int64_t cycles)
> +{
> +    uint32_t prescaler = npcm7xx_watchdog_timer_prescaler(t);
> +    int64_t ns = (NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ) * cycles;
> +
> +    /*
> +     * The reset function always clear the current timer. The caller to the
> +     * this needs to decide whether to start the watchdog timer based on

"always clears". "The caller of this".

> +     * specific flag in WTCR.
> +     */
> +    npcm7xx_timer_clear(&t->base_timer);
> +
> +    ns *= prescaler;
> +    t->base_timer.remaining_ns = ns;
> +}
> @@ -259,9 +333,47 @@ static void npcm7xx_timer_write_tisr(NPCM7xxTimerCtrlState *s, uint32_t value)
>          if (value & (1U << i)) {
>              npcm7xx_timer_check_interrupt(&s->timer[i]);
>          }
> +

Stray extra blank line?

>      }
>  }
>

> +    /*
> +     * Set WTCLK to 1(default) and resets all flags except WTRF.
> +     * WTRF is not reset during a core domain reset.
> +     */

"and reset all flags" (or "Sets", if you prefer)

+    s->watchdog_timer.wtcr = 0x00000400 | (s->watchdog_timer.wtcr &
> +            NPCM7XX_WTCR_WTRF);
> +}
> +
> +static void npcm7xx_watchdog_timer_expired(void *opaque)
> +{
> +    NPCM7xxWatchdogTimer *t = opaque;
> +
> +    if (t->wtcr & NPCM7XX_WTCR_WTE) {
> +        if (t->wtcr & NPCM7XX_WTCR_WTIF) {
> +            if (t->wtcr & NPCM7XX_WTCR_WTRE) {
> +                t->wtcr |= NPCM7XX_WTCR_WTRF;
> +                /* send reset signal to CLK module*/
> +                npcm7xx_clk_perform_watchdog_reset(t->ctrl->clk,
> +                        t->ctrl->index);
> +            }
> +        } else {
> +            t->wtcr |= NPCM7XX_WTCR_WTIF;
> +            if (t->wtcr & NPCM7XX_WTCR_WTIE)
> +                /* send interrupt */
> +                qemu_irq_raise(t->irq);

This if() is missing its mandatory braces. (Not sure why
checkpatch doesn't catch this.)

> +            npcm7xx_watchdog_timer_reset_cycles(t,
> +                    NPCM7XX_WATCHDOG_INTERRUPT_TO_RESET_CYCLES);
> +            npcm7xx_timer_start(&t->base_timer);
> +        }
> +    }
>  }

thanks
-- PMM


  reply	other threads:[~2020-10-20 12:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08 23:21 [PATCH 0/6] Additional NPCM7xx features, devices and tests Havard Skinnemoen via
2020-10-08 23:21 ` [PATCH 1/6] tests/qtest: Add npcm7xx timer test Havard Skinnemoen via
2020-10-08 23:21 ` [PATCH 2/6] Move npcm7xx_timer_reached_zero call out of npcm7xx_timer_pause Havard Skinnemoen via
2020-10-19 16:00   ` Philippe Mathieu-Daudé
2020-10-08 23:21 ` [PATCH 3/6] hw/timer: Adding watchdog for NPCM7XX Timer Havard Skinnemoen via
2020-10-20 12:55   ` Peter Maydell [this message]
2020-10-08 23:21 ` [PATCH 4/6] hw/misc: Add npcm7xx random number generator Havard Skinnemoen via
2020-10-20 13:02   ` Peter Maydell
2020-10-20 23:40     ` Havard Skinnemoen
2020-10-08 23:21 ` [PATCH 5/6] hw/arm/npcm7xx: Add EHCI and OHCI controllers Havard Skinnemoen via
2020-10-13  7:05   ` Gerd Hoffmann
2020-10-08 23:21 ` [PATCH 6/6] hw/gpio: Add GPIO model for Nuvoton NPCM7xx Havard Skinnemoen via
2020-10-20 13:07   ` Peter Maydell
2020-10-20 13:12 ` [PATCH 0/6] Additional NPCM7xx features, devices and tests Peter Maydell

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=CAFEAcA9gkSbQsP_sUJfXEdUQYrqGsq6SAb_0O8qWEV2iSRi1Mg@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=Avi.Fishman@nuvoton.com \
    --cc=clg@kaod.org \
    --cc=f4bug@amsat.org \
    --cc=hskinnemoen@google.com \
    --cc=kfting@nuvoton.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=wuhaotsh@google.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).