[PATCH 2/4] lib: sbi: Detect menvcfg CSR at boot time
Xiang W
wxjstz at 126.com
Wed Mar 30 07:48:07 PDT 2022
在 2022-03-29星期二的 21:22 +0530,Anup Patel写道:
> From: Atish Patra <atishp at rivosinc.com>
>
> We add the menvcfg CSR as a HART feature and detect it at boot time
> using traping mechanism.
>
> Signed-off-by: Atish Patra <atishp at rivosinc.com>
> Signed-off-by: Anup Patel <apatel at ventanamicro.com>
Reviewed-by: Xiang W <wxjstz at 126.com>
Regards,
Xiang W
> ---
> include/sbi/sbi_hart.h | 4 +++-
> lib/sbi/sbi_hart.c | 9 +++++++++
> 2 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h
> index a83b45b..57f80bc 100644
> --- a/include/sbi/sbi_hart.h
> +++ b/include/sbi/sbi_hart.h
> @@ -26,9 +26,11 @@ enum sbi_hart_features {
> SBI_HART_HAS_TIME = (1 << 4),
> /** HART has AIA local interrupt CSRs */
> SBI_HART_HAS_AIA = (1 << 5),
> + /** HART has menvcfg CSR */
> + SBI_HART_HAS_MENVCFG = (1 << 6),
>
> /** Last index of Hart features*/
> - SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_AIA,
> + SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_MENVCFG,
> };
>
> struct sbi_scratch;
> diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
> index e028540..31c8f39 100644
> --- a/lib/sbi/sbi_hart.c
> +++ b/lib/sbi/sbi_hart.c
> @@ -304,6 +304,9 @@ static inline char
> *sbi_hart_feature_id2string(unsigned long feature)
> case SBI_HART_HAS_AIA:
> fstr = "aia";
> break;
> + case SBI_HART_HAS_MENVCFG:
> + fstr = "menvcfg";
> + break;
> default:
> break;
> }
> @@ -534,6 +537,12 @@ __mhpm_skip:
> goto __aia_skip;
> hfeatures->features |= SBI_HART_HAS_AIA;
> __aia_skip:
> +
> + /* Detect if hart has menvcfg CSR */
> + csr_read_allowed(CSR_MENVCFG, (unsigned long)&trap);
> + if (!trap.cause)
> + hfeatures->features |= SBI_HART_HAS_MENVCFG;
> +
> return;
> }
>
> --
> 2.25.1
>
>
More information about the opensbi
mailing list