2018-12-12 14:12:30 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
2020-10-26 01:46:58 +00:00
|
|
|
* Copyright (C) 2020, Sean Anderson <seanga2@gmail.com>
|
2018-12-12 14:12:30 +00:00
|
|
|
* Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
|
|
|
|
*
|
|
|
|
* U-Boot syscon driver for SiFive's Core Local Interruptor (CLINT).
|
|
|
|
* The CLINT block holds memory-mapped control and status registers
|
|
|
|
* associated with software and timer interrupts.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <asm/io.h>
|
2020-10-26 01:46:58 +00:00
|
|
|
#include <asm/smp.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2018-12-12 14:12:30 +00:00
|
|
|
|
|
|
|
/* MSIP registers */
|
|
|
|
#define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4)
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
int riscv_init_ipi(void)
|
2018-12-12 14:12:30 +00:00
|
|
|
{
|
2020-09-28 14:52:26 +00:00
|
|
|
int ret;
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_TIMER,
|
|
|
|
DM_GET_DRIVER(sifive_clint), &dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2020-07-20 06:17:07 +00:00
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
gd->arch.clint = dev_read_addr_ptr(dev);
|
|
|
|
if (!gd->arch.clint)
|
|
|
|
return -EINVAL;
|
2018-12-12 14:12:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
int riscv_send_ipi(int hart)
|
2018-12-12 14:12:30 +00:00
|
|
|
{
|
2020-09-28 14:52:26 +00:00
|
|
|
writel(1, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
|
2018-12-12 14:12:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
int riscv_clear_ipi(int hart)
|
2018-12-12 14:12:30 +00:00
|
|
|
{
|
2020-09-28 14:52:26 +00:00
|
|
|
writel(0, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
|
2020-06-24 10:41:18 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-12-12 14:12:30 +00:00
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
int riscv_get_ipi(int hart, int *pending)
|
2020-06-24 10:41:18 +00:00
|
|
|
{
|
2020-09-28 14:52:26 +00:00
|
|
|
*pending = readl((void __iomem *)MSIP_REG(gd->arch.clint, hart));
|
2018-12-12 14:12:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|