[PATCH 3/4] platform: generic: nuclei: Add cache and PMA CSRs definitions

Junhui Liu junhui.liu at pigmoral.tech
Thu Dec 3 06:52:05 PST 2026


Hi Zhuxu,

On Wed Dec 2, 2026 at 10:30 PM CST, Zhuxu Ran wrote:
> Add cache-related and programmable PMA (MATTRI) CSRs definitions for
> Nuclei processors, required for cache initialization and non-cacheable
> DMA configuration on platforms using processors designed by Nuclei.
>
> Link: https://www.nucleisys.com/upload/files/doc/Nuclei_RISC-V_ISA_Spec.pdf
>
> Signed-off-by: Zhuxu Ran <zhuxu_ran at zohomail.com>

Please remove the blank line between tags.

> ---
>  platform/generic/include/nuclei/nuclei.h | 65 ++++++++++++++++++++++++++++++++
>  1 file changed, 65 insertions(+)
>
> diff --git a/platform/generic/include/nuclei/nuclei.h b/platform/generic/include/nuclei/nuclei.h
> new file mode 100644
> index 00000000..db26da66
> --- /dev/null
> +++ b/platform/generic/include/nuclei/nuclei.h
> @@ -0,0 +1,65 @@
> +/* SPDX-License-Identifier: BSD-2-Clause */
> +/*
> + * Copyright (c) 2026 Zhuxu Ran <zhuxu_ran at zohomail.com>
> + */
> +
> +#ifndef __RISCV_NUCLEI_H__
> +#define __RISCV_NUCLEI_H__
> +
> +/* Cache Control and Maintenance CSRs */
> +#define CSR_MCACHE_CTL		0x7ca

> +#define CSR_CCM_MBEGINADDR	0x7cb
> +#define CSR_CCM_MCOMMAND	0x7cc
> +#define CSR_CCM_MDATA		0x7cd

These three CSR definitions appear to be unused in this series. Could you
drop them unless they are needed?

> +#define CSR_CCM_SUEN		0x7ce
> +
> +/* CSR_MCACHE_CTL */
> +#define MCACHE_CTL_IC_EN	BIT(0)
> +#define MCACHE_CTL_IC_PF_EN	BIT(6)
> +#define MCACHE_CTL_IC_CANCEL_EN	BIT(7)
> +#define MCACHE_CTL_DC_EN	BIT(16)

I'd suggest placing the bit definitions immediately after their
corresponding CSR definitions to keep each CSR and its fields together.

Please also order the fields from high to low bits to match the manual
for easier reference.

For example:

/* Cache Control */
#define CSR_MCACHE_CTL			0x7ca
#define  MCACHE_CTL_DC_EN		BIT(16)
#define  MCACHE_CTL_IC_CANCEL_EN	BIT(7)
#define  MCACHE_CTL_IC_PF_EN		BIT(6)
#define  MCACHE_CTL_IC_EN		BIT(0)

...

> +
> +/* CSR_CCM_SUEN */
> +#define CCM_SUEN_UEN		BIT(0)
> +#define CCM_SUEN_SEN		BIT(1)
> +#define CCM_SUEN_UINVEN		BIT(8)
> +#define CCM_SUEN_SINVEN		BIT(9)
> +#define CCM_SUEN_UINVLEN	BIT(16)
> +#define CCM_SUEN_SINVLEN	BIT(17)
> +#define CCM_SUEN_UWBALLEN	BIT(24)
> +#define CCM_SUEN_SWBALLEN	BIT(25)
> +
> +/*
> + * M-mode Programmable PMA (MATTRI) CSRs

According to the Nuclei ISA manual, MATTRI stands for "Memory Attribute Tag
Registers". Could you use that name here?

> + * Note: 0x7f7 is CSR_MSMPCFG_INFO and 0x7f8 is reserved in Nuclei ISA.
> + */
> +#define CSR_MATTRI0_BASE	0x7f3
> +#define CSR_MATTRI0_MASK	0x7f4
> +#define CSR_MATTRI1_BASE	0x7f5
> +#define CSR_MATTRI1_MASK	0x7f6
> +#define CSR_MATTRI2_BASE	0x7f9
> +#define CSR_MATTRI2_MASK	0x7fa
> +#define CSR_MATTRI3_BASE	0x7fb
> +#define CSR_MATTRI3_MASK	0x7fc
> +#define CSR_MATTRI4_BASE	0x7fd
> +#define CSR_MATTRI4_MASK	0x7fe
> +#define CSR_MATTRI5_BASE	0xbe0
> +#define CSR_MATTRI5_MASK	0xbe1
> +#define CSR_MATTRI6_BASE	0xbe2
> +#define CSR_MATTRI6_MASK	0xbe3
> +#define CSR_MATTRI7_BASE	0xbe4
> +#define CSR_MATTRI7_MASK	0xbe5
> +
> +#define NUCLEI_MAX_PMA_REGIONS	8
> +#define NUCLEI_PMA_GRANULARITY	BIT(12)
> +#define NUCLEI_PMA_ADDR_MASK	(~(NUCLEI_PMA_GRANULARITY - 1))
> +
> +/* MATTRIn_BASE[3:0] */
> +#define NUCLEI_PMA_ENA		BIT(0)

Could we name the MATTRI field definitions consistently with the CSR names,
e.g. MATTRI_BASE_ENA?

> +#define NUCLEI_PMA_TYPE_CA	0UL
> +#define NUCLEI_PMA_TYPE_DEV	BIT(1)
> +#define NUCLEI_PMA_TYPE_NC	BIT(2)
> +#define NUCLEI_PMA_TYPE_SECSHARE BIT(3)

SecShare seems to be an independent attribute rather than a memory type, so
perhaps MATTRI_BASE_SECSHARE would be a clearer name.

> +#define NUCLEI_PMA_FLAGS_MASK	0xfUL
> +
> +#endif /* __RISCV_NUCLEI_H__ */

-- 
Best regards,
Junhui Liu




More information about the opensbi mailing list