Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Sean Anderson | 52a1db7 | 2020-10-25 21:46:58 -0400 | [diff] [blame] | 3 | * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com> |
Bin Meng | b6ee5e1 | 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> |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 13 | #include <asm/io.h> |
Sean Anderson | 52a1db7 | 2020-10-25 21:46:58 -0400 | [diff] [blame] | 14 | #include <asm/smp.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 15 | #include <linux/err.h> |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 16 | |
| 17 | /* MSIP registers */ |
| 18 | #define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4) |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 22 | int riscv_init_ipi(void) |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 23 | { |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 24 | int ret; |
| 25 | struct udevice *dev; |
Bin Meng | 257875d | 2020-07-19 23:17:07 -0700 | [diff] [blame] | 26 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 27 | 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 Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 39 | int riscv_send_ipi(int hart) |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 40 | { |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 41 | writel(1, (void __iomem *)MSIP_REG(gd->arch.clint, hart)); |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 46 | int riscv_clear_ipi(int hart) |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 47 | { |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 48 | writel(0, (void __iomem *)MSIP_REG(gd->arch.clint, hart)); |
Sean Anderson | b1d0cb3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 49 | |
| 50 | return 0; |
| 51 | } |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 52 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 53 | int riscv_get_ipi(int hart, int *pending) |
Sean Anderson | b1d0cb3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 54 | { |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 55 | *pending = readl((void __iomem *)MSIP_REG(gd->arch.clint, hart)); |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 56 | |
| 57 | return 0; |
| 58 | } |