aboutsummaryrefslogtreecommitdiff
path: root/lib/utils/fdt
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2021-05-20 13:38:38 +0530
committerAnup Patel <anup@brainfault.org>2021-06-24 09:39:48 +0530
commitbd5d2089b80742a210b257c8e6c1361310725200 (patch)
treeada664073241ca2ac195f1cd1f15001307c0e520 /lib/utils/fdt
parent5a049fe1d6a5d1c381113853fce3afad6573bb56 (diff)
lib: utils: Add FDT parsing API common for both ACLINT and CLINT
We add fdt_parse_aclint_node() which can parse both ACLINT and CLINT DT nodes. This means fdt_parse_clint_node() is not required anymore so we remove it as well. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com>
Diffstat (limited to 'lib/utils/fdt')
-rw-r--r--lib/utils/fdt/fdt_helper.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c
index 9143e44..de77196 100644
--- a/lib/utils/fdt/fdt_helper.c
+++ b/lib/utils/fdt/fdt_helper.c
@@ -14,7 +14,6 @@
#include <sbi/sbi_scratch.h>
#include <sbi_utils/fdt/fdt_helper.h>
#include <sbi_utils/irqchip/plic.h>
-#include <sbi_utils/sys/clint.h>
#define DEFAULT_UART_FREQ 0
#define DEFAULT_UART_BAUD 115200
@@ -421,8 +420,9 @@ int fdt_parse_plic(void *fdt, struct plic_data *plic, const char *compat)
return fdt_parse_plic_node(fdt, nodeoffset, plic);
}
-int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer,
- struct clint_data *clint)
+int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
+ unsigned long *out_addr, unsigned long *out_size,
+ u32 *out_first_hartid, u32 *out_hart_count)
{
const fdt32_t *val;
unsigned long reg_addr, reg_size;
@@ -430,22 +430,25 @@ int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer,
u32 phandle, hwirq, hartid, first_hartid, last_hartid;
u32 match_hwirq = (for_timer) ? IRQ_M_TIMER : IRQ_M_SOFT;
- if (nodeoffset < 0 || !clint || !fdt)
- return SBI_ENODEV;
+ if (nodeoffset < 0 || !fdt ||
+ !out_addr || !out_size ||
+ !out_first_hartid || !out_hart_count)
+ return SBI_EINVAL;
rc = fdt_get_node_addr_size(fdt, nodeoffset, &reg_addr, &reg_size);
if (rc < 0 || !reg_addr || !reg_size)
return SBI_ENODEV;
- clint->addr = reg_addr;
+ *out_addr = reg_addr;
+ *out_size = reg_size;
val = fdt_getprop(fdt, nodeoffset, "interrupts-extended", &count);
if (!val || count < sizeof(fdt32_t))
- return SBI_EINVAL;
+ return SBI_ENODEV;
count = count / sizeof(fdt32_t);
first_hartid = -1U;
last_hartid = 0;
- clint->hart_count = 0;
+ *out_hart_count = 0;
for (i = 0; i < count; i += 2) {
phandle = fdt32_to_cpu(val[i]);
hwirq = fdt32_to_cpu(val[i + 1]);
@@ -470,21 +473,17 @@ int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer,
first_hartid = hartid;
if (hartid > last_hartid)
last_hartid = hartid;
- clint->hart_count++;
+ (*out_hart_count)++;
}
}
if ((last_hartid < first_hartid) || first_hartid == -1U)
return SBI_ENODEV;
- clint->first_hartid = first_hartid;
+ *out_first_hartid = first_hartid;
count = last_hartid - first_hartid + 1;
- if (clint->hart_count < count)
- clint->hart_count = count;
-
- clint->has_64bit_mmio = TRUE;
- if (fdt_getprop(fdt, nodeoffset, "clint,has-no-64bit-mmio", &count))
- clint->has_64bit_mmio = FALSE;
+ if (*out_hart_count < count)
+ *out_hart_count = count;
return 0;
}