All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yao Zi <me@ziyao.cc>
To: Nikita Shubin <nikita.shubin@maquefel.me>, Yao Zi <me@ziyao.cc>,
	u-boot@lists.u-boot-project.org
Cc: Tom Rini <trini@konsulko.com>, Michal Simek <michal.simek@amd.com>
Subject: Re: [PATCH v4 2/2] riscv: timer: Enable early timer for M‑mode
Date: Fri, 11 Sep 2026 09:03:12 +0000	[thread overview]
Message-ID: <aqPD0KD-u7N425Ew@pie> (raw)
In-Reply-To: <62f45089b4898f390432fb189b3192c6e0a319de.camel@maquefel.me>

On Fri, Sep 11, 2026 at 11:36:35AM +0300, Nikita Shubin wrote:
> On Fri, 2026-09-11 at 08:27 +0000, Yao Zi wrote:
> > On Fri, Sep 11, 2026 at 10:14:06AM +0300, Nikita Shubin wrote:
> > > The generic RISC-V timer driver currently defines
> > > timer_early_get_count() only when CONFIG_IS_ENABLED(RISCV_SMODE),
> > > even though reading the TIME CSR is not inherently limited
> > > to S‑mode; it works in M‑mode as well when the CSR is implemented
> > > in hardware (e.g., with the Zicntr extension).
> > > 
> > > Moreover, timer_early_get_rate() is missing entirely for M‑mode,
> > > causing early timer functions to be unavailable on such systems.
> > > 
> > > Fix this by:
> > > - Moving timer_early_get_count() out of the RISCV_SMODE guard
> > >   so it is always available when CONFIG_TIMER_EARLY is set.
> > > - Adding M‑mode support to timer_early_get_rate(), returning
> > >   RISCV_MMODE_TIMER_FREQ when running in M‑mode
> > >   and RISCV_SMODE_TIMER_FREQ in S‑mode.
> > > 
> > > This is also necessary because several functions
> > > (e.g., net_random_ethaddr() via get_ticks()) rely on
> > > timer_early_get_count() even if CONFIG_TIMER_EARLY is not
> > > enabled.
> > 
> > Is this description correct? net_random_ethaddr() does invoke
> > get_ticks(), but the latter only delegates the work to
> > timer_early_get_count() when CONFIG_TIMER_EARLY is enabled and gd-
> > >timer
> > hasn't been initialized,
> > 
> > 	uint64_t notrace get_ticks(void)
> > 	{
> > 		u64 count;
> > 		int ret;
> > 
> > 		if (!gd->timer) {
> > 			int ret;
> > 
> > 			if (IS_ENABLED(CONFIG_TIMER_EARLY))
> > 				return timer_early_get_count();
> > 	...
> > 
> > 
> > > Signed-off-by: Nikita Shubin <nikita.shubin@maquefel.me>
> 
> Totally correct as this i how i came into fixing the RISCV TIMER, as 
> if (IS_ENABLED(CONFIG_TIMER_EARLY)) doesn't protect us from linking
> error if timer_early_get_count() is missing (unless i am missing
> something).

With optimization, this branch should be turned into dead code and
the reference is thus eliminated. But anyway, please improve the
description to mention it's only a possible linking time dependency. I'm
simply confused by "rely on" since this should be dead code without
CONFIG_TIMER_EARLY :)

> It could be simply avoided by turning on any kind of ACLINT/CLINT
> MTIMER (everybody has one of some sort) - but why i need it if i can
> rely on RISCV TIMER in SPL stage ?
> 
> It seems no RISC-V board is currently using BOOTP/TFTP boot in SPL.
> 
> > 
> > Otherwise this patch looks good to me.
> > 
> > Best regards,
> > Yao Zi

Best regards,
Yao Zi

  reply	other threads:[~2026-09-11  9:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11  7:14 [PATCH v4 0/2] riscv: timer: Fix M-mode early timer support Nikita Shubin
2026-09-11  7:14 ` [PATCH v4 1/2] riscv: timer: Make RISCV_TIMER definitions weak Nikita Shubin
2026-09-11  7:14 ` [PATCH v4 2/2] riscv: timer: Enable early timer for M‑mode Nikita Shubin
2026-09-11  8:27   ` Yao Zi
2026-09-11  8:36     ` Nikita Shubin
2026-09-11  9:03       ` Yao Zi [this message]
2026-09-11  9:15         ` Nikita Shubin

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=aqPD0KD-u7N425Ew@pie \
    --to=me@ziyao.cc \
    --cc=michal.simek@amd.com \
    --cc=nikita.shubin@maquefel.me \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.