summaryrefslogtreecommitdiff
path: root/lib/utils/fdt/fdt_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils/fdt/fdt_helper.c')
-rw-r--r--lib/utils/fdt/fdt_helper.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c
index ce52fca..d390436 100644
--- a/lib/utils/fdt/fdt_helper.c
+++ b/lib/utils/fdt/fdt_helper.c
@@ -889,6 +889,60 @@ int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base,
return 0;
}
+int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base,
+ unsigned long *size, u32 *hart_count)
+{
+ const fdt32_t *val;
+ int rc, i, count;
+ uint64_t reg_addr, reg_size, cpu_offset, cpu_intc_offset;
+ u32 phandle, hwirq, hartid, hcount;
+
+ if (nodeoffset < 0 || !fdt || !plicsw_base ||
+ !hart_count || !size)
+ return SBI_EINVAL;
+
+ rc = fdt_get_node_addr_size(fdt, nodeoffset, 0,
+ &reg_addr, &reg_size);
+ if (rc < 0 || !plicsw_base || !size)
+ return SBI_ENODEV;
+ *plicsw_base = reg_addr;
+ *size = reg_size;
+
+ val = fdt_getprop(fdt, nodeoffset, "interrupts-extended", &count);
+ if (!val || count < sizeof(fdt32_t))
+ return 0;
+ count = count / sizeof(fdt32_t);
+
+ hcount = 0;
+ for (i = 0; i < (count / 2); i++) {
+ phandle = fdt32_to_cpu(val[2 * i]);
+ hwirq = fdt32_to_cpu(val[2 * i + 1]);
+
+ cpu_intc_offset = fdt_node_offset_by_phandle(fdt, phandle);
+ if (cpu_intc_offset < 0)
+ continue;
+
+ cpu_offset = fdt_parent_offset(fdt, cpu_intc_offset);
+ if (cpu_intc_offset < 0)
+ continue;
+
+ rc = fdt_parse_hart_id(fdt, cpu_offset, &hartid);
+
+ if (rc)
+ continue;
+
+ if (SBI_HARTMASK_MAX_BITS <= hartid)
+ continue;
+
+ if (hwirq == IRQ_M_SOFT)
+ hcount++;
+ }
+
+ *hart_count = hcount;
+
+ return 0;
+}
+
int fdt_parse_compat_addr(void *fdt, uint64_t *addr,
const char *compatible)
{