All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yao Zi <me@ziyao.cc>
To: Han Gao <gaohan@iscas.ac.cn>, Yao Zi <me@ziyao.cc>,
	u-boot@lists.u-boot-project.org
Cc: Tim Ouyang <tim609@andestech.com>,
	Leo Liang <leo.liang@sifive.com>, Tom Rini <trini@konsulko.com>,
	Han Gao <rabenda.cn@gmail.com>
Subject: Re: [PATCH] riscv: thead: fix D-cache flushing
Date: Sun, 20 Sep 2026 10:21:59 +0000	[thread overview]
Message-ID: <aq-zx89k_eDPm1X3@pie> (raw)
In-Reply-To: <20260919-fixcmo-v1-1-0a9db1d0fa61@iscas.ac.cn>

On Sat, Sep 19, 2026 at 04:29:41AM +0800, Han Gao wrote:
> Use CIPA instead of CPA to clean and invalidate cache lines. This
> fixes stale DMA descriptors breaking USB enumeration on TH1520.

I guess this issue isn't present in mainline U-Boot yet, since we don't
have USB support for TH1520 currently? If so, please omit this part in
commit message, you could mention this below the --- line.

And it would be good to mention the meaning and full form
("th.dcache.*") of CPA/CIPA here, and attach a link to the documentation
of T-Head's extensions. As a fix, this also deserves a Fixes tag.

For the fix itself, it sounds correct. I had a brief look over several
architectures' flush_dcache_range(),

- The zicbom path on RISC-V makes use of cbo.flush, per the RISC-V
  specification (Volume I, 19.6.1 Cache-Block Management Instructions),
  a flush operation atomically performs a clean operation followed by an
  invalidate operation.
- MIPS uses HIT_WRITEBACK_INV_D & HIT_WRITEBACK_INV_SD
- PowerPC implements flush_dcache_range() with dcbf, which is described
  as "those locations are written to main storage and additional
  locations in the block may be written to main storage. The block is
  invalidated in the data caches of all/this (depending on memory
  coherence) processors", matching the behavior of flush
  (clean/writeback & invalidate).
  - flush_dcache_range() is no-op on platforms other than
    MPC85xx/MPC86xx, I guess coherency is guaranteed otherwise?
- ARMv8's flush_dcache_range() is also commented as "INvalidates range
  in all levels of D-cache/unified cache"

So this fix aligns thead_cmo.c's behavior with other implementations.
With the commit message improved,

Reviewed-by: Yao Zi <me@ziyao.cc>

> Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
> ---
>  arch/riscv/lib/thead_cmo.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/lib/thead_cmo.c b/arch/riscv/lib/thead_cmo.c
> index b8051e29e02b..763ff799eddd 100644
> --- a/arch/riscv/lib/thead_cmo.c
> +++ b/arch/riscv/lib/thead_cmo.c
> @@ -40,6 +40,6 @@ void flush_dcache_range(unsigned long start, unsigned long end)
>  {
>  	register unsigned long i asm("a0") = start & ~(CONFIG_SYS_CACHELINE_SIZE - 1);
>  	for (; i < end; i += CONFIG_SYS_CACHELINE_SIZE)
> -		__asm__ __volatile__(DCACHE_CPA_A0);
> +		__asm__ __volatile__(DCACHE_CIPA_A0);
>  	__asm__ __volatile__(SYNC_S);
>  }

Regards,
Yao Zi

      parent reply	other threads:[~2026-09-20 10:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 20:29 [PATCH] riscv: thead: fix D-cache flushing Han Gao
2026-09-20  0:56 ` Yixun Lan
2026-09-20 10:38   ` Yao Zi
2026-09-20 10:21 ` Yao Zi [this message]

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=aq-zx89k_eDPm1X3@pie \
    --to=me@ziyao.cc \
    --cc=gaohan@iscas.ac.cn \
    --cc=leo.liang@sifive.com \
    --cc=rabenda.cn@gmail.com \
    --cc=tim609@andestech.com \
    --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.