lib: utils/fdt: Extend fdt_parse_aclint_node() function

The fdt_parse_aclint_node() is used to parse DT node for SiFive
CLINT, ACLINT MTIMER, and ACLINT MSWI devices.

The ACLINT MTIMER has undergone following changes:
1) MTIMER DT node now requires separate addresses in for MTIME
   register and MTIMECMPx registers in the reg DT property.
2) MTIMER DT node might have no interrupts-extended DT property
   when the MTIMER device has no associated HARTs (i.e. the
   MTIMER device has no MTIMECMPx registers)

This patch extends fdt_parse_aclint_node() to handle above
mentioned changes in ACLINT MTIMER DT bindings.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
Anup Patel 2021-07-23 15:37:51 +05:30 committed by Anup Patel
parent 7a3a0cce4d
commit f3a0eb8583
4 changed files with 49 additions and 30 deletions

View file

@ -72,7 +72,8 @@ 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);
int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer, int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
unsigned long *out_addr, unsigned long *out_size, unsigned long *out_addr1, unsigned long *out_size1,
unsigned long *out_addr2, unsigned long *out_size2,
u32 *out_first_hartid, u32 *out_hart_count); u32 *out_first_hartid, u32 *out_hart_count);
int fdt_parse_compat_addr(void *fdt, uint64_t *addr, int fdt_parse_compat_addr(void *fdt, uint64_t *addr,

View file

@ -481,38 +481,50 @@ int fdt_parse_plic(void *fdt, struct plic_data *plic, const char *compat)
} }
int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer, int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
unsigned long *out_addr, unsigned long *out_size, unsigned long *out_addr1, unsigned long *out_size1,
unsigned long *out_addr2, unsigned long *out_size2,
u32 *out_first_hartid, u32 *out_hart_count) u32 *out_first_hartid, u32 *out_hart_count)
{ {
const fdt32_t *val; const fdt32_t *val;
uint64_t reg_addr, reg_size; uint64_t reg_addr, reg_size;
int i, rc, count, cpu_offset, cpu_intc_offset; int i, rc, count, cpu_offset, cpu_intc_offset;
u32 phandle, hwirq, hartid, first_hartid, last_hartid; u32 phandle, hwirq, hartid, first_hartid, last_hartid, hart_count;
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 || !fdt || if (nodeoffset < 0 || !fdt ||
!out_addr || !out_size || !out_addr1 || !out_size1 ||
!out_first_hartid || !out_hart_count) !out_first_hartid || !out_hart_count)
return SBI_EINVAL; return SBI_EINVAL;
rc = fdt_get_node_addr_size(fdt, nodeoffset, 0, rc = fdt_get_node_addr_size(fdt, nodeoffset, 0,
&reg_addr, &reg_size); &reg_addr, &reg_size);
if (rc < 0 || !reg_addr || !reg_size) if (rc < 0 || !reg_size)
return SBI_ENODEV; return SBI_ENODEV;
*out_addr = reg_addr; *out_addr1 = reg_addr;
*out_size = reg_size; *out_size1 = reg_size;
rc = fdt_get_node_addr_size(fdt, nodeoffset, 1,
&reg_addr, &reg_size);
if (rc < 0 || !reg_size)
reg_addr = reg_size = 0;
if (out_addr2)
*out_addr2 = reg_addr;
if (out_size2)
*out_size2 = reg_size;
*out_first_hartid = 0;
*out_hart_count = 0;
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_ENODEV; return 0;
count = count / sizeof(fdt32_t); count = count / sizeof(fdt32_t);
first_hartid = -1U; first_hartid = -1U;
last_hartid = 0; hart_count = last_hartid = 0;
*out_hart_count = 0; for (i = 0; i < (count / 2); i++) {
for (i = 0; i < count; i += 2) { phandle = fdt32_to_cpu(val[2 * i]);
phandle = fdt32_to_cpu(val[i]); hwirq = fdt32_to_cpu(val[(2 * i) + 1]);
hwirq = fdt32_to_cpu(val[i + 1]);
cpu_intc_offset = fdt_node_offset_by_phandle(fdt, phandle); cpu_intc_offset = fdt_node_offset_by_phandle(fdt, phandle);
if (cpu_intc_offset < 0) if (cpu_intc_offset < 0)
@ -534,17 +546,15 @@ int fdt_parse_aclint_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;
(*out_hart_count)++; hart_count++;
} }
} }
if ((last_hartid < first_hartid) || first_hartid == -1U) if ((last_hartid >= first_hartid) && first_hartid != -1U) {
return SBI_ENODEV;
*out_first_hartid = first_hartid; *out_first_hartid = first_hartid;
count = last_hartid - first_hartid + 1; count = last_hartid - first_hartid + 1;
if (*out_hart_count < count) *out_hart_count = (hart_count < count) ? hart_count : count;
*out_hart_count = count; }
return 0; return 0;
} }

View file

@ -28,7 +28,8 @@ static int ipi_mswi_cold_init(void *fdt, int nodeoff,
return SBI_ENOSPC; return SBI_ENOSPC;
ms = &mswi[mswi_count]; ms = &mswi[mswi_count];
rc = fdt_parse_aclint_node(fdt, nodeoff, false, &ms->addr, &ms->size, rc = fdt_parse_aclint_node(fdt, nodeoff, false,
&ms->addr, &ms->size, NULL, NULL,
&ms->first_hartid, &ms->hart_count); &ms->first_hartid, &ms->hart_count);
if (rc) if (rc)
return rc; return rc;

View file

@ -22,7 +22,7 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
const struct fdt_match *match) const struct fdt_match *match)
{ {
int rc; int rc;
unsigned long offset, addr, size; unsigned long offset, addr[2], size[2];
struct aclint_mtimer_data *mt, *mtmaster = NULL; struct aclint_mtimer_data *mt, *mtmaster = NULL;
if (MTIMER_MAX_NR <= mtimer_count) if (MTIMER_MAX_NR <= mtimer_count)
@ -31,18 +31,19 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
if (0 < mtimer_count) if (0 < mtimer_count)
mtmaster = &mtimer[0]; mtmaster = &mtimer[0];
rc = fdt_parse_aclint_node(fdt, nodeoff, true, &addr, &size, rc = fdt_parse_aclint_node(fdt, nodeoff, true,
&addr[0], &size[0], &addr[1], &size[1],
&mt->first_hartid, &mt->hart_count); &mt->first_hartid, &mt->hart_count);
if (rc) if (rc)
return rc; return rc;
mt->has_64bit_mmio = true; mt->has_64bit_mmio = true;
mt->mtimecmp_addr = addr + ACLINT_DEFAULT_MTIMECMP_OFFSET; if (match->data) { /* SiFive CLINT */
/* Set CLINT addresses */
mt->mtimecmp_addr = addr[0] + ACLINT_DEFAULT_MTIMECMP_OFFSET;
mt->mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE; mt->mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE;
mt->mtime_addr = addr + ACLINT_DEFAULT_MTIME_OFFSET; mt->mtime_addr = addr[0] + ACLINT_DEFAULT_MTIME_OFFSET;
mt->mtime_size = size - mt->mtimecmp_size; mt->mtime_size = size[0] - mt->mtimecmp_size;
if (match->data) {
/* Adjust MTIMER address and size for CLINT device */ /* Adjust MTIMER address and size for CLINT device */
offset = *((unsigned long *)match->data); offset = *((unsigned long *)match->data);
mt->mtime_addr += offset; mt->mtime_addr += offset;
@ -51,6 +52,12 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
/* Parse additional CLINT properties */ /* Parse additional CLINT properties */
if (fdt_getprop(fdt, nodeoff, "clint,has-no-64bit-mmio", &rc)) if (fdt_getprop(fdt, nodeoff, "clint,has-no-64bit-mmio", &rc))
mt->has_64bit_mmio = false; mt->has_64bit_mmio = false;
} else { /* RISC-V ACLINT MTIMER */
/* Set ACLINT MTIMER addresses */
mt->mtime_addr = addr[0];
mt->mtime_size = size[0];
mt->mtimecmp_addr = addr[1];
mt->mtimecmp_size = size[1];
} }
rc = aclint_mtimer_cold_init(mt, mtmaster); rc = aclint_mtimer_cold_init(mt, mtmaster);