blob: dcd7e5e6b3449ab22b0881f49fd0f14e0f1651c1 [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
Bin Meng644a3cd2018-12-12 06:12:30 -080011#include <dm.h>
Bin Meng7f1a30f2023-06-21 23:11:45 +080012#include <regmap.h>
13#include <syscon.h>
Simon Glass401d1c42020-10-30 21:38:53 -060014#include <asm/global_data.h>
Bin Meng644a3cd2018-12-12 06:12:30 -080015#include <asm/io.h>
Sean Anderson47d7e3b2020-10-25 21:46:58 -040016#include <asm/smp.h>
Bin Meng7f1a30f2023-06-21 23:11:45 +080017#include <asm/syscon.h>
Simon Glass61b29b82020-02-03 07:36:15 -070018#include <linux/err.h>
Bin Meng644a3cd2018-12-12 06:12:30 -080019
20/* MSIP registers */
21#define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4)
Bin Meng644a3cd2018-12-12 06:12:30 -080022
23DECLARE_GLOBAL_DATA_PTR;
24
Sean Anderson40686c32020-06-24 06:41:18 -040025int riscv_init_ipi(void)
26{
Sean Andersone5ca9a72020-09-28 10:52:26 -040027 int ret;
28 struct udevice *dev;
Sean Anderson40686c32020-06-24 06:41:18 -040029
Sean Andersone5ca9a72020-09-28 10:52:26 -040030 ret = uclass_get_device_by_driver(UCLASS_TIMER,
Bin Meng9675d922023-06-21 23:11:46 +080031 DM_DRIVER_GET(riscv_aclint_timer), &dev);
Sean Andersone5ca9a72020-09-28 10:52:26 -040032 if (ret)
33 return ret;
34
Bin Meng7f1a30f2023-06-21 23:11:45 +080035 if (dev_get_driver_data(dev) != 0)
Bin Meng9675d922023-06-21 23:11:46 +080036 gd->arch.aclint = dev_read_addr_ptr(dev);
Bin Meng7f1a30f2023-06-21 23:11:45 +080037 else
Bin Meng9675d922023-06-21 23:11:46 +080038 gd->arch.aclint = syscon_get_first_range(RISCV_SYSCON_ACLINT);
Bin Meng7f1a30f2023-06-21 23:11:45 +080039
Bin Meng9675d922023-06-21 23:11:46 +080040 if (!gd->arch.aclint)
Sean Andersone5ca9a72020-09-28 10:52:26 -040041 return -EINVAL;
Sean Anderson40686c32020-06-24 06:41:18 -040042
43 return 0;
44}
45
Bin Meng644a3cd2018-12-12 06:12:30 -080046int riscv_send_ipi(int hart)
47{
Bin Meng9675d922023-06-21 23:11:46 +080048 writel(1, (void __iomem *)MSIP_REG(gd->arch.aclint, hart));
Bin Meng644a3cd2018-12-12 06:12:30 -080049
50 return 0;
51}
52
53int riscv_clear_ipi(int hart)
54{
Bin Meng9675d922023-06-21 23:11:46 +080055 writel(0, (void __iomem *)MSIP_REG(gd->arch.aclint, hart));
Bin Meng644a3cd2018-12-12 06:12:30 -080056
57 return 0;
58}
59
Lukas Auer8b3e97b2019-12-08 23:28:50 +010060int riscv_get_ipi(int hart, int *pending)
61{
Bin Meng9675d922023-06-21 23:11:46 +080062 *pending = readl((void __iomem *)MSIP_REG(gd->arch.aclint, hart));
Lukas Auer8b3e97b2019-12-08 23:28:50 +010063
64 return 0;
65}
Bin Meng7f1a30f2023-06-21 23:11:45 +080066
67static const struct udevice_id riscv_aclint_swi_ids[] = {
Bin Meng9675d922023-06-21 23:11:46 +080068 { .compatible = "riscv,aclint-mswi", .data = RISCV_SYSCON_ACLINT },
Bin Meng7f1a30f2023-06-21 23:11:45 +080069 { }
70};
71
72U_BOOT_DRIVER(riscv_aclint_swi) = {
73 .name = "riscv_aclint_swi",
74 .id = UCLASS_SYSCON,
75 .of_match = riscv_aclint_swi_ids,
76 .flags = DM_FLAG_PRE_RELOC,
77};