Re: [PATCH 6/8] lib: sbi_domain: add SBI_DOMAIN_MEMREGION_FW memregion flag

Xiang W
2025-08-21T10:29:19Z

在 2025-08-14四的 19:05 +0800，Yu-Chien Peter Lin写道：
> Add a new memregion flag, SBI_DOMAIN_MEMREGION_FW and mark the
> code and data sections of firmware.
>
> Signed-off-by: Yu-Chien Peter Lin <peter.lin@sifive.com>
> ---
>  include/sbi/sbi_domain.h | 1 +
>  lib/sbi/sbi_domain.c     | 8 ++++++--
>  2 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h
> index 8a51f289..d71354c7 100644
> --- a/include/sbi/sbi_domain.h
> +++ b/include/sbi/sbi_domain.h
> @@ -157,6 +157,7 @@ struct sbi_domain_memregion {
>   SBI_DOMAIN_MEMREGION_M_EXECUTABLE)
>
>  #define SBI_DOMAIN_MEMREGION_MMIO (1UL << 31)
> +#define SBI_DOMAIN_MEMREGION_FW (1UL << 32)
Will overflow under RV32.

Regards,
Xiang W
>   unsigned long flags;
>  };
>
> diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
> index d6566b12..ccfcc7f0 100644
> --- a/lib/sbi/sbi_domain.c
> +++ b/lib/sbi/sbi_domain.c
> @@ -541,6 +541,8 @@ void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix)
>   sbi_printf("M: ");
>   if (reg->flags & SBI_DOMAIN_MEMREGION_MMIO)
>   sbi_printf("%cI", (k++) ? ',' : '(');
> + if (reg->flags & SBI_DOMAIN_MEMREGION_FW)
> + sbi_printf("%cF", (k++) ? ',' : '(');
>   if (reg->flags & SBI_DOMAIN_MEMREGION_M_READABLE)
>   sbi_printf("%cR", (k++) ? ',' : '(');
>   if (reg->flags & SBI_DOMAIN_MEMREGION_M_WRITABLE)
> @@ -894,13 +896,15 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)
>   /* Root domain firmware memory region */
>   sbi_domain_memregion_init(scratch->fw_start, scratch->fw_rw_offset,
>     (SBI_DOMAIN_MEMREGION_M_READABLE |
> -    SBI_DOMAIN_MEMREGION_M_EXECUTABLE),
> +    SBI_DOMAIN_MEMREGION_M_EXECUTABLE |
> +    SBI_DOMAIN_MEMREGION_FW),
>     &root_memregs[root_memregs_count++]);
>
>   sbi_domain_memregion_init((scratch->fw_start + scratch->fw_rw_offset),
>     (scratch->fw_size - scratch->fw_rw_offset),
>     (SBI_DOMAIN_MEMREGION_M_READABLE |
> -    SBI_DOMAIN_MEMREGION_M_WRITABLE),
> +    SBI_DOMAIN_MEMREGION_M_WRITABLE |
> +    SBI_DOMAIN_MEMREGION_FW),
>     &root_memregs[root_memregs_count++]);
>
>   root.fw_region_inited = true;
> --
> 2.39.3
>