Debian Codegraph @

src/mainboard/emulation/qemu-riscv/smp.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <mcall.h>
4 #include <arch/smp/smp.h>
5 #include <commonlib/device_tree.h>
6 #include <console/console.h>
7
8 unsigned int smp_get_hart_count(void)
9 {
10 if (!fdt_is_valid(HLS()->fdt))
11 goto error;
12
13 uint32_t cpus_offset = fdt_find_node_by_path(HLS()->fdt, "/cpus", NULL, NULL);
14 if (!cpus_offset)
15 goto error;
16
17 static u32 harts[CONFIG_MAX_CPUS]; // too big for the stack
18 size_t count_harts = fdt_find_subnodes_by_prefix(HLS()->fdt, cpus_offset, "cpu@",
19 NULL, NULL, harts, CONFIG_MAX_CPUS);
20 if (!count_harts)
21 goto error;
22
23 printk(BIOS_DEBUG, "found %zu harts in devicetree\n", count_harts);
24 return count_harts;
25 error:
26 printk(BIOS_ERR, "%s: Failed to read devicetree to get number of harts\n", __func__);
27 return 1; // Return single hart on failure to keep booting
28 }