From 44dd7be3b2b3b821912e32a1021706a2edb9d44b Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 24 Apr 2020 15:08:19 +0530 Subject: [PATCH] lib: utils: Add fdt_parse_max_hart_id() API We add fdt_parse_max_hart_id() API which return max HART id based on CPU DT nodes. This will be used by generic FDT based drivers in subsequent patches. Signed-off-by: Anup Patel Reviewed-by: Atish Patra Reviewed-by: Alistair Francis --- include/sbi_utils/fdt/fdt_helper.h | 2 ++ lib/utils/fdt/fdt_helper.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/sbi_utils/fdt/fdt_helper.h b/include/sbi_utils/fdt/fdt_helper.h index 98c789bf..5a0a719e 100644 --- a/include/sbi_utils/fdt/fdt_helper.h +++ b/include/sbi_utils/fdt/fdt_helper.h @@ -41,6 +41,8 @@ int fdt_get_node_addr_size(void *fdt, int node, unsigned long *addr, int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid); +int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid); + int fdt_parse_sifive_uart_node(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 af13810a..2d79f759 100644 --- a/lib/utils/fdt/fdt_helper.c +++ b/lib/utils/fdt/fdt_helper.c @@ -132,6 +132,34 @@ int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid) return 0; } +int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid) +{ + u32 hartid; + int err, cpu_offset, cpus_offset; + + if (!fdt) + return SBI_EINVAL; + if (!max_hartid) + return 0; + + *max_hartid = 0; + + cpus_offset = fdt_path_offset(fdt, "/cpus"); + if (cpus_offset < 0) + return cpus_offset; + + fdt_for_each_subnode(cpu_offset, fdt, cpus_offset) { + err = fdt_parse_hart_id(fdt, cpu_offset, &hartid); + if (err) + continue; + + if (hartid > *max_hartid) + *max_hartid = hartid; + } + + return 0; +} + int fdt_parse_sifive_uart_node(void *fdt, int nodeoffset, struct platform_uart_data *uart) {