blob: f24216838120b0a239215bcbb6cdc302952c9747 [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>
Bin Meng7f1a30f2023-06-21 23:11:45 +080013#include <regmap.h>
14#include <syscon.h>
Simon Glass401d1c42020-10-30 21:38:53 -060015#include <asm/global_data.h>
Bin Meng644a3cd2018-12-12 06:12:30 -080016#include <asm/io.h>
Sean Anderson47d7e3b2020-10-25 21:46:58 -040017#include <asm/smp.h>
Bin Meng7f1a30f2023-06-21 23:11:45 +080018#include <asm/syscon.h>
Simon Glass61b29b82020-02-03 07:36:15 -070019#include <linux/err.h>
Bin Meng644a3cd2018-12-12 06:12:30 -080020
21/* MSIP registers */
22#define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4)
Bin Meng644a3cd2018-12-12 06:12:30 -080023
24DECLARE_GLOBAL_DATA_PTR;
25
Sean Anderson40686c32020-06-24 06:41:18 -040026int riscv_init_ipi(void)
27{
Sean Andersone5ca9a72020-09-28 10:52:26 -040028 int ret;
29 struct udevice *dev;
Sean Anderson40686c32020-06-24 06:41:18 -040030
Sean Andersone5ca9a72020-09-28 10:52:26 -040031 ret = uclass_get_device_by_driver(UCLASS_TIMER,
Simon Glass65e25be2020-12-28 20:34:56 -070032 DM_DRIVER_GET(sifive_clint), &dev);
Sean Andersone5ca9a72020-09-28 10:52:26 -040033 if (ret)
34 return ret;
35
Bin Meng7f1a30f2023-06-21 23:11:45 +080036 if (dev_get_driver_data(dev) != 0)
37 gd->arch.clint = dev_read_addr_ptr(dev);
38 else
39 gd->arch.clint = syscon_get_first_range(RISCV_SYSCON_CLINT);
40
Sean Andersone5ca9a72020-09-28 10:52:26 -040041 if (!gd->arch.clint)
42 return -EINVAL;
Sean Anderson40686c32020-06-24 06:41:18 -040043
44 return 0;
45}
46
Bin Meng644a3cd2018-12-12 06:12:30 -080047int riscv_send_ipi(int hart)
48{
Bin Meng644a3cd2018-12-12 06:12:30 -080049 writel(1, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
50
51 return 0;
52}
53
54int riscv_clear_ipi(int hart)
55{
Bin Meng644a3cd2018-12-12 06:12:30 -080056 writel(0, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
57
58 return 0;
59}
60
Lukas Auer8b3e97b2019-12-08 23:28:50 +010061int riscv_get_ipi(int hart, int *pending)
62{
Lukas Auer8b3e97b2019-12-08 23:28:50 +010063 *pending = readl((void __iomem *)MSIP_REG(gd->arch.clint, hart));
64
65 return 0;
66}
Bin Meng7f1a30f2023-06-21 23:11:45 +080067
68static const struct udevice_id riscv_aclint_swi_ids[] = {
69 { .compatible = "riscv,aclint-mswi", .data = RISCV_SYSCON_CLINT },
70 { }
71};
72
73U_BOOT_DRIVER(riscv_aclint_swi) = {
74 .name = "riscv_aclint_swi",
75 .id = UCLASS_SYSCON,
76 .of_match = riscv_aclint_swi_ids,
77 .flags = DM_FLAG_PRE_RELOC,
78};