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>
|
2023-06-21 15:11:45 +00:00
|
|
|
#include <regmap.h>
|
|
|
|
#include <syscon.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2018-12-12 14:12:30 +00:00
|
|
|
#include <asm/io.h>
|
2020-10-26 01:46:58 +00:00
|
|
|
#include <asm/smp.h>
|
2023-06-21 15:11:45 +00:00
|
|
|
#include <asm/syscon.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,
|
2023-06-21 15:11:46 +00:00
|
|
|
DM_DRIVER_GET(riscv_aclint_timer), &dev);
|
2020-09-28 14:52:26 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2020-07-20 06:17:07 +00:00
|
|
|
|
2023-06-21 15:11:45 +00:00
|
|
|
if (dev_get_driver_data(dev) != 0)
|
2023-06-21 15:11:46 +00:00
|
|
|
gd->arch.aclint = dev_read_addr_ptr(dev);
|
2023-06-21 15:11:45 +00:00
|
|
|
else
|
2023-06-21 15:11:46 +00:00
|
|
|
gd->arch.aclint = syscon_get_first_range(RISCV_SYSCON_ACLINT);
|
2023-06-21 15:11:45 +00:00
|
|
|
|
2023-06-21 15:11:46 +00:00
|
|
|
if (!gd->arch.aclint)
|
2020-09-28 14:52:26 +00:00
|
|
|
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
|
|
|
{
|
2023-06-21 15:11:46 +00:00
|
|
|
writel(1, (void __iomem *)MSIP_REG(gd->arch.aclint, 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
|
|
|
{
|
2023-06-21 15:11:46 +00:00
|
|
|
writel(0, (void __iomem *)MSIP_REG(gd->arch.aclint, 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
|
|
|
{
|
2023-06-21 15:11:46 +00:00
|
|
|
*pending = readl((void __iomem *)MSIP_REG(gd->arch.aclint, hart));
|
2018-12-12 14:12:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2023-06-21 15:11:45 +00:00
|
|
|
|
|
|
|
static const struct udevice_id riscv_aclint_swi_ids[] = {
|
2023-06-21 15:11:46 +00:00
|
|
|
{ .compatible = "riscv,aclint-mswi", .data = RISCV_SYSCON_ACLINT },
|
2023-06-21 15:11:45 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(riscv_aclint_swi) = {
|
|
|
|
.name = "riscv_aclint_swi",
|
|
|
|
.id = UCLASS_SYSCON,
|
|
|
|
.of_match = riscv_aclint_swi_ids,
|
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
|
|
|
};
|