public inbox for opensbi@lists.infradead.org
 help / color / mirror / Atom feed
From: Bo Gan <ganboing@gmail.com>
To: Yu-Chien Peter Lin <peter.lin@sifive.com>,
	opensbi@lists.infradead.org, ganboing@gmail.com
Subject: Re: [PATCH v3 2/4] lib: sbi: give platform choice of using single memregion to cover OpenSBI
Date: Sat, 6 Dec 2025 22:09:35 -0800	[thread overview]
Message-ID: <198651c8-9d0c-4199-8bc3-8e26f4320e7d@gmail.com> (raw)
In-Reply-To: <aa81c0c1-9688-46f0-8254-cf39a61b5049@sifive.com>

Hi Peter,

On 12/1/25 00:11, Yu-Chien Peter Lin wrote:
> Hi Bo,
> 
> Maybe use a FW option to enable single FW region at compile
> or runtime options.
> 
> compile time [1]:
> make PLATFORM=generic FW_OPTIONS=0x4
> 
> runtime [2]:
> Use fw dynamic and pass 0x4 via ((struct fw_dynamic_info *)$a2)->options
> 

I could be wrong, but I don't think it's the right approach. The strategy
of covering OpenSBI itself with single memregion is something internal to
OpenSBI, and shouldn't be allowed to be controlled by previous stage boot-
loader. Even if we allows it, previous stage bootloader will likely still
use options=0, and expect it to just boot, not to mention EIC7700 doesn't
have a previous stage bootloader. (It directly boots with OpenSBI) This
means we'll have to specify at compile time, not so different than my
previous version that got NAK'ed by Anup.

Bo

> [1] https://github.com/riscv-software-src/opensbi/blob/master/docs/firmware/fw.md#options-for-opensbi-firmware-behaviors
> [2] https://github.com/riscv-software-src/opensbi/blob/825d0e918a9e41cc57097a8cb913f26550699911/docs/firmware/fw_dynamic.md?plain=1#L10
> 
> diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h
> index f1b4155d..4f40fedd 100644
> --- a/include/sbi/sbi_scratch.h
> +++ b/include/sbi/sbi_scratch.h
> @@ -115,6 +115,13 @@ enum sbi_scratch_options {
>          SBI_SCRATCH_NO_BOOT_PRINTS = (1 << 0),
>          /** Enable runtime debug prints */
>          SBI_SCRATCH_DEBUG_PRINTS = (1 << 1),
> +       /**
> +        * Use single PMP entry covering entire firmware region.
> +        * Saves one PMP entry on non-Smepmp platforms at the cost
> +        * of coarser PMP granularity.
> +        * Not compatible with Smepmp (M-mode RWX is not supported).
> +        */
> +       SBI_SCRATCH_SINGLE_FW_PMP = (1 << 2),
>   };
> 
>   /** Get pointer to sbi_scratch for current HART */
> diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
> index da0f0557..0222ca93 100644
> --- a/lib/sbi/sbi_domain.c
> +++ b/lib/sbi/sbi_domain.c
> @@ -904,18 +904,27 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)
>          root.possible_harts = root_hmask;
> 
>          /* 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_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_FW),
> -  &root_memregs[root_memregs_count++]);
> +       if (scratch->options & SBI_SCRATCH_SINGLE_FW_PMP) {
> +               sbi_domain_memregion_init(scratch->fw_start, scratch->fw_size,
> +  (SBI_DOMAIN_MEMREGION_M_READABLE |
> + SBI_DOMAIN_MEMREGION_M_WRITABLE |
> + SBI_DOMAIN_MEMREGION_M_EXECUTABLE |
> + SBI_DOMAIN_MEMREGION_FW),
> +  &root_memregs[root_memregs_count++]);
> +       } else {
> +               sbi_domain_memregion_init(scratch->fw_start, scratch->fw_rw_offset,
> +  (SBI_DOMAIN_MEMREGION_M_READABLE |
> + 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_FW),
> +  &root_memregs[root_memregs_count++]);
> +       }
> 
>          root.fw_region_inited = true;
> 
> Best regards,
> Peter Lin
> 
> On 11/20/25 5:34 PM, Bo Gan wrote:
>> ...

-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

  reply	other threads:[~2025-12-07  6:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-20  9:34 [PATCH v3 0/4] Initial ESWIN/EIC7700 support Bo Gan
2025-11-20  9:34 ` [PATCH v3 1/4] lib: sbi: allow platform to override PMP (un)configuration Bo Gan
2025-11-20  9:34 ` [PATCH v3 2/4] lib: sbi: give platform choice of using single memregion to cover OpenSBI Bo Gan
2025-12-01  8:11   ` Yu-Chien Peter Lin
2025-12-07  6:09     ` Bo Gan [this message]
2025-11-20  9:34 ` [PATCH v3 3/4] include: sbi_domain: make is_region_subset public Bo Gan
2025-11-20  9:34 ` [PATCH v3 4/4] platform: generic: eswin: add EIC7700 Bo Gan
2025-12-01  7:35   ` Yu-Chien Peter Lin
2025-12-01 22:15     ` Bo Gan
2025-11-26 14:23 ` [PATCH v3 0/4] Initial ESWIN/EIC7700 support Anup Patel
2025-11-26 22:56   ` Bo Gan
2025-12-07  6:12     ` Bo Gan
2025-12-07 16:02       ` Anup Patel

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=198651c8-9d0c-4199-8bc3-8e26f4320e7d@gmail.com \
    --to=ganboing@gmail.com \
    --cc=opensbi@lists.infradead.org \
    --cc=peter.lin@sifive.com \
    /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