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>
This commit is contained in:
Anup Patel
2021-05-20 13:38:38 +05:30
committed by Anup Patel
parent 5a049fe1d6
commit bd5d2089b8
4 changed files with 30 additions and 22 deletions

View File

@@ -60,10 +60,9 @@ int fdt_parse_plic_node(void *fdt, int nodeoffset, struct plic_data *plic);
int fdt_parse_plic(void *fdt, struct plic_data *plic, const char *compat); int fdt_parse_plic(void *fdt, struct plic_data *plic, const char *compat);
struct clint_data; int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
unsigned long *out_addr, unsigned long *out_size,
int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer, u32 *out_first_hartid, u32 *out_hart_count);
struct clint_data *clint);
int fdt_parse_compat_addr(void *fdt, unsigned long *addr, int fdt_parse_compat_addr(void *fdt, unsigned long *addr,
const char *compatible); const char *compatible);

View File

@@ -14,7 +14,6 @@
#include <sbi/sbi_scratch.h> #include <sbi/sbi_scratch.h>
#include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/fdt/fdt_helper.h>
#include <sbi_utils/irqchip/plic.h> #include <sbi_utils/irqchip/plic.h>
#include <sbi_utils/sys/clint.h>
#define DEFAULT_UART_FREQ 0 #define DEFAULT_UART_FREQ 0
#define DEFAULT_UART_BAUD 115200 #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); return fdt_parse_plic_node(fdt, nodeoffset, plic);
} }
int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer, int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
struct clint_data *clint) unsigned long *out_addr, unsigned long *out_size,
u32 *out_first_hartid, u32 *out_hart_count)
{ {
const fdt32_t *val; const fdt32_t *val;
unsigned long reg_addr, reg_size; 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 phandle, hwirq, hartid, first_hartid, last_hartid;
u32 match_hwirq = (for_timer) ? IRQ_M_TIMER : IRQ_M_SOFT; u32 match_hwirq = (for_timer) ? IRQ_M_TIMER : IRQ_M_SOFT;
if (nodeoffset < 0 || !clint || !fdt) if (nodeoffset < 0 || !fdt ||
return SBI_ENODEV; !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); rc = fdt_get_node_addr_size(fdt, nodeoffset, &reg_addr, &reg_size);
if (rc < 0 || !reg_addr || !reg_size) if (rc < 0 || !reg_addr || !reg_size)
return SBI_ENODEV; return SBI_ENODEV;
clint->addr = reg_addr; *out_addr = reg_addr;
*out_size = reg_size;
val = fdt_getprop(fdt, nodeoffset, "interrupts-extended", &count); val = fdt_getprop(fdt, nodeoffset, "interrupts-extended", &count);
if (!val || count < sizeof(fdt32_t)) if (!val || count < sizeof(fdt32_t))
return SBI_EINVAL; return SBI_ENODEV;
count = count / sizeof(fdt32_t); count = count / sizeof(fdt32_t);
first_hartid = -1U; first_hartid = -1U;
last_hartid = 0; last_hartid = 0;
clint->hart_count = 0; *out_hart_count = 0;
for (i = 0; i < count; i += 2) { for (i = 0; i < count; i += 2) {
phandle = fdt32_to_cpu(val[i]); phandle = fdt32_to_cpu(val[i]);
hwirq = fdt32_to_cpu(val[i + 1]); 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; first_hartid = hartid;
if (hartid > last_hartid) if (hartid > last_hartid)
last_hartid = hartid; last_hartid = hartid;
clint->hart_count++; (*out_hart_count)++;
} }
} }
if ((last_hartid < first_hartid) || first_hartid == -1U) if ((last_hartid < first_hartid) || first_hartid == -1U)
return SBI_ENODEV; return SBI_ENODEV;
clint->first_hartid = first_hartid; *out_first_hartid = first_hartid;
count = last_hartid - first_hartid + 1; count = last_hartid - first_hartid + 1;
if (clint->hart_count < count) if (*out_hart_count < count)
clint->hart_count = count; *out_hart_count = count;
clint->has_64bit_mmio = TRUE;
if (fdt_getprop(fdt, nodeoffset, "clint,has-no-64bit-mmio", &count))
clint->has_64bit_mmio = FALSE;
return 0; return 0;
} }

View File

@@ -21,15 +21,18 @@ static int ipi_clint_cold_init(void *fdt, int nodeoff,
const struct fdt_match *match) const struct fdt_match *match)
{ {
int rc; int rc;
unsigned long cisize;
struct clint_data *ci; struct clint_data *ci;
if (CLINT_IPI_MAX_NR <= clint_ipi_count) if (CLINT_IPI_MAX_NR <= clint_ipi_count)
return SBI_ENOSPC; return SBI_ENOSPC;
ci = &clint_ipi[clint_ipi_count++]; ci = &clint_ipi[clint_ipi_count++];
rc = fdt_parse_clint_node(fdt, nodeoff, FALSE, ci); rc = fdt_parse_aclint_node(fdt, nodeoff, false, &ci->addr, &cisize,
&ci->first_hartid, &ci->hart_count);
if (rc) if (rc)
return rc; return rc;
ci->has_64bit_mmio = false;
return clint_cold_ipi_init(ci); return clint_cold_ipi_init(ci);
} }

View File

@@ -7,6 +7,7 @@
* Anup Patel <anup.patel@wdc.com> * Anup Patel <anup.patel@wdc.com>
*/ */
#include <libfdt.h>
#include <sbi/sbi_error.h> #include <sbi/sbi_error.h>
#include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/fdt/fdt_helper.h>
#include <sbi_utils/timer/fdt_timer.h> #include <sbi_utils/timer/fdt_timer.h>
@@ -21,6 +22,7 @@ static int timer_clint_cold_init(void *fdt, int nodeoff,
const struct fdt_match *match) const struct fdt_match *match)
{ {
int rc; int rc;
unsigned long ctsize;
struct clint_data *ct, *ctmaster = NULL; struct clint_data *ct, *ctmaster = NULL;
if (CLINT_TIMER_MAX_NR <= clint_timer_count) if (CLINT_TIMER_MAX_NR <= clint_timer_count)
@@ -29,10 +31,15 @@ static int timer_clint_cold_init(void *fdt, int nodeoff,
if (1 < clint_timer_count) if (1 < clint_timer_count)
ctmaster = &clint_timer[0]; ctmaster = &clint_timer[0];
rc = fdt_parse_clint_node(fdt, nodeoff, TRUE, ct); rc = fdt_parse_aclint_node(fdt, nodeoff, true, &ct->addr, &ctsize,
&ct->first_hartid, &ct->hart_count);
if (rc) if (rc)
return rc; return rc;
ct->has_64bit_mmio = true;
if (fdt_getprop(fdt, nodeoff, "clint,has-no-64bit-mmio", &rc))
ct->has_64bit_mmio = false;
return clint_cold_timer_init(ct, ctmaster); return clint_cold_timer_init(ct, ctmaster);
} }