mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-06-12 22:31:45 +01:00
platform: generic: Optimize extensions_init() to parse ISA extensions once
Instead of parsing ISA extensions separately for each hart in the generic_extensions_init() function, it is better to parse ISA extensions for all available harts in the cold boot path. Also, this allows us to remove fdt_isa_bitmap from scratch space and directly initialize "extensions" in struct sbi_hart_features for each hart. Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com> Link: https://lore.kernel.org/r/20260521082625.1520870-3-anup.patel@oss.qualcomm.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
@@ -328,8 +328,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;
|
||||
@@ -409,15 +407,15 @@ 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_all_harts(const void *fdt)
|
||||
{
|
||||
u32 hartid;
|
||||
const fdt32_t *val;
|
||||
unsigned long *hart_exts;
|
||||
struct sbi_scratch *scratch;
|
||||
struct sbi_hart_features *hfeatures;
|
||||
int err, cpu_offset, cpus_offset, len;
|
||||
|
||||
if (!fdt || !fdt_isa_bitmap_offset)
|
||||
if (!fdt)
|
||||
return SBI_EINVAL;
|
||||
|
||||
cpus_offset = fdt_path_offset(fdt, "/cpus");
|
||||
@@ -436,13 +434,14 @@ static int fdt_parse_isa_all_harts(const void *fdt)
|
||||
if (!scratch)
|
||||
return SBI_ENOENT;
|
||||
|
||||
hart_exts = sbi_scratch_offset_ptr(scratch,
|
||||
fdt_isa_bitmap_offset);
|
||||
hfeatures = sbi_hart_features_ptr(scratch);
|
||||
if (!hfeatures)
|
||||
return SBI_ENOENT;
|
||||
|
||||
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);
|
||||
hfeatures->extensions, len);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -450,7 +449,7 @@ static int fdt_parse_isa_all_harts(const void *fdt)
|
||||
if (!val || len <= 0)
|
||||
return SBI_ENOENT;
|
||||
|
||||
err = fdt_parse_isa_one_hart((const char *)val, hart_exts);
|
||||
err = fdt_parse_isa_one_hart((const char *)val, hfeatures->extensions);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
@@ -458,36 +457,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,
|
||||
|
||||
Reference in New Issue
Block a user