From: Xiang W <wxjstz@126.com>
To: Yu-Chien Peter Lin <peter.lin@sifive.com>, opensbi@lists.infradead.org
Cc: zong.li@sifive.com, greentime.hu@sifive.com
Subject: Re: [PATCH v2] lib: utils: fdt_helper: simplify fdt_parse_isa_extensions() helper
Date: Mon, 08 Sep 2025 19:11:33 +0800 [thread overview]
Message-ID: <d62bb60cdb73a67c486440e8ff48861b99c11229.camel@126.com> (raw)
In-Reply-To: <20250906072656.5525-1-peter.lin@sifive.com>
在 2025-09-06六的 15:26 +0800,Yu-Chien Peter Lin写道:
> The fdt_isa_bitmap was previously used as a temporary array
> to store ISA extensions when parsing device-tree.
> To reduce scratch space consumption, set the ISA bitmap
> directly in hfeature->extensions, allows us to remove the
> fdt_parse_isa_all_harts() as fdt_parse_isa_extensions() can
> now handle the task directly.
>
> This change makes the helper function more versatile, even
> before scratch space is initialized.
>
> Signed-off-by: Yu-Chien Peter Lin <peter.lin@sifive.com>
LGTM
Signed-off-by: Xiang W <wxjstz@126.com>
> ---
> include/sbi_utils/fdt/fdt_helper.h | 3 +-
> lib/utils/fdt/fdt_helper.c | 48 ++++--------------------------
> platform/generic/platform.c | 2 +-
> 3 files changed, 7 insertions(+), 46 deletions(-)
>
> diff --git a/include/sbi_utils/fdt/fdt_helper.h b/include/sbi_utils/fdt/fdt_helper.h
> index 04c850cc..24ad1a94 100644
> --- a/include/sbi_utils/fdt/fdt_helper.h
> +++ b/include/sbi_utils/fdt/fdt_helper.h
> @@ -54,8 +54,7 @@ int fdt_parse_cbom_block_size(const void *fdt, int cpu_offset, unsigned long *c
>
> int fdt_parse_timebase_frequency(const void *fdt, unsigned long *freq);
>
> -int fdt_parse_isa_extensions(const void *fdt, unsigned int hartid,
> - unsigned long *extensions);
> +int fdt_parse_isa_extensions(const void *fdt, unsigned long *hart_exts);
>
> int fdt_parse_gaisler_uart_node(const void *fdt, int nodeoffset,
> struct platform_uart_data *uart);
> diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c
> index 0f4859c1..252dd459 100644
> --- a/lib/utils/fdt/fdt_helper.c
> +++ b/lib/utils/fdt/fdt_helper.c
> @@ -324,8 +324,6 @@ int fdt_parse_timebase_frequency(const void *fdt, unsigned long *freq)
>
> #define RISCV_ISA_EXT_NAME_LEN_MAX 32
>
> -static unsigned long fdt_isa_bitmap_offset;
> -
> static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions)
> {
> size_t i, j, isa_len;
> @@ -405,15 +403,13 @@ static void fdt_parse_isa_extensions_one_hart(const char *isa,
> }
> }
>
> -static int fdt_parse_isa_all_harts(const void *fdt)
> +int fdt_parse_isa_extensions(const void *fdt, unsigned long *hart_exts)
> {
> u32 hartid;
> const fdt32_t *val;
> - unsigned long *hart_exts;
> - struct sbi_scratch *scratch;
> int err, cpu_offset, cpus_offset, len;
>
> - if (!fdt || !fdt_isa_bitmap_offset)
> + if (!fdt || !hart_exts)
> return SBI_EINVAL;
>
> cpus_offset = fdt_path_offset(fdt, "/cpus");
> @@ -425,15 +421,11 @@ static int fdt_parse_isa_all_harts(const void *fdt)
> if (err)
> continue;
>
> - if (!fdt_node_is_enabled(fdt, cpu_offset))
> + if (hartid != current_hartid())
> continue;
>
> - scratch = sbi_hartid_to_scratch(hartid);
> - if (!scratch)
> - return SBI_ENOENT;
> -
> - hart_exts = sbi_scratch_offset_ptr(scratch,
> - fdt_isa_bitmap_offset);
> + if (!fdt_node_is_enabled(fdt, cpu_offset))
> + continue;
>
> val = fdt_getprop(fdt, cpu_offset, "riscv,isa-extensions", &len);
> if (val && len > 0) {
> @@ -454,36 +446,6 @@ static int fdt_parse_isa_all_harts(const void *fdt)
> return 0;
> }
>
> -int fdt_parse_isa_extensions(const void *fdt, unsigned int hartid,
> - unsigned long *extensions)
> -{
> - int rc, i;
> - unsigned long *hart_exts;
> - struct sbi_scratch *scratch;
> -
> - if (!fdt_isa_bitmap_offset) {
> - fdt_isa_bitmap_offset = sbi_scratch_alloc_offset(
> - sizeof(*hart_exts) *
> - BITS_TO_LONGS(SBI_HART_EXT_MAX));
> - if (!fdt_isa_bitmap_offset)
> - return SBI_ENOMEM;
> -
> - rc = fdt_parse_isa_all_harts(fdt);
> - if (rc)
> - return rc;
> - }
> -
> - scratch = sbi_hartid_to_scratch(hartid);
> - if (!scratch)
> - return SBI_ENOENT;
> -
> - hart_exts = sbi_scratch_offset_ptr(scratch, fdt_isa_bitmap_offset);
> -
> - for (i = 0; i < BITS_TO_LONGS(SBI_HART_EXT_MAX); i++)
> - extensions[i] |= hart_exts[i];
> - return 0;
> -}
> -
> static int fdt_parse_uart_node_common(const void *fdt, int nodeoffset,
> struct platform_uart_data *uart,
> unsigned long default_freq,
> diff --git a/platform/generic/platform.c b/platform/generic/platform.c
> index 47e771ad..2e8c6051 100644
> --- a/platform/generic/platform.c
> +++ b/platform/generic/platform.c
> @@ -251,7 +251,7 @@ int generic_final_init(bool cold_boot)
> int generic_extensions_init(struct sbi_hart_features *hfeatures)
> {
> /* Parse the ISA string from FDT and enable the listed extensions */
> - return fdt_parse_isa_extensions(fdt_get_address(), current_hartid(),
> + return fdt_parse_isa_extensions(fdt_get_address(),
> hfeatures->extensions);
> }
>
> --
> 2.48.0
>
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev parent reply other threads:[~2025-09-08 12:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-06 7:26 [PATCH v2] lib: utils: fdt_helper: simplify fdt_parse_isa_extensions() helper Yu-Chien Peter Lin
2025-09-08 11:11 ` Xiang W [this message]
2025-09-10 5:04 ` Samuel Holland
2025-09-12 3:05 ` Peter Lin
2025-09-12 5:35 ` [PATCH v3] " Xiang W
2025-09-12 6:38 ` Peter Lin
2025-09-12 7:06 ` [PATCH v4] " Xiang W
2025-09-12 8:56 ` Peter Lin
2025-09-12 9:09 ` Xiang W
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=d62bb60cdb73a67c486440e8ff48861b99c11229.camel@126.com \
--to=wxjstz@126.com \
--cc=greentime.hu@sifive.com \
--cc=opensbi@lists.infradead.org \
--cc=peter.lin@sifive.com \
--cc=zong.li@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