[PATCH v5 2/9] lib: utils: fdt_helper: parse RISC-V Worlds per-hart WID properties

Pawandeep Oza pawandeep.oza at oss.qualcomm.com
Tue Nov 10 10:48:43 PST 2026


On Tue, Nov 10, 2026 at 1:50 AM Yu-Chien Peter Lin <peter.lin at sifive.com> wrote:
>
> Extend fdt_parse_isa_extensions_all_harts() to also parse the
> platform-defined RISC-V Worlds DT properties in /cpus/cpu at X:
> - riscv,pmwid: M-mode World ID
> - riscv,pmwidlist: bitmap of permitted M-mode WIDs
> - riscv,pmlwidlist: bitmap of permitted lower-privilege WIDs
> and store the parsed values in struct sbi_hart_features.
>
> These platform-defined values serve as the root-of-trust constraints
> for per-domain WID assignment during domain creation and context
> switching.
>
> Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
> Reviewed-by: Anup Patel <anup at brainfault.org>
> ---
> Changes v4->v5:
> - No change
> ---
>  include/sbi/sbi_hart.h     |  5 +++
>  lib/utils/fdt/fdt_helper.c | 69 ++++++++++++++++++++++++++++++++++----
>  2 files changed, 67 insertions(+), 7 deletions(-)
>
> diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h
> index ed344783..629e3f64 100644
> --- a/include/sbi/sbi_hart.h
> +++ b/include/sbi/sbi_hart.h
> @@ -138,6 +138,11 @@ struct sbi_hart_features {
>         unsigned int mhpm_mask;
>         unsigned int mhpm_bits;
>         unsigned long expected_trap;
> +       u32 pmwid;
> +       u64 pmwidlist;
> +       u64 pmlwidlist;
> +       bool has_pmwid;
> +       bool has_pmlwidlist;
>  };
>
>  extern unsigned long hart_features_offset;
> diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c
> index 747ba028..fdd25648 100644
> --- a/lib/utils/fdt/fdt_helper.c
> +++ b/lib/utils/fdt/fdt_helper.c
> @@ -442,16 +442,71 @@ int fdt_parse_isa_extensions_all_harts(const void *fdt)
>                 if (val && len > 0) {
>                         fdt_parse_isa_extensions_one_hart((const char *)val,
>                                                           hfeatures->extensions, len);
> -                       continue;
> +               } else {
> +                       val = fdt_getprop(fdt, cpu_offset, "riscv,isa", &len);
> +                       if (!val || len <= 0)
> +                               return SBI_ENOENT;
> +
> +                       err = fdt_parse_isa_one_hart((const char *)val,
> +                                                    hfeatures->extensions);
> +                       if (err)
> +                               return err;
>                 }
>
> -               val = fdt_getprop(fdt, cpu_offset, "riscv,isa", &len);
> -               if (!val || len <= 0)
> -                       return SBI_ENOENT;
> +               val = fdt_getprop(fdt, cpu_offset, "riscv,pmwid", &len);
> +               if (val && len == sizeof(fdt32_t)) {
> +                       hfeatures->pmwid = fdt32_to_cpu(*val);
> +                       hfeatures->has_pmwid = true;
> +               }
>
> -               err = fdt_parse_isa_one_hart((const char *)val, hfeatures->extensions);
> -               if (err)
> -                       return err;
> +               val = fdt_getprop(fdt, cpu_offset, "riscv,pmwidlist", &len);
> +               if (val && len == 2 * sizeof(fdt32_t)) {
> +                       hfeatures->pmwidlist = ((u64)fdt32_to_cpu(val[0]) << 32) |
> +                                               fdt32_to_cpu(val[1]);
> +                       if (!hfeatures->pmwidlist) {
> +                               sbi_printf("%s: hart%u riscv,pmwidlist is empty\n",
> +                                          __func__, hartid);
> +                               return SBI_EINVAL;
> +                       }
> +               }
> +
> +               val = fdt_getprop(fdt, cpu_offset, "riscv,pmlwidlist", &len);
> +               if (val && len == 2 * sizeof(fdt32_t)) {
> +                       hfeatures->pmlwidlist = ((u64)fdt32_to_cpu(val[0]) << 32) |
> +                                                fdt32_to_cpu(val[1]);
> +                       hfeatures->has_pmlwidlist = true;
> +               }
> +
> +               /* Sanity checks */
> +#if __riscv_xlen == 32
> +               if (hfeatures->pmwidlist &&
> +                   (hfeatures->pmwidlist >> 32)) {
> +                       sbi_printf("%s: hart%u riscv,pmwidlist has bits beyond XLEN\n",
> +                                  __func__, hartid);
> +                       return SBI_EINVAL;
> +               }
> +
> +               if (hfeatures->has_pmlwidlist &&
> +                   (hfeatures->pmlwidlist >> 32)) {
> +                       sbi_printf("%s: hart%u riscv,pmlwidlist has bits beyond XLEN\n",
> +                                  __func__, hartid);
> +                       return SBI_EINVAL;
> +               }
> +#endif
> +
> +               if (hfeatures->has_pmwid &&
> +                   hfeatures->pmwid >= __riscv_xlen) {
> +                       sbi_printf("%s: hart%u riscv,pmwid (%u) exceeds max WID\n",
> +                                  __func__, hartid, hfeatures->pmwid);
> +                       return SBI_EINVAL;
> +               }
> +
> +               if (hfeatures->pmwidlist && hfeatures->has_pmwid &&
> +                   !(hfeatures->pmwidlist & BIT_ULL(hfeatures->pmwid))) {
> +                       sbi_printf("%s: hart%u riscv,pmwid (%u) not in pmwidlist\n",
> +                                  __func__, hartid, hfeatures->pmwid);
> +                       return SBI_EINVAL;
> +               }
>         }
>
>         return 0;
> --
> 2.43.7
>

Reviewed-by: Pawandeep Oza <pawandeep.oza at oss.qualcomm.com>



More information about the opensbi mailing list