Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Sean Anderson | 47d7e3b | 2020-10-25 21:46:58 -0400 | [diff] [blame] | 3 | * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com> |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 4 | * 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 Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 14 | #include <asm/io.h> |
Sean Anderson | 47d7e3b | 2020-10-25 21:46:58 -0400 | [diff] [blame] | 15 | #include <asm/smp.h> |
Simon Glass | 61b29b8 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 16 | #include <linux/err.h> |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 17 | |
| 18 | /* MSIP registers */ |
| 19 | #define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4) |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Sean Anderson | 40686c3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 23 | int riscv_init_ipi(void) |
| 24 | { |
Sean Anderson | e5ca9a7 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 25 | int ret; |
| 26 | struct udevice *dev; |
Sean Anderson | 40686c3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 27 | |
Sean Anderson | e5ca9a7 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 28 | ret = uclass_get_device_by_driver(UCLASS_TIMER, |
Simon Glass | 65e25be | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 29 | DM_DRIVER_GET(sifive_clint), &dev); |
Sean Anderson | e5ca9a7 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 30 | if (ret) |
| 31 | return ret; |
| 32 | |
| 33 | gd->arch.clint = dev_read_addr_ptr(dev); |
| 34 | if (!gd->arch.clint) |
| 35 | return -EINVAL; |
Sean Anderson | 40686c3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 40 | int riscv_send_ipi(int hart) |
| 41 | { |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 42 | writel(1, (void __iomem *)MSIP_REG(gd->arch.clint, hart)); |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | int riscv_clear_ipi(int hart) |
| 48 | { |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 49 | writel(0, (void __iomem *)MSIP_REG(gd->arch.clint, hart)); |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
Lukas Auer | 8b3e97b | 2019-12-08 23:28:50 +0100 | [diff] [blame] | 54 | int riscv_get_ipi(int hart, int *pending) |
| 55 | { |
Lukas Auer | 8b3e97b | 2019-12-08 23:28:50 +0100 | [diff] [blame] | 56 | *pending = readl((void __iomem *)MSIP_REG(gd->arch.clint, hart)); |
| 57 | |
| 58 | return 0; |
| 59 | } |