U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Junhui Liu" <junhui.liu@pigmoral.tech>
To: "Indrek Kruusa" <indrek.kruusa@gmail.com>,
	"Tim Ouyang" <tim609@andestech.com>,
	"Leo Liang" <leo.liang@sifive.com>
Cc: "Yao Zi" <me@ziyao.cc>, "Tom Rini" <trini@konsulko.com>,
	"Han Gao" <gaohan@iscas.ac.cn>,
	"Kongyang Liu" <seashell11234455@gmail.com>,
	"Junhui Liu" <junhui.liu@pigmoral.tech>,
	"Samuel Holland" <samuel@sholland.org>,
	"Andre Przywara" <andre.przywara@arm.com>,
	"Hiago De Franco" <hfranco@baylibre.com>,
	"E Shattow" <e@freeshell.de>, "Yixun Lan" <dlan@kernel.org>,
	"Raymond Mao" <raymond.mao@riscstar.com>,
	<u-boot@lists.u-boot-project.org>
Subject: Re: [PATCH 1/4] riscv: thead: add a common header for the C9xx CSRs
Date: Wed, 25 Nov 2026 23:00:41 +0800	[thread overview]
Message-ID: <DN4DR7Y17SY4.2ZHAVQDW8UMV1@pigmoral.tech> (raw)
In-Reply-To: <20261124195237.692679-2-indrek.kruusa@gmail.com>

Hi Indrek,

Thanks for doing these!

On Wed Nov 25, 2026 at 3:52 AM CST, Indrek Kruusa wrote:
> Add a header with the register numbers and bitfields currently used by the
> C9xx ports. It is placed in asm/ so that both SPL and U-Boot proper can
> include it. M-mode only.
>
> Signed-off-by: Indrek Kruusa <indrek.kruusa@gmail.com>
> ---
>  arch/riscv/include/asm/thead_csr.h | 105 +++++++++++++++++++++++++++++
>  1 file changed, 105 insertions(+)
>  create mode 100644 arch/riscv/include/asm/thead_csr.h
>
> diff --git a/arch/riscv/include/asm/thead_csr.h b/arch/riscv/include/asm/thead_csr.h
> new file mode 100644
> index 00000000000..32d3bf773ee
> --- /dev/null
> +++ b/arch/riscv/include/asm/thead_csr.h
> @@ -0,0 +1,105 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Copyright (C) 2025 Yao Zi <ziyao@disroot.org>
> + * Copyright (C) 2026, Indrek Kruusa <indrek.kruusa@gmail.com>
> + *
> + * T-Head C9xx machine-mode control registers.
> + *
> + * Register numbers are shared, but the fields defined here are only those used
> + * by the in-tree ports. Availability and layout may differ between cores. Any
> + * known differences that could cause incorrect configuration are noted at the
> + * corresponding definitions.
> + */
> +
> +#ifndef _ASM_RISCV_THEAD_CSR_H
> +#define _ASM_RISCV_THEAD_CSR_H
> +
> +#include <linux/bitops.h>
> +
> +/* M-mode control registers */
> +#define CSR_MXSTATUS		0x7c0
> +#define CSR_MHCR		0x7c1
> +#define CSR_MCOR		0x7c2
> +#define CSR_MHINT		0x7c5
> +
> +/* not decoded by every core */
> +#define CSR_MCCR2		0x7c3
> +#define CSR_MHINT2		0x7cc
> +#define CSR_MHINT4		0x7ce
> +#define CSR_MSMPR		0x7f3
> +
> +/* MXSTATUS - machine-mode status */
> +#define MXSTATUS_THEADISAEE	BIT(22)	/* T-HEAD ISA extensions enable */
> +#define MXSTATUS_MAEE		BIT(21)	/* MMU honours the PTE memory type */
> +#define MXSTATUS_CLINTEE	BIT(17)	/* CLINT extension enable */
> +#define MXSTATUS_UCME		BIT(16)	/* user-mode cache ops enable */
> +#define MXSTATUS_MM		BIT(15)	/* misaligned access enable */

Could you keep Ziyao's original style, with the bit definitions grouped
under each CSR definition? That makes it easier to see which register
each bit belongs to.

Could you also keep the existing names, e.g. CSR_MXSTATUS_THEADISAEE?
Then patches 1 and 2 could be combined into a straightforward move of
the definitions into the common header, without renaming their uses
in arch/riscv/cpu/th1520/spl.c. Any new definitions could be added in a
separate patch, or later in the D1 series when needed. This keeps the
code move separate from other changes and makes it easier to review.

> +
> +/*
> + * MHCR - machine-mode hardware configuration
> + *
> + * WB and WBR are read-only and always read back as 1.
> + */
> +#define MHCR_IE			BIT(0)	/* I-cache enable */
> +#define MHCR_DE			BIT(1)	/* D-cache enable */
> +#define MHCR_WA			BIT(2)	/* D-cache write allocate */
> +#define MHCR_WB			BIT(3)	/* D-cache write back */
> +#define MHCR_RS			BIT(4)	/* return stack enable */
> +#define MHCR_BPE		BIT(5)	/* branch prediction enable */
> +#define MHCR_BTB		BIT(6)	/* branch target buffer enable */
> +#define MHCR_WBR		BIT(8)	/* write-back read allocate */
> +
> +/*
> + * MCOR - machine-mode cache operation
> + *
> + * The address is common but the encoding is not: the C906 decodes a single
> + * INV and CLR bit qualified by a cache select field, the C910 four separate
> + * invalidate bits.  The layout below is the C910's; a core whose manual
> + * documents the C906 form must not reuse these bits.
> + */
> +#define MCOR_CACHE_SEL(n)	((n) << 0)	/* 1: I-cache, 2: D-cache, 3: both */
> +#define MCOR_INV		BIT(4)		/* invalidate the selected caches */
> +#define MCOR_BHT_INV		BIT(16)		/* branch history table */
> +#define MCOR_BTB_INV		BIT(17)		/* branch target buffer */
> +#define MCOR_IBP_INV		BIT(18)		/* indirect branch predictor */
> +
> +/* MCCR2 - machine-mode L2 cache configuration */
> +#define MCCR2_RFE		BIT(0)		/* read allocate enable */
> +#define MCCR2_L2EN		BIT(3)		/* L2 cache enable */
> +#define MCCR2_DLNTCY(n)		((n) << 16)	/* data RAM latency */
> +#define MCCR2_DSETUP		BIT(19)		/* data RAM setup time */
> +#define MCCR2_TLNTCY(n)		((n) << 22)	/* tag RAM latency */
> +#define MCCR2_TSETUP		BIT(25)		/* tag RAM setup time */
> +#define MCCR2_IPRF(n)		((n) << 29)	/* instruction prefetch lines */
> +#define MCCR2_TPRF		BIT(31)		/* tag RAM prefetch enable */
> +
> +/*
> + * MHINT - machine-mode implicit operation
> + *
> + * AMR selects how many consecutive stores to the same 4 KiB region make the
> + * core stop allocating cache lines for the rest of it.  It is a two-bit field
> + * on the C906 but the C910 only decodes bit 3.
> + *
> + * Some of the fields the C906 does not have also mean something else there:
> + * bit 20 is L2STPLD on the C910 and AEE on the C906, so it is left undefined
> + * until one of them needs it.
> + */
> +#define MHINT_DPLD		BIT(2)		/* D-cache prefetch enable */
> +#define MHINT_AMR(n)		((n) << 3)	/* write-allocate adjustment */
> +#define MHINT_IPLD		BIT(8)		/* I-cache prefetch enable */
> +#define MHINT_LPE		BIT(9)		/* loop prefetch enable */
> +#define MHINT_DCACHE_PREF_DIST(n)	((n) << 13)	/* in 64 B lines */
> +/* not decoded by every core */
> +#define MHINT_L2PLD		BIT(15)		/* L2 prefetch enable */
> +#define MHINT_L2_PREF_DIST(n)	((n) << 16)	/* in 64 B lines */
> +#define MHINT_NSFE		BIT(18)
> +#define MHINT_TLB_BROAD_DIS	BIT(21)		/* keep TLB ops hart-local */
> +#define MHINT_FENCERW_BROAD_DIS	BIT(22)	/* keep fence rw hart-local */
> +
> +/* MHINT2 - per-unit clock gating */
> +#define MHINT2_LOCAL_ICG_EN(n)	BIT((n) + 14)
> +
> +/* MSMPR - machine-mode SMP control */
> +#define MSMPR_SMPEN		BIT(0)		/* cache snooping enable */

I think most of the comments in this file can be dropped. The CSR and
bit names are generally clear enough, and the details are available in
the XuanTie manuals. Brief notes about differences between cores should
be enough.

> +
> +#endif /* _ASM_RISCV_THEAD_CSR_H */

-- 
Best regards,
Junhui Liu


  reply	other threads:[~2026-11-25 15:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 19:52 [PATCH 0/4] riscv: consolidate the T-Head C9xx cache operations and CSRs Indrek Kruusa
2026-11-24 19:52 ` [PATCH 1/4] riscv: thead: add a common header for the C9xx CSRs Indrek Kruusa
2026-11-25 15:00   ` Junhui Liu [this message]
2026-11-24 19:52 ` [PATCH 2/4] riscv: th1520: use the common C9xx CSR definitions Indrek Kruusa
2026-11-24 19:52 ` [PATCH 3/4] riscv: lib: rename thead_cmo.c to thead_cache.c Indrek Kruusa
2026-11-24 19:52 ` [PATCH 4/4] riscv: lib: add the whole-cache and enable operations Indrek Kruusa
2026-11-25 17:23 ` [PATCH 0/4] riscv: consolidate the T-Head C9xx cache operations and CSRs Yao Zi

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=DN4DR7Y17SY4.2ZHAVQDW8UMV1@pigmoral.tech \
    --to=junhui.liu@pigmoral.tech \
    --cc=andre.przywara@arm.com \
    --cc=dlan@kernel.org \
    --cc=e@freeshell.de \
    --cc=gaohan@iscas.ac.cn \
    --cc=hfranco@baylibre.com \
    --cc=indrek.kruusa@gmail.com \
    --cc=leo.liang@sifive.com \
    --cc=me@ziyao.cc \
    --cc=raymond.mao@riscstar.com \
    --cc=samuel@sholland.org \
    --cc=seashell11234455@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox