blob: ab22395c552936496816a15a1e059446bc7d7978 [file] [log] [blame]
Bin Mengb6ee5e12018-12-12 06:12:30 -08001// SPDX-License-Identifier: GPL-2.0+
2/*
Sean Anderson52a1db72020-10-25 21:46:58 -04003 * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com>
Bin Mengb6ee5e12018-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 Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Bin Mengb6ee5e12018-12-12 06:12:30 -080014#include <asm/io.h>
Sean Anderson52a1db72020-10-25 21:46:58 -040015#include <asm/smp.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070016#include <linux/err.h>
Bin Mengb6ee5e12018-12-12 06:12:30 -080017
18/* MSIP registers */
19#define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4)
Bin Mengb6ee5e12018-12-12 06:12:30 -080020
21DECLARE_GLOBAL_DATA_PTR;
22
Sean Anderson272ab202020-09-28 10:52:26 -040023int riscv_init_ipi(void)
Bin Mengb6ee5e12018-12-12 06:12:30 -080024{
Sean Anderson272ab202020-09-28 10:52:26 -040025 int ret;
26 struct udevice *dev;
Bin Meng257875d2020-07-19 23:17:07 -070027
Sean Anderson272ab202020-09-28 10:52:26 -040028 ret = uclass_get_device_by_driver(UCLASS_TIMER,
Simon Glass65130cd2020-12-28 20:34:56 -070029 DM_DRIVER_GET(sifive_clint), &dev);
Sean Anderson272ab202020-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;
Bin Mengb6ee5e12018-12-12 06:12:30 -080036
37 return 0;
38}
39
Sean Anderson272ab202020-09-28 10:52:26 -040040int riscv_send_ipi(int hart)
Bin Mengb6ee5e12018-12-12 06:12:30 -080041{
Sean Anderson272ab202020-09-28 10:52:26 -040042 writel(1, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
Bin Mengb6ee5e12018-12-12 06:12:30 -080043
44 return 0;
45}
46
Sean Anderson272ab202020-09-28 10:52:26 -040047int riscv_clear_ipi(int hart)
Bin Mengb6ee5e12018-12-12 06:12:30 -080048{
Sean Anderson272ab202020-09-28 10:52:26 -040049 writel(0, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
Sean Andersonb1d0cb32020-06-24 06:41:18 -040050
51 return 0;
52}
Bin Mengb6ee5e12018-12-12 06:12:30 -080053
Sean Anderson272ab202020-09-28 10:52:26 -040054int riscv_get_ipi(int hart, int *pending)
Sean Andersonb1d0cb32020-06-24 06:41:18 -040055{
Sean Anderson272ab202020-09-28 10:52:26 -040056 *pending = readl((void __iomem *)MSIP_REG(gd->arch.clint, hart));
Bin Mengb6ee5e12018-12-12 06:12:30 -080057
58 return 0;
59}