blob: c8079dc510c271722163a771b249a4513981436e [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>
Bin Mengb6ee5e12018-12-12 06:12:30 -080013#include <asm/io.h>
Sean Anderson52a1db72020-10-25 21:46:58 -040014#include <asm/smp.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070015#include <linux/err.h>
Bin Mengb6ee5e12018-12-12 06:12:30 -080016
17/* MSIP registers */
18#define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4)
Bin Mengb6ee5e12018-12-12 06:12:30 -080019
20DECLARE_GLOBAL_DATA_PTR;
21
Sean Anderson272ab202020-09-28 10:52:26 -040022int riscv_init_ipi(void)
Bin Mengb6ee5e12018-12-12 06:12:30 -080023{
Sean Anderson272ab202020-09-28 10:52:26 -040024 int ret;
25 struct udevice *dev;
Bin Meng257875d2020-07-19 23:17:07 -070026
Sean Anderson272ab202020-09-28 10:52:26 -040027 ret = uclass_get_device_by_driver(UCLASS_TIMER,
28 DM_GET_DRIVER(sifive_clint), &dev);
29 if (ret)
30 return ret;
31
32 gd->arch.clint = dev_read_addr_ptr(dev);
33 if (!gd->arch.clint)
34 return -EINVAL;
Bin Mengb6ee5e12018-12-12 06:12:30 -080035
36 return 0;
37}
38
Sean Anderson272ab202020-09-28 10:52:26 -040039int riscv_send_ipi(int hart)
Bin Mengb6ee5e12018-12-12 06:12:30 -080040{
Sean Anderson272ab202020-09-28 10:52:26 -040041 writel(1, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
Bin Mengb6ee5e12018-12-12 06:12:30 -080042
43 return 0;
44}
45
Sean Anderson272ab202020-09-28 10:52:26 -040046int riscv_clear_ipi(int hart)
Bin Mengb6ee5e12018-12-12 06:12:30 -080047{
Sean Anderson272ab202020-09-28 10:52:26 -040048 writel(0, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
Sean Andersonb1d0cb32020-06-24 06:41:18 -040049
50 return 0;
51}
Bin Mengb6ee5e12018-12-12 06:12:30 -080052
Sean Anderson272ab202020-09-28 10:52:26 -040053int riscv_get_ipi(int hart, int *pending)
Sean Andersonb1d0cb32020-06-24 06:41:18 -040054{
Sean Anderson272ab202020-09-28 10:52:26 -040055 *pending = readl((void __iomem *)MSIP_REG(gd->arch.clint, hart));
Bin Mengb6ee5e12018-12-12 06:12:30 -080056
57 return 0;
58}