forked from Mirrors/opensbi
lib: utils: Add fdt_parse_clint_node() function
We add fdt_parse_clint_node() function which will be used by fdt_ipi_clint and fdt_timer_clint drivers to parse CLINT details from DT node. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
@@ -54,6 +54,11 @@ 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_clint_node(void *fdt, int nodeoffset, bool for_timer,
|
||||||
|
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);
|
||||||
|
|
||||||
|
@@ -9,10 +9,12 @@
|
|||||||
#include <libfdt.h>
|
#include <libfdt.h>
|
||||||
#include <sbi/riscv_asm.h>
|
#include <sbi/riscv_asm.h>
|
||||||
#include <sbi/sbi_console.h>
|
#include <sbi/sbi_console.h>
|
||||||
|
#include <sbi/sbi_hartmask.h>
|
||||||
#include <sbi/sbi_platform.h>
|
#include <sbi/sbi_platform.h>
|
||||||
#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
|
||||||
@@ -296,6 +298,73 @@ 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,
|
||||||
|
struct clint_data *clint)
|
||||||
|
{
|
||||||
|
const fdt32_t *val;
|
||||||
|
unsigned long reg_addr, reg_size;
|
||||||
|
int i, rc, count, cpu_offset, cpu_intc_offset;
|
||||||
|
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;
|
||||||
|
|
||||||
|
rc = fdt_get_node_addr_size(fdt, nodeoffset, ®_addr, ®_size);
|
||||||
|
if (rc < 0 || !reg_addr || !reg_size)
|
||||||
|
return SBI_ENODEV;
|
||||||
|
clint->addr = reg_addr;
|
||||||
|
|
||||||
|
val = fdt_getprop(fdt, nodeoffset, "interrupts-extended", &count);
|
||||||
|
if (!val || count < sizeof(fdt32_t))
|
||||||
|
return SBI_EINVAL;
|
||||||
|
count = count / sizeof(fdt32_t);
|
||||||
|
|
||||||
|
first_hartid = -1U;
|
||||||
|
last_hartid = 0;
|
||||||
|
clint->hart_count = 0;
|
||||||
|
for (i = 0; i < count; i += 2) {
|
||||||
|
phandle = fdt32_to_cpu(val[i]);
|
||||||
|
hwirq = fdt32_to_cpu(val[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 (match_hwirq == hwirq) {
|
||||||
|
if (hartid < first_hartid)
|
||||||
|
first_hartid = hartid;
|
||||||
|
if (hartid > last_hartid)
|
||||||
|
last_hartid = hartid;
|
||||||
|
clint->hart_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((last_hartid < first_hartid) || first_hartid == -1U)
|
||||||
|
return SBI_ENODEV;
|
||||||
|
|
||||||
|
clint->first_hartid = first_hartid;
|
||||||
|
count = last_hartid - first_hartid + 1;
|
||||||
|
if (clint->hart_count < count)
|
||||||
|
clint->hart_count = count;
|
||||||
|
|
||||||
|
/* TODO: We should figure-out CLINT has_64bit_mmio from DT node */
|
||||||
|
clint->has_64bit_mmio = TRUE;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@@ -17,23 +17,11 @@ static int ipi_clint_cold_init(void *fdt, int nodeoff,
|
|||||||
const struct fdt_match *match)
|
const struct fdt_match *match)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
u32 max_hartid;
|
|
||||||
unsigned long addr;
|
|
||||||
|
|
||||||
rc = fdt_parse_max_hart_id(fdt, &max_hartid);
|
rc = fdt_parse_clint_node(fdt, nodeoff, FALSE, &clint_ipi);
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
rc = fdt_get_node_addr_size(fdt, nodeoff, &addr, NULL);
|
|
||||||
if (rc)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
/* TODO: We should figure-out CLINT has_64bit_mmio from DT node */
|
|
||||||
clint_ipi.addr = addr;
|
|
||||||
clint_ipi.first_hartid = 0;
|
|
||||||
clint_ipi.hart_count = max_hartid + 1;
|
|
||||||
clint_ipi.has_64bit_mmio = TRUE;
|
|
||||||
|
|
||||||
return clint_cold_ipi_init(&clint_ipi);
|
return clint_cold_ipi_init(&clint_ipi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,23 +17,11 @@ static int timer_clint_cold_init(void *fdt, int nodeoff,
|
|||||||
const struct fdt_match *match)
|
const struct fdt_match *match)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
u32 max_hartid;
|
|
||||||
unsigned long addr;
|
|
||||||
|
|
||||||
rc = fdt_parse_max_hart_id(fdt, &max_hartid);
|
rc = fdt_parse_clint_node(fdt, nodeoff, TRUE, &clint_timer);
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
rc = fdt_get_node_addr_size(fdt, nodeoff, &addr, NULL);
|
|
||||||
if (rc)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
/* TODO: We should figure-out CLINT has_64bit_mmio from DT node */
|
|
||||||
clint_timer.addr = addr;
|
|
||||||
clint_timer.first_hartid = 0;
|
|
||||||
clint_timer.hart_count = max_hartid + 1;
|
|
||||||
clint_timer.has_64bit_mmio = TRUE;
|
|
||||||
|
|
||||||
return clint_cold_timer_init(&clint_timer, NULL);
|
return clint_cold_timer_init(&clint_timer, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user