blob: ab22395c552936496816a15a1e059446bc7d7978 [file] [log] [blame]
Bin Meng644a3cd2018-12-12 06:12:30 -08001// SPDX-License-Identifier: GPL-2.0+
2/*
Sean Anderson47d7e3b2020-10-25 21:46:58 -04003 * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com>
Bin Meng644a3cd2018-12-12 06:12:30 -08004 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
5 *
6 * U-Boot syscon driver for SiFive's Core Local Interruptor (CLINT).
7 * The CLINT block holds memory-mapped control and status registers
8 * associated with software and timer interrupts.
9 */
10
11#include <common.h>
12#include <dm.h>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Bin Meng644a3cd2018-12-12 06:12:30 -080014#include <asm/io.h>
Sean Anderson47d7e3b2020-10-25 21:46:58 -040015#include <asm/smp.h>
Simon Glass61b29b82020-02-03 07:36:15 -070016#include <linux/err.h>
Bin Meng644a3cd2018-12-12 06:12:30 -080017
18/* MSIP registers */
19#define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4)
Bin Meng644a3cd2018-12-12 06:12:30 -080020
21DECLARE_GLOBAL_DATA_PTR;
22
Sean Anderson40686c32020-06-24 06:41:18 -040023int riscv_init_ipi(void)
24{
Sean Andersone5ca9a72020-09-28 10:52:26 -040025 int ret;
26 struct udevice *dev;
Sean Anderson40686c32020-06-24 06:41:18 -040027
Sean Andersone5ca9a72020-09-28 10:52:26 -040028 ret = uclass_get_device_by_driver(UCLASS_TIMER,
Simon Glass65e25be2020-12-28 20:34:56 -070029 DM_DRIVER_GET(sifive_clint), &dev);
Sean Andersone5ca9a72020-09-28 10:52:26 -040030 if (ret)
31 return ret;
32
33 gd->arch.clint = dev_read_addr_ptr(dev);
34 if (!gd->arch.clint)
35 return -EINVAL;
Sean Anderson40686c32020-06-24 06:41:18 -040036
37 return 0;
38}
39
Bin Meng644a3cd2018-12-12 06:12:30 -080040int riscv_send_ipi(int hart)
41{
Bin Meng644a3cd2018-12-12 06:12:30 -080042 writel(1, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
43
44 return 0;
45}
46
47int riscv_clear_ipi(int hart)
48{
Bin Meng644a3cd2018-12-12 06:12:30 -080049 writel(0, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
50
51 return 0;
52}
53
Lukas Auer8b3e97b2019-12-08 23:28:50 +010054int riscv_get_ipi(int hart, int *pending)
55{
Lukas Auer8b3e97b2019-12-08 23:28:50 +010056 *pending = readl((void __iomem *)MSIP_REG(gd->arch.clint, hart));
57
58 return 0;
59}