lib: utils/fdt: Add support for parsing riscv,isa-extensions
PATCH 1/1 lib: utils/fdt: Add support for parsing riscv,isa-extensions
From: Conor Dooley <[email protected]>
A new property has been added, with an extensive rationale at [1], that can be used in place of "riscv,isa" to indicate what extensions are supported by a given platform that is a list of strings rather than a single string. There are some differences between the new property, "riscv,isa-extensions" and the incumbent "riscv,isa" - chief among them for the sake of parsing being the list of strings, as opposed to a string. Another advantage is strictly defined meanings for each string in a dt-binding, rather than deriving meaning from RVI standards. This may likely to some divergence over time, but, at least for now, there's no relevant differences between the two for an M-Mode program.
Add support for the new property in OpenSBI, prioritising it, before falling back to the, now deprecated, "riscv,isa" property if it is not present.
--- lib/utils/fdt/fdt_helper.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
lib/utils/fdt/fdt_helper.c +23 -4
@@ -411,6 +411,18 @@ static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions)return 0 ; } +static void fdt_parse_isa_extensions_one_hart (const char *isa, +unsigned long *extensions, +int len) +{ +size_t i; + +for (i =0 ; i <SBI_HART_EXT_MAX ; i++) { +if (fdt_stringlist_contains (isa, len, sbi_hart_ext[i].name)) +__set_bit (sbi_hart_ext[i].id, extensions); + } +} +static int fdt_parse_isa_all_harts (void *fdt) {u32 hartid;
@@ -434,10 +446,6 @@ static int fdt_parse_isa_all_harts(void *fdt)if (!fdt_node_is_enabled (fdt, cpu_offset))continue ; - val =fdt_getprop (fdt, cpu_offset,"riscv,isa" , &len); -if (!val || len <=0 ) -return SBI_ENOENT ; - scratch =sbi_hartid_to_scratch (hartid);if (!scratch)return SBI_ENOENT ;
@@ -445,6 +453,17 @@ static int fdt_parse_isa_all_harts(void *fdt) hart_exts =sbi_scratch_offset_ptr (scratch, fdt_isa_bitmap_offset); + val =fdt_getprop (fdt, cpu_offset,"riscv,isa-extensions" , &len); +if (val && len >0 ) { +fdt_parse_isa_extensions_one_hart ((const char *)val, + hart_exts, len); +continue ; + } + + 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, hart_exts);if (err)return err;
Signature · 1 line
2.43.0
Anup Patel
AppliedPATCH 1/1 lib: utils/fdt: Add support for parsing riscv,isa-extensions
Quoted 14 lines · On Tue, Jul 2, 2024 at 4:30?PM Conor Dooley <[email protected]> wrote:
From: Conor Dooley <[email protected]>
A new property has been added, with an extensive rationale at [1], that can be used in place of "riscv,isa" to indicate what extensions are supported by a given platform that is a list of strings rather than a single string. There are some differences between the new property, "riscv,isa-extensions" and the incumbent "riscv,isa" - chief among them for the sake of parsing being the list of strings, as opposed to a string. Another advantage is strictly defined meanings for each string in a dt-binding, rather than deriving meaning from RVI standards. This may likely to some divergence over time, but, at least for now, there's no relevant differences between the two for an M-Mode program.
Quoted 6 lines
Add support for the new property in OpenSBI, prioritising it, before falling back to the, now deprecated, "riscv,isa" property if it is not present.
Link https://lore.kernel.org/all/20230702-eats-scorebook-c951f170d29f at spud/ [1]Signed-off-by Conor Dooley <[email protected]>
LGTM.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 64 lines
--- lib/utils/fdt/fdt_helper.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)lib/utils/fdt/fdt_helper.c +23
-5@@ -411,6 +411,18 @@ static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions)return 0 ; } +static void fdt_parse_isa_extensions_one_hart (const char *isa, +unsigned long *extensions, +int len) +{ +size_t i; + +for (i =0 ; i <SBI_HART_EXT_MAX ; i++) { +if (fdt_stringlist_contains (isa, len, sbi_hart_ext[i].name)) +__set_bit (sbi_hart_ext[i].id, extensions); + } +} +static int fdt_parse_isa_all_harts (void *fdt) {u32 hartid;@@ -434,10 +446,6 @@ static int fdt_parse_isa_all_harts(void *fdt)if (!fdt_node_is_enabled (fdt, cpu_offset))continue ; - val =fdt_getprop (fdt, cpu_offset,"riscv,isa" , &len); -if (!val || len <=0 ) -return SBI_ENOENT ; - scratch =sbi_hartid_to_scratch (hartid);if (!scratch)return SBI_ENOENT ;@@ -445,6 +453,17 @@ static int fdt_parse_isa_all_harts(void *fdt) hart_exts =sbi_scratch_offset_ptr (scratch, fdt_isa_bitmap_offset); + val =fdt_getprop (fdt, cpu_offset,"riscv,isa-extensions" , &len); +if (val && len >0 ) { +fdt_parse_isa_extensions_one_hart ((const char *)val, + hart_exts, len); +continue ; + } + + 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, hart_exts);if (err)return err; --2.43.0
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi